native-libs: patches to adjust Pango font-face matching

This commit is contained in:
Matthew Flatt 2019-02-14 08:57:51 -07:00
parent ecf3766d96
commit e7e9d02c9e
3 changed files with 86 additions and 1 deletions

View File

@ -141,6 +141,12 @@
;; Merge a Pango patch that fixes a decoding problem
(define-runtime-path pango-emojiiter-patch "patches/pango-emojiiter.patch")
;; Allow more flexible font matching
(define-runtime-path pango-match-patch "patches/pango-match.patch")
;; Detect oblique before italic on Mac OS
(define-runtime-path pango-preferoblique-patch "patches/pango-preferoblique.patch")
;; Needed when building with old GCC, such as 4.0:
(define-runtime-path gmp-weak-patch "patches/gmp-weak.patch")
@ -533,7 +539,11 @@
coretext-fontreg-patch
coretext-nullarray
win32text-patch
pango-emojiiter-patch)
pango-emojiiter-patch
pango-match-patch)
(if mac?
(list pango-preferoblique-patch)
null)
(if (and mac? m32?)
(list pango-surrogate-patch)
null)

View File

@ -0,0 +1,57 @@
diff -u -r old/pango-1.42.0/pango/fonts.c new/pango-1.42.0/pango/fonts.c
--- old/pango-1.42.0/pango/fonts.c 2018-01-03 10:48:10.000000000 -0700
+++ new/pango-1.42.0/pango/fonts.c 2019-02-14 06:44:15.000000000 -0700
@@ -718,19 +718,30 @@
compute_distance (const PangoFontDescription *a,
const PangoFontDescription *b)
{
- if (a->style == b->style)
- {
- return abs((int)(a->weight) - (int)(b->weight));
- }
- else if (a->style != PANGO_STYLE_NORMAL &&
- b->style != PANGO_STYLE_NORMAL)
- {
- /* Equate oblique and italic, but with a big penalty
- */
- return 1000000 + abs ((int)(a->weight) - (int)(b->weight));
- }
- else
- return G_MAXINT;
+ gint dist;
+
+ dist = abs((int)(a->weight) - (int)(b->weight));
+
+ if (a->variant != b->variant)
+ dist += 10000;
+
+ if (a->stretch != b->stretch)
+ dist += 1000 * abs((int)a->stretch - (int)b->stretch);
+
+ if (a->style != b->style) {
+ if (a->style != PANGO_STYLE_NORMAL &&
+ b->style != PANGO_STYLE_NORMAL)
+ /* Equate oblique and italic, but with a modest penalty */
+ dist += 10000;
+ else
+ /* Normal and oblique/italic has a larger penalty */
+ dist += 20000;
+ }
+
+ if (a->gravity != b->gravity)
+ dist += 100000;
+
+ return dist;
}
/**
@@ -761,9 +772,6 @@
g_return_val_if_fail (desc != NULL, G_MAXINT);
g_return_val_if_fail (new_match != NULL, G_MAXINT);
- if (new_match->variant == desc->variant &&
- new_match->stretch == desc->stretch &&
- new_match->gravity == desc->gravity)
{
int old_distance = old_match ? compute_distance (desc, old_match) : G_MAXINT;
int new_distance = compute_distance (desc, new_match);

View File

@ -0,0 +1,18 @@
diff -r -u old/pango-1.42.0/pango/pangocoretext-fontmap.c new/pango-1.42.0/pango/pangocoretext-fontmap.c
--- old/pango-1.42.0/pango/pangocoretext-fontmap.c 2017-08-15 15:53:10.000000000 -0600
+++ new/pango-1.42.0/pango/pangocoretext-fontmap.c 2019-02-14 08:33:52.000000000 -0700
@@ -415,10 +415,10 @@
font_traits = ct_font_descriptor_get_traits (desc);
style_name = ct_font_descriptor_get_style_name (desc);
- if ((font_traits & kCTFontItalicTrait) == kCTFontItalicTrait)
- pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
- else if (pango_core_text_style_name_is_oblique (style_name))
+ if (pango_core_text_style_name_is_oblique (style_name))
pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
+ else if ((font_traits & kCTFontItalicTrait) == kCTFontItalicTrait)
+ pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
else
pango_font_description_set_style (font_desc, PANGO_STYLE_NORMAL);
Only in new/pango-1.42.0/pango: pangocoretext-fontmap.c~