Determine if a Unicode character is supported

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Determine if a Unicode character is supported

05 Feb 2019, 04:20

Code: Select all

Chr(0x263E) ;moon symbol
On some systems the above character will just display as a square box, which I presume means the character is not supported by the system. Whereas on other systems the character displays correctly.

Is there any way to determine if the user's system supports a character, that way if it doesn't I can swap it for some other character like the letter O or something, instead of the user having a bunch of square boxes.

Thanks!
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Determine if a Unicode character is supported

05 Feb 2019, 04:45

How about this ? It is just several seconds idea.

Code: Select all

myUniCode := 0x263E 
myCharacter := Chr(myUniCode) 
myCode := Asc(myCharacter)
SetFormat, IntegerFast, H
MsgBox % myUniCode = myCode ? "O" : "X"
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Determine if a Unicode character is supported

05 Feb 2019, 04:46

Ooops, Document says "Deprecated"
I do not care about it.
I hate "New" style. It is so difficult to use.
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:21

IMEime wrote:
05 Feb 2019, 04:45
How about this ? It is just several seconds idea.

Code: Select all

myUniCode := 0x263E 
myCharacter := Chr(myUniCode) 
myCode := Asc(myCharacter)
SetFormat, IntegerFast, H
MsgBox % myUniCode = myCode ? "O" : "X"
^ It appears to work correctly on ahk 1.1 for some characters, but not others (shows O when not supported).

Came up with this, similar problem

Code: Select all

hDC := DllCall("GetDC", "Uint", 0)  ;handle to device context of entire screen
lpstr := Chr(0x1F326)  ;character for WHITE SUN BEHIND CLOUD WITH RAIN
varsetcapacity(pgi, 2)  ;array of glyph indices corresponding to the characters in lpstr
c := 2  ;length of both the length of the string pointed to by lpstr and the size (in WORDs) of pgi.  Not sure if that means "add their sizes together"
fl := 1  ;GGI_MARK_NONEXISTING_GLYPHS; marks unsupported glyphs with the hexadecimal value 0xffff 

r := DllCall("GetGlyphIndicesA" ;https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getglyphindicesa
		, "Uint", hDC
		, "Ptr" , &lpstr
		, "Uint" , c
		, "Uint" , &pgi
		, "Uint" , fl )
		
msgbox % "`nlpstr: " . lpstr . " <- if empty square, pgi should be 65535"
		. "`npgi: " . NumGet(pgi, 0, "uint") 
		. "`nresult: " . r 
I'm probably doing something wrong though.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:29

@pneumatic
Good point.
I did not have any chance to test it.
Because, The only system I have tested with was UniCode 100% support.

Can you tell me "what is the system" you are targeted ?
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:38

IMEime wrote:
05 Feb 2019, 05:29
Can you tell me "what is the system" you are targeted ?
Ahk 1.1.24.03 unicode 64 bit, windows 7 or 10.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:45

pneumatic wrote:
05 Feb 2019, 04:20

Code: Select all

Chr(0x263E) ;moon symbol
On some systems the above character will just display as a square box, which I presume means the character is not supported by the system. Whereas on other systems the character displays correctly.

Is there any way to determine if the user's system supports a character, that way if it doesn't I can swap it for some other character like the letter O or something, instead of the user having a bunch of square boxes.

Thanks!
When you say system, are you referring to the operating system, language used on the system, or to some type of application that they are using?

For OS and language, you would want to look at- A_OSVersion and A_Language. This is likely to give a decent picture about what characters are able to be displayed.

In regards to the application or what your script is displaying and writing, perhaps you want to make sure of using UTF-8 or UTF-16. Take a look at FileEncoding [, Encoding], which relates to FileReadLine, Loop Read, FileAppend, and FileOpen.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:48

I guess You have to find some other reason(s).
Because, "the system" you mentioned supports UniCode perfectly.
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:53

SOTE wrote:
05 Feb 2019, 05:45
When you say system, are you referring to the operating system, language used on the system, or to some type of application that they are using?
Just the first two, since I am adding the character to an ahk GUI. On some Windows systems it just shows an empty square.
Image

It seems there is a Windows update which contains all the extra unicode glyphs, because on a fresh install of W10 I get empty square, but after downloading all updates it displays the glyph.

@IMEime I tried your code but adding it to a Gui first, then retrieve it with GuiControlGet, same problem.
eg. with this character 0x2912 (upwards arrow to bar) it correctly retrieves 0x2912, but on screen shows as empty square.


Stackoverflow article complaining of same problem
https://stackoverflow.com/questions/34278340/easy-way-to-tell-if-unicode-character-is-supported-in-current-font wrote:Also want to point out that GetFontUnicodeRanges didn't work for me on Windows 8.1 and Windows 10. It works for simple Unicode characters, but any new ones are not included by this API. For example, L'৳'. Additionally, a simpler API to do the same, i.e. GetGlyphIndices, doesn't seem to work either.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Determine if a Unicode character is supported

05 Feb 2019, 05:55

The reason is only one.
MsgBox is OLD (or GUI)

and, MS guys/girls are lazy (of course nowdays, lots of things are free of charge, so they do not feel to work hard)
That is all

Make it into a File
Then, you can Not prove that it does not work.
just me
Posts: 9425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Determine if a Unicode character is supported

05 Feb 2019, 06:34

pneumatic wrote:On some Windows systems it just shows an empty square.
It depends on the font used to show the text. Many fonts do not support the whole range of Unicode characters.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Determine if a Unicode character is supported

05 Feb 2019, 07:22

just me wrote:
05 Feb 2019, 06:34
pneumatic wrote:On some Windows systems it just shows an empty square.
It depends on the font used to show the text. Many fonts do not support the whole range of Unicode characters.
Good point. You might want to use the fonts that come with Windows and users are most likely to already have installed, versus some type of exotic font that you downloaded from somewhere and they don't have.
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Determine if a Unicode character is supported

05 Feb 2019, 09:32

just me wrote:
05 Feb 2019, 06:34
It depends on the font used to show the text. Many fonts do not support the whole range of Unicode characters.
Yes, that's why I'm always using the default font, and I set it explicitly too just to be sure (Microsoft Sans Serif S8 Norm cDefault)
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Determine if a Unicode character is supported

05 Feb 2019, 10:30

pneumatic wrote:
05 Feb 2019, 09:32
just me wrote:
05 Feb 2019, 06:34
It depends on the font used to show the text. Many fonts do not support the whole range of Unicode characters.
Yes, that's why I'm always using the default font, and I set it explicitly too just to be sure (Microsoft Sans Serif S8 Norm cDefault)
1. Microsoft Sans Serif might not be the best font, relative to the language. Like if you were using Chinese, etc... You might want to make sure that the font is the recommended one for the language or is good for the different languages on the computers.

2. Are you doing the other recommended steps, like checking with A_OSVersion and A_Language

3. Are you using the various file encoding features of AutoHotkey? Like FileEncoding [, Encoding] or FileAppend [, Text, Filename, Encoding](if you are writing and reading data to a file).
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Determine if a Unicode character is supported

06 Feb 2019, 22:05

SOTE wrote:
05 Feb 2019, 10:30
1. Microsoft Sans Serif might not be the best font, relative to the language. Like if you were using Chinese, etc... You might want to make sure that the font is the recommended one for the language or is good for the different languages on the computers.
My GUIs are entirely in English and I've found that changing fonts is not viable as different fonts have different character widths which makes controls not align properly or become cut off. So rather than just leaving font at system default (which could be different on different systems) I explicitly set it to the default system font in which the GUI was written. That way the user should get that font on all systems (assuming they have the font, which they should given Microsoft Sans Serif appears to be a standard font on all fresh installs of at least Windows 7 and above).
SOTE wrote:
05 Feb 2019, 10:30
2. Are you doing the other recommended steps, like checking with A_OSVersion
I can't see the benefit of doing that since I already know that the problematic unicode glyphs I'm using don't come standard with a fresh install of windows anyway, and installing updates solves the issue.

I might just use IMEime's solution as it seems to work with the 2 glyphs that I happen to be using. Even if it doesn't work on all systems, it will just fall back to a different standard glyph so there's no risk involved and is overall still better than having the "missing glyph" glyph.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Determine if a Unicode character is supported

06 Feb 2019, 23:04

pneumatic wrote:
06 Feb 2019, 22:05
SOTE wrote:
05 Feb 2019, 10:30
1. Microsoft Sans Serif might not be the best font, relative to the language. Like if you were using Chinese, etc... You might want to make sure that the font is the recommended one for the language or is good for the different languages on the computers.
My GUIs are entirely in English and I've found that changing fonts is not viable as different fonts have different character widths which makes controls not align properly or become cut off. So rather than just leaving font at system default (which could be different on different systems) I explicitly set it to the default system font in which the GUI was written. That way the user should get that font on all systems (assuming they have the font, which they should given Microsoft Sans Serif appears to be a standard font on all fresh installs of at least Windows 7 and above).
SOTE wrote:
05 Feb 2019, 10:30
2. Are you doing the other recommended steps, like checking with A_OSVersion
I can't see the benefit of doing that since I already know that the problematic unicode glyphs I'm using don't come standard with a fresh install of windows anyway, and installing updates solves the issue.

I might just use IMEime's solution as it seems to work with the 2 glyphs that I happen to be using. Even if it doesn't work on all systems, it will just fall back to a different standard glyph so there's no risk involved and is overall still better than having the "missing glyph" glyph.
I suppose that if you can determine the computers that won't show the glyphs, those computers probably have some common characteristics that a script can identify. My suggestion was along the lines of you finding out what those common system features are, for those computers that won't display the glyph properly. Then your script can identify and switch to a font that those computers can display, or even download and install the correct font, if you have such administrative control over the computers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Determine if a Unicode character is supported

07 Feb 2019, 01:13

- One idea may be to draw the image of the character, using Gdip, into memory.
- Then find the extreme leftmost/topmost/rightmost/bottommost points (pixels).
- Then check if there are pixels all along the extremes, i.e. is it a rectangle.

- There is some potentially relevant code here:
AHKathon! [AHK Hackathon] 12/17 - Page 4 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=17&t=39389&p=187320#p187320
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Determine if a Unicode character is supported

07 Feb 2019, 05:36

Interesting:

Code: Select all

Gui, Font, s24 q5, Calibri
Gui, Add, Text, hwndhText, ☾
Gui, Show, w150
Calibri has no character with code 0x263E, but it is displayed.
Spoiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 177 guests