1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$ */
package org.apache.fop.svg;
import java.awt.Graphics2D;
import java.io.StringWriter;
import org.junit.Test;
import org.apache.batik.gvt.TextPainter;
import org.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.pdf.PDFDocument;
public class PDFTextPainterTestCase extends NativeTextPainterTest {
private static class OperatorCheckingPDFGraphics2D extends PDFGraphics2D {
OperatorCheckingPDFGraphics2D(FontInfo fontInfo, final OperatorValidator validator) {
super(false, fontInfo, new PDFDocument("test"), null, null, null, 0, null);
this.currentStream = new StringWriter() {
@Override
public void write(String str) {
validator.check(str);
}
};
}
}
@Override
protected TextPainter createTextPainter(FontInfo fontInfo) {
return new PDFTextPainter(fontInfo);
}
@Override
protected Graphics2D createGraphics2D(FontInfo fontInfo, OperatorValidator validator) {
PDFGraphics2D g2d = new OperatorCheckingPDFGraphics2D(fontInfo, validator);
g2d.setGraphicContext(new GraphicContext());
return g2d;
}
@Test
public void testRotatedGlyph() throws Exception {
runTest("rotated-glyph.svg", new OperatorValidator()
.addOperatorMatch("Tm", "1 0 0 -1 40 110 Tm ")
.addOperatorMatch("TJ", "[(A)] TJ\n")
.addOperatorMatch("Tm", "0.70710677 0.7071068 0.7071068 -0.70710677 106.69999695 110 Tm ")
.addOperatorMatch("TJ", "[(B)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 173.3999939 110 Tm ")
.addOperatorMatch("TJ", "[(C)] TJ\n"));
}
@Test
public void testDxDy() throws Exception {
runTest("dx-dy.svg", new OperatorValidator()
.addOperatorMatch("Tm", "1 0 0 -1 55 35 Tm ")
.addOperatorMatch("TJ", "[(ABCDE)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 55 75 Tm ")
.addOperatorMatch("TJ", "[(A)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 69 85 Tm ")
.addOperatorMatch("TJ", "[(B)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 109 80 Tm ")
.addOperatorMatch("TJ", "[(C)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 91 65 Tm ")
.addOperatorMatch("TJ", "[(D)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 127 75 Tm ")
.addOperatorMatch("TJ", "[(E)] TJ\n"));
}
@Test
public void testSpacing() throws Exception {
runTest("spacing.svg", new OperatorValidator()
.addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
.addOperatorMatch("TJ", "[(V) 80 (A) 70 (V)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
.addOperatorMatch("TJ", "[(V) 80 (A) 70 (V)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
.addOperatorMatch("TJ", "[(V) -20 (A) -30 (V)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
.addOperatorMatch("TJ", "[(ab) -111 ( ) -389 (cd)] TJ\n"));
}
@Test
public void testGlyphOrientation() throws Exception {
runTest("glyph-orientation.svg", new OperatorValidator()
.addOperatorMatch("Tm", "0 1 1 0 738.5 0 Tm ")
.addOperatorMatch("TJ", "[(A)] TJ\n")
.addOperatorMatch("Tm", "0 1 1 0 738.5 667 Tm ")
.addOperatorMatch("TJ", "[(B)] TJ\n")
.addOperatorMatch("Tm", "0 1 1 0 738.5 1334 Tm ")
.addOperatorMatch("TJ", "[(C)] TJ\n")
.addOperatorMatch("Tm", "0 1 1 0 738.5 2056 Tm ")
.addOperatorMatch("TJ", "[(D)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 2149 718 Tm ")
.addOperatorMatch("TJ", "[(E)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 2165.5 1643 Tm ")
.addOperatorMatch("TJ", "[(F)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 2124 2568 Tm ")
.addOperatorMatch("TJ", "[(G)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 2138.5 3493 Tm ")
.addOperatorMatch("TJ", "[(H)] TJ\n")
.addOperatorMatch("Tm", "0 -1 -1 0 718 5000 Tm ")
.addOperatorMatch("TJ", "[(I)] TJ\n")
.addOperatorMatch("Tm", "0 -1 -1 0 1643 5000 Tm ")
.addOperatorMatch("TJ", "[(J)] TJ\n")
.addOperatorMatch("Tm", "0 -1 -1 0 2568 5000 Tm ")
.addOperatorMatch("TJ", "[(K)] TJ\n")
.addOperatorMatch("Tm", "0 -1 -1 0 3493 5000 Tm ")
.addOperatorMatch("TJ", "[(L)] TJ\n"));
}
@Test
public void testBaselineShift() throws Exception {
runTest("baseline-shift.svg", new OperatorValidator()
.addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
.addOperatorMatch("TJ", "[(AB)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 1334 -462.5 Tm ")
.addOperatorMatch("TJ", "[(CD)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 2778 0 Tm ")
.addOperatorMatch("TJ", "[(EF)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 4056 462.5 Tm ")
.addOperatorMatch("TJ", "[(GH)] TJ\n")
.addOperatorMatch("Tm", "1 0 0 -1 5556 0 Tm ")
.addOperatorMatch("TJ", "[(IJ)] TJ\n"));
}
}
|