Browse Source

FOP-2608: Improve OTF to Type1 full embedding

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1744593 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_2
Simon Steiner 8 years ago
parent
commit
b5d27aef6d

+ 1
- 1
fop-core/src/main/java/org/apache/fop/fonts/CFFToType1Font.java View File

@@ -52,7 +52,7 @@ public class CFFToType1Font extends MultiByteFont {
if (!(f instanceof CFFType1Font)) {
throw new IOException(getEmbedFileURI() + ": only OTF CFF Type1 font can be converted to Type1");
}
byte[] t1 = new Type1FontFormatter(cidSet.getGlyphs()).format((CFFType1Font) f);
byte[] t1 = new Type1FontFormatter(cidSet.getGlyphs(), eventListener).format((CFFType1Font) f);
PFBData pfb = new PFBParser().parsePFB(new ByteArrayInputStream(t1));
ByteArrayOutputStream s1 = new ByteArrayOutputStream();
s1.write(pfb.getHeaderSegment());

+ 4
- 0
fop-core/src/main/java/org/apache/fop/fonts/FontEventAdapter.java View File

@@ -66,6 +66,10 @@ public class FontEventAdapter implements FontEventListener {
getEventProducer().fontDirectoryNotFound(source, dir);
}

public void fontType1MaxGlyphs(Object source, String fontName) {
getEventProducer().fontType1MaxGlyphs(source, fontName);
}

/** {@inheritDoc} */
public void svgTextStrokedAsShapes(Object source, String fontFamily) {
getEventProducer().svgTextStrokedAsShapes(source, fontFamily);

+ 2
- 0
fop-core/src/main/java/org/apache/fop/fonts/FontEventListener.java View File

@@ -61,4 +61,6 @@ public interface FontEventListener {
* @param fontFamily the family name of the font that is being stroked
*/
void svgTextStrokedAsShapes(Object source, String fontFamily);

void fontType1MaxGlyphs(Object source, String fontName);
}

+ 8
- 0
fop-core/src/main/java/org/apache/fop/fonts/FontEventProducer.java View File

@@ -86,4 +86,12 @@ public interface FontEventProducer extends EventProducer {
* @event.severity WARN
*/
void svgTextStrokedAsShapes(Object source, String fontFamily);

/**
* A method to warn the user that the font has too many glyphs
* @param source
* @param fontName
* @event.severity ERROR
*/
void fontType1MaxGlyphs(Object source, String fontName);
}

+ 15
- 5
fop-core/src/main/java/org/apache/fop/render/ps/Type1FontFormatter.java View File

@@ -28,6 +28,8 @@ import org.apache.fontbox.cff.CFFType1Font;
import org.apache.fontbox.cff.DataOutput;
import org.apache.fontbox.cff.Type1FontUtil;

import org.apache.fop.fonts.FontEventListener;

/**
* This class represents a formatter for a given Type1 font.
* author Villu Ruusmann
@@ -35,9 +37,11 @@ import org.apache.fontbox.cff.Type1FontUtil;
*/
public final class Type1FontFormatter {
private Map<Integer, Integer> gids;
private FontEventListener eventListener;

public Type1FontFormatter(Map<Integer, Integer> gids) {
public Type1FontFormatter(Map<Integer, Integer> gids, FontEventListener eventListener) {
this.gids = gids;
this.eventListener = eventListener;
}

/**
@@ -108,13 +112,19 @@ public final class Type1FontFormatter {
output.println("/StrokeWidth " + font.getTopDict().get("StrokeWidth")
+ " def");

output.println("/Encoding " + gids.size() + " array");
output.println("0 1 " + (gids.size() - 1) + " {1 index exch /.notdef put} for");

int max = 0;
StringBuilder sb = new StringBuilder();
for (Map.Entry<Integer, Integer> gid : gids.entrySet()) {
String name = font.getCharset().getNameForGID(gid.getKey());
output.println("dup " + gid.getValue() + " /" + name + " put");
sb.append(String.format("dup %d /%s put", gid.getValue(), name)).append('\n');
max = Math.max(max, gid.getValue());
}
if (max > 255) {
eventListener.fontType1MaxGlyphs(this, font.getName());
}
output.println("/Encoding " + (max + 1) + " array");
output.println("0 1 " + max + " {1 index exch /.notdef put} for");
output.print(sb.toString());
output.println("readonly def");

output.println("currentdict end");

+ 3
- 0
fop-core/src/main/java/org/apache/fop/tools/fontlist/FontListMain.java View File

@@ -155,6 +155,9 @@ public final class FontListMain {
// ignore
}

public void fontType1MaxGlyphs(Object source, String fontName) {
//ignore
}
};

FontListGenerator listGenerator = new FontListGenerator();

+ 1
- 0
fop-core/src/main/resources/org/apache/fop/fonts/FontEventProducer.xml View File

@@ -22,4 +22,5 @@
<message key="glyphNotAvailable">Glyph "{ch}" (0x{ch,hex}[, {ch,glyph-name}]) not available in font "{fontName}".</message>
<message key="fontDirectoryNotFound">The font directory {dir} could not be found.</message>
<message key="svgTextStrokedAsShapes">The SVG text for font {fontFamily} will be stroked as shapes.</message>
<message key="fontType1MaxGlyphs">Font "{fontName}" encoding has more than 256 glyphs may cause wrong output, enable font subsetting or disable 'embed-as-type1'.</message>
</catalogue>

Loading…
Cancel
Save