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 je...@apache.org on 2009/10/02 17:31:16 UTC
svn commit: r821058 - in /xmlgraphics/fop/trunk: ./
src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/fonts/
src/java/org/apache/fop/render/afp/
Author: jeremias
Date: Fri Oct 2 15:31:14 2009
New Revision: 821058
URL: http://svn.apache.org/viewvc?rev=821058&view=rev
Log:
Added support for specifying referenced fonts per renderer in addition to the general match list. If any of the two match lists (if specified) match a font, it is not embedded.
Modified:
xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml Fri Oct 2 15:31:14 2009
@@ -468,6 +468,13 @@
referenced. If you want to reference all fonts, just specify <code>font-family=".*"</code>.
</p>
<p>
+ The <code>referenced-fonts</code> element can be placed either inside the general
+ <code>fonts</code> element (right under the root) or in the <code>fonts</code> element
+ under the renderer configuration. In the first case, matches apply to all renderers.
+ In the second case, matches only apply to the renderer where the element was specified.
+ Both cases can be used at the same time.
+ </p>
+ <p>
Various notes related to embedded fonts:
</p>
<ul>
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java Fri Oct 2 15:31:14 2009
@@ -33,6 +33,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.fonts.autodetect.FontFileFinder;
import org.apache.fop.fonts.autodetect.FontInfoFinder;
@@ -83,7 +84,7 @@
}
FontAdder fontAdder = new FontAdder(fontManager, fontResolver, listener);
-
+
// native o/s search (autodetect) configuration
boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null);
if (autodetectFonts) {
@@ -93,7 +94,7 @@
// Add configured directories to FontInfo
addDirectories(fonts, fontAdder, fontInfoList);
-
+
// Add configured fonts to FontInfo
FontCache fontCache = fontManager.getFontCache();
addFonts(fonts, fontCache, fontInfoList);
@@ -101,6 +102,14 @@
// Update referenced fonts (fonts which are not to be embedded)
fontManager.updateReferencedFonts(fontInfoList);
+ // Renderer-specific referenced fonts
+ Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false);
+ if (referencedFontsCfg != null) {
+ FontTriplet.Matcher matcher = FontManagerConfigurator.createFontsMatcher(
+ referencedFontsCfg, strict);
+ fontManager.updateReferencedFonts(fontInfoList, matcher);
+ }
+
// Update font cache if it has changed
if (fontCache != null && fontCache.hasChanged()) {
fontCache.save();
@@ -112,7 +121,7 @@
}
}
}
-
+
private void addDirectories(Configuration fontsCfg,
FontAdder fontAdder, List/*<URL>*/ fontInfoList) throws FOPException {
// directory (multiple font) configuration
@@ -131,7 +140,7 @@
new FOPException("directory defined without value"), strict);
continue;
}
-
+
// add fonts found in directory
FontFileFinder fontFileFinder = new FontFileFinder(recursive ? -1 : 1);
List/*<URL>*/ fontURLList;
@@ -145,7 +154,7 @@
}
/**
- * Populates the font info list from the fonts configuration
+ * Populates the font info list from the fonts configuration
* @param fontsCfg a fonts configuration
* @param fontCache a font cache
* @param fontInfoList a font info list
@@ -163,7 +172,7 @@
}
}
}
-
+
private static void closeSource(Source src) {
if (src instanceof StreamSource) {
StreamSource streamSource = (StreamSource)src;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java Fri Oct 2 15:31:14 2009
@@ -190,11 +190,21 @@
}
/**
- * Updates the referenced font list
+ * Updates the referenced font list using the FontManager's referenced fonts matcher
+ * ({@link #getReferencedFontsMatcher()}).
* @param fontInfoList a font info list
*/
public void updateReferencedFonts(List fontInfoList) {
Matcher matcher = getReferencedFontsMatcher();
+ updateReferencedFonts(fontInfoList, matcher);
+ }
+
+ /**
+ * Updates the referenced font list.
+ * @param fontInfoList a font info list
+ * @param matcher the font triplet matcher to use
+ */
+ public void updateReferencedFonts(List fontInfoList, Matcher matcher) {
if (matcher == null) {
return; //No referenced fonts
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Fri Oct 2 15:31:14 2009
@@ -93,16 +93,25 @@
// referenced fonts (fonts which are not to be embedded)
Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false);
if (referencedFontsCfg != null) {
- createReferencedFontsMatcher(referencedFontsCfg, strict, fontManager);
+ FontTriplet.Matcher matcher = createFontsMatcher(
+ referencedFontsCfg, strict);
+ fontManager.setReferencedFontsMatcher(matcher);
}
}
}
- private static void createReferencedFontsMatcher(Configuration referencedFontsCfg,
- boolean strict, FontManager fontManager) throws FOPException {
+ /**
+ * Creates a font triplet matcher from a configuration object.
+ * @param cfg the configuration object
+ * @param strict true for strict configuraton error handling
+ * @return the font matcher
+ * @throws FOPException if an error occurs while building the matcher
+ */
+ public static FontTriplet.Matcher createFontsMatcher(
+ Configuration cfg, boolean strict) throws FOPException {
List matcherList = new java.util.ArrayList();
- Configuration[] matches = referencedFontsCfg.getChildren("match");
+ Configuration[] matches = cfg.getChildren("match");
for (int i = 0; i < matches.length; i++) {
try {
matcherList.add(new FontFamilyRegExFontTripletMatcher(
@@ -115,7 +124,7 @@
FontTriplet.Matcher orMatcher = new OrFontTripletMatcher(
(FontTriplet.Matcher[])matcherList.toArray(
new FontTriplet.Matcher[matcherList.size()]));
- fontManager.setReferencedFontsMatcher(orMatcher);
+ return orMatcher;
}
private static class OrFontTripletMatcher implements FontTriplet.Matcher {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java Fri Oct 2 15:31:14 2009
@@ -43,6 +43,7 @@
import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontManager;
+import org.apache.fop.fonts.FontManagerConfigurator;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.FontUtil;
import org.apache.fop.fonts.Typeface;
@@ -71,9 +72,7 @@
throws ConfigurationException {
FontManager fontManager = this.userAgent.getFactory().getFontManager();
- FontTriplet.Matcher referencedFontsMatcher = fontManager.getReferencedFontsMatcher();
- boolean embeddable = true;
Configuration[] triple = fontCfg.getChildren("font-triplet");
List/*<FontTriplet>*/ tripletList = new java.util.ArrayList/*<FontTriplet>*/();
if (triple.length == 0) {
@@ -85,9 +84,6 @@
FontTriplet triplet = new FontTriplet(triple[j].getAttribute("name"),
triple[j].getAttribute("style"),
weight);
- if (referencedFontsMatcher != null && referencedFontsMatcher.matches(triplet)) {
- embeddable = false;
- }
tripletList.add(triplet);
}
@@ -142,7 +138,6 @@
// Create a new font object
RasterFont font = new RasterFont(name);
- font.setEmbeddable(embeddable);
Configuration[] rasters = afpFontCfg.getChildren("afp-raster-font");
if (rasters.length == 0) {
@@ -220,7 +215,6 @@
}
// Create a new font object
OutlineFont font = new OutlineFont(name, characterSet);
- font.setEmbeddable(embeddable);
return new AFPFontInfo(font, tripletList);
} else {
log.error("No or incorrect type attribute");
@@ -236,24 +230,49 @@
* @throws ConfigurationException if something's wrong with the config data
*/
private List/*<AFPFontInfo>*/ buildFontListFromConfiguration(Configuration cfg)
- throws ConfigurationException {
+ throws FOPException, ConfigurationException {
+
+ Configuration fonts = cfg.getChild("fonts");
+ FontManager fontManager = this.userAgent.getFactory().getFontManager();
+
+ // General matcher
+ FontTriplet.Matcher referencedFontsMatcher = fontManager.getReferencedFontsMatcher();
+ // Renderer-specific matcher
+ FontTriplet.Matcher localMatcher = null;
+
+ // Renderer-specific referenced fonts
+ Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false);
+ if (referencedFontsCfg != null) {
+ localMatcher = FontManagerConfigurator.createFontsMatcher(
+ referencedFontsCfg, this.userAgent.getFactory().validateUserConfigStrictly());
+ }
+
List/*<AFPFontInfo>*/ fontList = new java.util.ArrayList();
- Configuration[] font = cfg.getChild("fonts").getChildren("font");
+ Configuration[] font = fonts.getChildren("font");
final String fontPath = null;
for (int i = 0; i < font.length; i++) {
AFPFontInfo afi = buildFont(font[i], fontPath);
if (afi != null) {
if (log.isDebugEnabled()) {
log.debug("Adding font " + afi.getAFPFont().getFontName());
- List/*<FontTriplet>*/ fontTriplets = afi.getFontTriplets();
- for (int j = 0; j < fontTriplets.size(); ++j) {
- FontTriplet triplet = (FontTriplet) fontTriplets.get(j);
+ }
+ List/*<FontTriplet>*/ fontTriplets = afi.getFontTriplets();
+ for (int j = 0; j < fontTriplets.size(); ++j) {
+ FontTriplet triplet = (FontTriplet) fontTriplets.get(j);
+ if (log.isDebugEnabled()) {
log.debug(" Font triplet "
+ triplet.getName() + ", "
+ triplet.getStyle() + ", "
+ triplet.getWeight());
}
+
+ if (referencedFontsMatcher.matches(triplet)
+ || (localMatcher != null && localMatcher.matches(triplet))) {
+ afi.getAFPFont().setEmbeddable(false);
+ break;
+ }
}
+
fontList.add(afi);
}
}
Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=821058&r1=821057&r2=821058&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Oct 2 15:31:14 2009
@@ -58,6 +58,10 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Fonts" dev="JM" type="add">
+ Added support for specifying referenced fonts per renderer in addition to the general
+ match list.
+ </action>
<action context="Renderers" dev="JM" type="add">
Added support for creating thumbnails or preview bitmaps of fixed size for PNG and TIFF
output.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org