Skip to content

Inochi2D/hairetsu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuMem

Rendered with Hairetsu using Noto Sans JP

Hairetsu

Hairetsu (配列 /haiɾetsɯ/, sequence/arrangement in Japanese) provides cross-platform text lookup, shaping and rasterization with plans for complex text layout and bidi in the pipeline.

Hairetsu is built around reference counted types built ontop of numem; despite this the types provided by hairetsu should be usable in a GC context.

Loading Fonts

Hairetsu includes its own font reading and rendering mechanism, to load a font you first create a FontFile instance. A couple of convenience functions are provided to do this.

Font Files are the top level object of Hairetsu's font ownership hirearchy; ownership is managed internally by hairetsu, as such you should not attempt to manually destroy objects unless the documentation tells you to.

From these font files you can create Font objects, which represent the logical font within a font file container, some containers can contain multiple fonts within a single file, such as TTC containers.

FontFile myFile = FontFile.fromFile("notosans.ttf");
Font myFont = myFile.fonts[0]; // Gets the first font within the file.

writeln(myFont.type, " ", myFile.type); // Likely would print "TrueType SFNT"

Looking up glyphs

Generally you should refer to a text shaper to find glyph IDs for your target language, but Hairetsu does provide the essentials for looking up glyphs by character, however this will be without substitutions unless you write code to fetch those.

A CharMap is provided by fonts which allows looking up glyph indices from eg. the CMAP table in TTF and OTF fonts. If a font does not contain a glyph for the given character code, the .notdef glyph index will be returned instead, a convenience GLYPH_MISSING enum is provided to help you check this case.

GlyphIndex i = myFont.charMap.getGlyphIndex('');

Faces

When using a font it's often desired to be able to configure properties about the font without needing to repeatedly reload a font to do so; the FontFace facilitates this by being a type which refers back in to the parent font that created it.

This allows you to, for example, set style, sizing, hinting requirements, etc. for the glyph data you wish to fetch from the font. You can have as many font faces loaded at a time as you want.

// Create a font face, scaled to half of the base size.
FontFace myFace = myFont.createFace();
myFace.scale.x = 0.5;
myFace.scale.y = 0.5;

Acknowledgements

Language tag mapping is based on the map table created by jclark.

https://github.com/jclark/lang-ietf-opentype

Some inspiration has been taken from various renderers, such as fontdue, canvas_ity and others.
The glyph rendering algorithm is more or less an amalgamation of them all, with smaller tweaks, using signed converage masks (note; NOT SDFs) to effectively render glyphs.

About

Simple font handling and text shaping for DLang.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages