summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/org/apache/fop/area/CTM.java140
-rw-r--r--src/org/apache/fop/render/pdf/CTMHelper.java103
-rw-r--r--src/org/apache/fop/render/pdf/PDFRenderer.java292
3 files changed, 323 insertions, 212 deletions
diff --git a/src/org/apache/fop/area/CTM.java b/src/org/apache/fop/area/CTM.java
index d506d3feb..cdb28de0f 100644
--- a/src/org/apache/fop/area/CTM.java
+++ b/src/org/apache/fop/area/CTM.java
@@ -19,21 +19,21 @@ import org.apache.fop.fo.properties.WritingMode;
*/
public class CTM implements Serializable {
- private double a,b,c,d,e,f;
+ private double a, b, c, d, e, f;
- private static CTM s_CTM_lrtb = new CTM(1,0,0,1,0,0);
- private static CTM s_CTM_rltb = new CTM(-1,0,0,1,0,0);
- private static CTM s_CTM_tbrl = new CTM(0,1,-1,0,0,0);
-/**
- * Create the identity matrix
- */
+ private static CTM s_CTM_lrtb = new CTM(1, 0, 0, 1, 0, 0);
+ private static CTM s_CTM_rltb = new CTM(-1, 0, 0, 1, 0, 0);
+ private static CTM s_CTM_tbrl = new CTM(0, 1, -1, 0, 0, 0);
+ /**
+ * Create the identity matrix
+ */
public CTM() {
- a=1;
- b=0;
- c=0;
- d=1;
- e=0;
- f=0;
+ a = 1;
+ b = 0;
+ c = 0;
+ d = 1;
+ e = 0;
+ f = 0;
}
/**
@@ -62,12 +62,12 @@ public class CTM implements Serializable {
}
protected CTM(CTM ctm) {
- this.a = ctm.a;
- this.b = ctm.b;
- this.c = ctm.c;
- this.d = ctm.d;
- this.e = ctm.e;
- this.f = ctm.f;
+ this.a = ctm.a;
+ this.b = ctm.b;
+ this.c = ctm.c;
+ this.d = ctm.d;
+ this.e = ctm.e;
+ this.f = ctm.f;
}
/**
@@ -81,26 +81,26 @@ public class CTM implements Serializable {
* CTM is being set.
*/
static public CTM getWMctm(int wm, int ipd, int bpd) {
- CTM wmctm;
+ CTM wmctm;
switch (wm) {
case WritingMode.LR_TB:
return new CTM(s_CTM_lrtb);
case WritingMode.RL_TB:
- {
- wmctm = new CTM(s_CTM_rltb);
- wmctm.e = ipd;
- return wmctm;
- }
+ {
+ wmctm = new CTM(s_CTM_rltb);
+ wmctm.e = ipd;
+ return wmctm;
+ }
//return s_CTM_rltb.translate(ipd, 0);
case WritingMode.TB_RL: // CJK
- {
- wmctm = new CTM(s_CTM_tbrl);
- wmctm.e = bpd;
- return wmctm;
- }
+ {
+ wmctm = new CTM(s_CTM_tbrl);
+ wmctm.e = bpd;
+ return wmctm;
+ }
//return s_CTM_tbrl.translate(0, ipd);
- default:
- return null;
+ default:
+ return null;
}
}
@@ -111,14 +111,12 @@ public class CTM implements Serializable {
* @return CTM The result of multiplying premult * this.
*/
public CTM multiply(CTM premult) {
- CTM rslt= new CTM (
- (premult.a * a) + (premult.b * c),
- (premult.a * b) + (premult.b * d),
- (premult.c * a) + (premult.d * c),
- (premult.c * b) + (premult.d * d),
- (premult.e * a) + (premult.f * c) + e,
- (premult.e * b) + (premult.f * d) + f
- );
+ CTM rslt = new CTM ((premult.a * a) + (premult.b * c),
+ (premult.a * b) + (premult.b * d),
+ (premult.c * a) + (premult.d * c),
+ (premult.c * b) + (premult.d * d),
+ (premult.e * a) + (premult.f * c) + e,
+ (premult.e * b) + (premult.f * d) + f);
return rslt;
}
@@ -130,25 +128,22 @@ public class CTM implements Serializable {
* @return CTM The result of rotating this CTM.
*/
public CTM rotate(double angle) {
- double cos, sin;
- if (angle == 90.0) {
- cos = 0.0;
- sin = 1.0;
- }
- else if (angle == 270.0) {
- cos = 0.0;
- sin = -1.0;
- }
- else if (angle == 180.0) {
- cos = -1.0;
- sin = 0.0;
- }
- else {
- double rad = Math.toRadians(angle);
- cos = Math.cos(rad);
- sin = Math.sin(rad);
- }
- CTM rotate= new CTM(cos,-sin, sin, cos, 0, 0);
+ double cos, sin;
+ if (angle == 90.0) {
+ cos = 0.0;
+ sin = 1.0;
+ } else if (angle == 270.0) {
+ cos = 0.0;
+ sin = -1.0;
+ } else if (angle == 180.0) {
+ cos = -1.0;
+ sin = 0.0;
+ } else {
+ double rad = Math.toRadians(angle);
+ cos = Math.cos(rad);
+ sin = Math.sin(rad);
+ }
+ CTM rotate = new CTM(cos, -sin, sin, cos, 0, 0);
return multiply(rotate);
}
@@ -159,7 +154,7 @@ public class CTM implements Serializable {
* @return CTM The result of translating this CTM.
*/
public CTM translate(double x, double y) {
- CTM translate= new CTM(1,0,0,1,x,y);
+ CTM translate = new CTM(1, 0, 0, 1, x, y);
return multiply(translate);
}
@@ -170,7 +165,7 @@ public class CTM implements Serializable {
* @return CTM The result of scaling this CTM.
*/
public CTM scale(double x, double y) {
- CTM scale= new CTM(x,0,0,y,0,0);
+ CTM scale = new CTM(x, 0, 0, y, 0, 0);
return multiply(scale);
}
@@ -183,12 +178,12 @@ public class CTM implements Serializable {
public Rectangle2D transform(Rectangle2D inRect) {
// Store as 2 sets of 2 points and transform those, then
// recalculate the width and height
- int x1t = (int)(inRect.getX()*a + inRect.getY()*c + e);
- int y1t = (int)(inRect.getX()*b + inRect.getY()*d + f);
- int x2t = (int)((inRect.getX()+inRect.getWidth())*a +
- (inRect.getY()+inRect.getHeight())*c + e);
- int y2t = (int)((inRect.getX()+inRect.getWidth())*b +
- (inRect.getY()+inRect.getHeight())*d + f);
+ int x1t = (int)(inRect.getX() * a + inRect.getY() * c + e);
+ int y1t = (int)(inRect.getX() * b + inRect.getY() * d + f);
+ int x2t = (int)((inRect.getX() + inRect.getWidth()) * a +
+ (inRect.getY() + inRect.getHeight()) * c + e);
+ int y2t = (int)((inRect.getX() + inRect.getWidth()) * b +
+ (inRect.getY() + inRect.getHeight()) * d + f);
// Normalize with x1 < x2
if (x1t > x2t) {
int tmp = x2t;
@@ -200,18 +195,15 @@ public class CTM implements Serializable {
y2t = y1t;
y1t = tmp;
}
- return new Rectangle(x1t, y1t, x2t-x1t, y2t-y1t);
+ return new Rectangle(x1t, y1t, x2t - x1t, y2t - y1t);
}
public String toString() {
- return "[" + a + " " + b + " " + c + " " + d + " " + e + " " + f + "]";
- }
-
- public String toPDFctm() {
- return a + " " + b + " " + c + " " + d + " " + e/1000f + " " + f/1000f;
+ return "[" + a + " " + b + " " + c + " " + d + " " + e + " " +
+ f + "]";
}
public double[] toArray() {
- return new double[] {a, b, c, d, e / 1000.0, f / 1000.0};
+ return new double[]{a, b, c, d, e, f};
}
}
diff --git a/src/org/apache/fop/render/pdf/CTMHelper.java b/src/org/apache/fop/render/pdf/CTMHelper.java
new file mode 100644
index 000000000..6641dc59f
--- /dev/null
+++ b/src/org/apache/fop/render/pdf/CTMHelper.java
@@ -0,0 +1,103 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.render.pdf;
+
+import org.apache.fop.area.CTM;
+
+/**
+ * CTMHelper converts FOP transformation matrixis to those
+ * suitable for use by the PDFRender. The e and f elements
+ * of the matrix will be divided by 1000 as FOP uses millipoints
+ * as it's default user space and PDF uses points.
+ *
+ * @see org.apache.fop.area.CTM
+ *
+ * @author <a href="kevin@rocketred.com>Kevin O'Neill</a>
+ */
+public final class CTMHelper {
+ /**
+ * <p>Converts the sourceMatrix to a string for use in the PDFRender cm operations.</p>
+ * <p>For example:
+ * <pre>
+ * org.apache.fop.area.CTM ctm = new org.apache.fop.area.CTM(1.0, 0.0, 0.0, 1.0, 1000.0, 1000.0);
+ * String pdfMatrix = org.apache.fop.render.pdf.CTMHelper.toPDFString(ctm);
+ * </pre>
+ * will return the string "<code>1.0 0.0 0.0 1.0 1.0 1.0</code>".
+ *
+ * @param sourceMatrix - The matrix to convert.
+ *
+ * @return a space seperated string containing the matrix elements.
+ *
+ * @throws IllegalArgumentException if the sourceMatrix parameter is null.
+ */
+ public static String toPDFString(CTM sourceMatrix) {
+ if (null == sourceMatrix) {
+ throw new IllegalArgumentException("sourceMatrix must not be null");
+ }
+
+ final double matrix[] = toPDFArray(sourceMatrix);
+
+ return matrix[0] + " " + matrix[1] + " " + matrix[2] + " " +
+ matrix[3] + " " + matrix[4] + " " + matrix[5];
+ }
+
+ /**
+ * <p>Creates a new CTM based in the sourceMatrix.</p>
+ * <p>For example:
+ * <pre>
+ * org.apache.fop.area.CTM inCTM = new org.apache.fop.area.CTM(1.0, 0.0, 0.0, 1.0, 1000.0, 1000.0);
+ * org.apache.fop.area.CTM outCTM org.apache.fop.render.pdf.CTMHelper.toPDFCTM(ctm);
+ * </pre>
+ * will return a new CTM where a == 1.0, b == 0.0, c == 0.0, d == 1.0, e == 1.0 and f == 1.0.
+ *
+ * @param sourceMatrix - The matrix to convert.
+ *
+ * @return a new converted matrix.
+ *
+ * @throws IllegalArgumentException if the sourceMatrix parameter is null.
+ */
+ public static CTM toPDFCTM(CTM sourceMatrix) {
+ if (null == sourceMatrix) {
+ throw new IllegalArgumentException("sourceMatrix must not be null");
+ }
+
+ final double matrix[] = toPDFArray(sourceMatrix);
+
+ return new CTM(matrix[0], matrix[1], matrix[2], matrix[3],
+ matrix[4], matrix[5]);
+ }
+
+ /**
+ * <p>Creates an array of six doubles from the source CTM.</p>
+ * <p>For example:
+ * <pre>
+ * org.apache.fop.area.CTM inCTM = new org.apache.fop.area.CTM(1.0, 0.0, 0.0, 1.0, 1000.0, 1000.0);
+ * double matrix[] = org.apache.fop.render.pdf.CTMHelper.toPDFArray(ctm);
+ * </pre>
+ * will return a new array where matrix[0] == 1.0, matrix[1] == 0.0, matrix[2] == 0.0, matrix[3] == 1.0,
+ * matrix[4] == 1.0 and matrix[5] == 1.0.
+ *
+ * @param sourceMatrix - The matrix to convert.
+ *
+ * @return an array of doubles containing the converted matrix.
+ *
+ * @throws IllegalArgumentException if the sourceMatrix parameter is null.
+ */
+ public static double[] toPDFArray(CTM sourceMatrix) {
+ if (null == sourceMatrix) {
+ throw new IllegalArgumentException("sourceMatrix must not be null");
+ }
+
+ final double matrix[] = sourceMatrix.toArray();
+
+ return new double[]{matrix[0], matrix[1], matrix[2], matrix[3],
+ matrix[4] / 1000.0, matrix[5] / 1000.0};
+ }
+
+}
+
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java
index ac493e142..db2841125 100644
--- a/src/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/org/apache/fop/render/pdf/PDFRenderer.java
@@ -41,13 +41,11 @@ import java.util.List;
/*
TODO:
-viewport clipping
word rendering and optimistion
pdf state optimisation
line and border
leader
background pattern
-user agent xml (svg) rendering
orientation
writing mode
text decoration
@@ -186,13 +184,13 @@ public class PDFRenderer extends PrintRenderer {
*/
public void preparePage(PageViewport page) {
this.pdfResources = this.pdfDoc.getResources();
-
+
Rectangle2D bounds = page.getViewArea();
double w = bounds.getWidth();
double h = bounds.getHeight();
currentPage = this.pdfDoc.makePage(this.pdfResources,
(int) Math.round(w / 1000), (int) Math.round(h / 1000));
- if(pages == null) {
+ if (pages == null) {
pages = new HashMap();
}
pages.put(page, currentPage);
@@ -206,25 +204,28 @@ public class PDFRenderer extends PrintRenderer {
*/
public void renderPage(PageViewport page) throws IOException,
FOPException {
- if(pages != null && (currentPage = (PDFPage)pages.get(page)) != null) {
+ if (pages != null &&
+ (currentPage = (PDFPage) pages.get(page)) != null) {
pages.remove(page);
} else {
this.pdfResources = this.pdfDoc.getResources();
Rectangle2D bounds = page.getViewArea();
double w = bounds.getWidth();
double h = bounds.getHeight();
- pageHeight = (int)h;
- currentPage = this.pdfDoc.makePage(this.pdfResources,
- (int) Math.round(w / 1000), (int) Math.round(h / 1000));
+ pageHeight = (int) h;
+ currentPage = this.pdfDoc.makePage(this.pdfResources,
+ (int) Math.round(w / 1000), (int) Math.round(h / 1000));
pageReferences.put(page, currentPage.referencePDF());
}
- currentStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false);
+ currentStream =
+ this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false);
currentState = new PDFState();
- currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0, (int) Math.round(pageHeight / 1000)));
- // Transform origin at top left to origin at bottom left
- currentStream.add("1 0 0 -1 0 " +
- (int) Math.round(pageHeight / 1000) + " cm\n");
+ currentState.setTransform( new AffineTransform(1, 0, 0, -1, 0,
+ (int) Math.round(pageHeight / 1000)));
+ // Transform origin at top left to origin at bottom left
+ currentStream.add("1 0 0 -1 0 " +
+ (int) Math.round(pageHeight / 1000) + " cm\n");
//currentStream.add("BT\n");
currentFontName = "";
@@ -241,32 +242,33 @@ public class PDFRenderer extends PrintRenderer {
protected void startVParea(CTM ctm) {
- // Set the given CTM in the graphics state
+ // Set the given CTM in the graphics state
currentState.push();
- currentState.setTransform(new AffineTransform(ctm.toArray()));
+ currentState.setTransform(
+ new AffineTransform(CTMHelper.toPDFArray(ctm)));
- currentStream.add("q\n");
- // multiply with current CTM
- currentStream.add(ctm.toPDFctm() + " cm\n");
- // Set clip?
- currentStream.add("BT\n");
+ currentStream.add("q\n");
+ // multiply with current CTM
+ currentStream.add(CTMHelper.toPDFString(ctm) + " cm\n");
+ // Set clip?
+ currentStream.add("BT\n");
}
protected void endVParea() {
- currentStream.add("ET\n");
- currentStream.add("Q\n");
+ currentStream.add("ET\n");
+ currentStream.add("Q\n");
currentState.pop();
}
protected void renderRegion(RegionReference region) {
- // Draw a rectangle so we can see it!
- // x=0,y=0,w=ipd,h=bpd
- super.renderRegion(region);
+ // Draw a rectangle so we can see it!
+ // x=0,y=0,w=ipd,h=bpd
+ super.renderRegion(region);
}
protected void renderLineArea(LineArea line) {
- super.renderLineArea(line);
- closeText();
+ super.renderLineArea(line);
+ closeText();
}
public void renderCharacter(Character ch) {
@@ -275,58 +277,58 @@ public class PDFRenderer extends PrintRenderer {
}
public void renderWord(Word word) {
- StringBuffer pdf = new StringBuffer();
+ StringBuffer pdf = new StringBuffer();
- String name = (String)word.getTrait(Trait.FONT_NAME);
- int size = ((Integer)word.getTrait(Trait.FONT_SIZE)).intValue();
+ 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)fontInfo.getFonts().get(name);
- boolean useMultiByte = f.isMultiByte();
+ // This assumes that *all* CIDFonts use a /ToUnicode mapping
+ Font f = (Font) fontInfo.getFonts().get(name);
+ boolean useMultiByte = f.isMultiByte();
- // String startText = useMultiByte ? "<FEFF" : "(";
- String startText = useMultiByte ? "<" : "(";
- String endText = useMultiByte ? "> " : ") ";
+ // String startText = useMultiByte ? "<FEFF" : "(";
+ String startText = useMultiByte ? "<" : "(";
+ String endText = useMultiByte ? "> " : ") ";
- updateFont(name, size, pdf);
- updateColor(true, pdf);
+ updateFont(name, size, pdf);
+ updateColor(true, pdf);
- int rx = currentBlockIPPosition;
- // int bl = pageHeight - currentBPPosition;
- int bl = currentBPPosition + word.getOffset();
+ int rx = currentBlockIPPosition;
+ // int bl = pageHeight - currentBPPosition;
+ int bl = currentBPPosition + word.getOffset();
- // Set letterSpacing
- //float ls = fs.getLetterSpacing() / this.currentFontSize;
- //pdf.append(ls).append(" Tc\n");
+ // Set letterSpacing
+ //float ls = fs.getLetterSpacing() / this.currentFontSize;
+ //pdf.append(ls).append(" Tc\n");
+
+ if (!textOpen || bl != prevWordY) {
+ closeText();
- if (!textOpen || bl != prevWordY) {
+ pdf.append("1 0 0 -1 " + (rx / 1000f) + " " +
+ (bl / 1000f) + " Tm [" + startText);
+ prevWordY = bl;
+ textOpen = true;
+ } else {
+ // express the space between words in thousandths of an em
+ int space = prevWordX - rx + prevWordWidth;
+ float emDiff = (float) space / (float) currentFontSize * 1000f;
+ // this prevents a problem in Acrobat Reader and other viewers
+ // where large numbers cause text to disappear or default to
+ // a limit
+ if (emDiff < -33000) {
closeText();
- pdf.append("1 0 0 -1 " + (rx / 1000f) + " " + (bl / 1000f)
- + " Tm [" + startText);
- prevWordY = bl;
+ pdf.append("1 0 0 1 " + (rx / 1000f) + " " +
+ (bl / 1000f) + " Tm [" + startText);
textOpen = true;
} else {
- // express the space between words in thousandths of an em
- int space = prevWordX - rx + prevWordWidth;
- float emDiff = (float)space / (float)currentFontSize * 1000f;
- // this prevents a problem in Acrobat Reader and other viewers
- // where large numbers cause text to disappear or default to
- // a limit
- if (emDiff < -33000) {
- closeText();
-
- pdf.append("1 0 0 1 " + (rx / 1000f) + " " + (bl / 1000f)
- + " Tm [" + startText);
- textOpen = true;
- } else {
- pdf.append(Float.toString(emDiff));
- pdf.append(" ");
- pdf.append(startText);
- }
+ pdf.append(Float.toString(emDiff));
+ pdf.append(" ");
+ pdf.append(startText);
}
- prevWordWidth = word.getWidth();
- prevWordX = rx;
+ }
+ prevWordWidth = word.getWidth();
+ prevWordX = rx;
String s = word.getWord();
@@ -340,14 +342,15 @@ public class PDFRenderer extends PrintRenderer {
super.renderWord(word);
}
- public void escapeText(String s, FontState fs, boolean useMultiByte, StringBuffer pdf) {
+ public void escapeText(String s, FontState fs,
+ boolean useMultiByte, StringBuffer pdf) {
String startText = useMultiByte ? "<" : "(";
String endText = useMultiByte ? "> " : ") ";
boolean kerningAvailable = false;
HashMap kerning = null;
kerning = fs.getKerning();
- if (kerning != null &&!kerning.isEmpty()) {
+ if (kerning != null && !kerning.isEmpty()) {
kerningAvailable = true;
}
@@ -359,7 +362,7 @@ public class PDFRenderer extends PrintRenderer {
if (!useMultiByte) {
if (ch > 127) {
pdf.append("\\");
- pdf.append(Integer.toOctalString((int)ch));
+ pdf.append(Integer.toOctalString((int) ch));
} else {
switch (ch) {
case '(':
@@ -375,9 +378,9 @@ public class PDFRenderer extends PrintRenderer {
}
if (kerningAvailable && (i + 1) < l) {
- addKerning(pdf, (new Integer((int)ch)),
- (new Integer((int)fs.mapChar(s.charAt(i + 1)))),
- kerning, startText, endText);
+ addKerning(pdf, (new Integer((int) ch)),
+ (new Integer((int) fs.mapChar(s.charAt(i + 1)))
+ ), kerning, startText, endText);
}
}
}
@@ -397,8 +400,8 @@ public class PDFRenderer extends PrintRenderer {
}
for (int i = 0; i < uniBytes.length; i++) {
- int b = (uniBytes[i] < 0) ? (int)(256 + uniBytes[i])
- : (int)uniBytes[i];
+ int b = (uniBytes[i] < 0) ? (int)(256 + uniBytes[i]) :
+ (int) uniBytes[i];
String hexString = Integer.toHexString(b);
if (hexString.length() == 1)
@@ -410,14 +413,14 @@ public class PDFRenderer extends PrintRenderer {
}
private void addKerning(StringBuffer buf, Integer ch1, Integer ch2,
- HashMap kerning, String startText,
- String endText) {
- HashMap kernPair = (HashMap)kerning.get(ch1);
+ HashMap kerning, String startText, String endText) {
+ HashMap kernPair = (HashMap) kerning.get(ch1);
if (kernPair != null) {
- Integer width = (Integer)kernPair.get(ch2);
+ Integer width = (Integer) kernPair.get(ch2);
if (width != null) {
- buf.append(endText).append(-(width.intValue())).append(' ').append(startText);
+ buf.append(endText).append(-
+ (width.intValue())).append(' ').append(startText);
}
}
}
@@ -437,32 +440,33 @@ public class PDFRenderer extends PrintRenderer {
private void updateColor(boolean fill, StringBuffer pdf) {
/*PDFColor areaColor = null;
- if (this.currentFill instanceof PDFColor) {
- areaColor = (PDFColor)this.currentFill;
- }
-
- if (areaColor == null || areaColor.red() != (double)area.getRed()
- || areaColor.green() != (double)area.getGreen()
- || areaColor.blue() != (double)area.getBlue()) {
-
- areaColor = new PDFColor((double)area.getRed(),
- (double)area.getGreen(),
- (double)area.getBlue());
-
- closeText();
- this.currentFill = areaColor;
- pdf.append(this.currentFill.getColorSpaceOut(true));
- }*/
+ if (this.currentFill instanceof PDFColor) {
+ areaColor = (PDFColor)this.currentFill;
+ }
+
+ if (areaColor == null || areaColor.red() != (double)area.getRed()
+ || areaColor.green() != (double)area.getGreen()
+ || areaColor.blue() != (double)area.getBlue()) {
+
+ areaColor = new PDFColor((double)area.getRed(),
+ (double)area.getGreen(),
+ (double)area.getBlue());
+
+ closeText();
+ this.currentFill = areaColor;
+ pdf.append(this.currentFill.getColorSpaceOut(true));
+ }*/
}
private void updateFont(String name, int size, StringBuffer pdf) {
- if ((!name.equals(this.currentFontName))
- || (size != this.currentFontSize)) {
+ if ((!name.equals(this.currentFontName)) ||
+ (size != this.currentFontSize)) {
closeText();
this.currentFontName = name;
this.currentFontSize = size;
- pdf = pdf.append("/" + name + " " + ((float)size / 1000f) + " Tf\n");
+ pdf = pdf.append("/" + name + " " + ((float) size / 1000f) +
+ " Tf\n");
}
}
@@ -470,83 +474,86 @@ public class PDFRenderer extends PrintRenderer {
String url = image.getURL();
PDFXObject xobject = pdfDoc.getImage(url);
- if(xobject != null) {
- int w = (int)pos.getWidth() / 1000;
- int h = (int)pos.getHeight() / 1000;
- placeImage((int)pos.getX() / 1000, (int)pos.getY() / 1000, w, h, xobject.getXNumber());
+ if (xobject != null) {
+ int w = (int) pos.getWidth() / 1000;
+ int h = (int) pos.getHeight() / 1000;
+ placeImage((int) pos.getX() / 1000,
+ (int) pos.getY() / 1000, w, h, xobject.getXNumber());
return;
}
ImageFactory fact = ImageFactory.getInstance();
FopImage fopimage = fact.getImage(url, userAgent);
- if(fopimage == null) {
+ if (fopimage == null) {
return;
}
- if(!fopimage.load(FopImage.DIMENSIONS, userAgent)) {
+ if (!fopimage.load(FopImage.DIMENSIONS, userAgent)) {
return;
}
String mime = fopimage.getMimeType();
- if("text/xml".equals(mime)) {
- if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
+ if ("text/xml".equals(mime)) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
}
- Document doc = ((XMLImage)fopimage).getDocument();
- String ns = ((XMLImage)fopimage).getNameSpace();
+ Document doc = ((XMLImage) fopimage).getDocument();
+ String ns = ((XMLImage) fopimage).getNameSpace();
renderDocument(doc, ns, pos);
- } else if("image/svg+xml".equals(mime)) {
- if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
+ } else if ("image/svg+xml".equals(mime)) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
}
- Document doc = ((XMLImage)fopimage).getDocument();
- String ns = ((XMLImage)fopimage).getNameSpace();
+ Document doc = ((XMLImage) fopimage).getDocument();
+ String ns = ((XMLImage) fopimage).getNameSpace();
renderDocument(doc, ns, pos);
- } else if("image/eps".equals(mime)) {
- if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
+ } else if ("image/eps".equals(mime)) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
fact.releaseImage(url, userAgent);
- } else if("image/jpg".equals(mime)) {
- if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
+ } else if ("image/jpg".equals(mime)) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
fact.releaseImage(url, userAgent);
- int w = (int)pos.getWidth() / 1000;
- int h = (int)pos.getHeight() / 1000;
- placeImage((int)pos.getX() / 1000, (int)pos.getY() / 1000, w, h, xobj);
+ int w = (int) pos.getWidth() / 1000;
+ int h = (int) pos.getHeight() / 1000;
+ placeImage((int) pos.getX() / 1000,
+ (int) pos.getY() / 1000, w, h, xobj);
} else {
- if(!fopimage.load(FopImage.BITMAP, userAgent)) {
+ if (!fopimage.load(FopImage.BITMAP, userAgent)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
int xobj = pdfDoc.addImage(null, pdfimage).getXNumber();
fact.releaseImage(url, userAgent);
- int w = (int)pos.getWidth() / 1000;
- int h = (int)pos.getHeight() / 1000;
- placeImage((int)pos.getX() / 1000, (int)pos.getY() / 1000, w, h, xobj);
+ int w = (int) pos.getWidth() / 1000;
+ int h = (int) pos.getHeight() / 1000;
+ placeImage((int) pos.getX() / 1000,
+ (int) pos.getY() / 1000, w, h, xobj);
}
// output new data
try {
this.pdfDoc.output(ostream);
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
}
}
protected void placeImage(int x, int y, int w, int h, int xobj) {
- currentStream.add("q\n" + ((float)w) + " 0 0 "
- + ((float)-h) + " "
- + (((float)currentBlockIPPosition) / 1000f + x) + " "
- + (((float)(currentBPPosition + 1000 * h)) / 1000f + y) + " cm\n" + "/Im"
- + xobj + " Do\nQ\n");
+ currentStream.add("q\n" + ((float) w) + " 0 0 " +
+ ((float) - h) + " " +
+ (((float) currentBlockIPPosition) / 1000f + x) + " " +
+ (((float)(currentBPPosition + 1000 * h)) / 1000f +
+ y) + " cm\n" + "/Im" + xobj + " Do\nQ\n");
}
@@ -566,13 +573,18 @@ public class PDFRenderer extends PrintRenderer {
context.setProperty(PDFXMLHandler.PDF_STATE, currentState);
context.setProperty(PDFXMLHandler.PDF_PAGE, currentPage);
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()));
+ context.setProperty(PDFXMLHandler.PDF_XPOS,
+ new Integer(currentBlockIPPosition + (int) pos.getX()));
+ context.setProperty(PDFXMLHandler.PDF_YPOS,
+ new Integer(currentBPPosition + (int) pos.getY()));
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()));
- context.setProperty(PDFXMLHandler.PDF_HEIGHT, new Integer((int)pos.getHeight()));
+ context.setProperty(PDFXMLHandler.PDF_FONT_SIZE,
+ new Integer(currentFontSize));
+ context.setProperty(PDFXMLHandler.PDF_WIDTH,
+ new Integer((int) pos.getWidth()));
+ context.setProperty(PDFXMLHandler.PDF_HEIGHT,
+ new Integer((int) pos.getHeight()));
userAgent.renderXML(context, doc, ns);
}
@@ -605,9 +617,13 @@ public class PDFRenderer extends PrintRenderer {
public void renderLeader(Leader area) {
currentStream.add("ET\n");
- currentStream.add((((float)currentBlockIPPosition) / 1000f) + " "
- + ((currentBPPosition + area.getOffset()) / 1000f) + " m\n");
- currentStream.add(((currentBlockIPPosition + area.getWidth()) / 1000f) + " " + ((currentBPPosition + area.getOffset()) / 1000f) + " l\n");
+ currentStream.add((((float) currentBlockIPPosition) / 1000f) +
+ " " + ((currentBPPosition + area.getOffset()) /
+ 1000f) + " m\n");
+ currentStream.add(
+ ((currentBlockIPPosition + area.getWidth()) / 1000f) +
+ " " + ((currentBPPosition + area.getOffset()) /
+ 1000f) + " l\n");
currentStream.add("S\n");
currentStream.add("BT\n");
super.renderLeader(area);