Browse Source

Bugfix: restored support for characters not in a font's standard encoding when PostScript is generated with resource optimization turned off.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@742346 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_0
Jeremias Maerki 15 years ago
parent
commit
b8219e854f

+ 20
- 0
src/java/org/apache/fop/fonts/SingleByteFont.java View File

@@ -19,8 +19,10 @@

package org.apache.fop.fonts;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -218,6 +220,24 @@ public class SingleByteFont extends CustomFont {
}
}

/**
* Makes all unencoded characters available through additional encodings. This method
* is used in cases where the fonts need to be encoded in the target format before
* all text of the document is processed (for example in PostScript when resource optimization
* is disabled).
*/
public void encodeAllUnencodedCharacters() {
if (this.unencodedCharacters != null) {
Set sortedKeys = new java.util.TreeSet(this.unencodedCharacters.keySet());
Iterator iter = sortedKeys.iterator();
while (iter.hasNext()) {
Character ch = (Character)iter.next();
char mapped = mapChar(ch.charValue());
assert mapped != Typeface.NOT_FOUND;
}
}
}

/**
* Indicates whether the encoding has additional encodings besides the primary encoding.
* @return true if there are additional encodings.

+ 28
- 3
src/java/org/apache/fop/render/ps/PSFontUtils.java View File

@@ -57,7 +57,9 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
protected static Log log = LogFactory.getLog(PSFontUtils.class);

/**
* Generates the PostScript code for the font dictionary.
* Generates the PostScript code for the font dictionary. This method should only be
* used if no "resource optimization" is performed, i.e. when the fonts are not embedded
* in a second pass.
* @param gen PostScript generator to use for output
* @param fontInfo available fonts
* @return a Map of PSResource instances representing all defined fonts (key: font key)
@@ -65,11 +67,13 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
*/
public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo)
throws IOException {
return writeFontDict(gen, fontInfo, fontInfo.getFonts());
return writeFontDict(gen, fontInfo, fontInfo.getFonts(), true);
}

/**
* Generates the PostScript code for the font dictionary.
* Generates the PostScript code for the font dictionary. This method assumes all used
* fonts and characters are known, i.e. when PostScript is generated with resource
* optimization turned on.
* @param gen PostScript generator to use for output
* @param fontInfo available fonts
* @param fonts the set of fonts to work with
@@ -78,6 +82,21 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
*/
public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts)
throws IOException {
return writeFontDict(gen, fontInfo, fonts, false);
}

/**
* Generates the PostScript code for the font dictionary.
* @param gen PostScript generator to use for output
* @param fontInfo available fonts
* @param fonts the set of fonts to work with
* @param encodeAllCharacters true if all characters shall be encoded using additional,
* generated encodings.
* @return a Map of PSResource instances representing all defined fonts (key: font key)
* @throws IOException in case of an I/O problem
*/
private static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts,
boolean encodeAllCharacters) throws IOException {
gen.commentln("%FOPBeginFontDict");

Map fontResources = new java.util.HashMap();
@@ -91,6 +110,11 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {

if (tf instanceof SingleByteFont) {
SingleByteFont sbf = (SingleByteFont)tf;

if (encodeAllCharacters) {
sbf.encodeAllUnencodedCharacters();
}

for (int i = 0, c = sbf.getAdditionalEncodingCount(); i < c; i++) {
SingleByteEncoding encoding = sbf.getAdditionalEncoding(i);
defineEncoding(gen, encoding);
@@ -110,6 +134,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
ResourceTracker tracker = gen.getResourceTracker();

if (!tracker.isResourceSupplied(WINANSI_ENCODING_RESOURCE)) {
//Only out Base 14 fonts still use that
defineWinAnsiEncoding(gen);
}
gen.commentln("%FOPBeginFontReencode");

Loading…
Cancel
Save