Posts

Showing posts from August, 2024

Variable Font in Emacs

Image
Variable fonts are an evolution of the OpenType font specification that enables many different variations of a typeface to be incorporated into a single file, rather than having a separate font file for every width, weight, or style. Please note that the fonts are designed for readability. These are not simple geometric transformations. Hence, the fonts may or may not support full range of variations specified by the standards. Font weight ranges from 100 to 900 for variable fonts. For static fonts, this range is between 0 to 215. You can use FcWeightToOpenTypeDouble() for converting static font weight to variable font weight. Font width ranges from 50 to 200. This is a percentage value. For example, ultra-expanded is 200% of normal width. This is same for static font. In Emacs, use :weight and :width face attributes for setting the values. cairo_font_options_set_variations() Cairo API can be used to render these variations in Emacs. Please note that the sequence of axes - wght

Faux Bold and Italic

Image
Faux bold and italic using Freetype API   Modern Outline fonts (Truetype and Opentype) have a separate file for each weight and style for better readability. They are usually suffixed as normal, Bold, Italic and Bold-Italic. This means that one cannot render these variants if the font files are missing. From the end user perspective this is annoying at times. Following APIs can be used to generate faux bold and italic variants.   Freetype API   cairo_ft_font_face_set_synthesize (font_face, CAIRO_FT_SYNTHESIZE_BOLD                      | CAIRO_FT_SYNTHESIZE_OBLIQUE);   Cairo transformation API Use x-stretch transformation for bold and skew transformation for italic. cairo_matrix_t font_matrix;   font_matrix.xx *= 1.5; // Bold - stretch font_matrix.xy = -5;     // Italic - skew   Harfbuzz API This didn't work for me.  hb_font_set_synthetic_slant(font, .5);