[Solved] High unicode numbers in Chr()

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

[Solved] High unicode numbers in Chr()

Post by mango »

I want to use musical symbols. Some of them get very high unicode numbers as 119070. I tried to use the Chr-method, i.e. Chr(119070). That ended in an overflow-message. Entering Hex-Code to Chr did not work either.
Is that because there is a (byte) limit using Chr, do I have to load musical symbols (how will that work) to include them into Open Office or what else could I do to get access to these symbols?
Many thanks
Last edited by Hagar Delest on Mon May 13, 2019 7:54 am, edited 1 time in total.
Reason: Tagged solved
Apache Open Office 4.1.6 on Windows 10
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: High unicode numbers in Chr()

Post by JeJe »

Chr only supports up to 16 bit Unicode values - that's in the help file. If you look at the special characters dialog - it only has characters in that range too. And when I tried copying and pasting the musical symbols it didn't work.

So it looks like you're out of luck and Openoffice doesn't support these symbols.

Edit: I guess you could create a picture using the symbol you want and insert that instead.

Edit2: There might be a special font that has those symbols - I don't know.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: High unicode numbers in Chr()

Post by RusselB »

Chr (CHAR is the Calc function) are limited to 1-255.... so 119070 is way too high.
From the help file
CHAR
Converts a number into a character according to the current code table. The number can be a two-digit or three-digit integer number.
Codes greater than 127 may depend on your system's character mapping (for example iso-8859-1, iso-8859-2, Windows-1252, Windows-1250), and hence may not be portable.
Syntax
CHAR(Number)
Number is a number between 1 and 255 representing the code value for the character.
Example
=CHAR(100) returns the character d.
="abc" & CHAR(10) & "def" inserts a newline character into the string.
For musical notes (not sure how they relate to Calc, as there's no math that can be done with them, to my knowledge), you could try using Insert -> Special Character

It's been a long time since I had anything to do with musical notation, and I don't know which note(s) you're wanting, so you'll have to go through the various options until you find something that works for you,

Since you are working with unicode characters, the UNICHAR function might be better suited....as a, possible, easier method than using Insert -> Special Character
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: High unicode numbers in Chr()

Post by RusselB »

A quick test of

Code: Select all

=UNICHAR(119070)
didn't give me a musical note that I recognized, but then again that may be due to the font.
It also didn't give me any kind of error message, so the code was accepted.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: High unicode numbers in Chr()

Post by Zizi64 »

I want to use musical symbols. Some of them get very high unicode numbers as 119070.
Chr only supports up to 16 bit Unicode values - that's in the help file.
The Unicode 12.0 version adds 554 characters, for a total of 137,928 characters, and this number will be increased in the future.

No one character set will support all of these characters, because the relevant font file should be too huge to storing the vector graphic informations for all of the characters.


You need use a partial character set like the Lilypond or others.
http://lilypond.org/doc/v2.18/Documenta ... fonts.html
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: High unicode numbers in Chr()

Post by Lupp »

You may try:
http://doc.rhavin.de/MuML/ See "How to use". There's a link to the suggested font QMuML9.ttf.
The application of that font shouldn't be limited to the "Musical Markup Language V0.6.1" described on that page.
The page also is asking for a contribution of €5.00 (five EURO).

Among the rather few glyphs coming with that .ttf, there is no G clef, however. Therefore I would assume most of the musical symbols are supposed to be accessible on current systems anyway.

My LibO V 6.2.3 and also AOO V 4.1.5 on Win 10 obviously have access to fonts containing the violin clef (what the given unicode place is) and replace their standard font "transparently" iof needed. That's the kind of transparence making it difficult to identify what actually happened.
Last edited by Lupp on Wed May 08, 2019 1:24 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: High unicode numbers in Chr()

Post by JeJe »

Don't know whether these have what you want but some fonts here:

https://www.smufl.org/fonts/

There are also plenty of font editors around to customise a font... reassign glyphs to codepoints within the integer range perhaps?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: High unicode numbers in Chr()

Post by Zizi64 »

The MuseScore is an excellent free sheet music maker software:

https://musescore.org/en

You can create sheet music pages, and then you can embed it into the Writer (as an image) - if it necessary.
https://musescore.org/en/node/10398
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: High unicode numbers in Chr()

Post by mango »

Thanks all for your answers
I really need only four symbols up to now: musical sharp sign (9839), musical flat sign (9837), violin clef (119070), bass clef (119074). Chr(9839) and Chr(9839) work on my system.
I downloaded Bravura text Font for musical symbols and installed it. I can see the symbols in the Windows character table, but only the Hex-numbers seem to be displayed.
Anyway, how would I now address this font in LO or Apache. Do I have to include the font inside the installation directory of LO or Apache? Or include it at the beginning of the script, are there some methods I could use or can I directly address the symbols ?
Unichar didn't work with my installation, what could be the reason of this?
Apache Open Office 4.1.6 on Windows 10
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: High unicode numbers in Chr()

Post by RusselB »

If your font has been properly installed in Windows, then OpenOffice should recognize it upon the start up of OpenOffice.
Ie: In order to see the font in Calc, make sure that Calc is not running when you do the installation.
As to UNICHAR, if you entered it correctly, as I showed in my earlier post, then I can't think of any reason it wouldn't work.
Saying that it didn't work is, realistically, useless for us to try to determine a reason... Did you get an error message? If so, what was the message.. please be precise.
If no error message, then what did you get that indicates to you that the function didn't work?
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: High unicode numbers in Chr()

Post by Lupp »

(Just to emphasize this once more:)
It's not a matter of OpenOffice having problems with high unicode places. On my Win-10-system AOO 4.1.5 recognizes all the mentioned unicodes used with UNICHAR() as expected without any additional measures.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: High unicode numbers in Chr()

Post by Zizi64 »

My LibreOffice 6.1.5 portable version can show the characters with the built-in default character set named Liberation Sans:
unichar.png
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: High unicode numbers in Chr()

Post by mango »

That would be good news, I got the same font installed.
But UNICHAR does not work with my installation (LO 6.2.3.2 x64), neither with direct cell input, nor in scripting. Do I have to install an add-on?
Apache Open Office 4.1.6 on Windows 10
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: High unicode numbers in Chr()

Post by Lupp »

Might you tell us what you get instead of what you don't get, please?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: High unicode numbers in Chr()

Post by Zizi64 »

But UNICHAR does not work with my installation (LO 6.2.3.2 x64), neither with direct cell input, nor in scripting. Do I have to install an add-on?
Yes. Maybe that extension is named as "Windows 10" :D :D :D
it is very strange: While the UNICHAR() function worked fine for me at work on my Win10 machine, it not work on my Win7 machine at home - with same LO version. And Lupp tried it on Win10 too.

But your signature is:
Apache Open Office 4.1.6 on Windows 10

I do not know, what causes the difference on same op.sys. and with same LO version...
Do you have x64 version of the Win10?
What version of Java have you installed?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: High unicode numbers in Chr()

Post by mango »

I updated Java to its newest version Java 8 Update 211, it doesn't work either.
My signature is Apache 4.1.6, but in the course of the problems I met with shifted shapes I installed LO 6.2.3.2
I'm working with Windows10, x64. I didn't yet try, if it works with Apache.
When I use unichar in my macro I get a runtime error, saying that procudure sub or function is undefined.
Using it as cell input, I get #NAME?
Apache Open Office 4.1.6 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: High unicode numbers in Chr()

Post by Zizi64 »

When I use unichar in my macro I get a runtime error, saying that procudure sub or function is undefined.
The UNICHAR is a CELL function. You can call it from a Basic macro, but you can not use a simple calling by its name.
Search in this forum for examples: how to call the cell functions from a macro.
The list of the Built-in Basic functions are in the help: There are some MS VBA compatible functions, like the CharW(). You must use the statement,

Code: Select all

option vbasupport 1
if you want use them.
Be careful! The option vbasupport 1 will degrade the normal Chr() function to 8 bit parameters in the specific Module. (I just tried it.) And even the ChrW() can handle the 16 bit wide Unicode characters only.
https://help.libreoffice.org/latest/he/ ... 03350.html


Using it as cell input, I get #NAME?
That means you are using the LO with localized settings. Switch to English function names and try it again:
Tools - Options - LibreOffice Calc - Formula - Use English function names
Or search the relevant function name for your locale setting.
The Hungarian function name is UNIKARAKTER()
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: High unicode numbers in Chr()

Post by Lupp »

For testing the API-based solution:

Code: Select all

fa = createUnoService("com.sun.star.sheet.FunctionAccess")
ch = fa.CallFunction("UNICHAR", Array(119070))
Print ch
co = fa.CallFunction("UNICODE", Array(ch))
Print co
(This also works if called for any different model. Writer, Draw, ...)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: High unicode numbers in Chr()

Post by mango »

Thanks all for your help, guys
I tried
fa = createUnoService("com.sun.star.sheet.FunctionAccess")
ch = fa.CallFunction("UNICHAR", Array(119070))
and that did the trick. I put that into a TextShape and I could clearly see a violin clef.
One question about that still: Why do I have to set the second argument as an array?
Thanks again
Apache Open Office 4.1.6 on Windows 10
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: High unicode numbers in Chr()

Post by Lupp »

mango wrote:Why do I have to set the second argument as an array?
The two arguments of the callFunction method are typed and mandatory. The second one is typed as a 1D-array of element type Variant. It must be present even if the function is expecting 0 arguments. In other words: The array is the equivalent of the complete parameter-part of a function call.

The reported success is a surpise in a sense. If the macro approach worked, your LibO must have access to a font providing the glyph. A probably needed replacement automatism must also have worked. Why shouldn't a Calc cell then show the clef for =UNICHAR(119070) on your system as it does on mine? Or did I misunderstand the situation insofar?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: [Solved] High unicode numbers in Chr()

Post by mango »

Yes, that's strange. I tried it again: entering =UNICHAR(119070) into a cell ends up in =NAME? .
Regarding the font, I got Liberation Sans on my system (the one Tibor said, it would contain violin clef) and additionally installed Bravura, so the symbols should be accessible. Does that FunctionAccess provide a more universal way to access additional functions? Would be nice to understand that.
Apache Open Office 4.1.6 on Windows 10
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: [Solved] High unicode numbers in Chr()

Post by RusselB »

Zizi64 wrote:That means you are using the LO with localized settings. Switch to English function names and try it again:
Tools - Options - LibreOffice Calc - Formula - Use English function names
Or search the relevant function name for your locale setting.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
mango
Posts: 25
Joined: Mon Jan 07, 2019 12:28 am

Re: [Solved] High unicode numbers in Chr()

Post by mango »

Thanks for reminding me; I forgot to try that.
That was the reason. Now UNICHAR works.
Thanks again to all for supporting me on that.
Apache Open Office 4.1.6 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] High unicode numbers in Chr()

Post by Zizi64 »

Yes, it works on Windows 10, but it can not work for me on Windows 7 anyway...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply