1 #pragma once 2 3 #include <stdbool.h> 4 #include <wchar.h> 5 6 #include <pixman.h> 7 8 /* 9 * Defines the subpixel order to use. 10 * 11 * Note that this is *ignored* if antialiasing has been disabled. 12 */ 13 enum fcft_subpixel { 14 FCFT_SUBPIXEL_DEFAULT, /* Use subpixel order from FontConfig */ 15 FCFT_SUBPIXEL_NONE, /* Disable subpixel antialiasing (use grayscale antialiasing) */ 16 FCFT_SUBPIXEL_HORIZONTAL_RGB, 17 FCFT_SUBPIXEL_HORIZONTAL_BGR, 18 FCFT_SUBPIXEL_VERTICAL_RGB, 19 FCFT_SUBPIXEL_VERTICAL_BGR, 20 }; 21 22 struct fcft_font { 23 /* font extents */ 24 int height; 25 int descent; 26 int ascent; 27 28 /* Width/height of font's widest glyph */ 29 struct { 30 int x; 31 int y; 32 } max_advance; 33 34 /* Width/height of space (0x20), if available, -1 otherwise */ 35 struct { 36 int x; 37 int y; 38 } space_advance; 39 40 struct { 41 int position; 42 int thickness; 43 } underline; 44 45 struct { 46 int position; 47 int thickness; 48 } strikeout; 49 50 bool antialias; 51 52 /* Mode used if a) antialias==true, and b) rasterize is called 53 * with FCFT_SUBPIXEL_DEFAULT */ 54 enum fcft_subpixel subpixel; 55 }; 56 57 /* Bitmask of optional capabilities */ 58 enum fcft_capabilities { 59 FCFT_CAPABILITY_GRAPHEME_SHAPING = 0x1, /* Since 2.3.0 */ 60 FCFT_CAPABILITY_TEXT_RUN_SHAPING = 0x2, /* Since 2.4.0 */ 61 }; 62 63 enum fcft_capabilities fcft_capabilities(void); 64 65 /* First entry is the main/primary font, the remaining (if any) are 66 * custom fallback fonts */ 67 struct fcft_font *fcft_from_name( 68 size_t count, const char *names[static count], const char *attributes); 69 struct fcft_font *fcft_clone(const struct fcft_font *font); 70 void fcft_destroy(struct fcft_font *font); 71 72 /* Returns a *new* font instance */ 73 struct fcft_font *fcft_size_adjust(const struct fcft_font *font, double amount) __attribute__((deprecated)); 74 75 struct fcft_glyph { 76 wchar_t wc; 77 int cols; /* wcwidth(wc) */ 78 79 pixman_image_t *pix; 80 81 int x; 82 int y; 83 int width; 84 int height; 85 86 struct { 87 int x; 88 int y; 89 } advance; 90 }; 91 92 /* Rasterize 'wc' using 'font'. Use the defined subpixel mode *if* 93 * antialiasing is enabled for this font */ 94 const struct fcft_glyph *fcft_glyph_rasterize( 95 struct fcft_font *font, wchar_t wc, enum fcft_subpixel subpixel); 96 97 struct fcft_grapheme { 98 int cols; /* wcswidth(grapheme) */ 99 100 size_t count; 101 const struct fcft_glyph **glyphs; 102 }; 103 104 struct fcft_layout_tag { 105 char tag[4]; 106 unsigned value; 107 }; 108 109 const struct fcft_grapheme *fcft_grapheme_rasterize( 110 struct fcft_font *font, 111 size_t len, const wchar_t grapheme_cluster[static len], 112 size_t tag_count, const struct fcft_layout_tag *tags, 113 enum fcft_subpixel subpixel); 114 115 struct fcft_text_run { 116 const struct fcft_glyph **glyphs; 117 int *cluster; 118 size_t count; 119 }; 120 121 struct fcft_text_run *fcft_text_run_rasterize( 122 struct fcft_font *font, size_t len, const wchar_t text[static len], 123 enum fcft_subpixel subpixel); 124 125 void fcft_text_run_destroy(struct fcft_text_run *run); 126 127 bool fcft_kerning( 128 struct fcft_font *font, wchar_t left, wchar_t right, 129 long *restrict x, long *restrict y); 130 131 wchar_t fcft_precompose(const struct fcft_font *font, 132 wchar_t base, wchar_t comb, 133 bool *base_is_from_primary, 134 bool *comb_is_from_primary, 135 bool *composed_is_from_primary); 136 137 enum fcft_scaling_filter { 138 FCFT_SCALING_FILTER_NONE, 139 FCFT_SCALING_FILTER_NEAREST, 140 FCFT_SCALING_FILTER_BILINEAR, 141 FCFT_SCALING_FILTER_CUBIC, 142 FCFT_SCALING_FILTER_LANCZOS3, 143 }; 144 145 /* Note: this function does not clear any caches - call *before* 146 * rasterizing any glyphs! */ 147 bool fcft_set_scaling_filter(enum fcft_scaling_filter filter); 148 149 /* 150 * Logging 151 * 152 * By default, fcft does not log anything at all. This can be changed 153 * by calling fcft_log_init() (typically at program start). 154 * 155 * Note that fcft_log_init() does *not* call openlog(3), even when 156 * do_syslog==true. 157 */ 158 enum fcft_log_colorize { 159 FCFT_LOG_COLORIZE_NEVER, 160 FCFT_LOG_COLORIZE_ALWAYS, 161 FCFT_LOG_COLORIZE_AUTO 162 }; 163 164 /* Which log messages to show. If you enable e.g. FCFT_LOG_CLASS_INFO, 165 * then WARNINGs and ERRORs will also be shown. */ 166 enum fcft_log_class { 167 FCFT_LOG_CLASS_NONE, 168 FCFT_LOG_CLASS_ERROR, 169 FCFT_LOG_CLASS_WARNING, 170 FCFT_LOG_CLASS_INFO, 171 FCFT_LOG_CLASS_DEBUG 172 }; 173 174 void fcft_log_init( 175 enum fcft_log_colorize colorize, bool do_syslog, 176 enum fcft_log_class log_level); 177 178 /* 179 * Emoji presentation 180 * 181 * This API allows you to configure which emoji presentation to use 182 * for emojis that have both a “text” and an “emoji” presentation, 183 * when no explicit presentation selector is present. 184 * 185 * This setting does *not* affect emojis that does not have multiple 186 * presentation forms. Nor does it affect emoji codepoints followed by 187 * an explicit presentation selector (0xfe0e or 0xfe0f). 188 * 189 * Note that this setting is always applied (for emojis with multiple 190 * presentation forms, that is) in fcft_glyph_rasterize(), since it 191 * only sees a single codepoint. 192 * 193 * Note: this function does *not* clear the glyph or grapheme caches - 194 * call *before* rasterizing any glyphs! 195 */ 196 enum fcft_emoji_presentation { 197 FCFT_EMOJI_PRESENTATION_DEFAULT, 198 FCFT_EMOJI_PRESENTATION_TEXT, 199 FCFT_EMOJI_PRESENTATION_EMOJI, 200 }; 201 202 void fcft_set_emoji_presentation( 203 struct fcft_font *font, enum fcft_emoji_presentation presentation); 204