foray-commit Mailing List for FOray (Page 82)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(4) |
Dec
|
|
From: <vic...@us...> - 2021-01-20 17:34:51
|
Revision: 11844
http://sourceforge.net/p/foray/code/11844
Author: victormote
Date: 2021-01-20 17:34:49 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Minor cleanup on graphics test document.
Modified Paths:
--------------
trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
Modified: trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 17:30:03 UTC (rev 11843)
+++ trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 17:34:49 UTC (rev 11844)
@@ -204,7 +204,8 @@
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An SVG graphic with Text from an Embedded Font. The font chosen is called "Saturn" and was
+ space-after="2em">An SVG graphic with Text from an Embedded Font.</fo:block>
+ <fo:block>The font chosen is called "Saturn" and was
chosen primarily because it is in the public domain and because it is not likely to be confused with another typeface.
Specifically, each glyph in the font looks like it is painted onto the planet Saturn.</fo:block>
<fo:block>
@@ -304,7 +305,7 @@
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">MathML Examples in an external-graphic</fo:block>
+ space-after="2em">MathML Examples</fo:block>
<fo:block>The following is from an external-graphic:</fo:block>
<fo:block>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 17:30:07
|
Revision: 11843
http://sourceforge.net/p/foray/code/11843
Author: victormote
Date: 2021-01-20 17:30:03 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Add SVG test documents for linear and radial gradients.
Modified Paths:
--------------
trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
Modified: trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 15:58:55 UTC (rev 11842)
+++ trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 17:30:03 UTC (rev 11843)
@@ -126,94 +126,180 @@
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
+
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An SVG graphic</fo:block>
+ space-after="2em">An EPS graphic (Bar Code)</fo:block>
<fo:block>
- <fo:external-graphic src="url('../svg/boxes.svg')"/>
+ <fo:external-graphic src="url('../graphics/barcode1.eps')"
+ content-height="2in"/>
</fo:block>
+
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
+
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An SVG graphic with Text</fo:block>
+ space-after="2em">An EPS graphic (Coffee Shop Symbol)</fo:block>
<fo:block>
- <fo:external-graphic src="url('../svg/text-001.svg')"/>
+ <fo:external-graphic src="url('../graphics/29_coffeeshop_inv.ps')"
+ content-height="2in"/>
</fo:block>
+
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
+
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An SVG graphic with Text from an Embedded Font</fo:block>
+ space-after="2em">An Embedded PDF</fo:block>
<fo:block>
- <fo:external-graphic src="url('../svg/font-embed.svg')"/>
+ <fo:external-graphic src="url('../graphics/01_telephone_inv.pdf')"
+ content-height="2in"/>
</fo:block>
+
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
-
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An EPS graphic (Bar Code)</fo:block>
+ space-after="2em">An SVG graphic</fo:block>
<fo:block>
- <fo:external-graphic src="url('../graphics/barcode1.eps')"
- content-height="2in"/>
+ <fo:external-graphic src="url('../svg/boxes.svg')"/>
</fo:block>
-
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
-
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An EPS graphic (Coffee Shop Symbol)</fo:block>
+ space-after="2em">An SVG graphic with Text</fo:block>
<fo:block>
- <fo:external-graphic src="url('../graphics/29_coffeeshop_inv.ps')"
- content-height="2in"/>
+ <fo:external-graphic src="url('../svg/text-001.svg')"/>
</fo:block>
-
</fo:flow>
</fo:page-sequence>
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
-
<fo:block
font-size="16pt"
font-weight="bold"
space-before="2em"
- space-after="2em">An Embedded PDF</fo:block>
+ space-after="2em">An SVG graphic with Text from an Embedded Font. The font chosen is called "Saturn" and was
+chosen primarily because it is in the public domain and because it is not likely to be confused with another typeface.
+Specifically, each glyph in the font looks like it is painted onto the planet Saturn.</fo:block>
<fo:block>
- <fo:external-graphic src="url('../graphics/01_telephone_inv.pdf')"
- content-height="2in"/>
+ <fo:external-graphic src="url('../svg/font-embed.svg')"/>
</fo:block>
+</fo:flow>
+</fo:page-sequence>
+
+
+<fo:page-sequence master-reference="psmOddEven">
+<fo:flow flow-name="xsl-region-body">
+ <fo:block
+ font-size="16pt"
+ font-weight="bold"
+ space-before="2em"
+ space-after="2em">An SVG graphic containing two linear gradients.</fo:block>
+
+ <fo:block>See https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients for baseline.
+ <fo:instream-foreign-object>
+
+<svg
+ version="1.1"
+ xmlns="http://www.w3.org/2000/svg" width="120" height="240">
+ <defs>
+ <linearGradient id="Gradient1">
+ <stop class="stop1" offset="0%"/>
+ <stop class="stop2" offset="50%"/>
+ <stop class="stop3" offset="100%"/>
+ </linearGradient>
+ <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
+ <stop offset="0%" stop-color="red"/>
+ <stop offset="50%" stop-color="black" stop-opacity="0"/>
+ <stop offset="100%" stop-color="blue"/>
+ </linearGradient>
+ <style type="text/css"><![CDATA[
+ #rect1 { fill: url(#Gradient1); }
+ .stop1 { stop-color: red; }
+ .stop2 { stop-color: black; stop-opacity: 0; }
+ .stop3 { stop-color: blue; }
+ ]]></style>
+ </defs>
+
+ <rect id="rect1" x="10" y="10" rx="15" ry="15" width="100" height="100"/>
+ <rect x="10" y="120" rx="15" ry="15" width="100" height="100" fill="url(#Gradient2)"/>
+</svg>
+
+ </fo:instream-foreign-object>
+ </fo:block>
</fo:flow>
</fo:page-sequence>
+
+
+
+
<fo:page-sequence master-reference="psmOddEven">
<fo:flow flow-name="xsl-region-body">
+ <fo:block
+ font-size="16pt"
+ font-weight="bold"
+ space-before="2em"
+ space-after="2em">An SVG graphic containing two radial gradients.</fo:block>
+ <fo:block>See https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients for baseline.
+ <fo:instream-foreign-object>
+<svg
+ version="1.1" xmlns="http://www.w3.org/2000/svg"
+ width="120" height="240">
+ <defs>
+ <radialGradient id="RadialGradient1">
+ <stop offset="0%" stop-color="red"/>
+ <stop offset="100%" stop-color="blue"/>
+ </radialGradient>
+ <radialGradient id="RadialGradient2" cx="0.25" cy="0.25" r="0.25">
+ <stop offset="0%" stop-color="red"/>
+ <stop offset="100%" stop-color="blue"/>
+ </radialGradient>
+ </defs>
+
+ <rect x="10" y="10" rx="15" ry="15" width="100" height="100" fill="url(#RadialGradient1)"/>
+ <rect x="10" y="120" rx="15" ry="15" width="100" height="100" fill="url(#RadialGradient2)"/>
+
+</svg>
+ </fo:instream-foreign-object>
+ </fo:block>
+</fo:flow>
+</fo:page-sequence>
+
+
+
+
+<fo:page-sequence master-reference="psmOddEven">
+<fo:flow flow-name="xsl-region-body">
+
<fo:block
font-size="16pt"
font-weight="bold"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 15:59:02
|
Revision: 11842
http://sourceforge.net/p/foray/code/11842
Author: victormote
Date: 2021-01-20 15:58:55 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Minor changes to test documents.
Modified Paths:
--------------
trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg
trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg
trunk/foray/master/dist/resource/fo-examples/svg/multi.svg
trunk/foray/master/dist/resource/fo-examples/svg/ref.svg
trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg
trunk/foray/master/dist/resource/fo-examples/svg/view.svg
Modified: trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/basic/graphics.fo 2021-01-20 15:58:55 UTC (rev 11842)
@@ -51,9 +51,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A GIF image</fo:block>
+ space-before="2em"
+ space-after="2em">A GIF image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/xml_feather.gif')"/>
</fo:block>
@@ -65,9 +64,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A transparent GIF image</fo:block>
+ space-before="2em"
+ space-after="2em">A transparent GIF image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/xml_feather_transparent.gif')"/>
</fo:block>
@@ -79,9 +77,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A JPEG image</fo:block>
+ space-before="2em"
+ space-after="2em">A JPEG image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/jpeg-test1.jpg')"/>
</fo:block>
@@ -93,9 +90,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A BMP image</fo:block>
+ space-before="2em"
+ space-after="2em">A BMP image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/linux.bmp')"/>
</fo:block>
@@ -107,9 +103,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A PNG image</fo:block>
+ space-before="2em"
+ space-after="2em">A PNG image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/png-test1.png')"/>
</fo:block>
@@ -121,9 +116,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">A TIFF image</fo:block>
+ space-before="2em"
+ space-after="2em">A TIFF image</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/xml_fax.tif')"/>
</fo:block>
@@ -135,9 +129,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An SVG graphic</fo:block>
+ space-before="2em"
+ space-after="2em">An SVG graphic</fo:block>
<fo:block>
<fo:external-graphic src="url('../svg/boxes.svg')"/>
</fo:block>
@@ -149,9 +142,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An SVG graphic with Text</fo:block>
+ space-before="2em"
+ space-after="2em">An SVG graphic with Text</fo:block>
<fo:block>
<fo:external-graphic src="url('../svg/text-001.svg')"/>
</fo:block>
@@ -163,10 +155,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An SVG graphic with Text from an
-Embedded Font</fo:block>
+ space-before="2em"
+ space-after="2em">An SVG graphic with Text from an Embedded Font</fo:block>
<fo:block>
<fo:external-graphic src="url('../svg/font-embed.svg')"/>
</fo:block>
@@ -179,9 +169,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An EPS graphic (Bar Code)</fo:block>
+ space-before="2em"
+ space-after="2em">An EPS graphic (Bar Code)</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/barcode1.eps')"
content-height="2in"/>
@@ -196,9 +185,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An EPS graphic (Coffee Shop Symbol)</fo:block>
+ space-before="2em"
+ space-after="2em">An EPS graphic (Coffee Shop Symbol)</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/29_coffeeshop_inv.ps')"
content-height="2in"/>
@@ -213,9 +201,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-before.minimum="1em"
- space-before.optimum="1.5em"
- space-before.maximum="2em">An Embedded PDF</fo:block>
+ space-before="2em"
+ space-after="2em">An Embedded PDF</fo:block>
<fo:block>
<fo:external-graphic src="url('../graphics/01_telephone_inv.pdf')"
content-height="2in"/>
@@ -230,9 +217,8 @@
<fo:block
font-size="16pt"
font-weight="bold"
- space-after.minimum="1em"
- space-after.optimum="1.5em"
- space-after.maximum="2em">MathML Examples in an external-graphic</fo:block>
+ space-before="2em"
+ space-after="2em">MathML Examples in an external-graphic</fo:block>
<fo:block>The following is from an external-graphic:</fo:block>
<fo:block>
Modified: trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
-"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<svg
xmlns="http://www.w3.org/2000/svg"
width="20" height="20" xml:space="preserve">
Modified: trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
- "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<!--
This document tests the ability to handle a font that is embedded directly
in the SVG content. The font chosen is called "Saturn" and was chosen
Modified: trunk/foray/master/dist/resource/fo-examples/svg/multi.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/multi.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/multi.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
-"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
Modified: trunk/foray/master/dist/resource/fo-examples/svg/ref.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/ref.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/ref.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
-"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<svg
xmlns="http://www.w3.org/2000/svg"
width="20" height="20" xml:space="preserve">
Modified: trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
- "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<!--
This document tests the ability of writing some simple text.
-->
Modified: trunk/foray/master/dist/resource/fo-examples/svg/view.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/view.svg 2021-01-20 14:31:37 UTC (rev 11841)
+++ trunk/foray/master/dist/resource/fo-examples/svg/view.svg 2021-01-20 15:58:55 UTC (rev 11842)
@@ -1,7 +1,8 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
-"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 10 10" width="20" height="20" xml:space="preserve">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 14:31:39
|
Revision: 11841
http://sourceforge.net/p/foray/code/11841
Author: victormote
Date: 2021-01-20 14:31:37 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
1. Break PdfDashPattern into a separate class. 2. Clean up some doc.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 12:02:48 UTC (rev 11840)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 14:31:37 UTC (rev 11841)
@@ -29,40 +29,60 @@
package org.foray.pdf;
import org.foray.pdf.object.PdfColor4a;
+import org.foray.pdf.object.PdfDashPattern;
import org.axsl.pdf.PdfColor;
import org.axsl.pdf.PdfLineCapStyle;
+import lombok.Getter;
+
/**
- * Represents a PDF Graphics State object. The Graphics State is ordinarily
- * used by PDF viewer applications. Our application is instead a PDF writing
- * application. However keeping track of the Graphics State is useful because
- * it allows us to avoid writing operators that change the Graphics State
- * unnecessarily.
+ * The PDF graphics state.
+ * Tracks the current state of various properties used to render content, such as colors and fonts.
+ * The PDF Reference distinguishes between graphics state parameters that are device-independent and those that are
+ * device-dependent.
+ * While rendering the PDF document, we care only about those that are device-independent, and therefore track only
+ * those in this class.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
*/
public class PdfGraphicsState {
- /** Constant for the initial horizontal scaling percentage, that is 100%. */
- public static final float INITIAL_HORIZONTAL_SCALING = 100;
-
- /** The stroke color. */
+ /**
+ * The stroke color.
+ * @return The stroke color.
+ */
+ @Getter
private PdfColor strokeColor;
- /** The "non-stroke" or "other" color. */
+ /**
+ * The "non-stroke" or "other" color.
+ * @return The non-stroke or other color.
+ */
+ @Getter
private PdfColor fillColor;
- /** The text state. */
+ /**
+ * The text state.
+ * @return The text state.
+ */
+ @Getter
private PdfTextState textState = new PdfTextState();
- /** The dash array. */
- private float[] dashArray;
-
- /** The dash phase. */
- private float dashPhase;
-
- /** The line cap style. */
+ /**
+ * The line cap style.
+ * @return The line cap style.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+ @Getter
private PdfLineCapStyle lineCapStyle;
+ /**
+ * The dash pattern.
+ * @return The dash pattern.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+ @Getter
+ private PdfDashPattern dashPattern;
/**
* Create a PdfGraphicsState instance.
@@ -72,41 +92,36 @@
}
/**
- * Creates a new PdfGraphicsState instance, initilializing its values to
- * those of an existing instance.
- * @param existingState The instance whose values should be copied into the
- * new instance.
+ * Creates a new PdfGraphicsState instance, initilializing its values to those of an existing instance.
+ * @param existingState The instance whose values should be copied into the new instance.
*/
public PdfGraphicsState(final PdfGraphicsState existingState) {
this.strokeColor = existingState.strokeColor;
this.fillColor = existingState.fillColor;
- this.dashArray = new float[existingState.dashArray.length];
- System.arraycopy(existingState.dashArray, 0, this.dashArray, 0,
- existingState.dashArray.length);
- this.dashPhase = existingState.dashPhase;
+ this.textState = new PdfTextState(this.textState);
this.lineCapStyle = existingState.lineCapStyle;
-
- this.textState = new PdfTextState(this.textState);
+ this.dashPattern = existingState.dashPattern;
}
/**
- * Resets the Graphics State to its original state, as documented in
- * PDF Reference, 3rd Edition, Section 4.3.
+ * Resets each property in the Graphics State to its initial state.
+ * The initial state values are documented in Table 4.2 in "PDF Reference, Sixth Edition (PDF Version 1.7), Section
+ * 4.3."
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
*/
public void reset() {
this.strokeColor = PdfColor4a.BLACK;
this.fillColor = PdfColor4a.BLACK;
this.textState.reset();
- this.dashArray = new float[0];
- this.dashPhase = 0;
this.lineCapStyle = PdfLineCapStyle.BUTT_CAP;
+ this.dashPattern = PdfDashPattern.SOLID_LINE;
}
/**
- * Sets the stroke color (Graphics State holds two colors, one for stroke
- * operations and one for all other operations).
- * @param newStrokeColor The color that stroke operations should now use.
- * @return True if the Graphics State was changed by this operation.
+ * Sets the stroke color.
+ * @param newStrokeColor The new stroke color.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getStrokeColor()
*/
public boolean setStrokeColor(final PdfColor newStrokeColor) {
if (newStrokeColor == null) {
@@ -121,21 +136,11 @@
}
/**
- * Returns the "stroke" color.
- * @return The stroke color.
+ * Sets the "non-stroke" or "other" or "fill" color.
+ * @param newFillColor The new non-stroke color.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getFillColor()
*/
- public PdfColor getStrokeColor() {
- return this.strokeColor;
- }
-
- /**
- * Sets the "non-stroke" or "other" color (Graphics State holds two colors,
- * one for stroke operations and one for all other operations). This is the
- * one for all other operations. The name "fill" was chosen because that is
- * the common use for this color.
- * @param newFillColor The color that non-stroke operations should now use.
- * @return True if the Graphics State was changed by this operation.
- */
public boolean setFillColor(final PdfColor newFillColor) {
if (newFillColor == null) {
return false;
@@ -149,76 +154,15 @@
}
/**
- * Returns the "non-stroke" or "other" color.
- * @return The fill color.
+ * Sets the line cap style.
+ * @param newLineCapStyle The new line cap style.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getLineCapStyle()
*/
- public PdfColor getFillColor() {
- return this.fillColor;
- }
-
- /**
- * Returns the text state.
- * @return The text state.
- */
- public PdfTextState getTextState() {
- return this.textState;
- }
-
- /**
- * Sets the line dash pattern. See PDF Reference, 3rd Edition, Section 4.3.
- * @param newDashArray The new dash array.
- * @param newDashPhase The new dash phase.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setLineDashPattern(final float[] newDashArray,
- final float newDashPhase) {
+ public boolean setLineCapStyle(final PdfLineCapStyle newLineCapStyle) {
boolean anyChange = false;
- anyChange |= setLineDashArray(newDashArray);
- anyChange |= setLineDashPhase(newDashPhase);
- return anyChange;
- }
-
- /**
- * Set the dash array. See PDF Reference, 3rd Edition, Section 4.3.
- * @param newDashArray The new dash array.
- * @return True iff the Graphics State was changed by this operation.
- */
- private boolean setLineDashArray(final float[] newDashArray) {
- /* Null is a valid value for a dash array. If either the new or old
- * value is null, or both, we need to handle those cases before trying
- * to test equality between the two values. */
- if (newDashArray == null) {
- if (this.dashArray == null) {
- // Both are null. Nothing changes.
- return false;
- }
- // One is null, one not. Replace old with new.
- this.dashArray = newDashArray;
- return true;
- }
- if (this.dashArray == null) {
- // One is null, one not. Replace old with new.
- this.dashArray = newDashArray;
- return true;
- }
-
- // Neither is null. Do normal test.
- if (newDashArray.equals(this.dashArray)) {
- return false;
- }
- this.dashArray = newDashArray;
- return true;
- }
-
- /**
- * Set the dash phase. See PDF Reference, 3rd Edition, Section 4.3.
- * @param newDashPhase The new dash phase.
- * @return True iff the Graphics State was changed by this operation.
- */
- private boolean setLineDashPhase(final float newDashPhase) {
- boolean anyChange = false;
- if (newDashPhase != this.dashPhase) {
- this.dashPhase = newDashPhase;
+ if (newLineCapStyle != this.lineCapStyle) {
+ this.lineCapStyle = newLineCapStyle;
anyChange = true;
}
return anyChange;
@@ -225,18 +169,18 @@
}
/**
- * Sets the line cap style. See PDF Reference, 3rd Edition, Section 4.3.
- * @param newLineCapStyle The new line cap style.
- * @return True iff the Graphics State was changed by this operation.
+ * Sets the line dash pattern.
+ * @param newDashPattern The new dash pattern.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getDashPattern()
*/
- public boolean setLineCapStyle(final PdfLineCapStyle newLineCapStyle) {
+ public boolean setLineDashPattern(final PdfDashPattern newDashPattern) {
boolean anyChange = false;
- if (newLineCapStyle != this.lineCapStyle) {
- this.lineCapStyle = newLineCapStyle;
+ if (! this.dashPattern.equals(newDashPattern)) {
+ this.dashPattern = newDashPattern;
anyChange = true;
}
return anyChange;
}
-
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2021-01-20 12:02:48 UTC (rev 11840)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2021-01-20 14:31:37 UTC (rev 11841)
@@ -31,6 +31,8 @@
import org.axsl.pdf.PdfFont;
import org.axsl.pdf.PdfTextRenderingMode;
+import lombok.Getter;
+
/**
* The text state for the PDF graphics state.
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
@@ -37,31 +39,77 @@
*/
public class PdfTextState {
- /** The character spacing, in points. */
+ /** Constant for the initial horizontal scaling percentage, that is 100%. */
+ public static final float INITIAL_HORIZONTAL_SCALING = 100;
+
+ /**
+ * The character spacing, expressed in unscaled text space units.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.1."
+ * @return The character spacing.
+ */
+ @Getter
private float characterSpacing;
- /** The word spacing, in points. */
+ /**
+ * The word spacing, expressed in unscaled text space units.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.2."
+ * @return The word spacing.
+ */
+ @Getter
private float wordSpacing;
- /** The horizontal scaling percentage. */
+ /**
+ * The horizontal scaling, a percentage.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.3."
+ * @return The horizontal scaling.
+ */
+ @Getter
private float horizontalScaling;
- /** The text leading, expressed in unscaled text units. */
+ /**
+ * The text leading, expressed in unscaled text units.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.4."
+ * @return The text leading.
+ */
+ @Getter
private float leading;
- /** The font. */
+ /**
+ * The font.
+ * @return The font.
+ */
+ @Getter
private PdfFont font;
- /** The font size. */
+ /**
+ * The font size.
+ * @return The font size.
+ */
+ @Getter
private float fontSize;
- /** The text rendering mode. */
+ /**
+ * The text rendering mode.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.5."
+ * @return The text rendering mode.
+ */
+ @Getter
private PdfTextRenderingMode textRenderingMode;
- /** The text rise, expressed in unscaled text space units. */
+ /**
+ * The text rise, expressed in unscaled text space units.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.6."
+ * @return The text rise.
+ */
+ @Getter
private float textRise;
- /** The text knockout flag. */
+ /**
+ * The text knockout flag.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.7."
+ * @return The text knockout.
+ */
+ @Getter
private boolean textKnockout;
/**
@@ -72,10 +120,8 @@
}
/**
- * Creates a new PdfGraphicsState instance, initilializing its values to
- * those of an existing instance.
- * @param existingState The instance whose values should be copied into the
- * new instance.
+ * Creates a new instance, initilializing its values to those of an existing instance.
+ * @param existingState The instance whose values should be copied into the new instance.
*/
public PdfTextState(final PdfTextState existingState) {
this.characterSpacing = existingState.characterSpacing;
@@ -90,13 +136,15 @@
}
/**
- * Resets the Graphics State to its original state, as documented in
- * PDF Reference, 3rd Edition, Section 4.3.
+ * Resets the text state parameters to their initial values.
+ * The initial values, except for font and fontSize are documented at Table 5.2 in "PDF Reference, Sixth Edition
+ * (PDV Version 1.7), Section 5.2".
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
*/
public void reset() {
this.characterSpacing = 0;
this.wordSpacing = 0;
- this.horizontalScaling = PdfGraphicsState.INITIAL_HORIZONTAL_SCALING;
+ this.horizontalScaling = PdfTextState.INITIAL_HORIZONTAL_SCALING;
this.leading = 0;
this.font = null;
this.fontSize = -1;
@@ -107,8 +155,9 @@
/**
* Sets the character spacing.
- * @param newCharacterSpacing The new character spacing, in points.
- * @return True iff the character spacing was changed.
+ * @param newCharacterSpacing The new character spacing, expressed in unscaled text space units.
+ * @return True if and only if the character spacing was changed.
+ * @see #getCharacterSpacing()
*/
public boolean setCharacterSpacing(final float newCharacterSpacing) {
boolean anyChange = false;
@@ -121,8 +170,9 @@
/**
* Sets the word spacing.
- * @param newWordSpacing The new word spacing, in points.
- * @return True iff the word spacing was changed.
+ * @param newWordSpacing The new word spacing, expressed unscaled text space units.
+ * @return True if and only if the word spacing was changed.
+ * @see #getWordSpacing()
*/
public boolean setWordSpacing(final float newWordSpacing) {
boolean anyChange = false;
@@ -134,9 +184,25 @@
}
/**
+ * Sets the horizontal scaling.
+ * @param newHorizontalScaling The new horizontal scaling, expressed as a percentage.
+ * @return True if and only if the horizontal scaling was changed.
+ * @see #getHorizontalScaling()
+ */
+ public boolean setHorizontalScaling(final float newHorizontalScaling) {
+ boolean anyChange = false;
+ if (newHorizontalScaling != this.horizontalScaling) {
+ this.horizontalScaling = newHorizontalScaling;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
* Sets the font.
* @param newFont The new font.
- * @return True iff the font was changed.
+ * @return True if and only if the font was changed.
+ * @see #getFont()
*/
public boolean setFont(final PdfFont newFont) {
boolean anyChange = false;
@@ -148,18 +214,11 @@
}
/**
- * Returns the font.
- * @return The font.
+ * Sets the font size.
+ * @param newFontSize The new font size, in points.
+ * @return True if and only if the font size was changed.
+ * @see #getFontSize()
*/
- public PdfFont getFont() {
- return this.font;
- }
-
- /**
- * Sets the font-size.
- * @param newFontSize The new font-size, in points.
- * @return True iff the font-size was changed.
- */
public boolean setFontSize(final float newFontSize) {
boolean anyChange = false;
if (newFontSize != this.fontSize) {
@@ -170,32 +229,10 @@
}
/**
- * Return the font-size.
- * @return The font-size.
- */
- public float getFontSize() {
- return this.fontSize;
- }
-
- /**
- * Sets the horizontal scaling. See PDF Reference, 3rd Edition, Section
- * 5.2.3.
- * @param newHorizontalScaling The new horizontal scaling percentage.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setHorizontalScaling(final float newHorizontalScaling) {
- boolean anyChange = false;
- if (newHorizontalScaling != this.horizontalScaling) {
- this.horizontalScaling = newHorizontalScaling;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
* Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
* @param newLeading The new leading value.
- * @return True iff the Graphics State was changed by this operation.
+ * @return True if and only if the text leading was changed by this operation.
+ * @see #getLeading()
*/
public boolean setLeading(final float newLeading) {
boolean anyChange = false;
@@ -210,7 +247,8 @@
* Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
* 5.2.5.
* @param newTextRenderingMode The new text rendering mode.
- * @return True iff the Graphics State was changed by this operation.
+ * @return True if and only if the text rendering mode was changed by this operation.
+ * @see #getTextRenderingMode()
*/
public boolean setTextRenderingMode(
final PdfTextRenderingMode newTextRenderingMode) {
@@ -225,7 +263,8 @@
/**
* Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
* @param newTextRise The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
+ * @return True if and only if the text rise was changed by this operation.
+ * @see #getTextRise()
*/
public boolean setTextRise(final float newTextRise) {
boolean anyChange = false;
@@ -237,10 +276,10 @@
}
/**
- * Sets the text knockout flag. See PDF Reference, 3rd Edition, Section
- * 5.2.7.
+ * Sets the text knockout flag.
* @param newTextKnockout The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
+ * @return True if and only if the text knockout was changed by this operation.
+ * @see #isTextKnockout()
*/
public boolean setTextKnockout(final boolean newTextKnockout) {
boolean anyChange = false;
@@ -249,7 +288,6 @@
anyChange = true;
}
return anyChange;
-
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 12:02:48 UTC (rev 11840)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 14:31:37 UTC (rev 11841)
@@ -318,7 +318,8 @@
@Override
public void setDashPattern(final float[] dashArray, final float dashPhase) throws PdfException {
- if (! this.getCurrentGraphicsState().setLineDashPattern(dashArray, dashPhase)) {
+ final PdfDashPattern newDashPattern = new PdfDashPattern(dashArray, dashPhase);
+ if (! this.getCurrentGraphicsState().setLineDashPattern(newDashPattern)) {
// Nothing needs to change.
return;
}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java 2021-01-20 14:31:37 UTC (rev 11841)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2021 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.pdf.object;
+
+import lombok.Getter;
+
+/**
+ * A PDF Line Dash Pattern.
+ * Instances of this class are immutable.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+public class PdfDashPattern {
+
+ /** Dash pattern that will draw a solid, unbroken line. */
+ public static final PdfDashPattern SOLID_LINE = new PdfDashPattern(new float[0], 0);
+
+ /** Constant used to designate a "dotted" dash pattern. */
+ public static final PdfDashPattern DOTTED = new PdfDashPattern(new float[] {1, 3}, 0);
+
+ /** Constant used to designate a "dashed" dash pattern. */
+ public static final PdfDashPattern DASHED = new PdfDashPattern(new float[] {3, 3}, 0);
+
+ /**
+ * The dash array.
+ * @return The dash array.
+ */
+ @Getter
+ private float[] dashArray;
+
+ /**
+ * The dash phase.
+ * @return The dash phase.
+ */
+ @Getter
+ private float dashPhase;
+
+ public PdfDashPattern(final float[] dashArray, final float dashPhase) {
+ this.dashArray = new float[dashArray.length];
+ System.arraycopy(dashArray, 0, this.dashArray, 0, dashArray.length);
+ this.dashPhase = dashPhase;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (! (other instanceof PdfDashPattern)) {
+ return false;
+ }
+ final PdfDashPattern otherDashPattern = (PdfDashPattern) other;
+ if (! this.dashArray.equals(otherDashPattern.dashArray)) {
+ return false;
+ }
+ if (this.dashPhase != otherDashPattern.dashPhase) {
+ return false;
+ }
+ return true;
+ }
+
+}
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-20 12:02:48 UTC (rev 11840)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-20 14:31:37 UTC (rev 11841)
@@ -95,6 +95,9 @@
*/
public class PdfRenderer extends PrintRenderer {
+ /** Constant used to designate a solid dash pattern. */
+ private static final float[] DASHPATTERN_SOLID = new float[] {};
+
/** Constant used to designate a "dotted" dash pattern. */
private static final float[] DASHPATTERN_DOTTED = new float[] {1, 3};
@@ -232,7 +235,7 @@
final float[] dashArray;
if (ruleStyle == null) {
- dashArray = null;
+ dashArray = PdfRenderer.DASHPATTERN_SOLID;
} else {
switch (ruleStyle) {
case DASHED:
@@ -242,7 +245,7 @@
dashArray = PdfRenderer.DASHPATTERN_DOTTED;
break;
default:
- dashArray = null;
+ dashArray = PdfRenderer.DASHPATTERN_SOLID;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 12:02:55
|
Revision: 11840
http://sourceforge.net/p/foray/code/11840
Author: victormote
Date: 2021-01-20 12:02:48 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Break the text state parts of the PdfGraphicsState into a separate class.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 11:06:58 UTC (rev 11839)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -31,9 +31,7 @@
import org.foray.pdf.object.PdfColor4a;
import org.axsl.pdf.PdfColor;
-import org.axsl.pdf.PdfFont;
import org.axsl.pdf.PdfLineCapStyle;
-import org.axsl.pdf.PdfTextRenderingMode;
/**
* Represents a PDF Graphics State object. The Graphics State is ordinarily
@@ -53,6 +51,9 @@
/** The "non-stroke" or "other" color. */
private PdfColor fillColor;
+ /** The text state. */
+ private PdfTextState textState = new PdfTextState();
+
/** The dash array. */
private float[] dashArray;
@@ -62,37 +63,7 @@
/** The line cap style. */
private PdfLineCapStyle lineCapStyle;
- /*--------------------- Start Text State Parameters. -------------------- */
- /** The character spacing, in points. */
- private float characterSpacing;
-
- /** The word spacing, in points. */
- private float wordSpacing;
-
- /** The horizontal scaling percentage. */
- private float horizontalScaling;
-
- /** The text leading, expressed in unscaled text units. */
- private float leading;
-
- /** The font. */
- private PdfFont font;
-
- /** The font size. */
- private float fontSize;
-
- /** The text rendering mode. */
- private PdfTextRenderingMode textRenderingMode;
-
- /** The text rise, expressed in unscaled text space units. */
- private float textRise;
-
- /** The text knockout flag. */
- private boolean textKnockout;
-
- /*---------------------- End Text State Parameters. --------------------- */
-
/**
* Create a PdfGraphicsState instance.
*/
@@ -115,15 +86,7 @@
this.dashPhase = existingState.dashPhase;
this.lineCapStyle = existingState.lineCapStyle;
- this.characterSpacing = existingState.characterSpacing;
- this.wordSpacing = existingState.wordSpacing;
- this.horizontalScaling = existingState.horizontalScaling;
- this.leading = existingState.leading;
- this.font = existingState.font;
- this.fontSize = existingState.fontSize;
- this.textRenderingMode = existingState.textRenderingMode;
- this.textRise = existingState.textRise;
- this.textKnockout = existingState.textKnockout;
+ this.textState = new PdfTextState(this.textState);
}
/**
@@ -133,19 +96,10 @@
public void reset() {
this.strokeColor = PdfColor4a.BLACK;
this.fillColor = PdfColor4a.BLACK;
+ this.textState.reset();
this.dashArray = new float[0];
this.dashPhase = 0;
this.lineCapStyle = PdfLineCapStyle.BUTT_CAP;
-
- this.characterSpacing = 0;
- this.wordSpacing = 0;
- this.horizontalScaling = PdfGraphicsState.INITIAL_HORIZONTAL_SCALING;
- this.leading = 0;
- this.font = null;
- this.fontSize = -1;
- this.textRenderingMode = PdfTextRenderingMode.FILL;
- this.textRise = 0;
- this.textKnockout = true;
}
/**
@@ -203,78 +157,14 @@
}
/**
- * Sets the character spacing.
- * @param newCharacterSpacing The new character spacing, in points.
- * @return True iff the character spacing was changed.
+ * Returns the text state.
+ * @return The text state.
*/
- public boolean setCharacterSpacing(final float newCharacterSpacing) {
- boolean anyChange = false;
- if (newCharacterSpacing != this.characterSpacing) {
- this.characterSpacing = newCharacterSpacing;
- anyChange = true;
- }
- return anyChange;
+ public PdfTextState getTextState() {
+ return this.textState;
}
/**
- * Sets the word spacing.
- * @param newWordSpacing The new word spacing, in points.
- * @return True iff the word spacing was changed.
- */
- public boolean setWordSpacing(final float newWordSpacing) {
- boolean anyChange = false;
- if (newWordSpacing != this.wordSpacing) {
- this.wordSpacing = newWordSpacing;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the font.
- * @param newFont The new font.
- * @return True iff the font was changed.
- */
- public boolean setFont(final PdfFont newFont) {
- boolean anyChange = false;
- if (! newFont.equals(this.font)) {
- this.font = newFont;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the font.
- * @return The font.
- */
- public PdfFont getFont() {
- return this.font;
- }
-
- /**
- * Sets the font-size.
- * @param newFontSize The new font-size, in points.
- * @return True iff the font-size was changed.
- */
- public boolean setFontSize(final float newFontSize) {
- boolean anyChange = false;
- if (newFontSize != this.fontSize) {
- this.fontSize = newFontSize;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Return the font-size.
- * @return The font-size.
- */
- public float getFontSize() {
- return this.fontSize;
- }
-
- /**
* Sets the line dash pattern. See PDF Reference, 3rd Edition, Section 4.3.
* @param newDashArray The new dash array.
* @param newDashPhase The new dash phase.
@@ -348,79 +238,5 @@
return anyChange;
}
- /**
- * Sets the horizontal scaling. See PDF Reference, 3rd Edition, Section
- * 5.2.3.
- * @param newHorizontalScaling The new horizontal scaling percentage.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setHorizontalScaling(final float newHorizontalScaling) {
- boolean anyChange = false;
- if (newHorizontalScaling != this.horizontalScaling) {
- this.horizontalScaling = newHorizontalScaling;
- anyChange = true;
- }
- return anyChange;
- }
- /**
- * Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
- * @param newLeading The new leading value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setLeading(final float newLeading) {
- boolean anyChange = false;
- if (newLeading != this.leading) {
- this.leading = newLeading;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
- * 5.2.5.
- * @param newTextRenderingMode The new text rendering mode.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextRenderingMode(
- final PdfTextRenderingMode newTextRenderingMode) {
- boolean anyChange = false;
- if (newTextRenderingMode != this.textRenderingMode) {
- this.textRenderingMode = newTextRenderingMode;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
- * @param newTextRise The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextRise(final float newTextRise) {
- boolean anyChange = false;
- if (newTextRise != this.textRise) {
- this.textRise = newTextRise;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text knockout flag. See PDF Reference, 3rd Edition, Section
- * 5.2.7.
- * @param newTextKnockout The new text rise value.
- * @return True iff the Graphics State was changed by this operation.
- */
- public boolean setTextKnockout(final boolean newTextKnockout) {
- boolean anyChange = false;
- if (newTextKnockout != this.textKnockout) {
- this.textKnockout = newTextKnockout;
- anyChange = true;
- }
- return anyChange;
-
- }
-
}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2021 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.pdf;
+
+import org.axsl.pdf.PdfFont;
+import org.axsl.pdf.PdfTextRenderingMode;
+
+/**
+ * The text state for the PDF graphics state.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
+ */
+public class PdfTextState {
+
+ /** The character spacing, in points. */
+ private float characterSpacing;
+
+ /** The word spacing, in points. */
+ private float wordSpacing;
+
+ /** The horizontal scaling percentage. */
+ private float horizontalScaling;
+
+ /** The text leading, expressed in unscaled text units. */
+ private float leading;
+
+ /** The font. */
+ private PdfFont font;
+
+ /** The font size. */
+ private float fontSize;
+
+ /** The text rendering mode. */
+ private PdfTextRenderingMode textRenderingMode;
+
+ /** The text rise, expressed in unscaled text space units. */
+ private float textRise;
+
+ /** The text knockout flag. */
+ private boolean textKnockout;
+
+ /**
+ * Create a new instance.
+ */
+ public PdfTextState() {
+ reset();
+ }
+
+ /**
+ * Creates a new PdfGraphicsState instance, initilializing its values to
+ * those of an existing instance.
+ * @param existingState The instance whose values should be copied into the
+ * new instance.
+ */
+ public PdfTextState(final PdfTextState existingState) {
+ this.characterSpacing = existingState.characterSpacing;
+ this.wordSpacing = existingState.wordSpacing;
+ this.horizontalScaling = existingState.horizontalScaling;
+ this.leading = existingState.leading;
+ this.font = existingState.font;
+ this.fontSize = existingState.fontSize;
+ this.textRenderingMode = existingState.textRenderingMode;
+ this.textRise = existingState.textRise;
+ this.textKnockout = existingState.textKnockout;
+ }
+
+ /**
+ * Resets the Graphics State to its original state, as documented in
+ * PDF Reference, 3rd Edition, Section 4.3.
+ */
+ public void reset() {
+ this.characterSpacing = 0;
+ this.wordSpacing = 0;
+ this.horizontalScaling = PdfGraphicsState.INITIAL_HORIZONTAL_SCALING;
+ this.leading = 0;
+ this.font = null;
+ this.fontSize = -1;
+ this.textRenderingMode = PdfTextRenderingMode.FILL;
+ this.textRise = 0;
+ this.textKnockout = true;
+ }
+
+ /**
+ * Sets the character spacing.
+ * @param newCharacterSpacing The new character spacing, in points.
+ * @return True iff the character spacing was changed.
+ */
+ public boolean setCharacterSpacing(final float newCharacterSpacing) {
+ boolean anyChange = false;
+ if (newCharacterSpacing != this.characterSpacing) {
+ this.characterSpacing = newCharacterSpacing;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the word spacing.
+ * @param newWordSpacing The new word spacing, in points.
+ * @return True iff the word spacing was changed.
+ */
+ public boolean setWordSpacing(final float newWordSpacing) {
+ boolean anyChange = false;
+ if (newWordSpacing != this.wordSpacing) {
+ this.wordSpacing = newWordSpacing;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the font.
+ * @param newFont The new font.
+ * @return True iff the font was changed.
+ */
+ public boolean setFont(final PdfFont newFont) {
+ boolean anyChange = false;
+ if (! newFont.equals(this.font)) {
+ this.font = newFont;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Returns the font.
+ * @return The font.
+ */
+ public PdfFont getFont() {
+ return this.font;
+ }
+
+ /**
+ * Sets the font-size.
+ * @param newFontSize The new font-size, in points.
+ * @return True iff the font-size was changed.
+ */
+ public boolean setFontSize(final float newFontSize) {
+ boolean anyChange = false;
+ if (newFontSize != this.fontSize) {
+ this.fontSize = newFontSize;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Return the font-size.
+ * @return The font-size.
+ */
+ public float getFontSize() {
+ return this.fontSize;
+ }
+
+ /**
+ * Sets the horizontal scaling. See PDF Reference, 3rd Edition, Section
+ * 5.2.3.
+ * @param newHorizontalScaling The new horizontal scaling percentage.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setHorizontalScaling(final float newHorizontalScaling) {
+ boolean anyChange = false;
+ if (newHorizontalScaling != this.horizontalScaling) {
+ this.horizontalScaling = newHorizontalScaling;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
+ * @param newLeading The new leading value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setLeading(final float newLeading) {
+ boolean anyChange = false;
+ if (newLeading != this.leading) {
+ this.leading = newLeading;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
+ * 5.2.5.
+ * @param newTextRenderingMode The new text rendering mode.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextRenderingMode(
+ final PdfTextRenderingMode newTextRenderingMode) {
+ boolean anyChange = false;
+ if (newTextRenderingMode != this.textRenderingMode) {
+ this.textRenderingMode = newTextRenderingMode;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
+ * @param newTextRise The new text rise value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextRise(final float newTextRise) {
+ boolean anyChange = false;
+ if (newTextRise != this.textRise) {
+ this.textRise = newTextRise;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Sets the text knockout flag. See PDF Reference, 3rd Edition, Section
+ * 5.2.7.
+ * @param newTextKnockout The new text rise value.
+ * @return True iff the Graphics State was changed by this operation.
+ */
+ public boolean setTextKnockout(final boolean newTextKnockout) {
+ boolean anyChange = false;
+ if (newTextKnockout != this.textKnockout) {
+ this.textKnockout = newTextKnockout;
+ anyChange = true;
+ }
+ return anyChange;
+
+ }
+
+}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 11:06:58 UTC (rev 11839)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 12:02:48 UTC (rev 11840)
@@ -117,7 +117,7 @@
}
openTextObject();
final CharSequence stringOut =
- this.getCurrentGraphicsState().getFont().textToPdf(text, fontOptions, orthography);
+ this.getCurrentGraphicsState().getTextState().getFont().textToPdf(text, fontOptions, orthography);
write(stringOut);
}
@@ -125,8 +125,8 @@
public void setFont(final PdfFont newFont, final float newFontSize) throws PdfException {
openTextObject();
boolean anyChange = false;
- anyChange |= this.getCurrentGraphicsState().setFont(newFont);
- anyChange |= this.getCurrentGraphicsState().setFontSize(newFontSize);
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFont(newFont);
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFontSize(newFontSize);
if (! anyChange) {
// Nothing needs to change.
return;
@@ -158,7 +158,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getCurrentGraphicsState().setWordSpacing(newWordSpacing)) {
+ if (! this.getCurrentGraphicsState().getTextState().setWordSpacing(newWordSpacing)) {
// Nothing needs to change.
return;
}
@@ -170,7 +170,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getCurrentGraphicsState().setCharacterSpacing(newCharacterSpacing)) {
+ if (! this.getCurrentGraphicsState().getTextState().setCharacterSpacing(newCharacterSpacing)) {
// Nothing needs to change.
return;
}
@@ -179,7 +179,7 @@
@Override
public void setHorizontalScaling(final float newHorizontalScaling) throws PdfException {
- if (! this.getCurrentGraphicsState().setHorizontalScaling(newHorizontalScaling)) {
+ if (! this.getCurrentGraphicsState().getTextState().setHorizontalScaling(newHorizontalScaling)) {
// Nothing needs to change.
return;
}
@@ -188,7 +188,7 @@
@Override
public void setLeading(final float newLeading) throws PdfException {
- if (! this.getCurrentGraphicsState().setLeading(newLeading)) {
+ if (! this.getCurrentGraphicsState().getTextState().setLeading(newLeading)) {
// Nothing needs to change.
return;
}
@@ -202,7 +202,7 @@
if (mode == null) {
mode = PdfTextRenderingMode.FILL;
}
- if (! this.getCurrentGraphicsState().setTextRenderingMode(mode)) {
+ if (! this.getCurrentGraphicsState().getTextState().setTextRenderingMode(mode)) {
// Nothing needs to change.
return;
}
@@ -211,7 +211,7 @@
@Override
public void setTextRise(final float newTextRise) throws PdfException {
- if (! this.getCurrentGraphicsState().setTextRise(newTextRise)) {
+ if (! this.getCurrentGraphicsState().getTextState().setTextRise(newTextRise)) {
// Nothing needs to change.
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 11:07:01
|
Revision: 11839
http://sourceforge.net/p/foray/code/11839
Author: victormote
Date: 2021-01-20 11:06:58 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Allow the graphics state colors to be any PdfColor, not just PdfColor4a.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java 2021-01-20 10:32:39 UTC (rev 11838)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java 2021-01-20 11:06:58 UTC (rev 11839)
@@ -82,7 +82,7 @@
return false;
}
final PdfColor4a otherColor = (PdfColor4a) obj;
- return this.getColor().equals(otherColor.getColor());
+ return this.getAwtColor().equals(otherColor.getAwtColor());
}
/**
@@ -120,11 +120,8 @@
return false;
}
- /**
- * Return the encapsulated Color.
- * @return The encapsulated Color.
- */
- public Color getColor() {
+ @Override
+ public Color getAwtColor() {
return this.color;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-20 10:32:39 UTC (rev 11838)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-20 11:06:58 UTC (rev 11839)
@@ -556,7 +556,7 @@
PdfColor4a pdfColor = null;
for (int i = 0; i < this.usedColors.size(); i++) {
pdfColor = this.usedColors.get(i);
- if (pdfColor.getColor().equals(color)) {
+ if (pdfColor.getAwtColor().equals(color)) {
return pdfColor;
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-20 10:32:39 UTC (rev 11838)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-20 11:06:58 UTC (rev 11839)
@@ -40,6 +40,7 @@
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
import org.foray.pdf.PdfConstants;
+import org.foray.pdf.object.PdfColor4a;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontOptions;
@@ -46,6 +47,7 @@
import org.axsl.font.FontUse;
import org.axsl.font.FontUtility;
import org.axsl.graphic.output.GraphicOutputContext;
+import org.axsl.pdf.PdfColor;
import org.axsl.pdf.PdfPage;
import org.apache.batik.ext.awt.g2d.GraphicContext;
@@ -105,10 +107,10 @@
private final class PdfGraphicsState {
/** The stroke color. */
- private Color strokeColor;
+ private PdfColor strokeColor;
/** The "non-stroke" or "other" color. */
- private Color fillColor;
+ private PdfColor fillColor;
/** The font. */
private FontUse font;
@@ -280,7 +282,7 @@
return false;
}
- final int numChannels = this.getGraphicsState().strokeColor.getColorSpace().getNumComponents();
+ final int numChannels = this.getGraphicsState().strokeColor.getAwtColor().getColorSpace().getNumComponents();
final Dimension size = new Dimension(width * numChannels,
height * numChannels);
final BufferedImage buf = new BufferedImage(size.width, size.height,
@@ -395,7 +397,7 @@
this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
- setNonStrokeColor(c);
+ setNonStrokeColor(new PdfColor4a(c));
applyPaint(getPaint(), false);
applyStroke(getStroke());
@@ -486,27 +488,27 @@
/**
* Set the stroke color.
- * @param color The color to be set.
+ * @param pdfColor The color to be set.
*/
- protected void setStrokeColor(final Color color) {
+ protected void setStrokeColor(final PdfColor4a pdfColor) {
boolean anyChange = false;
- anyChange = ! color.equals(this.getGraphicsState().strokeColor);
- this.getGraphicsState().strokeColor = color;
+ anyChange = ! pdfColor.equals(this.getGraphicsState().strokeColor);
+ this.getGraphicsState().strokeColor = pdfColor;
if (anyChange) {
- this.write(PsColor.toPS(color, false));
+ this.write(PsColor.toPS(pdfColor.getAwtColor(), false));
}
}
/**
* Set the fill or non-stroke color.
- * @param color The color to be set.
+ * @param pdfColor The color to be set.
*/
- protected void setNonStrokeColor(final Color color) {
+ protected void setNonStrokeColor(final PdfColor4a pdfColor) {
boolean anyChange = false;
- anyChange = ! color.equals(this.getGraphicsState().fillColor);
- this.getGraphicsState().fillColor = color;
+ anyChange = ! pdfColor.equals(this.getGraphicsState().fillColor);
+ this.getGraphicsState().fillColor = pdfColor;
if (anyChange) {
- this.write(PsColor.toPS(color, true));
+ this.write(PsColor.toPS(pdfColor.getAwtColor(), true));
}
}
@@ -657,9 +659,9 @@
final Shape imclip = getClip();
writeClip(imclip);
Color c = getColor();
- setNonStrokeColor(c);
+ setNonStrokeColor(new PdfColor4a(c));
c = getBackground();
- setStrokeColor(c);
+ setStrokeColor(new PdfColor4a(c));
this.write("BT");
@@ -722,9 +724,9 @@
final Shape imclip = getClip();
writeClip(imclip);
Color c = getColor();
- setNonStrokeColor(c);
+ setNonStrokeColor(new PdfColor4a(c));
c = getBackground();
- setStrokeColor(c);
+ setStrokeColor(new PdfColor4a(c));
this.write("BT");
@@ -779,9 +781,9 @@
final Shape imclip = getClip();
writeClip(imclip);
c = getColor();
- setNonStrokeColor(c);
+ setNonStrokeColor(new PdfColor4a(c));
c = getBackground();
- setStrokeColor(c);
+ setStrokeColor(new PdfColor4a(c));
applyPaint(getPaint(), true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 10:32:47
|
Revision: 11838
http://sourceforge.net/p/foray/code/11838
Author: victormote
Date: 2021-01-20 10:32:39 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Split setting of fill and stroke colors into separate methods.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-20 09:53:22 UTC (rev 11837)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-20 10:32:39 UTC (rev 11838)
@@ -395,7 +395,7 @@
this.saveGraphicsState();
final Shape imclip = getClip();
writeClip(imclip);
- applyColor(c, false);
+ setNonStrokeColor(c);
applyPaint(getPaint(), false);
applyStroke(getStroke());
@@ -485,21 +485,28 @@
}
/**
- * Apply a color to the document.
- * @param color The color to be applied.
- * @param fill Set to true if the color is for fill, false if for stroke.
+ * Set the stroke color.
+ * @param color The color to be set.
*/
- protected void applyColor(final Color color, final boolean fill) {
+ protected void setStrokeColor(final Color color) {
boolean anyChange = false;
- if (fill) {
- anyChange = ! color.equals(this.getGraphicsState().fillColor);
- this.getGraphicsState().fillColor = color;
- } else {
- anyChange = ! color.equals(this.getGraphicsState().strokeColor);
- this.getGraphicsState().strokeColor = color;
+ anyChange = ! color.equals(this.getGraphicsState().strokeColor);
+ this.getGraphicsState().strokeColor = color;
+ if (anyChange) {
+ this.write(PsColor.toPS(color, false));
}
+ }
+
+ /**
+ * Set the fill or non-stroke color.
+ * @param color The color to be set.
+ */
+ protected void setNonStrokeColor(final Color color) {
+ boolean anyChange = false;
+ anyChange = ! color.equals(this.getGraphicsState().fillColor);
+ this.getGraphicsState().fillColor = color;
if (anyChange) {
- this.write(PsColor.toPS(color, fill));
+ this.write(PsColor.toPS(color, true));
}
}
@@ -650,9 +657,9 @@
final Shape imclip = getClip();
writeClip(imclip);
Color c = getColor();
- applyColor(c, true);
+ setNonStrokeColor(c);
c = getBackground();
- applyColor(c, false);
+ setStrokeColor(c);
this.write("BT");
@@ -715,9 +722,9 @@
final Shape imclip = getClip();
writeClip(imclip);
Color c = getColor();
- applyColor(c, true);
+ setNonStrokeColor(c);
c = getBackground();
- applyColor(c, false);
+ setStrokeColor(c);
this.write("BT");
@@ -772,9 +779,9 @@
final Shape imclip = getClip();
writeClip(imclip);
c = getColor();
- applyColor(c, true);
+ setNonStrokeColor(c);
c = getBackground();
- applyColor(c, false);
+ setStrokeColor(c);
applyPaint(getPaint(), true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 09:53:25
|
Revision: 11837
http://sourceforge.net/p/foray/code/11837
Author: victormote
Date: 2021-01-20 09:53:22 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Convert the current graphics state to the top item on a stack of such states.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 00:45:14 UTC (rev 11836)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 09:53:22 UTC (rev 11837)
@@ -46,6 +46,7 @@
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
+import java.util.Stack;
/**
* Specialized version of PdfStream with methods useful in creating PDF content
@@ -53,20 +54,27 @@
*/
public class PdfContentStream4a extends PdfStream implements PdfContentStream {
- /** The current graphics state. */
- private PdfGraphicsState currentGraphicsState = new PdfGraphicsState();
+ /** The stack of PDF Graphics States for this content stream. */
+ private Stack<PdfGraphicsState> graphicsStateStack = new Stack<PdfGraphicsState>();
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
/**
- * Return the graphic state.
- * @return The graphic state.
+ * Constructor.
*/
- private PdfGraphicsState getGS() {
- return this.currentGraphicsState;
+ public PdfContentStream4a() {
+ this.graphicsStateStack.push(new PdfGraphicsState());
}
+ /**
+ * Returns the current graphics state.
+ * @return The current graphics state.
+ */
+ public PdfGraphicsState getCurrentGraphicsState() {
+ return this.graphicsStateStack.peek();
+ }
+
@Override
public void close() throws PdfException {
closeTextObject();
@@ -109,7 +117,7 @@
}
openTextObject();
final CharSequence stringOut =
- this.getGS().getFont().textToPdf(text, fontOptions, orthography);
+ this.getCurrentGraphicsState().getFont().textToPdf(text, fontOptions, orthography);
write(stringOut);
}
@@ -117,8 +125,8 @@
public void setFont(final PdfFont newFont, final float newFontSize) throws PdfException {
openTextObject();
boolean anyChange = false;
- anyChange |= this.getGS().setFont(newFont);
- anyChange |= this.getGS().setFontSize(newFontSize);
+ anyChange |= this.getCurrentGraphicsState().setFont(newFont);
+ anyChange |= this.getCurrentGraphicsState().setFontSize(newFontSize);
if (! anyChange) {
// Nothing needs to change.
return;
@@ -129,7 +137,7 @@
@Override
public void setStrokeColor(final PdfColor newColor) throws PdfException {
- if (! this.getGS().setStrokeColor(newColor)) {
+ if (! this.getCurrentGraphicsState().setStrokeColor(newColor)) {
// Nothing needs to change.
return;
}
@@ -138,7 +146,7 @@
@Override
public void setFillColor(final PdfColor newColor) throws PdfException {
- if (! this.getGS().setFillColor(newColor)) {
+ if (! this.getCurrentGraphicsState().setFillColor(newColor)) {
// Nothing needs to change.
return;
}
@@ -150,7 +158,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getGS().setWordSpacing(newWordSpacing)) {
+ if (! this.getCurrentGraphicsState().setWordSpacing(newWordSpacing)) {
// Nothing needs to change.
return;
}
@@ -162,7 +170,7 @@
/* TODO: Remove following line. We do not need to be in a text object
* to set this parameter. */
openTextObject();
- if (! this.getGS().setCharacterSpacing(newCharacterSpacing)) {
+ if (! this.getCurrentGraphicsState().setCharacterSpacing(newCharacterSpacing)) {
// Nothing needs to change.
return;
}
@@ -171,7 +179,7 @@
@Override
public void setHorizontalScaling(final float newHorizontalScaling) throws PdfException {
- if (! this.getGS().setHorizontalScaling(newHorizontalScaling)) {
+ if (! this.getCurrentGraphicsState().setHorizontalScaling(newHorizontalScaling)) {
// Nothing needs to change.
return;
}
@@ -180,7 +188,7 @@
@Override
public void setLeading(final float newLeading) throws PdfException {
- if (! this.getGS().setLeading(newLeading)) {
+ if (! this.getCurrentGraphicsState().setLeading(newLeading)) {
// Nothing needs to change.
return;
}
@@ -194,7 +202,7 @@
if (mode == null) {
mode = PdfTextRenderingMode.FILL;
}
- if (! this.getGS().setTextRenderingMode(mode)) {
+ if (! this.getCurrentGraphicsState().setTextRenderingMode(mode)) {
// Nothing needs to change.
return;
}
@@ -203,7 +211,7 @@
@Override
public void setTextRise(final float newTextRise) throws PdfException {
- if (! this.getGS().setTextRise(newTextRise)) {
+ if (! this.getCurrentGraphicsState().setTextRise(newTextRise)) {
// Nothing needs to change.
return;
}
@@ -222,7 +230,7 @@
@Override
public void setLineCapStyle(final PdfLineCapStyle newLineCapStyle) throws PdfException {
- if (! this.getGS().setLineCapStyle(newLineCapStyle)) {
+ if (! this.getCurrentGraphicsState().setLineCapStyle(newLineCapStyle)) {
// Nothing needs to change.
return;
}
@@ -310,7 +318,7 @@
@Override
public void setDashPattern(final float[] dashArray, final float dashPhase) throws PdfException {
- if (! this.getGS().setLineDashPattern(dashArray, dashPhase)) {
+ if (! this.getCurrentGraphicsState().setLineDashPattern(dashArray, dashPhase)) {
// Nothing needs to change.
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-20 00:45:22
|
Revision: 11836
http://sourceforge.net/p/foray/code/11836
Author: victormote
Date: 2021-01-20 00:45:14 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: Add method for creating XObjects to PdfDocument. Add method for displaying them to PdfContentStream.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -42,6 +42,7 @@
import org.axsl.pdf.PdfFont;
import org.axsl.pdf.PdfLineCapStyle;
import org.axsl.pdf.PdfTextRenderingMode;
+import org.axsl.pdf.PdfXobject;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
@@ -55,21 +56,10 @@
/** The current graphics state. */
private PdfGraphicsState currentGraphicsState = new PdfGraphicsState();
- /** The PDF document. */
- private PdfDocument4a doc;
-
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
/**
- * Create a PdfContentStream.
- * @param doc The parent PDF document.
- */
- public PdfContentStream4a(final PdfDocument4a doc) {
- this.doc = doc;
- }
-
- /**
* Return the graphic state.
* @return The graphic state.
*/
@@ -276,39 +266,9 @@
}
@Override
- public void drawGraphic(final Graphic image,
- final Rectangle2D.Float contentRectangle,
- final Rectangle2D.Float clipRectangle,
- final FontConsumer fontConsumer, final boolean strokeText) throws PdfException {
- final PdfXobject4a xObject;
- try {
- if (strokeText) {
- xObject = PdfXobject4a.makeXObject(doc, image, null);
- } else {
- xObject = PdfXobject4a.makeXObject(doc, image, fontConsumer);
- }
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
- if (xObject == null) {
- throw new PdfException("Don't know how to process graphic:" + MSG_EOL
- + image.getUrl());
- }
- closeTextObject();
- write("q" + EOL);
- clip(clipRectangle, contentRectangle);
- try {
- write(xObject.getHorizontalScaling(contentRectangle)
- + " 0 0 "
- + xObject.getVerticalScaling(contentRectangle) + " "
- + contentRectangle.x + " "
- + (contentRectangle.y - contentRectangle.height) + " cm"
- + EOL);
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
- write("/" + xObject.getXObjectName() + " Do" + EOL);
- write("Q" + EOL);
+ public void drawGraphic(final Graphic image, final Rectangle2D.Float contentRectangle,
+ final Rectangle2D.Float clipRectangle, final FontConsumer fontConsumer) throws PdfException {
+ throw new UnsupportedOperationException();
}
/**
@@ -376,4 +336,24 @@
return WellKnownConstants.EMPTY_STRING;
}
+ @Override
+ public void drawXobject(final PdfXobject xObject, final Rectangle2D.Float contentRectangle,
+ final Rectangle2D.Float clipRectangle) throws PdfException {
+ closeTextObject();
+ write("q" + EOL);
+ clip(clipRectangle, contentRectangle);
+ try {
+ write(xObject.getHorizontalScaling(contentRectangle)
+ + " 0 0 "
+ + xObject.getVerticalScaling(contentRectangle) + " "
+ + contentRectangle.x + " "
+ + (contentRectangle.y - contentRectangle.height) + " cm"
+ + EOL);
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ write("/" + xObject.getXobjectName() + " Do" + EOL);
+ write("Q" + EOL);
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -47,8 +47,10 @@
import org.axsl.common.Gradient;
import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
import org.axsl.font.FontUse;
import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
import org.axsl.graphic.output.GraphicOutputContext;
import org.axsl.pdf.PdfDocument;
import org.axsl.pdf.PdfException;
@@ -56,6 +58,7 @@
import org.axsl.pdf.PdfPageProvider;
import org.axsl.pdf.PdfSerializationConfig;
import org.axsl.pdf.PdfVersion;
+import org.axsl.pdf.PdfXobject;
import org.axsl.ps.Encoding;
import org.axsl.ps.PsServer;
@@ -762,4 +765,18 @@
return this.xrefInfo;
}
+ @Override
+ public PdfXobject createXobject(final Graphic graphic, final FontConsumer fontConsumer) throws PdfException {
+ final PdfXobject4a xObject;
+ try {
+ xObject = PdfXobject4a.makeXObject(this, graphic, null);
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ if (xObject == null) {
+ throw new PdfException("Don't know how to process graphic: " + graphic.getUrl());
+ }
+ return xObject;
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -89,7 +89,7 @@
this.resources = resources;
this.pagewidth = pagewidth;
this.pageheight = pageheight;
- this.contents = new PdfContentStream4a(this.getPDFDocument());
+ this.contents = new PdfContentStream4a();
try {
this.contents.addDefaultFilters(doc);
} catch (final PdfException e) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -137,7 +137,7 @@
p.append("<<" + EOL);
for (int i = 0; i < this.xObjects.size(); i++) {
final PdfXobject4a xObject = this.xObjects.get(i);
- p.append("/" + xObject.getXObjectName() + " "
+ p.append("/" + xObject.getXobjectName() + " "
+ xObject.pdfReference(doc) + EOL);
}
p.append(">>" + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -41,11 +41,11 @@
import org.axsl.graphic.MathGraphic;
import org.axsl.graphic.SvgGraphic;
import org.axsl.pdf.PdfException;
+import org.axsl.pdf.PdfXobject;
import org.axsl.ps.PsEncodeFilter;
import org.axsl.ps.PsFilterType;
import org.axsl.ps.PsServer;
-import java.awt.geom.Rectangle2D;
import java.io.OutputStream;
/**
@@ -59,7 +59,7 @@
*
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
*/
-public abstract class PdfXobject4a extends PdfStream {
+public abstract class PdfXobject4a extends PdfStream implements PdfXobject {
/** The sequentially-assigned XObject number for this XObject. This is used
* to build the "name" entry in the XObject subdictionary. */
@@ -120,12 +120,8 @@
return xObject;
}
- /**
- * Returns the XObject name for this object.
- * @return The name by which this XObject is recorded in the XObject
- * subdictionary.
- */
- public String getXObjectName() {
+ @Override
+ public String getXobjectName() {
return "X" + this.xNumber;
}
@@ -224,36 +220,6 @@
*/
public abstract Graphic getGraphic();
- /**
- * Returns the horizontal scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * This is used in transformations that are outside the actual XObject
- * definition, so that the XObject can be reused in other places, using
- * different content rectangles.
- * This abstraction is needed because bitmapped graphics are specified in
- * image space, and XForm graphics (SVG and EPS) are specified in form
- * space, which require radically different scaling mechanisms.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The horizontal scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
- /**
- * Returns the vertical scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * See {@link #getHorizontalScaling(java.awt.geom.Rectangle2D.Float)} for an
- * explanation of the need for this computation.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The vertical scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
@Override
protected String specialStreamDictEntries(final PdfDocument4a doc) throws PdfException {
addStreamFilters(doc);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -63,7 +63,7 @@
this.graphic = graphic;
/* Write the content of the graphic file to an embedded file stream. */
- final String efsName = this.getXObjectName() + "-EF";
+ final String efsName = this.getXobjectName() + "-EF";
final PdfEmbeddedFileStream embeddedFile = new PdfEmbeddedFileStream(doc, efsName);
final ByteSequence efsContent = this.graphic.getContent();
try {
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -78,6 +78,7 @@
import org.axsl.pdf.PdfPageLabelStyle;
import org.axsl.pdf.PdfPathPaint;
import org.axsl.pdf.PdfVersion;
+import org.axsl.pdf.PdfXobject;
import java.awt.Color;
import java.awt.Rectangle;
@@ -301,8 +302,8 @@
final Rectangle2D.Float pdfClipRectangle = convertMillipointRectangle(
clipRectangle);
try {
- getContentStream().drawGraphic(image, pdfContentRectangle,
- pdfClipRectangle, this.getFontConsumer(), getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(image, getFontConsumer());
+ getContentStream().drawXobject(xObject, pdfContentRectangle, pdfClipRectangle);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
@@ -317,9 +318,8 @@
toPoints(foreign.referenceBpd()));
final SvgGraphic svgGraphic = area.getGraphic();
try {
- getContentStream().drawGraphic(svgGraphic,
- contentRectangle, null, this.getFontConsumer(),
- getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, getFontConsumer());
+ getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
@@ -335,9 +335,8 @@
toPoints(foreign.referenceBpd()));
final MathGraphic mathGraphic = area.getGraphic();
try {
- getContentStream().drawGraphic(mathGraphic,
- contentRectangle, null, this.getFontConsumer(),
- getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, getFontConsumer());
+ getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-19 23:29:32
|
Revision: 11835
http://sourceforge.net/p/foray/code/11835
Author: victormote
Date: 2021-01-19 23:29:24 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Rename class in anticipation of same-named interface to be created in aXSL.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -280,12 +280,12 @@
final Rectangle2D.Float contentRectangle,
final Rectangle2D.Float clipRectangle,
final FontConsumer fontConsumer, final boolean strokeText) throws PdfException {
- final PdfXobject xObject;
+ final PdfXobject4a xObject;
try {
if (strokeText) {
- xObject = PdfXobject.makeXObject(doc, image, null);
+ xObject = PdfXobject4a.makeXObject(doc, image, null);
} else {
- xObject = PdfXobject.makeXObject(doc, image, fontConsumer);
+ xObject = PdfXobject4a.makeXObject(doc, image, fontConsumer);
}
} catch (final GraphicException e) {
throw new PdfException(e);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -131,8 +131,8 @@
* create the possibility of reusing XObjects.
* The key is the Graphic instance and the value is a PdfXobject instance.
*/
- private Map<Graphic, PdfXobject> xObjectsMap =
- new HashMap<Graphic, PdfXobject>();
+ private Map<Graphic, PdfXobject4a> xObjectsMap =
+ new HashMap<Graphic, PdfXobject4a>();
/**
* Default list of filters that should be applied to each stream in this
@@ -410,7 +410,7 @@
* @return The incremented X object count.
*/
public int registerXObjectResource(final Graphic graphic,
- final PdfXobject theXObject) {
+ final PdfXobject4a theXObject) {
// Add it to the global map so that it can be reused.
this.xObjectsMap.put(graphic, theXObject);
registerIndirectObject(theXObject);
@@ -492,7 +492,7 @@
* @param graphic The Graphic instance for which a PdfXobject is sought.
* @return The corresponding PdfXobject, or null if there is none.
*/
- public PdfXobject findXObject(final Graphic graphic) {
+ public PdfXobject4a findXObject(final Graphic graphic) {
return this.xObjectsMap.get(graphic);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -62,7 +62,7 @@
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.9, for Form XObjects, including a Note that explains
* the meaning of the term <em>form</em> in this context."
*/
-public abstract class PdfFormXobject extends PdfXobject {
+public abstract class PdfFormXobject extends PdfXobject4a {
/**
* Constructor.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -47,10 +47,10 @@
* A sampled image that is to be embedded in a PDF File.
* Images in PDF can either be written directly into the content stream or handled as XObjects (external objects).
*
- * @see PdfXobject
+ * @see PdfXobject4a
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
*/
-public class PdfImageXobject extends PdfXobject {
+public class PdfImageXobject extends PdfXobject4a {
/** The Graphic instance associated with this XObject. */
private Graphic graphic;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -43,7 +43,7 @@
private List<PdfFont4a> fonts = new ArrayList<PdfFont4a>();
/** The list of X Objects used in this document. */
- private List<PdfXobject> xObjects = new ArrayList<PdfXobject>();
+ private List<PdfXobject4a> xObjects = new ArrayList<PdfXobject4a>();
/** The list of patterns used in this document. */
private List<PdfPattern> patterns = new ArrayList<PdfPattern>();
@@ -63,7 +63,7 @@
* Add an x object to the resources list.
* @param xObject The x object to add.
*/
- public void addXObject(final PdfXobject xObject) {
+ public void addXObject(final PdfXobject4a xObject) {
this.xObjects.add(xObject);
}
@@ -136,7 +136,7 @@
p.append("/XObject" + EOL);
p.append("<<" + EOL);
for (int i = 0; i < this.xObjects.size(); i++) {
- final PdfXobject xObject = this.xObjects.get(i);
+ final PdfXobject4a xObject = this.xObjects.get(i);
p.append("/" + xObject.getXObjectName() + " "
+ xObject.pdfReference(doc) + EOL);
}
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -1,283 +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:
- * JKT
- * Eric SCHAEFFER
- */
-
-package org.foray.pdf.object;
-
-import org.axsl.font.FontConsumer;
-import org.axsl.graphic.EpsGraphic;
-import org.axsl.graphic.Graphic;
-import org.axsl.graphic.GraphicException;
-import org.axsl.graphic.MathGraphic;
-import org.axsl.graphic.SvgGraphic;
-import org.axsl.pdf.PdfException;
-import org.axsl.ps.PsEncodeFilter;
-import org.axsl.ps.PsFilterType;
-import org.axsl.ps.PsServer;
-
-import java.awt.geom.Rectangle2D;
-import java.io.OutputStream;
-
-/**
- * <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
- * <ul>
- * <li>An image XObject. See {@link PdfImageXobject} for a concrete implementation.</li>
- * <li>A form XObject. See {@link PdfFormXobject} for a concrete implementation.</li>
- * <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
- * for it.</li>
- * </ul>
- *
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
- */
-public abstract class PdfXobject extends PdfStream {
-
- /** The sequentially-assigned XObject number for this XObject. This is used
- * to build the "name" entry in the XObject subdictionary. */
- private int xNumber;
-
- /** The PSFilter, if any, that should be applied to this XObject. */
- private PsEncodeFilter filter;
-
- /**
- * Create an Xobject instance.
- * @param doc The parent PDF document.
- * @param graphic The graphic to be encapsulated.
- */
- protected PdfXobject(final PdfDocument4a doc, final Graphic graphic) {
- if (graphic == null) {
- throw new NullPointerException("Graphic must not be null.");
- }
- this.xNumber = doc.registerXObjectResource(graphic, this);
- }
-
- /**
- * Factory method that encapsulates a Graphic instance into an appropriate
- * PdfXobject instance.
- * @param pdfDoc The parent PDF document.
- * @param img The graphic to be encapsulated.
- * @param fontConsumer The font consumer to use for resolving fonts in the SVG.
- * @return An appropriate PdfXobject instance that encapsulates the input.
- * @throws GraphicException For errors getting the appropriate filter.
- */
- public static PdfXobject makeXObject(final PdfDocument4a pdfDoc, final Graphic img, final FontConsumer fontConsumer)
- throws GraphicException {
- /* If it has already been created, reuse it ... */
- PdfXobject xObject = pdfDoc.findXObject(img);
- if (xObject != null) {
- return xObject;
- }
-
- /* ... otherwise, create a new one. */
- if (img instanceof EpsGraphic) {
- final EpsGraphic epsGraphic = (EpsGraphic) img;
- xObject = new PdfXformEps(pdfDoc, epsGraphic);
- } else if (img instanceof SvgGraphic) {
- final SvgGraphic svgGraphic = (SvgGraphic) img;
- xObject = new PdfXformSvg(pdfDoc, svgGraphic, fontConsumer);
- } else if (img instanceof MathGraphic) {
- final MathGraphic mathGraphic = (MathGraphic) img;
- xObject = new PdfXformMath(pdfDoc, mathGraphic, fontConsumer);
- } else if (img.getGraphicType() == Graphic.Type.PDF) {
- xObject = new PdfXreference(pdfDoc, img);
- } else {
- /* The following line is bogus, and is intended only to make sure
- * that no exceptions are thrown. If there are any exceptions
- * thrown, we don't want to create the xObject. */
- img.getColorSpace();
- xObject = new PdfImageXobject(pdfDoc, img);
- }
- xObject.filter = xObject.getFilter(xObject.getOutputStream(), pdfDoc);
- return xObject;
- }
-
- /**
- * Returns the XObject name for this object.
- * @return The name by which this XObject is recorded in the XObject
- * subdictionary.
- */
- public String getXObjectName() {
- return "X" + this.xNumber;
- }
-
- /**
- * Returns the subtype for this XObject.
- * @return The subtype for this XObject.
- */
- protected abstract String xObjectSubtype();
-
- /**
- * Add the content specific to this type of XObject to the content stream.
- * @param doc The PDF document.
- * @throws PdfException For errors in the graphic or when writing to the
- * stream.
- */
- protected abstract void xObjectContent(PdfDocument4a doc) throws PdfException;
-
- /**
- * Subclasses return any specialized dictionary entries here, so that they
- * are included when writing the stream dictionary.
- * @param doc The PDF document.
- * @return The dictonary entries specific to this type of XObject.
- * @exception GraphicException For errors during parsing of the graphic content.
- */
- protected abstract String specialXObjectDictEntries(PdfDocument4a doc) throws GraphicException;
-
- /**
- * Return an appropriate compression filter for the Graphic.
- * @param outputStream The output stream into which the compressed data should be written.
- * @param doc The PDF document.
- * @return An appropriate compression filter, or null if no compression should be used.
- * @exception GraphicException For error reading Graphic file.
- */
- private PsEncodeFilter getFilter(final OutputStream outputStream, final PdfDocument4a doc)
- throws GraphicException {
- final PsServer psServer = doc.getPsServer();
- PsEncodeFilter filter = null;
- final Graphic graphic = this.getGraphic();
- if (graphic.getGraphicType() == Graphic.Type.JPEG) {
- filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
- filter.setInactive();
- return filter;
- }
- if (graphic.getGraphicType() == Graphic.Type.TIFF) {
- final Graphic.Compression imageCompression
- = graphic.getCompressionType();
- switch (imageCompression) {
- case UNCOMPRESSED:
- return null;
- case CCITT_GROUP_3:
- filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
- filter.setInactive();
- return filter;
- case CCITT_GROUP_4:
- filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
- filter.setInactive();
- filter.setDecodeParms("<< /K -1 /Columns " + graphic.pixelWidth() + " >>");
- return filter;
- case JPEG:
- filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
- filter.setInactive();
- return filter;
- default:
- throw new GraphicException("Error while loading image "
- + graphic.getUrl() + " : "
- + this.getClass() + " - "
- + "unsupported compression value "
- + imageCompression);
- }
- }
- return null;
- }
-
- /**
- * Adds the normal stream filters used for graphics.
- * @param doc The PDF document.
- */
- protected void addStreamFilters(final PdfDocument4a doc) {
- try {
- if (this.filter == null) {
- this.addDefaultFilters(doc);
- } else {
- this.addFilter(this.filter);
- }
- } catch (final PdfException e) {
- /* Ignore, should not happen. */
- }
- if (doc.getEncryption() != null) {
- this.addEncryption(doc.getEncryption());
- }
- }
-
- /**
- * Return the encapsulated graphic.
- * @return The graphic.
- */
- public abstract Graphic getGraphic();
-
- /**
- * Returns the horizontal scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * This is used in transformations that are outside the actual XObject
- * definition, so that the XObject can be reused in other places, using
- * different content rectangles.
- * This abstraction is needed because bitmapped graphics are specified in
- * image space, and XForm graphics (SVG and EPS) are specified in form
- * space, which require radically different scaling mechanisms.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The horizontal scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
- /**
- * Returns the vertical scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * See {@link #getHorizontalScaling(java.awt.geom.Rectangle2D.Float)} for an
- * explanation of the need for this computation.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The vertical scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
- @Override
- protected String specialStreamDictEntries(final PdfDocument4a doc) throws PdfException {
- addStreamFilters(doc);
- this.xObjectContent(doc);
- final String dictEntries = this.applyFilters();
-
- final StringBuilder builder = new StringBuilder();
- builder.append("/Type /XObject" + EOL
- + "/Subtype /" + xObjectSubtype() + EOL);
-
- /* Let the subclasses add entries if they need to (Image, PS, Form). */
- try {
- builder.append(this.specialXObjectDictEntries(doc));
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
-
- builder.append(dictEntries);
- return builder.toString();
- }
-
- @Override
- protected void finalizeStreamContent(final PdfDocument4a doc) {
- /* Nothing needs to be done here. */
- }
-
-}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java (from rev 11831, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -0,0 +1,283 @@
+/*
+ * 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:
+ * JKT
+ * Eric SCHAEFFER
+ */
+
+package org.foray.pdf.object;
+
+import org.axsl.font.FontConsumer;
+import org.axsl.graphic.EpsGraphic;
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.graphic.MathGraphic;
+import org.axsl.graphic.SvgGraphic;
+import org.axsl.pdf.PdfException;
+import org.axsl.ps.PsEncodeFilter;
+import org.axsl.ps.PsFilterType;
+import org.axsl.ps.PsServer;
+
+import java.awt.geom.Rectangle2D;
+import java.io.OutputStream;
+
+/**
+ * <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
+ * <ul>
+ * <li>An image XObject. See {@link PdfImageXobject} for a concrete implementation.</li>
+ * <li>A form XObject. See {@link PdfFormXobject} for a concrete implementation.</li>
+ * <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
+ * for it.</li>
+ * </ul>
+ *
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
+ */
+public abstract class PdfXobject4a extends PdfStream {
+
+ /** The sequentially-assigned XObject number for this XObject. This is used
+ * to build the "name" entry in the XObject subdictionary. */
+ private int xNumber;
+
+ /** The PSFilter, if any, that should be applied to this XObject. */
+ private PsEncodeFilter filter;
+
+ /**
+ * Create an Xobject instance.
+ * @param doc The parent PDF document.
+ * @param graphic The graphic to be encapsulated.
+ */
+ protected PdfXobject4a(final PdfDocument4a doc, final Graphic graphic) {
+ if (graphic == null) {
+ throw new NullPointerException("Graphic must not be null.");
+ }
+ this.xNumber = doc.registerXObjectResource(graphic, this);
+ }
+
+ /**
+ * Factory method that encapsulates a Graphic instance into an appropriate
+ * PdfXobject instance.
+ * @param pdfDoc The parent PDF document.
+ * @param img The graphic to be encapsulated.
+ * @param fontConsumer The font consumer to use for resolving fonts in the SVG.
+ * @return An appropriate PdfXobject instance that encapsulates the input.
+ * @throws GraphicException For errors getting the appropriate filter.
+ */
+ public static PdfXobject4a makeXObject(final PdfDocument4a pdfDoc, final Graphic img,
+ final FontConsumer fontConsumer) throws GraphicException {
+ /* If it has already been created, reuse it ... */
+ PdfXobject4a xObject = pdfDoc.findXObject(img);
+ if (xObject != null) {
+ return xObject;
+ }
+
+ /* ... otherwise, create a new one. */
+ if (img instanceof EpsGraphic) {
+ final EpsGraphic epsGraphic = (EpsGraphic) img;
+ xObject = new PdfXformEps(pdfDoc, epsGraphic);
+ } else if (img instanceof SvgGraphic) {
+ final SvgGraphic svgGraphic = (SvgGraphic) img;
+ xObject = new PdfXformSvg(pdfDoc, svgGraphic, fontConsumer);
+ } else if (img instanceof MathGraphic) {
+ final MathGraphic mathGraphic = (MathGraphic) img;
+ xObject = new PdfXformMath(pdfDoc, mathGraphic, fontConsumer);
+ } else if (img.getGraphicType() == Graphic.Type.PDF) {
+ xObject = new PdfXreference(pdfDoc, img);
+ } else {
+ /* The following line is bogus, and is intended only to make sure
+ * that no exceptions are thrown. If there are any exceptions
+ * thrown, we don't want to create the xObject. */
+ img.getColorSpace();
+ xObject = new PdfImageXobject(pdfDoc, img);
+ }
+ xObject.filter = xObject.getFilter(xObject.getOutputStream(), pdfDoc);
+ return xObject;
+ }
+
+ /**
+ * Returns the XObject name for this object.
+ * @return The name by which this XObject is recorded in the XObject
+ * subdictionary.
+ */
+ public String getXObjectName() {
+ return "X" + this.xNumber;
+ }
+
+ /**
+ * Returns the subtype for this XObject.
+ * @return The subtype for this XObject.
+ */
+ protected abstract String xObjectSubtype();
+
+ /**
+ * Add the content specific to this type of XObject to the content stream.
+ * @param doc The PDF document.
+ * @throws PdfException For errors in the graphic or when writing to the
+ * stream.
+ */
+ protected abstract void xObjectContent(PdfDocument4a doc) throws PdfException;
+
+ /**
+ * Subclasses return any specialized dictionary entries here, so that they
+ * are included when writing the stream dictionary.
+ * @param doc The PDF document.
+ * @return The dictonary entries specific to this type of XObject.
+ * @exception GraphicException For errors during parsing of the graphic content.
+ */
+ protected abstract String specialXObjectDictEntries(PdfDocument4a doc) throws GraphicException;
+
+ /**
+ * Return an appropriate compression filter for the Graphic.
+ * @param outputStream The output stream into which the compressed data should be written.
+ * @param doc The PDF document.
+ * @return An appropriate compression filter, or null if no compression should be used.
+ * @exception GraphicException For error reading Graphic file.
+ */
+ private PsEncodeFilter getFilter(final OutputStream outputStream, final PdfDocument4a doc)
+ throws GraphicException {
+ final PsServer psServer = doc.getPsServer();
+ PsEncodeFilter filter = null;
+ final Graphic graphic = this.getGraphic();
+ if (graphic.getGraphicType() == Graphic.Type.JPEG) {
+ filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
+ filter.setInactive();
+ return filter;
+ }
+ if (graphic.getGraphicType() == Graphic.Type.TIFF) {
+ final Graphic.Compression imageCompression
+ = graphic.getCompressionType();
+ switch (imageCompression) {
+ case UNCOMPRESSED:
+ return null;
+ case CCITT_GROUP_3:
+ filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
+ filter.setInactive();
+ return filter;
+ case CCITT_GROUP_4:
+ filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
+ filter.setInactive();
+ filter.setDecodeParms("<< /K -1 /Columns " + graphic.pixelWidth() + " >>");
+ return filter;
+ case JPEG:
+ filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
+ filter.setInactive();
+ return filter;
+ default:
+ throw new GraphicException("Error while loading image "
+ + graphic.getUrl() + " : "
+ + this.getClass() + " - "
+ + "unsupported compression value "
+ + imageCompression);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Adds the normal stream filters used for graphics.
+ * @param doc The PDF document.
+ */
+ protected void addStreamFilters(final PdfDocument4a doc) {
+ try {
+ if (this.filter == null) {
+ this.addDefaultFilters(doc);
+ } else {
+ this.addFilter(this.filter);
+ }
+ } catch (final PdfException e) {
+ /* Ignore, should not happen. */
+ }
+ if (doc.getEncryption() != null) {
+ this.addEncryption(doc.getEncryption());
+ }
+ }
+
+ /**
+ * Return the encapsulated graphic.
+ * @return The graphic.
+ */
+ public abstract Graphic getGraphic();
+
+ /**
+ * Returns the horizontal scaling factor that should be used for a specific
+ * "Do" for a specific content rectangle.
+ * This is used in transformations that are outside the actual XObject
+ * definition, so that the XObject can be reused in other places, using
+ * different content rectangles.
+ * This abstraction is needed because bitmapped graphics are specified in
+ * image space, and XForm graphics (SVG and EPS) are specified in form
+ * space, which require radically different scaling mechanisms.
+ * @param contentRectangle The content rectangle into which the graphic
+ * will be scaled.
+ * @return The horizontal scaling factor that should be applied to this
+ * graphic when converting from its native space to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
+
+ /**
+ * Returns the vertical scaling factor that should be used for a specific
+ * "Do" for a specific content rectangle.
+ * See {@link #getHorizontalScaling(java.awt.geom.Rectangle2D.Float)} for an
+ * explanation of the need for this computation.
+ * @param contentRectangle The content rectangle into which the graphic
+ * will be scaled.
+ * @return The vertical scaling factor that should be applied to this
+ * graphic when converting from its native space to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
+
+ @Override
+ protected String specialStreamDictEntries(final PdfDocument4a doc) throws PdfException {
+ addStreamFilters(doc);
+ this.xObjectContent(doc);
+ final String dictEntries = this.applyFilters();
+
+ final StringBuilder builder = new StringBuilder();
+ builder.append("/Type /XObject" + EOL
+ + "/Subtype /" + xObjectSubtype() + EOL);
+
+ /* Let the subclasses add entries if they need to (Image, PS, Form). */
+ try {
+ builder.append(this.specialXObjectDictEntries(doc));
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+
+ builder.append(dictEntries);
+ return builder.toString();
+ }
+
+ @Override
+ protected void finalizeStreamContent(final PdfDocument4a doc) {
+ /* Nothing needs to be done here. */
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-19 22:36:29
|
Revision: 11834
http://sourceforge.net/p/foray/code/11834
Author: victormote
Date: 2021-01-19 22:36:27 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Add some doc.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java 2021-01-19 22:03:46 UTC (rev 11833)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java 2021-01-19 22:36:27 UTC (rev 11834)
@@ -163,14 +163,28 @@
/** The maximum value for an object generation. */
public static final int MAX_OBJECT_GENERATION = 65535;
- /** Constant indicating the number of elements in a cubic element, which is {@value}. */
- public static final byte QTY_ELEMENTS_CUBIC = 6;
+ /**
+ * Constant indicating the number of elements describing the end point of a line when drawing a path, which is
+ * {@value}.
+ * There is 1 point defined, containing 2 elements.
+ * @see java.awt.geom.PathIterator#SEG_LINETO
+ */
+ public static final byte QTY_ELEMENTS_LINEAR = 2;
- /** Constant indicating the number of elements in a quad element, which is {@value}. */
+ /**
+ * Constant indicating the number of elements in a quadratic parametric curve when drawing a path, which is
+ * {@value}.
+ * There are 2 points defined, each containing 2 elements.
+ * @see java.awt.geom.PathIterator#SEG_QUADTO
+ */
public static final byte QTY_ELEMENTS_QUAD = 4;
- /** Constant indicating the number of elements in a linear element, which is {@value}. */
- public static final byte QTY_ELEMENTS_LINEAR = 2;
+ /**
+ * Constant indicating the number of elements in a cubic Bezier curve when drawing a path, which is {@value}.
+ * There are 3 points defined, each containing 2 elements.
+ * @see java.awt.geom.PathIterator#SEG_CUBICTO
+ */
+ public static final byte QTY_ELEMENTS_CUBIC = 6;
/**
* Private constructor. This is a utility class and should never be instantiated.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-19 22:03:49
|
Revision: 11833
http://sourceforge.net/p/foray/code/11833
Author: victormote
Date: 2021-01-19 22:03:46 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Move some constants to the constants class.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java 2021-01-19 13:54:52 UTC (rev 11832)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java 2021-01-19 22:03:46 UTC (rev 11833)
@@ -163,6 +163,15 @@
/** The maximum value for an object generation. */
public static final int MAX_OBJECT_GENERATION = 65535;
+ /** Constant indicating the number of elements in a cubic element, which is {@value}. */
+ public static final byte QTY_ELEMENTS_CUBIC = 6;
+
+ /** Constant indicating the number of elements in a quad element, which is {@value}. */
+ public static final byte QTY_ELEMENTS_QUAD = 4;
+
+ /** Constant indicating the number of elements in a linear element, which is {@value}. */
+ public static final byte QTY_ELEMENTS_LINEAR = 2;
+
/**
* Private constructor. This is a utility class and should never be instantiated.
*/
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-19 13:54:52 UTC (rev 11832)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java 2021-01-19 22:03:46 UTC (rev 11833)
@@ -39,6 +39,7 @@
import org.foray.common.i18n.Orthography4a;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
+import org.foray.pdf.PdfConstants;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontOptions;
@@ -131,18 +132,6 @@
}
- /** Constant indicating the number of elements in a cubic element, that is,
- * 6. */
- public static final byte QTY_ELEMENTS_CUBIC = 6;
-
- /** Constant indicating the number of elements in a quad element, that is,
- * 4. */
- public static final byte QTY_ELEMENTS_QUAD = 4;
-
- /** Constant indicating the number of elements in a linear element, that is,
- * 2. */
- public static final byte QTY_ELEMENTS_LINEAR = 2;
-
/** The current stream to add PDF commands to. */
private CharacterOutputStream currentStream;
@@ -377,7 +366,7 @@
final Shape imclip = getClip();
writeClip(imclip);
final String matrixString = matrixToString(matrix,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
+ PdfConstants.QTY_ELEMENTS_CUBIC);
this.write(matrixString + "cm");
this.restoreGraphicsState();
return true;
@@ -425,23 +414,19 @@
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_CUBIC);
this.write(matrixString + "c");
break;
case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "l");
break;
case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "m");
break;
case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_QUAD);
this.write(matrixString + "y");
break;
case PathIterator.SEG_CLOSE:
@@ -467,28 +452,23 @@
final PathIterator iter = s.getPathIterator(getTransform());
String matrixString = null;
while (!iter.isDone()) {
- final double vals[] =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
+ final double vals[] = new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
switch (type) {
case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_CUBIC);
this.write(matrixString + "c");
break;
case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "l");
break;
case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "m");
break;
case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_QUAD);
this.write(matrixString + "y");
break;
case PathIterator.SEG_CLOSE:
@@ -800,29 +780,24 @@
final PathIterator iter = s.getPathIterator(getTransform());
while (!iter.isDone()) {
- final double vals[] =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
+ final double vals[] = new double[PsUtil.MATRIX_QTY_ELEMENTS];
final int type = iter.currentSegment(vals);
String matrixString = null;
switch (type) {
case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_CUBIC);
this.write(matrixString + "c");
break;
case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "l");
break;
case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_LINEAR);
this.write(matrixString + "m");
break;
case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
+ matrixString = matrixToString(vals, PdfConstants.QTY_ELEMENTS_QUAD);
this.write(matrixString + "y");
break;
case PathIterator.SEG_CLOSE:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-19 13:55:00
|
Revision: 11832
http://sourceforge.net/p/foray/code/11832
Author: victormote
Date: 2021-01-19 13:54:52 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Remove dependencies on Batik modules that are apparently not needed.
Modified Paths:
--------------
trunk/foray/foray-graphic/build.gradle
Modified: trunk/foray/foray-graphic/build.gradle
===================================================================
--- trunk/foray/foray-graphic/build.gradle 2021-01-19 13:09:03 UTC (rev 11831)
+++ trunk/foray/foray-graphic/build.gradle 2021-01-19 13:54:52 UTC (rev 11832)
@@ -7,16 +7,9 @@
api group: 'org.apache.xmlgraphics', name: 'batik-bridge', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-gvt', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-parser', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-script', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-transcoder', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-util', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-svg-dom', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-dom', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-xml', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-css', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-awt-util', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-ext', version: batikVersion
- api group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: batikVersion
// api group: 'net.sourceforge.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
api group: 'de.rototor.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
api group: 'org.axsl', name: 'axsl-graphic', version: axslVersion
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-19 13:09:07
|
Revision: 11831
http://sourceforge.net/p/foray/code/11831
Author: victormote
Date: 2021-01-19 13:09:03 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Conform to aXSL change: Change API for rendering a vector graphic to PDF to use a Java Graphics2D implementation to do the rendering. This pushes the creation of the Graphics2D instance out of foray-graphic and into foray-pdf.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfaNode.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
trunk/foray/foray-pdf/build.gradle
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
Added Paths:
-----------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphicsConfiguration.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphicsDevice.java
Removed Paths:
-------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsConfiguration.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsDevice.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
Deleted: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-19 03:10:34 UTC (rev 11830)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-19 13:09:03 UTC (rev 11831)
@@ -1,950 +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:
- * Original Author: <a href="mailto:ke...@af...">Keiron Liddle</a>
- */
-
-package org.foray.graphic.batik;
-
-import org.foray.common.CharacterOutputStream;
-import org.foray.common.Gradient4a;
-import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.Orthography4a;
-import org.foray.common.ps.PsColor;
-import org.foray.common.ps.PsUtil;
-
-import org.axsl.font.FontConsumer;
-import org.axsl.font.FontOptions;
-import org.axsl.font.FontUse;
-import org.axsl.font.FontUtility;
-import org.axsl.graphic.output.GraphicOutputContext;
-import org.axsl.pdf.PdfPage;
-
-import org.slf4j.LoggerFactory;
-
-import java.awt.AlphaComposite;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.GradientPaint;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.TexturePaint;
-import java.awt.color.ColorSpace;
-import java.awt.font.TextAttribute;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferInt;
-import java.awt.image.ImageObserver;
-import java.awt.image.Raster;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.AttributedCharacterIterator;
-import java.text.CharacterIterator;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * A {@link Graphics2D} implementation used by Batik to render two-dimensional
- * objects (the SVG image) into a PDF document.
- */
-public class PdfGraphics2D
- extends org.apache.batik.ext.awt.g2d.AbstractGraphics2D {
- /* TODO: The capabilities in this class need to be merged with those of
- * {@link PDFContentStream}. This class should essentially use the content
- * stream to do most of the work. */
-
- /**
- * Private inner bean to track a subset of the graphics state.
- */
- private final class PdfGraphicsState {
-
- /** The stroke color. */
- private Color strokeColor;
-
- /** The "non-stroke" or "other" color. */
- private Color fillColor;
-
- /** The font. */
- private FontUse font;
-
- /** The font size. */
- private float fontSize;
-
- /**
- * Constructor.
- * @param existingState The state on which the new state should be based.
- * If null, the new state is set to default values.
- */
- private PdfGraphicsState(final PdfGraphicsState existingState) {
- if (existingState != null) {
- this.strokeColor = existingState.strokeColor;
- this.fillColor = existingState.fillColor;
- this.font = existingState.font;
- this.fontSize = existingState.fontSize;
- }
- }
-
- }
-
- /** Constant indicating the number of elements in a cubic element, that is,
- * 6. */
- public static final byte QTY_ELEMENTS_CUBIC = 6;
-
- /** Constant indicating the number of elements in a quad element, that is,
- * 4. */
- public static final byte QTY_ELEMENTS_QUAD = 4;
-
- /** Constant indicating the number of elements in a linear element, that is,
- * 2. */
- public static final byte QTY_ELEMENTS_LINEAR = 2;
-
- /** The current stream to add PDF commands to. */
- private CharacterOutputStream currentStream;
-
- /** The override font. */
- private FontUse overrideFont = null;
-
- /** The override font size, in points. */
- private float overrideFontSize;
-
- /** The font consumer instance for this document. */
- private FontConsumer fontConsumer;
-
- /** Used to create proper font metrics. */
- private Graphics2D fmg;
-
- /** The PDF context. */
- private GraphicOutputContext pdfContext;
-
- /** The graphics state stack. The top item on the stack is always the
- * current graphics state. The next one down is what will be current after
- * the next "restore". */
- private Stack<PdfGraphics2D.PdfGraphicsState> graphicsStateStack = new Stack<PdfGraphics2D.PdfGraphicsState>();
-
- /** Indicates whether any I/O Exceptions were found while processing. */
- private boolean ioErrorFound = false;
-
- /**
- * Create a new PdfGraphics2D with the given pdf document info.
- * This is used to create a Graphics object for use inside an already existing document.
- * @param textAsShapes Set this to true so that text will be rendered using curves and not the font.
- * @param fontConsumer The font consumer for this document.
- * @param pdfContext The PDF context in which this content is being written.
- * @param outputStream The output stream to which this processor writes its PDF output.
- */
- public PdfGraphics2D(final boolean textAsShapes, final FontConsumer fontConsumer,
- final GraphicOutputContext pdfContext, final OutputStream outputStream) {
- super(textAsShapes);
- /* TODO: Only write the comments if running in debug mode?? */
- this.currentStream = new CharacterOutputStream(outputStream, true);
- this.comment("%%%% Start FOrayGraphic SVG-to-PDF conversion. %%%%");
-
- this.fontConsumer = fontConsumer;
- this.pdfContext = pdfContext;
- this.graphicsStateStack.push(new PdfGraphicsState(null));
- }
-
- /**
- * This constructor supports the create method.
- * @param g The encapsulated image.
- */
- public PdfGraphics2D(final PdfGraphics2D g) {
- super(g);
- this.currentStream = g.currentStream;
- this.fontConsumer = g.fontConsumer;
- this.pdfContext = g.pdfContext;
- this.graphicsStateStack = g.graphicsStateStack;
- }
-
- /**
- * Converts a matrix of octal values to its PDF representation.
- * @param theMatrix The matrix to be converted.
- * @return The PDF representation of the matrix.
- */
- public static String octalMatrixToString(final double[] theMatrix) {
- final StringBuilder buffer = new StringBuilder();
- for (int i = 0; i < theMatrix.length; i++) {
- buffer.append(PsUtil.doubleOut(theMatrix[i],
- WellKnownConstants.RADIX_BASE_8));
- buffer.append(" ");
- }
- return buffer.toString();
- }
-
- /**
- * Converts a matrix of decimal values to its PDF representation.
- * @param theMatrix The matrix to be converted.
- * @param numElements The number of elements in the matrix to be included
- * in the output.
- * @return The PDF representation of the matrix.
- */
- public static String matrixToString(final double[] theMatrix,
- final int numElements) {
- final StringBuilder buffer = new StringBuilder();
- for (int i = 0; i < numElements; i++) {
- buffer.append(PsUtil.doubleOut(theMatrix[i]) + " ");
- }
- return buffer.toString();
- }
-
- /**
- * Sets the graphic context.
- * @param c The new graphic context.
- */
- public void setGraphicContext(
- final org.apache.batik.ext.awt.g2d.GraphicContext c) {
- gc = c;
- }
-
- /**
- * Sets the override font and size.
- * @param infont The new override font.
- * @param size The new override font size.
- */
- public void setOverrideFontState(final FontUse infont, final float size) {
- this.overrideFont = infont;
- this.overrideFontSize = size;
- }
-
- @Override
- public Graphics create() {
- return new PdfGraphics2D(this);
- }
-
- /**
- * This is a pdf specific method used to add a link to the pdf document.
- * @param pdfPage The page on which the link should be placed.
- * @param bounds The location of the link.
- * @param trans The affine transform.
- * @param dest The name of the destination.
- * @param externalLink Set to true if the link is to an external document.
- */
- public void addLink(final PdfPage pdfPage, final Shape bounds,
- final AffineTransform trans, final String dest,
- final boolean externalLink) {
- final AffineTransform at = getTransform();
- Shape b = at.createTransformedShape(bounds);
- b = trans.createTransformedShape(b);
- final Rectangle2D.Float linkRectangle =
- (Rectangle2D.Float) b.getBounds2D();
- linkRectangle.height *= -1;
- if (externalLink) {
- final String pdfdest = "/XYZ " + dest;
- pdfPage.createLink(linkRectangle, pdfdest, true);
- } else {
- pdfPage.createLink(linkRectangle, dest, false);
- }
- }
-
- @Override
- public boolean drawImage(final Image img, final int x, final int y,
- final ImageObserver observer) {
- final int width = img.getWidth(observer);
- final int height = img.getHeight(observer);
-
- if (width == -1 || height == -1) {
- return false;
- }
-
- final int numChannels = this.getGraphicsState().strokeColor.getColorSpace().getNumComponents();
- final Dimension size = new Dimension(width * numChannels,
- height * numChannels);
- final BufferedImage buf = new BufferedImage(size.width, size.height,
- BufferedImage.TYPE_INT_ARGB);
-
- final Graphics2D g = buf.createGraphics();
- g.setComposite(AlphaComposite.SrcOver);
- g.setBackground(new Color(1, 1, 1, 0));
- g.setPaint(new Color(1, 1, 1, 0));
- g.fillRect(0, 0, width * numChannels, height * numChannels);
- g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight()));
-
- if (!g.drawImage(img, 0, 0, buf.getWidth(), buf.getHeight(),
- observer)) {
- return false;
- }
- g.dispose();
-
- final byte[] result = new byte[buf.getWidth() * buf.getHeight()
- * numChannels];
-
- final Raster raster = buf.getData();
- final DataBuffer bd = raster.getDataBuffer();
-
- int count = 0;
- int[] iarray;
- int i;
- int j;
- int val;
- int alpha;
- int add;
- int mult;
- switch (bd.getDataType()) {
- case DataBuffer.TYPE_INT:
- final int[][] idata = ((DataBufferInt) bd).getBankData();
- for (i = 0; i < idata.length; i++) {
- iarray = idata[i];
- for (j = 0; j < iarray.length; j++) {
- val = iarray[j];
- alpha = val >>> WellKnownConstants.SHIFT_3_BYTES;
- // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF);
- if (alpha != WellKnownConstants.MAX_8_BIT_UNSIGNED_INT) {
- // Composite with opaque white...
- add = WellKnownConstants.MAX_8_BIT_UNSIGNED_INT - alpha;
- mult = (alpha << WellKnownConstants.SHIFT_2_BYTES)
- / WellKnownConstants.MAX_8_BIT_UNSIGNED_INT;
- result[count++] =
- (byte) (add
- + ((((val >> WellKnownConstants.SHIFT_2_BYTES)
- & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT)
- * mult) >> WellKnownConstants.SHIFT_2_BYTES));
- result[count++] =
- (byte) (add
- + ((((val >> WellKnownConstants.SHIFT_1_BYTE)
- & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT)
- * mult) >> WellKnownConstants.SHIFT_2_BYTES));
- result[count++] = (byte) (add
- + (((val & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT)
- * mult)
- >> WellKnownConstants.SHIFT_2_BYTES));
- } else {
- result[count++] = (byte) ((val >> WellKnownConstants.SHIFT_2_BYTES)
- & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT);
- result[count++] = (byte) ((val >> WellKnownConstants.SHIFT_1_BYTE)
- & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT);
- result[count++] = (byte) (val
- & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT);
- }
- }
- }
- break;
- default:
- // error
- break;
- }
-
- // now do any transformation required and add the actual image
- // placement instance
- final AffineTransform at = getTransform();
- final double[] matrix = new double[PsUtil.MATRIX_QTY_ELEMENTS];
- at.getMatrix(matrix);
- this.saveGraphicsState();
- final Shape imclip = getClip();
- writeClip(imclip);
- final String matrixString = matrixToString(matrix,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
- this.write(matrixString + "cm");
- this.restoreGraphicsState();
- return true;
- }
-
- @Override
- public boolean drawImage(final Image img, final int x, final int y,
- final int width, final int height, final ImageObserver observer) {
- return true;
- }
-
- @Override
- public void dispose() {
- this.comment("%%%% End FOrayGraphic SVG-to-PDF conversion. %%%%");
- this.currentStream = null;
- this.graphicsStateStack = null;
- }
-
- @Override
- public void draw(final Shape s) {
- final Color c = getColor();
- if (c.getAlpha() == 0) {
- return;
- }
-
- this.saveGraphicsState();
- final Shape imclip = getClip();
- writeClip(imclip);
- applyColor(c, false);
-
- applyPaint(getPaint(), false);
- applyStroke(getStroke());
-
- final AffineTransform trans = getTransform();
- final double[] tranvals =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
- trans.getMatrix(tranvals);
- String matrixString = octalMatrixToString(tranvals);
- this.write(matrixString + "cm");
-
- final PathIterator iter = s.getPathIterator(new AffineTransform());
- while (!iter.isDone()) {
- final double vals[] =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
- final int type = iter.currentSegment(vals);
- switch (type) {
- case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
- this.write(matrixString + "c");
- break;
- case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "l");
- break;
- case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "m");
- break;
- case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
- this.write(matrixString + "y");
- break;
- case PathIterator.SEG_CLOSE:
- this.write("h");
- break;
- default:
- break;
- }
- iter.next();
- }
- doDrawing(false, true, false);
- this.restoreGraphicsState();
- }
-
- /**
- * Clip the document to a specific shape.
- * @param s The shape to which the document should be clipped.
- */
- protected void writeClip(final Shape s) {
- if (s == null) {
- return;
- }
- final PathIterator iter = s.getPathIterator(getTransform());
- String matrixString = null;
- while (!iter.isDone()) {
- final double vals[] =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
- final int type = iter.currentSegment(vals);
- switch (type) {
- case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
- this.write(matrixString + "c");
- break;
- case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "l");
- break;
- case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "m");
- break;
- case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
- this.write(matrixString + "y");
- break;
- case PathIterator.SEG_CLOSE:
- this.write("h");
- break;
- default:
- break;
- }
- iter.next();
- }
- // clip area
- this.write("W");
- this.write("n");
- }
-
- /**
- * Apply a color to the document.
- * @param color The color to be applied.
- * @param fill Set to true if the color is for fill, false if for stroke.
- */
- protected void applyColor(final Color color, final boolean fill) {
- boolean anyChange = false;
- if (fill) {
- anyChange = ! color.equals(this.getGraphicsState().fillColor);
- this.getGraphicsState().fillColor = color;
- } else {
- anyChange = ! color.equals(this.getGraphicsState().strokeColor);
- this.getGraphicsState().strokeColor = color;
- }
- if (anyChange) {
- this.write(PsColor.toPS(color, fill));
- }
- }
-
- /**
- * Apply a paint to the document.
- * @param paint The paint to be applied.
- * @param fill Set to true if the paint is for fill, false if for stroke.
- */
- protected void applyPaint(final Paint paint, final boolean fill) {
- if (paint instanceof GradientPaint) {
- final GradientPaint gp = (GradientPaint) paint;
- final Color c1 = gp.getColor1();
- final Color c2 = gp.getColor2();
- final Point2D p1 = gp.getPoint1();
- final Point2D p2 = gp.getPoint2();
-
- final List<Double> theCoords = new ArrayList<Double>();
- theCoords.add(p1.getX());
- theCoords.add(p1.getY());
- theCoords.add(p2.getX());
- theCoords.add(p2.getY());
-
- final List<Boolean> theExtend = new ArrayList<Boolean>();
- theExtend.add(Boolean.TRUE);
- theExtend.add(Boolean.TRUE);
-
- final List<Double> theDomain = new ArrayList<Double>();
- theDomain.add(0D);
- theDomain.add(1D);
-
- final List<Double> theEncode = new ArrayList<Double>();
- theEncode.add(0D);
- theEncode.add(1D);
- theEncode.add(0D);
- theEncode.add(1D);
-
- final List<Double> theBounds = new ArrayList<Double>();
- theBounds.add(0D);
- theBounds.add(1D);
-
- final List<Color> someColors = new ArrayList<Color>();
-
- someColors.add(c1);
- someColors.add(c2);
-
- final ColorSpace aColorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
- final Gradient4a gradient = new Gradient4a(false, aColorSpace, someColors, null, theCoords);
- final String gradientName = this.pdfContext.getGradientName(gradient);
- if (fill) {
- this.write("/Pattern cs /" + gradientName + " scn" + WellKnownConstants.ASCII_LINEFEED);
- } else {
- this.write("/Pattern CS /" + gradientName + " SCN" + WellKnownConstants.ASCII_LINEFEED);
- }
- } else if (paint instanceof TexturePaint) { }
- }
-
- /**
- * Apply a stroke to the document.
- * @param stroke The stroke to be applied.
- */
- protected void applyStroke(final Stroke stroke) {
- if (stroke instanceof BasicStroke) {
- final BasicStroke bs = (BasicStroke) stroke;
-
- final float[] da = bs.getDashArray();
- if (da != null) {
- this.write("[");
- for (int count = 0; count < da.length; count++) {
- if (((int) da[count]) == 0) {
- // the dasharray units in pdf are (whole) numbers
- // in user space units, cannot be 0
- this.write("1");
- } else {
- this.write("" + ((int) da[count]));
- }
- if (count < da.length - 1) {
- this.write(" ");
- }
- }
- this.write("] ");
- final float offset = bs.getDashPhase();
- this.write(((int) offset) + " d");
- }
- final int ec = bs.getEndCap();
- switch (ec) {
- case BasicStroke.CAP_BUTT:
- this.write(0 + " J");
- break;
- case BasicStroke.CAP_ROUND:
- this.write(1 + " J");
- break;
- case BasicStroke.CAP_SQUARE:
- this.write(2 + " J");
- break;
- }
-
- final int lj = bs.getLineJoin();
- switch (lj) {
- case BasicStroke.JOIN_MITER:
- this.write(0 + " j");
- break;
- case BasicStroke.JOIN_ROUND:
- this.write(1 + " j");
- break;
- case BasicStroke.JOIN_BEVEL:
- this.write(2 + " j");
- break;
- }
- final float lw = bs.getLineWidth();
- this.write(PsUtil.doubleOut(lw) + " w");
-
- final float ml = bs.getMiterLimit();
- this.write(PsUtil.doubleOut(ml) + " M");
- }
- }
-
- @Override
- public void drawRenderedImage(final RenderedImage img, final AffineTransform xform) {
- }
-
- @Override
- public void drawRenderableImage(final RenderableImage img, final AffineTransform xform) {
- }
-
- @Override
- public void drawString(final String s, final float x, final float y) {
- final FontUse font;
- final float size;
- if (this.overrideFont == null) {
- font = getImplicitFont();
- size = getFont().getSize();
- } else {
- font = this.overrideFont;
- size = this.overrideFontSize;
- this.overrideFont = null;
- }
-
- if (font != this.getGraphicsState().font
- || (size != this.getGraphicsState().fontSize)) {
- this.getGraphicsState().font = font;
- this.getGraphicsState().fontSize = size;
- final String fontName = this.pdfContext.getFontName(font);
- this.write("/" + fontName + " " + size + " Tf");
- }
-
- this.saveGraphicsState();
-
- final Shape imclip = getClip();
- writeClip(imclip);
- Color c = getColor();
- applyColor(c, true);
- c = getBackground();
- applyColor(c, false);
-
- this.write("BT");
-
- final AffineTransform trans = getTransform();
- trans.translate(x, y);
- final double[] vals = new double[PsUtil.MATRIX_QTY_ELEMENTS];
- trans.getMatrix(vals);
-
- final String matrixString = octalMatrixToString(vals);
- this.write(matrixString + "cm");
- this.write("1 0 0 -1 0 0 Tm ");
-
- final CharSequence outputString = font.textToPdf(s, FontOptions.DEFAULT, Orthography4a.USA);
- this.write(outputString);
-
- this.write("ET");
- this.restoreGraphicsState();
- }
-
- /**
- * This method attempts to obtain an org.foray.font.Font instance from a
- * java.awt.Font that comes from the Batik environment.
- * @return The axsl Font, or null if the internal font cannot be converted.
- */
- private FontUse getImplicitFont() {
- final Font gFont = getFont();
- String fontFamily = gFont.getFamily();
- if (fontFamily.equals("sanserif")) {
- fontFamily = "sans-serif";
- }
- final float fontSize = gFont.getSize();
- org.axsl.font.Font.Style fontStyle = org.axsl.font.Font.Style.NORMAL;
- if (gFont.isItalic()) {
- fontStyle = org.axsl.font.Font.Style.ITALIC;
- }
- org.axsl.font.Font.Weight fontWeight
- = org.axsl.font.Font.Weight.NORMAL;
- if (gFont.isBold()) {
- fontWeight = org.axsl.font.Font.Weight.BOLD;
- }
- FontUse fontUse = this.fontConsumer.selectFontXsl(
- org.axsl.font.Font.SelectionStrategy.AUTO,
- FontUtility.foFontFamily(fontFamily),
- fontStyle, fontWeight,
- org.axsl.font.Font.Variant.NORMAL,
- org.axsl.font.Font.Stretch.NORMAL,
- (int) (fontSize * WellKnownConstants.MILLIPOINTS_PER_POINT),
- ' ');
- if (fontUse == null) {
- fontUse = this.fontConsumer.selectFontFallback();
- }
- return fontUse;
- }
-
- @Override
- public void drawString(final AttributedCharacterIterator iterator, final float x, final float y) {
- LoggerFactory.getLogger(this.getClass()).error("drawString(AttributedCharacterIterator)");
- /* TODO: This method may not ever be called, as we never see the above error logged. Investigate further. */
-
- final Shape imclip = getClip();
- writeClip(imclip);
- Color c = getColor();
- applyColor(c, true);
- c = getBackground();
- applyColor(c, false);
-
- this.write("BT");
-
- final AffineTransform trans = getTransform();
- trans.translate(x, y);
- final double[] vals = new double[PsUtil.MATRIX_QTY_ELEMENTS];
- trans.getMatrix(vals);
-
- for (char ch = iterator.first(); ch != CharacterIterator.DONE;
- ch = iterator.next()) {
- /* TODO: All of this should be integrated with the regular methods
- * in PDFContentStream. */
- final List<String> fontFamily = new ArrayList<String>(1);
- fontFamily.add((String) iterator.getAttribute(TextAttribute.FAMILY));
- final Float fontSize = (Float) iterator.getAttribute(
- TextAttribute.FAMILY);
- FontUse font = this.fontConsumer.selectFontCss(fontFamily,
- org.axsl.font.Font.Style.NORMAL,
- org.axsl.font.Font.Weight.NORMAL,
- org.axsl.font.Font.Variant.NORMAL,
- org.axsl.font.Font.Stretch.NORMAL, 0, ch);
- if (font == null) {
- font = this.fontConsumer.selectFontFallback();
- }
- final float size = fontSize.floatValue();
- if ((font != this.getGraphicsState().font)
- || (size != this.getGraphicsState().fontSize)) {
- this.getGraphicsState().font = font;
- this.getGraphicsState().fontSize = size;
- final String fontName = this.pdfContext.getFontName(font);
- this.write("/" + fontName + " " + size + " Tf");
- }
-
- final String matrixString = octalMatrixToString(vals);
- this.write(matrixString + " Tm (" + ch + ") Tj");
- }
-
- this.write("ET");
- }
-
- @Override
- public void fill(final Shape s) {
- Color c;
- c = getBackground();
- if (c.getAlpha() == 0) {
- c = getColor();
- if (c.getAlpha() == 0) {
- return;
- }
- }
- this.saveGraphicsState();
- final Shape imclip = getClip();
- writeClip(imclip);
- c = getColor();
- applyColor(c, true);
- c = getBackground();
- applyColor(c, false);
-
- applyPaint(getPaint(), true);
-
- final PathIterator iter = s.getPathIterator(getTransform());
- while (!iter.isDone()) {
- final double vals[] =
- new double[PsUtil.MATRIX_QTY_ELEMENTS];
- final int type = iter.currentSegment(vals);
- String matrixString = null;
- switch (type) {
- case PathIterator.SEG_CUBICTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_CUBIC);
- this.write(matrixString + "c");
- break;
- case PathIterator.SEG_LINETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "l");
- break;
- case PathIterator.SEG_MOVETO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_LINEAR);
- this.write(matrixString + "m");
- break;
- case PathIterator.SEG_QUADTO:
- matrixString = matrixToString(vals,
- PdfGraphics2D.QTY_ELEMENTS_QUAD);
- this.write(matrixString + "y");
- break;
- case PathIterator.SEG_CLOSE:
- this.write("h");
- break;
- default:
- break;
- }
- iter.next();
- }
- doDrawing(true, false,
- iter.getWindingRule() == PathIterator.WIND_EVEN_ODD);
- this.restoreGraphicsState();
- }
-
- /**
- * Add the commands to do the actual drawing.
- * @param fill Set to true if the item should be filled.
- * @param stroke Set to true if the item should be stroked.
- * @param nonzero Set to true to use the nonzero winding number rule.
- */
- protected void doDrawing(final boolean fill, final boolean stroke,
- final boolean nonzero) {
- if (fill) {
- if (stroke) {
- if (nonzero) {
- this.write("B*");
- } else {
- this.write("B");
- }
- } else {
- if (nonzero) {
- this.write("f*");
- } else {
- this.write("f");
- }
- }
- } else {
- // if(stroke)
- this.write("S");
- }
- }
-
- @Override
- public GraphicsConfiguration getDeviceConfiguration() {
- return new PdfGraphicsConfiguration();
- }
-
- @Override
- public FontMetrics getFontMetrics(final Font f) {
- return this.fmg.getFontMetrics(f);
- }
-
- @Override
- public void setXORMode(final Color c1) {
- }
-
-
- @Override
- public void copyArea(final int x, final int y, final int width, final int height, final int dx, final int dy) {
- }
-
- /**
- * Writes some content.
- * @param text The content to be written.
- */
- private void write(final CharSequence text) {
- try {
- this.currentStream.write(text);
- } catch (final IOException e) {
- this.ioErrorFound = true;
- }
- }
-
- /**
- * Writes some content.
- * @param text The content to be written.
- */
- private void comment(final String text) {
- try {
- this.currentStream.comment(text);
- } catch (final IOException e) {
- this.ioErrorFound = true;
- }
- }
-
- /**
- * Indicates whether any I/O errors were found while writing to the output
- * stream.
- * @return True iff there were I/O errors while writing to the output
- * stream.
- */
- public boolean ioErrorFound() {
- return this.ioErrorFound;
- }
-
- /**
- * Returns the current graphics state.
- * @return The current graphics state.
- */
- private PdfGraphicsState getGraphicsState() {
- return this.graphicsStateStack.peek();
- }
-
- /**
- * Saves the current PDF graphics state by pushing it onto the stack,
- * copying it, and making the copy the current graphics state.
- */
- private void saveGraphicsState() {
- this.write("q");
- /* Create a new state with the same settings as the current state. */
- final PdfGraphicsState newState = new PdfGraphicsState(
- this.getGraphicsState());
- /* Push it onto the stack. */
- this.graphicsStateStack.push(newState);
- }
-
- /**
- * Restores the previously-saved PDF graphics state by popping the current
- * one off of the stack.
- */
- private void restoreGraphicsState() {
- this.write("Q");
- this.graphicsStateStack.pop();
- }
-
-}
Deleted: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsConfiguration.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsConfiguration.java 2021-01-19 03:10:34 UTC (rev 11830)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsConfiguration.java 2021-01-19 13:09:03 UTC (rev 11831)
@@ -1,139 +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$
- */
-
-package org.foray.graphic.batik;
-
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.Rectangle;
-import java.awt.Transparency;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.VolatileImage;
-
-/**
- * PDF-specific implementation of {@link GraphicsConfiguration}, which describes
- * the characteristics of a graphics destination such as a printer or monitor,
- * or, in this case, a PDF document.
- */
-class PdfGraphicsConfiguration extends GraphicsConfiguration {
-
- /** Static item used to get an appropriate colormodel. */
- private static final BufferedImage BI_WITH_ALPHA =
- new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
-
- /** Static item used to get an appropriate colormodel. */
- private static final BufferedImage BI_WITHOUT_ALPHA =
- new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
-
- /**
- * {@inheritDoc}
- * Constructs a buffered image with an alpha channel, unless
- * transparencty is OPAQUE (no alpha at all).
- */
- @Override
- public BufferedImage createCompatibleImage(final int width,
- final int height, final int transparency) {
- if (transparency == Transparency.OPAQUE) {
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- }
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- }
-
- /**
- * {@inheritDoc}
- * Constructs a buffered image with an alpha channel.
- */
- @Override
- public BufferedImage createCompatibleImage(final int width,
- final int height) {
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- }
-
- @Override
- public VolatileImage createCompatibleVolatileImage(final int width,
- final int height) {
- /* Stub implementation to get Java 5 to compile.
- * TODO: This needs to be implemented properly. */
- return null;
- }
-
- @Override
- public VolatileImage createCompatibleVolatileImage(final int width,
- final int height, final int transparency) {
- /** Stub implementation to get Java 5 to compile.
- * TODO: This needs to be implemented properly. */
- return null;
- }
-
- @Override
- public Rectangle getBounds() {
- /* FIXX ME: This should return the page bounds in Pts,
- * I couldn't figure out how to get this for the current
- * page from the PDFDocument (this still works for now,
- * but it should be fixed...). */
- return null;
- }
-
- @Override
- public ColorModel getColorModel() {
- return PdfGraphicsConfiguration.BI_WITH_ALPHA.getColorModel();
- }
-
- @Override
- public ColorModel getColorModel(final int transparency) {
- if (transparency == Transparency.OPAQUE) {
- return PdfGraphicsConfiguration.BI_WITHOUT_ALPHA.getColorModel();
- }
- return PdfGraphicsConfiguration.BI_WITH_ALPHA.getColorModel();
- }
-
- /**
- * {@inheritDoc}
- * This implementation returns the default transform (1:1).
- */
- @Override
- public AffineTransform getDefaultTransform() {
- return new AffineTransform();
- }
-
- @Override
- public AffineTransform getNormalizingTransform() {
- return new AffineTransform(2, 0, 0, 2, 0, 0);
- }
-
- @Override
- public GraphicsDevice getDevice() {
- return new PdfGraphicsDevice(this);
- }
-
-}
Deleted: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsDevice.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsDevice.java 2021-01-19 03:10:34 UTC (rev 11830)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphicsDevice.java 2021-01-19 13:09:03 UTC (rev 11831)
@@ -1,95 +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$
- */
-
-package org.foray.graphic.batik;
-
-import java.awt.GraphicsConfigTemplate;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-
-/**
- * This implements the GraphicsDevice interface as appropriate for
- * a PdfGraphics2D. This is quite simple since we only have one
- * GraphicsConfiguration for now.
- */
-class PdfGraphicsDevice extends GraphicsDevice {
-
- /** The "parent" Graphics Config. */
- private GraphicsConfiguration gc;
-
- /** The array of possible Graphics Configs with which this device is
- * associated. */
- private GraphicsConfiguration[] configurations;
-
- /**
- * Create a new PDF graphics device.
- * @param gc The "parent" Graphics Config.
- */
- PdfGraphicsDevice(final PdfGraphicsConfiguration gc) {
- this.gc = gc;
- }
-
- /**
- * {@inheritDoc}
- * Override the superclass and return the only config we have.
- */
- @Override
- public GraphicsConfiguration getBestConfiguration(
- final GraphicsConfigTemplate gct) {
- return this.gc;
- }
-
- @Override
- public GraphicsConfiguration[] getConfigurations() {
- /* We have only one config, so return an array containing it. */
- if (this.configurations == null) {
- this.configurations = new GraphicsConfiguration[] {this.gc};
- }
- return this.configurations;
- }
-
- @Override
- public GraphicsConfiguration getDefaultConfiguration() {
- return this.gc;
- }
-
- @Override
- public String getIDstring() {
- return toString();
- }
-
- /**
- * {@inheritDoc}
- * This implementation reports itself as a "printer".
- */
- @Override
- public int getType() {
- return GraphicsDevice.TYPE_PRINTER;
- }
-
-}
Deleted: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-19 03:10:34 UTC (rev 11830)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-19 13:09:03 UTC (rev 11831)
@@ -1,414 +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:
- * Original Author: <a href="mailto:ke...@af...">Keiron Liddle</a>
- */
-
-package org.foray.graphic.batik;
-
-import org.foray.common.WellKnownConstants;
-import org.foray.common.i18n.Orthography4a;
-
-import org.axsl.font.Font;
-import org.axsl.font.FontConsumer;
-import org.axsl.font.FontException;
-import org.axsl.font.FontOptions;
-import org.axsl.font.FontUtility;
-
-import org.apache.batik.bridge.Mark;
-import org.apache.batik.bridge.StrokingTextPainter;
-import org.apache.batik.bridge.TextNode;
-import org.apache.batik.bridge.TextPainter;
-import org.apache.batik.gvt.font.GVTFontFamily;
-import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
-import org.apache.batik.gvt.text.TextPaintInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.font.TextAttribute;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.text.AttributedCharacterIterator;
-import java.text.CharacterIterator;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Implementation of the Batik {@link TextPainter} that handles the drawing of
- * text for SVG.
- */
-public class PdfTextPainter implements TextPainter {
-
- /** A stroking text painter to get the bounds and shape, which can also be
- * used as a fallback to draw the string with strokes. */
- private static final TextPainter PROXY_PAINTER =
- StrokingTextPainter.getInstance();
-
- /** The FontConsumer that should be used for font resolution. */
- private FontConsumer fontConsumer;
-
- /** The font family name used by this text. */
- private String fontFamily = null;
-
- /** Lazily-loaded logger. Use {@link #getLogger()} to obtain the instance. */
- private Logger logger;
-
- /**
- * Constructor.
- * @param consumer The FontConsumer that should be used for font resolution.
- */
- public PdfTextPainter(final FontConsumer consumer) {
- this.fontConsumer = consumer;
- }
-
- @Override
- public void paint(final TextNode node, final Graphics2D g2d) {
- final Point2D loc = node.getLocation();
- /*
-
- AttributedCharacterIterator aci =
- node.getAttributedCharacterIterator();
- if (aci.getBeginIndex() == aci.getEndIndex()) {
- return;
- }
- // reset position to start of char iterator
- char ch = aci.first();
- if (ch == AttributedCharacterIterator.DONE) {
- return;
- }
- */
- final TextNode.Anchor anchor = (TextNode.Anchor) node
- .getAttributedCharacterIterator()
- .getAttribute(GVTAttributedCharacterIterator
- .TextAttribute.ANCHOR_TYPE);
- if (anchor != null) {
- }
- /*
- printAttrs(node.getAttributedCharacterIterator());
- */
- paintTextRuns(node.getTextRuns(), g2d, loc);
-
- }
-
- /**
- * Paints a set of text runs.
- * @param textRuns The text runs to paint.
- * @param g2d The graphics environment.
- * @param loc The location at which the text items should be painted.
- */
- protected void paintTextRuns(final List<?> textRuns, final Graphics2D g2d,
- final Point2D loc) {
- Point2D currentloc = loc;
- final Iterator<?> i = textRuns.iterator();
- while (i.hasNext()) {
- final StrokingTextPainter.TextRun run =
- (StrokingTextPainter.TextRun) i.next();
- currentloc = paintTextRun(run, g2d, currentloc);
- }
- }
-
- /**
- * Paints a text runs.
- * @param run The text run to paint.
- * @param g2d The graphics environment.
- * @param loc The location at which the text item should be painted.
- * @return The ending point.
- */
- protected Point2D paintTextRun(final StrokingTextPainter.TextRun run,
- final Graphics2D g2d, final Point2D loc) {
- final AttributedCharacterIterator aci = run.getACI();
- return paintACI(aci, g2d, loc);
- }
-
- /**
- * Converts the text in an AttributedCharacterIterator into a String.
- * @param aci The iterator containing the needed text.
- * @return The iterator text as a String.
- */
- protected String getText(final AttributedCharacterIterator aci) {
- final StringBuilder sb = new StringBuilder(aci.getEndIndex()
- - aci.getBeginIndex());
- for (char c = aci.first(); c != CharacterIterator.DONE;
- c = aci.next()) {
- sb.append(c);
- }
- return sb.toString();
- }
-
- /**
- * Paints an AttributedCharacterIterator.
- * @param aci The iterator whose content should be painted.
- * @param g2d The graphics environment.
- * @param loc The location at which the text should be painted.
- * @return The ending point.
- */
- protected Point2D paintACI(final AttributedCharacterIterator aci, final Graphics2D g2d, final Point2D loc) {
- aci.first();
-
- final TextNode.Anchor anchor = (TextNode.Anchor) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
-
- //Adjust position of span
- final Float xpos = (Float) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.X);
- final Float ypos = (Float) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.Y);
- final Float dxpos = (Float) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.DX);
- final Float dypos = (Float) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.DY);
- if (xpos != null) {
- loc.setLocation(xpos.doubleValue(), loc.getY());
- }
- if (ypos != null) {
- loc.setLocation(loc.getX(), ypos.doubleValue());
- }
- if (dxpos != null) {
- loc.setLocation(loc.getX() + dxpos.doubleValue(), loc.getY());
- }
- if (dypos != null) {
- loc.setLocation(loc.getX(), loc.getY() + dypos.doubleValue());
- }
-
-
- /* Get and set the font size. */
- final Float taFontSize = (Float) aci.getAttribute(TextAttribute.SIZE);
- if (taFontSize == null) {
- return loc;
- }
-
- /* Get and set the colors. */
- final TextPaintInfo tpi = (TextPaintInfo) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
- if (tpi == null) {
- return loc;
- }
- final Paint forg = tpi.fillPaint;
- if (forg instanceof Color) {
- final Color col = (Color) forg;
- g2d.setColor(col);
- }
- g2d.setPaint(forg);
-
- /* Get and set the stroke. */
- final Stroke stroke = tpi.strokeStroke;
- g2d.setStroke(stroke);
-
- /*
- * There are at least four sets of measurements being used here for
- * font-size, font-weight, and font-style: 1) the java.awt.Font
- * nomenclature, 2) the org.foray.font.Font nomenclature, 3) the
- * FOray FOTree nomenclature, and 4) the Batik TextAttribute
- * nomenclature. The Batik may be related to the AWT.
- * To try to distinguish them, "awt", "fo", and "ta" prefixes are added
- * to local variable names.
- */
- final Float taPosture = (Float) aci.getAttribute(TextAttribute.POSTURE);
- final Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
-
- boolean isItalic = false;
- boolean isBold = false;
- int awtFontStyle = java.awt.Font.PLAIN;
- if ((taPosture != null) && (taPosture.floatValue() > 0.0)) {
- awtFontStyle |= java.awt.Font.ITALIC;
- isItalic = true;
- }
- if ((taWeight != null) && (taWeight.floatValue() > 1.0)) {
- awtFontStyle |= java.awt.Font.BOLD;
- isBold = true;
- }
-
- org.axsl.font.FontUse fontToUse = null;
-
- /*
- * TODO: Since an awt font is required here, it may be much better
- * to create the best awt font that can be created, and then enhance
- * the ForayFont system to allow a Foray Font to be created from the
- * awt font. It seems like the struggle here is to try to make sure
- * that the two are similar.
- */
- try {
- fontToUse = getFontToUse(aci, g2d, taFontSize, isItalic, isBold);
- } catch (final FontException e) {
- getLogger().error(e.getMessage());
- }
-
- final String awtFontFamily = this.fontFamily;
- final int awtFontSize = Math.round(taFontSize.floatValue());
- final java.awt.Font awtFont = new java.awt.Font(awtFontFamily,
- awtFontStyle, awtFontSize);
- g2d.setFont(awtFont);
-
- //Get text and paint
- final String txt = getText(aci);
- fontToUse.registerCharsUsed(txt);
- /* TODO: If letter-spacing is used, it needs to come from the SVG. */
- final int letterSpacing = 0;
- /* TODO: Pass the font options and orthography below instead of hard-coding them. */
- final int width = fontToUse.width(txt, 0, txt.length(),
- awtFontSize * WellKnownConstants.MILLIPOINTS_PER_POINT, letterSpacing, 0, FontOptions.DEFAULT,
- Orthography4a.USA);
- final float advance = WellKnownConstants.millipointsToPoints(width);
- float tx = 0;
- if (anchor != null) {
- switch (anchor.getType()) {
- case TextNode.Anchor.ANCHOR_MIDDLE:
- tx = -advance / 2;
- break;
- case TextNode.Anchor.ANCHOR_END:
- tx = -advance;
- }
- }
- g2d.drawString(txt, (float) (loc.getX() + tx), (float) loc.getY());
- loc.setLocation(loc.getX() + advance, loc.getY());
- return loc;
- }
-
- /**
- * Returns the font to use.
- * @param aci The attributed character iterator.
- * @param g2d The graphics 2D.
- * @param size The size, in points, of the text to be written.
- * @param italic Set to true if the font should be italic.
- * @param bold Set to true if the font should be bold.
- * @return The axsl font, or null if one cannot be matched.
- * @throws FontException For errors during font selection.
- */
- private org.axsl.font.FontUse getFontToUse(
- final AttributedCharacterIterator aci, final Graphics2D g2d,
- final Float size, final boolean italic, final boolean bold)
- throws FontException {
- Font.Style style = Font.Style.NORMAL;
- if (italic) {
- style = Font.Style.ITALIC;
- }
- org.axsl.font.Font.Weight weight
- = org.axsl.font.Font.Weight.NORMAL;
- if (bold) {
- weight = org.axsl.font.Font.Weight.BOLD;
- }
- final List<?> gvtFonts = (List<?>) aci.getAttribute(
- GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
-
- final int fsize = (int) size.floatValue();
- if (gvtFonts != null) {
- for (final Iterator<?> i = gvtFonts.iterator(); i.hasNext(); ) {
- final GVTFontFamily fam = (GVTFontFamily) i.next();
- this.fontFamily = fam.getFamilyName();
- final org.axsl.font.FontUse font = this.fontConsumer.selectFontCss(
- FontUtility.foFontFamily(this.fontFamily),
- style, weight, Font.Variant.NORMAL,
- org.axsl.font.Font.Stretch.NORMAL,
- fsize * WellKnownConstants.MILLIPOINTS_PER_POINT,
- ' ');
- if (font != null) {
- if (g2d instanceof PdfGraphics2D) {
- ((PdfGraphics2D) g2d).setOverrideFontState(font, fsize);
- }
- return font;
- }
- }
- }
- this.fontFamily = "any";
- return this.fontConsumer.selectFontXsl(
- Font.SelectionStrategy.AUTO,
- Arrays.asList(new String[] {"any"}),
- style,
- weight,
- Font.Variant.NORMAL,
- org.axsl.font.Font.Stretch.NORMAL,
- fsize * WellKnownConstants.MILLIPOINTS_PER_POINT,
- ' ');
- }
-
- @Override
- public Mark getMark(final TextNode node, final int pos, final boolean all) {
- return null;
- }
-
- @Override
- public Mark selectAt(final double x, final double y, final TextNode node) {
- return null;
- }
-
- @Override
- public Mark selectTo(final double x, final double y, final Mark beginMark) {
- return null;
- }
-
- @Override
- public Mark selectFirst(final TextNode node) {
- return null;
- }
-
- @Override
- public Mark selectLast(final TextNode node) {
- return null;
- }
-
- @Override
- public int[] getSelected(final Mark start, final Mark finish) {
- return null;
- }
-
- @Override
- public Shape getHighlightShape(final Mark beginMark, final Mark endMark) {
- return null;
- }
-
- @Override
- public Rectangle2D getBounds2D(final TextNode node) {
- return PdfTextPainter.PROXY_PAINTER.getBounds2D(node);
- }
-
- @Override
- public Rectangle2D getGeometryBounds(final TextNode node) {
- return PdfTextPainter.PROXY_PAINTER.getGeometryBounds(node);
- }
-
- @Override
- public Shape getOutline(final TextNode node) {
- return PdfTextPainter.PROXY_PAINTER.getOutline(node);
- }
-
- private Logger getLogger() {
- if (this.logger == null) {
- this.logger = LoggerFactory.getLogger(PdfTextPainter.class);
- }
- return this.logger;
- }
-
-}
Copied: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java (from rev 11829, trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java)
===================================================================
--- trunk/foray/foray-graphic/src/main/java/or...
[truncated message content] |
|
From: <vic...@us...> - 2021-01-19 03:10:35
|
Revision: 11830
http://sourceforge.net/p/foray/code/11830
Author: victormote
Date: 2021-01-19 03:10:34 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Combing methods for simplicity and clarity, in preparation for refactoring API.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-18 20:43:30 UTC (rev 11829)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-19 03:10:34 UTC (rev 11830)
@@ -75,47 +75,21 @@
final GraphicOutputContext outputContext,
final FontConsumer fontConsumer, final boolean strokeText,
final boolean commentsEnabled) throws GraphicException {
- SVGDocument doc = null;
- doc = this.svg.getSvgDocument();
- final PdfGraphics2D graphics = getPDFContent4SVG(fontConsumer, doc,
- strokeText, outputContext, output);
- if (graphics == null) {
- throw new GraphicException("Unable to convert to PDF: "
- + this.svg.getUrl().toExternalForm());
- }
- graphics.dispose();
- if (graphics.ioErrorFound()) {
- throw new GraphicException("I/O error(s) while converting to PDF: "
- + this.svg.getUrl().toExternalForm());
- }
- }
-
- /**
- * Convert an SVG document to a PdfGraphics2D.
- * @param fontConsumer The font consumer.
- * @param svgDocument The SVG document.
- * @param strokeSVGText Indicates whether text should be stroked.
- * @param pdfContext The PDF context in which this content is being written.
- * @return The PdfGraphics2D instance for the SVG.
- * @param outputStream The output stream to which this processor writes its
- * PDF output.
- */
- public PdfGraphics2D getPDFContent4SVG(final FontConsumer fontConsumer,
- final SVGDocument svgDocument,
- final boolean strokeSVGText, final GraphicOutputContext pdfContext,
- final OutputStream outputStream) {
/* If not running in a graphical environment, log an error message
* and skip the SVG. */
if (! Environment.isGraphicalEnvironment()) {
this.svg.getLogger().error("Unable to get Graphical Environment "
+ "required to process SVG. Skipping.");
- return null;
+ return;
}
+
+ final SVGDocument svgDocument = this.svg.getSvgDocument();
+
final BatikUaDocument userAgent = new BatikUaDocument(new AffineTransform());
BridgeContext ctx = new BridgeContext(userAgent);
GVTBuilder builder = new GVTBuilder();
TextPainter textPainter = null;
- if (strokeSVGText) {
+ if (strokeText) {
textPainter = new StrokingTextPainter();
} else {
textPainter = new PdfTextPainter(fontConsumer);
@@ -129,12 +103,16 @@
ctx = null;
builder = null;
- final PdfGraphics2D graphics;
- graphics = new PdfGraphics2D(true, fontConsumer, pdfContext, outputStream);
+ final PdfGraphics2D graphics = new PdfGraphics2D(strokeText, fontConsumer, outputContext, output);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
root.paint(graphics);
- return graphics;
+
+ graphics.dispose();
+ if (graphics.ioErrorFound()) {
+ throw new GraphicException("I/O error(s) while converting to PDF: "
+ + this.svg.getUrl().toExternalForm());
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 20:43:33
|
Revision: 11829
http://sourceforge.net/p/foray/code/11829
Author: victormote
Date: 2021-01-18 20:43:30 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Remove loggers from some method APIs.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/BatikUaDocument.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPs.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/BatikUaDocument.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/BatikUaDocument.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/BatikUaDocument.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -33,6 +33,7 @@
import org.apache.batik.bridge.UserAgentAdapter;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
@@ -54,8 +55,8 @@
/** The current AffineTransform. */
private AffineTransform currentTransform = null;
- /** The logger. */
- private Logger log;
+ /** The lazily-loaded logger. Use {@link #getLogger()} to obtain the instance. */
+ private Logger logger;
/**
* Creates a new SVGUserAgent.
@@ -65,28 +66,19 @@
this.currentTransform = at;
}
- /**
- * Sets the logger.
- * @param logger The new logger.
- */
- public void setLogger(final Logger logger) {
- this.log = logger;
- }
-
@Override
public void displayError(final String message) {
- this.log.error(message);
+ getLogger().error(message);
}
@Override
public void displayError(final Exception ex) {
- this.log.error("SVG Error" + ex.getMessage());
- this.log.error(ex.getMessage());
+ getLogger().error("SVG Error", ex);
}
@Override
public void displayMessage(final String message) {
- this.log.info(message);
+ getLogger().info(message);
}
@Override
@@ -137,5 +129,11 @@
return true;
}
+ private Logger getLogger() {
+ if (this.logger == null) {
+ this.logger = LoggerFactory.getLogger(BatikUaDocument.class);
+ }
+ return this.logger;
+ }
}
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -50,6 +50,7 @@
import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
import org.apache.batik.gvt.text.TextPaintInfo;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Graphics2D;
@@ -82,17 +83,15 @@
/** The font family name used by this text. */
private String fontFamily = null;
- /** The logger. */
+ /** Lazily-loaded logger. Use {@link #getLogger()} to obtain the instance. */
private Logger logger;
/**
* Constructor.
* @param consumer The FontConsumer that should be used for font resolution.
- * @param logger The logger.
*/
- public PdfTextPainter(final FontConsumer consumer, final Logger logger) {
+ public PdfTextPainter(final FontConsumer consumer) {
this.fontConsumer = consumer;
- this.logger = logger;
}
@Override
@@ -264,7 +263,7 @@
try {
fontToUse = getFontToUse(aci, g2d, taFontSize, isItalic, isBold);
} catch (final FontException e) {
- this.logger.error(e.getMessage());
+ getLogger().error(e.getMessage());
}
final String awtFontFamily = this.fontFamily;
@@ -405,4 +404,11 @@
return PdfTextPainter.PROXY_PAINTER.getOutline(node);
}
+ private Logger getLogger() {
+ if (this.logger == null) {
+ this.logger = LoggerFactory.getLogger(PdfTextPainter.class);
+ }
+ return this.logger;
+ }
+
}
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -119,7 +119,6 @@
*/
public BridgeContext makeBridgeContextAWT() {
final BatikUaAwt userAgent = new BatikUaAwt(new AffineTransform());
- userAgent.setLogger(getLogger());
return new BridgeContext(userAgent);
}
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -111,9 +111,7 @@
+ "required to process SVG. Skipping.");
return null;
}
- final BatikUaDocument userAgent = new BatikUaDocument(
- new AffineTransform());
- userAgent.setLogger(this.svg.getLogger());
+ final BatikUaDocument userAgent = new BatikUaDocument(new AffineTransform());
BridgeContext ctx = new BridgeContext(userAgent);
GVTBuilder builder = new GVTBuilder();
TextPainter textPainter = null;
@@ -120,7 +118,7 @@
if (strokeSVGText) {
textPainter = new StrokingTextPainter();
} else {
- textPainter = new PdfTextPainter(fontConsumer, this.svg.getLogger());
+ textPainter = new PdfTextPainter(fontConsumer);
}
ctx.setTextPainter(textPainter);
@@ -127,8 +125,7 @@
final PdfaElementBridge aBridge = new PdfaElementBridge();
ctx.putBridge(aBridge);
- final GraphicsNode root;
- root = builder.build(ctx, svgDocument);
+ final GraphicsNode root = builder.build(ctx, svgDocument);
ctx = null;
builder = null;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPs.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPs.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPs.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -107,9 +107,7 @@
* @return A Batik BridgeContext instance.
*/
public BridgeContext makeBridgeContext() {
- final BatikUaDocument userAgent = new BatikUaDocument(
- new AffineTransform());
- userAgent.setLogger(getLogger());
+ final BatikUaDocument userAgent = new BatikUaDocument(new AffineTransform());
return new BridgeContext(userAgent);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 20:03:09 UTC (rev 11828)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 20:43:30 UTC (rev 11829)
@@ -64,10 +64,9 @@
* SVG.
* @param strokeText Set to true if text should be stroked, false if it
* should be drawn with a font.
- * @throws GraphicException For errors getting the appropriate filter.
*/
- public PdfXformSvg(final PdfDocument4a doc, final SvgGraphic graphic,
- final FontConsumer fontConsumer, final boolean strokeText) {
+ public PdfXformSvg(final PdfDocument4a doc, final SvgGraphic graphic, final FontConsumer fontConsumer,
+ final boolean strokeText) {
super(doc, graphic);
this.graphic = graphic;
this.fontConsumer = fontConsumer;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 20:03:17
|
Revision: 11828
http://sourceforge.net/p/foray/code/11828
Author: victormote
Date: 2021-01-18 20:03:09 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Rename two classes to better fit names in the PDF reference.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java (from rev 11827, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -0,0 +1,154 @@
+/*
+ * 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$
+ */
+
+package org.foray.pdf.object;
+
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.pdf.PdfException;
+import org.axsl.ps.PsBoundingBox;
+
+import java.awt.geom.AffineTransform;
+
+/**
+ * <p>Represents a Form XObject.
+ * The use of the term "form" here is a bit confusing, and appears to be retained for historical reasons related to
+ * PDF's roots in the PostScript language.
+ * It has nothing to do with interactive forms in general, nor AcroForm in particular.
+ * Instead a Form XObject allows content that could be written into a {@link org.axsl.pdf.PdfContentStream} directly to
+ * be handled as an independent, self-contained object that is simply called as needed when creating the content stream.
+ * Using this approach has several benefits, including:</p>
+ * <ul>
+ * <li>Reusability. The object can be called from multiple pages or all pages.
+ * In a 100 page document that used the content on each page, it is defined only once, but used 100 times, resulting
+ * in a much more compact PDF document.</li>
+ * <li>Independence. The process of writing the content is separate from its placement, scaling, rotation, etc. in the
+ * stream.
+ * This has implicatons for reusability, but also provides a separation of concerns for development, as it allows the
+ * creation of the content to be separated from how it is used in the document.</li>
+ * <li></li>
+ * </ul>
+ *
+ * <p>For content that is only to be used one time in a document, there is some overhead associated with creating and
+ * using the content as an object instead of writing it directly in a content stream.
+ * In this case, the benefit of reusability does not exist.
+ * However, the benefit of independence may well outweigh the small cost of creating the content as a Form XObject.</p>
+ *
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.9, for Form XObjects, including a Note that explains
+ * the meaning of the term <em>form</em> in this context."
+ */
+public abstract class PdfFormXobject extends PdfXobject {
+
+ /**
+ * Constructor.
+ * @param doc The parent PDF document.
+ * @param graphic The form to be encapsulated.
+ */
+ public PdfFormXobject(final PdfDocument4a doc, final Graphic graphic) {
+ super(doc, graphic);
+ }
+
+ @Override
+ protected String xObjectSubtype() {
+ return "Form";
+ }
+
+ @Override
+ protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
+ byte[] bytes = null;
+ try {
+ bytes = getPdfContent(doc);
+ } catch (final GraphicException e) {
+ // Ignore this. An error was already logged & fallback is below.
+ }
+ if (bytes == null) {
+ return;
+ }
+ this.write(bytes);
+ }
+
+ /**
+ * Converts the graphic content to PDF content.
+ * @param doc The PDF document.
+ * @return The PDF content.
+ * @throws GraphicException For errors during conversion.
+ */
+ protected abstract byte[] getPdfContent(PdfDocument4a doc) throws GraphicException;
+
+ @Override
+ protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
+ final PsBoundingBox boundingBox = this.getBoundingBox();
+ final float llx = boundingBox.lowerLeftX();
+ final float lly = boundingBox.lowerLeftY();
+ final float urx = boundingBox.upperRightX();
+ final float ury = boundingBox.upperRightY();
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append("/FormType 1" + EOL);
+ buffer.append("/BBox [");
+ buffer.append(llx + " ");
+ buffer.append(lly + " ");
+ buffer.append(urx + " ");
+ buffer.append(ury + "]" + EOL);
+ final AffineTransform transform = this.getUserSpaceTransform();
+ buffer.append("/Matrix ["
+ + transform.getScaleX()
+ + " 0 0 "
+ + transform.getScaleY() + " "
+ + transform.getTranslateX() + " "
+ + transform.getTranslateY() + "]"
+ + EOL);
+ buffer.append("/Resources " + doc.getResources().pdfReference(doc) + EOL);
+
+ /* Add any special entries that the subclasses might have. */
+ buffer.append(this.specialXFormDict(doc));
+ return buffer.toString();
+ }
+
+ /**
+ * Returns the bounding box dimensions, in form space, for this graphic.
+ * @return The bounding box for this graphic.
+ * @exception GraphicException For errors during parsing of the graphic content.
+ */
+ protected abstract PsBoundingBox getBoundingBox() throws GraphicException;
+
+ /**
+ * Returns any special entries that should be added to the XForm dictionary.
+ * @param doc The PDF Document.
+ * @return Special XForm dictionary entries.
+ */
+ protected abstract String specialXFormDict(PdfDocument4a doc);
+
+ /**
+ * Return the transformation that should be used to convert this form from
+ * form space to user space.
+ * @return The transformation to be used to convert this form to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ protected abstract AffineTransform getUserSpaceTransform() throws GraphicException;
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java (from rev 11827, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -0,0 +1,168 @@
+/*
+ * 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:
+ * Eric Dalquist
+ * Manuel Mall
+ */
+
+package org.foray.pdf.object;
+
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.pdf.PdfException;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * A sampled image that is to be embedded in a PDF File.
+ * Images in PDF can either be written directly into the content stream or handled as XObjects (external objects).
+ *
+ * @see PdfXobject
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
+ */
+public class PdfImageXobject extends PdfXobject {
+
+ /** The Graphic instance associated with this XObject. */
+ private Graphic graphic;
+
+ /** The ICC stream. */
+ private PdfIccStream pdfICCStream;
+
+ /**
+ * Create a sampled-image Xobject.
+ * @param doc The parent PDF document.
+ * @param graphic The graphic to be encapsulated.
+ * @throws GraphicException For errors getting the appropriate filter.
+ */
+ public PdfImageXobject(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
+ super(doc, graphic);
+ this.graphic = graphic;
+ final ColorSpace cs = getGraphic().getColorSpace();
+ if (getGraphic().getGraphicType() == Graphic.Type.JPEG
+ && cs instanceof ICC_ColorSpace) {
+ final ICC_ColorSpace iccCS = (ICC_ColorSpace) cs;
+ this.pdfICCStream = new PdfIccStream(iccCS);
+ try {
+ this.pdfICCStream.addDefaultFilters(doc);
+ } catch (final PdfException e) {
+ /* Ignore. Shouldn't happen. */
+ }
+ if (doc.getEncryption() != null) {
+ this.pdfICCStream.addEncryption(doc.getEncryption());
+ }
+ }
+ }
+
+ @Override
+ protected String xObjectSubtype() {
+ return "Image";
+ }
+
+ @Override
+ protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
+ try {
+ if (getGraphic().getGraphicType() == Graphic.Type.JPEG
+ || getGraphic().getGraphicType() == Graphic.Type.TIFF) {
+ /* JPEG is natively compressed using DTD, so use its raw
+ * content.
+ * TIFF is currently presumed to be compressed natively also,
+ * and an appropriate filter has been added for that
+ * compression. */
+ this.write(getGraphic().getRawSamples());
+ } else {
+ this.write(getGraphic().getContent());
+ }
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ }
+
+ @Override
+ protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
+ int pixelWidth = 0;
+ int pixelHeight = 0;
+ int bitsPerPixel = 0;
+ ColorSpace cs = null;
+ boolean isTransparent = false;
+ Color transp = null;
+ pixelWidth = getGraphic().pixelWidth();
+ pixelHeight = getGraphic().pixelHeight();
+ bitsPerPixel = getGraphic().getBitsPerComponent();
+ cs = getGraphic().getColorSpace();
+ isTransparent = getGraphic().isTransparent();
+ transp = getGraphic().getTransparentColor();
+ final StringBuilder buffer = new StringBuilder();
+ // The width, in pixels (aka samples), *not* points.
+ buffer.append("/Width " + pixelWidth + EOL);
+ // The width, in pixels (aka samples), *not* points.
+ buffer.append("/Height " + pixelHeight + EOL);
+ buffer.append("/BitsPerComponent " + bitsPerPixel + EOL);
+ if (this.pdfICCStream != null) {
+ buffer.append("/ColorSpace [/ICCBased "
+ + this.pdfICCStream.pdfReference(doc) + "]" + EOL);
+ } else {
+ buffer.append("/ColorSpace /"
+ + PdfColor4a.getColorSpacePDFString(cs)
+ + EOL);
+ }
+ /* PhotoShop generates CMYK values that's inverse. */
+ if (cs.getType() == ColorSpace.TYPE_CMYK
+ && getGraphic().isInverted()) {
+ buffer.append("/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]" + EOL);
+ }
+ if (isTransparent) {
+ buffer.append("/Mask [" + transp.getRed() + " " + transp.getRed()
+ + " " + transp.getGreen() + " " + transp.getGreen()
+ + " " + transp.getBlue() + " " + transp.getBlue()
+ + "]" + EOL);
+ }
+ return buffer.toString();
+ }
+
+ @Override
+ public float getHorizontalScaling(
+ final Rectangle2D.Float contentRectangle) {
+ return contentRectangle.width;
+ }
+
+ @Override
+ public float getVerticalScaling(final Rectangle2D.Float contentRectangle) {
+ return contentRectangle.height;
+ }
+
+ @Override
+ public Graphic getGraphic() {
+ return this.graphic;
+ }
+
+}
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -1,154 +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$
- */
-
-package org.foray.pdf.object;
-
-import org.axsl.graphic.Graphic;
-import org.axsl.graphic.GraphicException;
-import org.axsl.pdf.PdfException;
-import org.axsl.ps.PsBoundingBox;
-
-import java.awt.geom.AffineTransform;
-
-/**
- * <p>Represents a Form XObject.
- * The use of the term "form" here is a bit confusing, and appears to be retained for historical reasons related to
- * PDF's roots in the PostScript language.
- * It has nothing to do with interactive forms in general, nor AcroForm in particular.
- * Instead a Form XObject allows content that could be written into a {@link org.axsl.pdf.PdfContentStream} directly to
- * be handled as an independent, self-contained object that is simply called as needed when creating the content stream.
- * Using this approach has several benefits, including:</p>
- * <ul>
- * <li>Reusability. The object can be called from multiple pages or all pages.
- * In a 100 page document that used the content on each page, it is defined only once, but used 100 times, resulting
- * in a much more compact PDF document.</li>
- * <li>Independence. The process of writing the content is separate from its placement, scaling, rotation, etc. in the
- * stream.
- * This has implicatons for reusability, but also provides a separation of concerns for development, as it allows the
- * creation of the content to be separated from how it is used in the document.</li>
- * <li></li>
- * </ul>
- *
- * <p>For content that is only to be used one time in a document, there is some overhead associated with creating and
- * using the content as an object instead of writing it directly in a content stream.
- * In this case, the benefit of reusability does not exist.
- * However, the benefit of independence may well outweigh the small cost of creating the content as a Form XObject.</p>
- *
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.9, for Form XObjects, including a Note that explains
- * the meaning of the term <em>form</em> in this context."
- */
-public abstract class PdfXform extends PdfXobject {
-
- /**
- * Constructor.
- * @param doc The parent PDF document.
- * @param graphic The form to be encapsulated.
- */
- public PdfXform(final PdfDocument4a doc, final Graphic graphic) {
- super(doc, graphic);
- }
-
- @Override
- protected String xObjectSubtype() {
- return "Form";
- }
-
- @Override
- protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
- byte[] bytes = null;
- try {
- bytes = getPdfContent(doc);
- } catch (final GraphicException e) {
- // Ignore this. An error was already logged & fallback is below.
- }
- if (bytes == null) {
- return;
- }
- this.write(bytes);
- }
-
- /**
- * Converts the graphic content to PDF content.
- * @param doc The PDF document.
- * @return The PDF content.
- * @throws GraphicException For errors during conversion.
- */
- protected abstract byte[] getPdfContent(PdfDocument4a doc) throws GraphicException;
-
- @Override
- protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
- final PsBoundingBox boundingBox = this.getBoundingBox();
- final float llx = boundingBox.lowerLeftX();
- final float lly = boundingBox.lowerLeftY();
- final float urx = boundingBox.upperRightX();
- final float ury = boundingBox.upperRightY();
- final StringBuilder buffer = new StringBuilder();
- buffer.append("/FormType 1" + EOL);
- buffer.append("/BBox [");
- buffer.append(llx + " ");
- buffer.append(lly + " ");
- buffer.append(urx + " ");
- buffer.append(ury + "]" + EOL);
- final AffineTransform transform = this.getUserSpaceTransform();
- buffer.append("/Matrix ["
- + transform.getScaleX()
- + " 0 0 "
- + transform.getScaleY() + " "
- + transform.getTranslateX() + " "
- + transform.getTranslateY() + "]"
- + EOL);
- buffer.append("/Resources " + doc.getResources().pdfReference(doc) + EOL);
-
- /* Add any special entries that the subclasses might have. */
- buffer.append(this.specialXFormDict(doc));
- return buffer.toString();
- }
-
- /**
- * Returns the bounding box dimensions, in form space, for this graphic.
- * @return The bounding box for this graphic.
- * @exception GraphicException For errors during parsing of the graphic content.
- */
- protected abstract PsBoundingBox getBoundingBox() throws GraphicException;
-
- /**
- * Returns any special entries that should be added to the XForm dictionary.
- * @param doc The PDF Document.
- * @return Special XForm dictionary entries.
- */
- protected abstract String specialXFormDict(PdfDocument4a doc);
-
- /**
- * Return the transformation that should be used to convert this form from
- * form space to user space.
- * @return The transformation to be used to convert this form to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- protected abstract AffineTransform getUserSpaceTransform() throws GraphicException;
-
-}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -48,7 +48,7 @@
/**
* A PDF "Form" XObject containing an EPS graphic.
*/
-public class PdfXformEps extends PdfXform {
+public class PdfXformEps extends PdfFormXobject {
/** The Graphic instance associated with this XObject. */
private EpsGraphic graphic;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -45,7 +45,7 @@
/**
* A PDF "Form" XObject containing a MathML document.
*/
-public class PdfXformMath extends PdfXform {
+public class PdfXformMath extends PdfFormXobject {
/** The Graphic instance associated with this XObject. */
private MathGraphic graphic;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -45,7 +45,7 @@
/**
* A PDF "Form" XObject containing an SVG.
*/
-public class PdfXformSvg extends PdfXform {
+public class PdfXformSvg extends PdfFormXobject {
/** The Graphic instance associated with this XObject. */
private SvgGraphic graphic;
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -1,168 +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:
- * Eric Dalquist
- * Manuel Mall
- */
-
-package org.foray.pdf.object;
-
-import org.axsl.graphic.Graphic;
-import org.axsl.graphic.GraphicException;
-import org.axsl.pdf.PdfException;
-
-import java.awt.Color;
-import java.awt.color.ColorSpace;
-import java.awt.color.ICC_ColorSpace;
-import java.awt.geom.Rectangle2D;
-
-/**
- * A sampled image that is to be embedded in a PDF File.
- * Images in PDF can either be written directly into the content stream or handled as XObjects (external objects).
- *
- * @see PdfXobject
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
- */
-public class PdfXimage extends PdfXobject {
-
- /** The Graphic instance associated with this XObject. */
- private Graphic graphic;
-
- /** The ICC stream. */
- private PdfIccStream pdfICCStream;
-
- /**
- * Create a sampled-image Xobject.
- * @param doc The parent PDF document.
- * @param graphic The graphic to be encapsulated.
- * @throws GraphicException For errors getting the appropriate filter.
- */
- public PdfXimage(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
- super(doc, graphic);
- this.graphic = graphic;
- final ColorSpace cs = getGraphic().getColorSpace();
- if (getGraphic().getGraphicType() == Graphic.Type.JPEG
- && cs instanceof ICC_ColorSpace) {
- final ICC_ColorSpace iccCS = (ICC_ColorSpace) cs;
- this.pdfICCStream = new PdfIccStream(iccCS);
- try {
- this.pdfICCStream.addDefaultFilters(doc);
- } catch (final PdfException e) {
- /* Ignore. Shouldn't happen. */
- }
- if (doc.getEncryption() != null) {
- this.pdfICCStream.addEncryption(doc.getEncryption());
- }
- }
- }
-
- @Override
- protected String xObjectSubtype() {
- return "Image";
- }
-
- @Override
- protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
- try {
- if (getGraphic().getGraphicType() == Graphic.Type.JPEG
- || getGraphic().getGraphicType() == Graphic.Type.TIFF) {
- /* JPEG is natively compressed using DTD, so use its raw
- * content.
- * TIFF is currently presumed to be compressed natively also,
- * and an appropriate filter has been added for that
- * compression. */
- this.write(getGraphic().getRawSamples());
- } else {
- this.write(getGraphic().getContent());
- }
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
- }
-
- @Override
- protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
- int pixelWidth = 0;
- int pixelHeight = 0;
- int bitsPerPixel = 0;
- ColorSpace cs = null;
- boolean isTransparent = false;
- Color transp = null;
- pixelWidth = getGraphic().pixelWidth();
- pixelHeight = getGraphic().pixelHeight();
- bitsPerPixel = getGraphic().getBitsPerComponent();
- cs = getGraphic().getColorSpace();
- isTransparent = getGraphic().isTransparent();
- transp = getGraphic().getTransparentColor();
- final StringBuilder buffer = new StringBuilder();
- // The width, in pixels (aka samples), *not* points.
- buffer.append("/Width " + pixelWidth + EOL);
- // The width, in pixels (aka samples), *not* points.
- buffer.append("/Height " + pixelHeight + EOL);
- buffer.append("/BitsPerComponent " + bitsPerPixel + EOL);
- if (this.pdfICCStream != null) {
- buffer.append("/ColorSpace [/ICCBased "
- + this.pdfICCStream.pdfReference(doc) + "]" + EOL);
- } else {
- buffer.append("/ColorSpace /"
- + PdfColor4a.getColorSpacePDFString(cs)
- + EOL);
- }
- /* PhotoShop generates CMYK values that's inverse. */
- if (cs.getType() == ColorSpace.TYPE_CMYK
- && getGraphic().isInverted()) {
- buffer.append("/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]" + EOL);
- }
- if (isTransparent) {
- buffer.append("/Mask [" + transp.getRed() + " " + transp.getRed()
- + " " + transp.getGreen() + " " + transp.getGreen()
- + " " + transp.getBlue() + " " + transp.getBlue()
- + "]" + EOL);
- }
- return buffer.toString();
- }
-
- @Override
- public float getHorizontalScaling(
- final Rectangle2D.Float contentRectangle) {
- return contentRectangle.width;
- }
-
- @Override
- public float getVerticalScaling(final Rectangle2D.Float contentRectangle) {
- return contentRectangle.height;
- }
-
- @Override
- public Graphic getGraphic() {
- return this.graphic;
- }
-
-}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -51,8 +51,8 @@
/**
* <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
* <ul>
- * <li>An image XObject. See {@link PdfXimage} for a concrete implementation.</li>
- * <li>A form XObject. See {@link PdfXform} for a concrete implementation.</li>
+ * <li>An image XObject. See {@link PdfImageXobject} for a concrete implementation.</li>
+ * <li>A form XObject. See {@link PdfFormXobject} for a concrete implementation.</li>
* <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
* for it.</li>
* </ul>
@@ -119,7 +119,7 @@
* that no exceptions are thrown. If there are any exceptions
* thrown, we don't want to create the xObject. */
img.getColorSpace();
- xObject = new PdfXimage(pdfDoc, img);
+ xObject = new PdfImageXobject(pdfDoc, img);
}
xObject.filter = xObject.getFilter(xObject.getOutputStream(), pdfDoc);
return xObject;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-18 19:24:08 UTC (rev 11827)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-18 20:03:09 UTC (rev 11828)
@@ -43,7 +43,7 @@
* Represents a "Reference" XObject, which is a reference to content from
* another PDF.
*/
-public class PdfXreference extends PdfXform {
+public class PdfXreference extends PdfFormXobject {
/** The Graphic instance associated with this XObject. */
private Graphic graphic;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 19:24:13
|
Revision: 11827
http://sourceforge.net/p/foray/code/11827
Author: victormote
Date: 2021-01-18 19:24:08 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Remove some unnecessary throws declarations.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -68,10 +68,8 @@
* Constructor.
* @param doc The parent PDF document.
* @param graphic The form to be encapsulated.
- * @throws GraphicException For errors getting the appropriate filter.
*/
- public PdfXform(final PdfDocument4a doc, final Graphic graphic)
- throws GraphicException {
+ public PdfXform(final PdfDocument4a doc, final Graphic graphic) {
super(doc, graphic);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -57,10 +57,8 @@
* Constructor.
* @param doc The parent PDF document.
* @param graphic The form to be encapsulated.
- * @throws GraphicException For errors getting the appropriate filter.
*/
- public PdfXformEps(final PdfDocument4a doc, final EpsGraphic graphic)
- throws GraphicException {
+ public PdfXformEps(final PdfDocument4a doc, final EpsGraphic graphic) {
super(doc, graphic);
this.graphic = graphic;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -60,15 +60,11 @@
* Constructor.
* @param doc The parent PDF document.
* @param graphic The form to be encapsulated.
- * @param fontConsumer The font consumer to use for resolving fonts in the
- * SVG.
- * @param strokeText Set to true if text should be stroked, false if it
- * should be drawn with a font.
- * @throws GraphicException For errors getting the appropriate filter.
+ * @param fontConsumer The font consumer to use for resolving fonts in the SVG.
+ * @param strokeText Set to true if text should be stroked, false if it should be drawn with a font.
*/
public PdfXformMath(final PdfDocument4a doc, final MathGraphic graphic,
- final FontConsumer fontConsumer, final boolean strokeText)
- throws GraphicException {
+ final FontConsumer fontConsumer, final boolean strokeText) {
super(doc, graphic);
this.graphic = graphic;
this.fontConsumer = fontConsumer;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -67,8 +67,7 @@
* @throws GraphicException For errors getting the appropriate filter.
*/
public PdfXformSvg(final PdfDocument4a doc, final SvgGraphic graphic,
- final FontConsumer fontConsumer, final boolean strokeText)
- throws GraphicException {
+ final FontConsumer fontConsumer, final boolean strokeText) {
super(doc, graphic);
this.graphic = graphic;
this.fontConsumer = fontConsumer;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -64,8 +64,7 @@
* @param graphic The graphic to be encapsulated.
* @throws GraphicException For errors getting the appropriate filter.
*/
- public PdfXimage(final PdfDocument4a doc, final Graphic graphic)
- throws GraphicException {
+ public PdfXimage(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
super(doc, graphic);
this.graphic = graphic;
final ColorSpace cs = getGraphic().getColorSpace();
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -72,9 +72,8 @@
* Create an Xobject instance.
* @param doc The parent PDF document.
* @param graphic The graphic to be encapsulated.
- * @throws GraphicException For errors getting the appropriate filter.
*/
- protected PdfXobject(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
+ protected PdfXobject(final PdfDocument4a doc, final Graphic graphic) {
if (graphic == null) {
throw new NullPointerException("Graphic must not be null.");
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-18 16:26:24 UTC (rev 11826)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-18 19:24:08 UTC (rev 11827)
@@ -58,8 +58,7 @@
* @param graphic The graphic to be encapsulated.
* @throws GraphicException For errors getting the appropriate filter.
*/
- public PdfXreference(final PdfDocument4a doc, final Graphic graphic)
- throws GraphicException {
+ public PdfXreference(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
super(doc, graphic);
this.graphic = graphic;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 16:26:32
|
Revision: 11826
http://sourceforge.net/p/foray/code/11826
Author: victormote
Date: 2021-01-18 16:26:24 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Remove some checkstyle magic number suppressions & rename the remaining ones for clarity.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/encoding/Latin1Encoding.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
trunk/foray/master/config/checkstyle/checkstyle-config.xml
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/encoding/Latin1Encoding.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/encoding/Latin1Encoding.java 2021-01-18 15:22:33 UTC (rev 11825)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/encoding/Latin1Encoding.java 2021-01-18 16:26:24 UTC (rev 11826)
@@ -31,13 +31,14 @@
import org.foray.common.primitive.CharacterUtils;
/**
- * Encoding for the Latin-1 character set, also knows as ISO-8859-1, which is a superset of US-ASCII.
+ * Encoding for the Latin-1 character set, which is a superset of US-ASCII.
+ * It is closely related to, but not identical with, ISO-8859-1
*/
public class Latin1Encoding extends SingleByteEncoding {
@Override
public boolean canEncode(final char theChar) {
- /* Checkstyle-MagicNumber-Off. */
+ /* Checkstyle: Allow Magic Numbers that are hard-coded data. */
if (theChar < 0x80) {
return true;
@@ -50,7 +51,7 @@
}
return false;
- /* Checkstyle-MagicNumber-On*/
+ /* Checkstyle: Restart Magic Number checking. */
}
@Override
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2021-01-18 15:22:33 UTC (rev 11825)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2021-01-18 16:26:24 UTC (rev 11826)
@@ -81,7 +81,7 @@
* provide maximum retrieval performance for those structures. */
private static Map<Short, Country4a> mapNumeric = new HashMap<Short, Country4a>(INITIAL_CAPACITY);
- /* Temporarily turn off checkstyle check for magic numbers. This is data. Checkstyle-MagicNumber-Off. */
+ /* Checkstyle: Allow Magic Numbers that are hard-coded data. */
static {
Country4a.registerCountry(UNDETERMINED);
Country4a.registerCountry(new Country4a("AALAND ISLANDS", "AX", "ALA", (short) 248));
@@ -336,7 +336,7 @@
RUSSIA = Country4a.findFrom3Char("RUS");
SPAIN = Country4a.findFrom3Char("ESP");
}
- /* Turn checkstyle check for magic numbers back on. Checkstyle-MagicNumber-On. */
+ /* Checkstyle: Restart Magic Number checking. */
/** The English name of this country. */
private String englishName;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2021-01-18 15:22:33 UTC (rev 11825)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2021-01-18 16:26:24 UTC (rev 11826)
@@ -60,7 +60,7 @@
/** The numeric code map. */
private static Map<Short, Script4a> mapNumeric = new HashMap<Short, Script4a>(INITIAL_CAPACITY);
- /* Temporarily turn off checkstyle check for magic numbers. This is data. Checkstyle-MagicNumber-Off. */
+ /* Checkstyle: Allow Magic Numbers that are hard-coded data. */
static {
Script4a.register(new Script4a("Arab", (short) 160, "Arabic", "arabe"));
Script4a.register(new Script4a("Armn", (short) 230, "Armenian", "arménien"));
@@ -200,7 +200,7 @@
LATIN = Script4a.findFromAlpha("Latn");
CYRILLIC = Script4a.findFromAlpha("Cyrl");
}
- /* Turn checkstyle check for magic numbers back on. Checkstyle-MagicNumber-On. */
+ /* Checkstyle: Restart Magic Number checking. */
/** The English name of this script. */
private String englishName;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2021-01-18 15:22:33 UTC (rev 11825)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2021-01-18 16:26:24 UTC (rev 11826)
@@ -103,12 +103,11 @@
* @param args The command-line arguments.
*/
public static void main(final String[] args) {
- /* Checkstyle-MagicNumber-Off. */
- final String inputFile = args[0];
- final String outputFile = args[1];
- final String password = args[2];
- final String description = args[3];
- /* Checkstyle-MagicNumber-On. */
+ int argsIndex = 0;
+ final String inputFile = args[argsIndex ++]; // index 0
+ final String outputFile = args[argsIndex ++]; // index 1
+ final String password = args[argsIndex ++]; // index 2
+ final String description = args[argsIndex ++]; // index 3
final Logger logger = LoggerFactory.getLogger(PdfReport.class);
try {
Modified: trunk/foray/master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 15:22:33 UTC (rev 11825)
+++ trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 16:26:24 UTC (rev 11826)
@@ -36,6 +36,7 @@
<module name="TreeWalker">
+ <!-- Allow System.exit() when marked as being in a main method. -->
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CheckStyle: Allow System.exit\(\) in main method."/>
<property name="idFormat" value="RestrictSystemExit"/>
@@ -44,6 +45,7 @@
<!-- TODO: This suppression may not be a good suppression to allow. Find out if there is a better way to handle
exiting a screen application. -->
+ <!-- Allow System.exit() when marked as being an exit from a screen application. -->
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CheckStyle: Allow System.exit\(\) to exit screen application."/>
<property name="idFormat" value="RestrictSystemExit"/>
@@ -53,8 +55,8 @@
<!-- Allow magic numbers where they represent hard-coded arbitrary data, for example numeric codes assigned by
a standard-setting body. -->
<module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="Checkstyle-MagicNumber-Off"/>
- <property name="onCommentFormat" value="Checkstyle-MagicNumber-On"/>
+ <property name="offCommentFormat" value="Checkstyle: Allow Magic Numbers that are hard-coded data."/>
+ <property name="onCommentFormat" value="Checkstyle: Restart Magic Number checking."/>
<property name="checkFormat" value="MagicNumber"/>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 15:22:36
|
Revision: 11825
http://sourceforge.net/p/foray/code/11825
Author: victormote
Date: 2021-01-18 15:22:33 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Remove remaining uses of generic SuppressionCommentFilter for use in main methods.
Modified Paths:
--------------
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/DictionarySerializer.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/PatternSerializer.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java
trunk/foray/master/config/checkstyle/checkstyle-config.xml
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/DictionarySerializer.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/DictionarySerializer.java 2021-01-18 14:53:18 UTC (rev 11824)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/DictionarySerializer.java 2021-01-18 15:22:33 UTC (rev 11825)
@@ -197,16 +197,17 @@
* @param args The command-line arguments.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(DictionarySerializer.class);
final Options commandLineOptions = DictionarySerializer.getCommandLineOptions();
CommandLine parsedCommandLine = null;
try {
parsedCommandLine = DictionarySerializer.parseCommandLine(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + DictionarySerializer.class.getName(),
commandLineOptions, true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -222,9 +223,10 @@
final DictionarySerializer serializer = new DictionarySerializer(inputDir, fileFilter, outputDir);
serializer.process();
} catch (final IOException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/PatternSerializer.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/PatternSerializer.java 2021-01-18 14:53:18 UTC (rev 11824)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/PatternSerializer.java 2021-01-18 15:22:33 UTC (rev 11825)
@@ -205,16 +205,17 @@
* @param args The command-line arguments.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(PatternSerializer.class);
final Options commandLineOptions = PatternSerializer.getCommandLineOptions();
CommandLine parsedCommandLine = null;
try {
parsedCommandLine = PatternSerializer.parseCommandLine(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + PatternSerializer.class.getName(),
commandLineOptions, true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -230,9 +231,10 @@
final PatternSerializer serializer = new PatternSerializer(inputDir, fileFilter, outputDir);
serializer.process();
} catch (final IOException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java 2021-01-18 14:53:18 UTC (rev 11824)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java 2021-01-18 15:22:33 UTC (rev 11825)
@@ -147,7 +147,7 @@
* Printed when the program starts.
* @see "patgen.web, line 54"
*/
- private String banner = "This is the FOray Java Port of patgen.";
+ private static final String BANNER = "This is the FOray Java Port of patgen.";
/** The logger. */
private Logger logger = LoggerFactory.getLogger(PatGen.class);
@@ -189,8 +189,6 @@
/* Following line allows this class to use System.in & System.out for IO, which is normally not directly allowed in
* FOray code. An exception is made here because we are trying to conform to the original patgen design in TeX. */
- /* Checkstyle-GenericIllegalRegexp-Off. */
-
/**
* Prints some arbitrary content to stdout.
* @param outputString The String to be printed.
@@ -198,7 +196,7 @@
*/
private void print(final String outputString) {
/* Converted from a WEB macro. */
- System.out.print(outputString);
+ this.stdoutProxy.print(outputString);
}
/**
@@ -208,7 +206,7 @@
*/
private void print(final char outputChar) {
/* Converted from a WEB macro. */
- System.out.print(outputChar);
+ this.stdoutProxy.print(outputChar);
}
/**
@@ -217,11 +215,9 @@
* @see "patgen.web, line 83"
*/
private void printLn(final String outputString) {
- System.out.println(outputString);
+ this.stdoutProxy.println(outputString);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
-
/**
* Reads a line of input from stdin, and parses it into either 2 or 3 integers, the first being placed in
* {@link #n1}, the second in {@link #n2}, and the third in {@link #n3}.
@@ -277,15 +273,19 @@
* @param patterns The patterns input stream to be read (may be null).
* @param translate The translate input stream to be read (may be null).
* @param patout The output stream to which the patterns should be written.
+ * @param stdoutProxy The print stream which serves as a proxy for stdout.
+ * It can be, but does not have to be, the actual stdout.
* @throws HyphenationException If {@code dictionary} is null, or if {@code output} is null.
* @see "patgen.web, line 93"
*/
- public PatGen(final String dictionary, final String patterns, final String translate, final String patout)
+ public PatGen(final String dictionary, final String patterns, final String translate, final String patout,
+ final PrintStream stdoutProxy)
throws HyphenationException {
this.dictionaryPath = dictionary;
this.patternsPath = patterns;
this.translatePath = translate;
this.patoutPath = patout;
+ this.stdoutProxy = stdoutProxy;
if (this.dictionaryPath == null) {
throw new HyphenationException("Dictionary cannot be null.");
}
@@ -301,7 +301,7 @@
* @see "patgen.web, line 98"
*/
private void initialize() throws HyphenationException {
- printLn(this.banner);
+ printLn(BANNER);
setInitialValuesPart1();
setInitialValuesPart2();
setInitialValuesPart3();
@@ -1892,6 +1892,9 @@
*/
private PrintStream pattmp;
+ /** A proxy for stdout. It can be, but does not have to be, the actual stdout. Used apparently for logging. */
+ private PrintStream stdoutProxy;
+
/*
* (patgen.web, line 1042)
* When reading a line from one of the input files (|dictionary|,
@@ -3698,7 +3701,7 @@
final String patout = parsedCommandLine.getOptionValue("output");
try {
- final PatGen generator = new PatGen(dictionary, patterns, translate, patout);
+ final PatGen generator = new PatGen(dictionary, patterns, translate, patout, System.out);
generator.process();
} catch (final HyphenationException e) {
logger.error(e.getMessage(), e);
Modified: trunk/foray/master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 14:53:18 UTC (rev 11824)
+++ trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 15:22:33 UTC (rev 11825)
@@ -50,14 +50,6 @@
<property name="influenceFormat" value="1"/>
</module>
- <!-- Allow "main" methods to suppress the checks for System.exit(), etc. -->
- <!-- TODO: Write a custom checkstyle plugin that does the suppression in "main" automatically. -->
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="Checkstyle-GenericIllegalRegexp-Off"/>
- <property name="onCommentFormat" value="Checkstyle-GenericIllegalRegexp-On"/>
- <property name="checkFormat" value="RegexpSinglelineJava"/>
- </module>
-
<!-- Allow magic numbers where they represent hard-coded arbitrary data, for example numeric codes assigned by
a standard-setting body. -->
<module name="SuppressionCommentFilter">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 14:53:21
|
Revision: 11824
http://sourceforge.net/p/foray/code/11824
Author: victormote
Date: 2021-01-18 14:53:18 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Add and use new targeted checkstyle suppression filter for exiting screen applications.
Modified Paths:
--------------
trunk/foray/foray-app/src/main/java/org/foray/app/AwtStarter.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVectorInputStream.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/GlyphListParser.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoFrame.java
trunk/foray/master/config/checkstyle/checkstyle-config.xml
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/AwtStarter.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/AwtStarter.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/AwtStarter.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -169,10 +169,9 @@
frame.validate();
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(final WindowEvent we) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
/* TODO: Is there a better way to handle this? */
+ /* CheckStyle: Allow System.exit() to exit screen application. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
});
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -81,10 +81,9 @@
frame.validate();
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(final WindowEvent we) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
/* TODO: Is there a better way to do this. */
+ /* CheckStyle: Allow System.exit() to exit screen application. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
});
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -244,12 +244,12 @@
* written.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final Logger logger = LoggerFactory.getLogger(CharSetParser.class);
final String usage = "Usage: CharSetParser <input-file> "
+ "<output-file>\n";
if (args.length != 2) {
logger.error("Wrong number of arguments.\n" + usage);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
URL url = null;
@@ -258,6 +258,7 @@
} catch (final MalformedURLException e) {
logger.error("Unable to create URL for: " + args[0] + "\n");
logger.error(" " + e.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
InputStream input = null;
@@ -265,6 +266,7 @@
input = url.openStream();
} catch (final IOException e1) {
logger.error("Unable to create Reader for: " + args[0] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
FileOutputStream output = null;
@@ -273,6 +275,7 @@
} catch (final FileNotFoundException e2) {
logger.error("Unable to create FileOutputStream for: "
+ args[1] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final CharSetParser parser = new CharSetParser(input);
@@ -281,10 +284,12 @@
} catch (final IOException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} catch (final PsException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
try {
@@ -292,10 +297,11 @@
} catch (final IOException e4) {
logger.error("Error writing to: " + args[1] + "\n");
logger.error(" " + e4.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -584,7 +584,6 @@
* listed here.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final Logger logger = LoggerFactory.getLogger(EncodingParser.class);
final String usage = "Usage: GlyphListParser <input-file> "
+ "<column-number> <output-file> <glyph-lists>?\n";
@@ -591,6 +590,7 @@
if (args.length > EncodingParser.MAX_ARGS
|| args.length < EncodingParser.MIN_ARGS) {
logger.error("Wrong number of arguments.\n" + usage);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
URL url = null;
@@ -601,6 +601,7 @@
+ args[EncodingParser.ARG_INPUT_URL]
+ "\n");
logger.error(" " + e.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
InputStream input = null;
@@ -610,6 +611,7 @@
logger.error("Unable to create Reader for: "
+ args[EncodingParser.ARG_INPUT_URL]
+ "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
int columnNum = 0;
@@ -619,6 +621,7 @@
} catch (final NumberFormatException e5) {
logger.error("Unable to parse column number: "
+ args[1] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
if (columnNum < 1) {
@@ -625,6 +628,7 @@
logger.error("Invalid column number: "
+ args[EncodingParser.ARG_COLUMN_NUMBER]
+ "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -638,6 +642,7 @@
} catch (final FileNotFoundException e2) {
logger.error("Unable to create FileOutputStream for: "
+ args[EncodingParser.ARG_OUTPUT_URL] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -658,11 +663,13 @@
logger.error("Error parsing: "
+ args[EncodingParser.ARG_INPUT_URL] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} catch (final PsException e3) {
logger.error("Error parsing: "
+ args[EncodingParser.ARG_INPUT_URL] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
try {
@@ -671,10 +678,11 @@
logger.error("Error writing to: "
+ args[EncodingParser.ARG_OUTPUT_URL] + "\n");
logger.error(" " + e4.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVectorInputStream.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVectorInputStream.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVectorInputStream.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -40,6 +40,8 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
@@ -116,7 +118,7 @@
* </ul>
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(EncodingVectorInputStream.class);
final Options commandLineOptions = EncodingVectorInputStream.getCommandLineOptions();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine parsedCommandLine = null;
@@ -123,10 +125,11 @@
try {
parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + EncodingVectorInputStream.class.getName(),
commandLineOptions, true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -140,7 +143,8 @@
fis = new FileInputStream(input);
inputStream = new BufferedInputStream(fis);
} catch (final FileNotFoundException e) {
- System.err.println("File cannot be opened for input: " + input);
+ logger.error("File cannot be opened for input: " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -149,8 +153,9 @@
final FileOutputStream fos = new FileOutputStream(output);
final Charset charset = Charset.forName("UTF-8");
writer = new OutputStreamWriter(fos, charset);
- } catch (final FileNotFoundException e1) {
- System.err.println("File cannot be opened for output: " + output);
+ } catch (final FileNotFoundException e) {
+ logger.error("File cannot be opened for output: " + output, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -170,20 +175,19 @@
}
writer.close();
} catch (final IOException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return;
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
} finally {
try {
inputFilter.close();
} catch (final IOException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
}
}
- /* Checkstyle-GenericIllegalRegexp-On. */
-
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/GlyphListParser.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/GlyphListParser.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/GlyphListParser.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -400,12 +400,11 @@
* written.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final Logger logger = LoggerFactory.getLogger(GlyphListParser.class);
- final String usage = "Usage: GlyphListParser <input-file> "
- + "<output-file>\n";
+ final String usage = "Usage: GlyphListParser <input-file> <output-file>\n";
if (args.length != 2) {
logger.error("Wrong number of arguments.\n" + usage);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
URL url = null;
@@ -414,6 +413,7 @@
} catch (final MalformedURLException e) {
logger.error("Unable to create URL for: " + args[0] + "\n");
logger.error(" " + e.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
InputStream input = null;
@@ -421,6 +421,7 @@
input = url.openStream();
} catch (final IOException e1) {
logger.error("Unable to create Reader for: " + args[0] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
FileOutputStream output = null;
@@ -427,8 +428,8 @@
try {
output = new FileOutputStream(args[1]);
} catch (final FileNotFoundException e2) {
- logger.error("Unable to create FileOutputStream for: "
- + args[1] + "\n");
+ logger.error("Unable to create FileOutputStream for: " + args[1] + "\n");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final GlyphListParser parser = new GlyphListParser(input);
@@ -437,10 +438,12 @@
} catch (final IOException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} catch (final PsException e3) {
logger.error("Error parsing: " + args[0] + "\n");
logger.error(" " + e3.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
try {
@@ -448,10 +451,11 @@
} catch (final IOException e4) {
logger.error("Error writing to: " + args[1] + "\n");
logger.error(" " + e4.getMessage());
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoFrame.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoFrame.java 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoFrame.java 2021-01-18 14:53:18 UTC (rev 11824)
@@ -81,10 +81,9 @@
@Override
public void windowClosing(final WindowEvent we) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
/* TODO: Is there a better way to exit the application? */
+ /* CheckStyle: Allow System.exit() to exit screen application. */
System.exit(0);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 14:33:37 UTC (rev 11823)
+++ trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 14:53:18 UTC (rev 11824)
@@ -42,6 +42,14 @@
<property name="influenceFormat" value="1"/>
</module>
+ <!-- TODO: This suppression may not be a good suppression to allow. Find out if there is a better way to handle
+ exiting a screen application. -->
+ <module name="SuppressWithNearbyCommentFilter">
+ <property name="commentFormat" value="CheckStyle: Allow System.exit\(\) to exit screen application."/>
+ <property name="idFormat" value="RestrictSystemExit"/>
+ <property name="influenceFormat" value="1"/>
+ </module>
+
<!-- Allow "main" methods to suppress the checks for System.exit(), etc. -->
<!-- TODO: Write a custom checkstyle plugin that does the suppression in "main" automatically. -->
<module name="SuppressionCommentFilter">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 14:33:40
|
Revision: 11823
http://sourceforge.net/p/foray/code/11823
Author: victormote
Date: 2021-01-18 14:33:37 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Remove no-longer-needed checkstyle suppression filter.
Modified Paths:
--------------
trunk/foray/master/config/checkstyle/checkstyle-config.xml
Modified: trunk/foray/master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 14:23:21 UTC (rev 11822)
+++ trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 14:33:37 UTC (rev 11823)
@@ -42,13 +42,6 @@
<property name="influenceFormat" value="1"/>
</module>
- <!-- Allow otherwise Illegal Types to be used in certain circumstances. -->
- <module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="Checkstyle-IllegalType-Off"/>
- <property name="onCommentFormat" value="Checkstyle-IllegalType-On"/>
- <property name="checkFormat" value="IllegalType"/>
- </module>
-
<!-- Allow "main" methods to suppress the checks for System.exit(), etc. -->
<!-- TODO: Write a custom checkstyle plugin that does the suppression in "main" automatically. -->
<module name="SuppressionCommentFilter">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 14:23:24
|
Revision: 11822
http://sourceforge.net/p/foray/code/11822
Author: victormote
Date: 2021-01-18 14:23:21 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
1. Convert main method System.err and System.out to loggers. 2. Use specific suppression filter for System.exit in main method instead of blanket suppression.
Modified Paths:
--------------
trunk/foray/foray-app/src/main/java/org/foray/app/FOray.java
trunk/foray/foray-app/src/main/java/org/foray/app/test/TestConverter.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoFo2Pdf.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Pdf.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Xml.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Fo.java
trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Pdf.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigGenerator.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TrueTypeCollectionLister.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/ValidateChars.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/WordListCreator.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/filter/PsFilter.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/Main.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/FOray.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/FOray.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/FOray.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -31,7 +31,6 @@
import org.foray.common.ConfigurationException;
import org.foray.common.primitive.StringUtils;
import org.foray.core.ForayException;
-import org.foray.core.SessionConfig;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -42,6 +41,8 @@
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Command-line entry point to the FOray application.
@@ -298,16 +299,17 @@
* for details on these arguments.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(FOray.class);
final Options commandLineOptions = FOray.getCommandLineOptions();
CommandLine parsedCommandLine = null;
try {
parsedCommandLine = FOray.parseCommandLine(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + FOray.class.getName(), commandLineOptions,
true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(FOray.STATUS_COMMAND_LINE_ERROR);
}
CommandLineOptions options = null;
@@ -317,22 +319,19 @@
final Starter starter = options.getStarter();
starter.run();
} catch (final ForayException e) {
- System.err.println("" + e.getMessage());
+ logger.error(e.getMessage(), e);
if (options != null) {
- final SessionConfig sessionConfig = options.getSessionConfig();
- if (sessionConfig.optionVerbosity().equals("debug")) {
- e.printStackTrace();
- }
if (options.getOutputFile() != null) {
options.getOutputFile().delete();
}
}
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(2);
} catch (final ConfigurationException e) {
- System.err.println("" + e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/test/TestConverter.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/test/TestConverter.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/test/TestConverter.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -105,62 +105,6 @@
}
/**
- * This main method can be used to run the test converter from
- * the command line.
- * This will take a specified testsuite xml and process all
- * tests in it.
- * @param args The command line options, which are:
- * -b to set the base directory for where the testsuite and associated
- * files are
- * -failOnly to process only the tests which are specified as fail in the
- * test results
- * -pdf to output the result as pdf
- */
- public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
- final Logger log = LoggerFactory.getLogger(TestConverter.class);
-
- final TestConverter tc = new TestConverter();
-
- String testFile = null;
- String output = null;
- for (int count = 0; count < args.length; count++) {
- final String argument = args[count];
- if (argument.equals("-failOnly")) {
- tc.setFailOnly(true);
- } else if (argument.equals("-pdf")) {
- tc.setOutputPDF(true);
- } else if (argument.equals("-b")) {
- tc.setBaseDir(args[count + 1]);
- count++;
- } else if (argument.equals("-input")) {
- testFile = args[count + 1];
- count++;
- } else if (argument.equals("-output")) {
- output = args[count + 1];
- count++;
- } else {
- log.error("Invalid argument: " + argument);
- System.exit(1);
- }
- }
- if (testFile == null) {
- log.error("Test suite file name (-input) required. Aborting.");
- System.exit(1);
- }
- if (output == null) {
- log.error("Ouput directory (-output) required. Aborting.");
- System.exit(1);
- }
- try {
- tc.runTests(testFile, output);
- } catch (final ForayException e) {
- e.printStackTrace();
- }
- /* Checkstyle-GenericIllegalRegexp-On. */
- }
-
- /**
* Creates a logger.
*/
private void setupLogging() {
@@ -407,4 +351,59 @@
return null;
}
+ /**
+ * This main method can be used to run the test converter from the command line.
+ * This will take a specified testsuite xml and process all tests in it.
+ * @param args The command line options, which are:
+ * -b to set the base directory for where the testsuite and associated
+ * files are
+ * -failOnly to process only the tests which are specified as fail in the
+ * test results
+ * -pdf to output the result as pdf
+ */
+ public static void main(final String[] args) {
+ final Logger logger = LoggerFactory.getLogger(TestConverter.class);
+
+ final TestConverter tc = new TestConverter();
+
+ String testFile = null;
+ String output = null;
+ for (int count = 0; count < args.length; count++) {
+ final String argument = args[count];
+ if (argument.equals("-failOnly")) {
+ tc.setFailOnly(true);
+ } else if (argument.equals("-pdf")) {
+ tc.setOutputPDF(true);
+ } else if (argument.equals("-b")) {
+ tc.setBaseDir(args[count + 1]);
+ count++;
+ } else if (argument.equals("-input")) {
+ testFile = args[count + 1];
+ count++;
+ } else if (argument.equals("-output")) {
+ output = args[count + 1];
+ count++;
+ } else {
+ logger.error("Invalid argument: " + argument);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ }
+ if (testFile == null) {
+ logger.error("Test suite file name (-input) required. Aborting.");
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ if (output == null) {
+ logger.error("Ouput directory (-output) required. Aborting.");
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ try {
+ tc.runTests(testFile, output);
+ } catch (final ForayException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoAwtViewer.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -176,7 +176,6 @@
* @param args Command-line arguments. This method currently uses none.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoAwtViewer app = new DemoAwtViewer();
app.getLogger().info(Application.getApplicationNameShort() +
" ExampleAWTViewer\n");
@@ -200,12 +199,13 @@
app.getLogger().info("Success!");
} catch (final ForayException e) {
app.getLogger().error("Demo AWT Viewer Error", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
} catch (final IOException e) {
app.getLogger().error("Demo AWT Viewer Error", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoFo2Pdf.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoFo2Pdf.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoFo2Pdf.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -88,7 +88,6 @@
* @param args The command-line arguments. None are currently supported.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoFo2Pdf app = new DemoFo2Pdf();
app.getLogger().info(Application.getApplicationNameShort()
+ " ExampleFO2PDF\n");
@@ -112,13 +111,14 @@
app.convertFO2PDF(fofile.toURI().toURL(), pdffile);
} catch (final ForayException e) {
app.getLogger().error("Demo FO to PDF Error", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
} catch (final IOException e) {
app.getLogger().error("Demo FO to PDF Error", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
app.getLogger().info("Success!");
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Pdf.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Pdf.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Pdf.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -111,7 +111,6 @@
* @param args The command-line arguments. None are currently supported.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoObj2Pdf app = new DemoObj2Pdf();
app.getLogger().info(Application.getApplicationNameShort()
+ " ExampleObj2PDF\n");
@@ -137,10 +136,10 @@
xsltfile, pdffile);
} catch (final ForayException e) {
app.getLogger().error("Demo Obj to PDF Error", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
app.getLogger().info("Success!");
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Xml.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Xml.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoObj2Xml.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -99,7 +99,6 @@
* @param args The command-line arguments. None are currently supported.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoObj2Xml app = new DemoObj2Xml();
app.getLogger().info(Application.getApplicationNameShort() +
" ExampleObj2XML\n");
@@ -122,13 +121,14 @@
app.convertProjectTeam2XML(createSampleProjectTeam(), xmlfile);
} catch (final IOException e) {
app.getLogger().error("Demo Obj to XML Error:", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
} catch (final TransformerException e) {
app.getLogger().error("Demo Obj to XML Error:", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
app.getLogger().info("Success!");
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Fo.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Fo.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Fo.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -86,7 +86,6 @@
* @param args The command-line arguments. None are currently supported.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoXml2Fo app = new DemoXml2Fo();
app.getLogger().info(Application.getApplicationNameShort() +
@@ -113,13 +112,14 @@
app.convertXML2FO(xmlfile, xsltfile, fofile);
} catch (final IOException e) {
app.getLogger().error("Demo XML to FO Error: ", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
} catch (final TransformerException e) {
app.getLogger().error("Demo XML to FO Error: ", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
app.getLogger().info("Success!");
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Pdf.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Pdf.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-app/src/main/java/org/foray/demo/embed/DemoXml2Pdf.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -112,7 +112,6 @@
* @param args The command-line arguments. None are currently supported.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
final DemoXml2Pdf app = new DemoXml2Pdf();
app.getLogger().info(Application.getApplicationNameShort() +
@@ -139,10 +138,10 @@
app.convertXML2PDF(xmlfile, xsltfile, pdffile);
} catch (final ForayException e) {
app.getLogger().error("Demo XML to PDF Error: ", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(-1);
}
app.getLogger().info("Success!");
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigGenerator.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigGenerator.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/ConfigGenerator.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -41,6 +41,7 @@
import org.apache.commons.io.IOCase;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
@@ -425,46 +426,6 @@
}
/**
- * Command-line interface for {@link ConfigGenerator}.
- * Arguments contain the list of directories for which the configuration
- * should be created.
- * The name "system" (case is irrelevant) indicates that all known font directories on this
- * system should be included.
- * The file is created in the current directory with the name
- * "axsl-font-config-auto.xml".
- * @param args The list of directories which should be traversed looking
- * for fonts to configure.
- */
- public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
- if (args == null) {
- System.err.println("At least one directory is required.");
- System.exit(1);
- }
- final String fileName = "axsl-font-config-auto.xml";
- final File file = new File(fileName);
- if (file.exists()) {
- System.err.println("Aborting. File already exists:\n "
- + file.getAbsolutePath());
- System.exit(1);
- }
- final FontServer4a fontServer = new FontServer4a();
- final ConfigGenerator config = new ConfigGenerator(fontServer);
- for (String arg : args) {
- config.processDirectory(arg, ConfigGenerator.getDefaultFilter());
- }
- try {
- config.write(file);
- } catch (final FontException e) {
- System.out.println(e.getMessage());
- System.exit(1);
- }
- System.out.println("Files processed: " + config.getSuccessCount());
- System.out.println("Not processed: " + config.getFailureCount());
- /* Checkstyle-GenericIllegalRegexp-On. */
- }
-
- /**
* Returns the quantity of files that could not be processed.
* @return The quantity of files that could not be processed.
*/
@@ -510,4 +471,45 @@
}
+ /**
+ * Command-line interface for {@link ConfigGenerator}.
+ * Arguments contain the list of directories for which the configuration
+ * should be created.
+ * The name "system" (case is irrelevant) indicates that all known font directories on this
+ * system should be included.
+ * The file is created in the current directory with the name
+ * "axsl-font-config-auto.xml".
+ * @param args The list of directories which should be traversed looking
+ * for fonts to configure.
+ */
+ public static void main(final String[] args) {
+ final Logger logger = LoggerFactory.getLogger(ConfigGenerator.class);
+ if (args == null) {
+ logger.error("At least one directory is required.");
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ final String fileName = "axsl-font-config-auto.xml";
+ final File file = new File(fileName);
+ if (file.exists()) {
+ logger.error("Aborting. File already exists:\n " + file.getAbsolutePath());
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ final FontServer4a fontServer = new FontServer4a();
+ final ConfigGenerator config = new ConfigGenerator(fontServer);
+ for (String arg : args) {
+ config.processDirectory(arg, ConfigGenerator.getDefaultFilter());
+ }
+ try {
+ config.write(file);
+ } catch (final FontException e) {
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
+ }
+ logger.info("Files processed: " + config.getSuccessCount());
+ logger.info("Not processed: " + config.getFailureCount());
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TrueTypeCollectionLister.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TrueTypeCollectionLister.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TrueTypeCollectionLister.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -45,6 +45,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -216,14 +217,15 @@
* @throws FontException For errors reading the content.
*/
public static void main(final String[] args) throws FontException {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(TrueTypeCollectionLister.class);
final Options commandLineOptions = TrueTypeCollectionLister.getCommandLineOptions();
CommandLine parsedCommandLine = null;
try {
parsedCommandLine = Type1MetricsSerializer.parseCommandLine(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
showCommandLineHelp(commandLineOptions);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final String inputURL = parsedCommandLine.getOptionValue("input");
@@ -232,6 +234,7 @@
if (helpSelected) {
showCommandLineHelp(commandLineOptions);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(0);
}
@@ -238,7 +241,6 @@
final FontServer4a fontServer = new FontServer4a();
final TrueTypeCollectionLister app = new TrueTypeCollectionLister(fontServer);
app.listTTCContents(inputURL, fontName);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -46,6 +46,7 @@
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.RegexFileFilter;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
@@ -224,16 +225,17 @@
* @param args The command-line arguments.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(Type1MetricsSerializer.class);
final Options commandLineOptions = Type1MetricsSerializer.getCommandLineOptions();
CommandLine parsedCommandLine = null;
try {
parsedCommandLine = Type1MetricsSerializer.parseCommandLine(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + Type1MetricsSerializer.class.getName(),
commandLineOptions, true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -249,9 +251,8 @@
final Type1MetricsSerializer serializer = new Type1MetricsSerializer(inputDir, fileFilter, outputDir, null);
serializer.process();
} catch (final IOException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/ValidateChars.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/ValidateChars.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/ValidateChars.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -356,11 +356,12 @@
* that can be used to locate local DTDs.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(ValidateChars.class);
if (args == null
|| args.length < ValidateChars.MIN_CL_ARGUMENTS
|| args.length > ValidateChars.MAX_CL_ARGUMENTS) {
- System.out.print("Wrong number of arguments.");
+ logger.error("Wrong number of arguments.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ValidateChars.STATUS_WRONG_QTY_ARGUMENTS);
}
final String input = args[0];
@@ -375,7 +376,7 @@
try {
hyphenationDir = UrlFactory.createURL(nlDir);
} catch (final MalformedURLException e) {
- System.err.println("Invalid URL: " + nlDir);
+ logger.error("Invalid URL: " + nlDir, e);
}
final HyphenationServerConfig config = new HyphenationServerConfig();
config.setRawHyphenationPatternsBaseDirectory(hyphenationDir);
@@ -384,7 +385,8 @@
try {
server = new HyphenationServer4a(config);
} catch (final HyphenationException e) {
- e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ValidateChars.STATUS_FILE_NOT_FOUND);
}
@@ -415,12 +417,13 @@
/* Process each file in the list. */
for (int i = 0; i < filesToProcess.length; i++) {
final File fileToProcess = filesToProcess[i];
- System.out.println("Processing: " + fileToProcess.getName());
+ logger.info("Processing: " + fileToProcess.getName());
FileInputStream fis = null;
try {
fis = new FileInputStream(fileToProcess);
} catch (final FileNotFoundException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ValidateChars.STATUS_FILE_NOT_FOUND);
}
final InputStream inputStream = new BufferedInputStream(fis);
@@ -429,21 +432,12 @@
inputSource, catalog, iso639);
try {
validator.start();
- } catch (final IOException e) {
- System.out.print(e.getMessage());
- e.printStackTrace();
+ } catch (final IOException | ParserConfigurationException | SAXException e) {
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ValidateChars.STATUS_PARSING_ERROR);
- } catch (final ParserConfigurationException e) {
- System.out.print(e.getMessage());
- e.printStackTrace();
- System.exit(ValidateChars.STATUS_PARSING_ERROR);
- } catch (final SAXException e) {
- System.out.print(e.getMessage());
- e.printStackTrace();
- System.exit(ValidateChars.STATUS_PARSING_ERROR);
}
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/WordListCreator.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/WordListCreator.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/util/WordListCreator.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -29,6 +29,8 @@
package org.foray.hyphen.util;
import com.ibm.icu.text.Normalizer2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
@@ -353,11 +355,11 @@
* encoding.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(WordListCreator.class);
if (args == null
|| args.length != WordListCreator.QTY_CL_ARGUMENTS) {
- System.err.println("Requires exactly " + WordListCreator.QTY_CL_ARGUMENTS
- + " arguments.");
+ logger.error("Requires exactly " + WordListCreator.QTY_CL_ARGUMENTS + " arguments.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
int argIndex = 0;
@@ -372,7 +374,8 @@
final File inputFile = new File(input);
final File outputFile = new File(output);
if (outputFile.exists()) {
- System.err.println("Output file already exists: " + output);
+ logger.error("Output file already exists: " + output);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
InputStream inputStream = null;
@@ -379,7 +382,8 @@
try {
inputStream = new FileInputStream(inputFile);
} catch (final FileNotFoundException e) {
- System.err.println("Error opening: " + input);
+ logger.error("Error opening: " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final WordListCreator wordList = new WordListCreator(inputStream, inputEncoding);
@@ -387,7 +391,8 @@
try {
words = wordList.parse();
} catch (final IOException e) {
- System.err.println("Error processing: " + input);
+ logger.error("Error processing: " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} finally {
try {
@@ -402,7 +407,8 @@
fos = new FileOutputStream(output);
writer = new OutputStreamWriter(fos, outputEncoding);
} catch (final IOException e) {
- System.err.println("Error opening: " + output);
+ logger.error("Error opening: " + output, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
try {
@@ -410,7 +416,8 @@
writer.write(word + "\n");
}
} catch (final IOException e) {
- System.err.println("Error writing to: " + output);
+ logger.error("Error writing to: " + output, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} finally {
if (writer != null) {
@@ -423,8 +430,7 @@
}
}
}
- System.out.println("Word List successfully written.");
- /* Checkstyle-GenericIllegalRegexp-On. */
+ logger.info("Word List successfully written.");
}
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/zzarchive/PatGen.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -46,6 +46,8 @@
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.FileOutputStream;
@@ -147,6 +149,9 @@
*/
private String banner = "This is the FOray Java Port of patgen.";
+ /** The logger. */
+ private Logger logger = LoggerFactory.getLogger(PatGen.class);
+
/*
* (patgen.web, line 56)
* 1. The original version 1 of PATGEN was written by Frank M. Liang
@@ -183,6 +188,7 @@
/* Following line allows this class to use System.in & System.out for IO, which is normally not directly allowed in
* FOray code. An exception is made here because we are trying to conform to the original patgen design in TeX. */
+
/* Checkstyle-GenericIllegalRegexp-Off. */
/**
@@ -214,6 +220,8 @@
System.out.println(outputString);
}
+ /* Checkstyle-GenericIllegalRegexp-On. */
+
/**
* Reads a line of input from stdin, and parses it into either 2 or 3 integers, the first being placed in
* {@link #n1}, the second in {@link #n2}, and the third in {@link #n3}.
@@ -232,11 +240,11 @@
try {
inputString = this.inputReader.readLine();
} catch (final IOException e) {
- System.err.println("Error reading from stdin.");
+ this.logger.error("Error reading from stdin.", e);
}
final String[] parsedInput = inputString.split(" ");
if (parsedInput.length != qtyExpected) {
- System.err.println("Expected " + qtyExpected + " inputs. Number read: " + parsedInput.length);
+ this.logger.error("Expected " + qtyExpected + " inputs. Number read: " + parsedInput.length);
}
if (parsedInput.length > 0) {
this.n1 = Integer.parseInt(parsedInput[0]);
@@ -249,8 +257,6 @@
}
}
- /* Checkstyle-GenericIllegalRegexp-On. */
-
/**
* Reads a line of input from stdin and returns it as an unparsed string.
* @return The line of input from stdin.
@@ -3659,8 +3665,6 @@
return clOptions;
}
- /* Checkstyle-GenericIllegalRegexp-Off. */
-
/**
* Command-line interface for the {@link PatGen} class.
* @param args The command-line arguments.
@@ -3673,6 +3677,7 @@
* </ul>
*/
public static void main(final String[] args) {
+ final Logger logger = LoggerFactory.getLogger(PatGen.class);
final Options commandLineOptions = PatGen.getCommandLineOptions();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine parsedCommandLine = null;
@@ -3679,10 +3684,11 @@
try {
parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + PatGen.class.getName(), commandLineOptions,
true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
@@ -3695,13 +3701,14 @@
final PatGen generator = new PatGen(dictionary, patterns, translate, patout);
generator.process();
} catch (final HyphenationException e) {
- System.err.println(e.getMessage());
- return;
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
} catch (final IOException e) {
- System.err.println(e.getMessage());
- return;
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
+ System.exit(1);
}
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -34,6 +34,9 @@
import org.axsl.pdf.PdfException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -107,8 +110,7 @@
final String description = args[3];
/* Checkstyle-MagicNumber-On. */
- /* Checkstyle-GenericIllegalRegexp-Off. */
-
+ final Logger logger = LoggerFactory.getLogger(PdfReport.class);
try {
final InputStream input = new FileInputStream(inputFile);
final PrintStream writer = new PrintStream(outputFile, "utf-8");
@@ -116,10 +118,8 @@
input.close();
writer.close();
} catch (final IOException | PdfException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
}
-
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/filter/PsFilter.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/filter/PsFilter.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/filter/PsFilter.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -28,6 +28,9 @@
package org.foray.ps.filter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -253,10 +256,11 @@
* </ol>
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(PsFilter.class);
if (args == null
|| args.length < PsFilter.CL_MIN_ARGS) {
- System.err.println("Must be at least three arguments.");
+ logger.error("Must be at least three arguments.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final File input = new File(args[0]);
@@ -275,7 +279,8 @@
final String filterName = args[i];
final PsFilter psFilter = PsFilter.findFilter(filterName);
if (psFilter == null) {
- System.err.println("PsFilter not found: " + filterName);
+ logger.error("PsFilter not found: " + filterName);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
lastOutputStream = psFilter.makeEncodeFilter(
@@ -292,7 +297,8 @@
}
}
} catch (final IOException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} finally {
try {
@@ -303,7 +309,7 @@
lastOutputStream.close();
}
} catch (final IOException e) {
- e.printStackTrace();
+ logger.error("Unable to close stream.", e);
}
}
@@ -317,7 +323,8 @@
final String filterName = args[i];
final PsFilter psFilter = PsFilter.findFilter(filterName);
if (psFilter == null) {
- System.err.println("PsFilter not found: " + filterName);
+ logger.error("PsFilter not found: " + filterName);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
lastInputStream = psFilter.makeDecodeFilter(
@@ -334,7 +341,8 @@
}
}
} catch (final IOException e) {
- System.err.println(e.getMessage());
+ logger.error(e.getMessage(), e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
} finally {
try {
@@ -345,11 +353,10 @@
outputStream.close();
}
} catch (final IOException e) {
- e.printStackTrace();
+ logger.error("Unable to close stream.", e);
}
}
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/Main.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/Main.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/Main.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -28,6 +28,8 @@
package org.foray.ps.java2d.demo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Main entry point to the java 2d barcode demonstration.
@@ -50,16 +52,16 @@
* the name of a file containing PostScript content to be interpreted.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(org.foray.ps.java2d.demo.Main.class);
if (args == null
|| args.length != 1) {
- System.out.print("Wrong number of arguments.");
+ logger.error("Wrong number of arguments.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(1);
}
final String fileName = args[0];
final DemoFrame mainframe = new DemoFrame(fileName);
mainframe.setVisible(true);
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayPretty.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -1236,7 +1236,7 @@
* that can be used to locate local DTDs.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(ForayPretty.class);
final Options commandLineOptions = ForayPretty.getCommandLineOptions();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine parsedCommandLine = null;
@@ -1243,10 +1243,11 @@
try {
parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + ForayPretty.class.getName(), commandLineOptions,
true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_COMMAND_LINE_ERROR);
}
@@ -1260,7 +1261,8 @@
fis = new FileInputStream(input);
inputStream = new BufferedInputStream(fis);
} catch (final FileNotFoundException e) {
- System.err.println("File cannot be opened for input: " + input);
+ logger.error("File cannot be opened for input: " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_FILE_NOT_FOUND);
}
final InputSource inputSource = new InputSource(inputStream);
@@ -1268,8 +1270,9 @@
try {
final FileOutputStream fos = new FileOutputStream(output);
outputStream = new BufferedOutputStream(fos);
- } catch (final FileNotFoundException e1) {
- System.err.println("File cannot be opened for output: " + output);
+ } catch (final FileNotFoundException e) {
+ logger.error("File cannot be opened for output: " + output, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_FILE_NOT_FOUND);
}
final ForayPretty processor = new ForayPretty(inputSource, outputStream,
@@ -1277,19 +1280,19 @@
try {
processor.start();
} catch (final IOException e) {
- System.out.println("Error parsing " + input + ": " + e.getClass().getName() + ": " + e.getMessage());
+ logger.error("Error parsing " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_PARSING_ERROR);
} catch (final ParserConfigurationException e) {
- System.out.println("Error parsing input.");
- e.printStackTrace();
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_PARSING_ERROR);
} catch (final SAXException e) {
- System.out.println("Error parsing input.");
- e.printStackTrace();
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayPretty.STATUS_PARSING_ERROR);
}
- System.out.println("Input: " + input + " successfully pretty-printed,\n output in: " + output);
- /* Checkstyle-GenericIllegalRegexp-On. */
+ logger.info("Input: " + input + " successfully pretty-printed,\n output in: " + output);
}
}
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java 2021-01-18 13:15:27 UTC (rev 11821)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayXdiff.java 2021-01-18 14:23:21 UTC (rev 11822)
@@ -676,7 +676,7 @@
* </ul>
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(ForayXdiff.class);
final Options commandLineOptions = ForayXdiff.getCommandLineOptions();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine parsedCommandLine = null;
@@ -683,10 +683,11 @@
try {
parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error("Error parsing command line", e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + ForayXdiff.class.getName(), commandLineOptions,
true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_COMMAND_LINE_ERROR);
}
final String catalog = parsedCommandLine.getOptionValue("catalog");
@@ -699,7 +700,8 @@
final File file = new File(files[i]);
stream = new FileInputStream(file);
} catch (final FileNotFoundException e) {
- System.out.println("File Not Found: " + files[i]);
+ logger.error("File Not Found: " + files[i], e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_MALFORMED_URL);
}
streamsToCompare[i] = stream;
@@ -708,22 +710,23 @@
final ForayXdiff processor = new ForayXdiff(streamsToCompare, catalog);
final boolean equivalent = processor.equivalent();
if (equivalent) {
- System.out.println("All XML Streams are equivalent.");
+ logger.info("All XML Streams are equivalent.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_SUCCESS);
} else {
- System.out.println("Differences(s) in XML Streams found.");
+ logger.warn("Differences(s) in XML Streams found.");
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_DIFFERENCE_FOUND);
}
} catch (final XMLStreamException e) {
- System.out.println("Error parsing input.");
- System.out.println(e.getMessage());
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_PARSING_ERROR);
} catch (final IOException e) {
- System.out.println("Error parsing input.");
- System.out.println(e.getMessage());
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayXdiff.STATUS_PARSING_ERROR);
}
- /* Checkstyle-GenericIllegalRegexp-On. */
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 13:15:29
|
Revision: 11821
http://sourceforge.net/p/foray/code/11821
Author: victormote
Date: 2021-01-18 13:15:27 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Add SuppressionWithNearbyCommentFilter to checkstyle config to allow System.exit calls to be marked as allowable more cleanly.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/resources/logback.xml
trunk/foray/foray-common/src/test/resources/logback-test.xml
trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayAssignId.java
trunk/foray/master/config/checkstyle/checkstyle-config.xml
Modified: trunk/foray/foray-common/src/main/resources/logback.xml
===================================================================
--- trunk/foray/foray-common/src/main/resources/logback.xml 2021-01-18 11:30:50 UTC (rev 11820)
+++ trunk/foray/foray-common/src/main/resources/logback.xml 2021-01-18 13:15:27 UTC (rev 11821)
@@ -1,5 +1,12 @@
<configuration>
+ <!--
+ See http://logback.qos.ch/manual/layouts.html for configuration documentation. Of note:
+ 1. [When configuring the handling of Throwable] "By default the full stack trace will be output."
+ This section of the documentation also indicates how this default behavior can be changed, to avoid the security
+ issues that may arise by dumping a stack trace.
+ -->
+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
Modified: trunk/foray/foray-common/src/test/resources/logback-test.xml
===================================================================
--- trunk/foray/foray-common/src/test/resources/logback-test.xml 2021-01-18 11:30:50 UTC (rev 11820)
+++ trunk/foray/foray-common/src/test/resources/logback-test.xml 2021-01-18 13:15:27 UTC (rev 11821)
@@ -1,5 +1,12 @@
<configuration>
+ <!--
+ See http://logback.qos.ch/manual/layouts.html for configuration documentation. Of note:
+ 1. [When configuring the handling of Throwable] "By default the full stack trace will be output."
+ This section of the documentation also indicates how this default behavior can be changed, to avoid the security
+ issues that may arise by dumping a stack trace.
+ -->
+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
Modified: trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayAssignId.java
===================================================================
--- trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayAssignId.java 2021-01-18 11:30:50 UTC (rev 11820)
+++ trunk/foray/foray-xml/src/main/java/org/foray/xml/ForayAssignId.java 2021-01-18 13:15:27 UTC (rev 11821)
@@ -346,7 +346,7 @@
* that can be used to locate local DTDs.
*/
public static void main(final String[] args) {
- /* Checkstyle-GenericIllegalRegexp-Off. */
+ final Logger logger = LoggerFactory.getLogger(ForayAssignId.class);
final Options commandLineOptions = ForayAssignId.getCommandLineOptions();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine parsedCommandLine = null;
@@ -353,10 +353,11 @@
try {
parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
} catch (final ParseException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage(), e);
final HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + ForayAssignId.class.getName(), commandLineOptions,
true);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_COMMAND_LINE_ERROR);
}
@@ -370,7 +371,8 @@
fis = new FileInputStream(input);
inputStream = new BufferedInputStream(fis);
} catch (final FileNotFoundException e) {
- System.err.println("File cannot be opened for input: " + input);
+ logger.error("File cannot be opened for input: " + input, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_FILE_NOT_FOUND);
}
final InputSource inputSource = new InputSource(inputStream);
@@ -378,8 +380,9 @@
try {
final FileOutputStream fos = new FileOutputStream(output);
outputStream = new BufferedOutputStream(fos);
- } catch (final FileNotFoundException e1) {
- System.err.println("File cannot be opened for output: " + output);
+ } catch (final FileNotFoundException e) {
+ logger.error("File cannot be opened for output: " + output, e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_FILE_NOT_FOUND);
}
final ForayAssignId processor = new ForayAssignId(inputSource, outputStream,
@@ -387,23 +390,23 @@
try {
processor.start();
} catch (final IOException e) {
- System.out.println("Error parsing " + input + ": " + e.getClass().getName() + ": " + e.getMessage());
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_PARSING_ERROR);
} catch (final ParserConfigurationException e) {
- System.out.println("Error parsing input.");
- e.printStackTrace();
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_PARSING_ERROR);
} catch (final SAXException e) {
- System.out.println("Error parsing input.");
- e.printStackTrace();
+ logger.error("Error parsing input.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_PARSING_ERROR);
} catch (final TransformerException e) {
- System.out.println("Error writing output.");
- e.printStackTrace();
+ logger.error("Error writing output.", e);
+ /* CheckStyle: Allow System.exit() in main method. */
System.exit(ForayAssignId.STATUS_WRITING_ERROR);
}
- System.out.println("Input: " + input + " successfully modified,\n output in: " + output);
- /* Checkstyle-GenericIllegalRegexp-On. */
+ logger.info("Input: " + input + " successfully modified,\n output in: " + output);
}
}
Modified: trunk/foray/master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 11:30:50 UTC (rev 11820)
+++ trunk/foray/master/config/checkstyle/checkstyle-config.xml 2021-01-18 13:15:27 UTC (rev 11821)
@@ -36,6 +36,12 @@
<module name="TreeWalker">
+ <module name="SuppressWithNearbyCommentFilter">
+ <property name="commentFormat" value="CheckStyle: Allow System.exit\(\) in main method."/>
+ <property name="idFormat" value="RestrictSystemExit"/>
+ <property name="influenceFormat" value="1"/>
+ </module>
+
<!-- Allow otherwise Illegal Types to be used in certain circumstances. -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="Checkstyle-IllegalType-Off"/>
@@ -44,8 +50,7 @@
</module>
<!-- Allow "main" methods to suppress the checks for System.exit(), etc. -->
- <!-- TODO: Write a custom checkstyle plugin that does the suppression in "main" automatically.
- -->
+ <!-- TODO: Write a custom checkstyle plugin that does the suppression in "main" automatically. -->
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="Checkstyle-GenericIllegalRegexp-Off"/>
<property name="onCommentFormat" value="Checkstyle-GenericIllegalRegexp-On"/>
@@ -262,6 +267,7 @@
</module>
<module name="RegexpSinglelineJava">
+ <property name="id" value="RestrictSystemExit"/>
<property name="ignoreComments" value="true"/>
<!-- . matches any character, so we need to escape it and use \. to match dots. -->
<property name="format" value="System\.exit"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 11:30:53
|
Revision: 11820
http://sourceforge.net/p/foray/code/11820
Author: victormote
Date: 2021-01-18 11:30:50 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Update DTD reference to match current reality.
Modified Paths:
--------------
trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml
Modified: trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml
===================================================================
--- trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml 2021-01-18 11:09:59 UTC (rev 11819)
+++ trunk/foray/master/config/checkstyle/checkstyle-suppressions.xml 2021-01-18 11:30:50 UTC (rev 11820)
@@ -2,7 +2,7 @@
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
- "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
+ "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|