summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-22 02:43:58 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-12-22 02:43:58 +0000
commitde06bb288fb23a833e6813993f31248eee0680dd (patch)
tree14cf437b74f69c172ecf8bf90e274639391e3e26
parent254a11aefbd00a95e7a7e938b3044d171afe98df (diff)
parent9fe2853692bb64ded58a507d87508dc8536cd386 (diff)
downloadpango-de06bb288fb23a833e6813993f31248eee0680dd.tar.gz
Merge branch 'better-space-size' into 'main'
Add a private api to get the font size Closes #647 See merge request GNOME/pango!561
-rw-r--r--NEWS1
-rw-r--r--pango/fonts.c14
-rw-r--r--pango/pango-font-private.h8
-rw-r--r--pango/pangocairo-font.c43
-rw-r--r--pango/pangofc-font.c14
-rw-r--r--tests/layouts/no-space.layout10
-rw-r--r--tests/layouts/valid-14.layout4
7 files changed, 47 insertions, 47 deletions
diff --git a/NEWS b/NEWS
index bbf71cbe..908a4b33 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Overview of changes
* Revert a transformation change that broke metrics for vertical text
* Handle fonts without space glyph (such as icon fonts) better
* Fix some corner cases of line width accounting
+* Fix line height with emulated Small Caps
Overview of changes in 1.50.2, 10-16-2021
=========================================
diff --git a/pango/fonts.c b/pango/fonts.c
index 35527e7a..2054dd31 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1761,6 +1761,19 @@ pango_font_default_get_matrix (PangoFont *font,
*matrix = (PangoMatrix) PANGO_MATRIX_INIT;
}
+static int
+pango_font_default_get_absolute_size (PangoFont *font)
+{
+ PangoFontDescription *desc;
+ int size;
+
+ desc = pango_font_describe_with_absolute_size (font);
+ size = pango_font_description_get_size (desc);
+ pango_font_description_free (desc);
+
+ return size;
+}
+
static void
pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
{
@@ -1777,6 +1790,7 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
pclass->has_char = pango_font_default_has_char;
pclass->get_face = pango_font_default_get_face;
pclass->get_matrix = pango_font_default_get_matrix;
+ pclass->get_absolute_size = pango_font_default_get_absolute_size;
}
static void
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 1e38371d..885e38c1 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -47,6 +47,7 @@ typedef struct {
PangoFontFace * (* get_face) (PangoFont *font);
void (* get_matrix) (PangoFont *font,
PangoMatrix *matrix);
+ int (* get_absolute_size) (PangoFont *font);
} PangoFontClassPrivate;
gboolean pango_font_is_hinted (PangoFont *font);
@@ -55,7 +56,12 @@ void pango_font_get_scale_factors (PangoFont *font,
double *y_scale);
void pango_font_get_matrix (PangoFont *font,
PangoMatrix *matrix);
-
+static inline int pango_font_get_absolute_size (PangoFont *font)
+{
+ GTypeClass *klass = (GTypeClass *) PANGO_FONT_GET_CLASS (font);
+ PangoFontClassPrivate *priv = g_type_class_get_private (klass, PANGO_TYPE_FONT);
+ return priv->get_absolute_size (font);
+}
G_END_DECLS
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 02a976d8..5eb385d9 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -671,50 +671,15 @@ _pango_cairo_font_private_is_metrics_hinted (PangoCairoFontPrivate *cf_priv)
return cf_priv->is_hinted;
}
+
static void
get_space_extents (PangoCairoFontPrivate *cf_priv,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
- cairo_scaled_font_t *scaled_font;
- const char hexdigits[] = "0123456789ABCDEF";
- char c[2] = {0, 0};
- int i;
- double hex_width;
- int width;
- int n_chars;
-
- /* we don't render missing spaces as hex boxes,
- * so come up with some width to use. For lack
- * of anything better, use average hex digit width.
- */
-
- scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv);
- hex_width = 0;
- n_chars = 0;
- for (i = 0 ; i < 16 ; i++)
- {
- cairo_text_extents_t extents;
-
- c[0] = hexdigits[i];
- cairo_scaled_font_text_extents (scaled_font, c, &extents);
- if (extents.width > 0)
- {
- hex_width += extents.width;
- n_chars++;
- }
- }
-
- if (n_chars == 0)
- {
- cairo_font_extents_t extents;
-
- cairo_scaled_font_extents (scaled_font, &extents);
- hex_width += extents.max_x_advance;
- n_chars++;
- }
+ /* See https://docs.microsoft.com/en-us/typography/develop/character-design-standards/whitespace */
- width = pango_units_from_double (hex_width / n_chars);
+ int width = pango_font_get_absolute_size (PANGO_FONT (cf_priv->cfont)) / 2;
if (ink_rect)
{
@@ -934,7 +899,7 @@ _pango_cairo_font_private_get_glyph_extents (PangoCairoFontPrivate *cf_priv,
}
else if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
{
- _pango_cairo_font_private_get_glyph_extents_missing(cf_priv, glyph, ink_rect, logical_rect);
+ _pango_cairo_font_private_get_glyph_extents_missing (cf_priv, glyph, ink_rect, logical_rect);
return;
}
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 77e99e16..03f15efa 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -77,6 +77,7 @@ static void _pango_fc_font_get_scale_factors (PangoFont *fon
double *y_scale);
static void pango_fc_font_get_matrix (PangoFont *font,
PangoMatrix *matrix);
+static int pango_fc_font_get_absolute_size (PangoFont *font);
#define PANGO_FC_FONT_LOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->lock_face (font))
#define PANGO_FC_FONT_UNLOCK_FACE(font) (PANGO_FC_FONT_GET_CLASS (font)->unlock_face (font))
@@ -112,6 +113,7 @@ pango_fc_font_class_init (PangoFcFontClass *class)
pclass->is_hinted = _pango_fc_font_is_hinted;
pclass->get_scale_factors = _pango_fc_font_get_scale_factors;
pclass->get_matrix = pango_fc_font_get_matrix;
+ pclass->get_absolute_size = pango_fc_font_get_absolute_size;
/**
* PangoFcFont:pattern:
@@ -300,6 +302,18 @@ pango_fc_font_describe_absolute (PangoFont *font)
return desc;
}
+static int
+pango_fc_font_get_absolute_size (PangoFont *font)
+{
+ PangoFcFont *fcfont = (PangoFcFont *)font;
+ double size;
+
+ if (FcPatternGetDouble (fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) == FcResultMatch)
+ return (int) (size * PANGO_SCALE);
+
+ return 0;
+}
+
static PangoCoverage *
pango_fc_font_get_coverage (PangoFont *font,
PangoLanguage *language G_GNUC_UNUSED)
diff --git a/tests/layouts/no-space.layout b/tests/layouts/no-space.layout
index 7b62c2e1..646450c1 100644
--- a/tests/layouts/no-space.layout
+++ b/tests/layouts/no-space.layout
@@ -21,7 +21,7 @@
"is-wrapped" : false,
"is-ellipsized" : false,
"unknown-glyphs" : 4,
- "width" : 261120,
+ "width" : 130048,
"height" : 45056,
"log-attrs" : [
{
@@ -105,13 +105,13 @@
"glyphs" : [
{
"glyph" : 268435488,
- "width" : 54272,
+ "width" : 21504,
"is-cluster-start" : true,
"log-cluster" : 0
},
{
"glyph" : 268435488,
- "width" : 54272,
+ "width" : 21504,
"is-cluster-start" : true,
"log-cluster" : 1
},
@@ -123,13 +123,13 @@
},
{
"glyph" : 268435488,
- "width" : 54272,
+ "width" : 21504,
"is-cluster-start" : true,
"log-cluster" : 5
},
{
"glyph" : 268435488,
- "width" : 54272,
+ "width" : 21504,
"is-cluster-start" : true,
"log-cluster" : 6
}
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
index 593e538e..07c80f17 100644
--- a/tests/layouts/valid-14.layout
+++ b/tests/layouts/valid-14.layout
@@ -235,7 +235,7 @@
},
{
"glyph" : 1058,
- "width" : 6144,
+ "width" : 14336,
"log-cluster" : 0
}
]
@@ -267,7 +267,7 @@
"glyphs" : [
{
"glyph" : 268435488,
- "width" : 15360,
+ "width" : 7168,
"is-cluster-start" : true,
"log-cluster" : 0
}