* Moved AFPEventProducer from org.apache.fop.render.afp package to org.apache.fop.afp package. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@721151 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_0
@@ -17,7 +17,7 @@ | |||
/* $Id$ */ | |||
package org.apache.fop.render.afp; | |||
package org.apache.fop.afp; | |||
import org.apache.fop.events.EventBroadcaster; | |||
import org.apache.fop.events.EventProducer; | |||
@@ -55,6 +55,7 @@ public interface AFPEventProducer extends EventProducer { | |||
/** | |||
* Warn about using default font setup. | |||
* | |||
* @param source the event source | |||
* @event.severity WARN | |||
*/ | |||
@@ -62,10 +63,21 @@ public interface AFPEventProducer extends EventProducer { | |||
/** | |||
* Warn about a missing default "any" font configuration. | |||
* | |||
* @param source the event source | |||
* @param style the font style | |||
* @param weight the font weight | |||
* @event.severity WARN | |||
*/ | |||
void warnMissingDefaultFont(Object source, String style, int weight); | |||
/** | |||
* A character set encoding error occurred. | |||
* | |||
* @param source the event source | |||
* @param charSetName the character set name | |||
* @param encoding the encoding | |||
* @event.severity ERROR | |||
*/ | |||
void characterSetEncodingError(Object source, String charSetName, String encoding); | |||
} |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<catalogue xml:lang="en"> | |||
<message key="org.apache.fop.afp.AFPEventProducer.warnDefaultFontSetup">No AFP fonts configured. Using default setup.</message> | |||
<message key="org.apache.fop.afp.AFPEventProducer.warnMissingDefaultFont">No AFP default "any", {style}, {weight} font configured.</message> | |||
<message key="org.apache.fop.afp.AFPEventProducer.characterSetEncodingError">An error occurred when attempting to encode character set {charSetName} with encoding scheme {encoding}.</message> | |||
</catalogue> |
@@ -26,22 +26,33 @@ import java.awt.Color; | |||
*/ | |||
public class AFPTextDataInfo { | |||
/** the text font reference */ | |||
private int fontReference; | |||
/** the text x coordinate position */ | |||
private int x; | |||
/** the text y coordinate position */ | |||
private int y; | |||
/** the text color */ | |||
private Color color; | |||
/** the text variable space adjustment */ | |||
private int variableSpaceCharacterIncrement; | |||
/** the text inter character adjustment */ | |||
private int interCharacterAdjustment; | |||
private byte[] data; | |||
/** the text orientation */ | |||
private int rotation; | |||
/** the text encoding */ | |||
private String textEncoding; | |||
/** the text string */ | |||
private String textString; | |||
/** | |||
* Returns the font reference | |||
* | |||
@@ -152,39 +163,57 @@ public class AFPTextDataInfo { | |||
} | |||
/** | |||
* Return the text data | |||
* Sets the text orientation | |||
* | |||
* @return the text data | |||
* @param rotation the text rotation | |||
*/ | |||
public byte[] getData() { | |||
return data; | |||
public void setRotation(int rotation) { | |||
this.rotation = rotation; | |||
} | |||
/** | |||
* Sets the text data | |||
* Returns the text rotation | |||
* | |||
* @param data the text orientation | |||
* @return the text rotation | |||
*/ | |||
public void setData(byte[] data) { | |||
this.data = data; | |||
public int getRotation() { | |||
return this.rotation; | |||
} | |||
/** | |||
* Sets the text orientation | |||
* Sets the text encoding | |||
* | |||
* @param rotation the text rotation | |||
* @param textEncoding the text encoding | |||
*/ | |||
public void setRotation(int rotation) { | |||
this.rotation = rotation; | |||
public void setEncoding(String textEncoding) { | |||
this.textEncoding = textEncoding; | |||
} | |||
/** | |||
* Returns the text rotation | |||
* Returns the text encoding | |||
* | |||
* @return the text rotation | |||
* @return the text encoding | |||
*/ | |||
public int getRotation() { | |||
return this.rotation; | |||
public String getEncoding() { | |||
return this.textEncoding; | |||
} | |||
/** | |||
* Sets the text string | |||
* | |||
* @param textString the text string | |||
*/ | |||
public void setString(String textString) { | |||
this.textString = textString; | |||
} | |||
/** | |||
* Returns the text string | |||
* | |||
* @return the text string | |||
*/ | |||
public String getString() { | |||
return this.textString; | |||
} | |||
/** {@inheritDoc} */ | |||
@@ -196,7 +225,8 @@ public class AFPTextDataInfo { | |||
+ ", vsci=" + variableSpaceCharacterIncrement | |||
+ ", ica=" + interCharacterAdjustment | |||
+ ", orientation=" + rotation | |||
+ ", data=" + data | |||
+ ", textString=" + textString | |||
+ ", textEncoding=" + textEncoding | |||
+ "}"; | |||
} | |||
} |
@@ -23,6 +23,7 @@ import java.awt.Color; | |||
import java.awt.Point; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
@@ -364,8 +365,9 @@ public class DataStream { | |||
* | |||
* @param textDataInfo | |||
* the afp text data | |||
* @throws UnsupportedEncodingException thrown if character encoding is not supported | |||
*/ | |||
public void createText(AFPTextDataInfo textDataInfo) { | |||
public void createText(AFPTextDataInfo textDataInfo) throws UnsupportedEncodingException { | |||
int rotation = paintingState.getRotation(); | |||
if (rotation != 0) { | |||
textDataInfo.setRotation(rotation); |
@@ -22,12 +22,12 @@ package org.apache.fop.afp.fonts; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import org.apache.fop.afp.AFPEventProducer; | |||
import org.apache.fop.events.EventBroadcaster; | |||
import org.apache.fop.fonts.Font; | |||
import org.apache.fop.fonts.FontCollection; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.fop.fonts.FontTriplet; | |||
import org.apache.fop.render.afp.AFPEventProducer; | |||
/** | |||
* A base collection of AFP fonts |
@@ -21,6 +21,7 @@ package org.apache.fop.afp.modca; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.List; | |||
import org.apache.fop.afp.AFPLineDataInfo; | |||
@@ -171,8 +172,9 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject implemen | |||
* | |||
* @param textDataInfo | |||
* the afp text data | |||
* @throws UnsupportedEncodingException thrown if character encoding is not supported | |||
*/ | |||
public void createText(AFPTextDataInfo textDataInfo) { | |||
public void createText(AFPTextDataInfo textDataInfo) throws UnsupportedEncodingException { | |||
getPresentationTextObject().createTextData(textDataInfo); | |||
} | |||
@@ -22,6 +22,7 @@ package org.apache.fop.afp.modca; | |||
import java.awt.Color; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.UnsupportedEncodingException; | |||
import org.apache.commons.io.output.ByteArrayOutputStream; | |||
import org.apache.fop.afp.AFPLineDataInfo; | |||
@@ -50,49 +51,31 @@ import org.apache.fop.afp.util.BinaryUtils; | |||
*/ | |||
public class PresentationTextData extends AbstractAFPObject { | |||
/** | |||
* The maximum size of the presentation text data. | |||
*/ | |||
/** the maximum size of the presentation text data.*/ | |||
private static final int MAX_SIZE = 8192; | |||
/** | |||
* The afp data relating to this presentation text data. | |||
*/ | |||
/** the AFP data relating to this presentation text data. */ | |||
private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
/** | |||
* The current x coordinate. | |||
*/ | |||
/** the current x coordinate. */ | |||
private int currentX = -1; | |||
/** | |||
* The current y cooridnate | |||
*/ | |||
/** the current y cooridnate */ | |||
private int currentY = -1; | |||
/** | |||
* The current font | |||
*/ | |||
/** the current font */ | |||
private String currentFont = ""; | |||
/** | |||
* The current orientation | |||
*/ | |||
/** the current orientation */ | |||
private int currentOrientation = 0; | |||
/** | |||
* The current color | |||
*/ | |||
/** the current color */ | |||
private Color currentColor = new Color(0, 0, 0); | |||
/** | |||
* The current variable space increment | |||
*/ | |||
/** the current variable space increment */ | |||
private int currentVariableSpaceCharacterIncrement = 0; | |||
/** | |||
* The current inter character adjustment | |||
*/ | |||
/** the current inter character adjustment */ | |||
private int currentInterCharacterAdjustment = 0; | |||
/** | |||
@@ -115,9 +98,9 @@ public class PresentationTextData extends AbstractAFPObject { | |||
0x5A, // Structured field identifier | |||
0x00, // Record length byte 1 | |||
0x00, // Record length byte 2 | |||
(byte) 0xD3, // PresentationTextData identifier byte 1 | |||
(byte) 0xEE, // PresentationTextData identifier byte 2 | |||
(byte) 0x9B, // PresentationTextData identifier byte 3 | |||
SF_CLASS, // PresentationTextData identifier byte 1 | |||
Type.DATA, // PresentationTextData identifier byte 2 | |||
Category.PRESENTATION_TEXT, // PresentationTextData identifier byte 3 | |||
0x00, // Flag | |||
0x00, // Reserved | |||
0x00, // Reserved | |||
@@ -270,10 +253,12 @@ public class PresentationTextData extends AbstractAFPObject { | |||
* @param textDataInfo | |||
* the afp text data | |||
* @throws MaximumSizeExceededException | |||
* thrown if the maximum number of text data is exceeded | |||
* thrown if the maximum number of text data is exceeded | |||
* @throws UnsupportedEncodingException | |||
* thrown if character encoding is not supported | |||
*/ | |||
public void createTextData(AFPTextDataInfo textDataInfo) | |||
throws MaximumSizeExceededException { | |||
throws MaximumSizeExceededException, UnsupportedEncodingException { | |||
ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); | |||
@@ -325,7 +310,9 @@ public class PresentationTextData extends AbstractAFPObject { | |||
afpdata); | |||
// Add transparent data | |||
byte[] data = textDataInfo.getData(); | |||
String textString = textDataInfo.getString(); | |||
String encoding = textDataInfo.getEncoding(); | |||
byte[] data = textString.getBytes(encoding); | |||
if (data.length <= TRANSPARENT_MAX_SIZE) { | |||
addTransparentData(data, afpdata); | |||
} else { |
@@ -21,6 +21,7 @@ package org.apache.fop.afp.modca; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.List; | |||
import org.apache.fop.afp.AFPLineDataInfo; | |||
@@ -68,8 +69,9 @@ public class PresentationTextObject extends AbstractNamedAFPObject { | |||
* | |||
* @param textDataInfo | |||
* The afp text data | |||
* @throws UnsupportedEncodingException thrown if character encoding is not supported | |||
*/ | |||
public void createTextData(AFPTextDataInfo textDataInfo) { | |||
public void createTextData(AFPTextDataInfo textDataInfo) throws UnsupportedEncodingException { | |||
if (currentPresentationTextData == null) { | |||
startPresentationTextData(); | |||
} | |||
@@ -78,6 +80,9 @@ public class PresentationTextObject extends AbstractNamedAFPObject { | |||
} catch (MaximumSizeExceededException msee) { | |||
endPresentationTextData(); | |||
createTextData(textDataInfo); | |||
} catch (UnsupportedEncodingException e) { | |||
endPresentationTextData(); | |||
throw e; | |||
} | |||
} | |||
@@ -1,5 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<catalogue xml:lang="en"> | |||
<message key="org.apache.fop.render.afp.AFPEventProducer.warnDefaultFontSetup">No AFP fonts configured. Using default setup.</message> | |||
<message key="org.apache.fop.render.afp.AFPEventProducer.warnMissingDefaultFont">No AFP default "any", {style}, {weight} font configured.</message> | |||
</catalogue> |
@@ -34,8 +34,8 @@ import java.util.List; | |||
import java.util.Map; | |||
import org.apache.fop.afp.AFPBorderPainter; | |||
import org.apache.fop.afp.AFPConstants; | |||
import org.apache.fop.afp.AFPDataObjectInfo; | |||
import org.apache.fop.afp.AFPEventProducer; | |||
import org.apache.fop.afp.AFPPaintingState; | |||
import org.apache.fop.afp.AFPRectanglePainter; | |||
import org.apache.fop.afp.AFPResourceManager; | |||
@@ -48,6 +48,7 @@ import org.apache.fop.afp.fonts.AFPFont; | |||
import org.apache.fop.afp.fonts.AFPFontAttributes; | |||
import org.apache.fop.afp.fonts.AFPFontCollection; | |||
import org.apache.fop.afp.fonts.AFPPageFonts; | |||
import org.apache.fop.afp.fonts.CharacterSet; | |||
import org.apache.fop.afp.modca.PageObject; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
@@ -537,40 +538,34 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { | |||
Color color = (Color) text.getTrait(Trait.COLOR); | |||
textDataInfo.setColor(color); | |||
int variableSpaceCharacterIncrement = font.getWidth(' ', fontSize) / 1000 | |||
+ text.getTextWordSpaceAdjust() | |||
+ text.getTextLetterSpaceAdjust(); | |||
int textWordSpaceAdjust = text.getTextWordSpaceAdjust(); | |||
int textLetterSpaceAdjust = text.getTextLetterSpaceAdjust(); | |||
int textWidth = font.getWidth(' ', fontSize) / 1000; | |||
int variableSpaceCharacterIncrement | |||
= textWidth + textWordSpaceAdjust + textLetterSpaceAdjust; | |||
variableSpaceCharacterIncrement | |||
= Math.round(unitConv.mpt2units(variableSpaceCharacterIncrement)); | |||
textDataInfo.setVariableSpaceCharacterIncrement(variableSpaceCharacterIncrement); | |||
int interCharacterAdjustment | |||
= Math.round(unitConv.mpt2units(text.getTextLetterSpaceAdjust())); | |||
= Math.round(unitConv.mpt2units(textLetterSpaceAdjust)); | |||
textDataInfo.setInterCharacterAdjustment(interCharacterAdjustment); | |||
// Try and get the encoding to use for the font | |||
String encoding = null; | |||
try { | |||
encoding = font.getCharacterSet(fontSize).getEncoding(); | |||
} catch (Throwable ex) { | |||
encoding = AFPConstants.EBCIDIC_ENCODING; | |||
log.warn("renderText():: Error getting encoding for font '" | |||
+ font.getFullName() + "' - using default encoding " | |||
+ encoding); | |||
} | |||
CharacterSet charSet = font.getCharacterSet(fontSize); | |||
String encoding = charSet.getEncoding(); | |||
textDataInfo.setEncoding(encoding); | |||
String textString = text.getText(); | |||
byte[] data = null; | |||
textDataInfo.setString(textString); | |||
try { | |||
data = textString.getBytes(encoding); | |||
textDataInfo.setData(data); | |||
} catch (UnsupportedEncodingException usee) { | |||
log.error("renderText:: Font " + fontAttributes.getFontKey() | |||
+ " caused UnsupportedEncodingException"); | |||
return; | |||
dataStream.createText(textDataInfo); | |||
} catch (UnsupportedEncodingException e) { | |||
AFPEventProducer eventProducer | |||
= AFPEventProducer.Provider.get(userAgent.getEventBroadcaster()); | |||
eventProducer.characterSetEncodingError(this, charSet.getName(), encoding); | |||
} | |||
dataStream.createText(textDataInfo); | |||
// word.getOffset() = only height of text itself | |||
// currentBlockIPPosition: 0 for beginning of line; nonzero | |||
// where previous line area failed to take up entire allocated space |