aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2001-08-06 09:43:08 +0000
committerKeiron Liddle <keiron@apache.org>2001-08-06 09:43:08 +0000
commit8a3bc2543bd1c31e78da3b8fa919e53e4f3dd1ee (patch)
treebb6c5f9c31d93d4426dc4cf5f3365af30eea2657
parent87c21b95e4a613a802ba9f2b8ad876b0e029c459 (diff)
downloadxmlgraphics-fop-8a3bc2543bd1c31e78da3b8fa919e53e4f3dd1ee.tar.gz
xmlgraphics-fop-8a3bc2543bd1c31e78da3b8fa919e53e4f3dd1ee.zip
adds support for lazy loading of fonts
saves some cpu, memory Submitted by: SASAKI Suguru <s-sasaki@hkg.odn.ne.jp> Reviewed by: Keiron git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194397 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/org/apache/fop/pdf/PDFDocument.java8
-rw-r--r--src/org/apache/fop/render/pdf/FontSetup.java8
-rw-r--r--src/org/apache/fop/render/pdf/PDFRenderer.java8
-rw-r--r--src/org/apache/fop/render/pdf/fonts/LazyFont.java176
4 files changed, 197 insertions, 3 deletions
diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java
index f2701d530..a545ab40f 100644
--- a/src/org/apache/fop/pdf/PDFDocument.java
+++ b/src/org/apache/fop/pdf/PDFDocument.java
@@ -18,6 +18,7 @@ import org.apache.fop.layout.LinkSet;
import org.apache.fop.datatypes.ColorSpace;
import org.apache.fop.render.pdf.CIDFont;
+import org.apache.fop.render.pdf.fonts.LazyFont;
import org.apache.fop.datatypes.IDReferences;
import org.apache.fop.layout.Page;
@@ -813,7 +814,12 @@ public class PDFDocument {
font.setDescriptor(pdfdesc);
if (subtype == PDFFont.TYPE0) {
- CIDFont cidMetrics = (CIDFont)metrics;
+ CIDFont cidMetrics;
+ if(metrics instanceof LazyFont){
+ cidMetrics = (CIDFont) ((LazyFont) metrics).getRealFont();
+ }else{
+ cidMetrics = (CIDFont)metrics;
+ }
PDFCIDSystemInfo sysInfo =
new PDFCIDSystemInfo(cidMetrics.getRegistry(),
cidMetrics.getOrdering(),
diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java
index 81b6b0d58..00a415230 100644
--- a/src/org/apache/fop/render/pdf/FontSetup.java
+++ b/src/org/apache/fop/render/pdf/FontSetup.java
@@ -156,11 +156,17 @@ public class FontSetup {
if (metricsFile != null) {
internalName = "F" + num;
num++;
+ /*
reader = new FontReader(metricsFile);
reader.useKerning(configFontInfo.getKerning());
reader.setFontEmbedPath(configFontInfo.getEmbedFile());
fontInfo.addMetrics(internalName, reader.getFont());
-
+ */
+ LazyFont font = new LazyFont(configFontInfo.getEmbedFile(),
+ metricsFile,
+ configFontInfo.getKerning());
+ fontInfo.addMetrics(internalName, font);
+
Vector triplets = configFontInfo.getFontTriplets();
for (Enumeration t = triplets.elements();
t.hasMoreElements(); ) {
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java
index db77183b0..dca1fedb2 100644
--- a/src/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/org/apache/fop/render/pdf/PDFRenderer.java
@@ -22,6 +22,7 @@ import org.apache.fop.layout.*;
import org.apache.fop.image.*;
import org.apache.fop.extensions.*;
import org.apache.fop.datatypes.IDReferences;
+import org.apache.fop.render.pdf.fonts.LazyFont;
import org.apache.batik.bridge.*;
import org.apache.batik.swing.svg.*;
@@ -487,8 +488,13 @@ public class PDFRenderer extends PrintRenderer {
boolean useMultiByte = false;
Font f =
(Font)area.getFontState().getFontInfo().getFonts().get(name);
- if (f instanceof CIDFont)
+ if (f instanceof LazyFont){
+ if(((LazyFont) f).getRealFont() instanceof CIDFont){
+ useMultiByte = true;
+ }
+ }else if (f instanceof CIDFont){
useMultiByte = true;
+ }
// String startText = useMultiByte ? "<FEFF" : "(";
String startText = useMultiByte ? "<" : "(";
String endText = useMultiByte ? "> " : ") ";
diff --git a/src/org/apache/fop/render/pdf/fonts/LazyFont.java b/src/org/apache/fop/render/pdf/fonts/LazyFont.java
new file mode 100644
index 000000000..80faae2de
--- /dev/null
+++ b/src/org/apache/fop/render/pdf/fonts/LazyFont.java
@@ -0,0 +1,176 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.render.pdf.fonts;
+
+import org.apache.fop.render.pdf.Font;
+import org.apache.fop.layout.FontDescriptor;
+import org.apache.fop.pdf.PDFStream;
+import org.apache.fop.messaging.MessageHandler;
+import java.util.Hashtable;
+
+import org.apache.fop.render.pdf.FontReader;
+
+public class LazyFont extends Font implements FontDescriptor {
+
+ private String metricsFileName = null;
+ private String fontEmbedPath = null;
+ private boolean useKerning = false;
+
+ private boolean isMetricsLoaded = false;
+ private Font realFont = null;
+ private FontDescriptor realFontDescriptor = null;
+
+ public LazyFont(String fontEmbedPath, String metricsFileName, boolean useKerning){
+ this.metricsFileName = metricsFileName;
+ this.fontEmbedPath = fontEmbedPath;
+ this.useKerning = useKerning;
+ }
+
+ private void load(){
+ if(! isMetricsLoaded){
+ try{
+ FontReader reader = new FontReader(metricsFileName);
+ reader.useKerning(useKerning);
+ reader.setFontEmbedPath(fontEmbedPath);
+ realFont = reader.getFont();
+ if(realFont instanceof FontDescriptor){
+ realFontDescriptor = (FontDescriptor) realFont;
+ }
+ isMetricsLoaded = true;
+ // System.out.println("Metrics " + metricsFileName + " loaded.");
+ } catch (Exception ex) {
+ MessageHandler.error("Failed to read font metrics file "
+ + metricsFileName
+ + " : " + ex.getMessage());
+ }
+ }
+ }
+
+ public Font getRealFont(){
+ return realFont;
+ }
+
+ // Font
+ public String encoding(){
+ load();
+ return realFont.encoding();
+ }
+
+ public String fontName(){
+ load();
+ return realFont.fontName();
+ }
+
+ public byte getSubType(){
+ load();
+ return realFont.getSubType();
+ }
+
+ public char mapChar(char c){
+ load();
+ return realFont.mapChar(c);
+ }
+
+ // FontMetrics
+ public int getAscender(int size){
+ load();
+ return realFont.getAscender(size);
+ }
+
+ public int getCapHeight(int size){
+ load();
+ return realFont.getCapHeight(size);
+ }
+
+ public int getDescender(int size){
+ load();
+ return realFont.getDescender(size);
+ }
+
+ public int getXHeight(int size){
+ load();
+ return realFont.getXHeight(size);
+ }
+
+ public int getFirstChar(){
+ load();
+ return realFont.getFirstChar();
+ }
+
+ public int getLastChar(){
+ load();
+ return realFont.getLastChar();
+ }
+
+ public int width(int i, int size){
+ load();
+ return realFont.width(i, size);
+ }
+
+ public int[] getWidths(int size){
+ load();
+ return realFont.getWidths(size);
+ }
+
+ // FontDescriptor
+ public int getCapHeight(){
+ load();
+ return realFontDescriptor.getCapHeight();
+ }
+
+ public int getDescender(){
+ load();
+ return realFontDescriptor.getDescender();
+ }
+
+ public int getAscender(){
+ load();
+ return realFontDescriptor.getAscender();
+ }
+
+ public int getFlags(){
+ load();
+ return realFontDescriptor.getFlags();
+ }
+
+ public int[] getFontBBox(){
+ load();
+ return realFontDescriptor.getFontBBox();
+ }
+
+ public int getItalicAngle(){
+ load();
+ return realFontDescriptor.getItalicAngle();
+ }
+
+ public int getStemV(){
+ load();
+ return realFontDescriptor.getStemV();
+ }
+
+ public boolean hasKerningInfo(){
+ load();
+ return realFontDescriptor.hasKerningInfo();
+ }
+
+ public Hashtable getKerningInfo(){
+ load();
+ return realFontDescriptor.getKerningInfo();
+ }
+
+ public boolean isEmbeddable(){
+ load();
+ return realFontDescriptor.isEmbeddable();
+ }
+
+ public PDFStream getFontFile(int objNum){
+ load();
+ return realFontDescriptor.getFontFile(objNum);
+ }
+}
+