Ttf2mesh-Bibliothek - Konvertieren Sie TrueType-Schriftarten in ein Raster

Viele Menschen kennen das Problem der dreidimensionalen Grafik - das Fehlen leichter plattformĂŒbergreifender Lösungen fĂŒr die Textausgabe.


Bei den meisten Implementierungen können Sie die ausgewÀhlte Schriftart als Textur verwenden. Die veröffentlichte ttf2mesh-Bibliothek implementiert eine andere Möglichkeit: Sie konvertiert die TrueType-Schriftvektorzeichen in Netzobjekte. Auf diese Weise können Sie Text als eine Reihe von Dreiecken anzeigen.


Bild


Dieser Ansatz hat sowohl wichtige Vor- als auch Nachteile. Die KomplexitĂ€t der nachfolgend beschriebenen Aufgabe und die Betrachtung der großartigen Formen der Schriftgestaltung haben der Entwicklung viel Freude bereitet. Ich hoffe es gefĂ€llt euch auch.


Eintauchen in das Problem


Auf der Stackoverflow-Website wird möglicherweise die Frage "Wie zeichnet man Text nur mit OpenGL-Methoden?" . Eine ausfĂŒhrliche Antwort darauf beginnt mit dem Satz "Warum es schwer ist". Ich werde diese Antwort kurz ĂŒbersetzen, da sie besser ist - es ist kaum möglich, das Problem zu beschreiben.


GĂ€ngige Schriftarten (wie TrueType oder OpenType) haben ein Vektorformat zur Darstellung von Zeichen: Ihr Umriss wird durch eine Reihe von Bezier-Kurven definiert.


Bild


— OpenGL, (, , ).


, CPU, — OpenGL- . , . :


Bild


, . , web- (CSS-sprites).


FOSDEM 2014, , :


  1. : . GPU . : ; O(N log N).
  2. . : , . Resolution independent cubic bezier drawing on GPU (Blinn/Loop)
  3. OpenVG. : API , (. OpenGL, OpenVG. Draw text OpenVG implementation)

, 3d- 2016 . .. "Distance fields" ( , . ). .


FreeType


FreeType . FTGL, API, "Distance fields" .
— libgdx.



github.com/nothings/stb/blob/master/stb_truetype.h
www.angelcode.com/products/bmfont


, . (DDS, PNG) . — .


FOSDEM 2014 .



: — ? 6000 ( Ubuntu ):


Bild


2.5 (Times New Roman , 15000 ).


, , ( )? ( , , , GPU ), .


O(N log N)
, , . , ( ) — . log(N) . , . , , .. " " , O(N2), O(N). , O(N).


, . , :


  • (, 3d-)

: ; .


. "" "", .


ttf2mesh


" ". ttf2mesh — (ttf2mesh.h ttf2mesh.c) C99. , :


ttf_list_fonts ttf_list_system_fontsttf_free_list
ttf_load_from_file ttf_load_from_memttf_free
ttf_glyph2meshttf_free_mesh

API. , ttf2mesh.h doxygen-. ttf_export_to_obj, Wavefront .obj. , . examples - ttf2obj.


:


  1. TTF- ,
  2. ( )

  3. 5.1.
    5.2. ( )
    5.3.
    5.4.

TTF-


Microsoft (OpenType specification). OpenType- (.otf) — TrueType- (.ttf), , . , , TTF, , OTF TTC.


. ( ELF ) TrueType 
 . 
 , , .


TTF- Windows 7 font list Ubuntu 18.04.4 LTS ( 500 TTF ).
TrueType — . .



— , . outline quality .


Bild


.


ttf2mesh . TTF_QUALITY_LOW, TTF_QUALITY_NORMAL TTF_QUALITY_HIGH. . .


Bild


"Q" 76, 97 175 .



, . — . . , . . :



  • .

, , U+2592 (▒). . , , Ctrl+V. 
 : , .
, ( ), EPSILON.


— .
. , . , - , . . ?


— .
Microsoft Apple. . , Microsoft Apple (. Overlapping contours) .


, ( , ?). — , . , even-odd , nonzero.


, 0.1% Windows 7. 497931 680 UNICODE:


UNICODE

Basic Latin — 14 errors
Latin-1 Supplement — 9 errors
Latin Extended-A — 2 errors
Greek and Coptic — 2 errors
Thai — 11 errors
Letterlike Symbols — 1 errors
Mathematical Operators — 1 errors
Block Elements — 1 errors
Geometric Shapes — 1 errors
Hiragana — 1 errors
Enclosed CJK Letters and Months — 1 errors
CJK Unified Ideographs Extension A — 74 errors
CJK Unified Ideographs — 555 errors
Private Use Area — 3 errors
CJK Compatibility Ideographs — 4 errors


, 36 497931 ( 0.01%). "Basic Latin", : IrisUPC, KodchiangUPC, LilyUPC, Footlight MT Light, Kunstler Script, Papyrus, Parchment Viner Hand ITC. UPC (Unity Progress Company).


, . , .



. "B", , 3 : - . "" 1 -. - . .


Bild


, , . U+00A2 — (), , ().


) Bild ) Bild


. — , . 
 . , . — "/" "C". . — , - "" .



, , . . . .


Bild


1) (y). p19, p15 .
2) . . , advancing front, . . .
3) , , 2 . , .
4) .3 , . p2.
5) . , . p5.


( Point event) , 2008 V. Domiter & B. Ćœalik "Sweep‐line algorithm for constrained Delaunay triangulation" (DOI: 10.1080/13658810701492241).


( ) , . , , . .


. , .


Bild


( X — , Y — ).


, , ( ) O(N). , O(N log N) , , . .


, , 2000 . "Tibetan Machine Uni" U+0FC7 (Tibetan Symbol Rdo Rje Rgya Gram) :


:


Bild


OpenGL MSAA:


Bild


...



. ( , , ) . , . .


ttf2mesh , . OBJ . , SVG , , PostScript.


. — , .


Bild


Die ttf2mesh-Bibliothek verfĂŒgt ĂŒber eine MIT-Lizenz und ist hier verfĂŒgbar . Ich hoffe, dass es sozial nĂŒtzlich sein wird.


All Articles