Skip to content

Commit 56cf7b2

Browse files
committed
Change visibility of Type3Font to internal.
DEVSIX-1468
1 parent 5c4e1ac commit 56cf7b2

File tree

3 files changed

+55
-40
lines changed

3 files changed

+55
-40
lines changed

kernel/src/main/java/com/itextpdf/kernel/font/PdfType3Font.java

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public class PdfType3Font extends PdfSimpleFont<Type3Font> {
107107
*/
108108
PdfType3Font(PdfDocument document, String fontName, String fontFamily, boolean colorized) {
109109
this(document, colorized);
110-
((Type3Font)fontProgram).setFontName(fontName);
111-
((Type3Font)fontProgram).setFontFamily(fontFamily);
110+
((Type3Font) fontProgram).setFontName(fontName);
111+
((Type3Font) fontProgram).setFontFamily(fontFamily);
112112
}
113113

114114
/**
@@ -157,7 +157,7 @@ public class PdfType3Font extends PdfSimpleFont<Type3Font> {
157157
* @param fontName the PostScript name of the font, shall not be null or empty.
158158
*/
159159
public void setFontName(String fontName) {
160-
((Type3Font)fontProgram).setFontName(fontName);
160+
((Type3Font) fontProgram).setFontName(fontName);
161161
}
162162

163163
/**
@@ -166,7 +166,7 @@ public void setFontName(String fontName) {
166166
* @param fontFamily a preferred font family name.
167167
*/
168168
public void setFontFamily(String fontFamily) {
169-
((Type3Font)fontProgram).setFontFamily(fontFamily);
169+
((Type3Font) fontProgram).setFontFamily(fontFamily);
170170
}
171171

172172
/**
@@ -175,7 +175,7 @@ public void setFontFamily(String fontFamily) {
175175
* @param fontWeight integer form 100 to 900. See {@link FontWeights}.
176176
*/
177177
public void setFontWeight(int fontWeight) {
178-
((Type3Font)fontProgram).setFontWeight(fontWeight);
178+
((Type3Font) fontProgram).setFontWeight(fontWeight);
179179
}
180180

181181
/**
@@ -186,7 +186,7 @@ public void setFontWeight(int fontWeight) {
186186
* @param italicAngle in counter-clockwise degrees from the vertical
187187
*/
188188
public void setItalicAngle(int italicAngle) {
189-
((Type3Font)fontProgram).setItalicAngle(italicAngle);
189+
((Type3Font) fontProgram).setItalicAngle(italicAngle);
190190
}
191191

192192
/**
@@ -195,17 +195,17 @@ public void setItalicAngle(int italicAngle) {
195195
* @param fontWidth {@link FontStretches}.
196196
*/
197197
public void setFontStretch(String fontWidth) {
198-
((Type3Font)fontProgram).setFontStretch(fontWidth);
198+
((Type3Font) fontProgram).setFontStretch(fontWidth);
199199
}
200200

201201
/**
202202
* Sets Font descriptor flags.
203-
* @see FontDescriptorFlags
204203
*
205204
* @param flags font descriptor flags.
205+
* @see FontDescriptorFlags
206206
*/
207207
public void setPdfFontFlags(int flags) {
208-
((Type3Font)fontProgram).setPdfFontFlags(flags);
208+
((Type3Font) fontProgram).setPdfFontFlags(flags);
209209
}
210210

211211

@@ -232,6 +232,15 @@ public void setFontMatrix(double[] fontMatrix) {
232232
this.fontMatrix = fontMatrix;
233233
}
234234

235+
/**
236+
* Gets count of glyphs in Type 3 font.
237+
*
238+
* @return number of glyphs.
239+
*/
240+
public int getGlyphsCount() {
241+
return ((Type3Font) getFontProgram()).getGlyphsCount();
242+
}
243+
235244
/**
236245
* Defines a glyph. If the character was already defined it will return the same content
237246
*
@@ -293,6 +302,32 @@ public boolean containsGlyph(int unicode) {
293302
&& getFontProgram().getGlyph(fontEncoding.getUnicodeDifference(unicode)) != null;
294303
}
295304

305+
@Override
306+
public void flush() {
307+
ensureUnderlyingObjectHasIndirectReference();
308+
if (((Type3Font) getFontProgram()).getGlyphsCount() < 1) {
309+
throw new PdfException("no.glyphs.defined.fo r.type3.font");
310+
}
311+
312+
PdfDictionary charProcs = new PdfDictionary();
313+
for (int i = 0; i < 256; i++) {
314+
if (fontEncoding.canDecode(i)) {
315+
Type3Glyph glyph = getType3Glyph(fontEncoding.getUnicode(i));
316+
if (glyph != null) {
317+
charProcs.put(new PdfName(fontEncoding.getDifference(i)), glyph.getContentStream());
318+
glyph.getContentStream().flush();
319+
}
320+
}
321+
}
322+
323+
getPdfObject().put(PdfName.CharProcs, charProcs);
324+
getPdfObject().put(PdfName.FontMatrix, new PdfArray(getFontMatrix()));
325+
getPdfObject().put(PdfName.FontBBox, new PdfArray(fontProgram.getFontMetrics().getBbox()));
326+
327+
super.flushFontData(fontProgram.getFontNames().getFontName(), PdfName.Type3);
328+
super.flush();
329+
}
330+
296331
@Override
297332
protected PdfDictionary getFontDescriptor(String fontName) {
298333
if (fontName != null && fontName.length() > 0) {
@@ -332,31 +367,6 @@ protected PdfDocument getDocument() {
332367
return getPdfObject().getIndirectReference().getDocument();
333368
}
334369

335-
@Override
336-
public void flush() {
337-
ensureUnderlyingObjectHasIndirectReference();
338-
if (((Type3Font) getFontProgram()).getGlyphsCount() < 1) {
339-
throw new PdfException("no.glyphs.defined.fo r.type3.font");
340-
}
341-
342-
PdfDictionary charProcs = new PdfDictionary();
343-
for (int i = 0; i < 256; i++) {
344-
if (fontEncoding.canDecode(i)) {
345-
Type3Glyph glyph = getType3Glyph(fontEncoding.getUnicode(i));
346-
if (glyph != null) {
347-
charProcs.put(new PdfName(fontEncoding.getDifference(i)), glyph.getContentStream());
348-
glyph.getContentStream().flush();
349-
}
350-
}
351-
}
352-
353-
getPdfObject().put(PdfName.CharProcs, charProcs);
354-
getPdfObject().put(PdfName.FontMatrix, new PdfArray(getFontMatrix()));
355-
getPdfObject().put(PdfName.FontBBox, new PdfArray(fontProgram.getFontMetrics().getBbox()));
356-
357-
super.flushFontData(fontProgram.getFontNames().getFontName(), PdfName.Type3);
358-
super.flush();
359-
}
360370

361371
/**
362372
* Gets first empty code, that could use with {@see addSymbol()}

kernel/src/main/java/com/itextpdf/kernel/font/Type3Font.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@ This file is part of the iText (R) project.
5353
import java.util.HashMap;
5454
import java.util.Map;
5555

56-
public class Type3Font extends FontProgram {
56+
class Type3Font extends FontProgram {
5757

5858
private static final long serialVersionUID = 1027076515537536993L;
5959

6060
private final Map<Integer, Type3Glyph> type3Glyphs = new HashMap<>();
6161
private boolean colorized = false;
6262
private int flags = 0;
6363

64-
public Type3Font(boolean colorized) {
64+
/**
65+
* Creates a Type 3 font programm.
66+
*
67+
* @param colorized defines whether the glyph color is specified in the glyph descriptions in the font.
68+
* @deprecated Type 3 font should contain font name and font family in case tagged PDF.
69+
*/
70+
Type3Font(boolean colorized) {
6571
this.colorized = colorized;
6672
this.fontNames = new FontNames();
6773
getFontMetrics().setBbox(0, 0, 0, 0);
@@ -120,7 +126,7 @@ protected void setFontFamily(String fontFamily) {
120126
* @param fontWeight integer form 100 to 900. See {@link FontWeights}.
121127
*/
122128
@Override //This dummy override allows PdfType3Font to set font weight.
123-
protected void setFontWeight(int fontWeight) {
129+
public void setFontWeight(int fontWeight) {
124130
super.setFontWeight(fontWeight);
125131
}
126132

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfFontTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ This file is part of the iText (R) project.
6464
import com.itextpdf.kernel.font.PdfType0Font;
6565
import com.itextpdf.kernel.font.PdfType1Font;
6666
import com.itextpdf.kernel.font.PdfType3Font;
67-
import com.itextpdf.kernel.font.Type3Font;
6867
import com.itextpdf.kernel.font.Type3Glyph;
6968
import com.itextpdf.kernel.geom.PageSize;
7069
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
@@ -883,7 +882,7 @@ public void testUpdateType3FontBasedExistingFont() throws IOException, Interrupt
883882
page.flush();
884883
pdfDoc.close();
885884

886-
Assert.assertEquals(6, ((Type3Font) pdfType3Font.getFontProgram()).getGlyphsCount());
885+
Assert.assertEquals(6, pdfType3Font.getGlyphsCount());
887886

888887
Assert.assertNull(new CompareTool().compareByContent(outputFileName, cmpOutputFileName, destinationFolder, "diff_"));
889888
}
@@ -926,7 +925,7 @@ public void testNewType3FontBasedExistingFont() throws IOException, InterruptedE
926925
page.flush();
927926
outputPdfDoc.close();
928927

929-
Assert.assertEquals(6, ((Type3Font) pdfType3Font.getFontProgram()).getGlyphsCount());
928+
Assert.assertEquals(6, pdfType3Font.getGlyphsCount());
930929

931930
Assert.assertNull(new CompareTool().compareByContent(outputFileName, cmpOutputFileName, destinationFolder, "diff_"));
932931
}

0 commit comments

Comments
 (0)