--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.afp;
+
+import org.apache.fop.events.EventBroadcaster;
+import org.apache.fop.events.EventProducer;
+import org.apache.fop.events.model.AbstractEventModelFactory;
+import org.apache.fop.events.model.EventModel;
+
+/**
+ * Event producer interface for AFP-specific events.
+ */
+public interface AFPEventProducer extends EventProducer {
+
+ /** Provider class for the event producer. */
+ class Provider {
+
+ /**
+ * Returns an event producer.
+ * @param broadcaster the event broadcaster to use
+ * @return the event producer
+ */
+ public static AFPEventProducer get(EventBroadcaster broadcaster) {
+ return (AFPEventProducer)broadcaster.getEventProducerFor(
+ AFPEventProducer.class);
+ }
+ }
+
+ /** Event model factory for AFP. */
+ public static class EventModelFactory extends AbstractEventModelFactory {
+
+ /** {@inheritDoc} */
+ public EventModel createEventModel() {
+ return loadModel(getClass(), "event-model.xml");
+ }
+
+ }
+
+ /**
+ * Warn about using default font setup.
+ *
+ * @param source the event source
+ * @event.severity WARN
+ */
+ void warnDefaultFontSetup(Object source);
+
+ /**
+ * 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);
+}
--- /dev/null
+<?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>
*/
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
*
}
/**
- * 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} */
+ ", vsci=" + variableSpaceCharacterIncrement
+ ", ica=" + interCharacterAdjustment
+ ", orientation=" + rotation
- + ", data=" + data
+ + ", textString=" + textString
+ + ", textEncoding=" + textEncoding
+ "}";
}
}
\ No newline at end of file
import java.awt.Point;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Map;
*
* @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);
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
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.fop.afp.AFPLineDataInfo;
*
* @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);
}
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;
*/
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;
/**
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
* @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();
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 {
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.fop.afp.AFPLineDataInfo;
*
* @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();
}
} catch (MaximumSizeExceededException msee) {
endPresentationTextData();
createTextData(textDataInfo);
+ } catch (UnsupportedEncodingException e) {
+ endPresentationTextData();
+ throw e;
}
}
+++ /dev/null
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.afp;
-
-import org.apache.fop.events.EventBroadcaster;
-import org.apache.fop.events.EventProducer;
-import org.apache.fop.events.model.AbstractEventModelFactory;
-import org.apache.fop.events.model.EventModel;
-
-/**
- * Event producer interface for AFP-specific events.
- */
-public interface AFPEventProducer extends EventProducer {
-
- /** Provider class for the event producer. */
- class Provider {
-
- /**
- * Returns an event producer.
- * @param broadcaster the event broadcaster to use
- * @return the event producer
- */
- public static AFPEventProducer get(EventBroadcaster broadcaster) {
- return (AFPEventProducer)broadcaster.getEventProducerFor(
- AFPEventProducer.class);
- }
- }
-
- /** Event model factory for AFP. */
- public static class EventModelFactory extends AbstractEventModelFactory {
-
- /** {@inheritDoc} */
- public EventModel createEventModel() {
- return loadModel(getClass(), "event-model.xml");
- }
-
- }
-
- /**
- * Warn about using default font setup.
- * @param source the event source
- * @event.severity WARN
- */
- void warnDefaultFontSetup(Object source);
-
- /**
- * 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);
-}
+++ /dev/null
-<?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>
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;
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;
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