[HarfBuzz] harfbuzz: Branch 'master' - 6 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Oct 11 11:35:48 UTC 2017
src/hb-coretext.cc | 86 ++++++++++++++++++++++-------------------------------
1 file changed, 36 insertions(+), 50 deletions(-)
New commits:
commit 7b23c286a71883ac3e5777a2dee262af48c76854
Merge: 8d450dd1 a5ebe1d4
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 11 13:35:32 2017 +0200
Merge branch 'coretext-optical-sizing'
Should fix https://github.com/behdad/harfbuzz/issues/360
commit a5ebe1d4aec41bc5e289a7969e5e5f7bb57733b6
Author: Dominik Röttsches <drott at chromium.org>
Date: Wed Oct 11 13:32:38 2017 +0200
[coretext] Recreate CTFont if pt size changed
Attempt at fixing #360
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 9b680abf..8219284d 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -71,8 +71,9 @@ hb_coretext_face_create (CGFontRef cg_font)
HB_SHAPER_DATA_ENSURE_DEFINE(coretext, face)
-HB_SHAPER_DATA_ENSURE_DEFINE(coretext, font)
-
+HB_SHAPER_DATA_ENSURE_DEFINE_WITH_CONDITION(coretext, font,
+ abs (CTFontGetSize((CTFontRef) data) -
+ (font->ptem < 0 ? HB_CORETEXT_FONT_SIZE : font->ptem)) < 1)
/*
* shaper face data
commit db7a73ce0781d1fec0235e419ac448565dcfc8ca
Author: Dominik Röttsches <drott at chromium.org>
Date: Wed Oct 11 13:24:39 2017 +0200
[coretext] Fix build
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 26cc07c9..9b680abf 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -241,7 +241,8 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
hb_coretext_shaper_font_data_t *
_hb_coretext_shaper_font_data_create (hb_font_t *font)
{
- if (unlikely (!hb_coretext_shaper_face_data_ensure (font->face))) return NULL;
+ hb_face_t *face = font->face;
+ if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL;
CGFontRef cg_font = (CGFontRef) HB_SHAPER_DATA_GET (face);
float ptem = font->ptem < 0 ? HB_CORETEXT_FONT_SIZE : font->ptem;
@@ -289,7 +290,7 @@ CTFontRef
hb_coretext_font_get_ct_font (hb_font_t *font)
{
if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return NULL;
- return (CTFontRef)_SHAPER_DATA_GET (font);
+ return (CTFontRef)HB_SHAPER_DATA_GET (font);
}
commit f33413075655e6383cd16bc31f0bf804dcec1c64
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 11 13:17:46 2017 +0200
[coretext] Another try
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 3f1c6711..26cc07c9 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -203,12 +203,10 @@ create_ct_font (CGFontRef cg_font, CGFloat font_size)
return ct_font;
}
-typedef CGFontRef hb_coretext_shaper_face_data_t;
-
hb_coretext_shaper_face_data_t *
_hb_coretext_shaper_face_data_create (hb_face_t *face)
{
- hb_coretext_shaper_face_data_t *cg_font = create_cg_font (face);
+ CGFontRef cg_font = create_cg_font (face);
if (unlikely (!cg_font))
{
@@ -216,13 +214,13 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face)
return NULL;
}
- return cg_font;
+ return (hb_coretext_shaper_face_data_t *) cg_font;
}
void
-_hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *cg_font)
+_hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data)
{
- CFRelease (cg_font);
+ CFRelease ((CGFontRef) data);
}
/*
@@ -232,8 +230,7 @@ CGFontRef
hb_coretext_face_get_cg_font (hb_face_t *face)
{
if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL;
- hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
- return cg_font;
+ return (CGFontRef) HB_SHAPER_DATA_GET (face);
}
@@ -241,17 +238,15 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
* shaper font data
*/
-typedef CTFontRef hb_coretext_shaper_font_data_t;
-
hb_coretext_shaper_font_data_t *
_hb_coretext_shaper_font_data_create (hb_font_t *font)
{
if (unlikely (!hb_coretext_shaper_face_data_ensure (font->face))) return NULL;
- hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
+ CGFontRef cg_font = (CGFontRef) HB_SHAPER_DATA_GET (face);
float ptem = font->ptem < 0 ? HB_CORETEXT_FONT_SIZE : font->ptem;
- hb_coretext_shaper_font_data_t *ct_font = create_ct_font (cg_font, ptem);
+ CTFontRef ct_font = create_ct_font (cg_font, ptem);
if (unlikely (!ct_font))
{
@@ -259,13 +254,13 @@ _hb_coretext_shaper_font_data_create (hb_font_t *font)
return NULL;
}
- return ct_font;
+ return (hb_coretext_shaper_font_data_t *) ct_font;
}
void
-_hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *ct_font)
+_hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *data)
{
- CFRelease (ct_font);
+ CFRelease ((CTFontRef) data);
}
@@ -294,8 +289,7 @@ CTFontRef
hb_coretext_font_get_ct_font (hb_font_t *font)
{
if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return NULL;
- hb_coretext_shaper_font_data_t *ct_font = HB_SHAPER_DATA_GET (font);
- return ct_font;
+ return (CTFontRef)_SHAPER_DATA_GET (font);
}
@@ -527,8 +521,8 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
unsigned int num_features)
{
hb_face_t *face = font->face;
- hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
- hb_coretext_shaper_font_data_t *ct_font = HB_SHAPER_DATA_GET (font);
+ CGFontRef cg_font = (CGFontRef) HB_SHAPER_DATA_GET (face);
+ CTFontRef ct_font = (CTFontRef) HB_SHAPER_DATA_GET (font);
CGFloat ct_font_size = CTFontGetSize (ct_font);
CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size;
commit a8e466c3c12a3499028cb576721e5f85ff4cbf2d
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 11 13:05:59 2017 +0200
[coretext] Move CT_Font to font data
Towards implementing optical sizing. Untested; won't compile.
https://github.com/behdad/harfbuzz/issues/360
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 10859e16..3f1c6711 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -203,51 +203,26 @@ create_ct_font (CGFontRef cg_font, CGFloat font_size)
return ct_font;
}
-struct hb_coretext_shaper_face_data_t {
- CGFontRef cg_font;
- CTFontRef ct_font;
-};
+typedef CGFontRef hb_coretext_shaper_face_data_t;
hb_coretext_shaper_face_data_t *
_hb_coretext_shaper_face_data_create (hb_face_t *face)
{
- hb_coretext_shaper_face_data_t *data = (hb_coretext_shaper_face_data_t *) calloc (1, sizeof (hb_coretext_shaper_face_data_t));
- if (unlikely (!data))
- return NULL;
+ hb_coretext_shaper_face_data_t *cg_font = create_cg_font (face);
- data->cg_font = create_cg_font (face);
- if (unlikely (!data->cg_font))
+ if (unlikely (!cg_font))
{
DEBUG_MSG (CORETEXT, face, "CGFont creation failed..");
- free (data);
- return NULL;
- }
-
- /* We use 36pt size instead of UPEM, because CoreText implements the 'trak' table,
- * which can make the font too tight at large sizes. 36pt should be a good semi-neutral
- * size.
- *
- * Since we always create CTFont at a fixed size, our CTFont lives in face_data
- * instead of font_data. Which is good, because when people change scale on
- * hb_font_t, we won't need to update our CTFont. */
- data->ct_font = create_ct_font (data->cg_font, HB_CORETEXT_FONT_SIZE);
- if (unlikely (!data->ct_font))
- {
- DEBUG_MSG (CORETEXT, face, "CTFont creation failed.");
- CFRelease (data->cg_font);
- free (data);
return NULL;
}
- return data;
+ return cg_font;
}
void
-_hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data)
+_hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *cg_font)
{
- CFRelease (data->ct_font);
- CFRelease (data->cg_font);
- free (data);
+ CFRelease (cg_font);
}
/*
@@ -257,8 +232,8 @@ CGFontRef
hb_coretext_face_get_cg_font (hb_face_t *face)
{
if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL;
- hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
- return face_data->cg_font;
+ hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
+ return cg_font;
}
@@ -266,17 +241,31 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
* shaper font data
*/
-struct hb_coretext_shaper_font_data_t {};
+typedef CTFontRef hb_coretext_shaper_font_data_t;
hb_coretext_shaper_font_data_t *
-_hb_coretext_shaper_font_data_create (hb_font_t *font HB_UNUSED)
+_hb_coretext_shaper_font_data_create (hb_font_t *font)
{
- return (hb_coretext_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
+ if (unlikely (!hb_coretext_shaper_face_data_ensure (font->face))) return NULL;
+ hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
+
+ float ptem = font->ptem < 0 ? HB_CORETEXT_FONT_SIZE : font->ptem;
+
+ hb_coretext_shaper_font_data_t *ct_font = create_ct_font (cg_font, ptem);
+
+ if (unlikely (!ct_font))
+ {
+ DEBUG_MSG (CORETEXT, font, "CGFont creation failed..");
+ return NULL;
+ }
+
+ return ct_font;
}
void
-_hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *data)
+_hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *ct_font)
{
+ CFRelease (ct_font);
}
@@ -304,10 +293,9 @@ _hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shaper_shape_plan_data_
CTFontRef
hb_coretext_font_get_ct_font (hb_font_t *font)
{
- hb_face_t *face = font->face;
- if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL;
- hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
- return face_data->ct_font;
+ if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return NULL;
+ hb_coretext_shaper_font_data_t *ct_font = HB_SHAPER_DATA_GET (font);
+ return ct_font;
}
@@ -539,9 +527,10 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
unsigned int num_features)
{
hb_face_t *face = font->face;
- hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
+ hb_coretext_shaper_face_data_t *cg_font = HB_SHAPER_DATA_GET (face);
+ hb_coretext_shaper_font_data_t *ct_font = HB_SHAPER_DATA_GET (font);
- CGFloat ct_font_size = CTFontGetSize (face_data->ct_font);
+ CGFloat ct_font_size = CTFontGetSize (ct_font);
CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size;
CGFloat y_mult = (CGFloat) font->y_scale / ct_font_size;
@@ -676,7 +665,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
CTFontDescriptorRef font_desc = CTFontDescriptorCreateWithAttributes (attributes);
CFRelease (attributes);
- range->font = CTFontCreateCopyWithAttributes (face_data->ct_font, 0.0, NULL, font_desc);
+ range->font = CTFontCreateCopyWithAttributes (ct_font, 0.0, NULL, font_desc);
CFRelease (font_desc);
}
else
@@ -830,7 +819,7 @@ resize_and_retry:
CFRelease (lang);
}
CFAttributedStringSetAttribute (attr_string, CFRangeMake (0, chars_len),
- kCTFontAttributeName, face_data->ct_font);
+ kCTFontAttributeName, ct_font);
if (num_features && range_records.len)
{
@@ -948,7 +937,7 @@ resize_and_retry:
*/
CFDictionaryRef attributes = CTRunGetAttributes (run);
CTFontRef run_ct_font = static_cast<CTFontRef>(CFDictionaryGetValue (attributes, kCTFontAttributeName));
- if (!CFEqual (run_ct_font, face_data->ct_font))
+ if (!CFEqual (run_ct_font, ct_font))
{
/* The run doesn't use our main font instance. We have to figure out
* whether font fallback happened, or this is just CoreText giving us
@@ -986,13 +975,13 @@ resize_and_retry:
CGFontRef run_cg_font = CTFontCopyGraphicsFont (run_ct_font, 0);
if (run_cg_font)
{
- matched = CFEqual (run_cg_font, face_data->cg_font);
+ matched = CFEqual (run_cg_font, cg_font);
CFRelease (run_cg_font);
}
}
if (!matched)
{
- CFStringRef font_ps_name = CTFontCopyName (face_data->ct_font, kCTFontPostScriptNameKey);
+ CFStringRef font_ps_name = CTFontCopyName (ct_font, kCTFontPostScriptNameKey);
CFStringRef run_ps_name = CTFontCopyName (run_ct_font, kCTFontPostScriptNameKey);
CFComparisonResult result = CFStringCompare (run_ps_name, font_ps_name, 0);
CFRelease (run_ps_name);
commit f9b4c6570a4725eec5393f86e6468a189ac8c6be
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Oct 11 12:51:25 2017 +0200
[coretext] Move font size to a macro
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 5c0b65af..10859e16 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -36,6 +36,7 @@
#define HB_DEBUG_CORETEXT (HB_DEBUG+0)
#endif
+#define HB_CORETEXT_FONT_SIZE 18.0
static void
release_table_data (void *user_data)
@@ -229,7 +230,7 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face)
* Since we always create CTFont at a fixed size, our CTFont lives in face_data
* instead of font_data. Which is good, because when people change scale on
* hb_font_t, we won't need to update our CTFont. */
- data->ct_font = create_ct_font (data->cg_font, 18.);
+ data->ct_font = create_ct_font (data->cg_font, HB_CORETEXT_FONT_SIZE);
if (unlikely (!data->ct_font))
{
DEBUG_MSG (CORETEXT, face, "CTFont creation failed.");
More information about the HarfBuzz
mailing list