this.fontInfo = inFontInfo;
int num = 1;
if (this.fontList != null && this.fontList.size() > 0) {
- for (Iterator it = this.fontList.iterator(); it.hasNext(); ) {
+ for (Iterator it = this.fontList.iterator(); it.hasNext();) {
AFPFontInfo afi = (AFPFontInfo)it.next();
AFPFont bf = (AFPFont)afi.getAFPFont();
- for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext(); ) {
+ for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext();) {
FontTriplet ft = (FontTriplet)it2.next();
this.fontInfo.addFontProperties("F" + num, ft.getName()
, ft.getStyle(), ft.getWeight());
log.warn("No AFP fonts configured - using default setup");
}
if (this.fontInfo.fontLookup("sans-serif", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZH200 ", 1, new Helvetica());
+ CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZH200 ",
+ 1, new Helvetica());
AFPFont bf = new OutlineFont("Helvetica", cs);
this.fontInfo.addFontProperties("F" + num, "sans-serif", "normal", 400);
this.fontInfo.addMetrics("F" + num, bf);
num++;
}
if (this.fontInfo.fontLookup("serif", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZN200 ", 1, new TimesRoman());
+ CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZN200 ",
+ 1, new TimesRoman());
AFPFont bf = new OutlineFont("Helvetica", cs);
this.fontInfo.addFontProperties("F" + num, "serif", "normal", 400);
this.fontInfo.addMetrics("F" + num, bf);
num++;
}
if (this.fontInfo.fontLookup("monospace", "normal", 400) == null) {
- CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZ4200 ", 1, new Courier());
+ CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZ4200 ",
+ 1, new Courier());
AFPFont bf = new OutlineFont("Helvetica", cs);
this.fontInfo.addFontProperties("F" + num, "monospace", "normal", 400);
this.fontInfo.addMetrics("F" + num, bf);
}
if (this.fontInfo.fontLookup("any", "normal", 400) == null) {
FontTriplet ft = this.fontInfo.fontLookup("sans-serif", "normal", 400);
- this.fontInfo.addFontProperties(this.fontInfo.getInternalFontKey(ft), "any", "normal", 400);
+ this.fontInfo.addFontProperties(
+ this.fontInfo.getInternalFontKey(ft), "any", "normal", 400);
}
}
*
* {@inheritDoc}
*/
- public void preparePage(PageViewport page) {
+ public void preparePage(PageViewport pageViewport) {
// initializeRootExtensions(page);
_currentFontFamily = "";
_currentPageFonts.clear();
_lineCache = new HashSet();
- Rectangle2D bounds = page.getViewArea();
+ Rectangle2D bounds = pageViewport.getViewArea();
_pageWidth = mpts2units(bounds.getWidth());
_pageHeight = mpts2units(bounds.getHeight());
_afpDataStream.startPage(_pageWidth, _pageHeight, 0);
- renderPageObjectExtensions(page);
+ renderPageObjectExtensions(pageViewport);
if (_pages == null) {
_pages = new HashMap();
}
- _pages.put(page, _afpDataStream.savePage());
+ _pages.put(pageViewport, _afpDataStream.savePage());
}
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void startVParea(CTM ctm, Rectangle2D clippingRect) {
// dummy not used
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
protected void renderBlockViewport(BlockViewport bv, List children) {
// clip and position viewport if necessary
/**
* {@inheritDoc}
*/
- public void renderPage(PageViewport page) {
+ public void renderPage(PageViewport pageViewport) {
// initializeRootExtensions(page);
_currentPageFonts.clear();
_lineCache = new HashSet();
- Rectangle2D bounds = page.getViewArea();
+ Rectangle2D bounds = pageViewport.getViewArea();
_pageWidth = mpts2units(bounds.getWidth());
_pageHeight = mpts2units(bounds.getHeight());
- if (_pages != null && _pages.containsKey(page)) {
+ if (_pages != null && _pages.containsKey(pageViewport)) {
- _afpDataStream.restorePage((PageObject)_pages.remove(page));
+ _afpDataStream.restorePage((PageObject)_pages.remove(pageViewport));
} else {
// renderPageGroupExtensions(page);
_afpDataStream.startPage(_pageWidth, _pageHeight, 0);
- renderPageObjectExtensions(page);
+ renderPageObjectExtensions(pageViewport);
}
pushViewPortPos(new ViewPortPos());
- renderPageAreas(page.getPage());
+ renderPageAreas(pageViewport.getPage());
Iterator i = _currentPageFonts.values().iterator();
while (i.hasNext()) {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void clipRect(float x, float y, float width, float height) {
// TODO
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void moveTo(float x, float y) {
// TODO
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void lineTo(float x, float y) {
// TODO
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void fillRect(float x, float y, float width, float height) {
/*
protected RendererContext createRendererContext(int x, int y, int width, int height, Map foreignAttributes) {
RendererContext context;
context = super.createRendererContext(x, y, width, height, foreignAttributes);
- context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE,
+ context.setProperty(AFPRendererContextConstants.AFP_GRAYSCALE,
new Boolean(!this.colorImages));
return context;
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
String name = null;
}
}
}
-
+
/**
* Draws a BufferedImage to AFP.
* @param bi the BufferedImage
//Serialize image
writeImage(bi, baout);
byte[] buf = baout.toByteArray();
-
+
//Generate image
ImageObject io = _afpDataStream.getImageObject(afpx, afpy, afpw, afph);
io.setImageParameters(
log.error("Error while serializing bitmap: " + ioe.getMessage(), ioe);
}
}
-
+
/**
* Establishes a new foreground or fill color.
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void updateColor(Color col, boolean fill) {
if (fill) {
}
/**
- * {@inheritDoc}
+ * {@inheritDoc}
*/
public void renderImage(Image image, Rectangle2D pos) {
String url = image.getURL();
* Method to render the page extension.
* <p>
*
- * @param page
+ * @param pageViewport
* the page object
*/
- private void renderPageObjectExtensions(PageViewport page) {
+ private void renderPageObjectExtensions(PageViewport pageViewport) {
_pageSegmentsMap = null;
- if (page.getExtensionAttachments() != null
- && page.getExtensionAttachments().size() > 0) {
+ if (pageViewport.getExtensionAttachments() != null
+ && pageViewport.getExtensionAttachments().size() > 0) {
//Extract all AFPPageSetup instances from the attachment list on the s-p-m
- Iterator i = page.getExtensionAttachments().iterator();
+ Iterator i = pageViewport.getExtensionAttachments().iterator();
while (i.hasNext()) {
ExtensionAttachment attachment = (ExtensionAttachment)i.next();
if (AFPPageSetup.CATEGORY.equals(attachment.getCategory())) {
- AFPPageSetup aps = (AFPPageSetup)attachment;
- String element = aps.getElementName();
- if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
- String overlay = aps.getName();
- if (overlay != null) {
- _afpDataStream.createIncludePageOverlay(overlay);
+ if (attachment instanceof AFPPageSetup) {
+ AFPPageSetup aps = (AFPPageSetup)attachment;
+ if (log.isDebugEnabled()) {
+ log.debug(aps);
}
- } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(element)) {
- String name = aps.getName();
- String source = aps.getValue();
- if (_pageSegmentsMap == null) {
- _pageSegmentsMap = new HashMap();
+ String element = aps.getElementName();
+ if (AFPElementMapping.INCLUDE_PAGE_OVERLAY.equals(element)) {
+ String overlay = aps.getName();
+ if (overlay != null) {
+ _afpDataStream.createIncludePageOverlay(overlay);
+ }
+ } else if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(element)) {
+ String name = aps.getName();
+ String source = aps.getValue();
+ if (_pageSegmentsMap == null) {
+ _pageSegmentsMap = new HashMap();
+ }
+ _pageSegmentsMap.put(source, name);
+ } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) {
+ String name = aps.getName();
+ String value = aps.getValue();
+ if (_pageSegmentsMap == null) {
+ _pageSegmentsMap = new HashMap();
+ }
+ _afpDataStream.createTagLogicalElement(name, value);
+ } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+ String content = aps.getContent();
+ if (content != null) {
+ _afpDataStream.createNoOperation(content);
+ }
}
- _pageSegmentsMap.put(source, name);
- } else if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) {
- String name = aps.getName();
- String value = aps.getValue();
- if (_pageSegmentsMap == null) {
- _pageSegmentsMap = new HashMap();
- }
- _afpDataStream.createTagLogicalElement(name, value);
}
}
}
return (int)Math.round(mpt / DPI_CONVERSION_FACTOR_240);
}
- private void convertToGrayScaleImage(ImageObject io, byte raw[]) {
+ private void convertToGrayScaleImage(ImageObject io, byte[] raw) {
int pixelsPerByte = 8 / bitsPerPixel;
- byte bw[] = new byte[raw.length / (3 * pixelsPerByte)];
+ byte[] bw = new byte[raw.length / (3 * pixelsPerByte)];
int k = 0;
for (int i = 0, j = 0; i < raw.length; i += 3, j++) {
if (j == pixelsPerByte) {
j = 0;
k++;
+ if (k == bw.length) {
+ break;
+ }
}
// see http://www.jguru.com/faq/view.jsp?EID=221919
double greyVal = 0.212671d * ((int) raw[i] & 0xff)
import java.io.Serializable;
import org.apache.fop.fo.extensions.ExtensionAttachment;
+import org.apache.fop.util.XMLizable;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
/**
* This is the pass-through value object for the PostScript extension.
*/
-public class AFPPageSetup implements ExtensionAttachment, Serializable {
+public class AFPPageSetup implements ExtensionAttachment, Serializable, XMLizable {
+
+ private static final long serialVersionUID = 7190606822558332901L;
/** The category URI for this extension attachment. */
public static final String CATEGORY = "apache:fop:extensions:afp";
private String value;
+ private String content;
+
/**
* Default constructor.
- * @param name the name of the setup code object, may be null
+ *
+ * @param elementName the name of the setup code object, may be null
*/
- public AFPPageSetup(String name) {
- this.elementName = name;
+ public AFPPageSetup(String elementName) {
+ this.elementName = elementName;
}
/** @return the name */
public void setValue(String source) {
this.value = source;
}
-
+
/** {@inheritDoc} */
public String getCategory() {
return CATEGORY;
}
+ /**
+ * @return the data
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the data
+ * @param content The byte data to set.
+ */
+ public void setContent(String content) {
+ this.content = content;
+ }
+
/** {@inheritDoc} */
public String toString() {
return "AFPPageSetup(element-name=" + getElementName() + " name=" + getName() + ")";
}
+ private static final String ATT_NAME = "name";
+ private static final String ATT_VALUE = "value";
+
+ /** {@inheritDoc} */
+ public void toSAX(ContentHandler handler) throws SAXException {
+ AttributesImpl atts = new AttributesImpl();
+ if (name != null && name.length() > 0) {
+ atts.addAttribute(null, ATT_NAME, ATT_NAME, "CDATA", name);
+ }
+ if (value != null && value.length() > 0) {
+ atts.addAttribute(null, ATT_VALUE, ATT_VALUE, "CDATA", value);
+ }
+ handler.startElement(CATEGORY, elementName, elementName, atts);
+ if (content != null && content.length() > 0) {
+ char[] chars = content.toCharArray();
+ handler.characters(chars, 0, chars.length);
+ }
+ handler.endElement(CATEGORY, elementName, elementName);
+ }
}