*/
public static final int FONT_FACTOR = (1000 * 1000) / FONT_SIZE;
-
/**
* The width of all 256 character, if requested
*/
private FontMetrics fmt = null;
/**
- * Component parent is needed to have an AWT reference from which to get
- * the font metrics
+ * Temp graphics object needed to get the font metrics
*/
- Component parent;
+ Graphics2D graphics;
/**
* Constructs a new Font-metrics.
- * @param parent an AWT component - this is needed so
+ * @param parent an temp graphics object - this is needed so
* that we can get an instance of
* java.awt.FontMetrics
*/
- public AWTFontMetrics(Component parent) {
- this.parent = parent;
+ public AWTFontMetrics(Graphics2D graphics) {
+ this.graphics = graphics;
}
/**
*/
public int getAscender(String family, int style, int size) {
setFont(family, style, size);
- return (FONT_FACTOR * fmt.getAscent());
+ //return (int)(FONT_FACTOR * fmt.getAscent());
+
+ // workaround for sun bug on FontMetric.getAscent()
+ // http://developer.java.sun.com/developer/bugParade/bugs/4399887.html
+ int realAscent = fmt.getAscent() - (fmt.getDescent() + fmt.getLeading());
+ return FONT_FACTOR * realAscent;
}
* The size of a capital letter measured from the font's baseline
*/
public int getCapHeight(String family, int style, int size) {
- setFont(family, style, size);
- return (FONT_FACTOR * fmt.getAscent());
+ // currently just gets Ascent value but maybe should use
+ // getMaxAcent() at some stage
+ return getAscender(family, style, size);
}
/**
Rectangle2D rect;
TextLayout layout;
int s = (int)(size / 1000f);
- Graphics2D g;
if (f1 == null) {
f1 = new Font(family, style, s);
- fmt = parent.getFontMetrics(f1);
+ fmt = graphics.getFontMetrics(f1);
changed = true;
} else {
if ((this.style != style) || !this.family.equals(family) ||
f1 = f1.deriveFont(style, (float) s);
} else
f1 = new Font(family, style, s);
- fmt = parent.getFontMetrics(f1);
+ fmt = graphics.getFontMetrics(f1);
changed = true;
}
// else the font is unchanged from last time
}
if (changed) {
- g = (Graphics2D) parent.getGraphics();
- layout = new TextLayout("m", f1, g.getFontRenderContext());
+ layout = new TextLayout("m", f1, graphics.getFontRenderContext());
rect = layout.getBounds();
xHeight = (int) rect.getHeight();
}
*/
protected String currentFontName;
-
- /**
- * The parent component, used to set up the font.
- * This is needed as FontSetup needs a live AWT component
- * in order to generate valid font measures.
- */
- protected Component parent;
-
-
-
/**
* The current font size in millipoints
*/
protected float currentGreen = 0;
protected float currentBlue = 0;
+ /**
+ * The parent component, used to set up the font.
+ * This is needed as FontSetup needs a live AWT component
+ * in order to generate valid font measures.
+ */
+ protected Component parent;
+
/**
* The current vertical position in millipoints from bottom
*/
/** options */
protected Hashtable options;
-
+
/** set up renderer options */
public void setOptions(Hashtable options) {
this.options = options;
}
-
+
public AWTRenderer(Translator aRes) {
res = aRes;
}
return new Rectangle2D.Double(currentAreaContainerXPosition,
currentYPosition, a.getAllocationWidth(), a.getHeight());
}
-
+/*
public void renderBlockArea(BlockArea area) {
doFrame(area);
Enumeration e = area.getChildren().elements();
b.render(this);
}
}
+*/
+ public void renderBlockArea(BlockArea area) {
+ this.currentYPosition -= (area.getPaddingTop() + area.getBorderTopWidth());
+ doFrame(area);
+ Enumeration e = area.getChildren().elements();
+ while (e.hasMoreElements()) {
+ org.apache.fop.layout.Box b =
+ (org.apache.fop.layout.Box) e.nextElement();
+ b.render(this);
+ }
+ this.currentYPosition -= (area.getPaddingBottom() + area.getBorderBottomWidth());
+ }
+
public void setupFontInfo(FontInfo fontInfo) {
- FontSetup.setup(fontInfo, parent);
+ // create a temp Image to test font metrics on
+ BufferedImage fontImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
+ FontSetup.setup(fontInfo, fontImage.createGraphics());
}
public void renderDisplaySpace(DisplaySpace space) {
public void renderImageArea(ImageArea area) {
- int x = currentAreaContainerXPosition + area.getXOffset();
+ int x = currentAreaContainerXPosition +
+ area.getXOffset();
+
int y = currentYPosition;
int w = area.getContentWidth();
int h = area.getHeight();
area.getFontState().getFontInfo().getMetricsFor(name);
} catch (FOPException iox) {
mapper = new FontMetricsMapper("MonoSpaced",
- java.awt.Font.PLAIN, parent);
+ java.awt.Font.PLAIN, graphics);
}
if ((!name.equals(this.currentFontName)) ||
int bl = this.currentYPosition;
- String s = area.getText();
+ String s;// = area.getText();
+ if (area.getPageNumberID() != null) { // this text is a page number, so resolve it
+ s = tree.getIDReferences().getPageNumber(area.getPageNumberID());
+ if (s == null) {
+ s = "";
+ }
+ } else {
+ s = area.getText();
+ }
+
Color oldColor = graphics.getColor();
java.awt.Font oldFont = graphics.getFont();
java.awt.Font f = mapper.getFont(size);
}
graphics.setColor(saveColor);
- FontRenderContext newContext = graphics.getFontRenderContext();
AttributedString ats = new AttributedString(s);
ats.addAttribute(TextAttribute.FONT, f);
if (underlined) {
}
public void renderLineArea(LineArea area) {
+
int rx = this.currentAreaContainerXPosition + area.getStartIndent();
int ry = this.currentYPosition;
int w = area.getContentWidth();
Page page = (Page) tree.getPages().elementAt(pageIndex);
PageFormat pageFormat = new PageFormat();
Paper paper = new Paper();
- paper.setImageableArea(0, 0, page.getWidth() / 1000d,
- page.getHeight() / 1000d);
- paper.setSize(page.getWidth() / 1000d, page.getHeight() / 1000d);
- pageFormat.setPaper(paper);
+ double width = page.getWidth();
+ double height = page.getHeight();
+
+ // if the width is greater than the height assume lanscape mode
+ // and swap the width and height values in the paper format
+ if(width > height)
+ {
+ paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
+ paper.setSize(height / 1000d, width / 1000d);
+ pageFormat.setOrientation(PageFormat.LANDSCAPE);
+ }
+ else
+ {
+ paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
+ paper.setSize(width / 1000d, height / 1000d);
+ pageFormat.setOrientation(PageFormat.PORTRAIT);
+ }
+ pageFormat.setPaper(paper);
return pageFormat;
}
MessageHandler.errorln("AWTRenderer: renderImage(): " +
ex.getMessage());
}
+
}*/
public void renderForeignObjectArea(ForeignObjectArea area) {
area.getObject().render(this);
}
+
protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;
/**
// Java
import java.util.Enumeration;
import java.util.Hashtable;
-import java.awt.Component;
+import java.awt.Graphics2D;
import java.awt.Font;
* that we can get an instance of
* java.awt.FontMetrics
*/
- public FontMetricsMapper(String family, int style, Component parent) {
+ public FontMetricsMapper(String family, int style, Graphics2D graphics) {
this.family = family;
this.style = style;
if (metric == null)
- metric = new AWTFontMetrics(parent);
+ metric = new AWTFontMetrics(graphics);
}
/**
import java.util.Enumeration;
import java.util.Hashtable;
import java.awt.Font;
-import java.awt.Component;
+import java.awt.Graphics2D;
/**
* sets up the AWT fonts. It is similar to
* @param parent needed, since a live AWT component is needed
* to get a valid java.awt.FontMetrics object
*/
- public static void setup(FontInfo fontInfo, Component parent) {
+ public static void setup(FontInfo fontInfo, Graphics2D graphics) {
FontMetricsMapper metric;
int normal, bold, bolditalic, italic;
italic = java.awt.Font.ITALIC;
bolditalic = java.awt.Font.BOLD + java.awt.Font.ITALIC;
- metric = new FontMetricsMapper("SansSerif", normal, parent);
+ metric = new FontMetricsMapper("SansSerif", normal, graphics);
// --> goes to F1
fontInfo.addMetrics("F1", metric);
- metric = new FontMetricsMapper("SansSerif",italic, parent);
+ metric = new FontMetricsMapper("SansSerif",italic, graphics);
// --> goes to F2
fontInfo.addMetrics("F2", metric);
- metric = new FontMetricsMapper("SansSerif", bold, parent);
+ metric = new FontMetricsMapper("SansSerif", bold, graphics);
// --> goes to F3
fontInfo.addMetrics("F3", metric);
- metric = new FontMetricsMapper("SansSerif", bolditalic, parent);
+ metric = new FontMetricsMapper("SansSerif", bolditalic, graphics);
// --> goes to F4
fontInfo.addMetrics("F4", metric);
- metric = new FontMetricsMapper("Serif", normal, parent);
+ metric = new FontMetricsMapper("Serif", normal, graphics);
// --> goes to F5
fontInfo.addMetrics("F5", metric);
- metric = new FontMetricsMapper("Serif", italic, parent);
+ metric = new FontMetricsMapper("Serif", italic, graphics);
// --> goes to F6
fontInfo.addMetrics("F6", metric);
- metric = new FontMetricsMapper("Serif", bold, parent);
+ metric = new FontMetricsMapper("Serif", bold, graphics);
// --> goes to F7
fontInfo.addMetrics("F7", metric);
- metric = new FontMetricsMapper("Serif", bolditalic, parent);
+ metric = new FontMetricsMapper("Serif", bolditalic, graphics);
// --> goes to F8
fontInfo.addMetrics("F8", metric);
- metric = new FontMetricsMapper("MonoSpaced", normal, parent);
+ metric = new FontMetricsMapper("MonoSpaced", normal, graphics);
// --> goes to F9
fontInfo.addMetrics("F9", metric);
- metric = new FontMetricsMapper("MonoSpaced", italic, parent);
+ metric = new FontMetricsMapper("MonoSpaced", italic, graphics);
// --> goes to F10
fontInfo.addMetrics("F10", metric);
- metric = new FontMetricsMapper("MonoSpaced", bold, parent);
+ metric = new FontMetricsMapper("MonoSpaced", bold, graphics);
// --> goes to F11
fontInfo.addMetrics("F11", metric);
- metric = new FontMetricsMapper("MonoSpaced", bolditalic, parent);
+ metric = new FontMetricsMapper("MonoSpaced", bolditalic, graphics);
// --> goes to F12
fontInfo.addMetrics("F12", metric);
- metric = new FontMetricsMapper("Symbol", bolditalic, parent);
+ metric = new FontMetricsMapper("Symbol", bolditalic, graphics);
// --> goes to F13 and F14
fontInfo.addMetrics("F13", metric);
fontInfo.addMetrics("F14", metric);