24
24
* Google Author(s): Seigo Nonaka, Calder Kitagawa
25
25
*/
26
26
27
- #ifndef HB_OT_COLOR_CBDT_TABLE_HH
28
- #define HB_OT_COLOR_CBDT_TABLE_HH
27
+ #ifndef OT_COLOR_CBDT_CBDT_HH
28
+ #define OT_COLOR_CBDT_CBDT_HH
29
29
30
- #include " hb-open-type.hh"
30
+ #include " ../../../hb-open-type.hh"
31
+ #include " ../../../hb-paint.hh"
31
32
32
33
/*
33
34
* CBLC -- Color Bitmap Location
@@ -67,7 +68,7 @@ _copy_data_to_cbdt (hb_vector_t<char> *cbdt_prime,
67
68
{
68
69
unsigned int new_len = cbdt_prime->length + length;
69
70
if (unlikely (!cbdt_prime->alloc (new_len))) return false ;
70
- memcpy (cbdt_prime->arrayZ + cbdt_prime->length , data, length);
71
+ hb_memcpy (cbdt_prime->arrayZ + cbdt_prime->length , data, length);
71
72
cbdt_prime->length = new_len;
72
73
return true ;
73
74
}
@@ -80,12 +81,15 @@ struct SmallGlyphMetrics
80
81
return_trace (c->check_struct (this ));
81
82
}
82
83
83
- void get_extents (hb_font_t *font, hb_glyph_extents_t *extents) const
84
+ void get_extents (hb_font_t *font, hb_glyph_extents_t *extents, bool scale ) const
84
85
{
85
- extents->x_bearing = font->em_scale_x (bearingX);
86
- extents->y_bearing = font->em_scale_y (bearingY);
87
- extents->width = font->em_scale_x (width);
88
- extents->height = font->em_scale_y (-static_cast <int >(height));
86
+ extents->x_bearing = bearingX;
87
+ extents->y_bearing = bearingY;
88
+ extents->width = width;
89
+ extents->height = -static_cast <int > (height);
90
+
91
+ if (scale)
92
+ font->scale_glyph_extents (extents);
89
93
}
90
94
91
95
HBUINT8 height;
@@ -307,7 +311,7 @@ struct IndexSubtable
307
311
}
308
312
}
309
313
310
- bool get_extents (hb_glyph_extents_t *extents HB_UNUSED) const
314
+ bool get_extents (hb_glyph_extents_t *extents HB_UNUSED, bool scale HB_UNUSED ) const
311
315
{
312
316
switch (u.header .indexFormat )
313
317
{
@@ -468,13 +472,13 @@ struct IndexSubtableRecord
468
472
if (unlikely (!c->serializer ->check_success (records->resize (records->length + 1 ))))
469
473
return_trace (false );
470
474
471
- (* records)[records-> length - 1 ] .firstGlyphIndex = 1 ;
472
- (* records)[records-> length - 1 ] .lastGlyphIndex = 0 ;
475
+ records-> tail () .firstGlyphIndex = 1 ;
476
+ records-> tail () .lastGlyphIndex = 0 ;
473
477
bitmap_size_context->size += IndexSubtableRecord::min_size;
474
478
475
479
c->serializer ->push ();
476
480
477
- if (unlikely (!add_new_subtable (c, bitmap_size_context, &((* records)[records-> length - 1 ] ), lookup, base, start)))
481
+ if (unlikely (!add_new_subtable (c, bitmap_size_context, &(records-> tail () ), lookup, base, start)))
478
482
{
479
483
c->serializer ->pop_discard ();
480
484
c->serializer ->revert (snap);
@@ -504,8 +508,8 @@ struct IndexSubtableRecord
504
508
return num_missing;
505
509
}
506
510
507
- bool get_extents (hb_glyph_extents_t *extents, const void *base) const
508
- { return (base+offsetToSubtable).get_extents (extents); }
511
+ bool get_extents (hb_glyph_extents_t *extents, const void *base, bool scale ) const
512
+ { return (base+offsetToSubtable).get_extents (extents, scale ); }
509
513
510
514
bool get_image_data (unsigned int gid,
511
515
const void *base,
@@ -833,15 +837,15 @@ struct CBDT
833
837
}
834
838
835
839
bool
836
- get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
840
+ get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents, bool scale = true ) const
837
841
{
838
842
const void *base;
839
843
const BitmapSizeTable &strike = this ->cblc ->choose_strike (font);
840
844
const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
841
845
if (!subtable_record || !strike.ppemX || !strike.ppemY )
842
846
return false ;
843
847
844
- if (subtable_record->get_extents (extents, base))
848
+ if (subtable_record->get_extents (extents, base, scale ))
845
849
return true ;
846
850
847
851
unsigned int image_offset = 0 , image_length = 0 , image_format = 0 ;
@@ -858,26 +862,29 @@ struct CBDT
858
862
if (unlikely (image_length < GlyphBitmapDataFormat17::min_size))
859
863
return false ;
860
864
auto &glyphFormat17 = StructAtOffset<GlyphBitmapDataFormat17> (this ->cbdt , image_offset);
861
- glyphFormat17.glyphMetrics .get_extents (font, extents);
865
+ glyphFormat17.glyphMetrics .get_extents (font, extents, scale );
862
866
break ;
863
867
}
864
868
case 18 : {
865
869
if (unlikely (image_length < GlyphBitmapDataFormat18::min_size))
866
870
return false ;
867
871
auto &glyphFormat18 = StructAtOffset<GlyphBitmapDataFormat18> (this ->cbdt , image_offset);
868
- glyphFormat18.glyphMetrics .get_extents (font, extents);
872
+ glyphFormat18.glyphMetrics .get_extents (font, extents, scale );
869
873
break ;
870
874
}
871
875
default : return false ; /* TODO: Support other image formats. */
872
876
}
873
877
874
878
/* Convert to font units. */
875
- float x_scale = upem / (float ) strike.ppemX ;
876
- float y_scale = upem / (float ) strike.ppemY ;
877
- extents->x_bearing = roundf (extents->x_bearing * x_scale);
878
- extents->y_bearing = roundf (extents->y_bearing * y_scale);
879
- extents->width = roundf (extents->width * x_scale);
880
- extents->height = roundf (extents->height * y_scale);
879
+ if (scale)
880
+ {
881
+ float x_scale = upem / (float ) strike.ppemX ;
882
+ float y_scale = upem / (float ) strike.ppemY ;
883
+ extents->x_bearing = roundf (extents->x_bearing * x_scale);
884
+ extents->y_bearing = roundf (extents->y_bearing * y_scale);
885
+ extents->width = roundf (extents->width * x_scale);
886
+ extents->height = roundf (extents->height * y_scale);
887
+ }
881
888
882
889
return true ;
883
890
}
@@ -934,6 +941,32 @@ struct CBDT
934
941
935
942
bool has_data () const { return cbdt.get_length (); }
936
943
944
+ bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
945
+ {
946
+ hb_glyph_extents_t extents;
947
+ hb_glyph_extents_t pixel_extents;
948
+ hb_blob_t *blob = reference_png (font, glyph);
949
+
950
+ if (unlikely (blob == hb_blob_get_empty ()))
951
+ return false ;
952
+
953
+ if (unlikely (!hb_font_get_glyph_extents (font, glyph, &extents)))
954
+ return false ;
955
+
956
+ if (unlikely (!get_extents (font, glyph, &pixel_extents, false )))
957
+ return false ;
958
+
959
+ bool ret = funcs->image (data,
960
+ blob,
961
+ pixel_extents.width , -pixel_extents.height ,
962
+ HB_PAINT_IMAGE_FORMAT_PNG,
963
+ font->slant_xy ,
964
+ &extents);
965
+
966
+ hb_blob_destroy (blob);
967
+ return ret;
968
+ }
969
+
937
970
private:
938
971
hb_blob_ptr_t <CBLC> cblc;
939
972
hb_blob_ptr_t <CBDT> cbdt;
@@ -994,4 +1027,4 @@ struct CBDT_accelerator_t : CBDT::accelerator_t {
994
1027
995
1028
} /* namespace OT */
996
1029
997
- #endif /* HB_OT_COLOR_CBDT_TABLE_HH */
1030
+ #endif /* OT_COLOR_CBDT_CBDT_HH */
0 commit comments