Author: vhennebert
Date: Fri Mar 30 19:09:29 2012
New Revision: 1307574
URL: http://svn.apache.org/viewvc?rev=1307574&view=rev
Log:
Bugzilla #50483: Improved support for TrueType fonts in PostScript
Refactored code and added unit tests
Patch by Mehdi Houshmand
Added:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFGlyphOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFTableName.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFTableOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/fonts/
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/fonts/PSTTFGenerator.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/fonts/PSTTFOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStream.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/FOPFontsTestSuite.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/truetype/
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/truetype/FontFileReaderTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/truetype/TTFFileTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/truetype/TTFSubSetFileTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/truetype/TTFTableNameTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/RenderPSTestSuite.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/fonts/
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/fonts/PSTTFGeneratorTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/fonts/PSTTFGlyphOutputStreamTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/fonts/PSTTFOutputStreamTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/render/ps/fonts/PSTTFTableOutputStreamTest.java
(with props)
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/resources/fonts/DroidSansMono.LICENSE
Removed:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/build.xml
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/BFEntry.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFont.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFontCollection.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbedFontInfo.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EncodingMode.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontLoader.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/LazyFont.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/MutableFont.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/apps/TTFReader.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFFile.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/pdf/PDFFactory.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/PSFontUtils.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/render/ps/PSPainter.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/DejaVuLGCSerifTest.java
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/test/java/org/apache/fop/fonts/EncodingModeTest.java
Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/build.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/build.xml?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/build.xml (original)
+++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/build.xml Fri Mar 30
19:09:29 2012
@@ -90,7 +90,10 @@ list of possible build targets.
<include name="lib/build/jaxen*"/>
<include name="lib/build/pmd*"/>
<include name="lib/build/qdox*"/>
- <include name="lib/build/xmlunit*"/>
+ <include name="lib/build/xmlunit*"/>
+ <include name="lib/build/mockito*"/>
+ <include name="lib/build/hamcrest*"/>
+ <include name="lib/build/objenesis*"/>
</patternset>
<fileset dir="${basedir}" id="dist.src">
<include name="src/**"/>
@@ -944,7 +947,15 @@ list of possible build targets.
<test name="org.apache.fop.text.linebreak.LineBreakStatusTest"
todir="${junit.reports.dir}"/>
</junit>
</target>
- <target name="junit-reduced" depends="junit-userconfig, junit-basic,
junit-transcoder, junit-text-linebreak, junit-fotree"/>
+ <target name="junit-fonts" depends="junit-compile">
+ <echo message="Running tests for the fonts package"/>
+ <junit-run title="fonts"
testsuite="org.apache.fop.fonts.FOPFontsTestSuite" outfile="TEST-fonts"/>
+ </target>
+ <target name="junit-render-ps" depends="junit-compile">
+ <echo message="Running tests for the render ps package"/>
+ <junit-run title="render-ps"
testsuite="org.apache.fop.render.ps.RenderPSTestSuite"
outfile="TEST-render-ps"/>
+ </target>
+ <target name="junit-reduced" depends="junit-userconfig, junit-basic,
junit-transcoder, junit-text-linebreak, junit-fotree, junit-fonts,
junit-render-ps"/>
<target name="junit-full" depends="junit-reduced, junit-layout,
junit-area-tree-xml-format, junit-intermediate-format"/>
<target name="junit" depends="junit-full" description="Runs all of FOP's
JUnit tests" if="junit.present">
<fail><condition><or><isset property="fop.junit.error"/><isset
property="fop.junit.failure"/><not><isset
property="hyphenation.present"/></not></or></condition>
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java
Fri Mar 30 19:09:29 2012
@@ -37,18 +37,16 @@ import javax.xml.transform.sax.SAXTransf
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import org.w3c.dom.Node;
-
import org.apache.commons.io.IOUtils;
+import org.apache.fop.events.model.EventModel;
+import org.apache.fop.events.model.EventProducerModel;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.selectors.FilenameSelector;
-
-import org.apache.fop.events.model.EventModel;
-import org.apache.fop.events.model.EventProducerModel;
+import org.w3c.dom.Node;
/**
* Ant task which inspects a file set for Java interfaces which extend the
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/BFEntry.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/BFEntry.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/BFEntry.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/BFEntry.java
Fri Mar 30 19:09:29 2012
@@ -22,14 +22,13 @@ package org.apache.fop.fonts;
/**
* This is just a holder class for bfentries, groups of characters of a base
font (bf).
*/
-public class BFEntry {
+public final class BFEntry {
//TODO Think about renaming this class to CMapRange or something.
- //TODO Copy equals() and hashCode() from TTFCmapEntry
- private int unicodeStart;
- private int unicodeEnd;
- private int glyphStartIndex;
+ private final int unicodeStart;
+ private final int unicodeEnd;
+ private final int glyphStartIndex;
/**
* Main constructor.
@@ -44,6 +43,32 @@ public class BFEntry {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int hc = 17;
+ hc = 31 * hc + unicodeStart;
+ hc = 31 * hc + unicodeEnd;
+ hc = 31 * hc + glyphStartIndex;
+ return hc;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof BFEntry) {
+ BFEntry ce = (BFEntry) o;
+ return ce.unicodeStart == this.unicodeStart
+ && ce.unicodeEnd == this.unicodeEnd
+ && ce.glyphStartIndex == this.glyphStartIndex;
+ }
+ return false;
+ }
+
+ /**
* Returns the unicodeStart.
* @return the Unicode start index
*/
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFont.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFont.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFont.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFont.java
Fri Mar 30 19:09:29 2012
@@ -42,6 +42,7 @@ public abstract class CustomFont extends
private String embedFileName = null;
private String embedResourceName = null;
private FontResolver resolver = null;
+ private EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
private int capHeight = 0;
private int xHeight = 0;
@@ -114,6 +115,14 @@ public abstract class CustomFont extends
}
/**
+ * Returns the embedding mode for this font.
+ * @return embedding mode
+ */
+ public EmbeddingMode getEmbeddingMode() {
+ return embeddingMode;
+ }
+
+ /**
* Returns a Source representing an embeddable font file.
* @return Source for an embeddable font file
* @throws IOException if embedFileName is not null but Source is not found
@@ -262,7 +271,7 @@ public abstract class CustomFont extends
return lastChar;
}
- /**
+ /**MutableFont
* Used to determine if kerning is enabled.
* @return True if kerning is enabled.
*/
@@ -330,6 +339,13 @@ public abstract class CustomFont extends
/**
* {@inheritDoc}
*/
+ public void setEmbeddingMode(EmbeddingMode embeddingMode) {
+ this.embeddingMode = embeddingMode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void setCapHeight(int capHeight) {
this.capHeight = capHeight;
}
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFontCollection.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFontCollection.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFontCollection.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/CustomFontCollection.java
Fri Mar 30 19:09:29 2012
@@ -71,7 +71,7 @@ public class CustomFontCollection implem
List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
for (int tripletIndex = 0; tripletIndex < triplets.size();
tripletIndex++) {
- FontTriplet triplet = (FontTriplet) triplets.get(tripletIndex);
+ FontTriplet triplet = triplets.get(tripletIndex);
fontInfo.addFontProperties(internalName, triplet);
}
}
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbedFontInfo.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbedFontInfo.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbedFontInfo.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbedFontInfo.java
Fri Mar 30 19:09:29 2012
@@ -25,6 +25,8 @@ import java.util.List;
/**
* FontInfo contains meta information on fonts (where is the metrics file etc.)
+ * TODO: We need to remove this class and think about more intelligent design
patterns
+ * (Data classes => Procedural code)
*/
public class EmbedFontInfo implements Serializable {
@@ -39,6 +41,8 @@ public class EmbedFontInfo implements Se
protected boolean kerning;
/** the requested encoding mode for the font */
protected EncodingMode encodingMode = EncodingMode.AUTO;
+ /** the requested embedding mode for this font */
+ protected EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
/** the PostScript name of the font */
protected String postScriptName = null;
@@ -137,6 +141,14 @@ public class EmbedFontInfo implements Se
}
/**
+ * Returns the embedding mode for this font.
+ * @return the embedding mode.
+ */
+ public EmbeddingMode getEmbeddingMode() {
+ return embeddingMode;
+ }
+
+ /**
* Defines whether the font is embedded or not.
* @param value true to embed the font, false to reference it
*/
@@ -163,6 +175,17 @@ public class EmbedFontInfo implements Se
this.encodingMode = mode;
}
+ /**
+ * Sets the embedding mode for this font, currently not supported for
type1 fonts.
+ * @param embeddingMode the new embedding mode.
+ */
+ public void setEmbeddingMode(EmbeddingMode embeddingMode) {
+ if (embeddingMode == null) {
+ throw new NullPointerException("embeddingMode must not be null");
+ }
+ this.embeddingMode = embeddingMode;
+ }
+
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
Added:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java?rev=1307574&view=auto
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
(added)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
Fri Mar 30 19:09:29 2012
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+/**
+ * This enumerates the embedding mode of fonts; full; subset; auto (auto
defaults to full for
+ * type1 fonts and subset for truetype fonts.
+ */
+public enum EmbeddingMode {
+ /** Default option: assumes FULL for type1 fonts and SUBSET for truetype
fonts. */
+ AUTO,
+ /** Full font embedding: This means the whole of the font is written to
file. */
+ FULL,
+ /** Subset font embedding: Only the mandatory tables and a subset of
glyphs are written
+ * to file.*/
+ SUBSET;
+
+ /**
+ * Returns the name of this embedding mode.
+ * @return String - lower case.
+ */
+ public String getName() {
+ return this.toString().toLowerCase();
+ }
+
+ /**
+ * Returns {@link EmbeddingMode} by name.
+ * @param value String - the name of the embedding mode (not case
sensitive).
+ * @return embedding mode constant.
+ */
+ public static EmbeddingMode getValue(String value) {
+ for (EmbeddingMode mode : EmbeddingMode.values()) {
+ if (mode.toString().equalsIgnoreCase(value)) {
+ return mode;
+ }
+ }
+ throw new IllegalArgumentException("Invalid embedding-mode: " + value);
+ }
+}
Propchange:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EmbeddingMode.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EncodingMode.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EncodingMode.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EncodingMode.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/EncodingMode.java
Fri Mar 30 19:09:29 2012
@@ -52,7 +52,7 @@ public enum EncodingMode {
* @param name the name of the encoding mode to look up
* @return the encoding mode constant
*/
- public static EncodingMode getEncodingMode(String name) {
+ public static EncodingMode getValue(String name) {
for (EncodingMode em : EncodingMode.values()) {
if (name.equalsIgnoreCase(em.getName())) {
return em;
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontInfoConfigurator.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
Fri Mar 30 19:09:29 2012
@@ -251,11 +251,15 @@ public class FontInfoConfigurator {
}
boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", true);
- EncodingMode encodingMode = EncodingMode.getEncodingMode(
+ EncodingMode encodingMode = EncodingMode.getValue(
fontCfg.getAttribute("encoding-mode",
EncodingMode.AUTO.getName()));
+ EmbeddingMode embeddingMode = EmbeddingMode.getValue(
+ fontCfg.getAttribute("embedding-mode",
EmbeddingMode.AUTO.toString()));
EmbedFontInfo embedFontInfo
= new EmbedFontInfo(metricsUrl, useKerning, tripletList,
embedUrl, subFont);
embedFontInfo.setEncodingMode(encodingMode);
+ embedFontInfo.setEmbeddingMode(embeddingMode);
+
if (fontCache != null) {
if (!fontCache.containsFont(embedFontInfo)) {
fontCache.addFont(embedFontInfo);
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontLoader.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontLoader.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontLoader.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/FontLoader.java
Fri Mar 30 19:09:29 2012
@@ -30,7 +30,6 @@ import javax.xml.transform.stream.Stream
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.fonts.truetype.TTFFontLoader;
import org.apache.fop.fonts.type1.Type1FontLoader;
@@ -80,15 +79,17 @@ public abstract class FontLoader {
* @param fontFile the File representation of the font
* @param subFontName the sub-fontname of a font (for TrueType
Collections, null otherwise)
* @param embedded indicates whether the font is embedded or referenced
+ * @param embeddingMode the embedding mode
* @param encodingMode the requested encoding mode
* @param resolver the font resolver to use when resolving URIs
* @return the newly loaded font
* @throws IOException In case of an I/O error
*/
public static CustomFont loadFont(File fontFile, String subFontName,
- boolean embedded, EncodingMode encodingMode, FontResolver
resolver) throws IOException {
+ boolean embedded, EmbeddingMode embeddingMode, EncodingMode
encodingMode,
+ FontResolver resolver) throws IOException {
return loadFont(fontFile.toURI().toURL(), subFontName,
- embedded, encodingMode, resolver);
+ embedded, embeddingMode, encodingMode, resolver);
}
/**
@@ -96,16 +97,17 @@ public abstract class FontLoader {
* @param fontUrl the URL representation of the font
* @param subFontName the sub-fontname of a font (for TrueType
Collections, null otherwise)
* @param embedded indicates whether the font is embedded or referenced
+ * @param embeddingMode the embedding mode of the font
* @param encodingMode the requested encoding mode
* @param resolver the font resolver to use when resolving URIs
* @return the newly loaded font
* @throws IOException In case of an I/O error
*/
public static CustomFont loadFont(URL fontUrl, String subFontName,
- boolean embedded, EncodingMode encodingMode,
+ boolean embedded, EmbeddingMode embeddingMode, EncodingMode
encodingMode,
FontResolver resolver) throws IOException {
return loadFont(fontUrl.toExternalForm(), subFontName,
- embedded, encodingMode, true,
+ embedded, embeddingMode, encodingMode, true,
resolver);
}
@@ -114,6 +116,7 @@ public abstract class FontLoader {
* @param fontFileURI the URI to the font
* @param subFontName the sub-fontname of a font (for TrueType
Collections, null otherwise)
* @param embedded indicates whether the font is embedded or referenced
+ * @param embeddingMode the embedding mode of the font
* @param encodingMode the requested encoding mode
* @param useKerning indicates whether kerning information should be
loaded if available
* @param resolver the font resolver to use when resolving URIs
@@ -121,8 +124,8 @@ public abstract class FontLoader {
* @throws IOException In case of an I/O error
*/
public static CustomFont loadFont(String fontFileURI, String subFontName,
- boolean embedded, EncodingMode encodingMode, boolean useKerning,
- FontResolver resolver) throws IOException {
+ boolean embedded, EmbeddingMode embeddingMode, EncodingMode
encodingMode,
+ boolean useKerning, FontResolver resolver) throws IOException {
fontFileURI = fontFileURI.trim();
boolean type1 = isType1(fontFileURI);
FontLoader loader;
@@ -131,10 +134,14 @@ public abstract class FontLoader {
throw new IllegalArgumentException(
"CID encoding mode not supported for Type 1 fonts");
}
+ if (embeddingMode == EmbeddingMode.SUBSET) {
+ throw new IllegalArgumentException(
+ "Subset embedding for Type 1 fonts is not supported");
+ }
loader = new Type1FontLoader(fontFileURI, embedded, useKerning,
resolver);
} else {
loader = new TTFFontLoader(fontFileURI, subFontName,
- embedded, encodingMode, useKerning, resolver);
+ embedded, embeddingMode, encodingMode, useKerning,
resolver);
}
return loader.getFont();
}
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/LazyFont.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/LazyFont.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/LazyFont.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/LazyFont.java
Fri Mar 30 19:09:29 2012
@@ -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.
@@ -45,6 +43,7 @@ public class LazyFont extends Typeface i
private String fontEmbedPath = null;
private boolean useKerning = false;
private EncodingMode encodingMode = EncodingMode.AUTO;
+ private EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
private boolean embedded = true;
private String subFontName = null;
@@ -65,6 +64,7 @@ public class LazyFont extends Typeface i
this.fontEmbedPath = fontInfo.getEmbedFile();
this.useKerning = fontInfo.getKerning();
this.encodingMode = fontInfo.getEncodingMode();
+ this.embeddingMode = fontInfo.getEmbeddingMode();
this.subFontName = fontInfo.getSubFontName();
this.embedded = fontInfo.isEmbedded();
this.resolver = resolver;
@@ -131,8 +131,9 @@ public class LazyFont extends Typeface i
if (fontEmbedPath == null) {
throw new RuntimeException("Cannot load font. No font
URIs available.");
}
- realFont = FontLoader.loadFont(fontEmbedPath,
this.subFontName,
- this.embedded, this.encodingMode, useKerning,
resolver);
+ realFont = FontLoader.loadFont(fontEmbedPath, subFontName,
+ embedded, embeddingMode, encodingMode,
+ useKerning, resolver);
}
if (realFont instanceof FontDescriptor) {
realFontDescriptor = (FontDescriptor) realFont;
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/MutableFont.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/MutableFont.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/MutableFont.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/MutableFont.java
Fri Mar 30 19:09:29 2012
@@ -61,6 +61,12 @@ public interface MutableFont {
void setEmbedResourceName(String name);
/**
+ * Set the embedding mode for this font.
+ * @param embeddingMode the embedding mode.
+ */
+ void setEmbeddingMode(EmbeddingMode embeddingMode);
+
+ /**
* Sets the capital height value.
* @param capHeight capital height
*/
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/apps/TTFReader.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/apps/TTFReader.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/apps/TTFReader.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/apps/TTFReader.java
Fri Mar 30 19:09:29 2012
@@ -20,7 +20,6 @@
package org.apache.fop.fonts.apps;
import java.io.IOException;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -28,9 +27,9 @@ import javax.xml.parsers.DocumentBuilder
import org.apache.commons.logging.LogFactory;
import org.apache.fop.Version;
+import org.apache.fop.fonts.BFEntry;
import org.apache.fop.fonts.FontUtil;
import org.apache.fop.fonts.truetype.FontFileReader;
-import org.apache.fop.fonts.truetype.TTFCmapEntry;
import org.apache.fop.fonts.truetype.TTFFile;
import org.apache.fop.util.CommandLineLogger;
import org.w3c.dom.Document;
@@ -272,9 +271,9 @@ public class TTFReader extends AbstractF
root.appendChild(el);
el.appendChild(doc.createTextNode(ttf.getFullName()));
}
- Set familyNames = ttf.getFamilyNames();
+ Set<String> familyNames = ttf.getFamilyNames();
if (familyNames.size() > 0) {
- String familyName = (String)familyNames.iterator().next();
+ String familyName = familyNames.iterator().next();
el = doc.createElement("family-name");
root.appendChild(el);
el.appendChild(doc.createTextNode(familyName));
@@ -370,9 +369,7 @@ public class TTFReader extends AbstractF
el = doc.createElement("bfranges");
mel.appendChild(el);
- Iterator iter = ttf.getCMaps().listIterator();
- while (iter.hasNext()) {
- TTFCmapEntry ce = (TTFCmapEntry)iter.next();
+ for (BFEntry ce : ttf.getCMaps()) {
Element el2 = doc.createElement("bf");
el.appendChild(el2);
el2.setAttribute("us", String.valueOf(ce.getUnicodeStart()));
@@ -427,31 +424,28 @@ public class TTFReader extends AbstractF
Document doc = parent.getOwnerDocument();
// Get kerning
- Iterator iter;
+ Set<Integer> kerningKeys;
if (isCid) {
- iter = ttf.getKerning().keySet().iterator();
+ kerningKeys = ttf.getKerning().keySet();
} else {
- iter = ttf.getAnsiKerning().keySet().iterator();
+ kerningKeys = ttf.getAnsiKerning().keySet();
}
- while (iter.hasNext()) {
- Integer kpx1 = (Integer)iter.next();
+ for (Integer kpx1 : kerningKeys) {
el = doc.createElement("kerning");
el.setAttribute("kpx1", kpx1.toString());
parent.appendChild(el);
Element el2 = null;
- Map h2;
+ Map<Integer, Integer> h2;
if (isCid) {
- h2 = (Map)ttf.getKerning().get(kpx1);
+ h2 = ttf.getKerning().get(kpx1);
} else {
- h2 = (Map)ttf.getAnsiKerning().get(kpx1);
+ h2 = ttf.getAnsiKerning().get(kpx1);
}
- Iterator iter2 = h2.keySet().iterator();
- while (iter2.hasNext()) {
- Integer kpx2 = (Integer)iter2.next();
+ for (Integer kpx2 : h2.keySet()) {
if (isCid || kpx2.intValue() < 256) {
el2 = doc.createElement("pair");
el2.setAttribute("kpx2", kpx2.toString());
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
Fri Mar 30 19:09:29 2012
@@ -31,6 +31,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.EmbeddingMode;
import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontCache;
@@ -218,7 +219,8 @@ public class FontInfoFinder {
}
try {
TTFFontLoader ttfLoader = new TTFFontLoader(
- fontFileURL, fontName, true, EncodingMode.AUTO,
true, resolver);
+ fontFileURL, fontName, true, EmbeddingMode.AUTO,
EncodingMode.AUTO,
+ true, resolver);
customFont = ttfLoader.getFont();
if (this.eventListener != null) {
customFont.setEventListener(this.eventListener);
@@ -242,7 +244,8 @@ public class FontInfoFinder {
} else {
// The normal case
try {
- customFont = FontLoader.loadFont(fontURL, null, true,
EncodingMode.AUTO, resolver);
+ customFont = FontLoader.loadFont(fontURL, null, true,
EmbeddingMode.AUTO,
+ EncodingMode.AUTO, resolver);
if (this.eventListener != null) {
customFont.setEventListener(this.eventListener);
}
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/FontFileReader.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
Fri Mar 30 19:09:29 2012
@@ -90,23 +90,13 @@ public class FontFileReader {
}
/**
- * Set current file position to offset
- *
- * @param add The number of bytes to advance
- * @throws IOException In case of an I/O problem
- */
- public void seekAdd(long add) throws IOException {
- seekSet(current + add);
- }
-
- /**
* Skip a given number of bytes.
*
* @param add The number of bytes to advance
* @throws IOException In case of an I/O problem
*/
public void skip(long add) throws IOException {
- seekAdd(add);
+ seekSet(current + add);
}
/**
@@ -133,7 +123,7 @@ public class FontFileReader {
* @return One byte
* @throws IOException If EOF is reached
*/
- public byte read() throws IOException {
+ private byte read() throws IOException {
if (current >= fsize) {
throw new java.io.EOFException("Reached EOF, file size=" + fsize);
}
@@ -277,14 +267,14 @@ public class FontFileReader {
public final String readTTFString() throws IOException {
int i = current;
while (file[i++] != 0) {
- if (i > fsize) {
+ if (i >= fsize) {
throw new java.io.EOFException("Reached EOF, file size="
+ fsize);
}
}
- byte[] tmp = new byte[i - current];
- System.arraycopy(file, current, tmp, 0, i - current);
+ byte[] tmp = new byte[i - current - 1];
+ System.arraycopy(file, current, tmp, 0, i - current - 1);
return new String(tmp, "ISO-8859-1");
}
@@ -352,6 +342,11 @@ public class FontFileReader {
System.arraycopy(file, offset, ret, 0, length);
return ret;
}
-
-
+ /**
+ * Returns the full byte array representation of the file.
+ * @return byte array.
+ */
+ public byte[] getAllBytes() {
+ return file;
+ }
}
\ No newline at end of file
Modified:
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java?rev=1307574&r1=1307573&r2=1307574&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java
(original)
+++
xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/fonts/truetype/TTFDirTabEntry.java
Fri Mar 30 19:09:29 2012
@@ -33,6 +33,14 @@ class TTFDirTabEntry {
private long offset;
private long length;
+ public TTFDirTabEntry() {
+ }
+
+ public TTFDirTabEntry(long offset, long length) {
+ this.offset = offset;
+ this.length = length;
+ }
+
/**
* Read Dir Tab, return tag name
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]