Recent

Author Topic: UTF-8: Is glyph available  (Read 380 times)

winni

  • Sr. Member
  • ****
  • Posts: 415
UTF-8: Is glyph available
« on: October 20, 2019, 03:14:26 pm »
Hi!

Searched in a lot of code amd in the net, but no reply.

Is there a function that tells me if a glyph for an UTF-8 codepoint in a Font is available?
Something like

Code: Pascal  [Select]
  1. function GlyphInFontAvailable (codepoint, fontname : string) : boolean;

Example:

Code: Pascal  [Select]
  1. if GlyphInFontAvailable('U+262E','Liberation sans') then ....

Even if someone knows a more complicated way - the answer is welcome.

Winni



howardpc

  • Hero Member
  • *****
  • Posts: 3176
Re: UTF-8: Is glyph available
« Reply #1 on: October 20, 2019, 05:31:14 pm »
I doubt that a reliable function of this sort could exist.
LowerCase("fontname") does not point to a single unambiguous entity, even sometimes on a single OS, never mind across the plethora of possible systems.
This is one reason many word processing file formats provide for embedding of specific fonts, to prevent the "wrong" font of the same name being used accidentally.
Also font foundries extend their fonts from time to time, and continually introduce new ones such a function would not know about.
I suspect you will have to trawl through the font data for the fonts you have available and discover this information, as it currently exists for the fonts you have access to, for yourself.

Thaddy

  • Hero Member
  • *****
  • Posts: 9140
Re: UTF-8: Is glyph available
« Reply #2 on: October 20, 2019, 05:43:11 pm »
Comes to mind:
user schuler's excellent AI library would be able to recognize the drawn glyph based on machine learning!
His library contains even an example how to implement such simple recognition! And it works...
So you can draw that glyph and see if it matches a given reference picture. In that case it is supported.
(This is doable! but complex)

But that is another matter. I partially agree with Howard in this case. Such a function, a simple function relies on too many factors. But note my remark: can be done.
« Last Edit: October 20, 2019, 05:54:07 pm by Thaddy »
also related to equus asinus.

lucamar

  • Hero Member
  • *****
  • Posts: 2075
Re: UTF-8: Is glyph available
« Reply #3 on: October 20, 2019, 06:39:02 pm »
I don't know whether this is useful but you could probably build your own function using classes/functions from the FreeType units of package LazUtils, like EasyLazFreeType, etc.

Drawback is that they are poorly documented if at all, though there are some examples in the Lazarus folder.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

winni

  • Sr. Member
  • ****
  • Posts: 415
Re: UTF-8: Is glyph available
« Reply #4 on: October 20, 2019, 08:01:47 pm »
Thanx markov & thaddy! I hoped you gave me another answer but that's the situation.

In windows there are some routines in the gdi*.dll, which are used by C++, Java and VBA. But that is win only.

@lucamar: Hihihi . I'm sitting here and read the freetype sources. Ugly C-style Pascal. But thanx for the hint.

sstvmaster

  • Full Member
  • ***
  • Posts: 125
Re: UTF-8: Is glyph available
« Reply #5 on: October 20, 2019, 08:53:41 pm »
Lazarus 2.0.4 x32
Lazarus 2.1.0 Trunk x32
OS Win 7 32bit

winni

  • Sr. Member
  • ****
  • Posts: 415
Re: UTF-8: Is glyph available
« Reply #6 on: October 20, 2019, 11:27:45 pm »
Yeah! Unknown treasures in the fpc sources.

Thanx

Winni