2424 * Google Author(s): Seigo Nonaka, Calder Kitagawa
2525 */
2626
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
2929
30- #include " hb-open-type.hh"
30+ #include " ../../../hb-open-type.hh"
31+ #include " ../../../hb-paint.hh"
3132
3233/*
3334 * CBLC -- Color Bitmap Location
@@ -67,7 +68,7 @@ _copy_data_to_cbdt (hb_vector_t<char> *cbdt_prime,
6768{
6869 unsigned int new_len = cbdt_prime->length + length;
6970 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);
7172 cbdt_prime->length = new_len;
7273 return true ;
7374}
@@ -80,12 +81,15 @@ struct SmallGlyphMetrics
8081 return_trace (c->check_struct (this ));
8182 }
8283
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
8485 {
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);
8993 }
9094
9195 HBUINT8 height;
@@ -307,7 +311,7 @@ struct IndexSubtable
307311 }
308312 }
309313
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
311315 {
312316 switch (u.header .indexFormat )
313317 {
@@ -468,13 +472,13 @@ struct IndexSubtableRecord
468472 if (unlikely (!c->serializer ->check_success (records->resize (records->length + 1 ))))
469473 return_trace (false );
470474
471- (* records)[records-> length - 1 ] .firstGlyphIndex = 1 ;
472- (* records)[records-> length - 1 ] .lastGlyphIndex = 0 ;
475+ records-> tail () .firstGlyphIndex = 1 ;
476+ records-> tail () .lastGlyphIndex = 0 ;
473477 bitmap_size_context->size += IndexSubtableRecord::min_size;
474478
475479 c->serializer ->push ();
476480
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)))
478482 {
479483 c->serializer ->pop_discard ();
480484 c->serializer ->revert (snap);
@@ -504,8 +508,8 @@ struct IndexSubtableRecord
504508 return num_missing;
505509 }
506510
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 ); }
509513
510514 bool get_image_data (unsigned int gid,
511515 const void *base,
@@ -833,15 +837,15 @@ struct CBDT
833837 }
834838
835839 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
837841 {
838842 const void *base;
839843 const BitmapSizeTable &strike = this ->cblc ->choose_strike (font);
840844 const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
841845 if (!subtable_record || !strike.ppemX || !strike.ppemY )
842846 return false ;
843847
844- if (subtable_record->get_extents (extents, base))
848+ if (subtable_record->get_extents (extents, base, scale ))
845849 return true ;
846850
847851 unsigned int image_offset = 0 , image_length = 0 , image_format = 0 ;
@@ -858,26 +862,29 @@ struct CBDT
858862 if (unlikely (image_length < GlyphBitmapDataFormat17::min_size))
859863 return false ;
860864 auto &glyphFormat17 = StructAtOffset<GlyphBitmapDataFormat17> (this ->cbdt , image_offset);
861- glyphFormat17.glyphMetrics .get_extents (font, extents);
865+ glyphFormat17.glyphMetrics .get_extents (font, extents, scale );
862866 break ;
863867 }
864868 case 18 : {
865869 if (unlikely (image_length < GlyphBitmapDataFormat18::min_size))
866870 return false ;
867871 auto &glyphFormat18 = StructAtOffset<GlyphBitmapDataFormat18> (this ->cbdt , image_offset);
868- glyphFormat18.glyphMetrics .get_extents (font, extents);
872+ glyphFormat18.glyphMetrics .get_extents (font, extents, scale );
869873 break ;
870874 }
871875 default : return false ; /* TODO: Support other image formats. */
872876 }
873877
874878 /* 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+ }
881888
882889 return true ;
883890 }
@@ -934,6 +941,32 @@ struct CBDT
934941
935942 bool has_data () const { return cbdt.get_length (); }
936943
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+
937970 private:
938971 hb_blob_ptr_t <CBLC> cblc;
939972 hb_blob_ptr_t <CBDT> cbdt;
@@ -994,4 +1027,4 @@ struct CBDT_accelerator_t : CBDT::accelerator_t {
9941027
9951028} /* namespace OT */
9961029
997- #endif /* HB_OT_COLOR_CBDT_TABLE_HH */
1030+ #endif /* OT_COLOR_CBDT_CBDT_HH */
0 commit comments