diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-08-16 07:23:08 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-08-16 07:23:08 +0000 |
commit | bb26941a468b994331286a55d41447cc2ef9326f (patch) | |
tree | 7e38be8a1800f49aeed0e0b54e8e74524124a46c /examples | |
parent | 292545e94970319545d1a2d8a5ebb700ade67565 (diff) | |
download | pango-bb26941a468b994331286a55d41447cc2ef9326f.tar.gz |
Render block progression and line direction arrows, and a base gravity
2006-08-16 Behdad Esfahbod <behdad@gnome.org>
* examples/viewer-pangocairo.c (render_callback): Render block
progression and line direction arrows, and a base gravity roof-top.
* pango/pango-matrix.c (pango_matrix_to_gravity): New function.
* pango/pango-utils.c (pango_gravity_to_rotation): New function.
* pango/pangocairo-fcfont.c (_pango_cairo_fc_font_new): Use
pango_gravity_to_rotation().
* pango/pango-utils.h:
* pango/pango-types.h:
Reorder a bit.
* examples/Makefile.am:
* examples/test-chinese.txt: New test text for Chinese.
* pango/check.defs: New script that checks that all the exported
symbols are listed in the respective .def file. (only checks the
libraries actually built. No win32 for example.)
* pango/Makefile.am: Hook check.defs as a 'make check' test.
* pango/pango.def:
* pango/pangoft2.def:
* pango/pangocairo.def:
Update.
* docs/tmpl/glyphs.sgml:
* docs/tmpl/main.sgml:
* docs/pango-sections.txt:
Update.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 1 | ||||
-rw-r--r-- | examples/test-chinese.txt | 7 | ||||
-rw-r--r-- | examples/viewer-pangocairo.c | 114 |
3 files changed, 104 insertions, 18 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index 3b8dfea7..9a3a10b8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -2,6 +2,7 @@ TEST_TEXTS = \ test-arabic.txt \ + test-chinese.txt \ test-devanagari.txt \ test-hebrew.txt \ test-ipa.txt \ diff --git a/examples/test-chinese.txt b/examples/test-chinese.txt new file mode 100644 index 00000000..d4fb796a --- /dev/null +++ b/examples/test-chinese.txt @@ -0,0 +1,7 @@ +你好,这是中文竖排测试。 +欢迎来到中国北京。 +白日依山尽, +黄河入海流。 +欲穷千里目, +更上一层楼。 +谢谢! diff --git a/examples/viewer-pangocairo.c b/examples/viewer-pangocairo.c index 82b8f05e..8420f8cc 100644 --- a/examples/viewer-pangocairo.c +++ b/examples/viewer-pangocairo.c @@ -142,44 +142,119 @@ render_callback (PangoLayout *layout, cairo_save (cr); cairo_translate (cr, x, y); - pango_cairo_show_layout (cr, - layout); if (show_borders) { + cairo_pattern_t *pattern; PangoRectangle ink, logical; double lw = cairo_get_line_width (cr); PangoLayoutIter* iter; pango_layout_get_extents (layout, &ink, &logical); - cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); - cairo_rectangle (cr, - (double)logical.x / PANGO_SCALE - lw / 2, - (double)logical.y / PANGO_SCALE - lw / 2, - (double)logical.width / PANGO_SCALE + lw, - (double)logical.height / PANGO_SCALE + lw); + /* draw resolved gravity "roof" in blue */ + cairo_save (cr); + cairo_translate (cr, + (double)logical.x / PANGO_SCALE, + (double)logical.y / PANGO_SCALE); + cairo_scale (cr, + (double)logical.width / PANGO_SCALE * 0.5, + (double)logical.height / PANGO_SCALE * 0.5); + cairo_translate (cr, 1.0, 1.0); + cairo_rotate (cr, + pango_gravity_to_rotation ( + pango_context_get_base_gravity ( + pango_layout_get_context (layout)))); + cairo_move_to (cr, -1.0, -1.1); + cairo_rel_line_to (cr, +1.0, -0.2); /* / */ + cairo_rel_line_to (cr, +1.0, +0.2); /* \ */ + cairo_close_path (cr); /* - */ + pattern = cairo_pattern_create_linear (0, -1.1, 0, -1.3); + cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 0.0, 1.0, 0.0); + cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 0.0, 1.0, 0.15); + cairo_set_source (cr, pattern); + cairo_fill_preserve (cr); + /* silly line_width is not locked :(. get rid of scale. */ + cairo_restore (cr); + cairo_save (cr); + cairo_set_source_rgba (cr, 0.0, 0.0, 0.7, 0.2); + cairo_stroke (cr); + cairo_restore (cr); + + + /* draw block progression arrow in green */ + cairo_save (cr); + cairo_translate (cr, + (double)logical.x / PANGO_SCALE, + (double)logical.y / PANGO_SCALE); + cairo_scale (cr, + (double)logical.width / PANGO_SCALE * 0.5, + (double)logical.height / PANGO_SCALE * 0.5); + cairo_translate (cr, 1.0, 1.0); + cairo_move_to (cr, -0.4, -0.7); + cairo_rel_line_to (cr, +0.8, 0.0); /* -- */ + cairo_rel_line_to (cr, 0.0, +0.9); /* | */ + cairo_rel_line_to (cr, +0.4, 0.0); /* - */ + cairo_rel_line_to (cr, -0.8, +0.5); /* / */ + cairo_rel_line_to (cr, -0.8, -0.5); /* \ */ + cairo_rel_line_to (cr, +0.4, 0.0); /* - */ + cairo_close_path (cr); /* | */ + pattern = cairo_pattern_create_linear (0, -0.7, 0, 0.7); + cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 1.0, 0.0, 0.0); + cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 1.0, 0.0, 0.15); + cairo_set_source (cr, pattern); + cairo_fill_preserve (cr); + /* silly line_width is not locked :(. get rid of scale. */ + cairo_restore (cr); + cairo_save (cr); + cairo_set_source_rgba (cr, 0.0, 0.7, 0.0, 0.2); cairo_stroke (cr); + cairo_restore (cr); + /* draw baselines with line direction arrow in orange */ cairo_save (cr); - cairo_set_line_width (cr, lw / 2); - cairo_set_source_rgba (cr, 0.4, 0.4, 1.0, 0.75); + cairo_set_source_rgba (cr, 1.0, 0.5, 0.0, 0.5); iter = pango_layout_get_iter (layout); do { + PangoLayoutLine *line = pango_layout_iter_get_line (iter); + double width = (double)logical.width / PANGO_SCALE; + y = pango_layout_iter_get_baseline (iter); - cairo_move_to (cr, - (double)logical.x / PANGO_SCALE, - (double)y / PANGO_SCALE + lw / 4); - cairo_rel_line_to (cr, - (double)logical.width / PANGO_SCALE, - 0); - cairo_stroke (cr); + cairo_save (cr); + cairo_translate (cr, + (double)logical.x / PANGO_SCALE + width * 0.5, + (double)y / PANGO_SCALE); + if (line->resolved_dir) + cairo_scale (cr, -1, 1); + cairo_move_to (cr, -width * .5, -lw*0.2); + cairo_rel_line_to (cr, +width * .9, -lw*0.3); + cairo_rel_line_to (cr, 0, -lw); + cairo_rel_line_to (cr, +width * .1, +lw*1.5); + cairo_rel_line_to (cr, -width * .1, +lw*1.5); + cairo_rel_line_to (cr, 0, -lw); + cairo_rel_line_to (cr, -width * .9, -lw*0.3); + cairo_close_path (cr); + cairo_fill (cr); + cairo_restore (cr); } while (pango_layout_iter_next_line (iter)); pango_layout_iter_free (iter); cairo_restore (cr); + /* draw the logical rect in red */ + cairo_save (cr); + cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); + cairo_rectangle (cr, + (double)logical.x / PANGO_SCALE - lw / 2, + (double)logical.y / PANGO_SCALE - lw / 2, + (double)logical.width / PANGO_SCALE + lw, + (double)logical.height / PANGO_SCALE + lw); + cairo_stroke (cr); + cairo_restore (cr); + + /* draw the ink rect in green */ + cairo_save (cr); cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 0.5); cairo_rectangle (cr, (double)ink.x / PANGO_SCALE - lw / 2, @@ -187,8 +262,11 @@ render_callback (PangoLayout *layout, (double)ink.width / PANGO_SCALE + lw, (double)ink.height / PANGO_SCALE + lw); cairo_stroke (cr); - + cairo_restore (cr); } + + pango_cairo_show_layout (cr, layout); + cairo_restore (cr); } |