aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorPeter Hancock <phancock@apache.org>2011-09-26 09:48:20 +0000
committerPeter Hancock <phancock@apache.org>2011-09-26 09:48:20 +0000
commita4b5668e88d868351a17dd62f75a4bf63a0172ad (patch)
tree4194ff307884b67e8e25f466691a6ff195a034aa /src/java
parent2f433908c6d8c49d22afb353a1ee025f7894e256 (diff)
downloadxmlgraphics-fop-a4b5668e88d868351a17dd62f75a4bf63a0172ad.tar.gz
xmlgraphics-fop-a4b5668e88d868351a17dd62f75a4bf63a0172ad.zip
PDFFactory responsible for asdigning name to a subset font.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1175754 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/fonts/FontDescriptor.java5
-rw-r--r--src/java/org/apache/fop/fonts/LazyFont.java12
-rw-r--r--src/java/org/apache/fop/fonts/MultiByteFont.java40
-rw-r--r--src/java/org/apache/fop/fonts/SingleByteFont.java6
-rw-r--r--src/java/org/apache/fop/pdf/PDFFactory.java37
5 files changed, 58 insertions, 42 deletions
diff --git a/src/java/org/apache/fop/fonts/FontDescriptor.java b/src/java/org/apache/fop/fonts/FontDescriptor.java
index e7c81c9f3..8aea105be 100644
--- a/src/java/org/apache/fop/fonts/FontDescriptor.java
+++ b/src/java/org/apache/fop/fonts/FontDescriptor.java
@@ -86,5 +86,10 @@ public interface FontDescriptor extends FontMetrics {
*/
boolean isEmbeddable();
+ /**
+ * Indicates whether this font is subset embedded.
+ * @return true if this font is subset embedded
+ */
+ boolean isSubsetEmbedded();
}
diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java
index a8fd447c4..f331a331e 100644
--- a/src/java/org/apache/fop/fonts/LazyFont.java
+++ b/src/java/org/apache/fop/fonts/LazyFont.java
@@ -27,12 +27,10 @@ import java.util.Set;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import org.xml.sax.InputSource;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.apps.FOPException;
+import org.xml.sax.InputSource;
/**
* This class is used to defer the loading of a font until it is really used.
@@ -375,5 +373,13 @@ public class LazyFont extends Typeface implements FontDescriptor {
return realFontDescriptor.isEmbeddable();
}
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSubsetEmbedded() {
+ load(true);
+ return realFont.isMultiByte();
+ }
+
}
diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java
index 629bfa1b7..397ca8a84 100644
--- a/src/java/org/apache/fop/fonts/MultiByteFont.java
+++ b/src/java/org/apache/fop/fonts/MultiByteFont.java
@@ -20,7 +20,6 @@
package org.apache.fop.fonts;
//Java
-import java.text.DecimalFormat;
import java.util.Map;
@@ -29,16 +28,12 @@ import java.util.Map;
*/
public class MultiByteFont extends CIDFont {
- private static int uniqueCounter = -1;
-
private String ttcName = null;
private String encoding = "Identity-H";
private int defaultWidth = 0;
private CIDFontType cidType = CIDFontType.CIDTYPE2;
- private String namePrefix = null; // Quasi unique prefix
-
private CIDSubset subset = new CIDSubset();
/** A map from Unicode indices to glyph indices */
@@ -49,31 +44,11 @@ public class MultiByteFont extends CIDFont {
*/
public MultiByteFont() {
subset.setupFirstGlyph();
-
- // Create a quasiunique prefix for fontname
- synchronized (this.getClass()) {
- uniqueCounter++;
- if (uniqueCounter > 99999 || uniqueCounter < 0) {
- uniqueCounter = 0; //We need maximum 5 character then we start again
- }
- }
- DecimalFormat counterFormat = new DecimalFormat("00000");
- String cntString = counterFormat.format(uniqueCounter);
-
- //Subset prefix as described in chapter 5.5.3 of PDF 1.4
- StringBuffer sb = new StringBuffer("E");
- for (int i = 0, c = cntString.length(); i < c; i++) {
- //translate numbers to uppercase characters
- sb.append((char)(cntString.charAt(i) + (65 - 48)));
- }
- sb.append("+");
- namePrefix = sb.toString();
-
setFontType(FontType.TYPE0);
}
- /** {@inheritDoc} */
- public int getDefaultWidth() {
+ /** {@inheritdoc} */
+ public int getdefaultwidth() {
return defaultWidth;
}
@@ -105,14 +80,10 @@ public class MultiByteFont extends CIDFont {
this.cidType = cidType;
}
- private String getPrefixedFontName() {
- return namePrefix + FontUtil.stripWhiteSpace(super.getFontName());
- }
-
/** {@inheritDoc} */
public String getEmbedFontName() {
if (isEmbeddable()) {
- return getPrefixedFontName();
+ return FontUtil.stripWhiteSpace(super.getFontName());
} else {
return super.getFontName();
}
@@ -124,6 +95,11 @@ public class MultiByteFont extends CIDFont {
}
/** {@inheritDoc} */
+ public boolean isSubsetEmbedded() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
public CIDSubset getCIDSubset() {
return this.subset;
}
diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java
index 0605cd11e..d5901297f 100644
--- a/src/java/org/apache/fop/fonts/SingleByteFont.java
+++ b/src/java/org/apache/fop/fonts/SingleByteFont.java
@@ -63,7 +63,11 @@ public class SingleByteFont extends CustomFont {
}
/** {@inheritDoc} */
- @Override
+ public boolean isSubsetEmbedded() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
public String getEncodingName() {
return this.mapping.getName();
}
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java
index 23542a49e..64941be94 100644
--- a/src/java/org/apache/fop/pdf/PDFFactory.java
+++ b/src/java/org/apache/fop/pdf/PDFFactory.java
@@ -27,6 +27,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
@@ -63,6 +64,7 @@ import org.apache.fop.fonts.truetype.FontFileReader;
import org.apache.fop.fonts.truetype.TTFSubSetFile;
import org.apache.fop.fonts.type1.PFBData;
import org.apache.fop.fonts.type1.PFBParser;
+import org.apache.xmlgraphics.xmp.Metadata;
/**
* This class provides method to create and register PDF objects.
@@ -76,6 +78,8 @@ public class PDFFactory {
private Log log = LogFactory.getLog(PDFFactory.class);
+ private int subsetFontCounter = -1;
+
/**
* Creates a new PDFFactory.
* @param document the parent PDFDocument needed to register the generated
@@ -1377,10 +1381,15 @@ public class PDFFactory {
} else {
FontType fonttype = metrics.getFontType();
- PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor);
+ String fontPrefix = descriptor.isSubsetEmbedded() ? createSubsetFontPrefix() : "";
+
+ String subsetFontName = fontPrefix + basefont;
+
+ PDFFontDescriptor pdfdesc = makeFontDescriptor(descriptor, fontPrefix);
PDFFont font = null;
- font = PDFFont.createFont(fontname, fonttype, basefont, null);
+
+ font = PDFFont.createFont(fontname, fonttype, subsetFontName, null);
getDocument().registerObject(font);
if (fonttype == FontType.TYPE0) {
@@ -1395,8 +1404,7 @@ public class PDFFactory {
= new PDFCIDSystemInfo(cidMetrics.getRegistry(),
cidMetrics.getOrdering(),
cidMetrics.getSupplement());
- PDFCIDFont cidFont
- = new PDFCIDFont(basefont,
+ PDFCIDFont cidFont = new PDFCIDFont(subsetFontName,
cidMetrics.getCIDType(),
cidMetrics.getDefaultWidth(),
getSubsetWidths(cidMetrics), sysInfo,
@@ -1550,18 +1558,35 @@ public class PDFFactory {
return warray;
}
+ private String createSubsetFontPrefix() {
+ subsetFontCounter++;
+ DecimalFormat counterFormat = new DecimalFormat("00000");
+ String counterString = counterFormat.format(subsetFontCounter);
+
+ // Subset prefix as described in chapter 5.5.3 of PDF 1.4
+ StringBuffer sb = new StringBuffer("E");
+
+ for (char c : counterString.toCharArray()) {
+ // translate numbers to uppercase characters
+ sb.append((char) (c + ('A' - '0')));
+ }
+ sb.append("+");
+ return sb.toString();
+ }
+
/**
* make a /FontDescriptor object
*
* @param desc the font descriptor
+ * @param fontPrefix the String with which to prefix the font name
* @return the new PDF font descriptor
*/
- public PDFFontDescriptor makeFontDescriptor(FontDescriptor desc) {
+ private PDFFontDescriptor makeFontDescriptor(FontDescriptor desc, String fontPrefix) {
PDFFontDescriptor descriptor = null;
if (desc.getFontType() == FontType.TYPE0) {
// CID Font
- descriptor = new PDFCIDFontDescriptor(desc.getEmbedFontName(),
+ descriptor = new PDFCIDFontDescriptor(fontPrefix + desc.getEmbedFontName(),
desc.getFontBBox(),
desc.getCapHeight(),
desc.getFlags(),