summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2020-09-17 15:34:02 +0100
committerKen Sharp <ken.sharp@artifex.com>2020-09-17 15:34:21 +0100
commitd5494de2cab28b91ba360d15b8afffef50a3f421 (patch)
treed712afb8d67b0fb01204c4913ea0977d9b3c3292
parentb81a73c34e48a547dd881f07aa046646a472e13c (diff)
downloadghostpdl-d5494de2cab28b91ba360d15b8afffef50a3f421.tar.gz
PDF interpreter with pdfwrite fix non-square scaling stroked text
Bug #702900 "pdfwrite device causes bold text output" The PDF interpreter has special code for dealing with line widths and stroked text, this is because we do not preserve the CTM in the input through to the output in pdfwrite. What we need to do is figure out what line width with an identity CTM would draw a line the same width as the current line width and CTM. Normally pdfwrite takes care of this itself, but until relatively recently it did not have access to the textmatrix, only the CTM. But for text, by the time we get to the point of emitting the text,, the CTM already includes the Text matrix (Tm). So the PDF interpreter (which does have the CTM before the TM is applied) calculates a line width and sets that before sending the text. However, when the scaling was non-square we were not doing that, leading pdfwrite to emit the unscaled linewidth. Intriguingly we have no files in the test suite for which this is a problem, all the files where the CTM is non-square it is also close to the identity so not visibly incorrect. The file here, however, has a non-identity CTM which is slightly non-square when the text is rendered, and very far from the identity. Since we can't tell which scaling to use for the linewidth we 'fudge' it by using the transformed x and y values of the linewidth, as two sides of a triangle, then calculating the hypotenuse. Obviously this won't work for seriously skewed matrices but it seems unlikely we could calculate a reasonable linewidth for that anyway.
-rw-r--r--Resource/Init/pdf_ops.ps32
1 files changed, 20 insertions, 12 deletions
diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps
index 47ff512d9..ac2d56ec4 100644
--- a/Resource/Init/pdf_ops.ps
+++ b/Resource/Init/pdf_ops.ps
@@ -1487,9 +1487,11 @@ currentdict /clip_if_required .undef
abs 2 copy exch abs eq {
pop
}{
- % non-square scaling reduces to Text matrix in pdfwrite , so
- % we can ignore it. (wrong answer, but consistent)
- pop pop currentlinewidth
+ % We used to leave the linewidth alone for non-square resolutions,
+ % claiming it reduced to the text matrix in pdfwrite. This is not
+ % true. So handle it the same way we usually do, the hypotenuse of
+ % the unit square transformed through the TextSaveMatrix.
+ dup mul exch dup mul add sqrt
}ifelse setlinewidth
show setlinewidth} bind executeonly
% Tr 2 - Fill then Stroke
@@ -1507,9 +1509,11 @@ currentdict /clip_if_required .undef
abs 2 copy exch abs eq {
pop
}{
- % non-square scaling reduces to Text matrix in pdfwrite , so
- % we can ignore it. (wrong answer, but consistent)
- pop pop currentlinewidth
+ % We used to leave the linewidth alone for non-square resolutions,
+ % claiming it reduced to the text matrix in pdfwrite. This is not
+ % true. So handle it the same way we usually do, the hypotenuse of
+ % the unit square transformed through the TextSaveMatrix.
+ dup mul exch dup mul add sqrt
}ifelse setlinewidth
setsmaskstate show setlinewidth} bind executeonly
% Tr 3 - Neither fill nor stroke
@@ -1530,9 +1534,11 @@ currentdict /clip_if_required .undef
abs 2 copy exch abs eq {
pop
}{
- % non-square scaling reduces to Text matrix in pdfwrite , so
- % we can ignore it. (wrong answer, but consistent)
- pop pop currentlinewidth
+ % We used to leave the linewidth alone for non-square resolutions,
+ % claiming it reduced to the text matrix in pdfwrite. This is not
+ % true. So handle it the same way we usually do, the hypotenuse of
+ % the unit square transformed through the TextSaveMatrix.
+ dup mul exch dup mul add sqrt
}ifelse setlinewidth
setsmaskstate dup show grestore
//true charpath} bind executeonly
@@ -1547,9 +1553,11 @@ currentdict /clip_if_required .undef
abs 2 copy exch abs eq {
pop
}{
- % non-square scaling reduces to Text matrix in pdfwrite , so
- % we can ignore it. (wrong answer, but consistent)
- pop pop currentlinewidth
+ % We used to leave the linewidth alone for non-square resolutions,
+ % claiming it reduced to the text matrix in pdfwrite. This is not
+ % true. So handle it the same way we usually do, the hypotenuse of
+ % the unit square transformed through the TextSaveMatrix.
+ dup mul exch dup mul add sqrt
}ifelse setlinewidth
setsmaskstate dup show grestore
//true charpath} bind executeonly