diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-08-03 20:35:30 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-08-03 20:35:30 +0000 |
commit | 55748a5a4bf928338cf704a3f955a5bdeef1fcd4 (patch) | |
tree | 0a366fb3a5576530ca62292db6e6244d53391ef0 | |
parent | 519c36733acb31a15c9f416f845c7887bfe64121 (diff) | |
parent | c3c030744fe75b987455a0e999bf12158c0a24a0 (diff) | |
download | pango-55748a5a4bf928338cf704a3f955a5bdeef1fcd4.tar.gz |
Merge branch 'round-glyphs-option' into 'master'
Round glyphs option
See merge request GNOME/pango!120
-rw-r--r-- | .gitlab-ci/render-msys2.sh | 2 | ||||
-rw-r--r-- | docs/pango-sections.txt | 4 | ||||
-rw-r--r-- | pango/pango-context.c | 46 | ||||
-rw-r--r-- | pango/pango-context.h | 7 | ||||
-rw-r--r-- | pango/pango-glyph.h | 45 | ||||
-rw-r--r-- | pango/pango-layout.c | 12 | ||||
-rw-r--r-- | pango/shape.c | 93 | ||||
-rw-r--r-- | tests/test-harfbuzz.c | 5 | ||||
-rw-r--r-- | utils/viewer-pangocairo.c | 4 | ||||
-rw-r--r-- | utils/viewer-render.c | 3 | ||||
-rw-r--r-- | utils/viewer-render.h | 1 |
11 files changed, 185 insertions, 37 deletions
diff --git a/.gitlab-ci/render-msys2.sh b/.gitlab-ci/render-msys2.sh index f81f0c60..8d13e9bc 100644 --- a/.gitlab-ci/render-msys2.sh +++ b/.gitlab-ci/render-msys2.sh @@ -2,4 +2,4 @@ set -e -PATH=_build/pango:$PATH _build/utils/pango-view --no-display --output _build/hello.png utils/HELLO.txt +PATH=_build/pango:$PATH gdb --eval-command=run --args _build/utils/pango-view --no-display --output _build/hello.png utils/HELLO.txt diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index 78a6b4cb..7a95d401 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -30,6 +30,8 @@ PangoLogAttr <SUBSECTION> pango_shape pango_shape_full +PangoShapeFlags +pango_shape_with_flags <SUBSECTION Standard> PANGO_TYPE_ITEM @@ -60,6 +62,8 @@ pango_context_get_gravity_hint pango_context_set_gravity_hint pango_context_get_matrix pango_context_set_matrix +pango_context_get_round_glyph_positions +pango_context_set_round_glyph_positions pango_context_load_font pango_context_load_fontset pango_context_get_metrics diff --git a/pango/pango-context.c b/pango/pango-context.c index 6ba64ce1..99fa454a 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -79,6 +79,8 @@ struct _PangoContext PangoMatrix *matrix; PangoFontMap *font_map; + + gboolean round_glyph_positions; }; struct _PangoContextClass @@ -103,6 +105,7 @@ pango_context_init (PangoContext *context) context->set_language = NULL; context->language = pango_language_get_default (); context->font_map = NULL; + context->round_glyph_positions = TRUE; context->font_desc = pango_font_description_new (); pango_font_description_set_family_static (context->font_desc, "serif"); @@ -1857,3 +1860,46 @@ pango_context_get_serial (PangoContext *context) check_fontmap_changed (context); return context->serial; } + +/** + * pango_context_set_round_glyph_positions: + * @context: a #PangoContext + * @round_positions: whether to round glyph positions + * + * Sets whether font rendering with this context should + * round glyph positions and widths to integral positions, + * in device units. + * + * This is useful when the renderer can't handle subpixel + * positioning of glyphs. + * + * The default value is to round glyph positions, to remain + * compatible with previous Pango behavior. + * + * Since: 1.44 + */ +void +pango_context_set_round_glyph_positions (PangoContext *context, + gboolean round_positions) +{ + if (context->round_glyph_positions != round_positions) + { + context->round_glyph_positions = round_positions; + context_changed (context); + } +} + +/** + * pango_context_get_round_glyph_positions: + * @context: a #PangoContext + * + * Returns whether font rendering with this context should + * round glyph positions and widths. + * + * Since: 1.44 + */ +gboolean +pango_context_get_round_glyph_positions (PangoContext *context) +{ + return context->round_glyph_positions; +} diff --git a/pango/pango-context.h b/pango/pango-context.h index af934491..0f775ff4 100644 --- a/pango/pango-context.h +++ b/pango/pango-context.h @@ -113,6 +113,13 @@ void pango_context_set_matrix (PangoContext PANGO_AVAILABLE_IN_1_6 const PangoMatrix * pango_context_get_matrix (PangoContext *context); +PANGO_AVAILABLE_IN_1_44 +void pango_context_set_round_glyph_positions (PangoContext *context, + gboolean round_positions); +PANGO_AVAILABLE_IN_1_44 +gboolean pango_context_get_round_glyph_positions (PangoContext *context); + + /* Break a string of Unicode characters into segments with * consistent shaping/language engine and bidrectional level. * Returns a #GList of #PangoItem's diff --git a/pango/pango-glyph.h b/pango/pango-glyph.h index 917ec570..628eac96 100644 --- a/pango/pango-glyph.h +++ b/pango/pango-glyph.h @@ -189,18 +189,43 @@ void pango_glyph_string_x_to_index (PangoGlyphString *glyphs, /* Turn a string of characters into a string of glyphs */ PANGO_AVAILABLE_IN_ALL -void pango_shape (const gchar *text, - gint length, - const PangoAnalysis *analysis, - PangoGlyphString *glyphs); +void pango_shape (const char *text, + int length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs); PANGO_AVAILABLE_IN_1_32 -void pango_shape_full (const gchar *item_text, - gint item_length, - const gchar *paragraph_text, - gint paragraph_length, - const PangoAnalysis *analysis, - PangoGlyphString *glyphs); +void pango_shape_full (const char *item_text, + int item_length, + const char *paragraph_text, + int paragraph_length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs); + +/** + * PangoShapeFlags: + * @PANGO_SHAPE_NONE: Default value. + * @PANGO_SHAPE_ROUND_POSITIONS: Round glyph positions + * and widths to whole device units. This option should + * be set if the target renderer can't do subpixel + * positioning of glyphs. + * + * Flags influencing the shaping process. + * These can be passed to pango_shape_with_flags(). + */ +typedef enum { + PANGO_SHAPE_NONE = 0, + PANGO_SHAPE_ROUND_POSITIONS = 1 << 0, +} PangoShapeFlags; + +PANGO_AVAILABLE_IN_1_44 +void pango_shape_with_flags (const char *item_text, + int item_length, + const char *paragraph_text, + int paragraph_length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs, + PangoShapeFlags flags); PANGO_AVAILABLE_IN_ALL GList *pango_reorder_items (GList *logical_items); diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 521f806a..0ddb6e14 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3354,14 +3354,20 @@ shape_run (PangoLayoutLine *line, shape_tab (line, item, glyphs); else { + PangoShapeFlags shape_flags = PANGO_SHAPE_NONE; + + if (pango_context_get_round_glyph_positions (layout->context)) + shape_flags |= PANGO_SHAPE_ROUND_POSITIONS; + if (state->properties.shape_set) _pango_shape_shape (layout->text + item->offset, item->num_chars, state->properties.shape_ink_rect, state->properties.shape_logical_rect, glyphs); else - pango_shape_full (layout->text + item->offset, item->length, - layout->text, layout->length, - &item->analysis, glyphs); + pango_shape_with_flags (layout->text + item->offset, item->length, + layout->text, layout->length, + &item->analysis, glyphs, + shape_flags); if (state->properties.letter_spacing) { diff --git a/pango/shape.c b/pango/shape.c index cb969e67..efdb3177 100644 --- a/pango/shape.c +++ b/pango/shape.c @@ -55,14 +55,51 @@ * boundaries. */ void -pango_shape (const gchar *text, - gint length, +pango_shape (const gchar *text, + gint length, const PangoAnalysis *analysis, - PangoGlyphString *glyphs) + PangoGlyphString *glyphs) { pango_shape_full (text, length, text, length, analysis, glyphs); } +/** + * pango_shape_full: + * @item_text: valid UTF-8 text to shape. + * @item_length: the length (in bytes) of @item_text. -1 means nul-terminated text. + * @paragraph_text: (allow-none): text of the paragraph (see details). May be %NULL. + * @paragraph_length: the length (in bytes) of @paragraph_text. -1 means nul-terminated text. + * @analysis: #PangoAnalysis structure from pango_itemize(). + * @glyphs: glyph string in which to store results. + * + * Given a segment of text and the corresponding + * #PangoAnalysis structure returned from pango_itemize(), + * convert the characters into glyphs. You may also pass + * in only a substring of the item from pango_itemize(). + * + * This is similar to pango_shape(), except it also can optionally take + * the full paragraph text as input, which will then be used to perform + * certain cross-item shaping interactions. If you have access to the broader + * text of which @item_text is part of, provide the broader text as + * @paragraph_text. If @paragraph_text is %NULL, item text is used instead. + * + * Since: 1.32 + */ +void +pango_shape_full (const char *item_text, + int item_length, + const char *paragraph_text, + int paragraph_length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs) +{ + pango_shape_with_flags (item_text, item_length, + paragraph_text, paragraph_length, + analysis, + glyphs, + PANGO_SHAPE_NONE); +} + static void fallback_shape (const char *text, unsigned int length, @@ -113,34 +150,36 @@ fallback_shape (const char *text, } /** - * pango_shape_full: - * @item_text: valid UTF-8 text to shape. - * @item_length: the length (in bytes) of @item_text. -1 means nul-terminated text. - * @paragraph_text: (allow-none): text of the paragraph (see details). May be %NULL. - * @paragraph_length: the length (in bytes) of @paragraph_text. -1 means nul-terminated text. - * @analysis: #PangoAnalysis structure from pango_itemize(). - * @glyphs: glyph string in which to store results. + * pango_shape_with_flags: + * @item_text: valid UTF-8 text to shape + * @item_length: the length (in bytes) of @item_text. + * -1 means nul-terminated text. + * @paragraph_text: (allow-none): text of the paragraph (see details). + * May be %NULL. + * @paragraph_length: the length (in bytes) of @paragraph_text. + * -1 means nul-terminated text. + * @analysis: #PangoAnalysis structure from pango_itemize() + * @glyphs: glyph string in which to store results + * @flags: flags influencing the shaping process * * Given a segment of text and the corresponding * #PangoAnalysis structure returned from pango_itemize(), * convert the characters into glyphs. You may also pass * in only a substring of the item from pango_itemize(). * - * This is similar to pango_shape(), except it also can optionally take - * the full paragraph text as input, which will then be used to perform - * certain cross-item shaping interactions. If you have access to the broader - * text of which @item_text is part of, provide the broader text as - * @paragraph_text. If @paragraph_text is %NULL, item text is used instead. + * This is similar to pango_shape_full(), except it also takes + * flags that can influence the shaping process. * - * Since: 1.32 + * Since: 1.44 */ void -pango_shape_full (const gchar *item_text, - gint item_length, - const gchar *paragraph_text, - gint paragraph_length, - const PangoAnalysis *analysis, - PangoGlyphString *glyphs) +pango_shape_with_flags (const gchar *item_text, + gint item_length, + const gchar *paragraph_text, + gint paragraph_length, + const PangoAnalysis *analysis, + PangoGlyphString *glyphs, + PangoShapeFlags flags) { int i; int last_cluster; @@ -243,4 +282,14 @@ pango_shape_full (const gchar *item_text, /* *Fix* it so we don't crash later */ pango_glyph_string_reverse_range (glyphs, 0, glyphs->num_glyphs); } + + if (flags & PANGO_SHAPE_ROUND_POSITIONS) + { + for (i = 0; i < glyphs->num_glyphs; i++) + { + glyphs->glyphs[i].geometry.width = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.width ); + glyphs->glyphs[i].geometry.x_offset = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.x_offset); + glyphs->glyphs[i].geometry.y_offset = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.y_offset); + } + } } diff --git a/tests/test-harfbuzz.c b/tests/test-harfbuzz.c index f9392b67..cba9026c 100644 --- a/tests/test-harfbuzz.c +++ b/tests/test-harfbuzz.c @@ -37,7 +37,10 @@ test_hb_font (void) hb_bool_t res; hb_codepoint_t glyph; - desc = pango_font_description_from_string ("Cantarell 11"); + if (strcmp (G_OBJECT_TYPE_NAME (pango_context_get_font_map (context)), "PangoCairoWin32FontMap") == 0) + desc = pango_font_description_from_string ("Verdana 11"); + else + desc = pango_font_description_from_string ("Cantarell 11"); font = pango_context_load_font (context, desc); hb_font = pango_font_get_hb_font (font); diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c index f82bd72d..ac3b49c3 100644 --- a/utils/viewer-pangocairo.c +++ b/utils/viewer-pangocairo.c @@ -36,6 +36,7 @@ typedef struct PangoFontMap *fontmap; cairo_font_options_t *font_options; + gboolean subpixel_positions; } CairoViewer; static gpointer @@ -73,6 +74,8 @@ pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED) if (opt_antialias != ANTIALIAS_DEFAULT) cairo_font_options_set_antialias (instance->font_options, (cairo_antialias_t)opt_antialias); + instance->subpixel_positions = opt_subpixel_positions; + return instance; } @@ -100,6 +103,7 @@ pangocairo_view_get_context (gpointer instance) context = pango_font_map_create_context (c->fontmap); pango_cairo_context_set_font_options (context, c->font_options); + pango_context_set_round_glyph_positions (context, !c->subpixel_positions); return context; } diff --git a/utils/viewer-render.c b/utils/viewer-render.c index 36cee596..82b30f05 100644 --- a/utils/viewer-render.c +++ b/utils/viewer-render.c @@ -63,6 +63,7 @@ HintMode opt_hinting = HINT_DEFAULT; HintMetrics opt_hint_metrics = HINT_METRICS_DEFAULT; SubpixelOrder opt_subpixel_order = SUBPIXEL_DEFAULT; Antialias opt_antialias = ANTIALIAS_DEFAULT; +gboolean opt_subpixel_positions = FALSE; PangoWrapMode opt_wrap = PANGO_WRAP_WORD_CHAR; gboolean opt_wrap_set = FALSE; static const char *opt_pangorc = NULL; /* Unused */ @@ -800,6 +801,8 @@ parse_options (int argc, char *argv[]) "Antialiasing", "none/gray/subpixel"}, {"hint-metrics", 0, 0, G_OPTION_ARG_CALLBACK, &parse_hint_metrics, "Hint metrics", "on/off"}, + { "subpixel-positions", 0, 0, G_OPTION_ARG_NONE, &opt_subpixel_positions, + "Subpixel positioning", NULL}, {"subpixel-order", 0, 0, G_OPTION_ARG_CALLBACK, &parse_subpixel_order, "Subpixel order", "rgb/bgr/vrgb/vbgr"}, {"indent", 0, 0, G_OPTION_ARG_INT, &opt_indent, diff --git a/utils/viewer-render.h b/utils/viewer-render.h index bfb50e55..3ffc42e4 100644 --- a/utils/viewer-render.h +++ b/utils/viewer-render.h @@ -107,6 +107,7 @@ extern HintMode opt_hinting; extern SubpixelOrder opt_subpixel_order; extern Antialias opt_antialias; extern HintMetrics opt_hint_metrics; +extern gboolean opt_subpixel_positions; extern PangoColor opt_fg_color; extern guint16 opt_fg_alpha; extern gboolean opt_bg_set; |