diff options
Diffstat (limited to 'src/java/org/apache/fop/fonts')
13 files changed, 158 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index 4f35422ca..70961a55c 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -64,8 +64,6 @@ public abstract class CustomFont extends Typeface private boolean useKerning = true; private boolean useAdvanced = true; - /** the character map, mapping Unicode ranges to glyph indices. */ - protected CMapSegment[] cmap; /** * @param resourceResolver the URI resource resolver for controlling file access @@ -73,6 +71,8 @@ public abstract class CustomFont extends Typeface public CustomFont(InternalResourceResolver resourceResolver) { this.resourceResolver = resourceResolver; } + /** the character map, mapping Unicode ranges to glyph indices. */ + protected CMapSegment[] cmap; /** {@inheritDoc} */ public String getFontName() { @@ -124,6 +124,7 @@ public abstract class CustomFont extends Typeface } /** + * Returns the embedding mode for this font. * @return embedding mode */ diff --git a/src/java/org/apache/fop/fonts/DefaultFontConfig.java b/src/java/org/apache/fop/fonts/DefaultFontConfig.java index 439d28cc1..923e68fdc 100644 --- a/src/java/org/apache/fop/fonts/DefaultFontConfig.java +++ b/src/java/org/apache/fop/fonts/DefaultFontConfig.java @@ -112,7 +112,7 @@ public final class DefaultFontConfig implements FontConfig { fontCfg.getAttribute("sub-font", null), fontCfg.getAttributeAsBoolean( "kerning", true), fontCfg.getAttributeAsBoolean("advanced", true), fontCfg.getAttribute("encoding-mode", EncodingMode.AUTO.getName()), - fontCfg.getAttribute("embedding-mode", EmbeddingMode.AUTO.getName())); + fontCfg.getAttribute("embedding-mode", EncodingMode.AUTO.getName())); instance.fonts.add(font); boolean hasTriplets = false; for (Configuration tripletCfg : fontCfg.getChildren("font-triplet")) { @@ -279,6 +279,10 @@ public final class DefaultFontConfig implements FontConfig { private final String embeddingMode; + public String getEncodingMode() { + return encodingMode; + } + private final List<FontTriplet> tripletList = new ArrayList<FontTriplet>(); public List<FontTriplet> getTripletList() { @@ -332,10 +336,6 @@ public final class DefaultFontConfig implements FontConfig { return subFont; } - public String getEncodingMode() { - return encodingMode; - } - public String getEmbeddingMode() { return embeddingMode; } diff --git a/src/java/org/apache/fop/fonts/EmbedFontInfo.java b/src/java/org/apache/fop/fonts/EmbedFontInfo.java index 25d7c1c0f..5af3fc5ba 100644 --- a/src/java/org/apache/fop/fonts/EmbedFontInfo.java +++ b/src/java/org/apache/fop/fonts/EmbedFontInfo.java @@ -42,6 +42,7 @@ public class EmbedFontInfo implements Serializable { protected final boolean advanced; /** the requested encoding mode for the font */ private final EncodingMode encodingMode; + /** the requested embedding mode for this font */ private final EmbeddingMode embeddingMode; /** the PostScript name of the font */ @@ -63,7 +64,6 @@ public class EmbedFontInfo implements Serializable { * @param embedURI Path to the embeddable font file (may be null) * @param subFontName the sub-fontname used for TrueType Collections (null otherwise) * @param encodingMode the encoding mode to use for this font - * @param embeddingMode the embedding mode for this font */ public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced, List<FontTriplet> fontTriplets, URI embedURI, String subFontName, diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java index 35ec7355a..e9b021978 100644 --- a/src/java/org/apache/fop/fonts/FontManager.java +++ b/src/java/org/apache/fop/fonts/FontManager.java @@ -233,6 +233,16 @@ public class FontManager { } } + /** + * Detect fonts from the operating system via FOPs autodetect mechanism. + * + * @param autoDetectFonts if autodetect has been enabled + * @param fontAdder the font adding mechanism + * @param strict whether to enforce strict validation + * @param listener the listener for font related events + * @param fontInfoList a list of font info objects + * @throws FOPException if an exception was thrown auto-detecting fonts + */ public void autoDetectFonts(boolean autoDetectFonts, FontAdder fontAdder, boolean strict, FontEventListener listener, List<EmbedFontInfo> fontInfoList) throws FOPException { if (autoDetectFonts) { diff --git a/src/java/org/apache/fop/fonts/FontReader.java b/src/java/org/apache/fop/fonts/FontReader.java index 12d9e082d..68c5c7177 100644 --- a/src/java/org/apache/fop/fonts/FontReader.java +++ b/src/java/org/apache/fop/fonts/FontReader.java @@ -153,7 +153,6 @@ public class FontReader extends DefaultHandler { /** * {@inheritDoc} */ - @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (localName.equals("font-metrics")) { diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index ab261f275..8fb50fd08 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -46,9 +46,9 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, private final boolean useKerning; private final boolean useAdvanced; private final EncodingMode encodingMode; - private final EmbeddingMode embeddingMode; - private final boolean embedded; + private EmbeddingMode embeddingMode; private final String subFontName; + private final boolean embedded; private final InternalResourceResolver resourceResolver; private boolean isMetricsLoaded; @@ -70,8 +70,10 @@ public class LazyFont extends Typeface implements FontDescriptor, Substitutable, } else { this.useAdvanced = fontInfo.getAdvanced(); } - this.encodingMode = fontInfo.getEncodingMode(); - this.embeddingMode = fontInfo.getEmbeddingMode(); + this.encodingMode = fontInfo.getEncodingMode() != null ? fontInfo.getEncodingMode() + : EncodingMode.AUTO; + this.embeddingMode = fontInfo.getEmbeddingMode() != null ? fontInfo.getEmbeddingMode() + : EmbeddingMode.AUTO; this.subFontName = fontInfo.getSubFontName(); this.embedded = fontInfo.isEmbedded(); this.resourceResolver = resourceResolver; diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java index 6e4f84fd3..a460140cb 100644 --- a/src/java/org/apache/fop/fonts/MultiByteFont.java +++ b/src/java/org/apache/fop/fonts/MultiByteFont.java @@ -67,7 +67,7 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl private int lastUnmapped; /** - * @param resourceResolver the resource resolver for accessing the font + * Default constructor */ public MultiByteFont(InternalResourceResolver resourceResolver) { super(resourceResolver); diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java index 7adf41c58..e115264bb 100644 --- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java +++ b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java @@ -221,7 +221,8 @@ public class FontInfoFinder { } try { TTFFontLoader ttfLoader = new TTFFontLoader(fontURI, fontName, true, - EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced, resourceResolver); + EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced, + resourceResolver); customFont = ttfLoader.getFont(); if (this.eventListener != null) { customFont.setEventListener(this.eventListener); diff --git a/src/java/org/apache/fop/fonts/truetype/FontFileReader.java b/src/java/org/apache/fop/fonts/truetype/FontFileReader.java index 29ac86b4e..790e885bc 100644 --- a/src/java/org/apache/fop/fonts/truetype/FontFileReader.java +++ b/src/java/org/apache/fop/fonts/truetype/FontFileReader.java @@ -124,9 +124,9 @@ public class FontFileReader { final byte buf = read(); if (buf < 0) { - return (int)(256 + buf); + return (256 + buf); } else { - return (int)buf; + return buf; } } @@ -150,7 +150,7 @@ public class FontFileReader { */ public final int readTTFUShort() throws IOException { final int ret = (readTTFUByte() << 8) + readTTFUByte(); - return (int)ret; + return ret; } /** diff --git a/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java b/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java new file mode 100644 index 000000000..897d5e2de --- /dev/null +++ b/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java @@ -0,0 +1,118 @@ +/* + * 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.truetype; + +/** + * The CMap entry contains information of a Unicode range and the + * the glyph indexes related to the range + */ +public class TTFCmapEntry { + + private int unicodeStart; + private int unicodeEnd; + private int glyphStartIndex; + + TTFCmapEntry() { + unicodeStart = 0; + unicodeEnd = 0; + glyphStartIndex = 0; + } + + TTFCmapEntry(int unicodeStart, int unicodeEnd, int glyphStartIndex) { + this.unicodeStart = unicodeStart; + this.unicodeEnd = unicodeEnd; + this.glyphStartIndex = glyphStartIndex; + } + + /** + * {@inheritDoc} + */ + public int hashCode() { + int hc = super.hashCode(); + hc ^= ( hc * 11 ) + unicodeStart; + hc ^= ( hc * 19 ) + unicodeEnd; + hc ^= ( hc * 23 ) + glyphStartIndex; + return hc; + } + + /** + * {@inheritDoc} + */ + public boolean equals(Object o) { + if (o instanceof TTFCmapEntry) { + TTFCmapEntry ce = (TTFCmapEntry)o; + if (ce.unicodeStart == this.unicodeStart + && ce.unicodeEnd == this.unicodeEnd + && ce.glyphStartIndex == this.glyphStartIndex) { + return true; + } + } + return false; + } + + /** + * Returns the glyphStartIndex. + * @return int + */ + public int getGlyphStartIndex() { + return glyphStartIndex; + } + + /** + * Returns the unicodeEnd. + * @return int + */ + public int getUnicodeEnd() { + return unicodeEnd; + } + + /** + * Returns the unicodeStart. + * @return int + */ + public int getUnicodeStart() { + return unicodeStart; + } + + /** + * Sets the glyphStartIndex. + * @param glyphStartIndex The glyphStartIndex to set + */ + public void setGlyphStartIndex(int glyphStartIndex) { + this.glyphStartIndex = glyphStartIndex; + } + + /** + * Sets the unicodeEnd. + * @param unicodeEnd The unicodeEnd to set + */ + public void setUnicodeEnd(int unicodeEnd) { + this.unicodeEnd = unicodeEnd; + } + + /** + * Sets the unicodeStart. + * @param unicodeStart The unicodeStart to set + */ + public void setUnicodeStart(int unicodeStart) { + this.unicodeStart = unicodeStart; + } + +} diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFile.java b/src/java/org/apache/fop/fonts/truetype/TTFFile.java index 9c4c3a71b..05f61750e 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFile.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFile.java @@ -2018,9 +2018,9 @@ public class TTFFile { try { boolean useKerning = true; boolean useAdvanced = true; - stream = new FileInputStream(args[0]); TTFFile ttfFile = new TTFFile(useKerning, useAdvanced); + stream = new FileInputStream(args[0]); FontFileReader reader = new FontFileReader(stream); String name = null; @@ -2037,6 +2037,5 @@ public class TTFFile { } finally { IOUtils.closeQuietly(stream); } - } } diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java index f0443118d..c97b17211 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java @@ -72,10 +72,10 @@ public class TTFFontLoader extends FontLoader { * @param useAdvanced true to enable loading advanced info if available, false to disable * @param resolver the FontResolver for font URI resolution */ - public TTFFontLoader(URI fontFileURI, String subFontName, - boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode, - boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver) { - super(fontFileURI, embedded, useKerning, useAdvanced, resourceResolver); + public TTFFontLoader(URI fontFileURI, String subFontName, boolean embedded, + EmbeddingMode embeddingMode, EncodingMode encodingMode, boolean useKerning, + boolean useAdvanced, InternalResourceResolver resolver) { + super(fontFileURI, embedded, useKerning, useAdvanced, resolver); this.subFontName = subFontName; this.encodingMode = encodingMode; this.embeddingMode = embeddingMode; diff --git a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java index 5c6c32e7e..853e23eb5 100644 --- a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java +++ b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Set; import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.fonts.CodePointMapping; @@ -42,6 +44,8 @@ import org.apache.fop.fonts.SingleByteFont; */ public class Type1FontLoader extends FontLoader { + private static final Log log = LogFactory.getLog(Type1FontLoader.class); + private SingleByteFont singleFont; /** |