* handle all types of inline area, text, image etc and draws various lines and
* rectangles.
* </p>
- *
+ *
* Note: There are specific extensions that have been added to the FO. They are
* specific to their location within the FO and have to be processed accordingly
* (ie. at the start or end of the page).
- *
+ *
*/
public class AFPRenderer extends AbstractPathOrientedRenderer {
private static final int X = 0;
-
+
private static final int Y = 1;
-
+
private static final int X1 = 0;
private static final int Y1 = 1;
public Graphics2DAdapter getGraphics2DAdapter() {
return new AFPGraphics2DAdapter();
}
-
+
/** {@inheritDoc} */
public void startVParea(CTM ctm, Rectangle2D clippingRect) {
saveGraphicsState();
concatenateTransformationMatrix(at);
}
if (clippingRect != null) {
- clipRect((float)clippingRect.getX() / 1000f,
- (float)clippingRect.getY() / 1000f,
- (float)clippingRect.getWidth() / 1000f,
+ clipRect((float)clippingRect.getX() / 1000f,
+ (float)clippingRect.getY() / 1000f,
+ (float)clippingRect.getWidth() / 1000f,
(float)clippingRect.getHeight() / 1000f);
}
}
currentState.clear();
Rectangle2D bounds = pageViewport.getViewArea();
-
+
AffineTransform basicPageTransform = new AffineTransform();
int resolution = currentState.getResolution();
- double scale = (double)1 / (AFPConstants.DPI_72_MPTS / resolution);
+ double scale = mpt2units(1);
basicPageTransform.scale(scale, scale);
currentState.concatenate(basicPageTransform);
(PageObject)getPages().remove(pageViewport));
} else {
int pageWidth
- = (int)Math.round(bounds.getWidth() / (AFPConstants.DPI_72_MPTS / resolution));
+ = (int)Math.round(mpt2units((float)bounds.getWidth()));
currentState.setPageWidth(pageWidth);
int pageHeight
- = (int)Math.round(bounds.getHeight() / (AFPConstants.DPI_72_MPTS / resolution));
+ = (int)Math.round(mpt2units((float)bounds.getHeight()));
currentState.setPageHeight(pageHeight);
final int pageRotation = 0;
renderPageObjectExtensions(pageViewport);
}
-
+
super.renderPage(pageViewport);
AFPPageFonts pageFonts = currentState.getPageFonts();
return transformPoints(srcPts, null, false);
}
+ private float mpt2units(float mpt) {
+ return mpt / ((float)AFPConstants.DPI_72_MPTS / currentState.getResolution());
+ }
+
/** {@inheritDoc} */
public void fillRect(float x, float y, float width, float height) {
float[] srcPts = new float[] {x * 1000, y * 1000};
float[] dstPts = new float[srcPts.length];
- int[] coords = mpts2units(srcPts, dstPts);
- int resolution = currentState.getResolution();
- int x2 = Math.round(dstPts[X] + ((width * 1000) / (AFPConstants.DPI_72_MPTS / resolution)));
- int thickness = Math.round((height * 1000) / (AFPConstants.DPI_72_MPTS / resolution));
+ int[] coords = mpts2units(srcPts, dstPts);
+ int x2 = coords[X] + Math.round(mpt2units(width * 1000));
+ int thickness = Math.round(mpt2units(height * 1000));
getAFPDataStream().createLine(
coords[X],
coords[Y],
Math.round(w3),
leftcol);
afpDataStream.createLine(
- Math.round(xm1 + w3),
+ Math.round(xm1 + w3),
coords[Y1],
Math.round(xm1 + w3),
coords[Y2],
Point origin = new Point(currentIPPosition, currentBPPosition);
int x = origin.x + posInt.x;
int y = origin.y + posInt.y;
-
+
String name = (String)getPageSegments().get(uri);
if (name != null) {
float[] srcPts = {x, y};
imageObjectInfo.setBuffered(false);
imageObjectInfo.setUri(uri);
imageObjectInfo.setMimeType(mimeType);
-
+
ObjectAreaInfo objectAreaInfo = new ObjectAreaInfo();
objectAreaInfo.setX(coords[X]);
objectAreaInfo.setY(coords[Y]);
int resolution = currentState.getResolution();
- int w = Math.round(
- ((float)posInt.getWidth() * 1000)
- / (AFPConstants.DPI_72_MPTS / resolution));
- int h = Math.round(
- ((float)posInt.getHeight() * 1000)
- / (AFPConstants.DPI_72_MPTS / resolution));
+ int w = Math.round(mpt2units((float)posInt.getWidth() * 1000));
+ int h = Math.round(mpt2units((float)posInt.getHeight() * 1000));
objectAreaInfo.setWidth(w);
objectAreaInfo.setHeight(h);
objectAreaInfo.setWidthRes(resolution);
objectAreaInfo.setHeightRes(resolution);
imageObjectInfo.setObjectAreaInfo(objectAreaInfo);
-
+
imageObjectInfo.setData(buf);
imageObjectInfo.setDataHeight(ccitt.getSize().getHeightPx());
imageObjectInfo.setDataWidth(ccitt.getSize().getWidthPx());
/**
* Writes a RenderedImage to an OutputStream as raw sRGB bitmaps.
- *
+ *
* @param image
* the RenderedImage
* @param out
/**
* Draws a BufferedImage to AFP.
- *
+ *
* @param imageInfo
* the image info
* @param image
int[] coords = mpts2units(srcPts);
objectAreaInfo.setX(coords[X]);
objectAreaInfo.setY(coords[Y]);
- int resolution = currentState.getResolution();
- int w = Math.round(
- (width * 1000)
- / (AFPConstants.DPI_72_MPTS / resolution));
- int h = Math.round(
- (height * 1000)
- / (AFPConstants.DPI_72_MPTS / resolution));
+ int w = Math.round(mpt2units(width));
+ int h = Math.round(mpt2units(height));
objectAreaInfo.setWidth(w);
objectAreaInfo.setHeight(h);
-
+
objectAreaInfo.setWidthRes(imageRes);
objectAreaInfo.setHeightRes(imageRes);
imageObjectInfo.setObjectAreaInfo(objectAreaInfo);
}
/** {@inheritDoc} */
- public void renderText(TextArea text) {
+ public void renderText(TextArea text) {
log.debug(text.getText());
renderInlineAreaBackAndBorders(text);
int variableSpaceCharacterIncrement = font.getWidth(' ', fontSize) / 1000
+ text.getTextWordSpaceAdjust()
+ text.getTextLetterSpaceAdjust();
- int resolution = currentState.getResolution();
- variableSpaceCharacterIncrement /= (AFPConstants.DPI_72_MPTS / resolution);
-
- int interCharacterAdjustment = text.getTextLetterSpaceAdjust();
- interCharacterAdjustment /= (AFPConstants.DPI_72_MPTS / resolution);
+ variableSpaceCharacterIncrement = Math.round(mpt2units(variableSpaceCharacterIncrement));
+
+ int interCharacterAdjustment = Math.round(mpt2units(text.getTextLetterSpaceAdjust()));
AFPTextDataInfo textDataInfo = new AFPTextDataInfo();
textDataInfo.setFontReference(fontReference);
/**
* Render leader area. This renders a leader area which is an area with a
* rule.
- *
+ *
* @param area
* the leader area to render
*/
/**
* Sets the rotation to be used for portrait pages, valid values are 0
* (default), 90, 180, 270.
- *
+ *
* @param rotation
* The rotation in degrees.
*/
/**
* Sets the rotation to be used for landsacpe pages, valid values are 0, 90,
* 180, 270 (default).
- *
+ *
* @param rotation
* The rotation in degrees.
*/
/**
* Get the MIME type of the renderer.
- *
+ *
* @return The MIME type of the renderer
*/
public String getMimeType() {
/**
* Method to render the page extension.
* <p>
- *
+ *
* @param pageViewport
* the page object
*/
/**
* Sets the number of bits used per pixel
- *
+ *
* @param bitsPerPixel
* number of bits per pixel
*/
/**
* Sets whether images are color or not
- *
+ *
* @param colorImages
* color image output
*/
/**
* Returns the AFPDataStream
- *
+ *
* @return the AFPDataStream
*/
public AFPDataStream getAFPDataStream() {
/**
* Sets the output/device resolution
- *
+ *
* @param resolution
* the output resolution (dpi)
*/
/**
* Returns the output/device resolution.
- *
+ *
* @return the resolution in dpi
*/
public int getResolution() {
protected boolean isGOCAEnabled() {
return this.gocaEnabled;
}
-
- // TODO: remove this and use the superclass implementation
+
+ // TODO: remove this and use the superclass implementation
/** {@inheritDoc} */
protected void renderReferenceArea(Block block) {
// save position and offset
at.translate(currentIPPosition, currentBPPosition);
at.translate(block.getXOffset(), block.getYOffset());
at.translate(0, block.getSpaceBefore());
-
+
if (!at.isIdentity()) {
saveGraphicsState();
concatenateTransformationMatrix(at);
if (!at.isIdentity()) {
restoreGraphicsState();
}
-
+
// stacked and relative blocks effect stacking
currentIPPosition = saveIP;
currentBPPosition = saveBP;
}
coords[i] = Math.round(dstPts[i]);
}
- return coords;
+ return coords;
}
+
}
* 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.
private int resolution = 240; // 240 dpi
/**
- * The current page
+ * The current page
*/
private AFPPageState pageState = new AFPPageState();
-
+
/**
* Sets the rotation to be used for portrait pages, valid values are 0
* (default), 90, 180, 270.
- *
+ *
* @param rotation
* The rotation in degrees.
*/
/**
* Sets the rotation to be used for landscape pages, valid values are 0, 90,
* 180, 270 (default).
- *
+ *
* @param rotation
* The rotation in degrees.
*/
/**
* Sets the number of bits used per pixel
- *
+ *
* @param bitsPerPixel
* number of bits per pixel
*/
public void setBitsPerPixel(int bitsPerPixel) {
- this.bitsPerPixel = bitsPerPixel;
switch (bitsPerPixel) {
case 1:
case 4:
case 8:
+ this.bitsPerPixel = bitsPerPixel;
break;
default:
log.warn("Invalid bits_per_pixel value, must be 1, 4 or 8.");
- bitsPerPixel = 8;
+ this.bitsPerPixel = 8;
break;
}
}
/**
* Sets whether images are color or not
- *
+ *
* @param colorImages
* color image output
*/
/**
* Sets the output/device resolution
- *
+ *
* @param resolution
* the output resolution (dpi)
*/
/**
* Returns the output/device resolution.
- *
+ *
* @return the resolution in dpi
*/
protected int getResolution() {
protected AFPPageState getPageState() {
return this.pageState;
}
-
+
/**
* Sets if the current painted shape is to be filled
* @param fill true if the current painted shape is to be filled
*/
public String getImageUri() {
return ((AFPData)getData()).imageUri;
- }
+ }
/** {@inheritDoc} */
public String toString() {
}
/**
- * Page level state data
+ * Page level state data
*/
private class AFPPageState {
/** The current page width */
protected int incrementFontCount() {
return ++fontCount;
}
-
+
/** {@inheritDoc} */
public String toString() {
return "AFPPageState{width=" + width
/** The current fill status */
private boolean filled = false;
-
+
private String imageUri = null;
-
+
/** {@inheritDoc} */
public Object clone() throws CloneNotSupportedException {
AFPData obj = (AFPData)super.clone();
obj.imageUri = this.imageUri;
return obj;
}
-
+
/** {@inheritDoc} */
public String toString() {
return "AFPData{" + super.toString()