[cbdt] Move some more code around
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 5 Dec 2016 03:12:52 +0000 (19:12 -0800)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 5 Dec 2016 03:12:52 +0000 (19:12 -0800)
src/hb-ot-cbdt-table.hh
src/hb-ot-font.cc

index 2043a25..4770cf3 100644 (file)
@@ -80,9 +80,11 @@ struct SBitLineMetrics
   DEFINE_SIZE_STATIC(12);
 };
 
+
 /*
  * Index Subtables.
  */
+
 struct IndexSubtableHeader
 {
   inline bool sanitize (hb_sanitize_context_t *c) const
@@ -202,19 +204,6 @@ struct IndexSubtableRecord
   DEFINE_SIZE_STATIC(8);
 };
 
-/*
- * Glyph Bitmap Data Formats.
- */
-
-struct GlyphBitmapDataFormat17
-{
-  SmallGlyphMetrics glyphMetrics;
-  ULONG dataLen;
-  BYTE dataZ[VAR];
-
-  DEFINE_SIZE_ARRAY(9, dataZ);
-};
-
 struct IndexSubtableArray
 {
   inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
@@ -251,6 +240,8 @@ struct IndexSubtableArray
 
 struct BitmapSizeTable
 {
+  friend struct CBLC;
+
   inline bool sanitize (hb_sanitize_context_t *c, const void *base) const
   {
     TRACE_SANITIZE (this);
@@ -261,6 +252,12 @@ struct BitmapSizeTable
                  vertical.sanitize (c));
   }
 
+  const IndexSubtableRecord *find_table (hb_codepoint_t glyph, const void *base) const
+  {
+    return (base+indexSubtableArrayOffset).find_table (glyph, numberOfIndexSubtables);
+  }
+
+  protected:
   OffsetTo<IndexSubtableArray, ULONG> indexSubtableArrayOffset;
   ULONG indexTablesSize;
   ULONG numberOfIndexSubtables;
@@ -274,9 +271,25 @@ struct BitmapSizeTable
   BYTE bitDepth;
   CHAR flags;
 
+public:
   DEFINE_SIZE_STATIC(48);
 };
 
+
+/*
+ * Glyph Bitmap Data Formats.
+ */
+
+struct GlyphBitmapDataFormat17
+{
+  SmallGlyphMetrics glyphMetrics;
+  ULONG dataLen;
+  BYTE dataZ[VAR];
+
+  DEFINE_SIZE_ARRAY(9, dataZ);
+};
+
+
 /*
  * CBLC -- Color Bitmap Location Table
  */
@@ -296,18 +309,28 @@ struct CBLC
   }
 
   public:
-  const BitmapSizeTable* find_table (hb_codepoint_t glyph) const
+  const IndexSubtableRecord *find_table (hb_codepoint_t glyph,
+                                        unsigned int *x_ppem, unsigned int *y_ppem) const
   {
-    // TODO: Make it possible to select strike.
+    /* TODO: Make it possible to select strike. */
+
+    const BitmapSizeTable *sizeTable = &Null(BitmapSizeTable);
     unsigned int count = sizeTables.len;
-    for (uint32_t i = 0; i < count; ++i) {
+    for (uint32_t i = 0; i < count; ++i)
+    {
       unsigned int startGlyphIndex = sizeTables.array[i].startGlyphIndex;
       unsigned int endGlyphIndex = sizeTables.array[i].endGlyphIndex;
-      if (startGlyphIndex <= glyph && glyph <= endGlyphIndex) {
-        return &sizeTables[i];
+      if (startGlyphIndex <= glyph && glyph <= endGlyphIndex)
+      {
+       sizeTable = &sizeTables[i];
+       break;
       }
     }
-    return NULL;
+
+    *x_ppem = sizeTable->ppemX;
+    *y_ppem = sizeTable->ppemY;
+
+    return sizeTable->find_table (glyph, this);
   }
 
   protected:
index 1a2d382..1b6cea4 100644 (file)
@@ -244,17 +244,13 @@ struct hb_ot_face_cbdt_accelerator_t
 
   inline bool get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
   {
+    unsigned int x_ppem = upem, y_ppem = upem; /* TODO Use font ppem if available. */
+
     if (cblc == NULL) {
       return false;  // Not a color bitmap font.
     }
 
-    const OT::BitmapSizeTable* sizeTable = this->cblc->find_table(glyph);
-    if (sizeTable == NULL) {
-      return false;
-    }
-
-    const OT::IndexSubtableArray& subtables = this->cblc + sizeTable->indexSubtableArrayOffset;
-    const OT::IndexSubtableRecord *subtable_record = subtables.find_table (glyph, sizeTable->numberOfIndexSubtables);
+    const OT::IndexSubtableRecord *subtable_record = this->cblc->find_table(glyph, &x_ppem, &y_ppem);
     if (subtable_record == NULL) {
       return false;
     }
@@ -286,10 +282,10 @@ struct hb_ot_face_cbdt_accelerator_t
     }
 
     /* Convert to the font units. */
-    extents->x_bearing *= upem / (float)(sizeTable->ppemX);
-    extents->y_bearing *= upem / (float)(sizeTable->ppemY);
-    extents->width *= upem / (float)(sizeTable->ppemX);
-    extents->height *= upem / (float)(sizeTable->ppemY);
+    extents->x_bearing *= upem / (float) x_ppem;
+    extents->y_bearing *= upem / (float) y_ppem;
+    extents->width *= upem / (float) x_ppem;
+    extents->height *= upem / (float) y_ppem;
 
     return true;
   }