[HarfBuzz] harfbuzz: Branch 'master' - 9 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Mon Oct 29 06:17:01 UTC 2018
src/hb-ot-color-cbdt-table.hh | 69 ++++++++++-----------
src/hb-ot-color-sbix-table.hh | 36 +++++++---
src/hb-ot-color.cc | 4 -
src/hb-ot-font.cc | 2
test/api/test-ot-color.c | 4 -
test/shaping/data/in-house/tests/color-fonts.tests | 2
6 files changed, 68 insertions(+), 49 deletions(-)
New commits:
commit 5eb251aab041d89b06b0d3f65906ff6712608263
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:16:13 2018 -0700
[cbdt] Implement strike selection logic
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index 21d6c6c8..ae6d3b5e 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -345,13 +345,28 @@ struct CBLC
protected:
const BitmapSizeTable &choose_strike (hb_font_t *font) const
{
- /* TODO: Make it possible to select strike. */
+ unsigned count = sizeTables.len;
+ if (unlikely (!count))
+ return Null(BitmapSizeTable);
- unsigned int count = sizeTables.len;
- for (uint32_t i = 0; i < count; ++i)
- return sizeTables[i];
+ unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
+ if (!requested_ppem)
+ requested_ppem = 1<<30; /* Choose largest strike. */
+ unsigned int best_i = 0;
+ unsigned int best_ppem = MAX (sizeTables[0].ppemX, sizeTables[0].ppemY);
- return Null(BitmapSizeTable);
+ for (unsigned int i = 1; i < count; i++)
+ {
+ unsigned int ppem = MAX (sizeTables[i].ppemX, sizeTables[i].ppemY);
+ if ((requested_ppem <= ppem && ppem < best_ppem) ||
+ (requested_ppem > best_ppem && ppem > best_ppem))
+ {
+ best_i = i;
+ best_ppem = ppem;
+ }
+ }
+
+ return sizeTables[best_i];
}
protected:
commit 98bddbc8ef3330bc5635f6255e6b9c16593a1934
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:14:15 2018 -0700
[sbix] Minor
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 4a14a69d..39f85129 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -182,7 +182,8 @@ struct sbix
inline const SBIXStrike &choose_strike (hb_font_t *font) const
{
- if (unlikely (!table->strikes.len))
+ unsigned count = table->strikes.len;
+ if (unlikely (!count))
return Null(SBIXStrike);
unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem);
@@ -192,7 +193,7 @@ struct sbix
unsigned int best_i = 0;
unsigned int best_ppem = table->get_strike (0).ppem;
- for (unsigned int i = 1; i < table->strikes.len; i++)
+ for (unsigned int i = 1; i < count; i++)
{
unsigned int ppem = (table->get_strike (i)).ppem;
if ((requested_ppem <= ppem && ppem < best_ppem) ||
commit 8cffee0577284839a24d9fb863206886d2373974
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:07:59 2018 -0700
[cbdt] Simplify more
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index c30f36c4..21d6c6c8 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -343,20 +343,14 @@ struct CBLC
}
protected:
- const BitmapSizeTable &choose_strike (hb_font_t *font,
- unsigned int *x_ppem, unsigned int *y_ppem) const
+ const BitmapSizeTable &choose_strike (hb_font_t *font) const
{
/* TODO: Make it possible to select strike. */
unsigned int count = sizeTables.len;
for (uint32_t i = 0; i < count; ++i)
- {
- *x_ppem = sizeTables[i].ppemX;
- *y_ppem = sizeTables[i].ppemY;
return sizeTables[i];
- }
- *x_ppem = *y_ppem = 0;
return Null(BitmapSizeTable);
}
@@ -403,11 +397,10 @@ struct CBDT
if (!cblc)
return false;
- unsigned int x_ppem, y_ppem;
const void *base;
- const BitmapSizeTable &strike = this->cblc->choose_strike (font, &x_ppem, &y_ppem);
+ const BitmapSizeTable &strike = this->cblc->choose_strike (font);
const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
- if (!subtable_record || !x_ppem || !y_ppem)
+ if (!subtable_record || !strike.ppemX || !strike.ppemY)
return false;
if (subtable_record->get_extents (extents, base))
@@ -439,8 +432,8 @@ struct CBDT
}
/* Convert to font units. */
- double x_scale = upem / (double) x_ppem;
- double y_scale = upem / (double) y_ppem;
+ double x_scale = upem / (double) strike.ppemX;
+ double y_scale = upem / (double) strike.ppemY;
extents->x_bearing = round (extents->x_bearing * x_scale);
extents->y_bearing = round (extents->y_bearing * y_scale);
extents->width = round (extents->width * x_scale);
@@ -455,11 +448,10 @@ struct CBDT
if (!cblc)
return hb_blob_get_empty ();
- unsigned int x_ppem, y_ppem;
const void *base;
- const BitmapSizeTable &strike = this->cblc->choose_strike (font, &x_ppem, &y_ppem);
+ const BitmapSizeTable &strike = this->cblc->choose_strike (font);
const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
- if (!subtable_record || !x_ppem || !y_ppem)
+ if (!subtable_record || !strike.ppemX || !strike.ppemY)
return hb_blob_get_empty ();
unsigned int image_offset = 0, image_length = 0, image_format = 0;
commit 574579d3766b7b42e62495cb9a98f3ffd91079e8
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:04:37 2018 -0700
[color] Rename get_strike() to choose_strike()
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index e6a78200..c30f36c4 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -343,8 +343,8 @@ struct CBLC
}
protected:
- const BitmapSizeTable &get_strike (hb_font_t *font,
- unsigned int *x_ppem, unsigned int *y_ppem) const
+ const BitmapSizeTable &choose_strike (hb_font_t *font,
+ unsigned int *x_ppem, unsigned int *y_ppem) const
{
/* TODO: Make it possible to select strike. */
@@ -405,7 +405,7 @@ struct CBDT
unsigned int x_ppem, y_ppem;
const void *base;
- const BitmapSizeTable &strike = this->cblc->get_strike (font, &x_ppem, &y_ppem);
+ const BitmapSizeTable &strike = this->cblc->choose_strike (font, &x_ppem, &y_ppem);
const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
if (!subtable_record || !x_ppem || !y_ppem)
return false;
@@ -457,7 +457,7 @@ struct CBDT
unsigned int x_ppem, y_ppem;
const void *base;
- const BitmapSizeTable &strike = this->cblc->get_strike (font, &x_ppem, &y_ppem);
+ const BitmapSizeTable &strike = this->cblc->choose_strike (font, &x_ppem, &y_ppem);
const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
if (!subtable_record || !x_ppem || !y_ppem)
return hb_blob_get_empty ();
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 7bde38a6..4a14a69d 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -172,15 +172,15 @@ struct sbix
int *y_offset,
unsigned int *available_ppem) const
{
- return get_strike (font).get_glyph_blob (glyph_id, sbix_blob,
- HB_TAG ('p','n','g',' '),
- x_offset, y_offset,
- num_glyphs, available_ppem);
+ return choose_strike (font).get_glyph_blob (glyph_id, sbix_blob,
+ HB_TAG ('p','n','g',' '),
+ x_offset, y_offset,
+ num_glyphs, available_ppem);
}
private:
- inline const SBIXStrike &get_strike (hb_font_t *font) const
+ inline const SBIXStrike &choose_strike (hb_font_t *font) const
{
if (unlikely (!table->strikes.len))
return Null(SBIXStrike);
commit 0aa90271fdbb2b85389cd5af029b6d4468fb8146
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:03:20 2018 -0700
[tests] Fix for recent rounding change in CBDT
diff --git a/test/shaping/data/in-house/tests/color-fonts.tests b/test/shaping/data/in-house/tests/color-fonts.tests
index e7311bc3..b325d78c 100644
--- a/test/shaping/data/in-house/tests/color-fonts.tests
+++ b/test/shaping/data/in-house/tests/color-fonts.tests
@@ -1 +1 @@
-../fonts/ee39587d13b2afa5499cc79e45780aa79293bbd4.ttf:--font-funcs=ot --show-extents:U+1F42F:[gid1=0+2963<0,2178,2963,-2788>]
+../fonts/ee39587d13b2afa5499cc79e45780aa79293bbd4.ttf:--font-funcs=ot --show-extents:U+1F42F:[gid1=0+2963<0,2179,2963,-2789>]
commit e2ba96da4c39ba5fe941bf2704c1e7cc5f98034f
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 23:01:57 2018 -0700
[cbdt] Refactor get_strike()
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index a02bbba2..e6a78200 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -343,26 +343,21 @@ struct CBLC
}
protected:
- const IndexSubtableRecord *find_table (hb_codepoint_t glyph,
- unsigned int *x_ppem, unsigned int *y_ppem,
- const void **base) const
+ const BitmapSizeTable &get_strike (hb_font_t *font,
+ unsigned int *x_ppem, unsigned int *y_ppem) const
{
/* TODO: Make it possible to select strike. */
unsigned int count = sizeTables.len;
for (uint32_t i = 0; i < count; ++i)
{
- unsigned int startGlyphIndex = sizeTables.arrayZ[i].startGlyphIndex;
- unsigned int endGlyphIndex = sizeTables.arrayZ[i].endGlyphIndex;
- if (startGlyphIndex <= glyph && glyph <= endGlyphIndex)
- {
- *x_ppem = sizeTables[i].ppemX;
- *y_ppem = sizeTables[i].ppemY;
- return sizeTables[i].find_table (glyph, this, base);
- }
+ *x_ppem = sizeTables[i].ppemX;
+ *y_ppem = sizeTables[i].ppemY;
+ return sizeTables[i];
}
- return nullptr;
+ *x_ppem = *y_ppem = 0;
+ return Null(BitmapSizeTable);
}
protected:
@@ -405,13 +400,13 @@ struct CBDT
inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
- unsigned int x_ppem = font->x_ppem, y_ppem = font->y_ppem;
-
if (!cblc)
return false;
+ unsigned int x_ppem, y_ppem;
const void *base;
- const IndexSubtableRecord *subtable_record = this->cblc->find_table (glyph, &x_ppem, &y_ppem, &base);
+ const BitmapSizeTable &strike = this->cblc->get_strike (font, &x_ppem, &y_ppem);
+ const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
if (!subtable_record || !x_ppem || !y_ppem)
return false;
@@ -454,23 +449,21 @@ struct CBDT
return true;
}
- inline hb_blob_t* reference_png (hb_codepoint_t glyph_id,
- unsigned int x_ppem,
- unsigned int y_ppem) const
+ inline hb_blob_t* reference_png (hb_font_t *font,
+ hb_codepoint_t glyph) const
{
if (!cblc)
return hb_blob_get_empty ();
- if (x_ppem == 0) x_ppem = upem;
- if (y_ppem == 0) y_ppem = upem;
-
+ unsigned int x_ppem, y_ppem;
const void *base;
- const IndexSubtableRecord *subtable_record = this->cblc->find_table (glyph_id, &x_ppem, &y_ppem, &base);
+ const BitmapSizeTable &strike = this->cblc->get_strike (font, &x_ppem, &y_ppem);
+ const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base);
if (!subtable_record || !x_ppem || !y_ppem)
return hb_blob_get_empty ();
unsigned int image_offset = 0, image_length = 0, image_format = 0;
- if (!subtable_record->get_image_data (glyph_id, base, &image_offset, &image_length, &image_format))
+ if (!subtable_record->get_image_data (glyph, base, &image_offset, &image_length, &image_format))
return hb_blob_get_empty ();
switch (image_format)
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index 0cade5e7..a3cd6190 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, nullptr);
if (!blob->length && _get_cbdt (font->face).has_data ())
- blob = _get_cbdt (font->face).reference_png (glyph, font->x_ppem, font->y_ppem);
+ blob = _get_cbdt (font->face).reference_png (font, glyph);
return blob;
}
commit 6983cca9c865752fe0a9a065f9b0278b686c3abc
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 22:46:18 2018 -0700
[cbdt] Minor
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index dab07a20..a02bbba2 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -408,7 +408,7 @@ struct CBDT
unsigned int x_ppem = font->x_ppem, y_ppem = font->y_ppem;
if (!cblc)
- return false; // Not a color bitmap font.
+ return false;
const void *base;
const IndexSubtableRecord *subtable_record = this->cblc->find_table (glyph, &x_ppem, &y_ppem, &base);
commit e998fb9fbfbd79b476d758238af60f6a4ddff20c
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Sun Oct 28 22:45:53 2018 -0700
[color] Round extents when scaling
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index cacabd07..dab07a20 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -443,11 +443,13 @@ struct CBDT
}
}
- /* Convert to the font units. */
- 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;
+ /* Convert to font units. */
+ double x_scale = upem / (double) x_ppem;
+ double y_scale = upem / (double) y_ppem;
+ extents->x_bearing = round (extents->x_bearing * x_scale);
+ extents->y_bearing = round (extents->y_bearing * y_scale);
+ extents->width = round (extents->width * x_scale);
+ extents->height = round (extents->height * y_scale);
return true;
}
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index fbe48ec0..7bde38a6 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -252,14 +252,14 @@ struct sbix
extents->width = png.IHDR.width;
extents->height = png.IHDR.height;
- /* Convert to the font units. */
+ /* Convert to font units. */
if (strike_ppem)
{
- unsigned int upem = font->face->upem;
- extents->x_bearing *= upem / (float) strike_ppem;
- extents->y_bearing *= upem / (float) strike_ppem;
- extents->width *= upem / (float) strike_ppem;
- extents->height *= upem / (float) strike_ppem;
+ double scale = font->face->upem / (double) strike_ppem;
+ extents->x_bearing = round (extents->x_bearing * scale);
+ extents->y_bearing = round (extents->y_bearing * scale);
+ extents->width = round (extents->width * scale);
+ extents->height = round (extents->height * scale);
}
hb_blob_destroy (blob);
commit c929ccfcea18c5c35d6d41ae921845eeffba978a
Author: Ebrahim Byagowi <ebrahim at gnu.org>
Date: Mon Oct 29 08:41:13 2018 +0330
[ot-color/png] Consider strike ppem on scaling
diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh
index 467159c7..cacabd07 100644
--- a/src/hb-ot-color-cbdt-table.hh
+++ b/src/hb-ot-color-cbdt-table.hh
@@ -402,9 +402,10 @@ struct CBDT
hb_blob_destroy (this->cbdt_blob);
}
- inline bool get_extents (hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
+ inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph,
+ hb_glyph_extents_t *extents) const
{
- unsigned int x_ppem = upem, y_ppem = upem; /* TODO Use font ppem if available. */
+ unsigned int x_ppem = font->x_ppem, y_ppem = font->y_ppem;
if (!cblc)
return false; // Not a color bitmap font.
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 40680ca2..fbe48ec0 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -74,7 +74,8 @@ struct SBIXStrike
hb_tag_t file_type,
int *x_offset,
int *y_offset,
- unsigned int num_glyphs) const
+ unsigned int num_glyphs,
+ unsigned int *strike_ppem) const
{
if (unlikely (!ppem)) return hb_blob_get_empty (); /* To get Null() object out of the way. */
@@ -109,6 +110,7 @@ struct SBIXStrike
if (unlikely (file_type != glyph->graphicType))
return hb_blob_get_empty ();
+ if (strike_ppem) *strike_ppem = ppem;
if (x_offset) *x_offset = glyph->xOffset;
if (y_offset) *y_offset = glyph->yOffset;
return hb_blob_create_sub_blob (sbix_blob, glyph_offset, glyph_length);
@@ -167,12 +169,13 @@ struct sbix
inline hb_blob_t *reference_png (hb_font_t *font,
hb_codepoint_t glyph_id,
int *x_offset,
- int *y_offset) const
+ int *y_offset,
+ unsigned int *available_ppem) const
{
return get_strike (font).get_glyph_blob (glyph_id, sbix_blob,
HB_TAG ('p','n','g',' '),
x_offset, y_offset,
- num_glyphs);
+ num_glyphs, available_ppem);
}
private:
@@ -236,7 +239,8 @@ struct sbix
return false;
int x_offset = 0, y_offset = 0;
- hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset);
+ unsigned int strike_ppem = 0;
+ hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
if (unlikely (blob->length < sizeof (PNGHeader)))
return false;
@@ -247,6 +251,17 @@ struct sbix
extents->y_bearing = y_offset;
extents->width = png.IHDR.width;
extents->height = png.IHDR.height;
+
+ /* Convert to the font units. */
+ if (strike_ppem)
+ {
+ unsigned int upem = font->face->upem;
+ extents->x_bearing *= upem / (float) strike_ppem;
+ extents->y_bearing *= upem / (float) strike_ppem;
+ extents->width *= upem / (float) strike_ppem;
+ extents->height *= upem / (float) strike_ppem;
+ }
+
hb_blob_destroy (blob);
return true;
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc
index b38e67c4..0cade5e7 100644
--- a/src/hb-ot-color.cc
+++ b/src/hb-ot-color.cc
@@ -318,7 +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_png (font, glyph, nullptr, nullptr);
+ blob = _get_sbix (font->face).reference_png (font, glyph, nullptr, nullptr, nullptr);
if (!blob->length && _get_cbdt (font->face).has_data ())
blob = _get_cbdt (font->face).reference_png (glyph, font->x_ppem, font->y_ppem);
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index e9619c54..33a4388c 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -187,7 +187,7 @@ hb_ot_get_glyph_extents (hb_font_t *font,
if (!ret)
ret = ot_face->glyf->get_extents (glyph, extents);
if (!ret)
- ret = ot_face->CBDT->get_extents (glyph, extents);
+ ret = ot_face->CBDT->get_extents (font, glyph, extents);
// TODO Hook up side-bearings variations.
extents->x_bearing = font->em_scale_x (extents->x_bearing);
extents->y_bearing = font->em_scale_y (extents->y_bearing);
diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c
index 9cc353ba..ba3a0abc 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, ==, 300);
- g_assert_cmpint (extents.height, ==, 300);
+ g_assert_cmpint (extents.width, ==, 800);
+ g_assert_cmpint (extents.height, ==, 800);
hb_blob_destroy (blob);
hb_font_destroy (sbix_font);
More information about the HarfBuzz
mailing list