File: 04_tibco-changes.patch

package info (click to toggle)
libitext-java 2.1.7-11
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,624 kB
  • ctags: 15,568
  • sloc: java: 94,208; xml: 1,049; sh: 15; makefile: 8
file content (313 lines) | stat: -rw-r--r-- 11,310 bytes parent folder | download | duplicates (4)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Description: Modifications made by TIBCO Software for JasperReports >= 6.2 :
 #1 Fix for transparency issue with setClip method in PdfGraphics2D
 #2 Fix for transparency bleeding for Batik gradients
 #3 Fix for stroke opacity state in the create() method of PdfGraphics2D
 #4 Method to directly write AWT GlyphVectors to PDF for Indic scripts support
 #5 No character spacing in justified lines with a single word
Origin: other, http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js5/itext-2.1.7.js5-sources.jar
Forwarded: no
--- a/core/com/lowagie/text/pdf/FontDetails.java
+++ b/core/com/lowagie/text/pdf/FontDetails.java
@@ -245,6 +245,43 @@
         return b;
     }
     
+    // TIBCO Software #4 : Part 1 - START
+	byte[] convertToBytes(GlyphVector glyphVector) {
+		if (fontType != BaseFont.FONT_TYPE_TTUNI || symbolic) {
+			throw new UnsupportedOperationException("Only supported for True Type Unicode fonts");
+		}
+
+		char[] glyphs = new char[glyphVector.getNumGlyphs()];
+		int glyphCount = 0;
+		for (int i = 0; i < glyphs.length; i++) {
+			int code = glyphVector.getGlyphCode(i);
+			if (code == 0xFFFE || code == 0xFFFF) {// considered non-glyphs by AWT
+				continue;
+			}
+
+			glyphs[glyphCount++] = (char) code;// FIXME supplementary plane?
+
+			Integer codeKey = new Integer(code);
+			if (!longTag.containsKey(codeKey)) {
+				int glyphWidth = ttu.getGlyphWidth(code);
+				Integer charCode = ttu.getCharacterCode(code);
+				int[] metrics = charCode != null 
+						? new int[] { code, glyphWidth, charCode.intValue() }
+						: new int[] { code, glyphWidth };
+				longTag.put(codeKey, metrics);
+			}
+		}
+
+		String s = new String(glyphs, 0, glyphCount);
+		try {
+			byte[] b = s.getBytes(CJKFont.CJK_ENCODING);
+			return b;
+		} catch (UnsupportedEncodingException e) {
+			throw new ExceptionConverter(e);
+		}
+	}
+    // TIBCO Software #4 : Part 1 - END
+    
     /**
      * Writes the font definition to the document.
      * @param writer the <CODE>PdfWriter</CODE> of this document
--- a/core/com/lowagie/text/pdf/PdfContentByte.java
+++ b/core/com/lowagie/text/pdf/PdfContentByte.java
@@ -49,8 +49,10 @@
 
 package com.lowagie.text.pdf;
 import java.awt.Color;
+import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.print.PrinterJob;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -1433,6 +1435,14 @@
         content.append("Tj").append_i(separator);
     }
 
+    // TIBCO Software #4 : Part 1 - START
+	public void showText(GlyphVector glyphVector) {
+		byte[] b = state.fontDetails.convertToBytes(glyphVector);
+		escapeString(b, content);
+		content.append("Tj").append_i(separator);
+	}
+    // TIBCO Software #4 : Part 1 - END
+
     /**
      * Constructs a kern array for a text in a certain font
      * @param text the text
@@ -3014,6 +3024,13 @@
      * @param struc the tagging structure
      */
     public void beginMarkedContentSequence(PdfStructureElement struc) {
+        // TIBCO Software #4 : Part 1 - START
+    	PdfDictionary dict = new PdfDictionary();
+    	beginMarkedContentSequence(struc, dict);
+    }
+
+    public void beginMarkedContentSequence(PdfStructureElement struc, PdfDictionary dict) {
+        // TIBCO Software #4 : Part 1 - END
         PdfObject obj = struc.get(PdfName.K);
         int mark = pdf.getMarkPoint();
         if (obj != null) {
@@ -3042,7 +3059,16 @@
         }
         pdf.incMarkPoint();
         mcDepth++;
-        content.append(struc.get(PdfName.S).getBytes()).append(" <</MCID ").append(mark).append(">> BDC").append_i(separator);
+        // TIBCO Software #4 : Part 1 - START
+		dict.put(PdfName.MCID, new PdfNumber(mark));
+		content.append(struc.get(PdfName.S).getBytes()).append(" ");
+		try {
+			dict.toPdf(writer, content);
+		} catch (IOException e) {
+			throw new ExceptionConverter(e);
+		}
+		content.append(" BDC").append_i(separator);
+        // TIBCO Software #4 : Part 1 - END
     }
 
     /**
--- a/core/com/lowagie/text/pdf/PdfDocument.java
+++ b/core/com/lowagie/text/pdf/PdfDocument.java
@@ -1397,7 +1397,13 @@
                         hangingCorrection = width - oldWidth;
                     }
                 }
-                float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
+                
+                // TIBCO Software #5 : Part 1 - START
+                // if there's a single word on the line and we are using NO_SPACE_CHAR_RATIO,
+                // we don't want any character spacing
+                float baseFactor = (numberOfSpaces == 0 && ratio == PdfWriter.NO_SPACE_CHAR_RATIO) 
+                		? 0f : width / (ratio * numberOfSpaces + lineLen - 1);
+                // TIBCO Software #5 : Part 1 - END
                 baseWordSpacing = ratio * baseFactor;
                 baseCharacterSpacing = baseFactor;
                 lastBaseFactor = baseFactor;
--- a/core/com/lowagie/text/pdf/PdfGraphics2D.java
+++ b/core/com/lowagie/text/pdf/PdfGraphics2D.java
@@ -189,6 +189,9 @@
      * Constructor for PDFGraphics2D.
      *
      */
+    // TIBCO Software #4 : Part 1 - START
+    protected
+    // TIBCO Software #4 : Part 1 - END
     PdfGraphics2D(PdfContentByte cb, float width, float height, FontMapper fontMapper, boolean onlyShapes, boolean convertImagesToJPEG, float quality) {
         super();
         dg2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
@@ -909,6 +912,9 @@
         g2.paint = this.paint;
         g2.fillGState = this.fillGState;
         g2.currentFillGState = this.currentFillGState;
+        // TIBCO Software #3 : Part 1 - START
+        g2.currentStrokeGState = this.currentStrokeGState;
+        // TIBCO Software #3 : Part 1 - END
         g2.strokeGState = this.strokeGState;
         g2.background = this.background;
         g2.mediaTracker = this.mediaTracker;
@@ -1086,7 +1092,9 @@
             followPath(s, CLIP);
         }
         paintFill = paintStroke = null;
-        currentFillGState = currentStrokeGState = 255;
+        // TIBCO Software #1 : Part 1 - START
+        currentFillGState = currentStrokeGState = -1; // 255;
+        // TIBCO Software #1 : Part 1 - END
         oldStroke = strokeOne;
     }
     
@@ -1487,7 +1495,9 @@
         } catch (Exception ex) {
             throw new IllegalArgumentException();
         }
-        if (currentFillGState != 255) {
+        // TIBCO Software #1 : Part 2 - START
+        if (currentFillGState != 255 && currentFillGState != -1) {
+        // TIBCO Software #1 : Part 2 - END
             PdfGState gs = fillGState[currentFillGState];
             cb.setGState(gs);
         }        
@@ -1613,8 +1623,21 @@
                 PdfPatternPainter pattern = cb.createPattern(width, height);
                 image.setAbsolutePosition(0,0);
                 pattern.addImage(image);
-                if (fill)
+                // TIBCO Software #2 : Part 1 - START
+                if (fill) {
+                    if (currentFillGState != 255) {
+                        currentFillGState = 255;
+                        PdfGState gs = fillGState[255];
+                        if (gs == null) {
+                            gs = new PdfGState();
+                            gs.setFillOpacity(1);
+                            fillGState[255] = gs;
+                        }
+                        cb.setGState(gs);
+                    }
                     cb.setPatternFill(pattern);
+                }
+                // TIBCO Software #2 : Part 1 - END
                 else
                     cb.setPatternStroke(pattern);
             } catch (Exception ex) {
--- a/core/com/lowagie/text/pdf/TrueTypeFont.java
+++ b/core/com/lowagie/text/pdf/TrueTypeFont.java
@@ -671,7 +671,9 @@
                 readCMaps();
                 readKerning();
                 readBbox();
-                GlyphWidths = null;
+                // TIBCO Software #4 : Part 1 - START
+                //GlyphWidths = null;
+                // TIBCO Software #4 : Part 1 - END
             }
         }
         finally {
--- a/core/com/lowagie/text/pdf/TrueTypeFontUnicode.java
+++ b/core/com/lowagie/text/pdf/TrueTypeFontUnicode.java
@@ -50,9 +50,13 @@
 package com.lowagie.text.pdf;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import com.lowagie.text.DocumentException;
 import com.lowagie.text.Utilities;
@@ -70,6 +74,10 @@
      */    
     boolean vertical = false;
     
+    // TIBCO Software #4 : Part 1 - START
+    HashMap inverseCmap;
+    // TIBCO Software #4 : Part 1 - END
+    
     /**
      * Creates a new TrueType font addressed by Unicode characters. The font
      * will always be embedded.
@@ -116,6 +124,33 @@
         vertical = enc.endsWith("V");
     }
     
+    // TIBCO Software #4 : Part 1 - START
+	void readCMaps() throws DocumentException, IOException {
+		super.readCMaps();
+
+		HashMap cmap = null;
+		if (cmapExt != null) {
+			cmap = cmapExt;
+		} else if (cmap31 != null) {
+			cmap = cmap31;
+		}
+
+		if (cmap != null) {
+			inverseCmap = new HashMap();
+			for (Iterator iterator = cmap.entrySet().iterator(); iterator.hasNext();) {
+				Map.Entry entry = (Map.Entry) iterator.next();
+				Integer code = (Integer) entry.getKey();
+				int[] metrics = (int[]) entry.getValue();
+				inverseCmap.put(new Integer(metrics[0]), code);
+			}
+		}
+	}
+    
+	protected Integer getCharacterCode(int code) {
+		return inverseCmap == null ? null : (Integer) inverseCmap.get(new Integer(code));
+    }
+    // TIBCO Software #4 : Part 1 - END
+    
     /**
      * Gets the width of a <CODE>char</CODE> in normalized 1000 units.
      * @param char1 the unicode <CODE>char</CODE> to get the width of
@@ -173,6 +208,9 @@
      * @return the stream representing this CMap or <CODE>null</CODE>
      */    
     private PdfStream getToUnicode(Object metrics[]) {
+        // TIBCO Software #4 : Part 1 - START
+    	metrics = filterCmapMetrics(metrics);
+        // TIBCO Software #4 : Part 1 - END
         if (metrics.length == 0)
             return null;
         StringBuffer buf = new StringBuffer(
@@ -214,6 +252,30 @@
         return stream;
     }
     
+    // TIBCO Software #4 : Part 1 - START
+	private Object[] filterCmapMetrics(Object[] metrics) {
+		if (metrics.length == 0) {
+			return metrics;
+		}
+
+		List cmapMetrics = new ArrayList(metrics.length);
+		for (int i = 0; i < metrics.length; i++) {
+			int metric[] = (int[]) metrics[i];
+			// PdfContentByte.showText(GlyphVector) uses glyphs that might not map to a character.
+			// the glyphs are included in the metrics array, but we need to exclude them from the cmap.
+			if (metric.length >= 3) {
+				cmapMetrics.add(metric);
+			}
+		}
+
+		if (cmapMetrics.size() == metrics.length) {
+			return metrics;
+		}
+
+		return cmapMetrics.toArray();
+	}
+    // TIBCO Software #4 : Part 1 - END
+    
     private static String toHex4(int n) {
         String s = "0000" + Integer.toHexString(n);
         return s.substring(s.length() - 4);