Recent

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

winni

  • Hero Member
  • *****
  • Posts: 3197
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: 4144
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: 14201
  • Probably until I exterminate Putin.
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 »
Specialize a type, not a var.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 3197
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

  • Sr. Member
  • ****
  • Posts: 299
Re: UTF-8: Is glyph available
« Reply #5 on: October 20, 2019, 08:53:41 pm »
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

winni

  • Hero Member
  • *****
  • Posts: 3197
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

 

TinyPortal © 2005-2018