aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2007-11-03 10:51:31 +0000
committerJeremias Maerki <jeremias@apache.org>2007-11-03 10:51:31 +0000
commit281ac8bcab030f3cb9646f4eb3895f320a1abb6b (patch)
tree691fef15e6dd437269f05c030adde096d2f72a22 /src/java/org/apache
parentb58bd2b16672a0a39ac5d3d4d24291569fad6697 (diff)
downloadxmlgraphics-fop-281ac8bcab030f3cb9646f4eb3895f320a1abb6b.tar.gz
xmlgraphics-fop-281ac8bcab030f3cb9646f4eb3895f320a1abb6b.zip
More fine-grained mechanism to detect if a font has been used or not. If a font list is given for a text run and each character should be painted in the right font, it might be accessed but never really used. Needed for PDF text painting improvements.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@591583 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/fonts/LazyFont.java10
-rw-r--r--src/java/org/apache/fop/fonts/MultiByteFont.java1
-rw-r--r--src/java/org/apache/fop/fonts/SingleByteFont.java4
-rw-r--r--src/java/org/apache/fop/fonts/Typeface.java19
-rw-r--r--src/java/org/apache/fop/pdf/PDFResources.java36
5 files changed, 51 insertions, 19 deletions
diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java
index c629f14fe..cc8989b7d 100644
--- a/src/java/org/apache/fop/fonts/LazyFont.java
+++ b/src/java/org/apache/fop/fonts/LazyFont.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
+
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
@@ -166,6 +167,14 @@ public class LazyFont extends Typeface implements FontDescriptor {
/**
* {@inheritDoc}
*/
+ public boolean hadMappingOperations() {
+ load(true);
+ return realFont.hadMappingOperations();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public boolean hasChar(char c) {
load(true);
return realFont.hasChar(c);
@@ -332,5 +341,6 @@ public class LazyFont extends Typeface implements FontDescriptor {
load(true);
return realFontDescriptor.isEmbeddable();
}
+
}
diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java
index e00300324..dcd3bdfa0 100644
--- a/src/java/org/apache/fop/fonts/MultiByteFont.java
+++ b/src/java/org/apache/fop/fonts/MultiByteFont.java
@@ -214,6 +214,7 @@ public class MultiByteFont extends CIDFont {
* {@inheritDoc}
*/
public char mapChar(char c) {
+ notifyMapOperation();
int retIdx = findGlyphIndex(c);
if (isEmbeddable()) {
diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java
index 402a630e8..1baee3f98 100644
--- a/src/java/org/apache/fop/fonts/SingleByteFont.java
+++ b/src/java/org/apache/fop/fonts/SingleByteFont.java
@@ -98,6 +98,7 @@ public class SingleByteFont extends CustomFont {
* {@inheritDoc}
*/
public char mapChar(char c) {
+ notifyMapOperation();
char d = mapping.mapChar(c);
if (d != 0) {
return d;
@@ -129,8 +130,5 @@ public class SingleByteFont extends CustomFont {
this.width[index] = width;
}
- public char[] getCharsUsed() {
- return null;
- }
}
diff --git a/src/java/org/apache/fop/fonts/Typeface.java b/src/java/org/apache/fop/fonts/Typeface.java
index c165b4068..ebfc02c39 100644
--- a/src/java/org/apache/fop/fonts/Typeface.java
+++ b/src/java/org/apache/fop/fonts/Typeface.java
@@ -27,6 +27,8 @@ package org.apache.fop.fonts;
*/
public abstract class Typeface implements FontMetrics {
+ private long charMapOps = 0;
+
/**
* Get the encoding of the font.
* @return the encoding
@@ -41,6 +43,23 @@ public abstract class Typeface implements FontMetrics {
public abstract char mapChar(char c);
/**
+ * Used for keeping track of character mapping operations in order to determine if a font
+ * was used at all or not.
+ */
+ protected void notifyMapOperation() {
+ this.charMapOps++;
+ }
+
+ /**
+ * Indicates whether this font had to do any character mapping operations. If that was
+ * not the case, it's an indication that the font has never actually been used.
+ * @return true if the font had to do any character mapping operations
+ */
+ public boolean hadMappingOperations() {
+ return (this.charMapOps > 0);
+ }
+
+ /**
* Determines whether this font contains a particular character/glyph.
* @param c character to check
* @return True if the character is supported, Falso otherwise
diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java
index 310f8d8d0..d9420946a 100644
--- a/src/java/org/apache/fop/pdf/PDFResources.java
+++ b/src/java/org/apache/fop/pdf/PDFResources.java
@@ -19,17 +19,16 @@
package org.apache.fop.pdf;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
-import org.apache.fop.util.ColorProfileUtil;
-
-// Java
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
+
+import org.apache.fop.fonts.FontDescriptor;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.util.ColorProfileUtil;
/**
* class representing a /Resources object.
@@ -97,17 +96,22 @@ public class PDFResources extends PDFObject {
* @param fontInfo font info object to get font information from
*/
public void addFonts(PDFDocument doc, FontInfo fontInfo) {
- Map fonts = fontInfo.getUsedFonts();
- Iterator e = fonts.keySet().iterator();
+ Map usedFonts = fontInfo.getUsedFonts();
+ Iterator e = usedFonts.keySet().iterator();
while (e.hasNext()) {
String f = (String)e.next();
- Typeface font = (Typeface)fonts.get(f);
- FontDescriptor desc = null;
- if (font instanceof FontDescriptor) {
- desc = (FontDescriptor)font;
+ Typeface font = (Typeface)usedFonts.get(f);
+
+ //Check if the font actually had any mapping operations. If not, it is an indication
+ //that it has never actually been used and therefore doesn't have to be embedded.
+ if (font.hadMappingOperations()) {
+ FontDescriptor desc = null;
+ if (font instanceof FontDescriptor) {
+ desc = (FontDescriptor)font;
+ }
+ addFont(doc.getFactory().makeFont(
+ f, font.getFontName(), font.getEncoding(), font, desc));
}
- addFont(doc.getFactory().makeFont(
- f, font.getFontName(), font.getEncoding(), font, desc));
}
}