Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
pango
Commits
84ff272e
Commit
84ff272e
authored
Nov 26, 2021
by
Matthias Clasen
Browse files
Merge branch 'hinted-metrics-fixes' into 'main'
Hinted metrics fixes Closes
#626
See merge request
!518
parents
f37d293b
8c51a367
Pipeline
#336901
failed with stages
in 7 minutes and 30 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pango/pango-types.h
View file @
84ff272e
...
...
@@ -106,6 +106,32 @@ typedef guint32 PangoGlyph;
* PANGO_PIXELS also behaves differently for +512 and -512.
*/
/**
* PANGO_UNITS_FLOOR:
* @d: a dimension in Pango units.
*
* Rounds a dimension down to whole device units, but does not
* convert it to device units.
*
* Return value: rounded down dimension in Pango units.
* Since: 1.50
*/
#define PANGO_UNITS_FLOOR(d) \
((d) & ~(PANGO_SCALE - 1))
/**
* PANGO_UNITS_CEIL:
* @d: a dimension in Pango units.
*
* Rounds a dimension up to whole device units, but does not
* convert it to device units.
*
* Return value: rounded up dimension in Pango units.
* Since: 1.50
*/
#define PANGO_UNITS_CEIL(d) \
(((d) + (PANGO_SCALE - 1)) & ~(PANGO_SCALE - 1))
/**
* PANGO_UNITS_ROUND:
* @d: a dimension in Pango units.
...
...
pango/pangocairo-font.c
View file @
84ff272e
...
...
@@ -817,13 +817,13 @@ _pango_cairo_font_private_glyph_extents_cache_init (PangoCairoFontPrivate *cf_pr
if
(
cf_priv
->
is_hinted
)
{
if
(
cf_priv
->
font_extents
.
y
<
0
)
cf_priv
->
font_extents
.
y
=
PANGO_UNITS_
ROUND
(
cf_priv
->
font_extents
.
y
-
PANGO_SCALE
/
2
);
cf_priv
->
font_extents
.
y
=
PANGO_UNITS_
FLOOR
(
cf_priv
->
font_extents
.
y
);
else
cf_priv
->
font_extents
.
y
=
PANGO_UNITS_
ROUND
(
cf_priv
->
font_extents
.
y
+
PANGO_SCALE
/
2
);
cf_priv
->
font_extents
.
y
=
PANGO_UNITS_
CEIL
(
cf_priv
->
font_extents
.
y
);
if
(
cf_priv
->
font_extents
.
height
<
0
)
cf_priv
->
font_extents
.
height
=
PANGO_UNITS_
ROUND
(
cf_priv
->
font_extents
.
height
-
PANGO_SCALE
/
2
);
cf_priv
->
font_extents
.
height
=
PANGO_UNITS_
FLOOR
(
extents
.
ascender
)
-
PANGO_UNITS_CEIL
(
extents
.
descender
);
else
cf_priv
->
font_extents
.
height
=
PANGO_UNITS_
ROUND
(
cf_priv
->
font_extents
.
height
+
PANGO_SCALE
/
2
);
cf_priv
->
font_extents
.
height
=
PANGO_UNITS_
CEIL
(
extents
.
ascender
)
-
PANGO_UNITS_FLOOR
(
extents
.
descender
);
}
if
(
PANGO_GRAVITY_IS_IMPROPER
(
cf_priv
->
gravity
))
...
...
tests/testmisc.c
View file @
84ff272e
...
...
@@ -634,9 +634,11 @@ test_empty_line_height (void)
{
PangoContext
*
context
;
PangoLayout
*
layout
;
PangoFontDescription
*
description
;
PangoRectangle
ext1
,
ext2
,
ext3
;
cairo_font_options_t
*
options
;
int
hint
;
int
size
;
if
(
strcmp
(
G_OBJECT_TYPE_NAME
(
pango_cairo_font_map_get_default
()),
"PangoCairoCoreTextFontMap"
)
==
0
)
{
...
...
@@ -645,33 +647,41 @@ test_empty_line_height (void)
}
context
=
pango_font_map_create_context
(
pango_cairo_font_map_get_default
());
description
=
pango_font_description_new
();
for
(
hint
=
CAIRO_HINT_METRICS_OFF
;
hint
<=
CAIRO_HINT_METRICS_ON
;
hint
++
)
for
(
size
=
10
;
size
<=
20
;
size
++
)
{
options
=
cairo_font_options_create
();
cairo_font_options_set_hint_metrics
(
options
,
hint
);
pango_cairo_context_set_font_options
(
context
,
options
);
cairo_font_options_destroy
(
options
);
pango_font_description_set_size
(
description
,
size
);
layout
=
pango_layout_new
(
context
);
for
(
hint
=
CAIRO_HINT_METRICS_OFF
;
hint
<=
CAIRO_HINT_METRICS_ON
;
hint
++
)
{
options
=
cairo_font_options_create
();
cairo_font_options_set_hint_metrics
(
options
,
hint
);
pango_cairo_context_set_font_options
(
context
,
options
);
cairo_font_options_destroy
(
options
);
pango_layout_get_extents
(
layout
,
NULL
,
&
ext1
);
layout
=
pango_layout_new
(
context
);
pango_layout_set_font_description
(
layout
,
description
);
pango_layout_
s
et_
t
ext
(
layout
,
"a"
,
1
);
pango_layout_
g
et_ext
ents
(
layout
,
NULL
,
&
ext
1
);
pango_layout_
g
et_ext
ents
(
layout
,
NULL
,
&
ext2
);
pango_layout_
s
et_
t
ext
(
layout
,
"a"
,
1
);
g_assert_cmpint
(
ext1
.
height
,
==
,
ext2
.
height
);
pango_layout_get_extents
(
layout
,
NULL
,
&
ext2
);
pango_layout_
set_
text
(
layout
,
"Pg"
,
1
);
g_as
se
r
t_
cmpint
(
ext1
.
height
,
==
,
ext2
.
height
);
pango_layout_
g
et_ext
ents
(
layout
,
NULL
,
&
ext3
);
pango_layout_
s
et_
t
ext
(
layout
,
"Pg"
,
1
);
g_assert_cmpint
(
ext2
.
height
,
==
,
ext3
.
height
);
pango_layout_get_extents
(
layout
,
NULL
,
&
ext3
);
g_object_unref
(
layout
);
g_assert_cmpint
(
ext2
.
height
,
==
,
ext3
.
height
);
g_object_unref
(
layout
);
}
}
pango_font_description_free
(
description
);
g_object_unref
(
context
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment