TrueType Font in C

I want to read ttf and draw the text with this font in the buffer. Although libraries like freetype, gd exist for this task, I want to write my own code. Can you advise me how to complete this task?

+7
source share
4 answers

If you are not one of the world's experts in fonts, typography, and writing systems, the answer is simple: NOT . TrueType / OpenType has many tables that you need for proper rendering, and even when using FreeType (which is an extremely low-level library), most people make mistakes.

If you need to perform the processing of fonts at the level of lower levels determined between platforms, then at least you should use FreeType and libotf. This will provide you access to the glyphs and outlines, which you can then make as you like. In most cases, although using your GUI system, text rendering procedures will be much simpler and less error prone.

Finally, if you insist on ignoring my advice, a good RTFS in FreeType and Microsoft online resources explaining tables in TrueType / OpenType fonts is probably the best place to start.

+8
source

I suggest you

  • Read all the TTF docs you can find

  • Find all the open source + TTF parsers that you can find in many different languages, such as Freetype (c / C ++), Batik (java) and everything you can use for Google. Also, it’s probably very useful to use the George Williams font on your trip.

  • Take apart all the programs that you put together in 1. and see how they work. See if you can make a small small sample program to do something simple, for example, reset the list of points for the outline of the letter β€œI”.

  • Work on your rasterization. Start with something very simple, for example, rasterizing the letter "l".

The problem with TTF is that there is no simple file format, and freetype handles a lot of crazy details for you. However, if you do not care about portability, and you already have a specific TTF file that you want to display, and you only care about a small simple alphabet, such as Latin or Cyrillic, you are probably all right.

You can also check the list of TTF documentation that I linked to my small project https://github.com/donbright/font_to_svg/

+3
source

Not impossible, for someone else the temptation to try. I was curious to do this because I like the DIY graphics approach when I select a piece of memory and write to it and then save it as jpg or png. I copied the bitmap font from giflib, but it is strictly 8x8 pixels.

A few links:

'http://stevehanov.ca/blog/index.php?id=143' 'https://www.google.com/search?q=ttf+parser+c&ie=utf-8&oe=utf-8' 
0
source

as R .. wrote the same time as in my comment, I would not suggest building another TTF parser myself. If you want to know this very "spannende" in computer science, I would recommend the "Art of Programming" Vol 2 from Donald E. Knuth. (this is Metafont, not TTF, but it turned out to be correct :-)

-1
source

Source: https://habr.com/ru/post/1314736/


All Articles