From 7a102793913cb7a1a0eefbbfc9d5c0d04c9eb868 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Jan 2007 00:23:59 +0000 Subject: [PATCH] =?utf8?q?Bug=20323173=20=E2=80=93=20Add=20layout=20of=20m?= =?utf8?q?ixed=20direction=20text=20for=20vertical=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2007-01-15 Behdad Esfahbod Bug 323173 – Add layout of mixed direction text for vertical layout * pango/pango-gravity.h: * pango/pango-gravity.c: Moved gravity stuff here. New public API: PangoGravityHint pango_gravity_get_for_matrix() pango_gravity_get_for_script() * pango/pango-context.h: * pango/pango-context.c (pango_context_init), (update_resolved_gravity), (itemize_state_update_for_new_run): Support gravity hint. New public API: pango_context_set_gravity_hint() pango_context_get_gravity_hint() * pango/pango-utils.c: * pango/pango-matrix.c: * pango/pango-matrix.h: * pango/pango-types.h: Moved gravity and matrix stuff into its own header. pango-types.h includes both pango-matrix.h and pango-gravity.h * pango/pango.h: Include new headers. * pango/pango.def: * pango/Makefile.am: Update. * docs/pango-docs.sgml: * docs/pango-sections.txt: * docs/tmpl/glyphs.sgml: * docs/tmpl/main.sgml: * docs/tmpl/vertical.sgml: Add a section for Vertical Text. * examples/renderdemo.c (do_output), (parse_gravity_hint), (parse_options): Support gravity hint. * examples/test-mixed.txt: New test, mixed Latin, Arabic, Chinese text. svn path=/trunk/; revision=2144 --- ChangeLog | 48 +++++++ docs/pango-docs.sgml | 2 + docs/pango-sections.txt | 21 ++- docs/tmpl/glyphs.sgml | 9 -- docs/tmpl/main.sgml | 35 ++--- docs/tmpl/vertical.sgml | 83 +++++++++++ examples/renderdemo.c | 34 ++++- examples/test-mixed.txt | 8 ++ pango/Makefile.am | 10 +- pango/pango-attributes.c | 3 +- pango/pango-context.c | 57 +++++++- pango/pango-context.h | 3 + pango/pango-glyph-item-private.h | 1 - pango/pango-glyph-item.c | 1 - pango/pango-glyph-item.h | 1 - pango/pango-gravity.c | 294 +++++++++++++++++++++++++++++++++++++++ pango/pango-gravity.h | 109 +++++++++++++++ pango/pango-layout.c | 6 +- pango/pango-matrix.c | 37 +---- pango/pango-matrix.h | 115 +++++++++++++++ pango/pango-script.c | 1 - pango/pango-script.h | 7 +- pango/pango-types.h | 116 +-------------- pango/pango-utils.c | 30 +--- pango/pango.def | 6 +- pango/pango.h | 2 + 26 files changed, 807 insertions(+), 232 deletions(-) create mode 100644 docs/tmpl/vertical.sgml create mode 100644 examples/test-mixed.txt create mode 100644 pango/pango-gravity.c create mode 100644 pango/pango-gravity.h create mode 100644 pango/pango-matrix.h diff --git a/ChangeLog b/ChangeLog index 3111a13..32f4602 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,51 @@ +2007-01-15 Behdad Esfahbod + + Bug 323173 – Add layout of mixed direction text for vertical layout + + * pango/pango-gravity.h: + * pango/pango-gravity.c: + Moved gravity stuff here. New public API: + + PangoGravityHint + pango_gravity_get_for_matrix() + pango_gravity_get_for_script() + + * pango/pango-context.h: + * pango/pango-context.c (pango_context_init), + (update_resolved_gravity), (itemize_state_update_for_new_run): + Support gravity hint. New public API: + + pango_context_set_gravity_hint() + pango_context_get_gravity_hint() + + * pango/pango-utils.c: + * pango/pango-matrix.c: + * pango/pango-matrix.h: + * pango/pango-types.h: + Moved gravity and matrix stuff into its own header. pango-types.h + includes both pango-matrix.h and pango-gravity.h + + * pango/pango.h: + Include new headers. + + * pango/pango.def: + * pango/Makefile.am: + Update. + + * docs/pango-docs.sgml: + * docs/pango-sections.txt: + * docs/tmpl/glyphs.sgml: + * docs/tmpl/main.sgml: + * docs/tmpl/vertical.sgml: + Add a section for Vertical Text. + + * examples/renderdemo.c (do_output), (parse_gravity_hint), + (parse_options): + Support gravity hint. + + * examples/test-mixed.txt: + New test, mixed Latin, Arabic, Chinese text. + 2007-01-15 Tor Lillqvist * configure.in: Don't check for X and don't warn about missing diff --git a/docs/pango-docs.sgml b/docs/pango-docs.sgml index a9bfe03..1c91615 100644 --- a/docs/pango-docs.sgml +++ b/docs/pango-docs.sgml @@ -28,6 +28,7 @@ + ]> @@ -46,6 +47,7 @@ &markup-format; &pango-Layout-Objects; &pango-Scripts; + &pango-Vertical-Text; diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index 462eb45..64da609 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -8,8 +8,6 @@ PangoAnalysis PANGO_ANALYSIS_FLAG_CENTERED_BASELINE PangoDirection PANGO_TYPE_DIRECTION -PangoGravity -PANGO_TYPE_GRAVITY pango_itemize pango_itemize_with_base_dir @@ -31,6 +29,8 @@ pango_context_set_base_dir pango_context_get_base_gravity pango_context_set_base_gravity pango_context_get_gravity +pango_context_get_gravity_hint +pango_context_set_gravity_hint pango_context_get_matrix pango_context_set_matrix pango_context_load_font @@ -63,7 +63,6 @@ pango_shape pango_direction_get_type pango_context_get_type -pango_gravity_get_type pango_item_get_type @@ -96,7 +95,6 @@ pango_matrix_transform_distance pango_matrix_transform_rectangle pango_matrix_transform_pixel_rectangle pango_matrix_get_font_scale_factor -pango_matrix_to_gravity PangoGlyph PANGO_GLYPH_EMPTY PANGO_GLYPH_UNKNOWN_FLAG @@ -993,3 +991,18 @@ pango_version pango_version_string pango_version_check + +
+Vertical Text +vertical +PangoGravity +PANGO_TYPE_GRAVITY +PangoGravityHint +PANGO_TYPE_GRAVITY_HINT +PANGO_GRAVITY_IS_VERTICAL +pango_gravity_get_for_matrix +pango_gravity_get_for_script + +pango_gravity_get_type +pango_gravity_hint_get_type +
diff --git a/docs/tmpl/glyphs.sgml b/docs/tmpl/glyphs.sgml index b0be55d..7b0f2da 100644 --- a/docs/tmpl/glyphs.sgml +++ b/docs/tmpl/glyphs.sgml @@ -272,15 +272,6 @@ horizontal origin. @Returns: - - - - - -@matrix: -@Returns: - - A #PangoGlyph represents a single glyph in the output form of a string. diff --git a/docs/tmpl/main.sgml b/docs/tmpl/main.sgml index dbd6910..865229f 100644 --- a/docs/tmpl/main.sgml +++ b/docs/tmpl/main.sgml @@ -84,23 +84,6 @@ The #GObject type for #PangoDirection. - - - - -@PANGO_GRAVITY_SOUTH: -@PANGO_GRAVITY_EAST: -@PANGO_GRAVITY_NORTH: -@PANGO_GRAVITY_WEST: -@PANGO_GRAVITY_AUTO: - - - -The #GObject type for #PangoGravity. - - - - @@ -282,6 +265,24 @@ The #GObject type for #PangoGravity. @Returns: + + + + + +@context: +@Returns: + + + + + + + +@context: +@hint: + + diff --git a/docs/tmpl/vertical.sgml b/docs/tmpl/vertical.sgml new file mode 100644 index 0000000..ccbea1e --- /dev/null +++ b/docs/tmpl/vertical.sgml @@ -0,0 +1,83 @@ + +Vertical Text + + +Laying text out in vertical directions + + + +Since 1.16, Pango is able to correctly lay vertical text out. In fact, it can +set layouts of mixed vertical and non-vertical text. This section describes +the types used for setting vertical text parameters. + + + + + + + + + + + + + + + +@PANGO_GRAVITY_SOUTH: +@PANGO_GRAVITY_EAST: +@PANGO_GRAVITY_NORTH: +@PANGO_GRAVITY_WEST: +@PANGO_GRAVITY_AUTO: + + + +The #GObject type for #PangoGravity. + + + + + + + + + +@PANGO_GRAVITY_HINT_NATURAL: +@PANGO_GRAVITY_HINT_STRONG: +@PANGO_GRAVITY_HINT_LINE: + + + +The #GObject type for #PangoGravity. + + + + + + + + + +@gravity: + + + + + + + +@matrix: +@Returns: + + + + + + + +@script: +@base_gravity: +@hint: +@Returns: + + diff --git a/examples/renderdemo.c b/examples/renderdemo.c index 9fd16ff..21773e4 100644 --- a/examples/renderdemo.c +++ b/examples/renderdemo.c @@ -57,6 +57,7 @@ int opt_indent = 0; int opt_runs = 1; PangoEllipsizeMode opt_ellipsize = PANGO_ELLIPSIZE_NONE; PangoGravity opt_gravity = PANGO_GRAVITY_SOUTH; +PangoGravityHint opt_gravity_hint = PANGO_GRAVITY_HINT_NATURAL; HintMode opt_hinting = HINT_DEFAULT; PangoWrapMode opt_wrap = PANGO_WRAP_WORD_CHAR; gboolean opt_wrap_set = FALSE; @@ -289,6 +290,7 @@ do_output (PangoContext *context, } pango_context_set_base_gravity (context, opt_gravity); + pango_context_set_gravity_hint (context, opt_gravity_hint); set_transform (context, transform_cb, cb_context, cb_data, &matrix); @@ -389,6 +391,34 @@ parse_gravity (const char *name, } static gboolean +parse_gravity_hint (const char *name, + const char *arg, + gpointer data, + GError **error) +{ + static GEnumClass *class = NULL; + gboolean ret = TRUE; + GEnumValue *value; + + if (!class) + class = g_type_class_ref (PANGO_TYPE_GRAVITY_HINT); + + value = g_enum_get_value_by_nick (class, arg); + if (value) + opt_gravity_hint = value->value; + else + { + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for --gravity-hint must be one of natural/strong/line"); + ret = FALSE; + } + + return ret; +} + +static gboolean parse_hinting (const char *name, const char *arg, gpointer data, @@ -566,7 +596,9 @@ parse_options (int argc, char *argv[]) {"font", 0, 0, G_OPTION_ARG_STRING, &opt_font, "Set the font description", "description"}, {"gravity", 0, 0, G_OPTION_ARG_CALLBACK, &parse_gravity, - "Gravity: glyph rotation", "south/east/north/west/auto"}, + "Base gravity: glyph rotation", "south/east/north/west/auto"}, + {"gravity-hint", 0, 0, G_OPTION_ARG_CALLBACK, &parse_gravity_hint, + "Gravity hint", "natural/strong/line"}, {"header", 0, 0, G_OPTION_ARG_NONE, &opt_header, "Display the options in the output", NULL}, {"hinting", 0, 0, G_OPTION_ARG_CALLBACK, &parse_hinting, diff --git a/examples/test-mixed.txt b/examples/test-mixed.txt new file mode 100644 index 0000000..5c3f1a2 --- /dev/null +++ b/examples/test-mixed.txt @@ -0,0 +1,8 @@ +你好,这是中文竖排测试。 +欢迎来到中国北京。 +白日依山尽, +Roses are Red, +Grass is Green. 2006 +Arabic is گل‌ها قرمزند،‏ +چمن سبز. ۲۰۰۶ +白日依山尽, 2006 diff --git a/pango/Makefile.am b/pango/Makefile.am index 59e1bcb..9961d04 100644 --- a/pango/Makefile.am +++ b/pango/Makefile.am @@ -77,18 +77,19 @@ libpango_1_0_la_SOURCES = \ pango-fontset.c \ pango-glyph-item.c \ pango-glyph-item-private.h \ + pango-gravity.c \ pango-impl-utils.h \ pango-item.c \ pango-layout.c \ pango-layout-private.h \ pango-markup.c \ + pango-matrix.c \ pango-renderer.c \ pango-script.c \ pango-script-lang-table.h \ pango-script-table.h \ pango-tabs.c \ pango-utils.c \ - pango-matrix.c \ reorder-items.c \ shape.c \ pango-enum-types.c \ @@ -106,16 +107,16 @@ pango_headers = \ pango-fontset.h \ pango-glyph.h \ pango-glyph-item.h \ + pango-gravity.h \ pango-item.h \ pango-layout.h \ + pango-matrix.h \ pango-modules.h \ pango-renderer.h \ pango-script.h \ pango-tabs.h \ pango-types.h \ - pango-utils.h \ - pangofc-font.h \ - pangofc-fontmap.h + pango-utils.h pangoinclude_HEADERS = \ $(pango_headers) \ @@ -183,6 +184,7 @@ libpangox_1_0_la_SOURCES = \ # ------------------- libpangoft2 ------------------- if HAVE_FREETYPE +pangoinclude_HEADERS += pangofc-font.h pangofc-fontmap.h pangoinclude_HEADERS += pangoft2.h pango-ot.h pangofc-decoder.h lib_LTLIBRARIES += libpangoft2-1.0.la endif diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c index eef62ea..7f99746 100644 --- a/pango/pango-attributes.c +++ b/pango/pango-attributes.c @@ -1,5 +1,4 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* pango +/* Pango * pango-attributes.c: Attributed text * * Copyright (C) 2000-2002 Red Hat Software diff --git a/pango/pango-context.c b/pango/pango-context.c index 533929d..32197e5 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -1,7 +1,7 @@ /* Pango * pango-context.c: Contexts for itemization and shaping * - * Copyright (C) 2000 Red Hat Software + * Copyright (C) 2000, 2006 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -38,6 +38,7 @@ struct _PangoContext PangoDirection base_dir; PangoGravity base_gravity; PangoGravity resolved_gravity; + PangoGravityHint gravity_hint; PangoFontDescription *font_desc; @@ -61,6 +62,8 @@ pango_context_init (PangoContext *context) { context->base_dir = PANGO_DIRECTION_WEAK_LTR; context->resolved_gravity = context->base_gravity = PANGO_GRAVITY_SOUTH; + context->gravity_hint = PANGO_GRAVITY_HINT_NATURAL; + context->language = NULL; context->font_map = NULL; @@ -133,7 +136,7 @@ static void update_resolved_gravity (PangoContext *context) { if (context->base_gravity == PANGO_GRAVITY_AUTO) - context->resolved_gravity = pango_matrix_to_gravity (context->matrix); + context->resolved_gravity = pango_gravity_get_for_matrix (context->matrix); else context->resolved_gravity = context->base_gravity; } @@ -466,7 +469,7 @@ pango_context_get_base_gravity (PangoContext *context) * * Retrieves the gravity for the context. This is similar to * pango_context_get_base_gravity(), except for when the base gravity - * is %PANGO_GRAVITY_AUTO for which pango_matrix_to_gravity() is used + * is %PANGO_GRAVITY_AUTO for which pango_gravity_get_for_matrix() is used * to return the gravity from the current context matrix. * * Return value: the resolved gravity for the context. @@ -481,6 +484,47 @@ pango_context_get_gravity (PangoContext *context) return context->resolved_gravity; } +/** + * pango_context_set_gravity_hint: + * @context: a #PangoContext + * @hint: the new gravity hint + * + * Sets the gravity hint for the context. + * + * The gravity hint is used in laying vertical text out, and is only relevant + * if gravity of the context as returned by pango_context_get_gravity() + * is set %PANGO_GRAVITY_EAST or %PANGO_GRAVITY_WEST. + * + * Since: 1.16 + **/ +void +pango_context_set_gravity_hint (PangoContext *context, + PangoGravityHint hint) +{ + g_return_if_fail (context != NULL); + + context->gravity_hint = hint; +} + +/** + * pango_context_get_gravity_hint: + * @context: a #PangoContext + * + * Retrieves the gravity hint for the context. See + * pango_context_set_gravity_hint() for details. + * + * Return value: the gravity hint for the context. + * + * Since: 1.16 + **/ +PangoGravityHint +pango_context_get_gravity_hint (PangoContext *context) +{ + g_return_val_if_fail (context != NULL, PANGO_GRAVITY_HINT_NATURAL); + + return context->gravity_hint; +} + /**********************************************************************/ static gboolean @@ -1178,10 +1222,9 @@ itemize_state_update_for_new_run (ItemizeState *state) { PangoGravity gravity = state->context->resolved_gravity; - /* FIXME - * gravity = pango_script_get_resolved_gravity (script, gravity, hint); - */ - + gravity = pango_gravity_get_for_script (state->script, + state->context->resolved_gravity, + state->context->gravity_hint); state->gravity = gravity; } diff --git a/pango/pango-context.h b/pango/pango-context.h index 12a2508..5cd8840 100644 --- a/pango/pango-context.h +++ b/pango/pango-context.h @@ -82,6 +82,9 @@ void pango_context_set_base_gravity (PangoContext PangoGravity gravity); PangoGravity pango_context_get_base_gravity (PangoContext *context); PangoGravity pango_context_get_gravity (PangoContext *context); +void pango_context_set_gravity_hint (PangoContext *context, + PangoGravityHint hint); +PangoGravityHint pango_context_get_gravity_hint (PangoContext *context); void pango_context_set_matrix (PangoContext *context, const PangoMatrix *matrix); diff --git a/pango/pango-glyph-item-private.h b/pango/pango-glyph-item-private.h index 245706a..aa19c3c 100644 --- a/pango/pango-glyph-item-private.h +++ b/pango/pango-glyph-item-private.h @@ -1,4 +1,3 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ /* Pango * pango-glyph-item-private.h: Pair of PangoItem and a glyph string; private * functionality diff --git a/pango/pango-glyph-item.c b/pango/pango-glyph-item.c index 6506919..b33e7c4 100644 --- a/pango/pango-glyph-item.c +++ b/pango/pango-glyph-item.c @@ -1,4 +1,3 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ /* Pango * pango-glyph-item.c: Pair of PangoItem and a glyph string * diff --git a/pango/pango-glyph-item.h b/pango/pango-glyph-item.h index 3be2b9e..fec086a 100644 --- a/pango/pango-glyph-item.h +++ b/pango/pango-glyph-item.h @@ -1,4 +1,3 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ /* Pango * pango-glyph-item.h: Pair of PangoItem and a glyph string * diff --git a/pango/pango-gravity.c b/pango/pango-gravity.c new file mode 100644 index 0000000..7310313 --- /dev/null +++ b/pango/pango-gravity.c @@ -0,0 +1,294 @@ +/* Pango + * pango-gravity.c: Gravity routines + * + * Copyright (C) 2006, 2007 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include "pango-gravity.h" + +#include + +/** + * pango_gravity_to_rotation: + * @gravity: gravity to query + * + * Converts a #PangoGravity value to its rotation value. + * @gravity should not be %PANGO_GRAVITY_AUTO. + * + * Return value: the rotation value corresponding to @gravity. + * + * Since: 1.16 + */ +double +pango_gravity_to_rotation (PangoGravity gravity) +{ + double rotation; + + g_return_val_if_fail (gravity != PANGO_GRAVITY_AUTO, 0); + + switch (gravity) + { + default: + case PANGO_GRAVITY_AUTO: /* shut gcc up */ + case PANGO_GRAVITY_SOUTH: rotation = 0; break; + case PANGO_GRAVITY_NORTH: rotation = G_PI; break; + case PANGO_GRAVITY_EAST: rotation = -G_PI_2; break; + case PANGO_GRAVITY_WEST: rotation = +G_PI_2; break; + } + + return rotation; +} + +/** + * pango_gravity_get_for_matrix: + * @matrix: a #PangoMatrix + * + * Finds the gravity that best matches the rotation component + * in a #PangoMatrix. + * + * Return value: the gravity of @matrix, which will never be + * %PANGO_GRAVITY_AUTO, or %PANGO_GRAVITY_SOUTH if @matrix is %NULL + * + * Since: 1.16 + */ +PangoGravity +pango_gravity_get_for_matrix (const PangoMatrix *matrix) +{ + PangoGravity gravity; + double x; + double y; + + if (!matrix) + return PANGO_GRAVITY_SOUTH; + + x = matrix->xy; + y = matrix->yy; + + if (fabs (x) > fabs (y)) + gravity = x > 0 ? PANGO_GRAVITY_WEST : PANGO_GRAVITY_EAST; + else + gravity = y < 0 ? PANGO_GRAVITY_NORTH : PANGO_GRAVITY_SOUTH; + + return gravity; +} + + + +typedef enum +{ + PANGO_VERTICAL_DIRECTION_NONE, + PANGO_VERTICAL_DIRECTION_TTB, + PANGO_VERTICAL_DIRECTION_BTT +} PangoVerticalDirection; + +typedef struct { + /* PangoDirection */ + guint8 horiz_dir; /* Orientation in horizontal context */ + + /* PangoVerticalDirection */ + guint8 vert_dir; /* Orientation in vertical context */ + + /* PangoGravity */ + guint8 preferred_gravity; /* Preferred context gravity */ + + /* gboolean */ + guint8 upright; /* Whether glyphs are upright or + * rotated in foreign context */ +} PangoScriptProperties; + +#define NONE PANGO_VERTICAL_DIRECTION_NONE +#define TTB PANGO_VERTICAL_DIRECTION_TTB +#define BTT PANGO_VERTICAL_DIRECTION_BTT + +#define LTR PANGO_DIRECTION_LTR +#define RTL PANGO_DIRECTION_RTL +#define WEAK PANGO_DIRECTION_WEAK_LTR + +#define S PANGO_GRAVITY_SOUTH +#define E PANGO_GRAVITY_EAST +#define N PANGO_GRAVITY_NORTH +#define W PANGO_GRAVITY_WEST + +const PangoScriptProperties script_properties[] = + { /* ISO 15924 code */ + {LTR, NONE, S, FALSE}, /* Zyyy */ + {LTR, NONE, S, FALSE}, /* Qaai */ + {RTL, NONE, S, FALSE}, /* Arab */ + {LTR, NONE, S, FALSE}, /* Armn */ + {LTR, NONE, S, FALSE}, /* Beng */ + {LTR, TTB, E, TRUE }, /* Bopo */ + {LTR, NONE, S, FALSE}, /* Cher */ + {LTR, NONE, S, FALSE}, /* Qaac */ + {LTR, NONE, S, FALSE}, /* Cyrl (Cyrs) */ + {LTR, NONE, S, FALSE}, /* Dsrt */ + {LTR, NONE, S, FALSE}, /* Deva */ + {LTR, NONE, S, FALSE}, /* Ethi */ + {LTR, NONE, S, FALSE}, /* Geor (Geon, Geoa) */ + {LTR, NONE, S, FALSE}, /* Goth */ + {LTR, NONE, S, FALSE}, /* Grek */ + {LTR, NONE, S, FALSE}, /* Gujr */ + {LTR, NONE, S, FALSE}, /* Guru */ + {LTR, TTB, E, TRUE }, /* Hani */ + {LTR, TTB, E, TRUE }, /* Hang */ + {RTL, NONE, S, FALSE}, /* Hebr */ + {LTR, TTB, E, TRUE }, /* Hira */ + {LTR, NONE, S, FALSE}, /* Knda */ + {LTR, TTB, E, TRUE }, /* Kana */ + {LTR, NONE, S, FALSE}, /* Khmr */ + {LTR, NONE, S, FALSE}, /* Laoo */ + {LTR, NONE, S, FALSE}, /* Latn (Latf, Latg) */ + {LTR, NONE, S, FALSE}, /* Mlym */ + {WEAK,TTB, W, FALSE}, /* Mong */ + {LTR, NONE, S, FALSE}, /* Mymr */ + {LTR, BTT, W, FALSE}, /* Ogam */ + {LTR, NONE, S, FALSE}, /* Ital */ + {LTR, NONE, S, FALSE}, /* Orya */ + {LTR, NONE, S, FALSE}, /* Runr */ + {LTR, NONE, S, FALSE}, /* Sinh */ + {RTL, NONE, S, FALSE}, /* Syrc (Syrj, Syrn, Syre) */ + {LTR, NONE, S, FALSE}, /* Taml */ + {LTR, NONE, S, FALSE}, /* Telu */ + {RTL, NONE, S, FALSE}, /* Thaa */ + {LTR, NONE, S, FALSE}, /* Thai */ + {LTR, NONE, S, FALSE}, /* Tibt */ + {LTR, NONE, S, FALSE}, /* Cans */ + {LTR, TTB, S, TRUE }, /* Yiii */ + {LTR, NONE, S, FALSE}, /* Tglg */ + {LTR, NONE, S, FALSE}, /* Hano */ + {LTR, NONE, S, FALSE}, /* Buhd */ + {LTR, NONE, S, FALSE}, /* Tagb */ + + /* Unicode-4.0 additions */ + {LTR, NONE, S, FALSE}, /* Brai */ + {LTR, NONE, S, FALSE}, /* Cprt */ + {LTR, NONE, S, FALSE}, /* Limb */ + {LTR, NONE, S, FALSE}, /* Osma */ + {LTR, NONE, S, FALSE}, /* Shaw */ + {LTR, NONE, S, FALSE}, /* Linb */ + {LTR, NONE, S, FALSE}, /* Tale */ + {LTR, NONE, S, FALSE}, /* Ugar */ + + /* Unicode-4.1 additions */ + {LTR, NONE, S, FALSE}, /* Talu */ + {LTR, NONE, S, FALSE}, /* Bugi */ + {LTR, NONE, S, FALSE}, /* Glag */ + {LTR, NONE, S, FALSE}, /* Tfng */ + {LTR, NONE, S, FALSE}, /* Sylo */ + {LTR, NONE, S, FALSE}, /* Xpeo */ + {LTR, NONE, S, FALSE}, /* Khar */ + + /* Unicode-5.0 additions */ + {LTR, NONE, S, FALSE}, /* Zzzz */ + {LTR, NONE, S, FALSE}, /* Bali */ + {LTR, NONE, S, FALSE}, /* Xsux */ + {RTL, NONE, S, FALSE}, /* Phnx */ + {LTR, NONE, S, FALSE}, /* Phag */ + {RTL, NONE, S, FALSE} /* Nkoo */ +}; + +#undef NONE +#undef TTB +#undef BTT + +#undef LTR +#undef RTL +#undef WEAK + +#undef S +#undef E +#undef N +#undef W + +static PangoScriptProperties +get_script_properties (PangoScript script) +{ + if ((guint)script >= G_N_ELEMENTS (script_properties)) + script = 0; + + return script_properties[script]; +} + +/** + * pango_gravity_get_for_script: + * @script: #PangoScript to query + * @base_gravity: base gravity of the paragraph + * @hint: orientation hint + * + * Based on the script, base gravity, and hint, returns actual gravity + * to use in laying out a single #PangoItem. + * + * If @base_gravity is %PANGO_GRAVITY_AUTO, it is first replaced with the + * preferred gravity of @script. To get the preferred gravity of a script, + * pass %PANGO_GRAVITY_AUTO and %PANGO_GRAVITY_HINT_STRONG in. + * + * Return value: resolved gravity suitable to use for a run of text + * + * Since: 1.16 + */ +PangoGravity +pango_gravity_get_for_script (PangoScript script, + PangoGravity base_gravity, + PangoGravityHint hint) +{ + PangoScriptProperties props = get_script_properties (script); + gboolean vertical; + + + if (G_UNLIKELY (base_gravity == PANGO_GRAVITY_AUTO)) + base_gravity = props.preferred_gravity; + + vertical = PANGO_GRAVITY_IS_VERTICAL (base_gravity); + + /* Everything is designed such that a system with no vertical support + * renders everything correctly horizontally. So, if not in a vertical + * gravity, base and resolved gravities are always the same. + * + * If the script should be upright all the time, like Chinese and Japenese, + * any base gravity should resolve to itself. + */ + if (G_LIKELY (!vertical || props.upright)) + return base_gravity; + + /* If here, we have a non-upright script in a vertical gravity setting. + * Resolve depending on the hint. + */ + switch (hint) + { + default: + case PANGO_GRAVITY_HINT_NATURAL: + if (props.vert_dir == PANGO_VERTICAL_DIRECTION_NONE) + return PANGO_GRAVITY_SOUTH; + if ((base_gravity == PANGO_GRAVITY_EAST) ^ + (props.vert_dir == PANGO_VERTICAL_DIRECTION_BTT)) + return PANGO_GRAVITY_SOUTH; + else + return PANGO_GRAVITY_NORTH; + + case PANGO_GRAVITY_HINT_STRONG: + return base_gravity; + + case PANGO_GRAVITY_HINT_LINE: + if ((base_gravity == PANGO_GRAVITY_EAST) ^ + (props.horiz_dir == PANGO_DIRECTION_RTL)) + return PANGO_GRAVITY_SOUTH; + else + return PANGO_GRAVITY_NORTH; + } +} diff --git a/pango/pango-gravity.h b/pango/pango-gravity.h new file mode 100644 index 0000000..b79436c --- /dev/null +++ b/pango/pango-gravity.h @@ -0,0 +1,109 @@ +/* Pango + * pango-gravity.h: Gravity routines + * + * Copyright (C) 2006, 2007 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __PANGO_GRAVITY_H__ +#define __PANGO_GRAVITY_H__ + +#include + +G_BEGIN_DECLS + +/** + * PangoGravity: + * @PANGO_GRAVITY_SOUTH: Glyphs stand upright (default) + * @PANGO_GRAVITY_EAST: Glyphs are rotated 90 degrees clockwise + * @PANGO_GRAVITY_NORTH: Glyphs are upside-down + * @PANGO_GRAVITY_WEST: Glyphs are rotated 90 degrees counter-clockwise + * @PANGO_GRAVITY_AUTO: Gravity is resolved from the context matrix + * + * The #PangoGravity type represents the orientation of glyphs in a segment + * of text. This is useful when rendering vertical text layouts. In + * those situations, the layout is rotated using a non-identity PangoMatrix, + * and then glyph orientation is controlled using #PangoGravity. + * Not every value in this enumeration makes sense for every usage of + * #PangoGravity; for example, %PANGO_GRAVITY_AUTO only can be passed to + * pango_context_set_base_gravity() and can only be returned by + * pango_context_get_base_gravity(). + * + * See also: #PangoGravityHint + * + * Since: 1.16 + **/ +typedef enum { + PANGO_GRAVITY_SOUTH, + PANGO_GRAVITY_EAST, + PANGO_GRAVITY_NORTH, + PANGO_GRAVITY_WEST, + PANGO_GRAVITY_AUTO +} PangoGravity; + +/** + * PangoGravityHint: + * @PANGO_GRAVITY_HINT_NATURAL: scripts will take their natural gravity based + * on the base gravity and the script. This is the default. + * @PANGO_GRAVITY_HINT_STRONG: always use the base gravity set, regardless of + * the script. + * @PANGO_GRAVITY_HINT_LINE: for scripts not in their natural direction (eg. + * Latin in East gravity), choose per-script gravity such that every script + * respects the line progression. This means, Latin and Arabic will take + * opposite gravities and both flow top-to-bottom for example. + * + * The #PangoGravityHint defines how horizontal scripts should behave in a + * vertical context. That is, English excerpt in a vertical paragraph for + * example. + * + * See #PangoGravity. + * + * Since: 1.16 + **/ +typedef enum { + PANGO_GRAVITY_HINT_NATURAL, + PANGO_GRAVITY_HINT_STRONG, + PANGO_GRAVITY_HINT_LINE +} PangoGravityHint; + +/** + * PANGO_GRAVITY_IS_VERTICAL: + * @gravity: the #PangoGravity to check + * + * Whether a #PangoGravity represents vertical writing directions. + * + * Returns: %TRUE if @gravity is %PANGO_GRAVITY_EAST or %PANGO_GRAVITY_WEST, + * %FALSE otherwise. + * + * Since: 1.16 + **/ +#define PANGO_GRAVITY_IS_VERTICAL(gravity) \ + ((gravity) == PANGO_GRAVITY_EAST || (gravity) == PANGO_GRAVITY_WEST) + +#include +#include + +double pango_gravity_to_rotation (PangoGravity gravity) G_GNUC_CONST; +PangoGravity pango_gravity_get_for_matrix (const PangoMatrix *matrix); +PangoGravity pango_gravity_get_for_script (PangoScript script, + PangoGravity base_gravity, + PangoGravityHint hint) G_GNUC_CONST; + + +G_END_DECLS + +#endif /* __PANGO_GRAVITY_H__ */ diff --git a/pango/pango-layout.c b/pango/pango-layout.c index eab30f8..52b9dcc 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -1,7 +1,7 @@ /* Pango * pango-layout.c: High-level layout driver * - * Copyright (C) 2000, 2001 Red Hat Software + * Copyright (C) 2000, 2001, 2006 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -3138,6 +3138,7 @@ line_set_resolved_dir (PangoLayoutLine *line, { switch (direction) { + default: case PANGO_DIRECTION_LTR: case PANGO_DIRECTION_TTB_RTL: case PANGO_DIRECTION_WEAK_LTR: @@ -3166,8 +3167,9 @@ line_set_resolved_dir (PangoLayoutLine *line, */ switch (pango_context_get_gravity (line->layout->context)) { - case PANGO_GRAVITY_SOUTH: default: + case PANGO_GRAVITY_AUTO: + case PANGO_GRAVITY_SOUTH: break; case PANGO_GRAVITY_NORTH: line->resolved_dir = PANGO_DIRECTION_LTR diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c index 857cc97..907cc7e 100644 --- a/pango/pango-matrix.c +++ b/pango/pango-matrix.c @@ -1,7 +1,7 @@ /* Pango * pango-matrix.c: Matrix manipulation routines * - * Copyright (C) 2000 Red Hat Software + * Copyright (C) 2000, 2006 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,7 +23,7 @@ #include #include -#include "pango-types.h" +#include "pango-matrix.h" #include "pango-impl-utils.h" GType @@ -251,39 +251,6 @@ pango_matrix_get_font_scale_factor (const PangoMatrix *matrix) } /** - * pango_matrix_to_gravity: - * @matrix: a #PangoMatrix - * - * Finds the gravity that best matches the rotation component - * in a #PangoMatrix. - * - * Return value: the gravity of @matrix, which will never be - * %PANGO_GRAVITY_AUTO, or PANGO_GRAVITY_SOUTH if @matrix is %NULL - * - * Since: 1.16 - */ -PangoGravity -pango_matrix_to_gravity (const PangoMatrix *matrix) -{ - PangoGravity gravity; - double x; - double y; - - if (!matrix) - return PANGO_GRAVITY_SOUTH; - - x = matrix->xy; - y = matrix->yy; - - if (abs (x) > abs (y)) - gravity = x > 0 ? PANGO_GRAVITY_WEST : PANGO_GRAVITY_EAST; - else - gravity = y < 0 ? PANGO_GRAVITY_NORTH : PANGO_GRAVITY_SOUTH; - - return gravity; -} - -/** * pango_matrix_transform_distance: * @matrix: a #PangoMatrix, or %NULL * @dx: in/out X component of a distance vector diff --git a/pango/pango-matrix.h b/pango/pango-matrix.h new file mode 100644 index 0000000..2b746c4 --- /dev/null +++ b/pango/pango-matrix.h @@ -0,0 +1,115 @@ +/* Pango + * pango-matrix.h: Matrix manipulation routines + * + * Copyright (C) 2002, 2006 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#ifndef __PANGO_MATRIX_H__ +#define __PANGO_MATRIX_H__ + +G_BEGIN_DECLS + +typedef struct _PangoMatrix PangoMatrix; + +/** + * PangoMatrix: + * @xx: 1st component of the transformation matrix + * @xy: 2nd component of the transformation matrix + * @yx: 3rd component of the transformation matrix + * @yy: 4th component of the transformation matrix + * @x0: x translation + * @y0: y translation + * + * A structure specifying a transformation between user-space + * coordinates and device coordinates. The transformation + * is given by + * + * + * x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0; + * y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0; + * + * + * Since: 1.6 + **/ +struct _PangoMatrix +{ + double xx; + double xy; + double yx; + double yy; + double x0; + double y0; +}; + +/** + * PANGO_TYPE_MATRIX + * + * The GObject type for #PangoMatrix + **/ +#define PANGO_TYPE_MATRIX (pango_matrix_get_type ()) + +/** + * PANGO_MATRIX_INIT + * + * Constant that can be used to initialize a PangoMatrix to + * the identity transform. + * + * + * PangoMatrix matrix = PANGO_MATRIX_INIT; + * pango_matrix_rotate (&matrix, 45.); + * + * + * Since: 1.6 + **/ +#define PANGO_MATRIX_INIT { 1., 0., 0., 1., 0., 0. } + +#include + +GType pango_matrix_get_type (void); + +PangoMatrix *pango_matrix_copy (const PangoMatrix *matrix); +void pango_matrix_free (PangoMatrix *matrix); + +void pango_matrix_translate (PangoMatrix *matrix, + double tx, + double ty); +void pango_matrix_scale (PangoMatrix *matrix, + double scale_x, + double scale_y); +void pango_matrix_rotate (PangoMatrix *matrix, + double degrees); +void pango_matrix_concat (PangoMatrix *matrix, + const PangoMatrix *new_matrix); +void pango_matrix_transform_point (const PangoMatrix *matrix, + double *x, + double *y); +void pango_matrix_transform_distance (const PangoMatrix *matrix, + double *dx, + double *dy); +void pango_matrix_transform_rectangle (const PangoMatrix *matrix, + PangoRectangle *rect); +void pango_matrix_transform_pixel_rectangle (const PangoMatrix *matrix, + PangoRectangle *rect); +double pango_matrix_get_font_scale_factor (const PangoMatrix *matrix); + + +G_END_DECLS + +#endif /* __PANGO_MATRIX_H__ */ diff --git a/pango/pango-script.c b/pango/pango-script.c index 67133ba..130309f 100644 --- a/pango/pango-script.c +++ b/pango/pango-script.c @@ -1,4 +1,3 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ /* Pango * pango-script.c: Script tag handling * diff --git a/pango/pango-script.h b/pango/pango-script.h index ee1859d..e152a69 100644 --- a/pango/pango-script.h +++ b/pango/pango-script.h @@ -1,4 +1,3 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ /* Pango * pango-script.h: Script tag handling * @@ -25,13 +24,11 @@ #include -#include - G_BEGIN_DECLS /** * PangoScriptIter: - + * * A #PangoScriptIter is used to iterate through a string * and identify ranges in different scripts. **/ @@ -114,6 +111,8 @@ typedef enum { /* ISO 15924 code */ PANGO_SCRIPT_NKO /* Nkoo */ } PangoScript; +#include + PangoScript pango_script_for_unichar (gunichar ch); PangoScriptIter *pango_script_iter_new (const char *text, diff --git a/pango/pango-types.h b/pango/pango-types.h index 75c3127..45f76e4 100644 --- a/pango/pango-types.h +++ b/pango/pango-types.h @@ -35,7 +35,6 @@ typedef struct _PangoEngineShape PangoEngineShape; typedef struct _PangoFont PangoFont; typedef struct _PangoFontMap PangoFontMap; -typedef struct _PangoMatrix PangoMatrix; typedef struct _PangoRectangle PangoRectangle; @@ -147,118 +146,9 @@ gboolean pango_get_mirror_char (gunichar ch, #endif - -/** - * PangoGravity: - * @PANGO_GRAVITY_SOUTH: Glyphs stand upright (default) - * @PANGO_GRAVITY_EAST: Glyphs are rotated 90 degrees clockwise - * @PANGO_GRAVITY_NORTH: Glyphs are upside-down - * @PANGO_GRAVITY_WEST: Glyphs are rotated 90 degrees counter-clockwise - * @PANGO_GRAVITY_AUTO: Gravity is resolved from the context matrix - * - * The #PangoGravity type represents the orientation of glyphs in a segment - * of text. This is useful when rendering vertical text layouts. In - * those situations, the layout is rotated using a non-identity PangoMatrix, - * and then glyph orientation is controlled using #PangoGravity. - * Not every value in this enumeration makes sense for every usage of - * #PangoGravity; for example, %PANGO_GRAVITY_AUTO only can be passed to - * pango_context_set_base_gravity() and can only be returned by - * pango_context_get_base_gravity(). - * - * Since: 1.16 - **/ -typedef enum { - PANGO_GRAVITY_SOUTH, - PANGO_GRAVITY_EAST, - PANGO_GRAVITY_NORTH, - PANGO_GRAVITY_WEST, - PANGO_GRAVITY_AUTO -} PangoGravity; - -double pango_gravity_to_rotation (PangoGravity gravity) G_GNUC_CONST; - - - -/** - * PangoMatrix: - * @xx: 1st component of the transformation matrix - * @xy: 2nd component of the transformation matrix - * @yx: 3rd component of the transformation matrix - * @yy: 4th component of the transformation matrix - * @x0: x translation - * @y0: y translation - * - * A structure specifying a transformation between user-space - * coordinates and device coordinates. The transformation - * is given by - * - * - * x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0; - * y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0; - * - * - * Since: 1.6 - **/ -struct _PangoMatrix -{ - double xx; - double xy; - double yx; - double yy; - double x0; - double y0; -}; - -/** - * PANGO_TYPE_MATRIX - * - * The GObject type for #PangoMatrix - **/ -#define PANGO_TYPE_MATRIX (pango_matrix_get_type ()) - -/** - * PANGO_MATRIX_INIT - * - * Constant that can be used to initialize a PangoMatrix to - * the identity transform. - * - * - * PangoMatrix matrix = PANGO_MATRIX_INIT; - * pango_matrix_rotate (&matrix, 45.); - * - * - * Since: 1.6 - **/ -#define PANGO_MATRIX_INIT { 1., 0., 0., 1., 0., 0. } - -GType pango_matrix_get_type (void); - -PangoMatrix *pango_matrix_copy (const PangoMatrix *matrix); -void pango_matrix_free (PangoMatrix *matrix); - -void pango_matrix_translate (PangoMatrix *matrix, - double tx, - double ty); -void pango_matrix_scale (PangoMatrix *matrix, - double scale_x, - double scale_y); -void pango_matrix_rotate (PangoMatrix *matrix, - double degrees); -void pango_matrix_concat (PangoMatrix *matrix, - const PangoMatrix *new_matrix); -void pango_matrix_transform_point (const PangoMatrix *matrix, - double *x, - double *y); -void pango_matrix_transform_distance (const PangoMatrix *matrix, - double *dx, - double *dy); -void pango_matrix_transform_rectangle (const PangoMatrix *matrix, - PangoRectangle *rect); -void pango_matrix_transform_pixel_rectangle (const PangoMatrix *matrix, - PangoRectangle *rect); -double pango_matrix_get_font_scale_factor (const PangoMatrix *matrix); -PangoGravity pango_matrix_to_gravity (const PangoMatrix *matrix); - +#include +#include +#include G_END_DECLS diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 211b99a..ce778a8 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -1,4 +1,4 @@ - /* Pango +/* Pango * pango-utils.c: Utilities for internal functions and modules * * Copyright (C) 2000 Red Hat Software @@ -1832,34 +1832,6 @@ pango_quantize_line_geometry (int *thickness, } /** - * pango_gravity_to_rotation: - * @gravity: gravity to query - * - * Converts a #PangoGravity value to its rotation value. - * - * Return value: the rotation value corresponding to @gravity, - * or zero if @gravity is %PANGO_GRAVITY_AUTO - * - * Since: 1.16 - */ -double -pango_gravity_to_rotation (PangoGravity gravity) -{ - double rotation; - - switch (gravity) - { - default: - case PANGO_GRAVITY_SOUTH: rotation = 0; break; - case PANGO_GRAVITY_NORTH: rotation = G_PI; break; - case PANGO_GRAVITY_EAST: rotation = -G_PI_2; break; - case PANGO_GRAVITY_WEST: rotation = +G_PI_2; break; - } - - return rotation; -} - -/** * pango_units_from_double: * @d: double floating-point value * diff --git a/pango/pango.def b/pango/pango.def index 14a591e..dd37bf9 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -56,6 +56,7 @@ EXPORTS pango_context_get_font_description pango_context_get_font_map pango_context_get_gravity + pango_context_get_gravity_hint pango_context_get_language pango_context_get_matrix pango_context_get_metrics @@ -68,6 +69,7 @@ EXPORTS pango_context_set_base_gravity pango_context_set_font_description pango_context_set_font_map + pango_context_set_gravity_hint pango_context_set_language pango_context_set_matrix pango_coverage_copy @@ -184,7 +186,10 @@ EXPORTS pango_glyph_string_new pango_glyph_string_set_size pango_glyph_string_x_to_index + pango_gravity_get_for_matrix + pango_gravity_get_for_script pango_gravity_get_type + pango_gravity_hint_get_type pango_gravity_to_rotation pango_is_zero_width pango_item_copy @@ -287,7 +292,6 @@ EXPORTS pango_matrix_get_type pango_matrix_rotate pango_matrix_scale - pango_matrix_to_gravity pango_matrix_transform_distance pango_matrix_transform_pixel_rectangle pango_matrix_transform_point diff --git a/pango/pango.h b/pango/pango.h index b87d22f..5b5ef1e 100644 --- a/pango/pango.h +++ b/pango/pango.h @@ -34,8 +34,10 @@ #include #include #include +#include #include #include +#include #include #include #include -- 2.7.4