GithubHelp home page GithubHelp logo

fetisov / ttf2mesh Goto Github PK

View Code? Open in Web Editor NEW
164.0 2.0 37.0 462 KB

Standalone library for TrueType font tessellation. Allows to load ttf-file and convert its glyphs to 2D or 3D mesh objects without rasterization.

License: MIT License

QMake 0.22% Python 0.52% C 45.55% C++ 53.70%
triangulation vector-graphics fonts opengl open-source design-tools textview tessellation bezier-curves mesh-generation

ttf2mesh's Introduction

image

The ttf2mesh crossplatform library allows to convert a glyphs of truetype font (ttf) to a mesh objects in 2d and 3d space. The library does not require any graphical context and does not use system dependent functions.

The library consists of two files written in the C language of the c99 standard: ttf2mesh.c and ttf2mesh.h. The ttf2mesh.c code implements a parsing of ttf-files and a tessellation algorithm that provides the formats conversion. The tessellation algorithm uses the Delaunay test to form an optimal set of triangles. Tessellation (triangulation) process is described in "this post" and is shown in the animation below.

image

The library has a simple doxygen-documented API for loading TTF files and converting glyphs into mesh objects. Examples of using the library are presented in examples/src directory. There are three main examples:

FILE Description
examples/src/simple.c The simplest code that shows how a user can load a font from the system directory and convert its glyph to a 2d mesh object. The converted glyph is rendering to an opengl window as a filled mesh, wireframe or the glyph contours.
image
examples/src/glyph3d.c Same as simple.c example, except that the font glyphs are converted to a 3D mesh object, which is displayed in the opengl window with animation.
image
examples/src/ttf2obj.c Console application for converting TTF font input file to a Wavefront object file (.obj). Each object in the output file includes the plane geometry of the corresponding glyph and its parameters: Unicode ID, advance and bearing.
image

To compile examples on Linux system you can use the GNU make utility: make -C examples/build-linux-make all. In the Windows operating system, you can use for compilation the Microsoft Visual Studio C++ project files that are located in the examples/build-win-msvc directory. Additionally, the examples\build-any-qmake directory contains pro files for building examples using the qtcreator IDE.

You can read information on how the library works at this link.

PayPal me or: MasterCard 5469 3800 5517 1176 wmz Z518568605100 wmr R885157851601

ttf2mesh's People

Contributors

fetisov avatar jabuwu avatar stevenctl avatar wc-duck avatar zeuno8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ttf2mesh's Issues

What's motivated you to cap the quality to 128?

What's motivated you to cap the quality to 128? I wanted to have more triangles and have hacked the quality to be a uint16_t instead of uint8_t, and also increased the limit to 256. After running ttf2obj with quality=256 everything seems to be working like expected: more triangles, etc. Are there pitfalls I should know about? For instance, should I also change the call to mesher to have deep=256 instead of 128? 🤔 :

res = mesher(mesh, 256);

Request for Kerning Support or Improved Text Positioning Documentation

Hello,

I have been using ttf2mesh for rendering text in my application, and I have encountered a challenge with the text positioning due to the lack of kerning support. Kerning is crucial for high-quality text rendering as it adjusts the space between individual character pairs to improve the visual appearance and perceived uniformity of the type.

While it is possible to render text without kerning by using glyph advances and bearings, the result is often less visually pleasing, particularly for certain character combinations that would typically have a kerning adjustment in professional typesetting.

As of now, the library does not seem to expose a way to access the kerning information from the original TrueType or OpenType font file. It would be extremely beneficial if ttf2mesh could parse and expose the kerning information from the font's "kern" table, allowing users to adjust the positioning of their text more accurately.

If this feature is not feasible, could you provide more detailed documentation or examples on how to best position text when using ttf2mesh? This would be incredibly helpful for users to get the best possible results with your library.

Thank you for your time and for the work you've put into ttf2mesh.

Best regards,
Zeun

ttf_outline_evenodd_base is calling ttf_outline_evenodd_base only for x component

The signature of ttf_outline_evenodd is

bool ttf_outline_evenodd(const ttf_outline_t *outline, const float point[2], int subglyph_order)

I noticed that ttf_outline_evenodd_base is calling ttf_outline_evenodd_base only for x component

 int res = ttf_outline_evenodd_base(outline, &outline->cont[contour].pt[test_point].x, i, &dist);
                                                                                    ^
                                                                                    ^

Shouldn't it be?

 int res = ttf_outline_evenodd_base(outline, &outline->cont[contour].pt[test_point], i, &dist);

Thanks

Is it possible to convert 2byte txt into STL ?

Hi Sergey Fetisov

Thank you for sharing this great code. I am wondering how to convert 2byte txt into STL with your code.

It seems that the code use char(one byte) to find character in TTF.

Please give me some idea to convert 2byte txt like Korean into STL in your code.

Thanks.

Sangjo

Question regarding glyph state after mesh creation

Not an issue, but rather a question:

after creating a new 2d or 3d mesh with

int ttf_glyph2mesh3d(ttf_glyph_t *glyph, ttf_mesh3d_t **output, uint8_t quality, int features, float depth)

do I need to keep the ttf_glyph_t *glyph still allocated, or can it be dropped?

Thanks!

Outline font

@fetisov Is it possible to create geometry for outline only rather than the complete font , if not do you have any plans for doing that ?

Correct advance for space?

Using hhea.advanceWidthMax * fontSize returns spacing which are too wide. What is the correct way to calculate space advance?

Error when opening file

Hello, on some .ttf format fonts, when opening a file, the error “invalid file or table checksum” occurs. For example, there is such an error with the Roboto Black 900 Italic font. What could it be?

Emoji font support

I'm wondering what's the status of emoji glyph support for ttf2mesh.

I tried with two emoji-fonts (/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf and /usr/share/fonts/truetype/emojione/emojione-android.ttf), but both seems to result into TTF_ERR_NOTAB -error.

Specific table counters:

Loading font "/usr/share/fonts/truetype/emojione/emojione-android.ttf"...
s->shead == 54 || s->sos2 == 096|| s->smaxp == 32 || s->sloca == 0 || s->scmap == 10483 || s->sglyf == 0 || s->sname == 1293 || s->shhea == 36
FONT LOAD ERR

and

Loading font "/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf"...
s->shead == 54 || s->sos2 == 096|| s->smaxp == 32 || s->sloca == 0 || s->scmap == 2849 || s->sglyf == 0 || s->sname == 1344 || s->shhea == 36
FONT LOAD ERR

Linux file for both fonts tells:


$ file /usr/share/fonts/truetype/emojione/emojione-android.ttf
/usr/share/fonts/truetype/emojione/emojione-android.ttf: TrueType Font data, 11 tables, 1st "CBDT", 18 names, Macintosh, type 1 string, Emoji OneRegular2.000;ADBO;EmojiOneVersion 2.000;PS 1.000;hotconv 1.0.96;makeotf.lib2.5.65012Em

$ file /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf
/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf: TrueType Font data, 13 tables, 1st "CBDT", 15 names, Microsoft, language 0x409, Copyright 2013 Google Inc.Noto Color EmojiRegularVersion 2.020;GOOG;noto-emoji:20200914:BETANot

These are the unicode character ranges embedded in those:

$ fc-match --format='%{charset}\n' "Noto Color Emoji"
20 23 2a 30-39 a9 ae 200d 203c 2049 20e3 2122 2139 2194-2199 21a9-21aa 231a-231b 2328 23cf 23e9-23f3 23f8-23fa 24c2 25aa-25ab 25b6 25c0 25fb-25fe 2600-2604 260e 2611 2614-2615 2618 261d 2620 2622-2623 2626 262a 262e-262f 2638-263a 2640 2642 2648-2653 265f-2660 2663 2665-2666 2668 267b 267e-267f 2692-2697 2699 269b-269c 26a0-26a1 26a7 26aa-26ab 26b0-26b1 26bd-26be 26c4-26c5 26c8 26ce-26cf 26d1 26d3-26d4 26e9-26ea 26f0-26f5 26f7-26fa 26fd 2702 2705 2708-270d 270f 2712 2714 2716 271d 2721 2728 2733-2734 2744 2747 274c 274e 2753-2755 2757 2763-2764 2795-2797 27a1 27b0 27bf 2934-2935 2b05-2b07 2b1b-2b1c 2b50 2b55 3030 303d 3297 3299 1f004 1f0cf 1f170-1f171 1f17e-1f17f 1f18e 1f191-1f19a 1f1e6-1f1ff 1f201-1f202 1f21a 1f22f 1f232-1f23a 1f250-1f251 1f300-1f321 1f324-1f393 1f396-1f397 1f399-1f39b 1f39e-1f3f0 1f3f3-1f3f5 1f3f7-1f4fd 1f4ff-1f53d 1f549-1f54e 1f550-1f567 1f56f-1f570 1f573-1f57a 1f587 1f58a-1f58d 1f590 1f595-1f596 1f5a4-1f5a5 1f5a8 1f5b1-1f5b2 1f5bc 1f5c2-1f5c4 1f5d1-1f5d3 1f5dc-1f5de 1f5e1 1f5e3 1f5e8 1f5ef 1f5f3 1f5fa-1f64f 1f680-1f6c5 1f6cb-1f6d2 1f6d5-1f6d7 1f6e0-1f6e5 1f6e9 1f6eb-1f6ec 1f6f0 1f6f3-1f6fc 1f7e0-1f7eb 1f90c-1f93a 1f93c-1f945 1f947-1f978 1f97a-1f9cb 1f9cd-1f9ff 1fa70-1fa74 1fa78-1fa7a 1fa80-1fa86 1fa90-1faa8 1fab0-1fab6 1fac0-1fac2 1fad0-1fad6 e0030-e0039 e0061-e007a e007f fe4e5-fe4ee fe82c fe82e-fe837
$ fc-match --format='%{charset}\n' "emojione android"
20-7e a0-2e9 2ec-2ee 2f3 2f7 300-34f 351-353 357-358 35a 35c-362 370-377 37a-37f 384-38a 38c 38e-3a1 3a3-525 531-556 559-55f 561-587 589-58a 5b0-5c3 5c6-5c7 5d0-5ea 5f0-5f4 606-607 609-60a 60c 615 61b 61f 621-63a 640-655 657 65a 660-670 674 679-6bf 6c6-6c8 6cb-6cc 6ce 6d0 6d5 6f0-6f9 7c0-7e7 7eb-7f5 7f8-7fa e3f e81-e82 e84 e87-e88 e8a e8d e94-e97 e99-e9f ea1-ea3 ea5 ea7 eaa-eab ead-eb9 ebb-ebd ec0-ec4 ec6 ec8-ecd ed0-ed9 edc-edd 10a0-10c5 10d0-10fc 1401-1407 1409-141b 141d-1435 1437-144a 144c-1452 1454-14bd 14c0-14ea 14ec-1507 1510-153e 1540-1550 1552-156a 1574-1585 158a-1596 15a0-15af 15de 15e1 1646-1647 166e-1676 1680-169c 1d00-1d14 1d16-1d23 1d26-1d2e 1d30-1d5b 1d5d-1d6a 1d77-1d78 1d7b 1d7d 1d85 1d9b-1dbf 1dc4-1dc9 1e00-1efb 1f00-1f15 1f18-1f1d 1f20-1f45 1f48-1f4d 1f50-1f57 1f59 1f5b 1f5d 1f5f-1f7d 1f80-1fb4 1fb6-1fc4 1fc6-1fd3 1fd6-1fdb 1fdd-1fef 1ff2-1ff4 1ff6-1ffe 2000-2064 206a-2071 2074-208e 2090-209c 20a0-20b5 20b8-20ba 20bd 20d0-20d1 20d6-20d7 20db-20dc 20e1 2100-2109 210b-2149 214b 214e 2150-2185 2189 2190-2311 2318-2319 231c-2321 2324-2328 232b-232c 2373-2375 237a 237d 2387 2394 239b-23ae 23ce-23cf 23e3 23e5 23e8 2422-2423 2460-2469 2500-269c 269e-26b8 26c0-26c3 26e2 2701-2704 2706-2709 270c-2727 2729-274b 274d 274f-2752 2756 2758-275e 2761-2794 2798-27af 27b1-27be 27c5-27c6 27e0 27e6-27eb 27f0-28ff 2906-2907 290a-290b 2940-2941 2983-2984 29ce-29d5 29eb 29fa-29fb 2a00-2a02 2a0c-2a1c 2a2f 2a6a-2a6b 2a7d-2aa0 2aae-2aba 2af9-2afa 2b00-2b1a 2b1f-2b24 2b53-2b54 2c60-2c77 2c79-2c7f 2d00-2d25 2d30-2d65 2d6f 2e18 2e1f 2e22-2e25 2e2e 4dc0-4dff a4d0-a4ff a644-a647 a64c-a64d a650-a651 a654-a657 a662-a66e a68a-a68d a694-a695 a698-a699 a708-a716 a71b-a71f a722-a72b a730-a741 a746-a74b a74e-a753 a756-a757 a764-a767 a780-a783 a789-a78e a790-a791 a7a0-a7aa a7f8-a7ff ef00-ef19 f000-f003 f400-f426 f428-f441 f6c5 fb00-fb06 fb13-fb17 fb1d-fb36 fb38-fb3c fb3e fb40-fb41 fb43-fb44 fb46-fb4f fb52-fba3 fbaa-fbad fbd3-fbdc fbde-fbdf fbe4-fbe9 fbfc-fbff fe00-fe0f fe20-fe23 fe70-fe74 fe76-fefc feff fff9-fffd 10300-1031e 10320-10323 1d300-1d356 1d538-1d539 1d53b-1d53e 1d540-1d544 1d546 1d54a-1d550 1d552-1d56b 1d5a0-1d5d3 1d7d8-1d7eb 1ee00-1ee03 1ee05-1ee1f 1ee21-1ee22 1ee24 1ee27 1ee29-1ee32 1ee34-1ee37 1ee39 1ee3b 1ee61-1ee62 1ee64 1ee67-1ee6a 1ee6c-1ee72 1ee74-1ee77 1ee79-1ee7c 1ee7e 1f030-1f093 1f0a0-1f0ae 1f0b1-1f0be 1f0c1-1f0cf 1f0d1-1f0df 1f311-1f318 1f42d-1f42e 1f431 1f435 1f600-1f623 1f625-1f62b 1f62d-1f640 1f643

Seems like imagemagick display nor gnome-font-viewer can open the fonts either, though. Maybe some new(er) .ttf -format?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.