[FOray-commit] SF.net SVN: foray: [7896] trunk/foray/foray-render/src/java/org/foray/ render
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-09-05 01:07:26
|
Revision: 7896
http://svn.sourceforge.net/foray/?rev=7896&view=rev
Author: victormote
Date: 2006-09-04 18:07:17 -0700 (Mon, 04 Sep 2006)
Log Message:
-----------
Cleanup magic numbers and other style issues.
Modified Paths:
--------------
trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java
Modified: trunk/foray/foray-render/src/java/org/foray/render/Renderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2006-09-05 00:51:27 UTC (rev 7895)
+++ trunk/foray/foray-render/src/java/org/foray/render/Renderer.java 2006-09-05 01:07:17 UTC (rev 7896)
@@ -87,6 +87,15 @@
public abstract class Renderer extends OutputTarget
implements org.axsl.output.Renderer, org.axsl.areaR.RenderVisitor {
+ /** The number of millipoints in a point. */
+ public static final float MILLIPOINT_CONVERSION_FACTOR = 1000f;
+
+ /** The number of pixels in an inch. */
+ public static final byte PIXELS_PER_INCH = 96;
+
+ /** */
+ public static final int MAXIMUM_INTEGRAL_COLOR_VALUE = 255;
+
AreaTree areaTree;
/**
@@ -135,7 +144,7 @@
}
final Color backgroundColor = area.traitBackgroundColor();
- if (backgroundColor.getAlpha() == 255) {
+ if (backgroundColor.getAlpha() == MAXIMUM_INTEGRAL_COLOR_VALUE) {
this.drawRectangle(x, y, w, -h, false, null, true, backgroundColor);
}
}
@@ -248,7 +257,7 @@
* @return The pixel density, per inch.
*/
public int getPixelsPerInch() {
- return 96;
+ return PIXELS_PER_INCH;
}
/**
@@ -571,10 +580,32 @@
return null;
}
return new Rectangle2D.Float(
- input.x / 1000f,
- input.y / 1000,
- input.width / 1000f,
- input.height / 1000f);
+ toPoints(input.x),
+ toPoints(input.y),
+ toPoints(input.width),
+ toPoints(input.height));
}
+ /**
+ * Converts millipoints to points.
+ * @param millipoints The millipoint value to be converted to points.
+ * @return The converted value in points.
+ */
+ protected static float toPoints(final int millipoints) {
+ return millipoints / MILLIPOINT_CONVERSION_FACTOR;
+ }
+
+ /**
+ * Converts a color value in the range 0 - 255 to its floating-point
+ * equivelant, that is, a value in the range 0 - 1.
+ * @param integralColor The integral color value to be converted, a
+ * value in the range 0 - 255.
+ * @return The floating point value, a value in the range 0 - 1.
+ */
+ protected static float colorToFloat(final int integralColor) {
+ int colorValue = Math.max(integralColor, 0);
+ colorValue = Math.min(integralColor, MAXIMUM_INTEGRAL_COLOR_VALUE);
+ return colorValue / MAXIMUM_INTEGRAL_COLOR_VALUE;
+ }
+
}
Modified: trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java
===================================================================
--- trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2006-09-05 00:51:27 UTC (rev 7895)
+++ trunk/foray/foray-render/src/java/org/foray/render/svg/SVGRenderer.java 2006-09-05 01:07:17 UTC (rev 7896)
@@ -232,8 +232,8 @@
final int lastWidth = pageWidth;
final int lastHeight = pageHeight;
- pageWidth = (int)(page.getWidth() / 1000f + .5);
- pageHeight = (int)(page.getHeight() / 1000f + .5);
+ pageWidth = (int) Math.ceil(toPoints(page.getWidth()));
+ pageHeight = (int) Math.ceil(toPoints(page.getHeight()));
if(lastLink != null && currentPageG != null) {
lastLink.setAttributeNS(null, "xlink:href", "#svgView(viewBox(0, "
@@ -372,7 +372,8 @@
if (img instanceof SVGGraphic) {
try {
final SVGDocument svg = ((SVGGraphic) img).getSVGDocument();
- renderSVGDocument(svg, x / 1000f, pageHeight - y / 1000f);
+ renderSVGDocument(svg, toPoints(x),
+ pageHeight - toPoints(y));
} catch (final GraphicException e) {}
// } else {
@@ -512,8 +513,8 @@
}
public void render(final SVGArea area) {
- final float x = area.rrOriginX() / 1000f;
- final float y = pageHeight - area.rrOriginY() / 1000f;
+ final float x = toPoints(area.rrOriginX());
+ final float y = pageHeight - toPoints(area.rrOriginY());
final Document doc = area.getSVGDocument();
renderSVGDocument(doc, x, y);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|