You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2010/08/17 20:57:15 UTC
svn commit: r986451 [6/13] - in
/xmlgraphics/fop/branches/Temp_ComplexScripts: ./
examples/plan/src/org/apache/fop/plan/
src/codegen/java/org/apache/fop/tools/ src/codegen/unicode/data/
src/codegen/unicode/java/org/apache/fop/hyphenation/ src/codegen/u...
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontCache.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontCache.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontCache.java Tue Aug 17 18:57:04 2010
@@ -19,7 +19,9 @@
package org.apache.fop.fonts;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@@ -45,8 +47,8 @@ import org.apache.fop.util.LogUtil;
public final class FontCache implements Serializable {
/**
- * Serialization Version UID. Change this value if you want to make sure the user's cache
- * file is purged after an update.
+ * Serialization Version UID. Change this value if you want to make sure the
+ * user's cache file is purged after an update.
*/
private static final long serialVersionUID = 605232520271754719L;
@@ -59,19 +61,23 @@ public final class FontCache implements
/** font cache file path */
private static final String DEFAULT_CACHE_FILENAME = "fop-fonts.cache";
-
/** has this cache been changed since it was last read? */
private transient boolean changed = false;
/** change lock */
private final boolean[] changeLock = new boolean[1];
- /** master mapping of font url -> font info. This needs to be
- * a list, since a TTC file may contain more than 1 font. */
- private Map/*<String, CachedFontFile>*/ fontfileMap = null;
+ /**
+ * master mapping of font url -> font info. This needs to be a list, since a
+ * TTC file may contain more than 1 font.
+ */
+ private Map/* <String, CachedFontFile> */fontfileMap = null;
- /** mapping of font url -> file modified date (for all fonts that have failed to load) */
- private Map failedFontMap/*<String, Long>*/ = null;
+ /**
+ * mapping of font url -> file modified date (for all fonts that have failed
+ * to load)
+ */
+ private Map failedFontMap/* <String, Long> */= null;
/**
* Default constructor
@@ -100,7 +106,9 @@ public final class FontCache implements
/**
* Returns the default font cache file.
- * @param forWriting true if the user directory should be created
+ *
+ * @param forWriting
+ * true if the user directory should be created
* @return the default font cache file
*/
public static File getDefaultCacheFile(boolean forWriting) {
@@ -125,8 +133,9 @@ public final class FontCache implements
/**
* Reads the default font cache file and returns its contents.
- * @return the font cache deserialized from the file (or null if no cache file exists or if
- * it could not be read)
+ *
+ * @return the font cache deserialized from the file (or null if no cache
+ * file exists or if it could not be read)
*/
public static FontCache load() {
return loadFrom(getDefaultCacheFile(false));
@@ -134,36 +143,41 @@ public final class FontCache implements
/**
* Reads a font cache file and returns its contents.
- * @param cacheFile the cache file
- * @return the font cache deserialized from the file (or null if no cache file exists or if
- * it could not be read)
+ *
+ * @param cacheFile
+ * the cache file
+ * @return the font cache deserialized from the file (or null if no cache
+ * file exists or if it could not be read)
*/
public static FontCache loadFrom(File cacheFile) {
if (cacheFile.exists()) {
try {
if (log.isTraceEnabled()) {
- log.trace("Loading font cache from " + cacheFile.getCanonicalPath());
+ log.trace("Loading font cache from "
+ + cacheFile.getCanonicalPath());
}
- InputStream in = new java.io.FileInputStream(cacheFile);
- in = new java.io.BufferedInputStream(in);
+ InputStream in = new BufferedInputStream(new FileInputStream(cacheFile));
ObjectInputStream oin = new ObjectInputStream(in);
try {
- return (FontCache)oin.readObject();
+ return (FontCache) oin.readObject();
} finally {
IOUtils.closeQuietly(oin);
}
} catch (ClassNotFoundException e) {
- //We don't really care about the exception since it's just a cache file
+ // We don't really care about the exception since it's just a
+ // cache file
log.warn("Could not read font cache. Discarding font cache file. Reason: "
+ e.getMessage());
} catch (IOException ioe) {
- //We don't really care about the exception since it's just a cache file
- log.warn("I/O exception while reading font cache (" + ioe.getMessage()
- + "). Discarding font cache file.");
+ // We don't really care about the exception since it's just a
+ // cache file
+ log.warn("I/O exception while reading font cache ("
+ + ioe.getMessage() + "). Discarding font cache file.");
try {
cacheFile.delete();
} catch (SecurityException ex) {
- log.warn("Failed to delete font cache file: " + cacheFile.getAbsolutePath());
+ log.warn("Failed to delete font cache file: "
+ + cacheFile.getAbsolutePath());
}
}
}
@@ -172,7 +186,9 @@ public final class FontCache implements
/**
* Writes the font cache to disk.
- * @throws FOPException fop exception
+ *
+ * @throws FOPException
+ * fop exception
*/
public void save() throws FOPException {
saveTo(getDefaultCacheFile(true));
@@ -180,16 +196,17 @@ public final class FontCache implements
/**
* Writes the font cache to disk.
- * @param cacheFile the file to write to
- * @throws FOPException fop exception
+ *
+ * @param cacheFile
+ * the file to write to
+ * @throws FOPException
+ * fop exception
*/
public void saveTo(File cacheFile) throws FOPException {
synchronized (changeLock) {
if (changed) {
try {
- if (log.isTraceEnabled()) {
- log.trace("Writing font cache to " + cacheFile.getCanonicalPath());
- }
+ log.trace("Writing font cache to " + cacheFile.getCanonicalPath());
OutputStream out = new java.io.FileOutputStream(cacheFile);
out = new java.io.BufferedOutputStream(out);
ObjectOutputStream oout = new ObjectOutputStream(out);
@@ -209,7 +226,9 @@ public final class FontCache implements
/**
* creates a key given a font info for the font mapping
- * @param fontInfo font info
+ *
+ * @param fontInfo
+ * font info
* @return font cache key
*/
protected static String getCacheKey(EmbedFontInfo fontInfo) {
@@ -223,6 +242,7 @@ public final class FontCache implements
/**
* cache has been updated since it was read
+ *
* @return if this cache has changed
*/
public boolean hasChanged() {
@@ -231,28 +251,33 @@ public final class FontCache implements
/**
* is this font in the cache?
- * @param embedUrl font info
+ *
+ * @param embedUrl
+ * font info
* @return boolean
*/
public boolean containsFont(String embedUrl) {
- return (embedUrl != null
- && getFontFileMap().containsKey(embedUrl));
+ return (embedUrl != null && getFontFileMap().containsKey(embedUrl));
}
/**
* is this font info in the cache?
- * @param fontInfo font info
+ *
+ * @param fontInfo
+ * font info
* @return font
*/
public boolean containsFont(EmbedFontInfo fontInfo) {
- return (fontInfo != null
- && getFontFileMap().containsKey(getCacheKey(fontInfo)));
+ return (fontInfo != null && getFontFileMap().containsKey(
+ getCacheKey(fontInfo)));
}
/**
- * Tries to identify a File instance from an array of URLs. If there's no file URL in the
- * array, the method returns null.
- * @param urls array of possible font urls
+ * Tries to identify a File instance from an array of URLs. If there's no
+ * file URL in the array, the method returns null.
+ *
+ * @param urls
+ * array of possible font urls
* @return file font file
*/
public static File getFileFromUrls(String[] urls) {
@@ -279,31 +304,35 @@ public final class FontCache implements
return null;
}
- private Map/*<String, CachedFontFile>*/ getFontFileMap() {
+ private Map/* <String, CachedFontFile> */getFontFileMap() {
if (fontfileMap == null) {
- fontfileMap = new java.util.HashMap/*<String, CachedFontFile>*/();
+ fontfileMap = new java.util.HashMap/* <String, CachedFontFile> */();
}
return fontfileMap;
}
/**
* Adds a font info to cache
- * @param fontInfo font info
+ *
+ * @param fontInfo
+ * font info
*/
public void addFont(EmbedFontInfo fontInfo) {
String cacheKey = getCacheKey(fontInfo);
synchronized (changeLock) {
CachedFontFile cachedFontFile;
if (containsFont(cacheKey)) {
- cachedFontFile = (CachedFontFile)getFontFileMap().get(cacheKey);
+ cachedFontFile = (CachedFontFile) getFontFileMap()
+ .get(cacheKey);
if (!cachedFontFile.containsFont(fontInfo)) {
cachedFontFile.put(fontInfo);
}
} else {
// try and determine modified date
- File fontFile = getFileFromUrls(new String[]
- {fontInfo.getEmbedFile(), fontInfo.getMetricsFile()});
- long lastModified = (fontFile != null ? fontFile.lastModified() : -1);
+ File fontFile = getFileFromUrls(new String[] {
+ fontInfo.getEmbedFile(), fontInfo.getMetricsFile() });
+ long lastModified = (fontFile != null ? fontFile.lastModified()
+ : -1);
cachedFontFile = new CachedFontFile(lastModified);
if (log.isTraceEnabled()) {
log.trace("Font added to cache: " + cacheKey);
@@ -317,19 +346,27 @@ public final class FontCache implements
/**
* Returns a font from the cache.
- * @param embedUrl font info
+ *
+ * @param embedUrl
+ * font info
* @return CachedFontFile object
*/
public CachedFontFile getFontFile(String embedUrl) {
- return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get(embedUrl) : null;
+ return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get(
+ embedUrl) : null;
}
/**
- * Returns the EmbedFontInfo instances belonging to a font file. If the font file was
- * modified since it was cached the entry is removed and null is returned.
- * @param embedUrl the font URL
- * @param lastModified the last modified date/time of the font file
- * @return the EmbedFontInfo instances or null if there's no cached entry or if it is outdated
+ * Returns the EmbedFontInfo instances belonging to a font file. If the font
+ * file was modified since it was cached the entry is removed and null is
+ * returned.
+ *
+ * @param embedUrl
+ * the font URL
+ * @param lastModified
+ * the last modified date/time of the font file
+ * @return the EmbedFontInfo instances or null if there's no cached entry or
+ * if it is outdated
*/
public EmbedFontInfo[] getFontInfos(String embedUrl, long lastModified) {
CachedFontFile cff = getFontFile(embedUrl);
@@ -343,7 +380,9 @@ public final class FontCache implements
/**
* removes font from cache
- * @param embedUrl embed url
+ *
+ * @param embedUrl
+ * embed url
*/
public void removeFont(String embedUrl) {
synchronized (changeLock) {
@@ -359,14 +398,18 @@ public final class FontCache implements
/**
* has this font previously failed to load?
- * @param embedUrl embed url
- * @param lastModified last modified
+ *
+ * @param embedUrl
+ * embed url
+ * @param lastModified
+ * last modified
* @return whether this is a failed font
*/
public boolean isFailedFont(String embedUrl, long lastModified) {
synchronized (changeLock) {
if (getFailedFontMap().containsKey(embedUrl)) {
- long failedLastModified = ((Long)getFailedFontMap().get(embedUrl)).longValue();
+ long failedLastModified = ((Long) getFailedFontMap().get(
+ embedUrl)).longValue();
if (lastModified != failedLastModified) {
// this font has been changed so lets remove it
// from failed font map for now
@@ -382,8 +425,11 @@ public final class FontCache implements
/**
* Registers a failed font with the cache
- * @param embedUrl embed url
- * @param lastModified time last modified
+ *
+ * @param embedUrl
+ * embed url
+ * @param lastModified
+ * time last modified
*/
public void registerFailedFont(String embedUrl, long lastModified) {
synchronized (changeLock) {
@@ -394,9 +440,9 @@ public final class FontCache implements
}
}
- private Map/*<String, Long>*/ getFailedFontMap() {
+ private Map/* <String, Long> */getFailedFontMap() {
if (failedFontMap == null) {
- failedFontMap = new java.util.HashMap/*<String, Long>*/();
+ failedFontMap = new java.util.HashMap/* <String, Long> */();
}
return failedFontMap;
}
@@ -417,7 +463,9 @@ public final class FontCache implements
/**
* Retrieve the last modified date/time of a URL.
- * @param url the URL
+ *
+ * @param url
+ * the URL
* @return the last modified date/time
*/
public static long getLastModified(URL url) {
@@ -426,7 +474,8 @@ public final class FontCache implements
try {
return conn.getLastModified();
} finally {
- //An InputStream is created even if it's not accessed, but we need to close it.
+ // An InputStream is created even if it's not accessed, but we
+ // need to close it.
IOUtils.closeQuietly(conn.getInputStream());
}
} catch (IOException e) {
@@ -442,15 +491,15 @@ public final class FontCache implements
/** file modify date (if available) */
private long lastModified = -1;
- private Map/*<String, EmbedFontInfo>*/ filefontsMap = null;
+ private Map/* <String, EmbedFontInfo> */filefontsMap = null;
public CachedFontFile(long lastModified) {
setLastModified(lastModified);
}
- private Map/*<String, EmbedFontInfo>*/ getFileFontsMap() {
+ private Map/* <String, EmbedFontInfo> */getFileFontsMap() {
if (filefontsMap == null) {
- filefontsMap = new java.util.HashMap/*<String, EmbedFontInfo>*/();
+ filefontsMap = new java.util.HashMap/* <String, EmbedFontInfo> */();
}
return filefontsMap;
}
@@ -465,12 +514,13 @@ public final class FontCache implements
}
public EmbedFontInfo[] getEmbedFontInfos() {
- return (EmbedFontInfo[])getFileFontsMap().values().toArray(
+ return (EmbedFontInfo[]) getFileFontsMap().values().toArray(
new EmbedFontInfo[getFileFontsMap().size()]);
}
/**
* Gets the modified timestamp for font file (not always available)
+ *
* @return modified timestamp
*/
public long lastModified() {
@@ -478,17 +528,18 @@ public final class FontCache implements
}
/**
- * Gets the modified timestamp for font file
- * (used for the purposes of font info caching)
- * @param lastModified modified font file timestamp
+ * Gets the modified timestamp for font file (used for the purposes of
+ * font info caching)
+ *
+ * @param lastModified
+ * modified font file timestamp
*/
public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}
/**
- * @return string representation of this object
- * {@inheritDoc}
+ * @return string representation of this object {@inheritDoc}
*/
public String toString() {
return super.toString() + ", lastModified=" + lastModified;
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontInfoConfigurator.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontInfoConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontInfoConfigurator.java Tue Aug 17 18:57:04 2010
@@ -75,8 +75,8 @@ public class FontInfoConfigurator {
* @throws FOPException if an exception occurs while processing the configuration
*/
public void configure(List/*<EmbedFontInfo>*/ fontInfoList) throws FOPException {
- Configuration fonts = cfg.getChild("fonts", false);
- if (fonts != null) {
+ Configuration fontsCfg = cfg.getChild("fonts", false);
+ if (fontsCfg != null) {
long start = 0;
if (log.isDebugEnabled()) {
log.debug("Starting font configuration...");
@@ -86,24 +86,23 @@ public class FontInfoConfigurator {
FontAdder fontAdder = new FontAdder(fontManager, fontResolver, listener);
// native o/s search (autodetect) configuration
- boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null);
+ boolean autodetectFonts = (fontsCfg.getChild("auto-detect", false) != null);
if (autodetectFonts) {
FontDetector fontDetector = new FontDetector(fontManager, fontAdder, strict);
fontDetector.detect(fontInfoList);
}
- // Add configured directories to FontInfo
- addDirectories(fonts, fontAdder, fontInfoList);
+ // Add configured directories to FontInfo list
+ addDirectories(fontsCfg, fontAdder, fontInfoList);
- // Add configured fonts to FontInfo
- FontCache fontCache = fontManager.getFontCache();
- addFonts(fonts, fontCache, fontInfoList);
+ // Add fonts from configuration to FontInfo list
+ addFonts(fontsCfg, fontManager.getFontCache(), fontInfoList);
// Update referenced fonts (fonts which are not to be embedded)
fontManager.updateReferencedFonts(fontInfoList);
// Renderer-specific referenced fonts
- Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false);
+ Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false);
if (referencedFontsCfg != null) {
FontTriplet.Matcher matcher = FontManagerConfigurator.createFontsMatcher(
referencedFontsCfg, strict);
@@ -111,9 +110,7 @@ public class FontInfoConfigurator {
}
// Update font cache if it has changed
- if (fontCache != null && fontCache.hasChanged()) {
- fontCache.save();
- }
+ fontManager.saveCache();
if (log.isDebugEnabled()) {
log.debug("Finished font configuration in "
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManager.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManager.java Tue Aug 17 18:57:04 2010
@@ -19,6 +19,7 @@
package org.apache.fop.fonts;
+import java.io.File;
import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;
@@ -26,12 +27,12 @@ import java.util.List;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
+import org.apache.fop.apps.FOPException;
import org.apache.fop.fonts.FontTriplet.Matcher;
import org.apache.fop.fonts.substitute.FontSubstitutions;
// TODO: Refactor fonts package so major font activities (autodetection etc)
-// are all centrally managed and delegated from this class, also remove dependency on FopFactory
-// and start using POJO config/properties type classes
+// are all centrally managed and delegated from this class
/**
* The manager of fonts. The class holds a reference to the font cache and information about
@@ -56,11 +57,16 @@ public class FontManager {
/** FontTriplet matcher for fonts that shall be referenced rather than embedded. */
private FontTriplet.Matcher referencedFontsMatcher;
+ /** Enables/disables the use of font caching */
+ private boolean useCache = DEFAULT_USE_CACHE;
+
+ /** Provides a font cache file path **/
+ private File cacheFile;
+
/**
* Main constructor
*/
public FontManager() {
- setUseCache(DEFAULT_USE_CACHE);
}
/**
@@ -113,16 +119,31 @@ public class FontManager {
}
/**
+ * Sets the font cache file
+ * @param cacheFile the font cache file
+ */
+ public void setCacheFile(File cacheFile) {
+ this.cacheFile = cacheFile;
+ }
+
+ /**
+ * Returns the font cache file
+ * @return the font cache file
+ */
+ public File getCacheFile() {
+ if (cacheFile != null) {
+ return this.cacheFile;
+ }
+ return FontCache.getDefaultCacheFile(false);
+ }
+
+ /**
* Whether or not to cache results of font triplet detection/auto-config
* @param useCache use cache or not
*/
public void setUseCache(boolean useCache) {
- if (useCache) {
- this.fontCache = FontCache.load();
- if (this.fontCache == null) {
- this.fontCache = new FontCache();
- }
- } else {
+ this.useCache = useCache;
+ if (!useCache) {
this.fontCache = null;
}
}
@@ -132,7 +153,7 @@ public class FontManager {
* @return true if this font manager uses the cache
*/
public boolean useCache() {
- return (this.fontCache != null);
+ return useCache;
}
/**
@@ -140,7 +161,52 @@ public class FontManager {
* @return the font cache
*/
public FontCache getFontCache() {
- return this.fontCache;
+ if (fontCache == null) {
+ if (useCache) {
+ if (cacheFile != null) {
+ fontCache = FontCache.loadFrom(cacheFile);
+ } else {
+ fontCache = FontCache.load();
+ }
+ if (fontCache == null) {
+ fontCache = new FontCache();
+ }
+ }
+ }
+ return fontCache;
+ }
+
+ /**
+ * Saves the FontCache as necessary
+ *
+ * @throws FOPException fop exception
+ */
+ public void saveCache() throws FOPException {
+ if (useCache) {
+ if (fontCache != null && fontCache.hasChanged()) {
+ if (cacheFile != null) {
+ fontCache.saveTo(cacheFile);
+ } else {
+ fontCache.save();
+ }
+ }
+ }
+ }
+
+ /**
+ * Deletes the current FontCache file
+ * @return Returns true if the font cache file was successfully deleted.
+ */
+ public boolean deleteCache() {
+ boolean deleted = false;
+ if (useCache) {
+ if (cacheFile != null) {
+ deleted = cacheFile.delete();
+ } else {
+ deleted = FontCache.getDefaultCacheFile(true).delete();
+ }
+ }
+ return deleted;
}
/**
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Tue Aug 17 18:57:04 2010
@@ -19,6 +19,7 @@
package org.apache.fop.fonts;
+import java.io.File;
import java.net.MalformedURLException;
import java.util.List;
import java.util.regex.Pattern;
@@ -58,20 +59,24 @@ public class FontManagerConfigurator {
* @throws FOPException if an exception occurs while processing the configuration
*/
public void configure(FontManager fontManager, boolean strict) throws FOPException {
-
// caching (fonts)
if (cfg.getChild("use-cache", false) != null) {
try {
- fontManager.setUseCache(
- cfg.getChild("use-cache").getValueAsBoolean());
- } catch (ConfigurationException mfue) {
- LogUtil.handleException(log, mfue, true);
+ fontManager.setUseCache(cfg.getChild("use-cache").getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, true);
+ }
+ }
+ if (cfg.getChild("cache-file", false) != null) {
+ try {
+ fontManager.setCacheFile(new File(cfg.getChild("cache-file").getValue()));
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, true);
}
}
if (cfg.getChild("font-base", false) != null) {
try {
- fontManager.setFontBaseURL(
- cfg.getChild("font-base").getValue(null));
+ fontManager.setFontBaseURL(cfg.getChild("font-base").getValue(null));
} catch (MalformedURLException mfue) {
LogUtil.handleException(log, mfue, true);
}
@@ -80,13 +85,12 @@ public class FontManagerConfigurator {
// global font configuration
Configuration fontsCfg = cfg.getChild("fonts", false);
if (fontsCfg != null) {
+
// font substitution
Configuration substitutionsCfg = fontsCfg.getChild("substitutions", false);
if (substitutionsCfg != null) {
- FontSubstitutionsConfigurator fontSubstitutionsConfigurator
- = new FontSubstitutionsConfigurator(substitutionsCfg);
FontSubstitutions substitutions = new FontSubstitutions();
- fontSubstitutionsConfigurator.configure(substitutions);
+ new FontSubstitutionsConfigurator(substitutionsCfg).configure(substitutions);
fontManager.setFontSubstitutions(substitutions);
}
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontSetup.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontSetup.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontSetup.java Tue Aug 17 18:57:04 2010
@@ -25,8 +25,6 @@ import java.util.List;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.fop.fonts.base14.Courier;
import org.apache.fop.fonts.base14.CourierBold;
import org.apache.fop.fonts.base14.CourierBoldOblique;
@@ -51,12 +49,10 @@ import org.apache.fop.fonts.base14.ZapfD
* Assigns the font (with metrics) to internal names like "F1" and
* assigns family-style-weight triplets to the fonts
*/
-public class FontSetup {
+public final class FontSetup {
- /**
- * logging instance
- */
- protected static Log log = LogFactory.getLog(FontSetup.class);
+ private FontSetup() {
+ }
/**
* Sets up a font info
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontType.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontType.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontType.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontType.java Tue Aug 17 18:57:04 2010
@@ -54,6 +54,9 @@ public class FontType {
/**
+ * Construct a font type.
+ * @param name a font type name
+ * @param value a font type value
* @see org.apache.avalon.framework.Enum#Enum(String)
*/
protected FontType(String name, int value) {
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontUtil.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/FontUtil.java Tue Aug 17 18:57:04 2010
@@ -23,7 +23,10 @@ package org.apache.fop.fonts;
/**
* Font utilities.
*/
-public class FontUtil {
+public final class FontUtil {
+
+ private FontUtil() {
+ }
/**
* Parses an CSS2 (SVG and XSL-FO) font weight (normal, bold, 100-900) to
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/Glyphs.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/Glyphs.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/Glyphs.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/Glyphs.java Tue Aug 17 18:57:04 2010
@@ -23,7 +23,10 @@ package org.apache.fop.fonts;
* This class provides a number of constants for glyph management.
* @deprecated Use the Glyphs class from XML Graphics Commons instead!
*/
-public class Glyphs {
+public final class Glyphs {
+
+ private Glyphs() {
+ }
/**
* Glyph name for the "notdef" glyph
@@ -33,7 +36,7 @@ public class Glyphs {
/**
* Glyph names for Mac encoding
*/
- public static final String MAC_GLYPH_NAMES[] = {
+ public static final String[] MAC_GLYPH_NAMES = {
/* 0x00 */
NOTDEF, ".null", "CR", "space", "exclam", "quotedbl", "numbersign",
"dollar", "percent", "ampersand", "quotesingle", "parenleft",
@@ -1273,7 +1276,7 @@ public class Glyphs {
* @param ch glyph to evaluate
* @return the name of the glyph
*/
- public static final String charToGlyphName(char ch) {
+ public static String charToGlyphName(char ch) {
return stringToGlyph(new Character(ch).toString());
}
@@ -1286,7 +1289,7 @@ public class Glyphs {
* TODO: javadocs for glyphToString and stringToGlyph are confused
* TODO: Improve method names
*/
- public static final String glyphToString(String name) {
+ public static String glyphToString(String name) {
for (int i = 0; i < UNICODE_GLYPHS.length; i += 2) {
if (UNICODE_GLYPHS[i + 1].equals(name)) {
return UNICODE_GLYPHS[i];
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/MultiByteFont.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/MultiByteFont.java Tue Aug 17 18:57:04 2010
@@ -241,7 +241,7 @@ public class MultiByteFont extends CIDFo
return subset.getSubsetGlyphs();
}
- /** {@inheritDoc} */
+ /** @return an array of the chars used */
public char[] getCharsUsed() {
if (!isEmbeddable()) {
return null;
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java Tue Aug 17 18:57:04 2010
@@ -70,7 +70,7 @@ public class FontInfoFinder {
* It seems to be fairly accurate but will probably require some tweaking over time
*
* @param customFont CustomFont
- * @param triplet Collection that will take the generated triplets
+ * @param triplets Collection that will take the generated triplets
*/
private void generateTripletsFromFont(CustomFont customFont, Collection triplets) {
if (log.isTraceEnabled()) {
@@ -138,7 +138,7 @@ public class FontInfoFinder {
* @param fontUrl the font URL
* @param customFont the custom font
* @param fontCache font cache (may be null)
- * @return
+ * @return FontInfo from the given custom font
*/
private EmbedFontInfo getFontInfoFromCustomFont(
URL fontUrl, CustomFont customFont, FontCache fontCache) {
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/FontFileReader.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/FontFileReader.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/FontFileReader.java Tue Aug 17 18:57:04 2010
@@ -317,6 +317,7 @@ public class FontFileReader {
* Read an ISO-8859-1 string of len bytes.
*
* @param len The length of the string to read
+ * @param encodingID the string encoding id (presently ignored; always uses UTF-16BE)
* @return A String
* @throws IOException If EOF is reached
*/
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFCmapEntry.java Tue Aug 17 18:57:04 2010
@@ -44,6 +44,17 @@ public class TTFCmapEntry {
/**
* {@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;
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFFile.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFFile.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/truetype/TTFFile.java Tue Aug 17 18:57:04 2010
@@ -245,7 +245,8 @@ public class TTFFile {
}
}
- private boolean readUnicodeCmap(FontFileReader in, long cmapUniOffset, int encodingID)
+ private boolean readUnicodeCmap // CSOK: MethodLength
+ (FontFileReader in, long cmapUniOffset, int encodingID)
throws IOException {
//Read CMAP table and correct mtxTab.index
int mtxPtr = 0;
@@ -961,7 +962,7 @@ public class TTFFile {
* Read the "post" table
* containing the PostScript names of the glyphs.
*/
- private final void readPostScript(FontFileReader in) throws IOException {
+ private void readPostScript(FontFileReader in) throws IOException {
seekTab(in, "post", 0);
postFormat = in.readTTFLong();
italicAngle = in.readTTFULong();
@@ -1133,7 +1134,7 @@ public class TTFFile {
* @param in FontFileReader to read from
* @throws IOException In case of a I/O problem
*/
- private final void readGlyf(FontFileReader in) throws IOException {
+ private void readGlyf(FontFileReader in) throws IOException {
TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("glyf");
if (dirTab == null) {
throw new IOException("glyf table not found, cannot continue");
@@ -1188,7 +1189,7 @@ public class TTFFile {
* @param in FontFileReader to read from
* @throws IOException In case of a I/O problem
*/
- private final void readName(FontFileReader in) throws IOException {
+ private void readName(FontFileReader in) throws IOException {
seekTab(in, "name", 2);
int i = in.getCurrentPos();
int n = in.readTTFUShort();
@@ -1259,7 +1260,7 @@ public class TTFFile {
* @param in FontFileReader to read from
* @throws IOException In case of a I/O problem
*/
- private final boolean readPCLT(FontFileReader in) throws IOException {
+ private boolean readPCLT(FontFileReader in) throws IOException {
TTFDirTabEntry dirTab = (TTFDirTabEntry)dirTabs.get("PCLT");
if (dirTab != null) {
in.seekSet(dirTab.getOffset() + 4 + 4 + 2);
@@ -1403,7 +1404,7 @@ public class TTFFile {
* @param in FontFileReader to read from
* @throws IOException In case of a I/O problem
*/
- private final void readKerning(FontFileReader in) throws IOException {
+ private void readKerning(FontFileReader in) throws IOException {
// Read kerning
kerningTab = new java.util.HashMap();
ansiKerningTab = new java.util.HashMap();
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/PFBParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/PFBParser.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/PFBParser.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/PFBParser.java Tue Aug 17 18:57:04 2010
@@ -161,7 +161,7 @@ public class PFBParser {
}
- private static final boolean byteCmp(byte[] src, int srcOffset, byte[] cmp) {
+ private static boolean byteCmp(byte[] src, int srcOffset, byte[] cmp) {
for (int i = 0; i < cmp.length; i++) {
// System.out.println("Compare: " + src[srcOffset + i] + " " + cmp[i]);
if (src[srcOffset + i] != cmp[i]) {
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/ByteVector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/ByteVector.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/ByteVector.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/ByteVector.java Tue Aug 17 18:57:04 2010
@@ -45,10 +45,17 @@ public class ByteVector implements Seria
*/
private int n;
+ /**
+ * Construct byte vector instance with default block size.
+ */
public ByteVector() {
this(DEFAULT_BLOCK_SIZE);
}
+ /**
+ * Construct byte vector instance.
+ * @param capacity initial block size
+ */
public ByteVector(int capacity) {
if (capacity > 0) {
blockSize = capacity;
@@ -59,12 +66,25 @@ public class ByteVector implements Seria
n = 0;
}
+ /**
+ * Construct byte vector instance.
+ * @param a byte array to use
+ * @asf.todo should n should be initialized to a.length to be consistent with
+ * CharVector behavior? [GA]
+ */
public ByteVector(byte[] a) {
blockSize = DEFAULT_BLOCK_SIZE;
array = a;
n = 0;
}
+ /**
+ * Construct byte vector instance.
+ * @param a byte array to use
+ * @param capacity initial block size
+ * @asf.todo should n should be initialized to a.length to be consistent with
+ * CharVector behavior? [GA]
+ */
public ByteVector(byte[] a, int capacity) {
if (capacity > 0) {
blockSize = capacity;
@@ -75,34 +95,52 @@ public class ByteVector implements Seria
n = 0;
}
+ /**
+ * Obtain byte vector array.
+ * @return byte array
+ */
public byte[] getArray() {
return array;
}
/**
- * return number of items in array
+ * Obtain number of items in array.
+ * @return number of items
*/
public int length() {
return n;
}
/**
- * returns current capacity of array
+ * Obtain capacity of array.
+ * @return current capacity of array
*/
public int capacity() {
return array.length;
}
+ /**
+ * Pet byte at index.
+ * @param index the index
+ * @param val a byte
+ */
public void put(int index, byte val) {
array[index] = val;
}
+ /**
+ * Get byte at index.
+ * @param index the index
+ * @return a byte
+ */
public byte get(int index) {
return array[index];
}
/**
* This is to implement memory allocation in the array. Like malloc().
+ * @param size to allocate
+ * @return previous length
*/
public int alloc(int size) {
int index = n;
@@ -116,6 +154,9 @@ public class ByteVector implements Seria
return index;
}
+ /**
+ * Trim byte vector to current length.
+ */
public void trimToSize() {
if (n < array.length) {
byte[] aux = new byte[n];
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/CharVector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/CharVector.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/CharVector.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/CharVector.java Tue Aug 17 18:57:04 2010
@@ -45,10 +45,17 @@ public class CharVector implements Clone
*/
private int n;
+ /**
+ * Construct char vector instance with default block size.
+ */
public CharVector() {
this(DEFAULT_BLOCK_SIZE);
}
+ /**
+ * Construct char vector instance.
+ * @param capacity initial block size
+ */
public CharVector(int capacity) {
if (capacity > 0) {
blockSize = capacity;
@@ -59,12 +66,21 @@ public class CharVector implements Clone
n = 0;
}
+ /**
+ * Construct char vector instance.
+ * @param a char array to use
+ */
public CharVector(char[] a) {
blockSize = DEFAULT_BLOCK_SIZE;
array = a;
n = a.length;
}
+ /**
+ * Construct char vector instance.
+ * @param a char array to use
+ * @param capacity initial block size
+ */
public CharVector(char[] a, int capacity) {
if (capacity > 0) {
blockSize = capacity;
@@ -76,44 +92,66 @@ public class CharVector implements Clone
}
/**
- * Reset Vector but don't resize or clear elements
+ * Reset length of vector, but don't clear contents.
*/
public void clear() {
n = 0;
}
+ /** {@inheritDoc} */
public Object clone() {
CharVector cv = new CharVector((char[])array.clone(), blockSize);
cv.n = this.n;
return cv;
}
+ /**
+ * Obtain char vector array.
+ * @return char array
+ */
public char[] getArray() {
return array;
}
/**
- * return number of items in array
+ * Obtain number of items in array.
+ * @return number of items
*/
public int length() {
return n;
}
/**
- * returns current capacity of array
+ * Obtain capacity of array.
+ * @return current capacity of array
*/
public int capacity() {
return array.length;
}
+ /**
+ * Pet char at index.
+ * @param index the index
+ * @param val a char
+ */
public void put(int index, char val) {
array[index] = val;
}
+ /**
+ * Get char at index.
+ * @param index the index
+ * @return a char
+ */
public char get(int index) {
return array[index];
}
+ /**
+ * This is to implement memory allocation in the array. Like malloc().
+ * @param size to allocate
+ * @return previous length
+ */
public int alloc(int size) {
int index = n;
int len = array.length;
@@ -126,6 +164,9 @@ public class CharVector implements Clone
return index;
}
+ /**
+ * Trim char vector to current length.
+ */
public void trimToSize() {
if (n < array.length) {
char[] aux = new char[n];
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphen.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphen.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphen.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphen.java Tue Aug 17 18:57:04 2010
@@ -34,23 +34,43 @@ import java.io.Serializable;
* @author Carlos Villegas <ca...@uniscope.co.jp>
*/
+/**
+ * Represents a hyphen.
+ */
public class Hyphen implements Serializable {
- public String preBreak;
- public String noBreak;
- public String postBreak;
+ /** pre break string */
+ public String preBreak; // CSOK: VisibilityModifier
+
+ /** no break string */
+ public String noBreak; // CSOK: VisibilityModifier
+
+ /** post break string */
+ public String postBreak; // CSOK: VisibilityModifier
+
+ /**
+ * Construct a hyphen.
+ * @param pre break string
+ * @param no break string
+ * @param post break string
+ */
Hyphen(String pre, String no, String post) {
preBreak = pre;
noBreak = no;
postBreak = post;
}
+ /**
+ * Construct a hyphen.
+ * @param pre break string
+ */
Hyphen(String pre) {
preBreak = pre;
noBreak = null;
postBreak = null;
}
+ /** {@inheritDoc} */
public String toString() {
if (noBreak == null
&& postBreak == null
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenation.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenation.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenation.java Tue Aug 17 18:57:04 2010
@@ -52,6 +52,7 @@ public class Hyphenation {
}
/**
+ * @param index an index position
* @return the pre-break text, not including the hyphen character
*/
public String getPreHyphenText(int index) {
@@ -59,6 +60,7 @@ public class Hyphenation {
}
/**
+ * @param index an index position
* @return the post-break text
*/
public String getPostHyphenText(int index) {
@@ -72,6 +74,7 @@ public class Hyphenation {
return hyphenPoints;
}
+ /** {@inheritDoc} */
public String toString() {
StringBuffer str = new StringBuffer();
int start = 0;
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationException.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationException.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationException.java Tue Aug 17 18:57:04 2010
@@ -20,12 +20,15 @@
package org.apache.fop.hyphenation;
/**
+ * An hyphenation exception.
* @author Carlos Villegas <ca...@uniscope.co.jp>
- * (todo) Derive from FOPException
+ * @asf.todo Derive from FOPException
*/
public class HyphenationException extends Exception {
/**
+ * Construct a hyphenation exception.
+ * @param msg a message string
* @see java.lang.Throwable#Throwable(String)
*/
public HyphenationException(String msg) {
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationTree.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationTree.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationTree.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/HyphenationTree.java Tue Aug 17 18:57:04 2010
@@ -66,6 +66,7 @@ public class HyphenationTree extends Ter
*/
private transient TernaryTree ivalues;
+ /** Default constructor. */
public HyphenationTree() {
stoplist = new HashMap(23); // usually a small table
classmap = new TernaryTree();
@@ -100,6 +101,11 @@ public class HyphenationTree extends Ter
return offset;
}
+ /**
+ * Unpack values.
+ * @param k an integer
+ * @return a string
+ */
protected String unpackValues(int k) {
StringBuffer buf = new StringBuffer();
byte v = vspace.get(k++);
@@ -154,6 +160,11 @@ public class HyphenationTree extends Ter
ivalues = null;
}
+ /**
+ * Find pattern.
+ * @param pat a pattern
+ * @return a string
+ */
public String findPattern(String pat) {
int k = super.find(pat);
if (k >= 0) {
@@ -164,7 +175,12 @@ public class HyphenationTree extends Ter
/**
* String compare, returns 0 if equal or
- * t is a substring of s
+ * t is a substring of s.
+ * @param s first character array
+ * @param si starting index into first array
+ * @param t second character array
+ * @param ti starting index into second array
+ * @return an integer
*/
protected int hstrcmp(char[] s, int si, char[] t, int ti) {
for (; s[si] == t[ti]; si++, ti++) {
@@ -178,6 +194,11 @@ public class HyphenationTree extends Ter
return s[si] - t[ti];
}
+ /**
+ * Get values.
+ * @param k an integer
+ * @return a byte array
+ */
protected byte[] getValues(int k) {
StringBuffer buf = new StringBuffer();
byte v = vspace.get(k++);
@@ -352,12 +373,12 @@ public class HyphenationTree extends Ter
if (nc < 0) { // found a non-letter character ...
if (i == (1 + iIgnoreAtBeginning)) {
// ... before any letter character
- iIgnoreAtBeginning ++;
+ iIgnoreAtBeginning++;
} else {
// ... after a letter character
bEndOfLetters = true;
}
- iLength --;
+ iLength--;
} else {
if (!bEndOfLetters) {
word[i - iIgnoreAtBeginning] = (char)nc;
@@ -435,6 +456,7 @@ public class HyphenationTree extends Ter
* files use only lower case characters, in this case a class
* for letter 'a', for example, should be defined as "aA", the first
* character being the normalization char.
+ * @param chargroup a character class (group)
*/
public void addClass(String chargroup) {
if (chargroup.length() > 0) {
@@ -479,6 +501,9 @@ public class HyphenationTree extends Ter
insert(pattern, (char)k);
}
+ /**
+ * Print statistics.
+ */
public void printStats() {
System.out.println("Value space size = "
+ Integer.toString(vspace.length()));
@@ -486,11 +511,16 @@ public class HyphenationTree extends Ter
}
+ /**
+ * Main entry point for this hyphenation utility application.
+ * @param argv array of command linee arguments
+ * @throws Exception in case an exception is raised but not caught
+ */
public static void main(String[] argv) throws Exception {
HyphenationTree ht = null;
int minCharCount = 2;
- BufferedReader in =
- new BufferedReader(new java.io.InputStreamReader(System.in));
+ BufferedReader in
+ = new BufferedReader(new java.io.InputStreamReader(System.in));
while (true) {
System.out.print("l:\tload patterns from XML\n"
+ "L:\tload patterns from serialized object\n"
@@ -572,8 +602,8 @@ public class HyphenationTree extends Ter
long starttime = 0;
int counter = 0;
try {
- BufferedReader reader =
- new BufferedReader(new FileReader(token));
+ BufferedReader reader
+ = new BufferedReader(new FileReader(token));
String line;
starttime = System.currentTimeMillis();
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenator.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenator.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/Hyphenator.java Tue Aug 17 18:57:04 2010
@@ -259,7 +259,8 @@ public class Hyphenator {
if (source.getSystemId() != null) {
in = new java.net.URL(source.getSystemId()).openStream();
} else {
- throw new UnsupportedOperationException("Cannot load hyphenation pattern file"
+ throw new UnsupportedOperationException
+ ("Cannot load hyphenation pattern file"
+ " with the supplied Source object: " + source);
}
}
@@ -377,7 +378,8 @@ public class Hyphenator {
* @param rightMin the minimum number of characters after the hyphenation point
* @return the hyphenation result
*/
- public static Hyphenation hyphenate(String lang, String country,
+ public static Hyphenation hyphenate(String lang, // CSOK: ParameterNumber
+ String country,
HyphenationTreeResolver resolver,
char[] word, int offset, int len,
int leftMin, int rightMin) {
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternConsumer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternConsumer.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternConsumer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternConsumer.java Tue Aug 17 18:57:04 2010
@@ -44,6 +44,8 @@ public interface PatternConsumer {
* fails or the user wants to provide his own hyphenation.
* A hyphenatedword is a vector of alternating String's and
* {@link Hyphen Hyphen} instances
+ * @param word word to add as an exception
+ * @param hyphenatedword pre-hyphenated word
*/
void addException(String word, ArrayList hyphenatedword);
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternParser.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternParser.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/PatternParser.java Tue Aug 17 18:57:04 2010
@@ -61,6 +61,10 @@ public class PatternParser extends Defau
static final int ELEM_PATTERNS = 3;
static final int ELEM_HYPHEN = 4;
+ /**
+ * Construct a pattern parser.
+ * @throws HyphenationException if a hyphenation exception is raised
+ */
public PatternParser() throws HyphenationException {
this.consumer = this;
token = new StringBuffer();
@@ -70,6 +74,11 @@ public class PatternParser extends Defau
hyphenChar = '-'; // default
}
+ /**
+ * Construct a pattern parser.
+ * @param consumer a pattern consumer
+ * @throws HyphenationException if a hyphenation exception is raised
+ */
public PatternParser(PatternConsumer consumer) throws HyphenationException {
this();
this.consumer = consumer;
@@ -130,7 +139,7 @@ public class PatternParser extends Defau
}
}
- protected String readToken(StringBuffer chars) {
+ private String readToken(StringBuffer chars) {
String word;
boolean space = false;
int i;
@@ -175,7 +184,7 @@ public class PatternParser extends Defau
return null;
}
- protected static String getPattern(String word) {
+ private static String getPattern(String word) {
StringBuffer pat = new StringBuffer();
int len = word.length();
for (int i = 0; i < len; i++) {
@@ -186,7 +195,7 @@ public class PatternParser extends Defau
return pat.toString();
}
- protected ArrayList normalizeException(ArrayList ex) {
+ private ArrayList normalizeException(ArrayList ex) {
ArrayList res = new ArrayList();
for (int i = 0; i < ex.size(); i++) {
Object item = ex.get(i);
@@ -217,7 +226,7 @@ public class PatternParser extends Defau
return res;
}
- protected String getExceptionWord(ArrayList ex) {
+ private String getExceptionWord(ArrayList ex) {
StringBuffer res = new StringBuffer();
for (int i = 0; i < ex.size(); i++) {
Object item = ex.get(i);
@@ -232,7 +241,7 @@ public class PatternParser extends Defau
return res.toString();
}
- protected static String getInterletterValues(String pat) {
+ private static String getInterletterValues(String pat) {
StringBuffer il = new StringBuffer();
String word = pat + "a"; // add dummy letter to serve as sentinel
int len = word.length();
@@ -248,6 +257,7 @@ public class PatternParser extends Defau
return il.toString();
}
+ /** @throws SAXException if not caught */
protected void getExternalClasses() throws SAXException {
XMLReader mainParser = parser;
parser = createParser();
@@ -328,6 +338,8 @@ public class PatternParser extends Defau
case ELEM_HYPHEN:
// nothing to do
break;
+ default:
+ break;
}
if (currElement != ELEM_HYPHEN) {
token.setLength(0);
@@ -347,7 +359,7 @@ public class PatternParser extends Defau
/**
* {@inheritDoc}
*/
- public void characters(char ch[], int start, int length) {
+ public void characters(char[] ch, int start, int length) {
StringBuffer chars = new StringBuffer(length);
chars.append(ch, start, length);
String word = readToken(chars);
@@ -368,6 +380,8 @@ public class PatternParser extends Defau
consumer.addPattern(getPattern(word),
getInterletterValues(word));
break;
+ default:
+ break;
}
word = readToken(chars);
}
@@ -426,15 +440,26 @@ public class PatternParser extends Defau
} // getLocationString(SAXParseException):String
- // PatternConsumer implementation for testing purposes
+ /**
+ * For testing purposes only.
+ * {@inheritDoc}
+ */
public void addClass(String c) {
testOut.println("class: " + c);
}
+ /**
+ * For testing purposes only.
+ * {@inheritDoc}
+ */
public void addException(String w, ArrayList e) {
testOut.println("exception: " + w + " : " + e.toString());
}
+ /**
+ * For testing purposes only.
+ * {@inheritDoc}
+ */
public void addPattern(String p, String v) {
testOut.println("pattern: " + p + " : " + v);
}
@@ -442,17 +467,26 @@ public class PatternParser extends Defau
private PrintStream testOut = System.out;
/**
+ * Set test out stream.
* @param testOut the testOut to set
*/
public void setTestOut(PrintStream testOut) {
this.testOut = testOut;
}
+ /**
+ * Close test out file.
+ */
public void closeTestOut() {
testOut.flush();
testOut.close();
}
+ /**
+ * Main entry point when used as an application.
+ * @param args array of command line arguments
+ * @throws Exception in case of uncaught exception
+ */
public static void main(String[] args) throws Exception {
if (args.length > 0) {
PatternParser pp = new PatternParser();
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/TernaryTree.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/TernaryTree.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/TernaryTree.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/hyphenation/TernaryTree.java Tue Aug 17 18:57:04 2010
@@ -107,16 +107,22 @@ public class TernaryTree implements Clon
*/
protected CharVector kv;
+ /** root */
protected char root;
+ /** free node */
protected char freenode;
- protected int length; // number of items in tree
+ /** number of items in tree */
+ protected int length;
- protected static final int BLOCK_SIZE = 2048; // allocation size for arrays
+ /** allocation size for arrays */
+ protected static final int BLOCK_SIZE = 2048;
+ /** default constructor */
TernaryTree() {
init();
}
+ /** initialize */
protected void init() {
root = 0;
freenode = 1;
@@ -135,6 +141,8 @@ public class TernaryTree implements Clon
* another key with same prefix
* is inserted. This saves a lot of space,
* specially for long keys.
+ * @param key the key
+ * @param val a value
*/
public void insert(String key, char val) {
// make sure we have enough room in the arrays
@@ -143,12 +151,18 @@ public class TernaryTree implements Clon
if (freenode + len > eq.length) {
redimNodeArrays(eq.length + BLOCK_SIZE);
}
- char strkey[] = new char[len--];
+ char[] strkey = new char[len--];
key.getChars(0, len, strkey, 0);
strkey[len] = 0;
root = insert(root, strkey, 0, val);
}
+ /**
+ * Insert key.
+ * @param key the key
+ * @param start offset into key array
+ * @param val a value
+ */
public void insert(char[] key, int start, char val) {
int len = strlen(key) + 1;
if (freenode + len > eq.length) {
@@ -232,6 +246,11 @@ public class TernaryTree implements Clon
/**
* Compares 2 null terminated char arrays
+ * @param a a character array
+ * @param startA an index into character array
+ * @param b a character array
+ * @param startB an index into character array
+ * @return an integer
*/
public static int strcmp(char[] a, int startA, char[] b, int startB) {
for (; a[startA] == b[startB]; startA++, startB++) {
@@ -244,6 +263,10 @@ public class TernaryTree implements Clon
/**
* Compares a string with null terminated char array
+ * @param str a string
+ * @param a a character array
+ * @param start an index into character array
+ * @return an integer
*/
public static int strcmp(String str, char[] a, int start) {
int i, d, len = str.length();
@@ -263,6 +286,12 @@ public class TernaryTree implements Clon
}
+ /**
+ * @param dst a character array
+ * @param di an index into character array
+ * @param src a character array
+ * @param si an index into character array
+ */
public static void strcpy(char[] dst, int di, char[] src, int si) {
while (src[si] != 0) {
dst[di++] = src[si++];
@@ -270,6 +299,11 @@ public class TernaryTree implements Clon
dst[di] = 0;
}
+ /**
+ * @param a a character array
+ * @param start an index into character array
+ * @return an integer
+ */
public static int strlen(char[] a, int start) {
int len = 0;
for (int i = start; i < a.length && a[i] != 0; i++) {
@@ -278,19 +312,34 @@ public class TernaryTree implements Clon
return len;
}
+ /**
+ * @param a a character array
+ * @return an integer
+ */
public static int strlen(char[] a) {
return strlen(a, 0);
}
+ /**
+ * Find key.
+ * @param key the key
+ * @return result
+ */
public int find(String key) {
int len = key.length();
- char strkey[] = new char[len + 1];
+ char[] strkey = new char[len + 1];
key.getChars(0, len, strkey, 0);
strkey[len] = 0;
return find(strkey, 0);
}
+ /**
+ * Find key.
+ * @param key the key
+ * @param start offset into key array
+ * @return result
+ */
public int find(char[] key, int start) {
int d;
char p = root;
@@ -322,6 +371,10 @@ public class TernaryTree implements Clon
return -1;
}
+ /**
+ * @param key a key
+ * @return trye if key present
+ */
public boolean knows(String key) {
return (find(key) >= 0);
}
@@ -343,10 +396,12 @@ public class TernaryTree implements Clon
sc = na;
}
+ /** @return length */
public int size() {
return length;
}
+ /** {@inheritDoc} */
public Object clone() {
TernaryTree t = new TernaryTree();
t.lo = (char[])this.lo.clone();
@@ -366,6 +421,10 @@ public class TernaryTree implements Clon
* lower and upper halves, and so on in order to get a balanced
* tree. The array of keys is assumed to be sorted in ascending
* order.
+ * @param k array of keys
+ * @param v array of values
+ * @param offset where to insert
+ * @param n count to insert
*/
protected void insertBalanced(String[] k, char[] v, int offset, int n) {
int m;
@@ -453,37 +512,47 @@ public class TernaryTree implements Clon
}
}
-
+ /** @return the keys */
public Enumeration keys() {
return new Iterator();
}
+ /** an iterator */
public class Iterator implements Enumeration {
/**
* current node index
*/
- int cur;
+ int cur; // CSOK: VisibilityModifier
/**
* current key
*/
- String curkey;
+ String curkey; // CSOK: VisibilityModifier
private class Item implements Cloneable {
- char parent;
- char child;
+ /** parent */
+ char parent; // CSOK: VisibilityModifier
+ /** child */
+ char child; // CSOK: VisibilityModifier
+ /** default constructor */
public Item() {
parent = 0;
child = 0;
}
+ /**
+ * Construct item.
+ * @param p a char
+ * @param c a char
+ */
public Item(char p, char c) {
parent = p;
child = c;
}
+ /** {@inheritDoc} */
public Object clone() {
return new Item(parent, child);
}
@@ -493,13 +562,14 @@ public class TernaryTree implements Clon
/**
* Node stack
*/
- Stack ns;
+ Stack ns; // CSOK: VisibilityModifier
/**
* key stack implemented with a StringBuffer
*/
- StringBuffer ks;
+ StringBuffer ks; // CSOK: VisibilityModifier
+ /** default constructor */
public Iterator() {
cur = -1;
ns = new Stack();
@@ -507,6 +577,7 @@ public class TernaryTree implements Clon
rewind();
}
+ /** rewind iterator */
public void rewind() {
ns.removeAllElements();
ks.setLength(0);
@@ -514,6 +585,7 @@ public class TernaryTree implements Clon
run();
}
+ /** @return next element */
public Object nextElement() {
String res = new String(curkey);
cur = up();
@@ -521,6 +593,7 @@ public class TernaryTree implements Clon
return res;
}
+ /** @return value */
public char getValue() {
if (cur >= 0) {
return eq[cur];
@@ -528,6 +601,7 @@ public class TernaryTree implements Clon
return 0;
}
+ /** @return true if more elements */
public boolean hasMoreElements() {
return (cur != -1);
}
@@ -633,6 +707,9 @@ public class TernaryTree implements Clon
}
+ /**
+ * Print stats (for testing).
+ */
public void printStats() {
System.out.println("Number of keys = " + Integer.toString(length));
System.out.println("Node count = " + Integer.toString(freenode));
@@ -653,6 +730,11 @@ public class TernaryTree implements Clon
}
+ /**
+ * Main entry point for testing.
+ * @param args not used
+ * @throws Exception if not caught
+ */
public static void main(String[] args) throws Exception {
TernaryTree tt = new TernaryTree();
tt.insert("Carlos", 'C');
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/BatikUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/BatikUtil.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/BatikUtil.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/BatikUtil.java Tue Aug 17 18:57:04 2010
@@ -27,7 +27,10 @@ import org.apache.batik.dom.util.DOMUtil
/**
* Helper utilities for Apache Batik.
*/
-public class BatikUtil {
+public final class BatikUtil {
+
+ private BatikUtil() {
+ }
/**
* Checks whether Apache Batik is available in the classpath.
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java Tue Aug 17 18:57:04 2010
@@ -102,7 +102,11 @@ public class PreloaderSVG extends Abstra
* attempt to load Batik related classes when constructing the SVGPreloader
* class.
*/
- class Loader {
+ private final class Loader {
+
+ private Loader() {
+ }
+
private ImageInfo getImage(String uri, Source src,
ImageContext context) {
// parse document and get the size attributes of the svg element
Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java?rev=986451&r1=986450&r2=986451&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java Tue Aug 17 18:57:04 2010
@@ -78,7 +78,11 @@ public class PreloaderWMF extends Abstra
* attempt to load Batik related classes when constructing the WMFPreloader
* class.
*/
- class Loader {
+ private final class Loader {
+
+ private Loader() {
+ }
+
private ImageInfo getImage(String uri, Source src,
ImageContext context) {
// parse document and get the size attributes of the svg element
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org