[HarfBuzz] harfbuzz: Branch 'master' - 39 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon Oct 29 01:33:21 UTC 2018
docs/harfbuzz-sections.txt | 4
src/Makefile.am | 9 -
src/dump-emoji.cc | 321 ------------------------------------------
src/hb-open-type.hh | 8 -
src/hb-ot-color-cbdt-table.hh | 74 ---------
src/hb-ot-color-sbix-table.hh | 222 ++++++++++++++++++-----------
src/hb-ot-color-svg-table.hh | 33 +---
src/hb-ot-color.cc | 72 +--------
src/hb-ot-color.h | 21 ++
src/hb-ot-font.cc | 9 -
src/hb-ot-layout-common.hh | 4
test/api/test-ot-color.c | 45 +++--
12 files changed, 238 insertions(+), 584 deletions(-)
New commits:
commit a8c9facf7a73cca39e3fed1f637db4858e64414a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 18:32:37 2018 -0700
[svg] Cosmetic
diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh
index 35a36477..55629769 100644
--- a/src/hb-ot-color-svg-table.hh
+++ b/src/hb-ot-color-svg-table.hh
@@ -45,8 +45,8 @@ struct SVGDocumentIndexEntry
inline hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
{
- if (svgDocLength == 0) return hb_blob_get_empty ();
- return hb_blob_create_sub_blob (svg_blob, (unsigned int) svgDoc + index_offset,
+ return hb_blob_create_sub_blob (svg_blob,
+ index_offset + (unsigned int) svgDoc,
svgDocLength);
}
commit 9c1460e5685448ad4eac8faff9f05e456f87ed28
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 18:29:14 2018 -0700
[svg] Use SortedArrayOf.bsearch
diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh
index 3e6480cc..35a36477 100644
--- a/src/hb-ot-color-svg-table.hh
+++ b/src/hb-ot-color-svg-table.hh
@@ -43,13 +43,6 @@ struct SVGDocumentIndexEntry
inline int cmp (hb_codepoint_t g) const
{ return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
- static int cmp (const void *pa, const void *pb)
- {
- const hb_codepoint_t *a = (const hb_codepoint_t *) pa;
- const SVGDocumentIndexEntry *b = (const SVGDocumentIndexEntry *) pb;
- return b->cmp (*a);
- }
-
inline hb_blob_t *reference_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
{
if (svgDocLength == 0) return hb_blob_get_empty ();
@@ -113,13 +106,8 @@ struct SVG
inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const
{
- const SVGDocumentIndexEntry *rec = (SVGDocumentIndexEntry *)
- bsearch (&glyph_id,
- &(this+svgDocEntries).arrayZ,
- (this+svgDocEntries).len,
- sizeof (SVGDocumentIndexEntry),
- SVGDocumentIndexEntry::cmp);
- return likely (rec) ? *rec : Null(SVGDocumentIndexEntry);
+ const SortedArrayOf<SVGDocumentIndexEntry> docs = this+svgDocEntries;
+ return docs[docs.bsearch (glyph_id)];
}
inline bool sanitize (hb_sanitize_context_t *c) const
@@ -131,7 +119,7 @@ struct SVG
protected:
HBUINT16 version; /* Table version (starting at 0). */
- LOffsetTo<ArrayOf<SVGDocumentIndexEntry> >
+ LOffsetTo<SortedArrayOf<SVGDocumentIndexEntry> >
svgDocEntries; /* Offset (relative to the start of the SVG table) to the
* SVG Documents Index. Must be non-zero. */
/* Array of SVG Document Index Entries. */
commit 18dd6363a5021cfd770b431a6320386f94447674
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 18:26:49 2018 -0700
[svg] Minor
diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh
index 5238ad45..3e6480cc 100644
--- a/src/hb-ot-color-svg-table.hh
+++ b/src/hb-ot-color-svg-table.hh
@@ -87,7 +87,7 @@ struct SVG
{
svg_blob = hb_sanitize_context_t().reference_table<SVG> (face);
svg_len = hb_blob_get_length (svg_blob);
- svg = svg_blob->as<SVG> ();
+ table = svg_blob->as<SVG> ();
}
inline void fini (void)
@@ -97,29 +97,28 @@ struct SVG
inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const
{
- if (unlikely (svg_len == 0))
+ if (unlikely (!svg_len))
return hb_blob_get_empty ();
- return svg->get_glyph_entry (glyph_id).reference_blob (svg_blob, svg->svgDocEntries);
+ return table->get_glyph_entry (glyph_id).reference_blob (svg_blob, table->svgDocEntries);
}
- inline bool has_data () const
- { return svg_len; }
+ inline bool has_data () const { return svg_len; }
private:
hb_blob_t *svg_blob;
- const SVG *svg;
+ const SVG *table;
unsigned int svg_len;
};
inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const
{
- const SVGDocumentIndexEntry *rec;
- rec = (SVGDocumentIndexEntry *) bsearch (&glyph_id,
- &(this+svgDocEntries).arrayZ,
- (this+svgDocEntries).len,
- sizeof (SVGDocumentIndexEntry),
- SVGDocumentIndexEntry::cmp);
+ const SVGDocumentIndexEntry *rec = (SVGDocumentIndexEntry *)
+ bsearch (&glyph_id,
+ &(this+svgDocEntries).arrayZ,
+ (this+svgDocEntries).len,
+ sizeof (SVGDocumentIndexEntry),
+ SVGDocumentIndexEntry::cmp);
return likely (rec) ? *rec : Null(SVGDocumentIndexEntry);
}
commit 4876c938a20af356988d566ba95472d3bcbb133d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 18:01:25 2018 -0700
[sbix] Comment
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 9155db64..40680ca2 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -230,8 +230,8 @@ struct sbix
hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
- /* Following code is safe to call even without data, but faster to
- * short-circuit. */
+ /* Following code is safe to call even without data (XXX currently
+ * isn't. See has_data()), but faster to short-circuit. */
if (!has_data ())
return false;
commit 519fca101466283ca5c993dec2ec2c6891d8add5
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 16:32:20 2018 -0700
[color] Minor
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index c89dc9e5..b38e67c4 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -320,7 +320,7 @@ hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
if (_get_sbix (font->face).has_data ())
blob = _get_sbix (font->face).reference_png (font, glyph, nullptr, nullptr);
- if (hb_blob_get_length (blob) == 0 && _get_cbdt (font->face).has_data ())
+ if (!blob->length && _get_cbdt (font->face).has_data ())
blob = _get_cbdt (font->face).reference_png (glyph, font->x_ppem, font->y_ppem);
return blob;
commit e8ff27c2082ffcf3bd213e7a77d823dc1809857e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 16:29:09 2018 -0700
Minor
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index 207f36b6..6e545a6d 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -539,8 +539,10 @@ template <typename Type> struct LArrayOf : ArrayOf<Type, HBUINT32> {};
typedef ArrayOf<HBUINT8, HBUINT8> PString;
/* Array of Offset's */
-template <typename Type, typename OffsetType=HBUINT16>
-struct OffsetArrayOf : ArrayOf<OffsetTo<Type, OffsetType> > {};
+template <typename Type>
+struct OffsetArrayOf : ArrayOf<OffsetTo<Type, HBUINT16> > {};
+template <typename Type>
+struct LOffsetArrayOf : ArrayOf<OffsetTo<Type, HBUINT32> > {};
template <typename Type>
struct LOffsetLArrayOf : ArrayOf<OffsetTo<Type, HBUINT32>, HBUINT32> {};
diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh
index 7bca2cae..11297a57 100644
--- a/src/hb-ot-layout-common.hh
+++ b/src/hb-ot-layout-common.hh
@@ -1605,7 +1605,7 @@ struct VariationStore
protected:
HBUINT16 format;
LOffsetTo<VarRegionList> regions;
- OffsetArrayOf<VarData, HBUINT32> dataSets;
+ LOffsetArrayOf<VarData> dataSets;
public:
DEFINE_SIZE_ARRAY (8, dataSets);
};
@@ -1687,7 +1687,7 @@ struct ConditionSet
}
protected:
- OffsetArrayOf<Condition, HBUINT32> conditions;
+ LOffsetArrayOf<Condition> conditions;
public:
DEFINE_SIZE_ARRAY (2, conditions);
};
commit 65621723815138150e8a6354413ed14d53cf35b5
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 16:27:18 2018 -0700
[sbix] Use LOffsetLArrayOf<>
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index 8d17f3ed..207f36b6 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -541,6 +541,8 @@ typedef ArrayOf<HBUINT8, HBUINT8> PString;
/* Array of Offset's */
template <typename Type, typename OffsetType=HBUINT16>
struct OffsetArrayOf : ArrayOf<OffsetTo<Type, OffsetType> > {};
+template <typename Type>
+struct LOffsetLArrayOf : ArrayOf<OffsetTo<Type, HBUINT32>, HBUINT32> {};
/* Array of offsets relative to the beginning of the array itself. */
template <typename Type>
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 13ed0783..9155db64 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -271,7 +271,7 @@ struct sbix
HBUINT16 version; /* Table version number — set to 1 */
HBUINT16 flags; /* Bit 0: Set to 1. Bit 1: Draw outlines.
* Bits 2 to 15: reserved (set to 0). */
- LArrayOf<LOffsetTo<SBIXStrike> >
+ LOffsetLArrayOf<SBIXStrike>
strikes; /* Offsets from the beginning of the 'sbix'
* table to data for each individual bitmap strike. */
public:
commit a3ddd8067f266e49d9451c53a0fd40aff8551af7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 16:26:03 2018 -0700
[sbix] Add get_strike
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index b82a8847..13ed0783 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -132,6 +132,8 @@ struct sbix
inline bool has_data (void) const { return version; }
+ inline const SBIXStrike &get_strike (unsigned int i) const { return this+strikes[i]; }
+
struct accelerator_t
{
inline void init (hb_face_t *face)
@@ -185,11 +187,11 @@ struct sbix
requested_ppem = 1<<30; /* Choose largest strike. */
/* TODO Add DPI sensitivity as well? */
unsigned int best_i = 0;
- unsigned int best_ppem = (table+table->strikes[0]).ppem;
+ unsigned int best_ppem = table->get_strike (0).ppem;
for (unsigned int i = 1; i < table->strikes.len; i++)
{
- unsigned int ppem = (table+table->strikes[i]).ppem;
+ unsigned int ppem = (table->get_strike (i)).ppem;
if ((requested_ppem <= ppem && ppem < best_ppem) ||
(requested_ppem > best_ppem && ppem > best_ppem))
{
@@ -198,7 +200,7 @@ struct sbix
}
}
- return table+table->strikes[best_i];
+ return table->get_strike (best_i);
}
struct PNGHeader
commit 95524ed9bccdcd0d6a46c5dcc372e96a0c34b5f0
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:58:48 2018 -0700
[sbix] Remove sbix_len
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index bde66b77..b82a8847 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -130,18 +130,13 @@ struct sbix
{
static const hb_tag_t tableTag = HB_OT_TAG_sbix;
- inline bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
- return_trace (likely (c->check_struct (this) && strikes.sanitize (c, this)));
- }
+ inline bool has_data (void) const { return version; }
struct accelerator_t
{
inline void init (hb_face_t *face)
{
sbix_blob = hb_sanitize_context_t().reference_table<sbix> (face);
- sbix_len = hb_blob_get_length (sbix_blob);
table = sbix_blob->as<sbix> ();
num_glyphs = face->get_num_glyphs ();
}
@@ -151,7 +146,13 @@ struct sbix
hb_blob_destroy (sbix_blob);
}
- inline bool has_data () const { return sbix_len; }
+ inline bool has_data () const
+ {
+ /* XXX Fix somehow and remove next line.
+ * https://github.com/harfbuzz/harfbuzz/issues/1146 */
+ if (!num_glyphs) return false;
+ return table->has_data ();
+ }
inline bool get_extents (hb_font_t *font,
hb_codepoint_t glyph,
@@ -227,6 +228,11 @@ struct sbix
hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
+ /* Following code is safe to call even without data, but faster to
+ * short-circuit. */
+ if (!has_data ())
+ return false;
+
int x_offset = 0, y_offset = 0;
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset);
@@ -248,10 +254,17 @@ struct sbix
hb_blob_t *sbix_blob;
const sbix *table;
- unsigned int sbix_len;
unsigned int num_glyphs;
};
+ inline bool sanitize (hb_sanitize_context_t *c) const
+ {
+ TRACE_SANITIZE (this);
+ return_trace (likely (c->check_struct (this) &&
+ version >= 1 &&
+ strikes.sanitize (c, this)));
+ }
+
protected:
HBUINT16 version; /* Table version number — set to 1 */
HBUINT16 flags; /* Bit 0: Set to 1. Bit 1: Draw outlines.
commit 69e9846452f829f82f6866a683845167b3d3d6e5
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:53:11 2018 -0700
[sbix] Fix get_glyph_blob() on Null object
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 75d1cecc..bde66b77 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -76,6 +76,8 @@ struct SBIXStrike
int *y_offset,
unsigned int num_glyphs) const
{
+ if (unlikely (!ppem)) return hb_blob_get_empty (); /* To get Null() object out of the way. */
+
unsigned int retry_count = 8;
unsigned int sbix_len = sbix_blob->length;
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
@@ -83,7 +85,7 @@ struct SBIXStrike
retry:
if (unlikely (glyph_id >= num_glyphs ||
- imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
+ imageOffsetsZ[glyph_id + 1] <= imageOffsetsZ[glyph_id] ||
imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size ||
(unsigned int) imageOffsetsZ[glyph_id + 1] > sbix_len - strike_offset))
return hb_blob_get_empty ();
@@ -225,9 +227,6 @@ struct sbix
hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
- if (likely (sbix_len == 0))
- return false;
-
int x_offset = 0, y_offset = 0;
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset);
commit 4e0ee2af091634198c4b9b17036d9391a4e6b084
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:44:40 2018 -0700
[sbix] Simplify ppem access
If struct members are simple and needed publicly, we make them public.
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index e37c29ad..75d1cecc 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -69,9 +69,6 @@ struct SBIXStrike
imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1));
}
- inline unsigned int get_ppem () const { return ppem; }
- inline unsigned int get_resolution () const { return resolution; }
-
inline hb_blob_t *get_glyph_blob (unsigned int glyph_id,
hb_blob_t *sbix_blob,
hb_tag_t file_type,
@@ -115,10 +112,11 @@ struct SBIXStrike
return hb_blob_create_sub_blob (sbix_blob, glyph_offset, glyph_length);
}
- protected:
+ public:
HBUINT16 ppem; /* The PPEM size for which this strike was designed. */
HBUINT16 resolution; /* The device pixel density (in PPI) for which this
* strike was designed. (E.g., 96 PPI, 192 PPI.) */
+ protected:
UnsizedArrayOf<LOffsetTo<SBIXGlyph> >
imageOffsetsZ; /* Offset from the beginning of the strike data header
* to bitmap data for an individual glyph ID. */
@@ -184,11 +182,11 @@ struct sbix
requested_ppem = 1<<30; /* Choose largest strike. */
/* TODO Add DPI sensitivity as well? */
unsigned int best_i = 0;
- unsigned int best_ppem = (table+table->strikes[0]).get_ppem ();
+ unsigned int best_ppem = (table+table->strikes[0]).ppem;
for (unsigned int i = 1; i < table->strikes.len; i++)
{
- unsigned int ppem = (table+table->strikes[i]).get_ppem ();
+ unsigned int ppem = (table+table->strikes[i]).ppem;
if ((requested_ppem <= ppem && ppem < best_ppem) ||
(requested_ppem > best_ppem && ppem > best_ppem))
{
commit 6ac9a4eaa3a47c9b9f2c7aa123255e82ccc53551
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:43:54 2018 -0700
[sbix] Simplify glyph_length calc
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 51e4a166..e37c29ad 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -69,16 +69,8 @@ struct SBIXStrike
imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1));
}
- inline unsigned int get_ppem () const
- { return ppem; }
-
- inline unsigned int get_resolution () const
- { return resolution; }
-
- inline unsigned int calculate_blob_size (unsigned int glyph_id) const
- {
- return imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] - SBIXGlyph::min_size;
- }
+ inline unsigned int get_ppem () const { return ppem; }
+ inline unsigned int get_resolution () const { return resolution; }
inline hb_blob_t *get_glyph_blob (unsigned int glyph_id,
hb_blob_t *sbix_blob,
@@ -100,14 +92,13 @@ struct SBIXStrike
return hb_blob_get_empty ();
unsigned int glyph_offset = strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size;
- if (glyph_offset > sbix_len)
- return hb_blob_get_empty ();
+ unsigned int glyph_length = imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] - SBIXGlyph::min_size;
const SBIXGlyph *glyph = &(this+imageOffsetsZ[glyph_id]);
if (glyph->graphicType == HB_TAG ('d','u','p','e'))
{
- if (calculate_blob_size (glyph_id) >= 2)
+ if (glyph_length >= 2)
{
glyph_id = *((HBUINT16 *) &glyph->data);
if (retry_count--)
@@ -118,13 +109,10 @@ struct SBIXStrike
if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
- unsigned int blob_size = calculate_blob_size (glyph_id);
- if (unlikely (blob_size == 0))
- return hb_blob_get_empty ();
if (x_offset) *x_offset = glyph->xOffset;
if (y_offset) *y_offset = glyph->yOffset;
- return hb_blob_create_sub_blob (sbix_blob, glyph_offset, blob_size);
+ return hb_blob_create_sub_blob (sbix_blob, glyph_offset, glyph_length);
}
protected:
commit 0730d623854dc17ce0c3f1f2755a90b656c8e52c
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:38:42 2018 -0700
[sbix] Check glyph data end is in range
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index d3b73779..51e4a166 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -90,11 +90,13 @@ struct SBIXStrike
unsigned int retry_count = 8;
unsigned int sbix_len = sbix_blob->length;
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
+ assert (strike_offset < sbix_len);
retry:
if (unlikely (glyph_id >= num_glyphs ||
imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
- imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size))
+ imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size ||
+ (unsigned int) imageOffsetsZ[glyph_id + 1] > sbix_len - strike_offset))
return hb_blob_get_empty ();
unsigned int glyph_offset = strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size;
commit b76dc03108d04975335dbf3580f8d02321cb5d25
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:36:17 2018 -0700
[sbix] Reduce code
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 49320785..d3b73779 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -97,7 +97,8 @@ struct SBIXStrike
imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size))
return hb_blob_get_empty ();
- if (strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size > sbix_len)
+ unsigned int glyph_offset = strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size;
+ if (glyph_offset > sbix_len)
return hb_blob_get_empty ();
const SBIXGlyph *glyph = &(this+imageOffsetsZ[glyph_id]);
@@ -121,9 +122,7 @@ struct SBIXStrike
if (x_offset) *x_offset = glyph->xOffset;
if (y_offset) *y_offset = glyph->yOffset;
- unsigned int offset = strike_offset + SBIXGlyph::min_size;
- offset += imageOffsetsZ[glyph_id];
- return hb_blob_create_sub_blob (sbix_blob, offset, blob_size);
+ return hb_blob_create_sub_blob (sbix_blob, glyph_offset, blob_size);
}
protected:
commit 50fb02a219dbf168d300c4ccf9f29aee38a78e6c
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:33:12 2018 -0700
[sbix] Check glyph id before looking into unsafe array
That 'Z' at end of imageOffsetsZ is a reminder that you should check...
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 9a124a6e..49320785 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -92,8 +92,9 @@ struct SBIXStrike
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
retry:
- if (imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
- imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size)
+ if (unlikely (glyph_id >= num_glyphs ||
+ imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
+ imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size))
return hb_blob_get_empty ();
if (strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size > sbix_len)
@@ -106,7 +107,7 @@ struct SBIXStrike
if (calculate_blob_size (glyph_id) >= 2)
{
glyph_id = *((HBUINT16 *) &glyph->data);
- if (glyph_id < num_glyphs && retry_count--)
+ if (retry_count--)
goto retry;
}
return hb_blob_get_empty ();
commit a8cb9c73da29afa89b0253b6475ff220613e100a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:30:57 2018 -0700
[sbix] Simplify 'dupe' handling logic
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 91a9cb71..9a124a6e 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -87,8 +87,11 @@ struct SBIXStrike
int *y_offset,
unsigned int num_glyphs) const
{
+ unsigned int retry_count = 8;
unsigned int sbix_len = sbix_blob->length;
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
+
+ retry:
if (imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size)
return hb_blob_get_empty ();
@@ -97,20 +100,18 @@ struct SBIXStrike
return hb_blob_get_empty ();
const SBIXGlyph *glyph = &(this+imageOffsetsZ[glyph_id]);
- if (unlikely (glyph->graphicType == HB_TAG ('d','u','p','e') &&
- calculate_blob_size (glyph_id) >= 2))
+
+ if (glyph->graphicType == HB_TAG ('d','u','p','e'))
{
- unsigned int new_glyph_id = *((HBUINT16 *) &glyph->data);
- if (new_glyph_id < num_glyphs)
+ if (calculate_blob_size (glyph_id) >= 2)
{
- glyph = &(this+imageOffsetsZ[new_glyph_id]);
- glyph_id = new_glyph_id;
- if (strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size > sbix_len)
- return hb_blob_get_empty ();
+ glyph_id = *((HBUINT16 *) &glyph->data);
+ if (glyph_id < num_glyphs && retry_count--)
+ goto retry;
}
- else
- return hb_blob_get_empty ();
+ return hb_blob_get_empty ();
}
+
if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
unsigned int blob_size = calculate_blob_size (glyph_id);
commit d7eb534e59064633732959c3771b6557cc97005e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:27:04 2018 -0700
[sbix] Check offsets before proceeding
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 79f79a5a..91a9cb71 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -89,7 +89,8 @@ struct SBIXStrike
{
unsigned int sbix_len = sbix_blob->length;
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
- if (imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] == 0)
+ if (imageOffsetsZ[glyph_id + 1] < imageOffsetsZ[glyph_id] ||
+ imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size)
return hb_blob_get_empty ();
if (strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size > sbix_len)
commit c8380bd3e4a2e51dfbe2e44e19738445be16ac75
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:20:33 2018 -0700
[color] Remove more dump-emoji cruft
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index f744e1a6..467159c7 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -451,59 +451,6 @@ struct CBDT
return true;
}
- inline void dump (void (*callback) (const uint8_t* data, unsigned int length,
- unsigned int group, unsigned int gid)) const
- {
- if (!cblc)
- return; // Not a color bitmap font.
-
- for (unsigned int i = 0; i < cblc->sizeTables.len; ++i)
- {
- const BitmapSizeTable &sizeTable = cblc->sizeTables[i];
- const IndexSubtableArray &subtable_array = cblc+sizeTable.indexSubtableArrayOffset;
- for (unsigned int j = 0; j < sizeTable.numberOfIndexSubtables; ++j)
- {
- const IndexSubtableRecord &subtable_record = subtable_array.indexSubtablesZ[j];
- for (unsigned int gid = subtable_record.firstGlyphIndex;
- gid <= subtable_record.lastGlyphIndex; ++gid)
- {
- unsigned int image_offset = 0, image_length = 0, image_format = 0;
-
- if (!subtable_record.get_image_data (gid, &subtable_array,
- &image_offset, &image_length, &image_format))
- continue;
-
- switch (image_format)
- {
- case 17: {
- const GlyphBitmapDataFormat17& glyphFormat17 =
- StructAtOffset<GlyphBitmapDataFormat17> (this->cbdt, image_offset);
- callback ((const uint8_t *) &glyphFormat17.data.arrayZ,
- glyphFormat17.data.len, i, gid);
- }
- break;
- case 18: {
- const GlyphBitmapDataFormat18& glyphFormat18 =
- StructAtOffset<GlyphBitmapDataFormat18> (this->cbdt, image_offset);
- callback ((const uint8_t *) &glyphFormat18.data.arrayZ,
- glyphFormat18.data.len, i, gid);
- }
- break;
- case 19: {
- const GlyphBitmapDataFormat19& glyphFormat19 =
- StructAtOffset<GlyphBitmapDataFormat19> (this->cbdt, image_offset);
- callback ((const uint8_t *) &glyphFormat19.data.arrayZ,
- glyphFormat19.data.len, i, gid);
- }
- break;
- default:
- continue;
- }
- }
- }
- }
- }
-
inline hb_blob_t* reference_png (hb_codepoint_t glyph_id,
unsigned int x_ppem,
unsigned int y_ppem) const
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 2f33bf6c..79f79a5a 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -161,19 +161,6 @@ struct sbix
inline bool has_data () const { return sbix_len; }
- /* only to support dump-emoji, don't use it anywhere else */
- inline unsigned int *get_available_ppems (unsigned int *length)
- {
- if (unlikely (table->strikes.len == 0))
- return nullptr;
- *length = table->strikes.len;
- unsigned int *result;
- result = (unsigned int *) malloc (sizeof (unsigned int) * table->strikes.len);
- for (unsigned int i = 0; i < table->strikes.len; i++)
- result[i] = (table+table->strikes[i]).get_ppem ();
- return result;
- }
-
inline bool get_extents (hb_font_t *font,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
commit 68f2c832c894d71715073d4748ad321a9d271a0e
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:18:55 2018 -0700
Remove dump-emoji
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d614ee0..0b9ae9dc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -412,15 +412,6 @@ dump_use_data_SOURCES = dump-use-data.cc hb-ot-shape-complex-use-table.cc
dump_use_data_CPPFLAGS = $(HBCFLAGS)
dump_use_data_LDADD = libharfbuzz.la $(HBLIBS)
-if HAVE_FREETYPE
-if HAVE_CAIRO_FT
-check_PROGRAMS += dump-emoji
-dump_emoji_SOURCES = dump-emoji.cc
-dump_emoji_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) $(CAIRO_FT_CFLAGS)
-dump_emoji_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) $(CAIRO_LIBS) $(CAIRO_FT_LIBS)
-endif # HAVE_CAIRO_FT
-endif # HAVE_FREETYPE
-
check_PROGRAMS += test-ot-tag test-unicode-ranges
TESTS += test-ot-tag test-unicode-ranges
diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc
deleted file mode 100644
index e3cabc73..00000000
--- a/src/dump-emoji.cc
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright © 2018 Ebrahim Byagowi
- * Copyright © 2018 Khaled Hosny
- *
- * This is part of HarfBuzz, a text shaping library.
- *
- * Permission is hereby granted, without written agreement and without
- * license or royalty fees, to use, copy, modify, and distribute this
- * software and its documentation for any purpose, provided that the
- * above copyright notice and the following two paragraphs appear in
- * all copies of this software.
- *
- * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
- * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- */
-
-#include "hb-static.cc"
-#include "hb-ot-color-cbdt-table.hh"
-#include "hb-ot-color-colr-table.hh"
-#include "hb-ot-color-cpal-table.hh"
-#include "hb-ot-color-sbix-table.hh"
-#include "hb-ot-color-svg-table.hh"
-
-#include "hb-ft.h"
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-#include <cairo.h>
-#include <cairo-ft.h>
-#include <cairo-svg.h>
-
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-
-static void
-cbdt_callback (const uint8_t* data, unsigned int length,
- unsigned int group, unsigned int gid)
-{
- char output_path[255];
- sprintf (output_path, "out/cbdt-%d-%d.png", group, gid);
- FILE *f = fopen (output_path, "wb");
- fwrite (data, 1, length, f);
- fclose (f);
-}
-
-static void
-sbix_dump (hb_face_t *face)
-{
- OT::sbix::accelerator_t sbix;
- sbix.init (face);
- unsigned int length = 0;
- unsigned int *available_ppems = sbix.get_available_ppems (&length);
- unsigned int num_glyphs = face->num_glyphs;
- for (unsigned int group = 0; group < length; group++)
- for (unsigned int glyph_id = 0; glyph_id < num_glyphs; glyph_id++)
- {
- hb_blob_t *blob;
- unsigned int ppem = available_ppems[group];
- blob = sbix.reference_blob_for_glyph (glyph_id, ppem, ppem,
- HB_TAG('p','n','g',' '), nullptr, nullptr);
- if (hb_blob_get_length (blob) == 0) continue;
-
- char output_path[255];
- sprintf (output_path, "out/sbix-%d-%d.png", ppem, glyph_id);
- FILE *f = fopen (output_path, "wb");
- unsigned int length;
- const char* data = hb_blob_get_data (blob, &length);
- fwrite (data, 1, length, f);
- fclose (f);
- }
- sbix.fini ();
-}
-
-static void
-svg_dump (hb_face_t *face)
-{
- unsigned glyph_count = hb_face_get_glyph_count (face);
-
- OT::SVG::accelerator_t svg;
- svg.init (face);
-
- for (unsigned int glyph_id = 0; glyph_id < glyph_count; glyph_id++)
- {
- hb_blob_t *blob = svg.reference_blob_for_glyph (glyph_id);
-
- if (hb_blob_get_length (blob) == 0) continue;
-
- unsigned int length;
- const char *data = hb_blob_get_data (blob, &length);
-
- char output_path[256];
- sprintf (output_path, "out/svg-%d.svg%s",
- glyph_id,
- // append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
- (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
-
- FILE *f = fopen (output_path, "wb");
- fwrite (data, 1, length, f);
- fclose (f);
-
- hb_blob_destroy (blob);
- }
-
- svg.fini ();
-}
-
-static void
-colr_cpal_dump (hb_face_t *face, cairo_font_face_t *cairo_face)
-{
- unsigned int upem = hb_face_get_upem (face);
-
- unsigned glyph_count = hb_face_get_glyph_count (face);
- for (hb_codepoint_t gid = 0; gid < glyph_count; ++gid)
- {
- unsigned int num_layers = hb_ot_color_glyph_get_layers (face, gid, 0, nullptr, nullptr);
- if (!num_layers)
- continue;
-
- hb_ot_color_layer_t *layers = (hb_ot_color_layer_t*) malloc (num_layers * sizeof (hb_ot_color_layer_t));
-
- hb_ot_color_glyph_get_layers (face, gid, 0, &num_layers, layers);
- if (num_layers)
- {
- // Measure
- cairo_text_extents_t extents;
- {
- cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
- cairo_t *cr = cairo_create (surface);
- cairo_set_font_face (cr, cairo_face);
- cairo_set_font_size (cr, upem);
-
- cairo_glyph_t *glyphs = (cairo_glyph_t *) calloc (num_layers, sizeof (cairo_glyph_t));
- for (unsigned int j = 0; j < num_layers; ++j)
- glyphs[j].index = layers[j].glyph;
- cairo_glyph_extents (cr, glyphs, num_layers, &extents);
- free (glyphs);
- cairo_surface_destroy (surface);
- cairo_destroy (cr);
- }
-
- // Add a slight margin
- extents.width += extents.width / 10;
- extents.height += extents.height / 10;
- extents.x_bearing -= extents.width / 20;
- extents.y_bearing -= extents.height / 20;
-
- // Render
- unsigned int palette_count = hb_ot_color_palette_get_count (face);
- for (unsigned int palette = 0; palette < palette_count; palette++) {
- char output_path[255];
-
- unsigned int num_colors = hb_ot_color_palette_get_colors (face, palette, 0, nullptr, nullptr);
- if (!num_colors)
- continue;
-
- hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
- hb_ot_color_palette_get_colors (face, palette, 0, &num_colors, colors);
- if (num_colors)
- {
- // If we have more than one palette, use a simpler naming
- if (palette_count == 1)
- sprintf (output_path, "out/colr-%d.svg", gid);
- else
- sprintf (output_path, "out/colr-%d-%d.svg", gid, palette);
-
- cairo_surface_t *surface = cairo_svg_surface_create (output_path, extents.width, extents.height);
- cairo_t *cr = cairo_create (surface);
- cairo_set_font_face (cr, cairo_face);
- cairo_set_font_size (cr, upem);
-
- for (unsigned int layer = 0; layer < num_layers; ++layer)
- {
- hb_color_t color = 0x000000FF;
- if (layers[layer].color_index != 0xFFFF)
- color = colors[layers[layer].color_index];
- cairo_set_source_rgba (cr,
- hb_color_get_red (color) / 255.,
- hb_color_get_green (color) / 255.,
- hb_color_get_blue (color) / 255.,
- hb_color_get_alpha (color) / 255.);
-
- cairo_glyph_t glyph;
- glyph.index = layers[layer].glyph;
- glyph.x = -extents.x_bearing;
- glyph.y = -extents.y_bearing;
- cairo_show_glyphs (cr, &glyph, 1);
- }
-
- cairo_surface_destroy (surface);
- cairo_destroy (cr);
- }
- free (colors);
- }
- }
-
- free (layers);
- }
-}
-
-static void
-dump_glyphs (cairo_font_face_t *cairo_face, unsigned int upem,
- unsigned int num_glyphs)
-{
- // Dump every glyph available on the font
- return; // disabled for now
- for (unsigned int i = 0; i < num_glyphs; ++i)
- {
- cairo_text_extents_t extents;
- cairo_glyph_t glyph = {0};
- glyph.index = i;
-
- // Measure
- {
- cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
- cairo_t *cr = cairo_create (surface);
- cairo_set_font_face (cr, cairo_face);
- cairo_set_font_size (cr, upem);
-
- cairo_glyph_extents (cr, &glyph, 1, &extents);
- cairo_surface_destroy (surface);
- cairo_destroy (cr);
- }
-
- // Add a slight margin
- extents.width += extents.width / 10;
- extents.height += extents.height / 10;
- extents.x_bearing -= extents.width / 20;
- extents.y_bearing -= extents.height / 20;
-
- // Render
- {
- char output_path[255];
- sprintf (output_path, "out/%d.svg", i);
- cairo_surface_t *surface = cairo_svg_surface_create (output_path, extents.width, extents.height);
- cairo_t *cr = cairo_create (surface);
- cairo_set_font_face (cr, cairo_face);
- cairo_set_font_size (cr, upem);
- glyph.x = -extents.x_bearing;
- glyph.y = -extents.y_bearing;
- cairo_show_glyphs (cr, &glyph, 1);
- cairo_surface_destroy (surface);
- cairo_destroy (cr);
- }
- }
-}
-
-int
-main (int argc, char **argv)
-{
- if (argc != 2) {
- fprintf (stderr, "usage: %s font-file.ttf\n"
- "run it like `rm -rf out && mkdir out && %s font-file.ttf`\n",
- argv[0], argv[0]);
- exit (1);
- }
-
-
- FILE *font_name_file = fopen ("out/_font_name_file.txt", "r");
- if (font_name_file != nullptr)
- {
- fprintf (stderr, "Purge or move ./out folder in order to run a new dump\n");
- exit (1);
- }
-
- font_name_file = fopen ("out/_font_name_file.txt", "w");
- if (font_name_file == nullptr)
- {
- fprintf (stderr, "./out is not accessible as a folder, create it please\n");
- exit (1);
- }
- fwrite (argv[1], 1, strlen (argv[1]), font_name_file);
- fclose (font_name_file);
-
- hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
- hb_face_t *face = hb_face_create (blob, 0);
- hb_font_t *font = hb_font_create (face);
-
- OT::CBDT::accelerator_t cbdt;
- cbdt.init (face);
- cbdt.dump (cbdt_callback);
- cbdt.fini ();
-
- sbix_dump (face);
-
- if (hb_ot_color_has_svg (face))
- svg_dump (face);
-
- cairo_font_face_t *cairo_face;
- {
- FT_Library library;
- FT_Init_FreeType (&library);
- FT_Face ftface;
- FT_New_Face (library, argv[1], 0, &ftface);
- cairo_face = cairo_ft_font_face_create_for_ft_face (ftface, 0);
- }
- if (hb_ot_color_has_layers (face) && hb_ot_color_has_palettes (face))
- colr_cpal_dump (face, cairo_face);
-
- unsigned int num_glyphs = hb_face_get_glyph_count (face);
- unsigned int upem = hb_face_get_upem (face);
- dump_glyphs (cairo_face, upem, num_glyphs);
-
- hb_font_destroy (font);
- hb_face_destroy (face);
- hb_blob_destroy (blob);
-
- return 0;
-}
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 94b00120..2f33bf6c 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -105,8 +105,10 @@ struct SBIXStrike
glyph = &(this+imageOffsetsZ[new_glyph_id]);
glyph_id = new_glyph_id;
if (strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size > sbix_len)
- return hb_blob_get_empty ();
+ return hb_blob_get_empty ();
}
+ else
+ return hb_blob_get_empty ();
}
if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
commit b46de42b3a4bdf110154f4f067656f153f5a7d1b
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:13:45 2018 -0700
[sbix] Fix order of parameters
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index fc199da8..94b00120 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -82,9 +82,9 @@ struct SBIXStrike
inline hb_blob_t *get_glyph_blob (unsigned int glyph_id,
hb_blob_t *sbix_blob,
+ hb_tag_t file_type,
int *x_offset,
int *y_offset,
- hb_tag_t file_type,
unsigned int num_glyphs) const
{
unsigned int sbix_len = sbix_blob->length;
@@ -186,8 +186,8 @@ struct sbix
int *y_offset) const
{
return get_strike (font).get_glyph_blob (glyph_id, sbix_blob,
- x_offset, y_offset,
HB_TAG ('p','n','g',' '),
+ x_offset, y_offset,
num_glyphs);
}
commit a91cda72abdfc5e401510474c59dd14026e8b6cb
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:12:05 2018 -0700
[sbix] Remove redundant parameter
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index f6b198ff..fc199da8 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -82,12 +82,12 @@ struct SBIXStrike
inline hb_blob_t *get_glyph_blob (unsigned int glyph_id,
hb_blob_t *sbix_blob,
- unsigned int sbix_len,
int *x_offset,
int *y_offset,
hb_tag_t file_type,
unsigned int num_glyphs) const
{
+ unsigned int sbix_len = sbix_blob->length;
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
if (imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] == 0)
return hb_blob_get_empty ();
@@ -185,7 +185,7 @@ struct sbix
int *x_offset,
int *y_offset) const
{
- return get_strike (font).get_glyph_blob (glyph_id, sbix_blob, sbix_len,
+ return get_strike (font).get_glyph_blob (glyph_id, sbix_blob,
x_offset, y_offset,
HB_TAG ('p','n','g',' '),
num_glyphs);
commit c712005f55b2a1e5c782302d8a548cf1231c01f0
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:11:10 2018 -0700
[sbix] Add get_strike()
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 2331a5f9..f6b198ff 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -83,12 +83,12 @@ struct SBIXStrike
inline hb_blob_t *get_glyph_blob (unsigned int glyph_id,
hb_blob_t *sbix_blob,
unsigned int sbix_len,
- unsigned int strike_offset,
int *x_offset,
int *y_offset,
hb_tag_t file_type,
unsigned int num_glyphs) const
{
+ unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
if (imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] == 0)
return hb_blob_get_empty ();
@@ -185,8 +185,18 @@ struct sbix
int *x_offset,
int *y_offset) const
{
+ return get_strike (font).get_glyph_blob (glyph_id, sbix_blob, sbix_len,
+ x_offset, y_offset,
+ HB_TAG ('p','n','g',' '),
+ num_glyphs);
+ }
+
+ private:
+
+ inline const SBIXStrike &get_strike (hb_font_t *font) const
+ {
if (unlikely (!table->strikes.len))
- return hb_blob_get_empty ();
+ return Null(SBIXStrike);
unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
if (!requested_ppem)
@@ -206,16 +216,9 @@ struct sbix
}
}
- const SBIXStrike &strike = table+table->strikes[best_i];
- return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
- table->strikes[best_i],
- x_offset, y_offset,
- HB_TAG ('p','n','g',' '),
- num_glyphs);
+ return table+table->strikes[best_i];
}
- private:
-
struct PNGHeader
{
HBUINT8 signature[8];
commit 400bc3f030b4ffebe24aa3562d8eb5fcc1cf4bdd
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:05:40 2018 -0700
[sbix] Remove a couple of extra checks
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 5aee44e6..2331a5f9 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -162,7 +162,7 @@ struct sbix
/* only to support dump-emoji, don't use it anywhere else */
inline unsigned int *get_available_ppems (unsigned int *length)
{
- if (unlikely (sbix_len == 0 || table->strikes.len == 0))
+ if (unlikely (table->strikes.len == 0))
return nullptr;
*length = table->strikes.len;
unsigned int *result;
@@ -185,7 +185,7 @@ struct sbix
int *x_offset,
int *y_offset) const
{
- if (unlikely (!sbix_len || !table->strikes.len))
+ if (unlikely (!table->strikes.len))
return hb_blob_get_empty ();
unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
commit 3770282c837aacbf49b16be1986c91a608faa7da
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:02:53 2018 -0700
[sbix] Rename sbix_table to table in accelerator
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 54cc62a6..5aee44e6 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -148,7 +148,7 @@ struct sbix
{
sbix_blob = hb_sanitize_context_t().reference_table<sbix> (face);
sbix_len = hb_blob_get_length (sbix_blob);
- sbix_table = sbix_blob->as<sbix> ();
+ table = sbix_blob->as<sbix> ();
num_glyphs = face->get_num_glyphs ();
}
@@ -162,13 +162,13 @@ struct sbix
/* only to support dump-emoji, don't use it anywhere else */
inline unsigned int *get_available_ppems (unsigned int *length)
{
- if (unlikely (sbix_len == 0 || sbix_table->strikes.len == 0))
+ if (unlikely (sbix_len == 0 || table->strikes.len == 0))
return nullptr;
- *length = sbix_table->strikes.len;
+ *length = table->strikes.len;
unsigned int *result;
- result = (unsigned int *) malloc (sizeof (unsigned int) * sbix_table->strikes.len);
- for (unsigned int i = 0; i < sbix_table->strikes.len; i++)
- result[i] = (sbix_table+sbix_table->strikes[i]).get_ppem ();
+ result = (unsigned int *) malloc (sizeof (unsigned int) * table->strikes.len);
+ for (unsigned int i = 0; i < table->strikes.len; i++)
+ result[i] = (table+table->strikes[i]).get_ppem ();
return result;
}
@@ -185,7 +185,7 @@ struct sbix
int *x_offset,
int *y_offset) const
{
- if (unlikely (!sbix_len || !sbix_table->strikes.len))
+ if (unlikely (!sbix_len || !table->strikes.len))
return hb_blob_get_empty ();
unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
@@ -193,11 +193,11 @@ struct sbix
requested_ppem = 1<<30; /* Choose largest strike. */
/* TODO Add DPI sensitivity as well? */
unsigned int best_i = 0;
- unsigned int best_ppem = (sbix_table+sbix_table->strikes[0]).get_ppem ();
+ unsigned int best_ppem = (table+table->strikes[0]).get_ppem ();
- for (unsigned int i = 1; i < sbix_table->strikes.len; i++)
+ for (unsigned int i = 1; i < table->strikes.len; i++)
{
- unsigned int ppem = (sbix_table+sbix_table->strikes[i]).get_ppem ();
+ unsigned int ppem = (table+table->strikes[i]).get_ppem ();
if ((requested_ppem <= ppem && ppem < best_ppem) ||
(requested_ppem > best_ppem && ppem > best_ppem))
{
@@ -206,9 +206,9 @@ struct sbix
}
}
- const SBIXStrike &strike = sbix_table+sbix_table->strikes[best_i];
+ const SBIXStrike &strike = table+table->strikes[best_i];
return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
- sbix_table->strikes[best_i],
+ table->strikes[best_i],
x_offset, y_offset,
HB_TAG ('p','n','g',' '),
num_glyphs);
@@ -265,7 +265,7 @@ struct sbix
private:
hb_blob_t *sbix_blob;
- const sbix *sbix_table;
+ const sbix *table;
unsigned int sbix_len;
unsigned int num_glyphs;
commit 7346841807ad96fc65bfc6ee9e78c3f190488f2a
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 15:00:13 2018 -0700
[cbdt] Rename reference_blob_for_glyph() to reference_png()
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index d07c73db..f744e1a6 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -504,12 +504,12 @@ struct CBDT
}
}
- inline hb_blob_t* reference_blob_for_glyph (hb_codepoint_t glyph_id,
- unsigned int x_ppem,
- unsigned int y_ppem) const
+ inline hb_blob_t* reference_png (hb_codepoint_t glyph_id,
+ unsigned int x_ppem,
+ unsigned int y_ppem) const
{
if (!cblc)
- return hb_blob_get_empty (); // Not a color bitmap font.
+ return hb_blob_get_empty ();
if (x_ppem == 0) x_ppem = upem;
if (y_ppem == 0) y_ppem = upem;
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index c70549bc..c89dc9e5 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -321,7 +321,7 @@ hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
blob = _get_sbix (font->face).reference_png (font, glyph, nullptr, nullptr);
if (hb_blob_get_length (blob) == 0 && _get_cbdt (font->face).has_data ())
- blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
+ blob = _get_cbdt (font->face).reference_png (glyph, font->x_ppem, font->y_ppem);
return blob;
}
commit 1f33b8525d578323d6c798c08fc23c56896f9de0
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 14:56:55 2018 -0700
[sbix] Rename ugly reference_blob_for_glyph() to reference_png()
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 5cff5b97..54cc62a6 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -180,11 +180,10 @@ struct sbix
return get_png_extents (font, glyph, extents);
}
- inline hb_blob_t *reference_blob_for_glyph (hb_font_t *font,
- hb_codepoint_t glyph_id,
- unsigned int file_type,
- int *x_offset,
- int *y_offset) const
+ inline hb_blob_t *reference_png (hb_font_t *font,
+ hb_codepoint_t glyph_id,
+ int *x_offset,
+ int *y_offset) const
{
if (unlikely (!sbix_len || !sbix_table->strikes.len))
return hb_blob_get_empty ();
@@ -211,7 +210,8 @@ struct sbix
return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
sbix_table->strikes[best_i],
x_offset, y_offset,
- file_type, num_glyphs);
+ HB_TAG ('p','n','g',' '),
+ num_glyphs);
}
private:
@@ -247,9 +247,7 @@ struct sbix
return false;
int x_offset = 0, y_offset = 0;
- hb_blob_t *blob = reference_blob_for_glyph (font, glyph,
- HB_TAG ('p','n','g',' '),
- &x_offset, &y_offset);
+ hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset);
if (unlikely (blob->length < sizeof (PNGHeader)))
return false;
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index c61b2652..c70549bc 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -318,9 +318,7 @@ hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
hb_blob_t *blob = hb_blob_get_empty ();
if (_get_sbix (font->face).has_data ())
- blob = _get_sbix (font->face).reference_blob_for_glyph (font, glyph,
- HB_TAG('p','n','g',' '),
- nullptr, nullptr);
+ blob = _get_sbix (font->face).reference_png (font, glyph, nullptr, nullptr);
if (hb_blob_get_length (blob) == 0 && _get_cbdt (font->face).has_data ())
blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
commit 946b5344193183133bfc9799e26d3d0436d86404
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 14:52:25 2018 -0700
[sbix] Fix uninitialized variables
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index ce46f3fe..5cff5b97 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -246,15 +246,16 @@ struct sbix
if (likely (sbix_len == 0))
return false;
- int x_offset, y_offset;
+ int x_offset = 0, y_offset = 0;
hb_blob_t *blob = reference_blob_for_glyph (font, glyph,
HB_TAG ('p','n','g',' '),
&x_offset, &y_offset);
- const PNGHeader &png = *blob->as<PNGHeader>();
if (unlikely (blob->length < sizeof (PNGHeader)))
return false;
+ const PNGHeader &png = *blob->as<PNGHeader>();
+
extents->x_bearing = x_offset;
extents->y_bearing = y_offset;
extents->width = png.IHDR.width;
commit 01c7d53fb739b547f3633972194893f68a4738bc
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 14:51:18 2018 -0700
[sbix] Select best strike based on ppem
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 8dc2aedb..ce46f3fe 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -172,37 +172,44 @@ struct sbix
return result;
}
- inline bool get_extents (hb_codepoint_t glyph,
- unsigned int x_ppem,
- unsigned int y_ppem,
+ inline bool get_extents (hb_font_t *font,
+ hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
/* We only support PNG right now, and following function checks type. */
- return get_png_extents (glyph, x_ppem, y_ppem, extents);
+ return get_png_extents (font, glyph, extents);
}
- inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id,
- unsigned int x_ppem,
- unsigned int y_ppem,
+ inline hb_blob_t *reference_blob_for_glyph (hb_font_t *font,
+ hb_codepoint_t glyph_id,
unsigned int file_type,
int *x_offset,
int *y_offset) const
{
- if (unlikely (sbix_len == 0 || sbix_table->strikes.len == 0))
+ if (unlikely (!sbix_len || !sbix_table->strikes.len))
return hb_blob_get_empty ();
- /* TODO: Does spec guarantee strikes are ascended sorted? */
- unsigned int group = sbix_table->strikes.len - 1;
- unsigned int ppem = MAX (x_ppem, y_ppem);
- if (ppem != 0)
- /* TODO: Use bsearch maybe or doesn't worth it? */
- for (group = 0; group < sbix_table->strikes.len; group++)
- if ((sbix_table+sbix_table->strikes[group]).get_ppem () >= ppem)
- break;
+ unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
+ if (!requested_ppem)
+ requested_ppem = 1<<30; /* Choose largest strike. */
+ /* TODO Add DPI sensitivity as well? */
+ unsigned int best_i = 0;
+ unsigned int best_ppem = (sbix_table+sbix_table->strikes[0]).get_ppem ();
+
+ for (unsigned int i = 1; i < sbix_table->strikes.len; i++)
+ {
+ unsigned int ppem = (sbix_table+sbix_table->strikes[i]).get_ppem ();
+ if ((requested_ppem <= ppem && ppem < best_ppem) ||
+ (requested_ppem > best_ppem && ppem > best_ppem))
+ {
+ best_i = i;
+ best_ppem = ppem;
+ }
+ }
- const SBIXStrike &strike = sbix_table+sbix_table->strikes[group];
+ const SBIXStrike &strike = sbix_table+sbix_table->strikes[best_i];
return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
- sbix_table->strikes[group],
+ sbix_table->strikes[best_i],
x_offset, y_offset,
file_type, num_glyphs);
}
@@ -232,16 +239,15 @@ struct sbix
DEFINE_SIZE_STATIC (29);
};
- inline bool get_png_extents (hb_codepoint_t glyph,
- unsigned int x_ppem,
- unsigned int y_ppem,
+ inline bool get_png_extents (hb_font_t *font,
+ hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
if (likely (sbix_len == 0))
return false;
int x_offset, y_offset;
- hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem,
+ hb_blob_t *blob = reference_blob_for_glyph (font, glyph,
HB_TAG ('p','n','g',' '),
&x_offset, &y_offset);
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index 82fa7e29..c61b2652 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -318,8 +318,7 @@ hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
hb_blob_t *blob = hb_blob_get_empty ();
if (_get_sbix (font->face).has_data ())
- blob = _get_sbix (font->face).reference_blob_for_glyph (glyph,
- font->x_ppem, font->y_ppem,
+ blob = _get_sbix (font->face).reference_blob_for_glyph (font, glyph,
HB_TAG('p','n','g',' '),
nullptr, nullptr);
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 7b31e025..e9619c54 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -183,7 +183,7 @@ hb_ot_get_glyph_extents (hb_font_t *font,
void *user_data HB_UNUSED)
{
const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data;
- bool ret = ot_face->sbix->get_extents (glyph, font->x_ppem, font->y_ppem, extents);
+ bool ret = ot_face->sbix->get_extents (font, glyph, extents);
if (!ret)
ret = ot_face->glyf->get_extents (glyph, extents);
if (!ret)
commit f9f26bff4c79d65a92affd6b73e2b3de017f2d6d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 14:20:50 2018 -0700
[sbix] Move code around. Add get_extents()
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index ad962e6a..8dc2aedb 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -157,6 +157,8 @@ struct sbix
hb_blob_destroy (sbix_blob);
}
+ inline bool has_data () const { return sbix_len; }
+
/* only to support dump-emoji, don't use it anywhere else */
inline unsigned int *get_available_ppems (unsigned int *length)
{
@@ -170,6 +172,15 @@ struct sbix
return result;
}
+ inline bool get_extents (hb_codepoint_t glyph,
+ unsigned int x_ppem,
+ unsigned int y_ppem,
+ hb_glyph_extents_t *extents) const
+ {
+ /* We only support PNG right now, and following function checks type. */
+ return get_png_extents (glyph, x_ppem, y_ppem, extents);
+ }
+
inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id,
unsigned int x_ppem,
unsigned int y_ppem,
@@ -196,6 +207,8 @@ struct sbix
file_type, num_glyphs);
}
+ private:
+
struct PNGHeader
{
HBUINT8 signature[8];
@@ -245,8 +258,6 @@ struct sbix
return true;
}
- inline bool has_data () const { return sbix_len; }
-
private:
hb_blob_t *sbix_blob;
const sbix *sbix_table;
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index fa6fda27..7b31e025 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -183,7 +183,7 @@ hb_ot_get_glyph_extents (hb_font_t *font,
void *user_data HB_UNUSED)
{
const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data;
- bool ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents);
+ bool ret = ot_face->sbix->get_extents (glyph, font->x_ppem, font->y_ppem, extents);
if (!ret)
ret = ot_face->glyf->get_extents (glyph, extents);
if (!ret)
commit 48bc3039cb46d2b8cf672d86b63b4235a86252e6
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 14:16:52 2018 -0700
[sbix] Check blob length against PNG header leangth
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index bd298c62..ad962e6a 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -199,14 +199,24 @@ struct sbix
struct PNGHeader
{
HBUINT8 signature[8];
- HBUINT8 chunkHeaderIHDR[8];
- HBUINT32 width;
- HBUINT32 height;
- HBUINT8 bitDepth;
- HBUINT8 colorType;
- HBUINT8 compressionMethod;
- HBUINT8 filterMethod;
- HBUINT8 interlaceMethod;
+ struct
+ {
+ struct
+ {
+ HBUINT32 length;
+ Tag type;
+ } header;
+ HBUINT32 width;
+ HBUINT32 height;
+ HBUINT8 bitDepth;
+ HBUINT8 colorType;
+ HBUINT8 compressionMethod;
+ HBUINT8 filterMethod;
+ HBUINT8 interlaceMethod;
+ } IHDR;
+
+ public:
+ DEFINE_SIZE_STATIC (29);
};
inline bool get_png_extents (hb_codepoint_t glyph,
@@ -222,21 +232,20 @@ struct sbix
HB_TAG ('p','n','g',' '),
&x_offset, &y_offset);
- const PNGHeader &header = *blob->as<PNGHeader>();
- if (header.width == 0 && header.width == 0)
+ const PNGHeader &png = *blob->as<PNGHeader>();
+ if (unlikely (blob->length < sizeof (PNGHeader)))
return false;
extents->x_bearing = x_offset;
extents->y_bearing = y_offset;
- extents->width = header.width;
- extents->height = header.height;
+ extents->width = png.IHDR.width;
+ extents->height = png.IHDR.height;
hb_blob_destroy (blob);
return true;
}
- inline bool has_data () const
- { return sbix_len; }
+ inline bool has_data () const { return sbix_len; }
private:
hb_blob_t *sbix_blob;
commit d3ec31a57cb99048fb33bca65041da9dc884d8cb
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Mon Oct 29 00:28:44 2018 +0330
[ot-color] More on PNGHeader fields
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 5e49d7b2..bd298c62 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -198,9 +198,15 @@ struct sbix
struct PNGHeader
{
- HBUINT8 header[16];
- HBUINT32 width;
- HBUINT32 height;
+ HBUINT8 signature[8];
+ HBUINT8 chunkHeaderIHDR[8];
+ HBUINT32 width;
+ HBUINT32 height;
+ HBUINT8 bitDepth;
+ HBUINT8 colorType;
+ HBUINT8 compressionMethod;
+ HBUINT8 filterMethod;
+ HBUINT8 interlaceMethod;
};
inline bool get_png_extents (hb_codepoint_t glyph,
commit 35fa3d326096639a33635e19f204a9cb31f20826
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Mon Oct 29 00:07:26 2018 +0330
[ot-color] Apply Behdad comment
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 79c86ed0..5e49d7b2 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -215,12 +215,13 @@ struct sbix
hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem,
HB_TAG ('p','n','g',' '),
&x_offset, &y_offset);
- if (hb_blob_get_length (blob) < sizeof (PNGHeader))
+
+ const PNGHeader &header = *blob->as<PNGHeader>();
+ if (header.width == 0 && header.width == 0)
return false;
extents->x_bearing = x_offset;
extents->y_bearing = y_offset;
- const PNGHeader &header = *blob->as<PNGHeader>();
extents->width = header.width;
extents->height = header.height;
hb_blob_destroy (blob);
commit 307d61867a2b70073eecd1e0cb9b7d912e1c3f06
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Mon Oct 29 00:03:01 2018 +0330
[ot-color] Make PNGHeader reading actually work
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 95db7fe6..79c86ed0 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -198,7 +198,7 @@ struct sbix
struct PNGHeader
{
- HBUINT8 header[9];
+ HBUINT8 header[16];
HBUINT32 width;
HBUINT32 height;
};
@@ -209,7 +209,7 @@ struct sbix
hb_glyph_extents_t *extents) const
{
if (likely (sbix_len == 0))
- return hb_blob_get_empty ();
+ return false;
int x_offset, y_offset;
hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem,
@@ -221,7 +221,7 @@ struct sbix
extents->x_bearing = x_offset;
extents->y_bearing = y_offset;
const PNGHeader &header = *blob->as<PNGHeader>();
- extents->width = header.width + 100;
+ extents->width = header.width;
extents->height = header.height;
hb_blob_destroy (blob);
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index bef52bfb..9cc353ba 100644
--- a/test/api/test-ot-color.c
+++ b/test/api/test-ot-color.c
@@ -427,8 +427,8 @@ test_hb_ot_color_png (void)
hb_font_get_glyph_extents (sbix_font, 1, &extents);
g_assert_cmpint (extents.x_bearing, ==, 0);
g_assert_cmpint (extents.y_bearing, ==, 0);
- g_assert_cmpint (extents.width, ==, 3501);
- g_assert_cmpint (extents.height, ==, 20992);
+ g_assert_cmpint (extents.width, ==, 300);
+ g_assert_cmpint (extents.height, ==, 300);
hb_blob_destroy (blob);
hb_font_destroy (sbix_font);
commit 632e9af862aba49ab31343c4fd07dffef6d2749f
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sun Oct 28 23:43:50 2018 +0330
[ot-color] Implement PNGHeader and test it, it doesn't work however
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index bb259024..95db7fe6 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -196,23 +196,33 @@ struct sbix
file_type, num_glyphs);
}
+ struct PNGHeader
+ {
+ HBUINT8 header[9];
+ HBUINT32 width;
+ HBUINT32 height;
+ };
+
inline bool get_png_extents (hb_codepoint_t glyph,
unsigned int x_ppem,
unsigned int y_ppem,
hb_glyph_extents_t *extents) const
{
+ if (likely (sbix_len == 0))
+ return hb_blob_get_empty ();
+
int x_offset, y_offset;
hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem,
- HB_TAG ('P','N','G',' '),
+ HB_TAG ('p','n','g',' '),
&x_offset, &y_offset);
- if (hb_blob_get_length (blob) == 0)
+ if (hb_blob_get_length (blob) < sizeof (PNGHeader))
return false;
extents->x_bearing = x_offset;
extents->y_bearing = y_offset;
- /* XXX: Help me please! */
- extents->width = 0;
- extents->height = 0;
+ const PNGHeader &header = *blob->as<PNGHeader>();
+ extents->width = header.width + 100;
+ extents->height = header.height;
hb_blob_destroy (blob);
return true;
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index c8ad6f2f..fa6fda27 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -183,9 +183,7 @@ hb_ot_get_glyph_extents (hb_font_t *font,
void *user_data HB_UNUSED)
{
const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data;
- bool ret = false;
- if (ot_face->sbix->has_data ())
- ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents);
+ bool ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents);
if (!ret)
ret = ot_face->glyf->get_extents (glyph, extents);
if (!ret)
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index f825c83a..bef52bfb 100644
--- a/test/api/test-ot-color.c
+++ b/test/api/test-ot-color.c
@@ -407,17 +407,28 @@ test_hb_ot_color_png (void)
hb_blob_t *blob;
unsigned int length;
const char *data;
+ hb_glyph_extents_t extents;
/* sbix */
hb_font_t *sbix_font;
sbix_font = hb_font_create (sbix);
blob = hb_ot_color_glyph_reference_png (sbix_font, 0);
+ hb_font_get_glyph_extents (sbix_font, 0, &extents);
+ g_assert_cmpint (extents.x_bearing, ==, 0);
+ g_assert_cmpint (extents.y_bearing, ==, 0);
+ g_assert_cmpint (extents.width, ==, 0);
+ g_assert_cmpint (extents.height, ==, 0);
g_assert (hb_blob_get_length (blob) == 0);
blob = hb_ot_color_glyph_reference_png (sbix_font, 1);
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 224);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
+ hb_font_get_glyph_extents (sbix_font, 1, &extents);
+ g_assert_cmpint (extents.x_bearing, ==, 0);
+ g_assert_cmpint (extents.y_bearing, ==, 0);
+ g_assert_cmpint (extents.width, ==, 3501);
+ g_assert_cmpint (extents.height, ==, 20992);
hb_blob_destroy (blob);
hb_font_destroy (sbix_font);
@@ -431,6 +442,11 @@ test_hb_ot_color_png (void)
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 88);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
+ hb_font_get_glyph_extents (cbdt_font, 1, &extents);
+ g_assert_cmpint (extents.x_bearing, ==, 0);
+ g_assert_cmpint (extents.y_bearing, ==, 1024);
+ g_assert_cmpint (extents.width, ==, 1024);
+ g_assert_cmpint (extents.height, ==, -1024);
hb_blob_destroy (blob);
hb_font_destroy (cbdt_font);
}
commit 38706a0746822865008f810f9f577740c32580fa
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sun Oct 28 23:19:04 2018 +0330
[ot-color] Preparation for setting PNG width/height in extents
diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc
index 5cbf31ab..e3cabc73 100644
--- a/src/dump-emoji.cc
+++ b/src/dump-emoji.cc
@@ -69,12 +69,13 @@ sbix_dump (hb_face_t *face)
for (unsigned int glyph_id = 0; glyph_id < num_glyphs; glyph_id++)
{
hb_blob_t *blob;
- blob = sbix.reference_blob_for_glyph (glyph_id, 0, available_ppems[group],
- HB_TAG('p','n','g',' '));
+ unsigned int ppem = available_ppems[group];
+ blob = sbix.reference_blob_for_glyph (glyph_id, ppem, ppem,
+ HB_TAG('p','n','g',' '), nullptr, nullptr);
if (hb_blob_get_length (blob) == 0) continue;
char output_path[255];
- sprintf (output_path, "out/sbix-%d-%d.png", available_ppems[group], glyph_id);
+ sprintf (output_path, "out/sbix-%d-%d.png", ppem, glyph_id);
FILE *f = fopen (output_path, "wb");
unsigned int length;
const char* data = hb_blob_get_data (blob, &length);
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index a5bfa281..bb259024 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -75,7 +75,7 @@ struct SBIXStrike
inline unsigned int get_resolution () const
{ return resolution; }
- inline unsigned int blob_size (unsigned int glyph_id) const
+ inline unsigned int calculate_blob_size (unsigned int glyph_id) const
{
return imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] - SBIXGlyph::min_size;
}
@@ -84,6 +84,8 @@ struct SBIXStrike
hb_blob_t *sbix_blob,
unsigned int sbix_len,
unsigned int strike_offset,
+ int *x_offset,
+ int *y_offset,
hb_tag_t file_type,
unsigned int num_glyphs) const
{
@@ -95,7 +97,7 @@ struct SBIXStrike
const SBIXGlyph *glyph = &(this+imageOffsetsZ[glyph_id]);
if (unlikely (glyph->graphicType == HB_TAG ('d','u','p','e') &&
- blob_size (glyph_id) >= 2))
+ calculate_blob_size (glyph_id) >= 2))
{
unsigned int new_glyph_id = *((HBUINT16 *) &glyph->data);
if (new_glyph_id < num_glyphs)
@@ -108,9 +110,15 @@ struct SBIXStrike
}
if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
+ unsigned int blob_size = calculate_blob_size (glyph_id);
+ if (unlikely (blob_size == 0))
+ return hb_blob_get_empty ();
+
+ if (x_offset) *x_offset = glyph->xOffset;
+ if (y_offset) *y_offset = glyph->yOffset;
unsigned int offset = strike_offset + SBIXGlyph::min_size;
offset += imageOffsetsZ[glyph_id];
- return hb_blob_create_sub_blob (sbix_blob, offset, blob_size (glyph_id));
+ return hb_blob_create_sub_blob (sbix_blob, offset, blob_size);
}
protected:
@@ -163,25 +171,51 @@ struct sbix
}
inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id,
- unsigned int ptem HB_UNUSED,
- unsigned int requested_ppem,
- unsigned int requested_file_type) const
+ unsigned int x_ppem,
+ unsigned int y_ppem,
+ unsigned int file_type,
+ int *x_offset,
+ int *y_offset) const
{
if (unlikely (sbix_len == 0 || sbix_table->strikes.len == 0))
return hb_blob_get_empty ();
/* TODO: Does spec guarantee strikes are ascended sorted? */
unsigned int group = sbix_table->strikes.len - 1;
- if (requested_ppem != 0)
+ unsigned int ppem = MAX (x_ppem, y_ppem);
+ if (ppem != 0)
/* TODO: Use bsearch maybe or doesn't worth it? */
for (group = 0; group < sbix_table->strikes.len; group++)
- if ((sbix_table+sbix_table->strikes[group]).get_ppem () >= requested_ppem)
+ if ((sbix_table+sbix_table->strikes[group]).get_ppem () >= ppem)
break;
const SBIXStrike &strike = sbix_table+sbix_table->strikes[group];
return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
sbix_table->strikes[group],
- requested_file_type, num_glyphs);
+ x_offset, y_offset,
+ file_type, num_glyphs);
+ }
+
+ inline bool get_png_extents (hb_codepoint_t glyph,
+ unsigned int x_ppem,
+ unsigned int y_ppem,
+ hb_glyph_extents_t *extents) const
+ {
+ int x_offset, y_offset;
+ hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem,
+ HB_TAG ('P','N','G',' '),
+ &x_offset, &y_offset);
+ if (hb_blob_get_length (blob) == 0)
+ return false;
+
+ extents->x_bearing = x_offset;
+ extents->y_bearing = y_offset;
+ /* XXX: Help me please! */
+ extents->width = 0;
+ extents->height = 0;
+ hb_blob_destroy (blob);
+
+ return true;
}
inline bool has_data () const
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index ed41a3b2..82fa7e29 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -316,16 +316,14 @@ hb_blob_t *
hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
{
hb_blob_t *blob = hb_blob_get_empty ();
- /* don't run cbdt first if aat is set */
- if (!hb_options ().aat && _get_cbdt (font->face).has_data ())
- blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
- if (_get_sbix (font->face).has_data () && !hb_blob_get_length (blob))
- blob = _get_sbix (font->face).reference_blob_for_glyph (glyph, font->ptem,
- MAX (font->x_ppem, font->y_ppem),
- HB_TAG('p','n','g',' '));
+ if (_get_sbix (font->face).has_data ())
+ blob = _get_sbix (font->face).reference_blob_for_glyph (glyph,
+ font->x_ppem, font->y_ppem,
+ HB_TAG('p','n','g',' '),
+ nullptr, nullptr);
- if (hb_options ().aat && _get_cbdt (font->face).has_data () && !hb_blob_get_length (blob))
+ if (hb_blob_get_length (blob) == 0 && _get_cbdt (font->face).has_data ())
blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
return blob;
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 047c4eae..c8ad6f2f 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -39,6 +39,7 @@
#include "hb-ot-glyf-table.hh"
#include "hb-ot-vorg-table.hh"
#include "hb-ot-color-cbdt-table.hh"
+#include "hb-ot-color-sbix-table.hh"
/**
@@ -182,7 +183,11 @@ hb_ot_get_glyph_extents (hb_font_t *font,
void *user_data HB_UNUSED)
{
const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data;
- bool ret = ot_face->glyf->get_extents (glyph, extents);
+ bool ret = false;
+ if (ot_face->sbix->has_data ())
+ ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents);
+ if (!ret)
+ ret = ot_face->glyf->get_extents (glyph, extents);
if (!ret)
ret = ot_face->CBDT->get_extents (glyph, extents);
// TODO Hook up side-bearings variations.
commit d6d6f3bc225bab57c1ab29b41876c98ac4ec1e4d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 11:41:33 2018 -0700
[docs] Add comment
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index 7a451688..047c4eae 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -47,7 +47,9 @@
* @short_description: OpenType font implementation
* @include: hb-ot.h
*
- * Functions for using OpenType fonts with hb_shape().
+ * Functions for using OpenType fonts with hb_shape(). Not that fonts returned
+ * by hb_font_create() default to using these functions, so most clients would
+ * never need to call these functions directly.
**/
commit 3d4c1f6a41022ec99adefa2bdd2489622e2f9a66
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sun Oct 28 21:38:56 2018 +0330
[ot-color] Apply Behdad reviews
diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt
index ecce3c77..c33a1c12 100644
--- a/docs/harfbuzz-sections.txt
+++ b/docs/harfbuzz-sections.txt
@@ -459,8 +459,8 @@ hb_color_get_blue
hb_color_get_green
hb_color_get_red
hb_ot_color_glyph_get_layers
-hb_ot_color_glyph_reference_blob_png
-hb_ot_color_glyph_reference_blob_svg
+hb_ot_color_glyph_reference_png
+hb_ot_color_glyph_reference_svg
hb_ot_color_has_layers
hb_ot_color_has_palettes
hb_ot_color_has_png
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index 572fcec4..d07c73db 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -505,15 +505,14 @@ struct CBDT
}
inline hb_blob_t* reference_blob_for_glyph (hb_codepoint_t glyph_id,
- unsigned int requested_x_ppem,
- unsigned int requested_y_ppem) const
+ unsigned int x_ppem,
+ unsigned int y_ppem) const
{
if (!cblc)
return hb_blob_get_empty (); // Not a color bitmap font.
- if (requested_x_ppem == 0) requested_x_ppem = upem;
- if (requested_y_ppem == 0) requested_y_ppem = upem;
- unsigned int x_ppem = requested_x_ppem, y_ppem = requested_y_ppem;
+ if (x_ppem == 0) x_ppem = upem;
+ if (y_ppem == 0) y_ppem = upem;
const void *base;
const IndexSubtableRecord *subtable_record = this->cblc->find_table (glyph_id, &x_ppem, &y_ppem, &base);
@@ -527,8 +526,6 @@ struct CBDT
switch (image_format)
{
case 17: {
- // if (strike_x_ppem) *strike_x_ppem = x_ppem;
- // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat17& glyphFormat17 =
StructAtOffset<GlyphBitmapDataFormat17> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
@@ -536,8 +533,6 @@ struct CBDT
glyphFormat17.data.len);
}
case 18: {
- // if (strike_x_ppem) *strike_x_ppem = x_ppem;
- // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat18& glyphFormat18 =
StructAtOffset<GlyphBitmapDataFormat18> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
@@ -545,8 +540,6 @@ struct CBDT
glyphFormat18.data.len);
}
case 19: {
- // if (strike_x_ppem) *strike_x_ppem = x_ppem;
- // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat19& glyphFormat19 =
StructAtOffset<GlyphBitmapDataFormat19> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 6dfc29d4..a5bfa281 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -84,7 +84,7 @@ struct SBIXStrike
hb_blob_t *sbix_blob,
unsigned int sbix_len,
unsigned int strike_offset,
- hb_tag_t requested_file_type,
+ hb_tag_t file_type,
unsigned int num_glyphs) const
{
if (imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] == 0)
@@ -106,10 +106,8 @@ struct SBIXStrike
return hb_blob_get_empty ();
}
}
- if (unlikely (requested_file_type != glyph->graphicType))
+ if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
- // if (x_offset) *x_offset = glyph->xOffset;
- // if (y_offset) *y_offset = glyph->yOffset;
unsigned int offset = strike_offset + SBIXGlyph::min_size;
offset += imageOffsetsZ[glyph_id];
return hb_blob_create_sub_blob (sbix_blob, offset, blob_size (glyph_id));
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index 4a460c8b..ed41a3b2 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -268,7 +268,7 @@ hb_ot_color_has_svg (hb_face_t *face)
}
/**
- * hb_ot_color_glyph_reference_blob_svg:
+ * hb_ot_color_glyph_reference_svg:
* @face: a font face.
* @glyph: a svg glyph index.
*
@@ -277,7 +277,7 @@ hb_ot_color_has_svg (hb_face_t *face)
* Since: REPLACEME
*/
hb_blob_t *
-hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph)
+hb_ot_color_glyph_reference_svg (hb_face_t *face, hb_codepoint_t glyph)
{
return _get_svg (face).reference_blob_for_glyph (glyph);
}
@@ -302,7 +302,7 @@ hb_ot_color_has_png (hb_face_t *face)
}
/**
- * hb_ot_color_glyph_reference_blob_png:
+ * hb_ot_color_glyph_reference_png:
* @font: a font object, not face. upem should be set on
* that font object if one wants to get optimal png blob, otherwise
* return the biggest one
@@ -313,7 +313,7 @@ hb_ot_color_has_png (hb_face_t *face)
* Since: REPLACEME
*/
hb_blob_t *
-hb_ot_color_glyph_reference_blob_png (hb_font_t *font, hb_codepoint_t glyph)
+hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph)
{
hb_blob_t *blob = hb_blob_get_empty ();
/* don't run cbdt first if aat is set */
diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h
index 4b0d5b53..89935143 100644
--- a/src/hb-ot-color.h
+++ b/src/hb-ot-color.h
@@ -119,7 +119,7 @@ HB_EXTERN hb_bool_t
hb_ot_color_has_svg (hb_face_t *face);
HB_EXTERN hb_blob_t *
-hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph);
+hb_ot_color_glyph_reference_svg (hb_face_t *face, hb_codepoint_t glyph);
/*
* PNG: CBDT or sbix
@@ -129,7 +129,7 @@ HB_EXTERN hb_bool_t
hb_ot_color_has_png (hb_face_t *face);
HB_EXTERN hb_blob_t *
-hb_ot_color_glyph_reference_blob_png (hb_font_t *font, hb_codepoint_t glyph);
+hb_ot_color_glyph_reference_png (hb_font_t *font, hb_codepoint_t glyph);
HB_END_DECLS
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index c4c5610e..f825c83a 100644
--- a/test/api/test-ot-color.c
+++ b/test/api/test-ot-color.c
@@ -385,10 +385,10 @@ test_hb_ot_color_svg (void)
{
hb_blob_t *blob;
- blob = hb_ot_color_glyph_reference_blob_svg (svg, 0);
+ blob = hb_ot_color_glyph_reference_svg (svg, 0);
g_assert (hb_blob_get_length (blob) == 0);
- blob = hb_ot_color_glyph_reference_blob_svg (svg, 1);
+ blob = hb_ot_color_glyph_reference_svg (svg, 1);
unsigned int length;
const char *data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 146);
@@ -396,7 +396,7 @@ test_hb_ot_color_svg (void)
g_assert (strncmp (data + 140, "</svg>", 5) == 0);
hb_blob_destroy (blob);
- blob = hb_ot_color_glyph_reference_blob_svg (empty, 0);
+ blob = hb_ot_color_glyph_reference_svg (empty, 0);
g_assert (hb_blob_get_length (blob) == 0);
}
@@ -411,10 +411,10 @@ test_hb_ot_color_png (void)
/* sbix */
hb_font_t *sbix_font;
sbix_font = hb_font_create (sbix);
- blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 0);
+ blob = hb_ot_color_glyph_reference_png (sbix_font, 0);
g_assert (hb_blob_get_length (blob) == 0);
- blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 1);
+ blob = hb_ot_color_glyph_reference_png (sbix_font, 1);
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 224);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
@@ -424,10 +424,10 @@ test_hb_ot_color_png (void)
/* cbdt */
hb_font_t *cbdt_font;
cbdt_font = hb_font_create (cbdt);
- blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 0);
+ blob = hb_ot_color_glyph_reference_png (cbdt_font, 0);
g_assert (hb_blob_get_length (blob) == 0);
- blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 1);
+ blob = hb_ot_color_glyph_reference_png (cbdt_font, 1);
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 88);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
commit 8ef0d2ef928ac47278d7c6db8c8040a47f076e85
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sun Oct 28 20:09:40 2018 +0330
[ot-color] Apply Behdad comment
diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc
index b622da89..5cbf31ab 100644
--- a/src/dump-emoji.cc
+++ b/src/dump-emoji.cc
@@ -70,7 +70,7 @@ sbix_dump (hb_face_t *face)
{
hb_blob_t *blob;
blob = sbix.reference_blob_for_glyph (glyph_id, 0, available_ppems[group],
- HB_TAG('p','n','g',' '), NULL, NULL);
+ HB_TAG('p','n','g',' '));
if (hb_blob_get_length (blob) == 0) continue;
char output_path[255];
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index 5aa66ccb..572fcec4 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -506,9 +506,7 @@ struct CBDT
inline hb_blob_t* reference_blob_for_glyph (hb_codepoint_t glyph_id,
unsigned int requested_x_ppem,
- unsigned int requested_y_ppem,
- unsigned int *strike_x_ppem,
- unsigned int *strike_y_ppem) const
+ unsigned int requested_y_ppem) const
{
if (!cblc)
return hb_blob_get_empty (); // Not a color bitmap font.
@@ -529,8 +527,8 @@ struct CBDT
switch (image_format)
{
case 17: {
- if (strike_x_ppem) *strike_x_ppem = x_ppem;
- if (strike_x_ppem) *strike_y_ppem = y_ppem;
+ // if (strike_x_ppem) *strike_x_ppem = x_ppem;
+ // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat17& glyphFormat17 =
StructAtOffset<GlyphBitmapDataFormat17> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
@@ -538,8 +536,8 @@ struct CBDT
glyphFormat17.data.len);
}
case 18: {
- if (strike_x_ppem) *strike_x_ppem = x_ppem;
- if (strike_x_ppem) *strike_y_ppem = y_ppem;
+ // if (strike_x_ppem) *strike_x_ppem = x_ppem;
+ // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat18& glyphFormat18 =
StructAtOffset<GlyphBitmapDataFormat18> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
@@ -547,8 +545,8 @@ struct CBDT
glyphFormat18.data.len);
}
case 19: {
- if (strike_x_ppem) *strike_x_ppem = x_ppem;
- if (strike_x_ppem) *strike_y_ppem = y_ppem;
+ // if (strike_x_ppem) *strike_x_ppem = x_ppem;
+ // if (strike_x_ppem) *strike_y_ppem = y_ppem;
const GlyphBitmapDataFormat19& glyphFormat19 =
StructAtOffset<GlyphBitmapDataFormat19> (this->cbdt, image_offset);
return hb_blob_create_sub_blob (cbdt_blob,
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index b48ea171..6dfc29d4 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -84,8 +84,6 @@ struct SBIXStrike
hb_blob_t *sbix_blob,
unsigned int sbix_len,
unsigned int strike_offset,
- unsigned int *x_offset,
- unsigned int *y_offset,
hb_tag_t requested_file_type,
unsigned int num_glyphs) const
{
@@ -110,8 +108,8 @@ struct SBIXStrike
}
if (unlikely (requested_file_type != glyph->graphicType))
return hb_blob_get_empty ();
- if (likely (x_offset)) *x_offset = glyph->xOffset;
- if (likely (y_offset)) *y_offset = glyph->yOffset;
+ // if (x_offset) *x_offset = glyph->xOffset;
+ // if (y_offset) *y_offset = glyph->yOffset;
unsigned int offset = strike_offset + SBIXGlyph::min_size;
offset += imageOffsetsZ[glyph_id];
return hb_blob_create_sub_blob (sbix_blob, offset, blob_size (glyph_id));
@@ -169,9 +167,7 @@ struct sbix
inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id,
unsigned int ptem HB_UNUSED,
unsigned int requested_ppem,
- unsigned int requested_file_type,
- unsigned int *available_x_ppem,
- unsigned int *available_y_ppem) const
+ unsigned int requested_file_type) const
{
if (unlikely (sbix_len == 0 || sbix_table->strikes.len == 0))
return hb_blob_get_empty ();
@@ -185,11 +181,9 @@ struct sbix
break;
const SBIXStrike &strike = sbix_table+sbix_table->strikes[group];
- if (available_x_ppem) *available_x_ppem = strike.get_ppem ();
- if (available_y_ppem) *available_y_ppem = strike.get_ppem ();
return strike.get_glyph_blob (glyph_id, sbix_blob, sbix_len,
sbix_table->strikes[group],
- nullptr, nullptr, requested_file_type, num_glyphs);
+ requested_file_type, num_glyphs);
}
inline bool has_data () const
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index fb6ca866..4a460c8b 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -272,7 +272,7 @@ hb_ot_color_has_svg (hb_face_t *face)
* @face: a font face.
* @glyph: a svg glyph index.
*
- * Returns: respective svg blob of the glyph, if available.
+ * Returns: (transfer full): respective svg blob of the glyph, if available.
*
* Since: REPLACEME
*/
@@ -302,39 +302,31 @@ hb_ot_color_has_png (hb_face_t *face)
}
/**
- * hb_ot_color_glyph_reference_blob_svg:
+ * hb_ot_color_glyph_reference_blob_png:
* @font: a font object, not face. upem should be set on
* that font object if one wants to get optimal png blob, otherwise
* return the biggest one
* @glyph: a glyph index.
- * @strike_x_ppem: (out):
- * @strike_y_ppem: (out):
*
- * Returns: respective png blob of the glyph, if available.
+ * Returns: (transfer full): respective png blob of the glyph, if available.
*
* Since: REPLACEME
*/
hb_blob_t *
-hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
- hb_codepoint_t glyph,
- unsigned int *strike_x_ppem /* OUT */,
- unsigned int *strike_y_ppem /* OUT */)
+hb_ot_color_glyph_reference_blob_png (hb_font_t *font, hb_codepoint_t glyph)
{
hb_blob_t *blob = hb_blob_get_empty ();
/* don't run cbdt first if aat is set */
if (!hb_options ().aat && _get_cbdt (font->face).has_data ())
- blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem,
- strike_x_ppem, strike_y_ppem);
+ blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
if (_get_sbix (font->face).has_data () && !hb_blob_get_length (blob))
blob = _get_sbix (font->face).reference_blob_for_glyph (glyph, font->ptem,
MAX (font->x_ppem, font->y_ppem),
- HB_TAG('p','n','g',' '),
- strike_x_ppem, strike_y_ppem);
+ HB_TAG('p','n','g',' '));
if (hb_options ().aat && _get_cbdt (font->face).has_data () && !hb_blob_get_length (blob))
- blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem,
- strike_x_ppem, strike_y_ppem);
+ blob = _get_cbdt (font->face).reference_blob_for_glyph (glyph, font->x_ppem, font->y_ppem);
return blob;
}
diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h
index a8eae861..4b0d5b53 100644
--- a/src/hb-ot-color.h
+++ b/src/hb-ot-color.h
@@ -129,10 +129,7 @@ HB_EXTERN hb_bool_t
hb_ot_color_has_png (hb_face_t *face);
HB_EXTERN hb_blob_t *
-hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
- hb_codepoint_t glyph,
- unsigned int *strike_x_ppem,
- unsigned int *strike_y_ppem);
+hb_ot_color_glyph_reference_blob_png (hb_font_t *font, hb_codepoint_t glyph);
HB_END_DECLS
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index 51b901d2..c4c5610e 100644
--- a/test/api/test-ot-color.c
+++ b/test/api/test-ot-color.c
@@ -407,20 +407,16 @@ test_hb_ot_color_png (void)
hb_blob_t *blob;
unsigned int length;
const char *data;
- unsigned int strike_x_ppem, strike_y_ppem;
/* sbix */
hb_font_t *sbix_font;
sbix_font = hb_font_create (sbix);
- blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 0, NULL, NULL);
+ blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 0);
g_assert (hb_blob_get_length (blob) == 0);
- blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 1,
- &strike_x_ppem, &strike_y_ppem);
+ blob = hb_ot_color_glyph_reference_blob_png (sbix_font, 1);
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 224);
- g_assert_cmpuint (strike_x_ppem, ==, 300);
- g_assert_cmpuint (strike_y_ppem, ==, 300);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
hb_blob_destroy (blob);
hb_font_destroy (sbix_font);
@@ -428,15 +424,12 @@ test_hb_ot_color_png (void)
/* cbdt */
hb_font_t *cbdt_font;
cbdt_font = hb_font_create (cbdt);
- blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 0, NULL, NULL);
+ blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 0);
g_assert (hb_blob_get_length (blob) == 0);
- blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 1,
- &strike_x_ppem, &strike_y_ppem);
+ blob = hb_ot_color_glyph_reference_blob_png (cbdt_font, 1);
data = hb_blob_get_data (blob, &length);
g_assert_cmpuint (length, ==, 88);
- g_assert_cmpuint (strike_x_ppem, ==, 80);
- g_assert_cmpuint (strike_y_ppem, ==, 80);
g_assert (strncmp (data + 1, "PNG", 3) == 0);
hb_blob_destroy (blob);
hb_font_destroy (cbdt_font);
commit dbd419bedef06a07c844b6a748a5e2868016000c
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Sat Oct 27 15:15:24 2018 +0330
[ot-color] Add public API for CBDT/sbix/SVG color Emojis
diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt
index 9d4edc26..ecce3c77 100644
--- a/docs/harfbuzz-sections.txt
+++ b/docs/harfbuzz-sections.txt
@@ -459,8 +459,12 @@ hb_color_get_blue
hb_color_get_green
hb_color_get_red
hb_ot_color_glyph_get_layers
+hb_ot_color_glyph_reference_blob_png
+hb_ot_color_glyph_reference_blob_svg
hb_ot_color_has_layers
hb_ot_color_has_palettes
+hb_ot_color_has_png
+hb_ot_color_has_svg
hb_ot_color_layer_t
hb_ot_color_palette_color_get_name_id
hb_ot_color_palette_flags_t
diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc
index 63fb5885..b622da89 100644
--- a/src/dump-emoji.cc
+++ b/src/dump-emoji.cc
@@ -295,8 +295,8 @@ main (int argc, char **argv)
sbix_dump (face);
-// if (hb_ot_color_has_svg (face))
- svg_dump (face);
+ if (hb_ot_color_has_svg (face))
+ svg_dump (face);
cairo_font_face_t *cairo_face;
{
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index 8150b5e7..fb6ca866 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -57,14 +57,12 @@ _get_colr (hb_face_t *face)
return *(hb_ot_face_data (face)->COLR.get ());
}
-#if 0
static inline const OT::CBDT_accelerator_t&
_get_cbdt (hb_face_t *face)
{
if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CBDT_accelerator_t);
return *(hb_ot_face_data (face)->CBDT.get ());
}
-#endif
static inline const OT::CPAL&
_get_cpal (hb_face_t *face)
@@ -73,7 +71,6 @@ _get_cpal (hb_face_t *face)
return *(hb_ot_face_data (face)->CPAL.get ());
}
-#if 0
static inline const OT::sbix_accelerator_t&
_get_sbix (hb_face_t *face)
{
@@ -87,7 +84,6 @@ _get_svg (hb_face_t *face)
if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::SVG_accelerator_t);
return *(hb_ot_face_data (face)->SVG.get ());
}
-#endif
/*
@@ -253,7 +249,6 @@ hb_ot_color_glyph_get_layers (hb_face_t *face,
}
-#if 0
/*
* SVG
*/
@@ -264,7 +259,7 @@ hb_ot_color_glyph_get_layers (hb_face_t *face,
*
* Returns: whether SVG table is available.
*
- * Since: DONTREPLACEME
+ * Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_svg (hb_face_t *face)
@@ -279,7 +274,7 @@ hb_ot_color_has_svg (hb_face_t *face)
*
* Returns: respective svg blob of the glyph, if available.
*
- * Since: DONTREPLACEME
+ * Since: REPLACEME
*/
hb_blob_t *
hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph)
@@ -298,7 +293,7 @@ hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph)
*
* Returns: whether either of CBDT or sbix tables is available.
*
- * Since: DONTREPLACEME
+ * Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_png (hb_face_t *face)
@@ -317,7 +312,7 @@ hb_ot_color_has_png (hb_face_t *face)
*
* Returns: respective png blob of the glyph, if available.
*
- * Since: DONTREPLACEME
+ * Since: REPLACEME
*/
hb_blob_t *
hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
@@ -343,29 +338,3 @@ hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
return blob;
}
-
-/* To be moved to public header */
-
-/*
- * SVG
- */
-
-HB_EXTERN hb_bool_t
-hb_ot_color_has_svg (hb_face_t *face);
-
-HB_EXTERN hb_blob_t *
-hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph);
-
-/*
- * PNG: CBDT or sbix
- */
-
-HB_EXTERN hb_bool_t
-hb_ot_color_has_png (hb_face_t *face);
-
-HB_EXTERN hb_blob_t *
-hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
- hb_codepoint_t glyph,
- unsigned int *strike_x_ppem,
- unsigned int *strike_y_ppem);
-#endif
diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h
index 6e4c1777..a8eae861 100644
--- a/src/hb-ot-color.h
+++ b/src/hb-ot-color.h
@@ -111,6 +111,30 @@ hb_ot_color_glyph_get_layers (hb_face_t *face,
unsigned int *count, /* IN/OUT. May be NULL. */
hb_ot_color_layer_t *layers /* OUT. May be NULL. */);
+/*
+ * SVG
+ */
+
+HB_EXTERN hb_bool_t
+hb_ot_color_has_svg (hb_face_t *face);
+
+HB_EXTERN hb_blob_t *
+hb_ot_color_glyph_reference_blob_svg (hb_face_t *face, hb_codepoint_t glyph);
+
+/*
+ * PNG: CBDT or sbix
+ */
+
+HB_EXTERN hb_bool_t
+hb_ot_color_has_png (hb_face_t *face);
+
+HB_EXTERN hb_blob_t *
+hb_ot_color_glyph_reference_blob_png (hb_font_t *font,
+ hb_codepoint_t glyph,
+ unsigned int *strike_x_ppem,
+ unsigned int *strike_y_ppem);
+
+
HB_END_DECLS
#endif /* HB_OT_COLOR_H */
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index 27409e10..51b901d2 100644
--- a/test/api/test-ot-color.c
+++ b/test/api/test-ot-color.c
@@ -363,7 +363,6 @@ test_hb_ot_color_has_data (void)
g_assert (hb_ot_color_has_palettes (sbix) == FALSE);
g_assert (hb_ot_color_has_palettes (svg) == FALSE);
-#if 0
g_assert (hb_ot_color_has_svg (empty) == FALSE);
g_assert (hb_ot_color_has_svg (cpal_v0) == FALSE);
g_assert (hb_ot_color_has_svg (cpal_v1) == FALSE);
@@ -379,10 +378,8 @@ test_hb_ot_color_has_data (void)
g_assert (hb_ot_color_has_png (cbdt) == TRUE);
g_assert (hb_ot_color_has_png (sbix) == TRUE);
g_assert (hb_ot_color_has_png (svg) == FALSE);
-#endif
}
-#if 0
static void
test_hb_ot_color_svg (void)
{
@@ -444,7 +441,6 @@ test_hb_ot_color_png (void)
hb_blob_destroy (blob);
hb_font_destroy (cbdt_font);
}
-#endif
int
main (int argc, char **argv)
@@ -472,8 +468,8 @@ main (int argc, char **argv)
hb_test_add (test_hb_ot_color_palette_color_get_name_id);
hb_test_add (test_hb_ot_color_glyph_get_layers);
hb_test_add (test_hb_ot_color_has_data);
-// hb_test_add (test_hb_ot_color_png);
-// hb_test_add (test_hb_ot_color_svg);
+ hb_test_add (test_hb_ot_color_png);
+ hb_test_add (test_hb_ot_color_svg);
status = hb_test_run();
hb_face_destroy (cpal_v0);
hb_face_destroy (cpal_v1);
More information about the HarfBuzz
mailing list