try {
renderer.setupFontInfo(fontInfo);
+ // check that the "any,normal,400" font exists
+ if(!fontInfo.isSetupValid()) {
+ throw new SAXException(new FOPException("no default font defined by OutputConverter"));
+ }
renderer.startRenderer(outputStream);
} catch (IOException e) {
throw new SAXException(e);
public static final Integer ID_LINK = new Integer(0);
public static final Integer INTERNAL_LINK = new Integer(1); //resolved
public static final Integer EXTERNAL_LINK = new Integer(2);
- public static final Integer FONT_FAMILY = new Integer(3);
+ public static final Integer FONT_NAME = new Integer(3);
public static final Integer FONT_SIZE = new Integer(4);
- public static final Integer FONT_WEIGHT = new Integer(5);
- public static final Integer FONT_STYLE = new Integer(6);
public static final Integer COLOR = new Integer(7);
public static final Integer ID_AREA = new Integer(8);
public static final Integer BACKGROUND = new Integer(9);
public static final Integer PADDING_BEFORE = new Integer(21);
public static final Integer PADDING_AFTER = new Integer(22);
- public static final Integer FONT_STATE = new Integer(100);
-
static HashMap s_hmTraitInfo;
private static class TraitInfo {
new TraitInfo("internal-link", String.class));
s_hmTraitInfo.put(EXTERNAL_LINK,
new TraitInfo("external-link", String.class));
- s_hmTraitInfo.put(FONT_FAMILY,
+ s_hmTraitInfo.put(FONT_NAME,
new TraitInfo("font-family", String.class));
s_hmTraitInfo.put(FONT_SIZE,
new TraitInfo("font-size", Integer.class));
- s_hmTraitInfo.put(FONT_WEIGHT,
- new TraitInfo("font-weight", Integer.class));
- s_hmTraitInfo.put(FONT_STYLE,
- new TraitInfo("font-style", String.class));
s_hmTraitInfo.put(COLOR,
new TraitInfo("color", String.class));
s_hmTraitInfo.put(ID_AREA,
new TraitInfo("padding-before", Integer.class));
s_hmTraitInfo.put(PADDING_AFTER,
new TraitInfo("padding-after", Integer.class));
-
- s_hmTraitInfo.put(FONT_STATE,
- new TraitInfo("font-state", FontState.class));
}
public static String getTraitName(Object traitCode) {
import org.apache.fop.fo.TextInfo; // should be somewhere else probably...
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.FontInfo;
+import org.apache.fop.layout.FontMetric;
import org.apache.fop.layout.BorderAndPadding;
import org.apache.fop.layout.MarginProps;
import org.apache.fop.layout.MarginInlineProps;
}
- public FontState getFontState(FontInfo fontInfo) throws FOPException {
+ public FontState getFontState(FontInfo fontInfo) {
if (fontState == null) {
if (fontInfo == null) {
fontInfo = m_fontInfo;
}
String fontFamily = properties.get("font-family").getString();
String fontStyle = properties.get("font-style").getString();
- String fontWeight = properties.get("font-weight").getString();
+ String fw = properties.get("font-weight").getString();
+ int fontWeight = 400;
+ if(fw.equals("bolder")) {
+ // +100 from inherited
+ } else if(fw.equals("lighter")) {
+ // -100 from inherited
+ } else {
+ try {
+ fontWeight = Integer.parseInt(fw);
+ } catch(NumberFormatException nfe) {
+ }
+ }
+ fontWeight = ((int)fontWeight / 100) * 100;
+ if(fontWeight < 100) {
+ fontWeight = 100;
+ } else if(fontWeight > 900) {
+ fontWeight = 900;
+ }
+
// NOTE: this is incomplete. font-size may be specified with
// various kinds of keywords too
int fontSize = properties.get("font-size").getLength().mvalue();
int fontVariant = properties.get("font-variant").getEnum();
- // fontInfo is same for the whole FOP run but set in all FontState
- fontState = new FontState(fontInfo, fontFamily, fontStyle,
- fontWeight, fontSize, fontVariant);
+ String fname = fontInfo.fontLookup(fontFamily, fontStyle,
+ fontWeight);
+ FontMetric metrics = fontInfo.getMetricsFor(fname);
+ fontState = new FontState(fname, metrics, fontSize);
}
return fontState;
}
public TextInfo getTextLayoutProps(FontInfo fontInfo) {
if (textInfo == null) {
textInfo = new TextInfo();
- try {
textInfo.fs = getFontState(fontInfo);
- } catch (FOPException fopex) {
- /* log.error("Error setting FontState for characters: " +
- fopex.getMessage());*/
- // Now what should we do ???
- }
textInfo.color = properties.get("color").getColorType();
textInfo.verticalAlign =
BackgroundProps bProps = propMgr.getBackgroundProps();
// Common Font Properties
- //FontState fontState = propMgr.getFontState(structHandler.getFontInfo());
+ FontState fontState = propMgr.getFontState(structHandler.getFontInfo());
// Common Margin Properties-Inline
MarginInlineProps mProps = propMgr.getMarginInlineProps();
import java.util.HashMap;
-import org.apache.fop.apps.FOPException;
-
+/**
+ * The fontinfo for the layout and rendering of a fo document.
+ * This stores the list of available fonts that are setup by
+ * the renderer. The font name can be retrieved for the
+ * family style and weight.
+ * Currently font supported font-variant small-caps is not
+ * implemented.
+ */
public class FontInfo {
+ public static final String DEFAULT_FONT = "any,normal,400";
+ public static final int NORMAL = 400;
+ public static final int BOLD = 700;
+
HashMap usedFonts;
HashMap triplets; // look up a font-triplet to find a font-name
HashMap fonts; // look up a font-name to get a font (that implements FontMetric at least)
this.usedFonts = new HashMap();
}
+ public boolean isSetupValid() {
+ return triplets.containsKey(DEFAULT_FONT);
+ }
+
public void addFontProperties(String name, String family, String style,
- String weight) {
+ int weight) {
/*
* add the given family, style and weight as a lookup for the font
* with the given name
this.fonts.put(name, metrics);
}
+ /**
+ * Lookup a font.
+ * Locate the font name for a given familyi, style and weight.
+ * The font name can then be used as a key as it is unique for
+ * the associated document.
+ * This also adds the font to the list of used fonts.
+ */
public String fontLookup(String family, String style,
- String weight) throws FOPException {
- return fontLookup(createFontKey(family, style, weight));
- }
+ int weight) {
+ String key;
+ // first try given parameters
+ key = createFontKey(family, style, weight);
+ String f = (String)triplets.get(key);
+ if(f == null) {
+ // then adjust weight, favouring normal or bold
+ f = findAdjustWeight(family, style, weight);
+
+ // then try any family with orig weight
+ if(f == null) {
+ key = createFontKey("any", style, weight);
+ f = (String)triplets.get(key);
+ }
- public String fontLookup(String key) throws FOPException {
-
- String f = (String)this.triplets.get(key);
- if (f == null) {
- int i = key.indexOf(',');
- String s = "any" + key.substring(i);
- f = (String)this.triplets.get(s);
- if (f == null) {
- f = (String)this.triplets.get("any,normal,normal");
- if (f == null) {
- throw new FOPException("no default font defined by OutputConverter");
- }
- //log.error("defaulted font to any,normal,normal");
+ // then try any family with adjusted weight
+ if(f == null) {
+ f = findAdjustWeight(family, style, weight);
}
- //log.error("unknown font " + key
- // + " so defaulted font to any");
+
+ // then use default
+ f = (String)triplets.get(DEFAULT_FONT);
+
}
usedFonts.put(f, fonts.get(f));
return f;
}
- public boolean hasFont(String family, String style, String weight) {
+ /**
+ * Find a font with a given family and style by trying
+ * different font weights according to the spec.
+ */
+ public String findAdjustWeight(String family, String style,
+ int weight) {
+ String key;
+ String f = null;
+ int newWeight = weight;
+ if(newWeight < 400) {
+ while(f == null && newWeight > 0) {
+ newWeight -= 100;
+ key = createFontKey(family, style, newWeight);
+ f = (String)triplets.get(key);
+ }
+ } else if(newWeight == 500) {
+ key = createFontKey(family, style, 400);
+ f = (String)triplets.get(key);
+ } else if(newWeight > 500) {
+ while(f == null && newWeight < 1000) {
+ newWeight += 100;
+ key = createFontKey(family, style, newWeight);
+ f = (String)triplets.get(key);
+ }
+ newWeight = weight;
+ while(f == null && newWeight > 400) {
+ newWeight -= 100;
+ key = createFontKey(family, style, newWeight);
+ f = (String)triplets.get(key);
+ }
+ }
+ if(f == null) {
+ key = createFontKey(family, style, 400);
+ f = (String)triplets.get(key);
+ }
+
+ return f;
+ }
+
+ public boolean hasFont(String family, String style, int weight) {
String key = createFontKey(family, style, weight);
- return this.triplets.get(key) != null;
+ return this.triplets.containsKey(key);
}
/**
* Creates a key from the given strings
*/
public static String createFontKey(String family, String style,
- String weight) {
- int i;
-
- try {
- i = Integer.parseInt(weight);
- } catch (NumberFormatException e) {
- i = 0;
- }
-
- if (i > 600)
- weight = "bold";
- else if (i > 0)
- weight = "normal";
-
+ int weight) {
return family + "," + style + "," + weight;
}
return this.fonts;
}
+ /**
+ * This is used by the renderers to retrieve all the
+ * fonts used in the document.
+ * This is for embedded font or creating a list of used fonts.
+ */
public HashMap getUsedFonts() {
return this.usedFonts;
}
- public FontMetric getMetricsFor(String fontName) throws FOPException {
+ public FontMetric getMetricsFor(String fontName) {
usedFonts.put(fontName, fonts.get(fontName));
return (FontMetric)fonts.get(fontName);
}
-
}
+
import java.util.HashMap;
-import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.properties.FontVariant;
import org.apache.fop.render.pdf.CodePointMapping;
public class FontState {
- private FontInfo _fontInfo;
private String _fontName;
private int _fontSize;
private String _fontFamily;
private String _fontStyle;
- private String _fontWeight;
+ private int _fontWeight;
private int _fontVariant;
private FontMetric _metric;
private static HashMap EMPTY_HASHMAP = new HashMap();
- public FontState(FontInfo fontInfo, String fontFamily, String fontStyle,
- String fontWeight, int fontSize,
- int fontVariant) throws FOPException {
- _fontInfo = fontInfo;
- _fontFamily = fontFamily;
- _fontStyle = fontStyle;
- _fontWeight = fontWeight;
+ public FontState(String key, FontMetric met, int fontSize) {
_fontSize = fontSize;
- _fontName = fontInfo.fontLookup(fontFamily, fontStyle, fontWeight);
- _metric = fontInfo.getMetricsFor(_fontName);
- _fontVariant = fontVariant;
+ _fontName = key;
+ _metric = met;
}
public int getAscender() {
return _fontSize;
}
- public String getFontWeight() {
- return _fontWeight;
- }
-
- public String getFontFamily() {
- return _fontFamily;
- }
-
- public String getFontStyle() {
- return _fontStyle;
- }
-
- public int getFontVariant() {
- return _fontVariant;
- }
-
- public FontInfo getFontInfo() {
- return _fontInfo;
- }
-
public int getXHeight() {
return _metric.getXHeight(_fontSize) / 1000;
}
curWordArea.info.blOffset = true;
curWordArea.setWord(str);
- //curWordArea.addTrait(new Trait(Trait.FONT_STATE, textInfo.fs));
- curWordArea.addTrait(Trait.FONT_STATE, textInfo.fs);
+ curWordArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
+ curWordArea.addTrait(Trait.FONT_SIZE, new Integer(textInfo.fs.getFontSize()));
return curWordArea;
}
curWordArea.setWord(str);
// curWordArea.addTrait(new Trait(Trait.FONT_STATE, textInfo.fs));
- curWordArea.addTrait(Trait.FONT_STATE, textInfo.fs);
+ //curWordArea.addTrait(Trait.FONT_STATE, textInfo.fs);
return curWordArea;
}
// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
/* any is treated as serif */
- fontInfo.addFontProperties("F5", "any", "normal", "normal");
- fontInfo.addFontProperties("F6", "any", "italic", "normal");
- fontInfo.addFontProperties("F6", "any", "oblique", "normal");
- fontInfo.addFontProperties("F7", "any", "normal", "bold");
- fontInfo.addFontProperties("F8", "any", "italic", "bold");
- fontInfo.addFontProperties("F8", "any", "oblique", "bold");
-
- fontInfo.addFontProperties("F1", "sans-serif", "normal", "normal");
- fontInfo.addFontProperties("F2", "sans-serif", "oblique", "normal");
- fontInfo.addFontProperties("F2", "sans-serif", "italic", "normal");
- fontInfo.addFontProperties("F3", "sans-serif", "normal", "bold");
- fontInfo.addFontProperties("F4", "sans-serif", "oblique", "bold");
- fontInfo.addFontProperties("F4", "sans-serif", "italic", "bold");
- fontInfo.addFontProperties("F5", "serif", "normal", "normal");
- fontInfo.addFontProperties("F6", "serif", "oblique", "normal");
- fontInfo.addFontProperties("F6", "serif", "italic", "normal");
- fontInfo.addFontProperties("F7", "serif", "normal", "bold");
- fontInfo.addFontProperties("F8", "serif", "oblique", "bold");
- fontInfo.addFontProperties("F8", "serif", "italic", "bold");
- fontInfo.addFontProperties("F9", "monospace", "normal", "normal");
- fontInfo.addFontProperties("F10", "monospace", "oblique", "normal");
- fontInfo.addFontProperties("F10", "monospace", "italic", "normal");
- fontInfo.addFontProperties("F11", "monospace", "normal", "bold");
- fontInfo.addFontProperties("F12", "monospace", "oblique", "bold");
- fontInfo.addFontProperties("F12", "monospace", "italic", "bold");
-
- fontInfo.addFontProperties("F1", "Helvetica", "normal", "normal");
- fontInfo.addFontProperties("F2", "Helvetica", "oblique", "normal");
- fontInfo.addFontProperties("F2", "Helvetica", "italic", "normal");
- fontInfo.addFontProperties("F3", "Helvetica", "normal", "bold");
- fontInfo.addFontProperties("F4", "Helvetica", "oblique", "bold");
- fontInfo.addFontProperties("F4", "Helvetica", "italic", "bold");
- fontInfo.addFontProperties("F5", "Times", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times", "italic", "bold");
- fontInfo.addFontProperties("F9", "Courier", "normal", "normal");
- fontInfo.addFontProperties("F10", "Courier", "oblique", "normal");
- fontInfo.addFontProperties("F10", "Courier", "italic", "normal");
- fontInfo.addFontProperties("F11", "Courier", "normal", "bold");
- fontInfo.addFontProperties("F12", "Courier", "oblique", "bold");
- fontInfo.addFontProperties("F12", "Courier", "italic", "bold");
- fontInfo.addFontProperties("F13", "Symbol", "normal", "normal");
- fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal");
+ fontInfo.addFontProperties("F5", "any", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "any", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "any", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "any", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "any", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "any", "oblique", FontInfo.BOLD);
+
+ fontInfo.addFontProperties("F1", "sans-serif", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F3", "sans-serif", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "serif", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "serif", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "serif", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "serif", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F9", "monospace", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F11", "monospace", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "italic", FontInfo.BOLD);
+
+ fontInfo.addFontProperties("F1", "Helvetica", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F3", "Helvetica", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "Times", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F9", "Courier", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F11", "Courier", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F13", "Symbol", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", FontInfo.NORMAL);
// Custom type 1 fonts step 2/2
- // fontInfo.addFontProperties("F15", "OMEP", "normal", "normal");
- // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal");
- // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold");
+ // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
+ // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL);
+ // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
/* for compatibility with PassiveTex */
- fontInfo.addFontProperties("F5", "Times-Roman", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times-Roman", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times-Roman", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times-Roman", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times-Roman", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times-Roman", "italic", "bold");
- fontInfo.addFontProperties("F5", "Times Roman", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times Roman", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times Roman", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times Roman", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times Roman", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times Roman", "italic", "bold");
+ fontInfo.addFontProperties("F5", "Times-Roman", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times-Roman", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "Times Roman", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times Roman", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "italic", FontInfo.BOLD);
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
- "normal", "normal");
+ "normal", FontInfo.NORMAL);
}
}
-
-
-
-
-
-
-
-
-
// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
/* any is treated as serif */
- fontInfo.addFontProperties("F5", "any", "normal", "normal");
- fontInfo.addFontProperties("F6", "any", "italic", "normal");
- fontInfo.addFontProperties("F6", "any", "oblique", "normal");
- fontInfo.addFontProperties("F7", "any", "normal", "bold");
- fontInfo.addFontProperties("F8", "any", "italic", "bold");
- fontInfo.addFontProperties("F8", "any", "oblique", "bold");
-
- fontInfo.addFontProperties("F1", "sans-serif", "normal", "normal");
- fontInfo.addFontProperties("F2", "sans-serif", "oblique", "normal");
- fontInfo.addFontProperties("F2", "sans-serif", "italic", "normal");
- fontInfo.addFontProperties("F3", "sans-serif", "normal", "bold");
- fontInfo.addFontProperties("F4", "sans-serif", "oblique", "bold");
- fontInfo.addFontProperties("F4", "sans-serif", "italic", "bold");
- fontInfo.addFontProperties("F5", "serif", "normal", "normal");
- fontInfo.addFontProperties("F6", "serif", "oblique", "normal");
- fontInfo.addFontProperties("F6", "serif", "italic", "normal");
- fontInfo.addFontProperties("F7", "serif", "normal", "bold");
- fontInfo.addFontProperties("F8", "serif", "oblique", "bold");
- fontInfo.addFontProperties("F8", "serif", "italic", "bold");
- fontInfo.addFontProperties("F9", "monospace", "normal", "normal");
- fontInfo.addFontProperties("F10", "monospace", "oblique", "normal");
- fontInfo.addFontProperties("F10", "monospace", "italic", "normal");
- fontInfo.addFontProperties("F11", "monospace", "normal", "bold");
- fontInfo.addFontProperties("F12", "monospace", "oblique", "bold");
- fontInfo.addFontProperties("F12", "monospace", "italic", "bold");
-
- fontInfo.addFontProperties("F1", "Helvetica", "normal", "normal");
- fontInfo.addFontProperties("F2", "Helvetica", "oblique", "normal");
- fontInfo.addFontProperties("F2", "Helvetica", "italic", "normal");
- fontInfo.addFontProperties("F3", "Helvetica", "normal", "bold");
- fontInfo.addFontProperties("F4", "Helvetica", "oblique", "bold");
- fontInfo.addFontProperties("F4", "Helvetica", "italic", "bold");
- fontInfo.addFontProperties("F5", "Times", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times", "italic", "bold");
- fontInfo.addFontProperties("F9", "Courier", "normal", "normal");
- fontInfo.addFontProperties("F10", "Courier", "oblique", "normal");
- fontInfo.addFontProperties("F10", "Courier", "italic", "normal");
- fontInfo.addFontProperties("F11", "Courier", "normal", "bold");
- fontInfo.addFontProperties("F12", "Courier", "oblique", "bold");
- fontInfo.addFontProperties("F12", "Courier", "italic", "bold");
- fontInfo.addFontProperties("F13", "Symbol", "normal", "normal");
- fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal");
+ fontInfo.addFontProperties("F5", "any", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "any", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "any", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "any", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "any", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "any", "oblique", FontInfo.BOLD);
+
+ fontInfo.addFontProperties("F1", "sans-serif", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F3", "sans-serif", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "serif", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "serif", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "serif", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "serif", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F9", "monospace", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F11", "monospace", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "italic", FontInfo.BOLD);
+
+ fontInfo.addFontProperties("F1", "Helvetica", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F3", "Helvetica", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "Times", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F9", "Courier", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F11", "Courier", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F13", "Symbol", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", FontInfo.NORMAL);
// Custom type 1 fonts step 2/2
- // fontInfo.addFontProperties("F15", "OMEP", "normal", "normal");
- // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal");
- // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold");
+ // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
+ // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL);
+ // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
/* for compatibility with PassiveTex */
- fontInfo.addFontProperties("F5", "Times-Roman", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times-Roman", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times-Roman", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times-Roman", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times-Roman", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times-Roman", "italic", "bold");
- fontInfo.addFontProperties("F5", "Times Roman", "normal", "normal");
- fontInfo.addFontProperties("F6", "Times Roman", "oblique", "normal");
- fontInfo.addFontProperties("F6", "Times Roman", "italic", "normal");
- fontInfo.addFontProperties("F7", "Times Roman", "normal", "bold");
- fontInfo.addFontProperties("F8", "Times Roman", "oblique", "bold");
- fontInfo.addFontProperties("F8", "Times Roman", "italic", "bold");
+ fontInfo.addFontProperties("F5", "Times-Roman", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times-Roman", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "italic", FontInfo.BOLD);
+ fontInfo.addFontProperties("F5", "Times Roman", "normal", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "oblique", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "italic", FontInfo.NORMAL);
+ fontInfo.addFontProperties("F7", "Times Roman", "normal", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "oblique", FontInfo.BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "italic", FontInfo.BOLD);
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
- "normal", "normal");
+ "normal", FontInfo.NORMAL);
/* Add configured fonts */
addConfiguredFonts(fontInfo, 15);
for (int c = 0; c < triplets.size(); c++) {
FontTriplet triplet = (FontTriplet)triplets.get(c);
+ int weight = 400;
+ try {
+ weight = Integer.parseInt(triplet.getWeight());
+ weight = ((int)weight/100) * 100;
+ if(weight < 100) weight = 100;
+ if(weight > 900) weight = 900;
+ } catch(NumberFormatException nfe) {
+
+ }
fontInfo.addFontProperties(internalName,
triplet.getName(),
triplet.getStyle(),
- triplet.getWeight());
+ weight);
}
}
} catch (Exception ex) {
import org.apache.fop.area.inline.*;
import org.apache.fop.area.inline.Character;
import org.apache.fop.layout.FontState;
+import org.apache.fop.layout.FontInfo;
+import org.apache.fop.layout.FontMetric;
import org.w3c.dom.Document;
currentStream.add("1 0 0 -1 0 " +
(int) Math.round(pageHeight / 1000) + " cm\n");
//currentStream.add("BT\n");
+ currentFontName = "";
Page p = page.getPage();
renderPageAreas(p);
public void renderWord(Word word) {
StringBuffer pdf = new StringBuffer();
- FontState fs = null;
-
- fs = (FontState)word.getTrait(Trait.FONT_STATE);
- String name = fs.getFontName();
- int size = fs.getFontSize();
+ String name = (String)word.getTrait(Trait.FONT_NAME);
+ int size = ((Integer)word.getTrait(Trait.FONT_SIZE)).intValue();
// This assumes that *all* CIDFonts use a /ToUnicode mapping
- Font f = (Font)fs.getFontInfo().getFonts().get(name);
+ Font f = (Font)fontInfo.getFonts().get(name);
boolean useMultiByte = f.isMultiByte();
// String startText = useMultiByte ? "<FEFF" : "(";
String s = word.getWord();
+ FontMetric metrics = fontInfo.getMetricsFor(name);
+ FontState fs = new FontState(name, metrics, size);
escapeText(s, fs, useMultiByte, pdf);
pdf.append(endText);
context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream);
context.setProperty(PDFXMLHandler.PDF_XPOS, new Integer(currentBlockIPPosition + (int)pos.getX()));
context.setProperty(PDFXMLHandler.PDF_YPOS, new Integer(currentBPPosition + (int)pos.getY()));
- FontState fs = null;
- try {
- fs = new FontState(fontInfo, "Helvetica", "",
- "", 12 * 1000, 0);
- } catch (org.apache.fop.apps.FOPException fope) {
- fope.printStackTrace();
- }
-
- context.setProperty(PDFXMLHandler.PDF_FONT_STATE, fs);
+ context.setProperty(PDFXMLHandler.PDF_FONT_INFO, fontInfo);
context.setProperty(PDFXMLHandler.PDF_FONT_NAME, currentFontName);
context.setProperty(PDFXMLHandler.PDF_FONT_SIZE, new Integer(currentFontSize));
context.setProperty(PDFXMLHandler.PDF_WIDTH, new Integer((int)pos.getWidth()));
import org.apache.fop.pdf.*;
import org.apache.fop.svg.*;
import org.apache.fop.svg.SVGUserAgent;
-import org.apache.fop.layout.FontState;
+import org.apache.fop.layout.FontInfo;
import org.apache.batik.dom.util.DOMUtilities;
public static final String PDF_STREAM = "pdfStream";
public static final String PDF_WIDTH = "width";
public static final String PDF_HEIGHT = "height";
-public static final String PDF_FONT_STATE = "fontState";
+public static final String PDF_FONT_INFO = "fontInfo";
public static final String PDF_FONT_NAME = "fontName";
public static final String PDF_FONT_SIZE = "fontSize";
public static final String PDF_XPOS = "xpos";
pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
pdfi.width = ((Integer)context.getProperty(PDF_WIDTH)).intValue();
pdfi.height = ((Integer)context.getProperty(PDF_HEIGHT)).intValue();
- pdfi.fs = (FontState)context.getProperty(PDF_FONT_STATE);
+ pdfi.fi = (FontInfo)context.getProperty(PDF_FONT_INFO);
pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME);
pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue();
pdfi.currentXPosition = ((Integer)context.getProperty(PDF_XPOS)).intValue();
public PDFStream currentStream;
int width;
int height;
- FontState fs;
+ FontInfo fi;
String currentFontName;
int currentFontSize;
int currentXPosition;
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(ua);
- PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fs);
+ PDFTextElementBridge tBridge = new PDFTextElementBridge(pdfInfo.fi);
ctx.putBridge(tBridge);
PDFAElementBridge aBridge = new PDFAElementBridge();
+ PDFNumber.doubleOut(vals[5]) + " cm\n");
}
- PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fs, pdfInfo.pdfDoc,
+ PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fi, pdfInfo.pdfDoc,
pdfInfo.pdfPage, pdfInfo.pdfPage.referencePDF(), pdfInfo.currentFontName,
pdfInfo.currentFontSize,
pdfInfo.currentXPosition,
import org.apache.fop.render.xml.*;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.FontState;
+import org.apache.fop.layout.FontMetric;
import org.apache.fop.fo.FOUserAgent;
import org.apache.avalon.framework.logger.ConsoleLogger;
Character ch =
new Character(getString((Element) obj).charAt(0));
addTraits((Element) obj, ch);
- try {
- currentFontState =
- new FontState(fontInfo, "sans-serif", "normal",
- "normal", 12000, 0);
- } catch (FOPException e) {
- e.printStackTrace();
- }
+ String fname = fontInfo.fontLookup("sans-serif", "normal", FontInfo.NORMAL);
+ FontMetric metrics = fontInfo.getMetricsFor(fname);
+ currentFontState =
+ new FontState(fname, metrics, 12000);
ch.setWidth(currentFontState.width(ch.getChar()));
ch.setOffset(currentFontState.getCapHeight());
list.add(leader);
}
} else if (obj.getNodeName().equals("word")) {
- try {
- currentFontState =
- new FontState(fontInfo, "sans-serif", "normal",
- "normal", 12000, 0);
- } catch (FOPException e) {
- e.printStackTrace();
- }
+ String fname = fontInfo.fontLookup("sans-serif", "normal", FontInfo.NORMAL);
+ FontMetric metrics = fontInfo.getMetricsFor(fname);
+ currentFontState =
+ new FontState(fname, metrics, 12000);
Word word = getWord((Element) obj);
- word.addTrait(Trait.FONT_STATE, currentFontState);
+ word.addTrait(Trait.FONT_NAME, fname);
+ word.addTrait(Trait.FONT_SIZE, new Integer(12000));
+
if (word != null) {
list.add(word);
}