200 static const uchar gamma[256] = {
201 0, 5, 9, 11, 14, 16, 19, 21, 23, 25, 26, 28, 30, 32, 34, 35, 37, 38,
202 40, 41, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64,
203 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85,
204 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
205 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
206 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139,
207 140, 141, 142, 143, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 152, 153, 154, 155,
208 156, 157, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 168, 169, 170,
209 171, 172, 173, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 182, 183, 184, 185,
210 186, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 198, 199,
211 200, 201, 201, 202, 203, 204, 205, 205, 206, 207, 208, 208, 209, 210, 211, 211, 212, 213,
212 214, 214, 215, 216, 217, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226,
213 227, 228, 229, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239,
214 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252,
225 const FT_GlyphSlot glyph,
227 const FT_UInt glyph_index,
230 std::unique_ptr<GlyphBLF> g = std::make_unique<GlyphBLF>();
232 g->idx = glyph_index;
233 g->advance_x =
ft_pix(glyph->advance.x);
234 g->subpixel = subpixel;
247 FT_Outline_Get_CBox(&(glyph->outline), &bbox);
248 g->box_xmin =
ft_pix(bbox.xMin);
249 g->box_xmax =
ft_pix(bbox.xMax);
250 g->box_ymin =
ft_pix(bbox.yMin);
251 g->box_ymax =
ft_pix(bbox.yMax);
254 g->lsb_delta =
ft_pix(glyph->lsb_delta);
255 g->rsb_delta =
ft_pix(glyph->rsb_delta);
257 if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
259 g->pos[0] = glyph->bitmap_left;
260 g->pos[1] = glyph->bitmap_top;
261 g->dims[0] = int(glyph->bitmap.width);
262 g->dims[1] = int(glyph->bitmap.rows);
263 g->pitch = glyph->bitmap.pitch;
266 switch (glyph->bitmap.pixel_mode) {
267 case FT_PIXEL_MODE_LCD:
271 case FT_PIXEL_MODE_LCD_V:
276 case FT_PIXEL_MODE_BGRA:
281 const int buffer_size = g->dims[0] * g->dims[1] * g->num_channels;
284 if (
ELEM(glyph->bitmap.pixel_mode,
287 FT_PIXEL_MODE_GRAY4))
290 const char scale = char(255 / (glyph->bitmap.num_grays - 1));
291 for (
int i = 0; i < buffer_size; i++) {
292#ifdef BLF_GAMMA_CORRECT_GLYPHS
296 g->bitmap[i] = glyph->bitmap.buffer[i] *
scale;
300 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
302 for (
size_t y = 0;
y < size_t(g->dims[1]);
y++) {
303 for (
size_t x = 0;
x < size_t(g->dims[0]);
x++) {
304 size_t offs_in = (
y * size_t(glyph->bitmap.pitch)) + (
x *
size_t(g->num_channels));
305 size_t offs_out = (
y * size_t(g->dims[0]) * size_t(g->num_channels)) +
306 (
x *
size_t(g->num_channels));
307 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
308 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
309 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
313 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
315 for (
size_t y = 0;
y < size_t(g->dims[1]);
y++) {
316 for (
size_t x = 0;
x < size_t(g->dims[0]);
x++) {
317 size_t offs_in = (
y * size_t(glyph->bitmap.pitch) * size_t(g->num_channels)) +
x;
318 size_t offs_out = (
y * size_t(g->dims[0]) * size_t(g->num_channels)) +
319 (
x *
size_t(g->num_channels));
320 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in];
321 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch)];
322 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch) +
323 size_t(glyph->bitmap.pitch)];
327 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
329 for (
size_t y = 0;
y < size_t(g->dims[1]);
y++) {
330 for (
size_t x = 0;
x < size_t(g->dims[0]);
x++) {
331 size_t offs_in = (
y * size_t(g->pitch)) + (
x *
size_t(g->num_channels));
332 size_t offs_out = (
y * size_t(g->dims[0]) * size_t(g->num_channels)) +
333 (
x *
size_t(g->num_channels));
334 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
335 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
336 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
337 g->bitmap[offs_out + 3] = glyph->bitmap.buffer[offs_in + 3];
342 memcpy(g->bitmap, glyph->bitmap.buffer,
size_t(buffer_size));
348 gc->
glyphs.add(key, std::move(g));
1269 FT_UInt glyph_index,
1275 if (glyph_font != settings_font) {
1290 weight_target = std::min(weight_target + 300.0f, 900.0f);
1292 float slant_target = settings_font->
char_slant;
1294 slant_target = std::min(slant_target + 8.0f, 15.0f);
1296 float width_target = settings_font->
char_width;
1317 FT_GlyphSlot glyph =
blf_glyph_load(glyph_font, glyph_index, outline_only);
1331 if (weight != weight_target) {
1337 if (slant != slant_target) {
1340 if (width != width_target) {
1343 if (spacing != spacing_target) {
1351 FT_Outline_Translate(&glyph->outline, FT_Pos(subpixel), 0);