Author: cbowditch
Date: Fri Jul 10 10:32:23 2009
New Revision: 792873
URL: http://svn.apache.org/viewvc?rev=792873&view=rev
Log:
Bugfix: support justified text in AFP Renderer (already working in AFP Painter)
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/DataStream.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/DataStream.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/DataStream.java?rev=792873&r1=792872&r2=792873&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/DataStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/DataStream.java Fri Jul
10 10:32:23 2009
@@ -30,8 +30,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.afp.fonts.AFPFont;
import org.apache.fop.afp.fonts.AFPFontAttributes;
+import org.apache.fop.afp.fonts.AFPFont;
+import org.apache.fop.afp.fonts.CharacterSet;
import org.apache.fop.afp.modca.AbstractPageObject;
import org.apache.fop.afp.modca.Document;
import org.apache.fop.afp.modca.InterchangeSet;
@@ -41,6 +42,10 @@
import org.apache.fop.afp.modca.ResourceGroup;
import org.apache.fop.afp.modca.TagLogicalElementBean;
import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
+import org.apache.fop.afp.ptoca.PtocaProducer;
+import org.apache.fop.afp.ptoca.PtocaBuilder;
+import org.apache.fop.util.CharUtilities;
+import org.apache.fop.fonts.Font;
/**
* A data stream is a continuous ordered stream of data elements and objects
@@ -347,11 +352,15 @@
* Helper method to create text on the current page, this method delegates
* to the current presentation text object in order to construct the text.
*
- * @param textDataInfo
- * the afp text data
+ * @param textDataInfo the afp text data
+ * @param letterSpacing letter spacing to draw text with
+ * @param wordSpacing word Spacing to draw text with
+ * @param font is the font to draw text with
+ * @param charSet is the AFP Character Set to use with the text
* @throws UnsupportedEncodingException thrown if character encoding is
not supported
*/
- public void createText(AFPTextDataInfo textDataInfo) throws
UnsupportedEncodingException {
+ public void createText(final AFPTextDataInfo textDataInfo, final int
letterSpacing, final int wordSpacing,
+ final Font font, final CharacterSet charSet) throws
UnsupportedEncodingException {
int rotation = paintingState.getRotation();
if (rotation != 0) {
textDataInfo.setRotation(rotation);
@@ -359,7 +368,86 @@
textDataInfo.setX(p.x);
textDataInfo.setY(p.y);
}
- currentPage.createText(textDataInfo);
+ // use PtocaProducer to create PTX records
+ PtocaProducer producer = new PtocaProducer() {
+
+ public void produce(PtocaBuilder builder) throws IOException {
+ builder.setTextOrientation(textDataInfo.getRotation());
+ builder.absoluteMoveBaseline(textDataInfo.getY());
+ builder.absoluteMoveInline(textDataInfo.getX());
+
+ builder.setExtendedTextColor(textDataInfo.getColor());
+ builder.setCodedFont((byte)textDataInfo.getFontReference());
+
+ int l = textDataInfo.getString().length();
+ StringBuffer sb = new StringBuffer();
+
+ int interCharacterAdjustment = 0;
+ AFPUnitConverter unitConv = paintingState.getUnitConverter();
+ if (letterSpacing != 0) {
+ interCharacterAdjustment =
Math.round(unitConv.mpt2units(letterSpacing));
+ }
+ builder.setInterCharacterAdjustment(interCharacterAdjustment);
+
+ int spaceWidth = font.getCharWidth(CharUtilities.SPACE);
+ int spacing = spaceWidth + letterSpacing;
+ int fixedSpaceCharacterIncrement =
Math.round(unitConv.mpt2units(spacing));
+ int varSpaceCharacterIncrement = fixedSpaceCharacterIncrement;
+ if (wordSpacing != 0) {
+ varSpaceCharacterIncrement = Math.round(unitConv.mpt2units(
+ spaceWidth + wordSpacing + letterSpacing));
+ }
+
builder.setVariableSpaceCharacterIncrement(varSpaceCharacterIncrement);
+
+ boolean fixedSpaceMode = false;
+
+ for (int i = 0; i < l; i++) {
+ char orgChar = textDataInfo.getString().charAt(i);
+ float glyphAdjust = 0;
+ if (CharUtilities.isFixedWidthSpace(orgChar)) {
+ flushText(builder, sb, charSet);
+ builder.setVariableSpaceCharacterIncrement(
+ fixedSpaceCharacterIncrement);
+ fixedSpaceMode = true;
+ sb.append(CharUtilities.SPACE);
+ int charWidth = font.getCharWidth(orgChar);
+ glyphAdjust += (charWidth - spaceWidth);
+ } else {
+ if (fixedSpaceMode) {
+ flushText(builder, sb, charSet);
+ builder.setVariableSpaceCharacterIncrement(
+ varSpaceCharacterIncrement);
+ fixedSpaceMode = false;
+ }
+ char ch;
+ if (orgChar == CharUtilities.NBSPACE) {
+ ch = ' '; //converted to normal space to allow
word spacing
+ } else {
+ ch = orgChar;
+ }
+ sb.append(ch);
+ }
+
+ if (glyphAdjust != 0) {
+ flushText(builder, sb, charSet);
+ int increment =
Math.round(unitConv.mpt2units(glyphAdjust));
+ builder.relativeMoveInline(increment);
+ }
+ }
+ flushText(builder, sb, charSet);
+ }
+
+ private void flushText(PtocaBuilder builder, StringBuffer sb,
+ final CharacterSet charSet) throws IOException {
+ if (sb.length() > 0) {
+ builder.addTransparentData(charSet.encodeChars(sb));
+ sb.setLength(0);
+ }
+ }
+
+ };
+
+ currentPage.createText(producer);
}
/**
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/AbstractPageObject.java?rev=792873&r1=792872&r2=792873&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/AbstractPageObject.java
Fri Jul 10 10:32:23 2009
@@ -25,9 +25,9 @@
import java.util.List;
import org.apache.fop.afp.AFPLineDataInfo;
-import org.apache.fop.afp.AFPTextDataInfo;
import org.apache.fop.afp.Completable;
import org.apache.fop.afp.Factory;
+import org.apache.fop.afp.ptoca.PtocaProducer;
import org.apache.fop.afp.fonts.AFPFont;
/**
@@ -170,8 +170,10 @@
* the afp text data
* @throws UnsupportedEncodingException thrown if character encoding is
not supported
*/
- public void createText(AFPTextDataInfo textDataInfo) throws
UnsupportedEncodingException {
- getPresentationTextObject().createTextData(textDataInfo);
+ public void createText(PtocaProducer producer) throws
UnsupportedEncodingException {
+ //getPresentationTextObject().createTextData(textDataInfo);
+ getPresentationTextObject().createControlSequences(producer);
+
}
/**
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=792873&r1=792872&r2=792873&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
Fri Jul 10 10:32:23 2009
@@ -75,6 +75,7 @@
import org.apache.fop.datatypes.URISpecification;
import org.apache.fop.events.ResourceEventProducer;
import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontManager;
@@ -563,6 +564,8 @@
AFPFont font = (AFPFont)fontMetricMap.get(internalFontName);
AFPPageFonts pageFonts = paintingState.getPageFonts();
AFPFontAttributes fontAttributes =
pageFonts.registerFont(internalFontName, font, fontSize);
+ Font fnt = getFontFromArea(text);
+
// create text data info
AFPTextDataInfo textDataInfo = new AFPTextDataInfo();
@@ -603,7 +606,7 @@
textDataInfo.setString(textString);
try {
- dataStream.createText(textDataInfo);
+ dataStream.createText(textDataInfo, textLetterSpaceAdjust,
textWordSpaceAdjust, fnt, charSet);
} catch (UnsupportedEncodingException e) {
AFPEventProducer eventProducer
=
AFPEventProducer.Provider.get(userAgent.getEventBroadcaster());
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=792873&r1=792872&r2=792873&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Jul 10 10:32:23 2009
@@ -58,6 +58,9 @@
documents. Example: the fix of marks layering will be such a case when
it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Renderers" dev="CB" type="fix">
+ Bugfix: support justified text in AFP Renderer (already working in AFP
Painter)
+ </action>
<action context="Renderers" dev="AD" type="add">
AFP Renderer Raster Fonts:
<ul>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]