diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-08-03 15:31:40 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-08-03 16:06:39 -0400 |
commit | b5634799586ed8e3496ffc237b8d08e6d4e64d67 (patch) | |
tree | 5ac788b92c5a69b5c79309f0fd47637a1206eaa4 /pango | |
parent | 519c36733acb31a15c9f416f845c7887bfe64121 (diff) | |
download | pango-b5634799586ed8e3496ffc237b8d08e6d4e64d67.tar.gz |
Add a pango_shape variant that takes flags
The only flag currently defined affects whether
glyph positions are rounded or not.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-glyph.h | 45 | ||||
-rw-r--r-- | pango/shape.c | 93 |
2 files changed, 106 insertions, 32 deletions
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/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); + } + } } |