Ttf2mesh library - convert TrueType fonts to a grid

Many people know the problem of three-dimensional graphics - the lack of lightweight cross-platform solutions in the issue of text output.


Most implementations allow you to use the selected font as a texture. The published ttf2mesh library implements another way - it converts the TrueType font vector characters to grid objects. This allows you to display text as a set of triangles.


image


This approach has both important advantages and disadvantages. The complexity of the task described below and the contemplation of the magnificent forms of font design brought a lot of pleasure in the development. I hope you enjoy it too.


Immersion in the problem


On the stackoverflow website, you may come across the question "How to draw text using only OpenGL methods?" . A detailed answer to it begins with the phrase "Why it is hard". I will give a brief translation of this answer, since it is better - it is hardly possible to describe the problem.


Common fonts (such as TrueType or OpenType) have a vector format for representing characters: their outline is defined by a set of Bezier curves.


image


β€” OpenGL, (, , ).


, CPU, β€” OpenGL- . , . :


image


, . , 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 ):


image


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 .


image


.


ttf2mesh . TTF_QUALITY_LOW, TTF_QUALITY_NORMAL TTF_QUALITY_HIGH. . .


image


"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 -. - . .


image


, , . U+00A2 β€” (), , ().


) image ) image


. β€” , . … . , . β€” "/" "C". . β€” , - "" .



, , . . . .


image


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).


( ) , . , , . .


. , .


image


( X β€” , Y β€” ).


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


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


:


image


OpenGL MSAA:


image


...



. ( , , ) . , . .


ttf2mesh , . OBJ . , SVG , , PostScript.


. β€” , .


image


The ttf2mesh library has a MIT license and is available here . I hope that it will be socially useful.


All Articles