[cairo-commit] src/cairo-ps-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Fri Apr 11 06:08:15 PDT 2008


 src/cairo-ps-surface.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

New commits:
commit c5814d2aa3cb68a13bc9cc8b6a47f660febcad71
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Apr 11 21:42:19 2008 +0930

    PS: Fix inefficient implementation of Tm/Td operators that was crashing printers
    
    The Td and Tm operator emulation were setting the font matrix like this:
    
      /some_font [xx yx xy yy x0 y0] selectfont
    
    where [xx yx xy yy] is the font matrix and [x0 y0] is the position of
    the first glyph to be drawn. This seemed to be the easiest way to
    emulate the Tm operator since the six arguments to Tm required by PDF
    are xx,yx,xy,yy,x0,y0.
    
    Before the switch to pdf-operators the font matrix was set like this:
    
      /somefont [xx yx xy yy 0 0] selectfont x0 y0 moveto
    
    The selectfont operator is equivalent to calling findfont, makefont,
    and setfont. The makefont operator creates a new font dictionary for
    specified font that contains the specified font matrix. The
    description of the makefont operator in the PostScript Language
    Reference Manual states:
    
      "The interpreter keeps track of font dictionaries recently created
       by makefont. Calling makefont multiple times with the same font and
       matrix will usually return the same font rather than create a new
       one."
    
    So the emulation of Tm and Td was creating a new font dictionary every
    time a text string was displayed due to the change in the translation
    components of the font matrix. Previously the font dictionary was
    re-used as with the translation components of the matrix set to zero,
    the font matrix did not change frequently.
    
    Some printers did not handle well the frequent creation a font
    dictionary every time a few glyphs were displayed.
    
    Fix this by ensuring the translation components of the font matrix
    used in the emulation of Tm and Td operators is always set to
    zero. Use moveto instead for the translation components.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 54f5afe..f6940bf 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -183,10 +183,11 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 				 "    { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse\n"
 				 "  } forall\n"
 				 "} bind def\n"
-				 "/Td { matrix translate cairo_font_matrix matrix concatmatrix dup\n"
-				 "   /cairo_font_matrix exch def 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"
+				 "/Td { matrix translate cairo_font_matrix matrix concatmatrix aload\n"
+				 "      /cairo_font_matrix exch def 6 2 roll 0 0 6 array astore\n"
+				 "      cairo_font exch selectfont moveto } bind def\n"
+				 "/Tm { 6 copy 6 array astore /cairo_font_matrix exch def 6 2 roll 0 0\n"
+				 "      6 array astore cairo_font exch selectfont moveto } bind def\n"
 				 "/g { setgray } bind def\n"
 				 "/rg { setrgbcolor } bind def\n");
 


More information about the cairo-commit mailing list