[FOray-commit] SF.net SVN: foray:[12628] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-02-27 16:57:59
|
Revision: 12628
http://sourceforge.net/p/foray/code/12628
Author: victormote
Date: 2022-02-27 16:57:56 +0000 (Sun, 27 Feb 2022)
Log Message:
-----------
Rename classes for clarity.
Modified Paths:
--------------
trunk/foray/foray-output/src/main/java/org/foray/output/Converter.java
trunk/foray/foray-render/src/main/java/org/foray/render/PrintRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/awt/AwtRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/awt/viewer/PreviewDialogAboutBox.java
trunk/foray/foray-render/src/main/java/org/foray/render/pcl/PclRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/svg/SvgRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/txt/TxtRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/xml/XmlRenderer.java
trunk/foray/foray-render/src/test/java/org/foray/render/RendererTests.java
Added Paths:
-----------
trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget4a.java
trunk/foray/foray-render/src/main/java/org/foray/render/Renderer4a.java
Removed Paths:
-------------
trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget.java
trunk/foray/foray-render/src/main/java/org/foray/render/Renderer.java
Modified: trunk/foray/foray-output/src/main/java/org/foray/output/Converter.java
===================================================================
--- trunk/foray/foray-output/src/main/java/org/foray/output/Converter.java 2022-02-27 16:37:29 UTC (rev 12627)
+++ trunk/foray/foray-output/src/main/java/org/foray/output/Converter.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -29,9 +29,8 @@
package org.foray.output;
/**
- * Abstract superclass for all output targets that do no layout, instead
- * converting directly from the FO Tree.
+ * Abstract superclass for all output targets that do no layout, instead converting directly from the FO Tree.
*/
-public abstract class Converter extends OutputTarget {
+public abstract class Converter extends OutputTarget4a {
}
Deleted: trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget.java
===================================================================
--- trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget.java 2022-02-27 16:37:29 UTC (rev 12627)
+++ trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -1,198 +0,0 @@
-/*
- * Copyright 2005 The FOray Project.
- * http://www.foray.org
- *
- * Licensed 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.output;
-
-import org.axsl.font.FontConsumer;
-import org.axsl.output.OutputConfiguration;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.OutputStream;
-
-/**
- * Abstract superclass for all Renderers and Converters.
- */
-public abstract class OutputTarget implements org.axsl.output.OutputTarget {
-
- /** The stream to which output should be written. */
- private OutputStream outputStream;
-
- /** The name of the application generating the output (used in document
- * metadata). */
- private String applicationName;
-
- /** The short name of the application generating the output (used in
- * document metadata). */
- private String applicationNameShort;
-
- /** The version of the application generating the output (used in document
- * metadata). */
- private String applicationVersion;
-
- /** The short version of the URL of the developer organization creating the
- * output (used in document metadata). */
- private String developerURLShort;
-
- /** Indicates whether SVG text should be stroked in the output document. */
- private boolean strokeSVGText;
-
- /** The logger. */
- private Logger logger;
-
- /** The FontConsumer used by the document. */
- private FontConsumer fontConsumer;
-
- /**
- * Returns the logger.
- * @return The logger.
- */
- public Logger getLogger() {
- if (this.logger == null) {
- this.logger = LoggerFactory.getLogger(this.getClass());
- }
- return this.logger;
- }
-
- /**
- * Returns the FontConsumer.
- * @return The FontConsumer implementation which should be used by this
- * Renderer.
- */
- public FontConsumer getFontConsumer() {
- return this.fontConsumer;
- }
-
- @Override
- public void setOutputStream(final OutputStream stream) {
- this.outputStream = stream;
- }
-
- /**
- * Returns the OutputStream.
- * @return The OutputStream.
- */
- public OutputStream getOutputStream() {
- return this.outputStream;
- }
-
- /**
- * {@inheritDoc}
- * Subclasses that do not need an OutputStream should override this.
- */
- @Override
- public boolean outputStreamRequired() {
- return true;
- }
-
- /**
- * Returns the name of the application creating the output.
- * @return The name of the application creating the output.
- */
- public String getApplicationName() {
- return this.applicationName;
- }
-
- @Override
- public void setApplicationName(final String applicationName) {
- this.applicationName = applicationName;
- }
-
- /**
- * Returns the short name of the application creating the output.
- * @return The "short" name of the application that is creating the
- * output.
- * For example, if the name of the application is "XYZ Document Processor",
- * the short name might be "XYZ".
- */
- public String getApplicationNameShort() {
- return this.applicationNameShort;
- }
-
- @Override
- public void setApplicationNameShort(final String applicationNameShort) {
- this.applicationNameShort = applicationNameShort;
- }
-
- /**
- * Returna the current version of the application that is creating the
- * output.
- * @return The current version of the application that is creating the
- * output.
- */
- public String getApplicationVersion() {
- return this.applicationVersion;
- }
-
- @Override
- public void setApplicationVersion(final String applicationVersion) {
- this.applicationVersion = applicationVersion;
- }
-
- /**
- * Returns a short version of the URL of the developer.
- * @return The shortened version of the URL to the home-page of the
- * developer. For example, if the URL is "http://www.xyz.com", return
- * "www.xyz.com".
- */
- public String getDeveloperURLShort() {
- return this.developerURLShort;
- }
-
- @Override
- public void setDeveloperUrlShort(final String developerURLShort) {
- this.developerURLShort = developerURLShort;
- }
-
- @Override
- public void setStrokeText(final boolean stroke) {
- this.strokeSVGText = stroke;
- }
-
- /**
- * Indicates whether SVG text should be converted to strokes.
- * @return True if SVG text should be converted to strokes instead of
- * rendered as characters of a Font.
- */
- public boolean getStrokeSVGText() {
- return this.strokeSVGText;
- }
-
- @Override
- public void setFontConsumer(final FontConsumer fontConsumer) {
- this.fontConsumer = fontConsumer;
- }
-
- /**
- * Returns the output configuration for this renderer.
- * @return The output configuration for this renderer.
- */
- public abstract OutputConfiguration getOutputConfiguration();
-
-}
Copied: trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget4a.java (from rev 12602, trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget.java)
===================================================================
--- trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget4a.java (rev 0)
+++ trunk/foray/foray-output/src/main/java/org/foray/output/OutputTarget4a.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2005 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.output;
+
+import org.axsl.font.FontConsumer;
+import org.axsl.output.OutputConfiguration;
+import org.axsl.output.OutputTarget;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.OutputStream;
+
+/**
+ * Abstract superclass for all Renderers and Converters.
+ */
+public abstract class OutputTarget4a implements OutputTarget {
+
+ /** The stream to which output should be written. */
+ private OutputStream outputStream;
+
+ /** The name of the application generating the output (used in document
+ * metadata). */
+ private String applicationName;
+
+ /** The short name of the application generating the output (used in
+ * document metadata). */
+ private String applicationNameShort;
+
+ /** The version of the application generating the output (used in document
+ * metadata). */
+ private String applicationVersion;
+
+ /** The short version of the URL of the developer organization creating the
+ * output (used in document metadata). */
+ private String developerURLShort;
+
+ /** Indicates whether SVG text should be stroked in the output document. */
+ private boolean strokeSVGText;
+
+ /** The logger. */
+ private Logger logger;
+
+ /** The FontConsumer used by the document. */
+ private FontConsumer fontConsumer;
+
+ /**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Logger getLogger() {
+ if (this.logger == null) {
+ this.logger = LoggerFactory.getLogger(this.getClass());
+ }
+ return this.logger;
+ }
+
+ /**
+ * Returns the FontConsumer.
+ * @return The FontConsumer implementation which should be used by this
+ * Renderer.
+ */
+ public FontConsumer getFontConsumer() {
+ return this.fontConsumer;
+ }
+
+ @Override
+ public void setOutputStream(final OutputStream stream) {
+ this.outputStream = stream;
+ }
+
+ /**
+ * Returns the OutputStream.
+ * @return The OutputStream.
+ */
+ public OutputStream getOutputStream() {
+ return this.outputStream;
+ }
+
+ /**
+ * {@inheritDoc}
+ * Subclasses that do not need an OutputStream should override this.
+ */
+ @Override
+ public boolean outputStreamRequired() {
+ return true;
+ }
+
+ /**
+ * Returns the name of the application creating the output.
+ * @return The name of the application creating the output.
+ */
+ public String getApplicationName() {
+ return this.applicationName;
+ }
+
+ @Override
+ public void setApplicationName(final String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ /**
+ * Returns the short name of the application creating the output.
+ * @return The "short" name of the application that is creating the
+ * output.
+ * For example, if the name of the application is "XYZ Document Processor",
+ * the short name might be "XYZ".
+ */
+ public String getApplicationNameShort() {
+ return this.applicationNameShort;
+ }
+
+ @Override
+ public void setApplicationNameShort(final String applicationNameShort) {
+ this.applicationNameShort = applicationNameShort;
+ }
+
+ /**
+ * Returna the current version of the application that is creating the
+ * output.
+ * @return The current version of the application that is creating the
+ * output.
+ */
+ public String getApplicationVersion() {
+ return this.applicationVersion;
+ }
+
+ @Override
+ public void setApplicationVersion(final String applicationVersion) {
+ this.applicationVersion = applicationVersion;
+ }
+
+ /**
+ * Returns a short version of the URL of the developer.
+ * @return The shortened version of the URL to the home-page of the
+ * developer. For example, if the URL is "http://www.xyz.com", return
+ * "www.xyz.com".
+ */
+ public String getDeveloperURLShort() {
+ return this.developerURLShort;
+ }
+
+ @Override
+ public void setDeveloperUrlShort(final String developerURLShort) {
+ this.developerURLShort = developerURLShort;
+ }
+
+ @Override
+ public void setStrokeText(final boolean stroke) {
+ this.strokeSVGText = stroke;
+ }
+
+ /**
+ * Indicates whether SVG text should be converted to strokes.
+ * @return True if SVG text should be converted to strokes instead of
+ * rendered as characters of a Font.
+ */
+ public boolean getStrokeSVGText() {
+ return this.strokeSVGText;
+ }
+
+ @Override
+ public void setFontConsumer(final FontConsumer fontConsumer) {
+ this.fontConsumer = fontConsumer;
+ }
+
+ /**
+ * Returns the output configuration for this renderer.
+ * @return The output configuration for this renderer.
+ */
+ public abstract OutputConfiguration getOutputConfiguration();
+
+}
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/PrintRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/PrintRenderer.java 2022-02-27 16:37:29 UTC (rev 12627)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/PrintRenderer.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -45,7 +45,7 @@
/**
* Abstract base class of "Print" type renderers.
*/
-public abstract class PrintRenderer extends Renderer {
+public abstract class PrintRenderer extends Renderer4a {
/** A magic-number constant used to compute the width of leaders when they
* are "double". Presumably the logic is that the width is divided into
Deleted: trunk/foray/foray-render/src/main/java/org/foray/render/Renderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/Renderer.java 2022-02-27 16:37:29 UTC (rev 12627)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/Renderer.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -1,584 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed 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.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known contributors:
- * BoBoGi (graphics rendering)
- */
-
-package org.foray.render;
-
-import org.foray.common.ForayConstants;
-import org.foray.common.WellKnownConstants;
-import org.foray.output.OutputTarget;
-
-import org.axsl.galley.AreaG5;
-import org.axsl.galley.AreaNodeG5;
-import org.axsl.galley.BackgroundAreaG5;
-import org.axsl.galley.BlockContainerAreaG5;
-import org.axsl.galley.BorderPaddingAreaG5;
-import org.axsl.galley.ExternalGraphicAreaG5;
-import org.axsl.galley.ForeignContentG5;
-import org.axsl.galley.ForeignContentMathG5;
-import org.axsl.galley.ForeignContentSvgG5;
-import org.axsl.galley.ForeignObjectAreaG5;
-import org.axsl.galley.Galley;
-import org.axsl.galley.GlyphAreaSequenceG5;
-import org.axsl.galley.GraphicAreaG5;
-import org.axsl.galley.InlineAreaG5;
-import org.axsl.galley.LineAreaG5;
-import org.axsl.galley.NormalBlockAreaG5;
-import org.axsl.galley.PageCollectionG5;
-import org.axsl.galley.PageG5;
-import org.axsl.galley.RegionAreaG5;
-import org.axsl.galley.TableAreaG5;
-import org.axsl.galley.TableCellAreaG5;
-import org.axsl.galley.metadata.BookmarkTreeG5;
-import org.axsl.galley.render.GalleyVisitor;
-import org.axsl.galley.render.GalleyVisitorException;
-import org.axsl.graphic.Graphic;
-import org.axsl.graphic.GraphicException;
-import org.axsl.value.RuleStyle;
-
-import java.awt.Color;
-import java.awt.Rectangle;
-import java.awt.geom.Rectangle2D;
-
-/**
- * Abstract base class for all renderers.
- * Subclasses produce output in some format from an AreaTree or AreaTree
- * fragment.
- */
-public abstract class Renderer extends OutputTarget
- implements org.axsl.output.Renderer, GalleyVisitor<Void> {
-
- /** Magic-number constant used in the conversion of color to gray. */
- protected static final float SHADING_WEIGHT_RED = 0.3f;
- /* TODO: Replace these magic numbers for color-to-gray conversion with
- * AWT methods that convert from one colorspace to another. */
-
- /** Magic-number constant used in the conversion of color to gray. */
- protected static final float SHADING_WEIGHT_GREEN = 0.59f;
-
- /** Magic-number constant used in the conversion of color to gray. */
- protected static final float SHADING_WEIGHT_BLUE = 0.11f;
-
- /** The AreaTree being rendered. */
- private Galley areaTree;
-
- /**
- * Sets the AreaTree to be rendered.
- * @param areaTree The AreaTree to be rendered.
- */
- public void setGalley(final Galley areaTree) {
- this.areaTree = areaTree;
- }
-
- @Override
- public abstract void render(PageG5 page) throws GalleyVisitorException;
-
- /**
- * Marks the border, if any, for the given area.
- * @param area The area whose border is to be drawn.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected abstract void markBorder(BorderPaddingAreaG5 area) throws GalleyVisitorException;
-
- /**
- * Renders an area's background, both image and color.
- * @param area The area whose background should be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected void markBackground(final BackgroundAreaG5 area) throws GalleyVisitorException {
- markBackgroundColor(area);
- markBackgroundImage(area);
- }
-
- /**
- * Renders an area's background color, if any.
- * @param area The area whose background should be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- private void markBackgroundColor(final BackgroundAreaG5 area) throws GalleyVisitorException {
- final Color backgroundColor = area.traitBackgroundColor();
- /* If the background color is totally transparent, don't paint it. */
- if (backgroundColor.getAlpha() == 0) {
- return;
- }
-
- /*
- * Per XSL-FO Spec 1.0, Section 4.9.4, the background is rendered
- * inside the padding-rectangle.
- */
- final int x = area.prOriginX();
- final int y = area.prOriginY();
- final int w = area.prIpd();
- final int h = area.prBpd();
-
- if (h == 0 || w == 0) {
- return;
- }
-
- this.drawRectangle(x, y, w, -h, null, backgroundColor);
- }
-
- /**
- * Renders an area's background image, if any.
- * @param area The area whose background should be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- private void markBackgroundImage(final BackgroundAreaG5 area) throws GalleyVisitorException {
- final Graphic backgroundImage = area.traitBackgroundImage();
- if (backgroundImage == null) {
- return;
- }
- /*
- * Per XSL-FO Spec 1.0, Section 4.9.4, the background is rendered
- * inside the padding-rectangle.
- */
- final int x = area.prOriginX();
- final int y = area.prOriginY();
- final int w = area.prIpd();
- final int h = area.prBpd();
-
- if (h == 0 || w == 0) {
- return;
- }
-
- final int imgW;
- final int imgH;
- try {
- imgW = backgroundImage.absoluteWidth(getPixelsPerInch());
- imgH = backgroundImage.absoluteHeight(getPixelsPerInch());
- } catch (final GraphicException fie) {
- getLogger().error("Error obtaining bg image width and height");
- getLogger().error(fie.getMessage());
- return;
- }
-
- int currentX = x;
- int currentY = y;
- final int endX = x + w;
- final int endY = y - h;
- final int clipW = w % imgW;
- final int clipH = h % imgH;
-
- final boolean repeatX = area.traitBackgroundRepeat()
- .repeatsHorizontal();
- final boolean repeatY = area.traitBackgroundRepeat().repeatsVertical();
-
- Rectangle contentRectangle = null;
- Rectangle clipRectangle = null;
- while (currentY > endY) { // looping through rows
- while (currentX < endX) { // looping through cols
- if (currentX + imgW <= endX) {
- // no x clipping
- if (currentY - imgH >= endY) {
- // no x clipping, no y clipping
- contentRectangle = new Rectangle(currentX, currentY,
- imgW, imgH);
- drawGraphic(area, backgroundImage, contentRectangle,
- null);
- } else {
- // no x clipping, y clipping
- contentRectangle = new Rectangle(currentX, currentY,
- imgW, imgH);
- clipRectangle = new Rectangle(currentX,
- currentY - clipH, imgW, clipH);
- drawGraphic(area, backgroundImage, contentRectangle,
- clipRectangle);
- }
- } else {
- // x clipping
- if (currentY - imgH >= endY) {
- // x clipping, no y clipping
- contentRectangle = new Rectangle(currentX, currentY,
- imgW, imgH);
- clipRectangle = new Rectangle(currentX + clipW,
- currentY, clipW, imgH);
- drawGraphic(area, backgroundImage, contentRectangle,
- clipRectangle);
- } else {
- // x clipping, y clipping
- contentRectangle = new Rectangle(currentX, currentY,
- imgW, imgH);
- clipRectangle = new Rectangle(currentX + clipW,
- currentY - clipH, clipW, clipH);
- drawGraphic(area, backgroundImage, contentRectangle,
- clipRectangle);
- }
- }
-
- if (repeatX) {
- currentX += imgW;
- } else {
- break;
- }
- } // end looping through cols
-
- currentX = x;
-
- if (repeatY) {
- currentY -= imgH;
- } else {
- break;
- }
- } // end looping through rows
- }
-
- /**
- * The pixel density, per inch, that should be used to compute image
- * sizes when only the number of pixels is known.
- * @return The pixel density, per inch.
- */
- public int getPixelsPerInch() {
- return ForayConstants.DEFAULT_SCREEN_RESOLUTION;
- }
-
- /**
- * Draw a line in the output document.
- *
- * @param startX The start x location in millipoints.
- * @param startY The start y location in millipoints.
- * @param endX The end x location in millipoints.
- * @param endY The end y location in millipoints.
- * @param thickness The thickness in millipoints.
- * @param ruleStyle The rule style.
- * @param strokeColor The stroke color.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected abstract void drawLine(int startX, int startY, int endX, int endY,
- int thickness, RuleStyle ruleStyle, Color strokeColor) throws GalleyVisitorException;
-
- /**
- * Draw a rectangle in the output document.
- *
- * @param x The x position of left edge in millipoints.
- * @param y The y position of top edge in millipoints.
- * @param w The width in millipoints.
- * @param h The height in millipoints.
- * @param strokeColor The color to be used for the stroke.
- * Stroked means a box will be drawn around the rectangle.
- * Set to null if the rectangle should not be stroked.
- * @param fillColor The color to be used for the fill.
- * Set to null if the rectangle should not be filled.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected abstract void drawRectangle(int x, int y, int w, int h,
- Color strokeColor, Color fillColor) throws GalleyVisitorException;
-
- /**
- * Renders a Graphic to a given contentRectangle, and clipping it to a given
- * clip rectangle.
- * If the content rectangle is the same as the intrinsic dimensions of the
- * image, no scaling is done.
- * @param area The Area instance from which to obtain traits.
- * @param image The graphic to be rendered.
- * @param contentRectangle The rectangle to which the graphic should be
- * scaled during drawing.
- * @param clipRectangle The rectangle to which the content should be clipped
- * after any scaling.
- * @throws GalleyVisitorException For errors during rendering.
- * @see #drawGraphic(GraphicAreaG5, Graphic, Rectangle, Rectangle)
- */
- protected abstract void drawGraphic(GraphicAreaG5 area, Graphic image,
- Rectangle contentRectangle, Rectangle clipRectangle) throws GalleyVisitorException;
-
- @Override
- public Void visit(final AreaNodeG5 node) throws GalleyVisitorException {
- renderChildren(node);
- return null;
- }
-
- @Override
- public Void visit(final AreaG5 node) throws GalleyVisitorException {
- renderChildren(node);
- return null;
- }
-
- /**
- * Render a page's region areas.
- * @param page The page whose regions should be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected void renderRegions(final PageG5 page) throws GalleyVisitorException {
- for (int index = 0; index < page.qtyRegionBodies(); index ++) {
- final RegionAreaG5 regionBody = page.regionBodyAt(index);
- visit(regionBody);
- }
- if (page.getRegionBefore() != null) {
- visit(page.getRegionBefore());
- }
- if (page.getRegionAfter() != null) {
- visit(page.getRegionAfter());
- }
- if (page.getRegionStart() != null) {
- visit(page.getRegionStart());
- }
- if (page.getRegionEnd() != null) {
- visit(page.getRegionEnd());
- }
- }
-
- @Override
- public Void visit(final BlockContainerAreaG5 area) throws GalleyVisitorException {
- markBorder(area);
- markBackground(area);
- renderChildren(area);
- return null;
- }
-
- @Override
- public Void visit(final RegionAreaG5 area) throws GalleyVisitorException {
- markBackground(area);
- renderChildren(area);
- return null;
- }
-
- /**
- * Render the children of a given node.
- * @param area The area whose children should be rendered.
- * @return Void.
- * @throws GalleyVisitorException For errors during rendering.
- */
- public Void renderChildren(final AreaNodeG5 area) throws GalleyVisitorException {
- for (int i = 0; i < area.qtyAreaNodeChildren(); i++) {
- final AreaNodeG5 child = area.areaNodeChildAt(i);
- child.acceptVisitor(this);
- }
- return null;
- }
-
- @Override
- public Void visit(final NormalBlockAreaG5 area) throws GalleyVisitorException {
- markBorder(area);
- markBackground(area);
- renderChildren(area);
- return null;
- }
-
- /**
- * Render the SVG content of a {@link ForeignObjectAreaG5}.
- * @param svgContent The SVG content to be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- public abstract void render(ForeignContentSvgG5 svgContent) throws GalleyVisitorException;
-
- /**
- * Render the MathML content of a {@link ForeignObjectAreaG5}.
- * @param mathContent The MathML content to be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- public abstract void render(ForeignContentMathG5 mathContent) throws GalleyVisitorException;
-
- @Override
- public Void visit(final ForeignObjectAreaG5 area) throws GalleyVisitorException {
- final ForeignContentG5 foreignContent = area.getContainedForeignObject();
- if (foreignContent == null) {
- this.getLogger().warn("At rendering, ForeignContent area "
- + "has no parsed content");
- return null;
- }
- if (foreignContent instanceof ForeignContentSvgG5) {
- final ForeignContentSvgG5 svgArea =
- (ForeignContentSvgG5) foreignContent;
- render(svgArea);
- } else if (foreignContent instanceof ForeignContentMathG5) {
- final ForeignContentMathG5 mathArea =
- (ForeignContentMathG5) foreignContent;
- render(mathArea);
- } else {
- this.getLogger().warn("At rendering, ForeignContent area "
- + "is of an unsupported type.");
- }
- return null;
- }
-
- @Override
- public Void visit(final ExternalGraphicAreaG5 area) throws GalleyVisitorException {
- final Graphic graphic = area.getGraphic();
- if (graphic == null) {
- throw new NullPointerException("Null graphic.");
- }
- final Rectangle contentRect = new Rectangle(area.crOriginX(),
- area.crOriginY(), area.referenceIpd(), area.referenceBpd());
- final Rectangle clipRect = new Rectangle(area.crOriginX(),
- area.crOriginY(), area.crIpd(), area.crBpd());
- drawGraphic(area, graphic, contentRect, clipRect);
- return null;
- }
-
- @Override
- public Void visit(final TableAreaG5 area) throws GalleyVisitorException {
- /* Render background Areas for the table-related background-only
- * areas. */
- final BackgroundAreaG5[] backgroundAreas = area.getBackgroundAreas();
- if (backgroundAreas != null) {
- for (int i = 0; i < backgroundAreas.length; i++) {
- final BackgroundAreaG5 bga = backgroundAreas[i];
- markBackground(bga);
- }
- }
- /* TODO: Add logic that tries to paint the borders as efficiently
- * as possible. Contiguous cells that have identical borders should have
- * their borders painted at the same time. */
- markBorder(area);
- renderChildren(area);
- return null;
- }
-
- @Override
- public Void visit(final TableCellAreaG5 area) throws GalleyVisitorException {
- markBorder(area);
- markBackground(area);
- renderChildren(area);
- return null;
- }
-
- /**
- * Renders an arbitrary text chunk with attributes from an arbitrary Area.
- * Of course, ordinarily, the text will come from the Area, but the caller
- * should decide that.
- * @param area An Area instance that contains the traits that should be
- * used to render the text.
- * @param text The text content to be rendered.
- * @throws GalleyVisitorException For errors during rendering.
- */
- public abstract void renderTextSegment(GlyphAreaSequenceG5 area, CharSequence text)
- throws GalleyVisitorException;
-
- @Override
- public Void visit(final LineAreaG5 area) throws GalleyVisitorException {
- renderChildren(area);
- return null;
- }
-
- /**
- * Render the bookmark tree for this document.
- * @param bookmarkTree The bookmark tree to be rendered.
- * @throws GalleyVisitorException For invalid bookmark target.
- */
- public abstract void render(BookmarkTreeG5 bookmarkTree) throws GalleyVisitorException;
-
- @Override
- public Void visit(final InlineAreaG5 area) throws GalleyVisitorException {
- markBorder(area);
- markBackground(area);
- renderChildren(area);
- return null;
- }
-
- /**
- * Renders all of the non-area AreaNodes, i.e. those AreaTree nodes that
- * are direct children of AreaTree instead of a PageCollection. This
- * includes items like Destinations and Bookmarks.
- * @throws GalleyVisitorException For errors during rendering.
- */
- protected void renderDocumentNodes() throws GalleyVisitorException {
- final BookmarkTreeG5 bookmarkTree = this.areaTree.getBookmarkTree();
- if (bookmarkTree != null) {
- render(bookmarkTree);
- }
- for (int i = 0; i < this.areaTree.qtyAreaNodeChildren(); i++) {
- final AreaNodeG5 atNode = this.areaTree.areaNodeChildAt(i);
- if (! (atNode instanceof PageCollectionG5)) {
- atNode.acceptVisitor(this);
- }
- }
- }
-
- /**
- * Provides the Renderer with an opportunity to close any text objects that
- * are in progress.
- */
- public abstract void resetTextCursor();
-
- /**
- * Converts a Rectangle storing millipoints to one storing points.
- * @param input A rectangle whose dimensions are stored as millipoints.
- * @return A new rectangle whose dimensions are stored as points.
- */
- public static Rectangle2D.Float convertMillipointRectangle(
- final Rectangle input) {
- if (input == null) {
- return null;
- }
- return new Rectangle2D.Float(
- 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.
- */
- public static float toPoints(final int millipoints) {
- return millipoints / (float) WellKnownConstants.MILLIPOINTS_PER_POINT;
- }
-
- /**
- * Converts a color value in the range 0 - 255 to its floating-point
- * equivalant, that is, a value in the range 0 - 1.
- * @param integralColorComponent 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 integralColorComponent) {
- int colorValue = Math.max(integralColorComponent, 0);
- colorValue = Math.min(integralColorComponent,
- WellKnownConstants.MAXIMUM_INTEGRAL_COLOR_VALUE);
- return colorValue / WellKnownConstants.MAXIMUM_INTEGRAL_COLOR_VALUE;
- }
-
- /**
- * Converts a color to a percentage of black.
- * @param color The color to be converted.
- * @return A value in the range 0 to 100, representing a percentage of
- * black for this color.
- */
- protected static int shadingPercent(final Color color) {
- float lineshade = 0;
- lineshade += Renderer.SHADING_WEIGHT_RED * color.getRed();
- lineshade += Renderer.SHADING_WEIGHT_GREEN * color.getGreen();
- lineshade += Renderer.SHADING_WEIGHT_BLUE * color.getBlue();
- return WellKnownConstants.PERCENT_CONVERSION - (int) (lineshade
- * WellKnownConstants.PERCENT_CONVERSION);
- }
-
- /**
- * Returns the area tree being rendered.
- * @return The area tree being rendered.
- */
- protected Galley getAreaTree() {
- return this.areaTree;
- }
-
-}
Copied: trunk/foray/foray-render/src/main/java/org/foray/render/Renderer4a.java (from rev 12602, trunk/foray/foray-render/src/main/java/org/foray/render/Renderer.java)
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/Renderer4a.java (rev 0)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/Renderer4a.java 2022-02-27 16:57:56 UTC (rev 12628)
@@ -0,0 +1,583 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+/*
+ * Known contributors:
+ * BoBoGi (graphics rendering)
+ */
+
+package org.foray.render;
+
+import org.foray.common.ForayConstants;
+import org.foray.common.WellKnownConstants;
+import org.foray.output.OutputTarget4a;
+
+import org.axsl.galley.AreaG5;
+import org.axsl.galley.AreaNodeG5;
+import org.axsl.galley.BackgroundAreaG5;
+import org.axsl.galley.BlockContainerAreaG5;
+import org.axsl.galley.BorderPaddingAreaG5;
+import org.axsl.galley.ExternalGraphicAreaG5;
+import org.axsl.galley.ForeignContentG5;
+import org.axsl.galley.ForeignContentMathG5;
+import org.axsl.galley.ForeignContentSvgG5;
+import org.axsl.galley.ForeignObjectAreaG5;
+import org.axsl.galley.Galley;
+import org.axsl.galley.GlyphAreaSequenceG5;
+import org.axsl.galley.GraphicAreaG5;
+import org.axsl.galley.InlineAreaG5;
+import org.axsl.galley.LineAreaG5;
+import org.axsl.galley.NormalBlockAreaG5;
+import org.axsl.galley.PageCollectionG5;
+import org.axsl.galley.PageG5;
+import org.axsl.galley.RegionAreaG5;
+import org.axsl.galley.TableAreaG5;
+import org.axsl.galley.TableCellAreaG5;
+import org.axsl.galley.metadata.BookmarkTreeG5;
+import org.axsl.galley.render.GalleyVisitor;
+import org.axsl.galley.render.GalleyVisitorException;
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.output.Renderer;
+import org.axsl.value.RuleStyle;
+
+import java.awt.Color;
+import java.awt.Rectangle;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Abstract base class for all renderers.
+ * Subclasses produce output in some format from an AreaTree or AreaTree fragment.
+ */
+public abstract class Renderer4a extends OutputTarget4a implements Renderer, GalleyVisitor<Void> {
+
+ /** Magic-number constant used in the conversion of color to gray. */
+ protected static final float SHADING_WEIGHT_RED = 0.3f;
+ /* TODO: Replace these magic numbers for color-to-gray conversion with
+ * AWT methods that convert from one colorspace to another. */
+
+ /** Magic-number constant used in the conversion of color to gray. */
+ protected static final float SHADING_WEIGHT_GREEN = 0.59f;
+
+ /** Magic-number constant used in the conversion of color to gray. */
+ protected static final float SHADING_WEIGHT_BLUE = 0.11f;
+
+ /** The AreaTree being rendered. */
+ private Galley areaTree;
+
+ /**
+ * Sets the AreaTree to be rendered.
+ * @param areaTree The AreaTree to be rendered.
+ */
+ public void setGalley(final Galley areaTree) {
+ this.areaTree = areaTree;
+ }
+
+ @Override
+ public abstract void render(PageG5 page) throws GalleyVisitorException;
+
+ /**
+ * Marks the border, if any, for the given area.
+ * @param area The area whose border is to be drawn.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected abstract void markBorder(BorderPaddingAreaG5 area) throws GalleyVisitorException;
+
+ /**
+ * Renders an area's background, both image and color.
+ * @param area The area whose background should be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected void markBackground(final BackgroundAreaG5 area) throws GalleyVisitorException {
+ markBackgroundColor(area);
+ markBackgroundImage(area);
+ }
+
+ /**
+ * Renders an area's background color, if any.
+ * @param area The area whose background should be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ private void markBackgroundColor(final BackgroundAreaG5 area) throws GalleyVisitorException {
+ final Color backgroundColor = area.traitBackgroundColor();
+ /* If the background color is totally transparent, don't paint it. */
+ if (backgroundColor.getAlpha() == 0) {
+ return;
+ }
+
+ /*
+ * Per XSL-FO Spec 1.0, Section 4.9.4, the background is rendered
+ * inside the padding-rectangle.
+ */
+ final int x = area.prOriginX();
+ final int y = area.prOriginY();
+ final int w = area.prIpd();
+ final int h = area.prBpd();
+
+ if (h == 0 || w == 0) {
+ return;
+ }
+
+ this.drawRectangle(x, y, w, -h, null, backgroundColor);
+ }
+
+ /**
+ * Renders an area's background image, if any.
+ * @param area The area whose background should be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ private void markBackgroundImage(final BackgroundAreaG5 area) throws GalleyVisitorException {
+ final Graphic backgroundImage = area.traitBackgroundImage();
+ if (backgroundImage == null) {
+ return;
+ }
+ /*
+ * Per XSL-FO Spec 1.0, Section 4.9.4, the background is rendered
+ * inside the padding-rectangle.
+ */
+ final int x = area.prOriginX();
+ final int y = area.prOriginY();
+ final int w = area.prIpd();
+ final int h = area.prBpd();
+
+ if (h == 0 || w == 0) {
+ return;
+ }
+
+ final int imgW;
+ final int imgH;
+ try {
+ imgW = backgroundImage.absoluteWidth(getPixelsPerInch());
+ imgH = backgroundImage.absoluteHeight(getPixelsPerInch());
+ } catch (final GraphicException fie) {
+ getLogger().error("Error obtaining bg image width and height");
+ getLogger().error(fie.getMessage());
+ return;
+ }
+
+ int currentX = x;
+ int currentY = y;
+ final int endX = x + w;
+ final int endY = y - h;
+ final int clipW = w % imgW;
+ final int clipH = h % imgH;
+
+ final boolean repeatX = area.traitBackgroundRepeat()
+ .repeatsHorizontal();
+ final boolean repeatY = area.traitBackgroundRepeat().repeatsVertical();
+
+ Rectangle contentRectangle = null;
+ Rectangle clipRectangle = null;
+ while (currentY > endY) { // looping through rows
+ while (currentX < endX) { // looping through cols
+ if (currentX + imgW <= endX) {
+ // no x clipping
+ if (currentY - imgH >= endY) {
+ // no x clipping, no y clipping
+ contentRectangle = new Rectangle(currentX, currentY,
+ imgW, imgH);
+ drawGraphic(area, backgroundImage, contentRectangle,
+ null);
+ } else {
+ // no x clipping, y clipping
+ contentRectangle = new Rectangle(currentX, currentY,
+ imgW, imgH);
+ clipRectangle = new Rectangle(currentX,
+ currentY - clipH, imgW, clipH);
+ drawGraphic(area, backgroundImage, contentRectangle,
+ clipRectangle);
+ }
+ } else {
+ // x clipping
+ if (currentY - imgH >= endY) {
+ // x clipping, no y clipping
+ contentRectangle = new Rectangle(currentX, currentY,
+ imgW, imgH);
+ clipRectangle = new Rectangle(currentX + clipW,
+ currentY, clipW, imgH);
+ drawGraphic(area, backgroundImage, contentRectangle,
+ clipRectangle);
+ } else {
+ // x clipping, y clipping
+ contentRectangle = new Rectangle(currentX, currentY,
+ imgW, imgH);
+ clipRectangle = new Rectangle(currentX + clipW,
+ currentY - clipH, clipW, clipH);
+ drawGraphic(area, backgroundImage, contentRectangle,
+ clipRectangle);
+ }
+ }
+
+ if (repeatX) {
+ currentX += imgW;
+ } else {
+ break;
+ }
+ } // end looping through cols
+
+ currentX = x;
+
+ if (repeatY) {
+ currentY -= imgH;
+ } else {
+ break;
+ }
+ } // end looping through rows
+ }
+
+ /**
+ * The pixel density, per inch, that should be used to compute image
+ * sizes when only the number of pixels is known.
+ * @return The pixel density, per inch.
+ */
+ public int getPixelsPerInch() {
+ return ForayConstants.DEFAULT_SCREEN_RESOLUTION;
+ }
+
+ /**
+ * Draw a line in the output document.
+ *
+ * @param startX The start x location in millipoints.
+ * @param startY The start y location in millipoints.
+ * @param endX The end x location in millipoints.
+ * @param endY The end y location in millipoints.
+ * @param thickness The thickness in millipoints.
+ * @param ruleStyle The rule style.
+ * @param strokeColor The stroke color.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected abstract void drawLine(int startX, int startY, int endX, int endY,
+ int thickness, RuleStyle ruleStyle, Color strokeColor) throws GalleyVisitorException;
+
+ /**
+ * Draw a rectangle in the output document.
+ *
+ * @param x The x position of left edge in millipoints.
+ * @param y The y position of top edge in millipoints.
+ * @param w The width in millipoints.
+ * @param h The height in millipoints.
+ * @param strokeColor The color to be used for the stroke.
+ * Stroked means a box will be drawn around the rectangle.
+ * Set to null if the rectangle should not be stroked.
+ * @param fillColor The color to be used for the fill.
+ * Set to null if the rectangle should not be filled.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected abstract void drawRectangle(int x, int y, int w, int h,
+ Color strokeColor, Color fillColor) throws GalleyVisitorException;
+
+ /**
+ * Renders a Graphic to a given contentRectangle, and clipping it to a given
+ * clip rectangle.
+ * If the content rectangle is the same as the intrinsic dimensions of the
+ * image, no scaling is done.
+ * @param area The Area instance from which to obtain traits.
+ * @param image The graphic to be rendered.
+ * @param contentRectangle The rectangle to which the graphic should be
+ * scaled during drawing.
+ * @param clipRectangle The rectangle to which the content should be clipped
+ * after any scaling.
+ * @throws GalleyVisitorException For errors during rendering.
+ * @see #drawGraphic(GraphicAreaG5, Graphic, Rectangle, Rectangle)
+ */
+ protected abstract void drawGraphic(GraphicAreaG5 area, Graphic image,
+ Rectangle contentRectangle, Rectangle clipRectangle) throws GalleyVisitorException;
+
+ @Override
+ public Void visit(final AreaNodeG5 node) throws GalleyVisitorException {
+ renderChildren(node);
+ return null;
+ }
+
+ @Override
+ public Void visit(final AreaG5 node) throws GalleyVisitorException {
+ renderChildren(node);
+ return null;
+ }
+
+ /**
+ * Render a page's region areas.
+ * @param page The page whose regions should be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected void renderRegions(final PageG5 page) throws GalleyVisitorException {
+ for (int index = 0; index < page.qtyRegionBodies(); index ++) {
+ final RegionAreaG5 regionBody = page.regionBodyAt(index);
+ visit(regionBody);
+ }
+ if (page.getRegionBefore() != null) {
+ visit(page.getRegionBefore());
+ }
+ if (page.getRegionAfter() != null) {
+ visit(page.getRegionAfter());
+ }
+ if (page.getRegionStart() != null) {
+ visit(page.getRegionStart());
+ }
+ if (page.getRegionEnd() != null) {
+ visit(page.getRegionEnd());
+ }
+ }
+
+ @Override
+ public Void visit(final BlockContainerAreaG5 area) throws GalleyVisitorException {
+ markBorder(area);
+ markBackground(area);
+ renderChildren(area);
+ return null;
+ }
+
+ @Override
+ public Void visit(final RegionAreaG5 area) throws GalleyVisitorException {
+ markBackground(area);
+ renderChildren(area);
+ return null;
+ }
+
+ /**
+ * Render the children of a given node.
+ * @param area The area whose children should be rendered.
+ * @return Void.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ public Void renderChildren(final AreaNodeG5 area) throws GalleyVisitorException {
+ for (int i = 0; i < area.qtyAreaNodeChildren(); i++) {
+ final AreaNodeG5 child = area.areaNodeChildAt(i);
+ child.acceptVisitor(this);
+ }
+ return null;
+ }
+
+ @Override
+ public Void visit(final NormalBlockAreaG5 area) throws GalleyVisitorException {
+ markBorder(area);
+ markBackground(area);
+ renderChildren(area);
+ return null;
+ }
+
+ /**
+ * Render the SVG content of a {@link ForeignObjectAreaG5}.
+ * @param svgContent The SVG content to be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ public abstract void render(ForeignContentSvgG5 svgContent) throws GalleyVisitorException;
+
+ /**
+ * Render the MathML content of a {@link ForeignObjectAreaG5}.
+ * @param mathContent The MathML content to be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ public abstract void render(ForeignContentMathG5 mathContent) throws GalleyVisitorException;
+
+ @Override
+ public Void visit(final ForeignObjectAreaG5 area) throws GalleyVisitorException {
+ final ForeignContentG5 foreignContent = area.getContainedForeignObject();
+ if (foreignContent == null) {
+ this.getLogger().warn("At rendering, ForeignContent area "
+ + "has no parsed content");
+ return null;
+ }
+ if (foreignContent instanceof ForeignContentSvgG5) {
+ final ForeignContentSvgG5 svgArea =
+ (ForeignContentSvgG5) foreignContent;
+ render(svgArea);
+ } else if (foreignContent instanceof ForeignContentMathG5) {
+ final ForeignContentMathG5 mathArea =
+ (ForeignContentMathG5) foreignContent;
+ render(mathArea);
+ } else {
+ this.getLogger().warn("At rendering, ForeignContent area "
+ + "is of an unsupported type.");
+ }
+ return null;
+ }
+
+ @Override
+ public Void visit(final ExternalGraphicAreaG5 area) throws GalleyVisitorException {
+ final Graphic graphic = area.getGraphic();
+ if (graphic == null) {
+ throw new NullPointerException("Null graphic.");
+ }
+ final Rectangle contentRect = new Rectangle(area.crOriginX(),
+ area.crOriginY(), area.referenceIpd(), area.referenceBpd());
+ final Rectangle clipRect = new Rectangle(area.crOriginX(),
+ area.crOriginY(), area.crIpd(), area.crBpd());
+ drawGraphic(area, graphic, contentRect, clipRect);
+ return null;
+ }
+
+ @Override
+ public Void visit(final TableAreaG5 area) throws GalleyVisitorException {
+ /* Render background Areas for the table-related background-only
+ * areas. */
+ final BackgroundAreaG5[] backgroundAreas = area.getBackgroundAreas();
+ if (backgroundAreas != null) {
+ for (int i = 0; i < backgroundAreas.length; i++) {
+ final BackgroundAreaG5 bga = backgroundAreas[i];
+ markBackground(bga);
+ }
+ }
+ /* TODO: Add logic that tries to paint the borders as efficiently
+ * as possible. Contiguous cells that have identical borders should have
+ * their borders painted at the same time. */
+ markBorder(area);
+ renderChildren(area);
+ return null;
+ }
+
+ @Override
+ public Void visit(final TableCellAreaG5 area) throws GalleyVisitorException {
+ markBorder(area);
+ markBackground(area);
+ renderChildren(area);
+ return null;
+ }
+
+ /**
+ * Renders an arbitrary text chunk with attributes from an arbitrary Area.
+ * Of course, ordinarily, the text will come from the Area, but the caller
+ * should decide that.
+ * @param area An Area instance that contains the traits that should be
+ * used to render the text.
+ * @param text The text content to be rendered.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ public abstract void renderTextSegment(GlyphAreaSequenceG5 area, CharSequence text)
+ throws GalleyVisitorException;
+
+ @Override
+ public Void visit(final LineAreaG5 area) throws GalleyVisitorException {
+ renderChildren(area);
+ return null;
+ }
+
+ /**
+ * Render the bookmark tree for this document.
+ * @param bookmarkTree The bookmark tree to be rendered.
+ * @throws GalleyVisitorException For invalid bookmark target.
+ */
+ public abstract void render(BookmarkTreeG5 bookmarkTree) throws GalleyVisitorException;
+
+ @Override
+ public Void visit(final InlineAreaG5 area) throws GalleyVisitorException {
+ markBorder(area);
+ markBackground(area);
+ renderChildren(area);
+ return null;
+ }
+
+ /**
+ * Renders all of the non-area AreaNodes, i.e. those AreaTree nodes that
+ * are direct children of AreaTree instead of a PageCollection. This
+ * includes items like Destinations and Bookmarks.
+ * @throws GalleyVisitorException For errors during rendering.
+ */
+ protected void renderDocumentNodes() throws GalleyVisitorException {
+ final BookmarkTreeG5 bookmarkTree = this.areaTree.getBookmarkTree();
+ if (bookmarkTree != null) {
+ render(bookmarkTree);
+ }
+ for (int i = 0; i < this.areaTree.qtyAreaNodeChildren(); i++) {
+ final AreaNodeG5 atNode = this.areaTree.areaNodeChildAt(i);
+ if (! (atNode instanceof PageCollectionG5)) {
+ atNode.acceptVisitor(this);
+ }
+ }
+ }
+
+ /**
+ * Provides the Renderer with an opportunity to close any text objects that
+ * are in progress.
+ */
+ public abstract void resetTextCursor();
+
+ /**
+ * Converts a Rectangle storing millipoints to one storing points.
+ * @param input A rectangle whose dimensions are stored as millipoints.
+ * @return A new rectangle whose dimensions are stored as points.
+ */
+ public static Rectangle2D.Float convertMillipointRectangle(
+ final Rectangle input) {
+ if (input == null) {
+ return null;
+ }
+ return new Rectangle2D.Float(
+ 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.
+ */
+ public static float toPoints(final int millipoints) {
+ return millipoints / (float) WellKnownConstants.MILLIPOINTS_PER_POINT;
+ }
+
+ /**
+ * Converts a color value in the range 0 - 255 to its floating-point
+ * equivalant, that is, a value in the range 0 - 1.
+ * @param integralColorComponent 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 integralColorComponent) {
+ int colorValue = Math.max(integralColorComponent, 0);
+ colorValue = Math.min(integralColorComponent,
+ WellKnownConstants.MAXIMUM_INTEGRAL_COLOR_VALUE);
+ return colorValue / WellKnownConstants.MAXIMUM_INTEGRAL_COLOR_VALUE;
+ }
+
+ /**
+ * Converts a color to a percentage of black.
+ * @param color The color to be converted.
+ * @return A value in the range 0 to 100, representing a percentage of
+ * black for this color.
+ */
+ protected static int shadingPercent(final Color color) {
+ float lineshade = 0;
+ lineshade += Renderer4a.SHADING_WEIGHT_RED * color.getRed();
+ lineshade += Renderer4a.SHADING_WEIGHT_GREEN * color.getGreen();
+ lineshade += Renderer4a.SHADING_WEIGHT_BLUE * color.getBlue();
+ r...
[truncated message content] |