aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/render/awt
diff options
context:
space:
mode:
authorarved <arved@unknown>2001-05-21 18:35:03 +0000
committerarved <arved@unknown>2001-05-21 18:35:03 +0000
commitc2d7b44400efae12ec4ca16a04c078d51937d42f (patch)
tree5991346f6feef1d3f6692468aa702645a8a1645b /src/org/apache/fop/render/awt
parent563078c089f4e3519767f29c05e440a7d09e0d12 (diff)
downloadxmlgraphics-fop-c2d7b44400efae12ec4ca16a04c078d51937d42f.tar.gz
xmlgraphics-fop-c2d7b44400efae12ec4ca16a04c078d51937d42f.zip
D. Bradby: fixes for -print option
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194263 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/render/awt')
-rw-r--r--src/org/apache/fop/render/awt/AWTFontMetrics.java32
-rw-r--r--src/org/apache/fop/render/awt/AWTRenderer.java83
-rw-r--r--src/org/apache/fop/render/awt/FontMetricsMapper.java6
-rw-r--r--src/org/apache/fop/render/awt/FontSetup.java30
4 files changed, 96 insertions, 55 deletions
diff --git a/src/org/apache/fop/render/awt/AWTFontMetrics.java b/src/org/apache/fop/render/awt/AWTFontMetrics.java
index 5ddeb9fc0..1b1c7f4db 100644
--- a/src/org/apache/fop/render/awt/AWTFontMetrics.java
+++ b/src/org/apache/fop/render/awt/AWTFontMetrics.java
@@ -87,7 +87,6 @@ public class AWTFontMetrics {
*/
public static final int FONT_FACTOR = (1000 * 1000) / FONT_SIZE;
-
/**
* The width of all 256 character, if requested
*/
@@ -126,19 +125,18 @@ public class AWTFontMetrics {
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;
}
/**
@@ -150,7 +148,12 @@ public class AWTFontMetrics {
*/
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;
}
@@ -158,8 +161,9 @@ public class AWTFontMetrics {
* 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);
}
/**
@@ -239,11 +243,10 @@ public class AWTFontMetrics {
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) ||
@@ -252,14 +255,13 @@ public class AWTFontMetrics {
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();
}
diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java
index f4739e10f..82560470f 100644
--- a/src/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/org/apache/fop/render/awt/AWTRenderer.java
@@ -73,16 +73,6 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
*/
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
*/
@@ -96,6 +86,13 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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
*/
protected int currentYPosition = 0;
@@ -112,12 +109,12 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
/** options */
protected Hashtable options;
-
+
/** set up renderer options */
public void setOptions(Hashtable options) {
this.options = options;
}
-
+
public AWTRenderer(Translator aRes) {
res = aRes;
}
@@ -465,7 +462,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
return new Rectangle2D.Double(currentAreaContainerXPosition,
currentYPosition, a.getAllocationWidth(), a.getHeight());
}
-
+/*
public void renderBlockArea(BlockArea area) {
doFrame(area);
Enumeration e = area.getChildren().elements();
@@ -475,9 +472,24 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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) {
@@ -488,7 +500,9 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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();
@@ -553,7 +567,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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)) ||
@@ -573,7 +587,16 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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);
@@ -589,7 +612,6 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
}
graphics.setColor(saveColor);
- FontRenderContext newContext = graphics.getFontRenderContext();
AttributedString ats = new AttributedString(s);
ats.addAttribute(TextAttribute.FONT, f);
if (underlined) {
@@ -609,6 +631,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
}
public void renderLineArea(LineArea area) {
+
int rx = this.currentAreaContainerXPosition + area.getStartIndent();
int ry = this.currentYPosition;
int w = area.getContentWidth();
@@ -751,11 +774,25 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
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;
}
@@ -815,12 +852,14 @@ public class AWTRenderer implements Renderer, Printable, Pageable {
MessageHandler.errorln("AWTRenderer: renderImage(): " +
ex.getMessage());
}
+
}*/
public void renderForeignObjectArea(ForeignObjectArea area) {
area.getObject().render(this);
}
+
protected class MUserAgent implements UserAgent {
AffineTransform currentTransform = null;
/**
diff --git a/src/org/apache/fop/render/awt/FontMetricsMapper.java b/src/org/apache/fop/render/awt/FontMetricsMapper.java
index ee7f519d1..76cee666b 100644
--- a/src/org/apache/fop/render/awt/FontMetricsMapper.java
+++ b/src/org/apache/fop/render/awt/FontMetricsMapper.java
@@ -54,7 +54,7 @@ import org.apache.fop.layout.FontState;
// Java
import java.util.Enumeration;
import java.util.Hashtable;
-import java.awt.Component;
+import java.awt.Graphics2D;
import java.awt.Font;
@@ -99,11 +99,11 @@ public class FontMetricsMapper implements org.apache.fop.layout.FontMetric {
* 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);
}
/**
diff --git a/src/org/apache/fop/render/awt/FontSetup.java b/src/org/apache/fop/render/awt/FontSetup.java
index 2d24f55bd..7fb9535ab 100644
--- a/src/org/apache/fop/render/awt/FontSetup.java
+++ b/src/org/apache/fop/render/awt/FontSetup.java
@@ -59,7 +59,7 @@ import org.apache.fop.layout.FontDescriptor;
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
@@ -79,7 +79,7 @@ public class FontSetup {
* @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;
@@ -95,47 +95,47 @@ public class FontSetup {
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);