[cairo-commit] 5 commits - src/cairo-pdf-operators.c src/cairo-ps-surface.c test/font-matrix-translation-ps-argb32-ref.png test/font-matrix-translation-ps-rgb24-ref.png test/ft-show-glyphs-positioning.c test/ft-show-glyphs-positioning-pdf-ref.png test/ft-show-glyphs-positioning-ps-ref.png test/ft-show-glyphs-positioning-ref.png test/.gitignore test/glyph-cache-pressure-ps-ref.png test/Makefile.am test/select-font-face-ps-ref.png test/show-text-current-point-ps-ref.png test/text-pattern-ps-argb32-ref.png test/text-pattern-ps-rgb24-ref.png

Adrian Johnson ajohnson at kemper.freedesktop.org
Fri Mar 21 00:45:11 PDT 2008


 src/cairo-pdf-operators.c                      |   12 +
 src/cairo-ps-surface.c                         |    5 
 test/.gitignore                                |    1 
 test/Makefile.am                               |    4 
 test/font-matrix-translation-ps-argb32-ref.png |binary
 test/font-matrix-translation-ps-rgb24-ref.png  |binary
 test/ft-show-glyphs-positioning-pdf-ref.png    |binary
 test/ft-show-glyphs-positioning-ps-ref.png     |binary
 test/ft-show-glyphs-positioning-ref.png        |binary
 test/ft-show-glyphs-positioning.c              |  167 +++++++++++++++++++++++++
 test/glyph-cache-pressure-ps-ref.png           |binary
 test/select-font-face-ps-ref.png               |binary
 test/show-text-current-point-ps-ref.png        |binary
 test/text-pattern-ps-argb32-ref.png            |binary
 test/text-pattern-ps-rgb24-ref.png             |binary
 15 files changed, 184 insertions(+), 5 deletions(-)

New commits:
commit c4599324820cfb46700bf2f059c46e9245f98ea5
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 21 18:12:03 2008 +1030

    Update PS reference images
    
    Some of the text tests require new PS specific reference images as a
    result of the PS glyph positioning fix.

diff --git a/test/font-matrix-translation-ps-argb32-ref.png b/test/font-matrix-translation-ps-argb32-ref.png
index b8a9216..41d05a0 100644
Binary files a/test/font-matrix-translation-ps-argb32-ref.png and b/test/font-matrix-translation-ps-argb32-ref.png differ
diff --git a/test/font-matrix-translation-ps-rgb24-ref.png b/test/font-matrix-translation-ps-rgb24-ref.png
index b8a9216..41d05a0 100644
Binary files a/test/font-matrix-translation-ps-rgb24-ref.png and b/test/font-matrix-translation-ps-rgb24-ref.png differ
diff --git a/test/glyph-cache-pressure-ps-ref.png b/test/glyph-cache-pressure-ps-ref.png
index f0430de..88fa447 100644
Binary files a/test/glyph-cache-pressure-ps-ref.png and b/test/glyph-cache-pressure-ps-ref.png differ
diff --git a/test/select-font-face-ps-ref.png b/test/select-font-face-ps-ref.png
index c63f076..6c2f361 100644
Binary files a/test/select-font-face-ps-ref.png and b/test/select-font-face-ps-ref.png differ
diff --git a/test/show-text-current-point-ps-ref.png b/test/show-text-current-point-ps-ref.png
index c8b42e1..b42c48e 100644
Binary files a/test/show-text-current-point-ps-ref.png and b/test/show-text-current-point-ps-ref.png differ
diff --git a/test/text-pattern-ps-argb32-ref.png b/test/text-pattern-ps-argb32-ref.png
index 6a727b9..fa68f64 100644
Binary files a/test/text-pattern-ps-argb32-ref.png and b/test/text-pattern-ps-argb32-ref.png differ
diff --git a/test/text-pattern-ps-rgb24-ref.png b/test/text-pattern-ps-rgb24-ref.png
index 6ed28e4..943149c 100644
Binary files a/test/text-pattern-ps-rgb24-ref.png and b/test/text-pattern-ps-rgb24-ref.png differ
commit f3a5f7570104c8d48c99a2b6bd34f4142e52f099
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 21 16:34:01 2008 +1030

    Add PS/PDF ref images for ft-show-glyphs-positioning

diff --git a/test/Makefile.am b/test/Makefile.am
index a1199a7..7d0c52b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -375,6 +375,8 @@ REFERENCE_IMAGES = \
 	ft-text-antialias-none-ps-argb32-ref.png	\
 	ft-text-antialias-none-ref.png	\
 	ft-show-glyphs-positioning-ref.png		\
+	ft-show-glyphs-positioning-pdf-ref.png		\
+	ft-show-glyphs-positioning-ps-ref.png		\
 	ft-text-vertical-layout-type1-ps-ref.png	\
 	ft-text-vertical-layout-type1-ref.png	\
 	ft-text-vertical-layout-type1-svg-ref.png	\
diff --git a/test/ft-show-glyphs-positioning-pdf-ref.png b/test/ft-show-glyphs-positioning-pdf-ref.png
new file mode 100644
index 0000000..11f6953
Binary files /dev/null and b/test/ft-show-glyphs-positioning-pdf-ref.png differ
diff --git a/test/ft-show-glyphs-positioning-ps-ref.png b/test/ft-show-glyphs-positioning-ps-ref.png
new file mode 100644
index 0000000..c5fbf30
Binary files /dev/null and b/test/ft-show-glyphs-positioning-ps-ref.png differ
commit 4f56a6324f16fa58c21180cc362ee18520a59179
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 21 16:30:53 2008 +1030

    Finish the PDF text operator decimal reduction commit
    
    Commit 158b32b60bc7e0f6488383c1d4f83203ffe97c98 reduced excess
    decimals emitted for the TJ operator. However it only fixed the first
    of the two locations in pdf-operators where the TJ position
    adjustments are emitted.

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 9c14d61..9bf577f 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -923,10 +923,16 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                 if (in_TJ) {
                     if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
                         double delta = glyphs[i].x - Tm_x;
+			int rounded_delta;
 
-                        _cairo_output_stream_printf (word_wrap_stream,
-                                                     "> %f <",
-                                                     -1000.0*delta/scaled_font->scale.xx);
+			delta = -1000.0*delta/scaled_font->scale.xx;
+			rounded_delta = _cairo_lround (delta);
+			if (rounded_delta != 0) {
+			    _cairo_output_stream_printf (word_wrap_stream,
+							 "> %d <",
+							 rounded_delta);
+			}
+			delta = rounded_delta*scaled_font->scale.xx/-1000.0;
                         Tm_x += delta;
                     }
                     _cairo_output_stream_printf (word_wrap_stream,
commit 13e05bffd5cae5690fada24c7a7e2457c39e4dbf
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 21 15:41:31 2008 +1030

    Fix PS glyph positioning bug in PDF operator emulation
    
    The emulation of the PDF 'TJ' operator in the PS prolog was
    incorrectly updating the glyph position between strings. The glyph
    position values are a negative x offset that are in 1/1000 unit of
    text space. We were incorrectly multiplying the number by -0.0001
    instead of -0.001. We also need to transform this to device space
    before calling rmoveto.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 8614b8a..bfe8b19 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -180,11 +180,12 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 				 "  {\n"
 				 "    dup\n"
 				 "    type /stringtype eq\n"
-				 "    { show } { -0.0001 mul 0 rmoveto } ifelse\n"
+				 "    { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse\n"
 				 "  } forall\n"
 				 "} bind def\n"
 				 "/Td { moveto } bind def\n"
-				 "/Tm { 6 array astore cairo_font exch selectfont 0 0 moveto } bind def\n"
+				 "/Tm { 6 array astore dup /cairo_font_matrix exch def\n"
+				 "      cairo_font exch selectfont 0 0 moveto } bind def\n"
 				 "/g { setgray } bind def\n"
 				 "/rg { setrgbcolor } bind def\n");
 
commit 83486684520f3fd27d1118aa23462d013def83df
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 21 16:06:12 2008 +1030

    Add ft-show-glyphs-positioning test
    
    This demonstrates the glyph positioning bug in the PS backend.

diff --git a/test/.gitignore b/test/.gitignore
index 7f0a016..19a4a1f 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -64,6 +64,7 @@ fill-rule
 filter-nearest-offset
 ft-text-antialias-none
 ft-font-create-for-ft-face
+ft-show-glyphs-positioning
 ft-text-vertical-layout-type1
 ft-text-vertical-layout-type3
 font-face-get-type
diff --git a/test/Makefile.am b/test/Makefile.am
index c890a04..a1199a7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -195,6 +195,7 @@ endif
 if CAIRO_HAS_FT_FONT
 TESTS += bitmap-font$(EXEEXT)
 TESTS += ft-font-create-for-ft-face$(EXEEXT)
+TESTS += ft-show-glyphs-positioning$(EXEEXT)
 TESTS += ft-text-vertical-layout-type1$(EXEEXT)
 TESTS += ft-text-vertical-layout-type3$(EXEEXT)
 TESTS += ft-text-antialias-none$(EXEEXT)
@@ -373,6 +374,7 @@ REFERENCE_IMAGES = \
 	font-matrix-translation-quartz-ref.png \
 	ft-text-antialias-none-ps-argb32-ref.png	\
 	ft-text-antialias-none-ref.png	\
+	ft-show-glyphs-positioning-ref.png		\
 	ft-text-vertical-layout-type1-ps-ref.png	\
 	ft-text-vertical-layout-type1-ref.png	\
 	ft-text-vertical-layout-type1-svg-ref.png	\
diff --git a/test/ft-show-glyphs-positioning-ref.png b/test/ft-show-glyphs-positioning-ref.png
new file mode 100644
index 0000000..21b9a4e
Binary files /dev/null and b/test/ft-show-glyphs-positioning-ref.png differ
diff --git a/test/ft-show-glyphs-positioning.c b/test/ft-show-glyphs-positioning.c
new file mode 100644
index 0000000..d23c531
--- /dev/null
+++ b/test/ft-show-glyphs-positioning.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright © 2008 Adrian Johnson
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Adrian Johnson <ajohnson at redneon.com>
+ */
+
+#include "cairo-test.h"
+#include <cairo-ft.h>
+
+#define TEXT_SIZE 12
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "ft-show-glyphs-positioning",
+    "Test that the PS/PDF glyph positioning optimizations are correct",
+    235, (TEXT_SIZE + 4)*2,
+    draw
+};
+
+typedef struct {
+    cairo_glyph_t glyph_list[100];
+    int num_glyphs;
+    double x;
+    double y;
+} glyph_array_t;
+
+static void
+glyph_array_init (glyph_array_t *glyphs, double x, double y)
+{
+    glyphs->num_glyphs = 0;
+    glyphs->x = x;
+    glyphs->y = y;
+}
+
+static void
+glyph_array_rel_move_to (glyph_array_t *glyphs, double x, double y)
+{
+    glyphs->x += x;
+    glyphs->y += y;
+}
+
+static void
+glyph_array_show (glyph_array_t *glyphs, cairo_t *cr)
+{
+    cairo_show_glyphs (cr, glyphs->glyph_list, glyphs->num_glyphs);
+}
+
+#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
+
+static void
+glyph_array_add_text(glyph_array_t *glyphs, cairo_t *cr, const char *s, double spacing)
+{
+    cairo_scaled_font_t *scaled_font;
+    FT_Face face;
+    unsigned long charcode;
+    unsigned int index;
+    cairo_text_extents_t extents;
+    const char *p;
+    FT_Vector kerning;
+    double kern_x;
+    int first = TRUE;
+
+    scaled_font = cairo_get_scaled_font (cr);
+    face = cairo_ft_scaled_font_lock_face (scaled_font);
+    p = s;
+    while (*p)
+    {
+        charcode = *p;
+        index = FT_Get_Char_Index (face, charcode);
+        glyphs->glyph_list[glyphs->num_glyphs].index = index;
+        if (first) {
+            first = FALSE;
+            glyphs->glyph_list[glyphs->num_glyphs].x = glyphs->x;
+            glyphs->glyph_list[glyphs->num_glyphs].y = glyphs->y;
+        } else {
+            cairo_glyph_extents (cr, &glyphs->glyph_list[glyphs->num_glyphs - 1], 1, &extents);
+            FT_Get_Kerning (face,
+                            glyphs->glyph_list[glyphs->num_glyphs - 1].index,
+                            glyphs->glyph_list[glyphs->num_glyphs].index,
+                            FT_KERNING_UNSCALED,
+                            &kerning);
+            kern_x = DOUBLE_FROM_26_6(kerning.x);
+            glyphs->glyph_list[glyphs->num_glyphs].x =
+		glyphs->glyph_list[glyphs->num_glyphs - 1].x + extents.x_advance + kern_x + spacing;
+            glyphs->glyph_list[glyphs->num_glyphs].y =
+		glyphs->glyph_list[glyphs->num_glyphs - 1].y + extents.y_advance;
+	}
+
+	cairo_glyph_extents (cr, &glyphs->glyph_list[glyphs->num_glyphs], 1, &extents);
+	glyphs->x = glyphs->glyph_list[glyphs->num_glyphs].x + extents.x_advance + spacing;
+	glyphs->y = glyphs->glyph_list[glyphs->num_glyphs].y + extents.y_advance;
+	p++;
+        glyphs->num_glyphs++;
+    }
+
+    cairo_ft_scaled_font_unlock_face (scaled_font);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    glyph_array_t glyphs;
+    cairo_font_options_t *font_options;
+
+    /* paint white so we don't need separate ref images for
+     * RGB24 and ARGB32 */
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+    cairo_paint (cr);
+
+    cairo_select_font_face (cr, "Bitstream Vera Sans",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, TEXT_SIZE);
+
+    font_options = cairo_font_options_create ();
+    cairo_get_font_options (cr, font_options);
+    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
+    cairo_set_font_options (cr, font_options);
+    cairo_font_options_destroy (font_options);
+
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+
+    glyph_array_init (&glyphs, 1, TEXT_SIZE);
+    glyph_array_add_text(&glyphs, cr, "AWAY again", 0.0);
+    glyph_array_rel_move_to (&glyphs, TEXT_SIZE*1, 0.0);
+    glyph_array_add_text(&glyphs, cr, "character space", TEXT_SIZE*0.3);
+    glyph_array_show (&glyphs, cr);
+
+    glyph_array_init (&glyphs, 1, TEXT_SIZE*2 + 4);
+    glyph_array_add_text(&glyphs, cr, "Increasing", 0.0);
+    glyph_array_rel_move_to (&glyphs, TEXT_SIZE*0.5, 0.0);
+    glyph_array_add_text(&glyphs, cr, "space", 0.0);
+    glyph_array_rel_move_to (&glyphs, TEXT_SIZE*1.0, 0.0);
+    glyph_array_add_text(&glyphs, cr, "between", 0.0);
+    glyph_array_rel_move_to (&glyphs, TEXT_SIZE*1.5, 0.0);
+    glyph_array_add_text(&glyphs, cr, "words", 0.0);
+    glyph_array_show (&glyphs, cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}


More information about the cairo-commit mailing list