From c5814d2aa3cb68a13bc9cc8b6a47f660febcad71 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 11 Apr 2008 21:42:19 +0930 Subject: [PATCH] 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. --- src/cairo-ps-surface.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) 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"); -- 1.5.2.4