@@ -270,25 +270,21 @@ pub const Face = struct {
270
270
271
271
/// Returns true if the given glyph ID is colorized.
272
272
pub fn isColorGlyph (self : * const Face , glyph_id : u32 ) bool {
273
- // sbix table is always true for now
274
- if (self .face .hasSBIX ()) return true ;
275
-
276
- // CBDT/CBLC tables always imply colorized glyphs.
277
- // These are used by Noto.
278
- if (self .face .hasSfntTable (freetype .Tag .init ("CBDT" ))) return true ;
279
- if (self .face .hasSfntTable (freetype .Tag .init ("CBLC" ))) return true ;
280
-
281
- // Otherwise, load the glyph and see what format it is in.
273
+ // Load the glyph and see what pixel mode it renders with.
274
+ // All modes other than BGRA are non-color.
275
+ // If the glyph fails to load, just return false.
282
276
self .face .loadGlyph (glyph_id , .{
283
277
.render = true ,
284
278
.color = self .face .hasColor (),
279
+ // NO_SVG set to true because we don't currently support rendering
280
+ // SVG glyphs under FreeType, since that requires bundling another
281
+ // dependency to handle rendering the SVG.
282
+ .no_svg = true ,
285
283
}) catch return false ;
286
284
287
- // If the glyph is SVG we assume colorized
288
285
const glyph = self .face .handle .* .glyph ;
289
- if (glyph .* .format == freetype .c .FT_GLYPH_FORMAT_SVG ) return true ;
290
286
291
- return false ;
287
+ return glyph .* . bitmap . pixel_mode == freetype . c . FT_PIXEL_MODE_BGRA ;
292
288
}
293
289
294
290
/// Render a glyph using the glyph index. The rendered glyph is stored in the
@@ -321,6 +317,11 @@ pub const Face = struct {
321
317
.force_autohint = ! self .load_flags .@"force-autohint" ,
322
318
.monochrome = ! self .load_flags .monochrome ,
323
319
.no_autohint = ! self .load_flags .autohint ,
320
+
321
+ // NO_SVG set to true because we don't currently support rendering
322
+ // SVG glyphs under FreeType, since that requires bundling another
323
+ // dependency to handle rendering the SVG.
324
+ .no_svg = true ,
324
325
});
325
326
const glyph = self .face .handle .* .glyph ;
326
327
@@ -393,12 +394,13 @@ pub const Face = struct {
393
394
const original_width = bitmap_original .width ;
394
395
const original_height = bitmap_original .rows ;
395
396
var result = bitmap_original ;
396
- // TODO: We are limiting this to only emoji. We can rework this after a future
397
- // improvement (promised by Qwerasd) which implements more flexible resizing rules. For
398
- // now, this will suffice
399
- if (self . isColorGlyph ( glyph_index ) and opts .cell_width != null ) {
397
+ // TODO: We are limiting this to only color glyphs, so mainly emoji.
398
+ // We can rework this after a future improvement (promised by Qwerasd)
399
+ // which implements more flexible resizing rules.
400
+ if (atlas . format != .grayscale and opts .cell_width != null ) {
400
401
const cell_width = opts .cell_width orelse unreachable ;
401
- // If we have a cell_width, we constrain the glyph to fit within the cell
402
+ // If we have a cell_width, we constrain
403
+ // the glyph to fit within the cell(s).
402
404
result .width = metrics .cell_width * @as (u32 , cell_width );
403
405
result .rows = (result .width * original_height ) / original_width ;
404
406
} else {
@@ -743,7 +745,10 @@ pub const Face = struct {
743
745
var c : u8 = ' ' ;
744
746
while (c < 127 ) : (c += 1 ) {
745
747
if (face .getCharIndex (c )) | glyph_index | {
746
- if (face .loadGlyph (glyph_index , .{ .render = true })) {
748
+ if (face .loadGlyph (glyph_index , .{
749
+ .render = true ,
750
+ .no_svg = true ,
751
+ })) {
747
752
max = @max (
748
753
f26dot6ToF64 (face .handle .* .glyph .* .advance .x ),
749
754
max ,
@@ -776,15 +781,21 @@ pub const Face = struct {
776
781
break :heights .{
777
782
cap : {
778
783
if (face .getCharIndex ('H' )) | glyph_index | {
779
- if (face .loadGlyph (glyph_index , .{ .render = true })) {
784
+ if (face .loadGlyph (glyph_index , .{
785
+ .render = true ,
786
+ .no_svg = true ,
787
+ })) {
780
788
break :cap f26dot6ToF64 (face .handle .* .glyph .* .metrics .height );
781
789
} else | _ | {}
782
790
}
783
791
break :cap null ;
784
792
},
785
793
ex : {
786
794
if (face .getCharIndex ('x' )) | glyph_index | {
787
- if (face .loadGlyph (glyph_index , .{ .render = true })) {
795
+ if (face .loadGlyph (glyph_index , .{
796
+ .render = true ,
797
+ .no_svg = true ,
798
+ })) {
788
799
break :ex f26dot6ToF64 (face .handle .* .glyph .* .metrics .height );
789
800
} else | _ | {}
790
801
}
0 commit comments