aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
authorLuca Furini <lfurini@apache.org>2005-10-25 15:14:10 +0000
committerLuca Furini <lfurini@apache.org>2005-10-25 15:14:10 +0000
commit5cdaf10f11c193c2a2b833d2ea37a914764c665a (patch)
treecc275f275b5f3eb1085cf619deb8ddde9b43a0d7 /src/java/org/apache/fop/render
parent1cb5e8113f4eafa673ab1adbf63510ac1833cb87 (diff)
downloadxmlgraphics-fop-5cdaf10f11c193c2a2b833d2ea37a914764c665a.tar.gz
xmlgraphics-fop-5cdaf10f11c193c2a2b833d2ea37a914764c665a.zip
Fix for bug 36238 (at least in the PDFRenderer)
The text is split into WordAreas and SpaceAreas: the latters (when the font is multibyte) are not affected by the Tw operator, so they are shifted in the inline progression dimension instead. The behaviour of the other renderers should be the same as before this change. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@328381 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/AbstractRenderer.java35
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java73
-rw-r--r--src/java/org/apache/fop/render/xml/XMLRenderer.java29
3 files changed, 120 insertions, 17 deletions
diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java
index ab2fc8588..0335c2089 100644
--- a/src/java/org/apache/fop/render/AbstractRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractRenderer.java
@@ -59,6 +59,8 @@ import org.apache.fop.area.inline.Space;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Character;
+import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.FontInfo;
@@ -587,14 +589,18 @@ public abstract class AbstractRenderer
protected void renderInlineArea(InlineArea inlineArea) {
if (inlineArea instanceof TextArea) {
renderText((TextArea) inlineArea);
+ } else if (inlineArea instanceof Character) {
+ renderCharacter((Character) inlineArea);
+ } else if (inlineArea instanceof WordArea) {
+ renderWord((WordArea) inlineArea);
+ } else if (inlineArea instanceof SpaceArea) {
+ renderSpace((SpaceArea) inlineArea);
} else if (inlineArea instanceof InlineParent) {
renderInlineParent((InlineParent) inlineArea);
} else if (inlineArea instanceof InlineBlockParent) {
renderInlineBlockParent((InlineBlockParent) inlineArea);
} else if (inlineArea instanceof Space) {
renderInlineSpace((Space) inlineArea);
- } else if (inlineArea instanceof Character) {
- renderCharacter((Character) inlineArea);
} else if (inlineArea instanceof Viewport) {
renderViewport((Viewport) inlineArea);
} else if (inlineArea instanceof Leader) {
@@ -602,7 +608,6 @@ public abstract class AbstractRenderer
}
}
-
/**
* Render the given Character.
* @param ch the character to render
@@ -636,7 +641,29 @@ public abstract class AbstractRenderer
* @param text the text to render
*/
protected void renderText(TextArea text) {
- currentIPPosition += text.getAllocIPD();
+ int saveIP = currentIPPosition;
+ int saveBP = currentBPPosition;
+ Iterator iter = text.getChildAreas().iterator();
+ while (iter.hasNext()) {
+ renderInlineArea((InlineArea) iter.next());
+ }
+ currentIPPosition = saveIP + text.getAllocIPD();
+ }
+
+ /**
+ * Render the given WordArea.
+ * @param word the word to render
+ */
+ protected void renderWord(WordArea word) {
+ currentIPPosition += word.getAllocIPD();
+ }
+
+ /**
+ * Render the given SpaceArea.
+ * @param space the space to render
+ */
+ protected void renderSpace(SpaceArea space) {
+ currentIPPosition += space.getAllocIPD();
}
/**
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index 70beb20fb..69a96f432 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -52,6 +52,8 @@ import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.Leader;
import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.WordArea;
+import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.fonts.Font;
@@ -1095,11 +1097,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
// This assumes that *all* CIDFonts use a /ToUnicode mapping
Typeface tf = (Typeface) fontInfo.getFonts().get(name);
boolean useMultiByte = tf.isMultiByte();
-
- // String startText = useMultiByte ? "<FEFF" : "(";
- String startText = useMultiByte ? "<" : "(";
- String endText = useMultiByte ? "> " : ") ";
-
+
updateFont(name, size, pdf);
ColorType ct = (ColorType) text.getTrait(Trait.COLOR);
updateColor(ct, true, pdf);
@@ -1125,7 +1123,7 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
pdf.append("1 0 0 -1 " + (rx / 1000f) + " " + (bl / 1000f) + " Tm "
+ (text.getTextLetterSpaceAdjust() / 1000f) + " Tc "
- + (text.getTextWordSpaceAdjust() / 1000f) + " Tw [" + startText);
+ + (text.getTextWordSpaceAdjust() / 1000f) + " Tw [");
prevWordY = bl;
textOpen = true;
} else {
@@ -1133,24 +1131,77 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
pdf.append("1 0 0 -1 " + (rx / 1000f) + " " + (bl / 1000f) + " Tm "
+ (text.getTextLetterSpaceAdjust() / 1000f) + " Tc "
- + (text.getTextWordSpaceAdjust() / 1000f) + " Tw [" + startText);
+ + (text.getTextWordSpaceAdjust() / 1000f) + " Tw [");
textOpen = true;
}
prevWordWidth = text.getIPD();
prevWordX = rx;
- String s = text.getTextArea();
+ currentStream.add(pdf.toString());
+ renderTextDecoration(tf, size, text, bl, rx);
+
+ super.renderText(text);
+ }
+
+ /**
+ * @see org.apache.fop.render.AbstractRenderer#renderWord(WordArea)
+ */
+ public void renderWord(WordArea word) {
+ String name = (String) word.getParentArea().getTrait(Trait.FONT_NAME);
+ int size = ((Integer) word.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
+ Typeface tf = (Typeface) fontInfo.getFonts().get(name);
+ boolean useMultiByte = tf.isMultiByte();
+
+ String startText = useMultiByte ? "<" : "(";
+ String endText = useMultiByte ? "> " : ") ";
+
+ StringBuffer pdf = new StringBuffer();
+
+ pdf.append(startText);
+
+ String s = word.getWord();
+
FontMetrics metrics = fontInfo.getMetricsFor(name);
Font fs = new Font(name, metrics, size);
escapeText(s, fs, useMultiByte, pdf);
pdf.append(endText);
-
+
currentStream.add(pdf.toString());
- renderTextDecoration(tf, size, text, bl, rx);
+ super.renderWord(word);
+ }
+
+ /**
+ * @see org.apache.fop.render.AbstractRenderer#renderSpace(SpaceArea)
+ */
+ public void renderSpace(SpaceArea space) {
+ String name = (String) space.getParentArea().getTrait(Trait.FONT_NAME);
+ int size = ((Integer) space.getParentArea().getTrait(Trait.FONT_SIZE)).intValue();
+ Typeface tf = (Typeface) fontInfo.getFonts().get(name);
+ boolean useMultiByte = tf.isMultiByte();
+
+ String startText = useMultiByte ? "<" : "(";
+ String endText = useMultiByte ? "> " : ") ";
- super.renderText(text);
+ StringBuffer pdf = new StringBuffer();
+
+ pdf.append(startText);
+
+ String s = space.getSpace();
+
+ FontMetrics metrics = fontInfo.getMetricsFor(name);
+ Font fs = new Font(name, metrics, size);
+ escapeText(s, fs, useMultiByte, pdf);
+ pdf.append(endText);
+
+ if (useMultiByte) {
+ pdf.append(-(((TextArea) space.getParentArea()).getTextWordSpaceAdjust() / (size / 1000)) + " ");
+ }
+
+ currentStream.add(pdf.toString());
+
+ super.renderSpace(space);
}
/**
diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java
index 71d47df40..da3260d54 100644
--- a/src/java/org/apache/fop/render/xml/XMLRenderer.java
+++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java
@@ -66,6 +66,8 @@ import org.apache.fop.area.inline.Leader;
import org.apache.fop.area.inline.Space;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.area.inline.SpaceArea;
+import org.apache.fop.area.inline.WordArea;
/**
* Renderer that renders areas to XML for debugging purposes.
@@ -613,9 +615,32 @@ public class XMLRenderer extends PrintRenderer {
addAreaAttributes(text);
addTraitAttributes(text);
startElement("text", atts);
- characters(text.getTextArea());
- endElement("text");
super.renderText(text);
+ endElement("text");
+ }
+
+ /**
+ * @see org.apache.fop.render.AbstractRenderer#renderWord(WordArea)
+ */
+ protected void renderWord(WordArea word) {
+ atts.clear();
+ addAttribute("offset", word.getOffset());
+ startElement("word", atts);
+ characters(word.getWord());
+ endElement("word");
+ super.renderWord(word);
+ }
+
+ /**
+ * @see org.apache.fop.render.AbstractRenderer#renderSpace(SpaceArea)
+ */
+ protected void renderSpace(SpaceArea space) {
+ atts.clear();
+ addAttribute("offset", space.getOffset());
+ startElement("space", atts);
+ characters(space.getSpace());
+ endElement("space");
+ super.renderSpace(space);
}
/**