[med-svn] [Git][java-team/libpdfbox-graphics2d-java][upstream] New upstream version 0.38

Pierre Gruet (@pgt) gitlab at salsa.debian.org
Mon May 30 20:33:55 BST 2022



Pierre Gruet pushed to branch upstream at Debian Java Maintainers / libpdfbox-graphics2d-java


Commits:
e059c70e by Pierre Gruet at 2022-05-26T15:00:37+02:00
New upstream version 0.38
- - - - -


14 changed files:

- README.md
- extended-tests/pom.xml
- graphics2d/pom.xml
- graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/IPdfBoxGraphics2DColorMapper.java
- graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2D.java
- graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DColorMapper.java
- graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DFontTextDrawer.java
- graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java
- graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java
- graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/RenderSVGsTest.java
- graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/SpecialColorsTest.java
- + graphics2d/src/test/resources/de/rototor/pdfbox/graphics2d/dashedStrokeRotation.svg
- + graphics2d/src/test/resources/de/rototor/pdfbox/graphics2d/strokeRotation.svg
- pom.xml


Changes:

=====================================
README.md
=====================================
@@ -1,5 +1,6 @@
 [![Java CI with Maven](https://github.com/rototor/pdfbox-graphics2d/actions/workflows/maven.yml/badge.svg)](https://github.com/rototor/pdfbox-graphics2d/actions/workflows/maven.yml)
 [![CodeQL](https://github.com/rototor/pdfbox-graphics2d/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/rototor/pdfbox-graphics2d/actions/workflows/codeql-analysis.yml)
+
 # pdfbox-graphics2d
 
 Graphics2D Bridge for Apache PDFBox
@@ -51,7 +52,7 @@ This library is available through Maven:
 <dependency>
 	<groupId>de.rototor.pdfbox</groupId>
 	<artifactId>graphics2d</artifactId>
-	<version>0.35</version>
+	<version>0.38</version>
 </dependency>
 ```
 
@@ -321,6 +322,23 @@ graphs
 
 ## Changes
 
+Version 0.38:
+- Fix for line width of stroks in the case there is a rotation transform on the Graphics2D. Thanks @jonmccracken-wf for 
+  reporting and fixing this bug ([#36](https://github.com/rototor/pdfbox-graphics2d/pull/36))
+- Upgrade to PDFBox 2.0.26
+
+Version 0.37:
+
+- Make PdfBoxGraphics2DFontTextDrawer.getFontMetrics::stringWidth() behave like the
+  JDK. Thanks @Lorgod ([#35](https://github.com/rototor/pdfbox-graphics2d/issues/35))
+
+Version 0.36:
+
+- API breakage: Changed the `IPdfBoxGraphics2DColorMapper::mapColor()` signatur to get a
+  IColorMapperEnv instead of a
+  PDPageContentStream. The env provides access to the `PDPageContentStream` and the `PDResources`
+- It is now possible to get the associated PDResources by using `PdfBoxGraphics2D::getResources()`.
+
 Version 0.35:
 
 - Temporary workaround for [PDFBOX-5361](https://issues.apache.org/jira/browse/PDFBOX-5361). PDFBOX
@@ -371,7 +389,7 @@ Version 0.30:
 - Added a new module for extended-tests. This module will contain tests with 3rdparty library which
   by themself depend
   on pdfbox-graphics2d. It also now contains a new class DebugCodeGeneratingGraphics2d
-  (by @kiwiwings) which helps creating isolated testcases.
+  (by @kiwiwings) which helps to create isolated testcases.
 - Upgrade to PDFBox 2.0.22
 
 Version 0.29:
@@ -551,7 +569,7 @@ Version 0.4:
 - Initial support for basic ```AlphaComposite```. Thanks
   @FabioVassallo [#1](https://github.com/rototor/pdfbox-graphics2d/pull/1)
 - When drawing a shape with a zero or negative size don't use ```PDShadings```, as they won't
-  work.Thanks
+  work. Thanks
   @FabioVassallo [#1](https://github.com/rototor/pdfbox-graphics2d/pull/1)
 
 Version 0.3:


=====================================
extended-tests/pom.xml
=====================================
@@ -10,14 +10,14 @@
 	<parent>
 		<groupId>de.rototor.pdfbox</groupId>
 		<artifactId>pdfboxgraphics2d-parent</artifactId>
-		<version>0.35</version>
+		<version>0.38</version>
 	</parent>
 
 	<dependencies>
 		<dependency>
 			<groupId>de.rototor.pdfbox</groupId>
 			<artifactId>graphics2d</artifactId>
-			<version>0.35</version>
+			<version>0.38</version>
 		</dependency>
 
 		<dependency>


=====================================
graphics2d/pom.xml
=====================================
@@ -10,7 +10,7 @@
 	<parent>
 		<groupId>de.rototor.pdfbox</groupId>
 		<artifactId>pdfboxgraphics2d-parent</artifactId>
-		<version>0.35</version>
+		<version>0.38</version>
 	</parent>
 
 


=====================================
graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/IPdfBoxGraphics2DColorMapper.java
=====================================
@@ -15,11 +15,12 @@
  */
 package de.rototor.pdfbox.graphics2d;
 
+import java.awt.*;
+
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 
-import java.awt.*;
-
 /**
  * Map Color to PDColor
  */
@@ -27,11 +28,27 @@ public interface IPdfBoxGraphics2DColorMapper {
 	/**
 	 * Map the given Color to a PDColor
 	 * 
-	 * @param contentStream
-	 *            the content stream
 	 * @param color
 	 *            the color to map
+	 * @param env
+	 *            the environment which allow getting the content stream, resources
+	 *            etc.
 	 * @return the mapped color
 	 */
-	PDColor mapColor(PDPageContentStream contentStream, Color color);
+	PDColor mapColor(Color color, IColorMapperEnv env);
+
+	/**
+	 * Environment to use for mapping the given color
+	 */
+	interface IColorMapperEnv {
+		/**
+		 * @return the content stream
+		 */
+		PDPageContentStream getContentStream();
+
+		/**
+		 * @return the resources of the resulting XFOrm
+		 */
+		PDResources getResources();
+	}
 }


=====================================
graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2D.java
=====================================
@@ -15,6 +15,7 @@
  */
 package de.rototor.pdfbox.graphics2d;
 
+import de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DColorMapper.IColorMapperEnv;
 import de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DDrawControl.IDrawControlEnv;
 import de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DFontTextDrawer.IFontTextDrawerEnv;
 import de.rototor.pdfbox.graphics2d.IPdfBoxGraphics2DPaintApplier.IPaintEnv;
@@ -48,6 +49,7 @@ import java.awt.geom.Ellipse2D;
 import java.awt.geom.Line2D;
 import java.awt.geom.NoninvertibleTransformException;
 import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
 import java.awt.geom.PathIterator;
 import java.awt.geom.Rectangle2D;
 import java.awt.geom.RoundRectangle2D;
@@ -106,7 +108,7 @@ public class PdfBoxGraphics2D extends Graphics2D
     /**
      * Set a new image encoder
      *
-     * @param imageEncoder the image encoder, which encodes a image as PDImageXForm.
+     * @param imageEncoder the image encoder, which encodes an image as PDImageXForm.
      */
     @SuppressWarnings({ "unused" })
     public void setImageEncoder(IPdfBoxGraphics2DImageEncoder imageEncoder)
@@ -119,7 +121,7 @@ public class PdfBoxGraphics2D extends Graphics2D
      * from the {@link IPdfBoxGraphics2DPaintApplier} and just extend the paint
      * mapping for custom paint.
      * <p>
-     * If the paint you map is a paint from a standard library and you can implement
+     * If the paint you map is a paint from a standard library, and you can implement
      * the mapping using reflection please feel free to send a pull request to
      * extend the default paint mapper.
      *
@@ -269,9 +271,26 @@ public class PdfBoxGraphics2D extends Graphics2D
 
     }
 
-    /**
-     * @return the PDAppearanceStream which resulted in this graphics
-     */
+	/**
+	 * Sometimes you need to access the PDResources and add special resources to it
+	 * for some stuff (e.g. patterns of embedded PDFs or simmilar). For that you
+	 * need the PDResources associated with the XForm.
+	 *
+	 * It's identlical with getXFormObject().getResources(), with the difference
+	 * beeing that you can access it while the Graphics2D is not yet disposed.
+	 *
+	 * @return the PDResources of the resulting XForm
+	 */
+    public PDResources getResources()
+	{
+        return xFormObject.getResources();
+    }
+
+	/**
+	 * *AFTER* you have disposed() this Graphics2D you can access the XForm
+	 *
+	 * @return the PDFormXObject which resulted in this graphics
+	 */
     @SuppressWarnings("WeakerAccess")
     public PDFormXObject getXFormObject()
     {
@@ -481,7 +500,7 @@ public class PdfBoxGraphics2D extends Graphics2D
     }
 
     /**
-     * Interal debugflag to see if a unkown stroke is mapped
+     * Interal debugflag to see if an unkown stroke is mapped
      */
     private final static boolean ENABLE_DEBUG_UNKOWN_STROKE = false;
 
@@ -512,16 +531,18 @@ public class PdfBoxGraphics2D extends Graphics2D
             }
 
             AffineTransform tf = getCurrentEffectiveTransform();
+            float lineWidth = calculateTransformedLength(basicStroke.getLineWidth(), tf);
+
+            contentStream.setLineWidth(lineWidth);
 
-            double scaleX = tf.getScaleX();
-            contentStream.setLineWidth((float) Math.abs(basicStroke.getLineWidth() * scaleX));
             float[] dashArray = basicStroke.getDashArray();
             if (dashArray != null)
             {
                 for (int i = 0; i < dashArray.length; i++)
-                    dashArray[i] = (float) Math.abs(dashArray[i] * scaleX);
+                    dashArray[i] = calculateTransformedLength(dashArray[i], tf);
+
                 contentStream.setLineDashPattern(dashArray,
-                        (float) Math.abs(basicStroke.getDashPhase() * scaleX));
+                    calculateTransformedLength(basicStroke.getDashPhase(), tf));
             }
         }
         else if (strokeToApply != null)
@@ -531,6 +552,15 @@ public class PdfBoxGraphics2D extends Graphics2D
         }
     }
 
+    private float calculateTransformedLength(float length, AffineTransform tf) {
+        // Represent stroke width as a horizontal line from origin to basicStroke.LineWidth.
+        Point2D.Float lengthVector = new Point2D.Float(length, 0);
+        // Apply the current transform to the horizontal line.
+        tf.deltaTransform(lengthVector, lengthVector);
+        // Calculate the length of the transformed line. This is the new, adjusted length.
+        return (float) Math.sqrt(lengthVector.x * lengthVector.x + lengthVector.y * lengthVector.y);
+    }
+
     private AffineTransform getCurrentEffectiveTransform()
     {
         AffineTransform tf = new AffineTransform();
@@ -604,7 +634,7 @@ public class PdfBoxGraphics2D extends Graphics2D
         {
             if (bgcolor != null)
             {
-                contentStream.setNonStrokingColor(colorMapper.mapColor(contentStream, bgcolor));
+                contentStream.setNonStrokingColor(colorMapper.mapColor(bgcolor, colorMapperEnv));
                 walkShape(new Rectangle(x, y, width, height));
                 contentStream.fill();
             }
@@ -683,7 +713,7 @@ public class PdfBoxGraphics2D extends Graphics2D
              */
             if (bgcolor != null)
             {
-                contentStream.setNonStrokingColor(colorMapper.mapColor(contentStream, bgcolor));
+                contentStream.setNonStrokingColor(colorMapper.mapColor( bgcolor, colorMapperEnv));
                 walkShape(new Rectangle(dx1, dy1, width, height));
                 contentStream.fill();
             }
@@ -991,6 +1021,17 @@ public class PdfBoxGraphics2D extends Graphics2D
     }
 
     private final PaintEnvImpl paintEnv = new PaintEnvImpl();
+    final IColorMapperEnv colorMapperEnv = new IColorMapperEnv() {
+        @Override
+        public PDPageContentStream getContentStream() {
+            return contentStream;
+        }
+
+        @Override
+        public PDResources getResources() {
+            return PdfBoxGraphics2D.this.getResources();
+        }
+    };
 
     private static class PaintApplyResult
     {
@@ -1326,7 +1367,7 @@ public class PdfBoxGraphics2D extends Graphics2D
      * closed?
      * <p>
      * We need this flag to avoid to clip twice if both the plaint applyer needs to
-     * clip and we have some clipping. If at the end we try to clip with an empty
+     * clip, and we have some clipping. If at the end we try to clip with an empty
      * path, then Acrobat Reader does not like that and draws nothing.
      */
     private boolean hasPathOnStream = false;


=====================================
graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DColorMapper.java
=====================================
@@ -15,16 +15,15 @@
  */
 package de.rototor.pdfbox.graphics2d;
 
-import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import java.awt.*;
+
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 
-import java.awt.*;
-
 public class PdfBoxGraphics2DColorMapper implements IPdfBoxGraphics2DColorMapper {
 	@Override
-	public PDColor mapColor(PDPageContentStream contentStream, Color color) {
+	public PDColor mapColor(Color color, IColorMapperEnv env) {
 		if (color == null)
 			return new PDColor(new float[] { 1f, 1f, 1f }, PDDeviceRGB.INSTANCE);
 
@@ -36,7 +35,7 @@ public class PdfBoxGraphics2DColorMapper implements IPdfBoxGraphics2DColorMapper
 			float k = PdfBoxGraphics2DPaintApplier.getPropertyValue(color, "getBlack");
 			return new PDColor(new float[] { c, m, y, k }, PDDeviceCMYK.INSTANCE);
 		}
-		
+
 		// Our universial color carrier.
 		if (color instanceof IPdfBoxGraphics2DColor)
 			return ((IPdfBoxGraphics2DColor) color).toPDColor();


=====================================
graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DFontTextDrawer.java
=====================================
@@ -524,7 +524,8 @@ public class PdfBoxGraphics2DFontTextDrawer implements IPdfBoxGraphics2DFontText
             {
                 try
                 {
-                    return (int) (pdFont.getStringWidth(str) / 1000 * f.getSize2D());
+                    float width = pdFont.getStringWidth(str) / 1000 * f.getSize2D();
+                    return (int) (width + .5f);
                 }
                 catch (IOException e)
                 {


=====================================
graphics2d/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java
=====================================
@@ -56,6 +56,7 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
         protected Composite composite;
         private COSDictionary dictExtendedState;
         private IPaintEnv env;
+        private IPdfBoxGraphics2DColorMapper.IColorMapperEnv colorMapperEnv;
         public AffineTransform tf;
         /**
          * This transform is only set, when we apply a nested
@@ -91,6 +92,7 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
         state.composite = env.getComposite();
         state.pdExtendedGraphicsState = null;
         state.env = env;
+        state.colorMapperEnv = env.getGraphics2D().colorMapperEnv;;
         state.tf = tf;
         state.nestedTransform = null;
         PDShading shading = applyPaint(paint, state);
@@ -105,8 +107,8 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
     {
         PDPageContentStream contentStream = state.contentStream;
         IPdfBoxGraphics2DColorMapper colorMapper = state.colorMapper;
-        contentStream.setStrokingColor(colorMapper.mapColor(contentStream, color));
-        contentStream.setNonStrokingColor(colorMapper.mapColor(contentStream, color));
+		contentStream.setStrokingColor(colorMapper.mapColor(color, state.colorMapperEnv));
+		contentStream.setNonStrokingColor(colorMapper.mapColor(color, state.colorMapperEnv));
 
         int alpha = color.getAlpha();
         if (alpha < 255)
@@ -533,7 +535,7 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
         PDShadingType3 shading = new PDShadingType3(new COSDictionary());
         Color[] colors = getPropertyValue(paint, "getColors");
         Color firstColor = colors[0];
-        PDColor firstColorMapped = state.colorMapper.mapColor(state.contentStream, firstColor);
+		PDColor firstColorMapped = state.colorMapper.mapColor(firstColor, state.colorMapperEnv);
         applyAsStrokingColor(firstColor, state);
         float[] fractions = getPropertyValue(paint, "getFractions");
         PDFunctionType3 type3 = buildType3Function(colors, fractions, state);
@@ -639,7 +641,7 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
          */
         Color[] colors = getPropertyValue(paint, "getColors");
         Color firstColor = colors[0];
-        PDColor firstColorMapped = state.colorMapper.mapColor(state.contentStream, firstColor);
+		PDColor firstColorMapped = state.colorMapper.mapColor(firstColor, state.colorMapperEnv);
         applyAsStrokingColor(firstColor, state);
 
         /*
@@ -684,7 +686,7 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
     {
         Color[] colors = new Color[] { gradientPaint.getColor1(), gradientPaint.getColor2() };
         Color firstColor = colors[0];
-        PDColor firstColorMapped = state.colorMapper.mapColor(state.contentStream, firstColor);
+		PDColor firstColorMapped = state.colorMapper.mapColor(firstColor, state.colorMapperEnv);
         applyAsStrokingColor(firstColor, state);
 
         /*
@@ -840,8 +842,8 @@ public class PdfBoxGraphics2DPaintApplier implements IPdfBoxGraphics2DPaintAppli
         for (int i = 1; i < colors.size(); i++)
         {
             Color color = colors.get(i);
-            PDColor prevPdColor = state.colorMapper.mapColor(state.contentStream, prevColor);
-            PDColor pdColor = state.colorMapper.mapColor(state.contentStream, color);
+			PDColor prevPdColor = state.colorMapper.mapColor(prevColor, state.colorMapperEnv);
+			PDColor pdColor = state.colorMapper.mapColor(color, state.colorMapperEnv);
             COSArray c0 = new COSArray();
             COSArray c1 = new COSArray();
             for (float component : prevPdColor.getComponents())


=====================================
graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2dTest.java
=====================================
@@ -15,10 +15,6 @@
  */
 package de.rototor.pdfbox.graphics2d;
 
-import org.junit.Test;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
 import java.awt.*;
 import java.awt.font.TextAttribute;
 import java.awt.geom.*;
@@ -27,6 +23,11 @@ import java.io.IOException;
 import java.text.AttributedString;
 import java.util.Iterator;
 
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+
+import org.junit.Test;
+
 public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
 {
 
@@ -140,7 +141,7 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
             {
                 Font sansSerif = new Font(Font.SANS_SERIF, Font.PLAIN, 15);
                 Font embeddedFont = Font.createFont(Font.TRUETYPE_FONT,
-                        PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
+                                PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
                         .deriveFont(15f);
                 Font monoFont = Font.decode(Font.MONOSPACED).deriveFont(15f);
                 Font serifFont = Font.decode(Font.SERIF).deriveFont(15f);
@@ -191,16 +192,16 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
             @Override
             public void draw(Graphics2D gfx) throws IOException
             {
-                BufferedImage img2 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("pixeltest.png"));
-                BufferedImage img3 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
-                BufferedImage img4 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("Italy-P3.jpg"));
-                BufferedImage img5 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("16bit-image1.png"));
-                BufferedImage img6 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("16bit-image2.png"));
+                BufferedImage img2 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("pixeltest.png"));
+                BufferedImage img3 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
+                BufferedImage img4 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("Italy-P3.jpg"));
+                BufferedImage img5 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("16bit-image1.png"));
+                BufferedImage img6 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("16bit-image2.png"));
 
                 gfx.drawImage(img2, 70, 50, 100, 50, null);
                 gfx.drawImage(img3, 30, 200, 75, 50, null);
@@ -220,8 +221,8 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
             @Override
             public void draw(Graphics2D gfx) throws IOException
             {
-                BufferedImage img3 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
+                BufferedImage img3 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
                 gfx.setColor(new Color(128, 128, 255, 58));
                 gfx.drawImage(img3, 30, 10, 75, 50, null);
                 gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
@@ -275,14 +276,14 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
             @Override
             public void draw(Graphics2D gfx) throws IOException, FontFormatException
             {
-                BufferedImage imgColorTest = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("colortest.png"));
-                BufferedImage img2 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("pixeltest.png"));
-                BufferedImage img3 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
-                BufferedImage img4 = ImageIO
-                        .read(PdfBoxGraphics2dTest.class.getResourceAsStream("Italy-P3.jpg"));
+                BufferedImage imgColorTest = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("colortest.png"));
+                BufferedImage img2 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("pixeltest.png"));
+                BufferedImage img3 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("Rose-ProPhoto.jpg"));
+                BufferedImage img4 = ImageIO.read(
+                        PdfBoxGraphics2dTest.class.getResourceAsStream("Italy-P3.jpg"));
 
                 gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BICUBIC);
@@ -305,7 +306,7 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
 
                 Font font = new Font("SansSerif", Font.PLAIN, 30);
                 Font font2 = Font.createFont(Font.TRUETYPE_FONT,
-                        PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
+                                PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
                         .deriveFont(20f);
                 final String words = "Valour fate kinship darkness";
 
@@ -348,4 +349,67 @@ public class PdfBoxGraphics2dTest extends PdfBoxGraphics2DTestBase
         });
     }
 
+    private static final Color[] debugColors = new Color[] { new Color(0xE0C995), //
+            new Color(0xC1E4EA), //
+            new Color(0x8BC0FF), //
+            new Color(0xC5F5B7), //
+            new Color(0xF5B7D8), //
+            new Color(0xa5B7B7), //
+            new Color(0xF5EDB7), //
+            new Color(0xF5D6B7), //
+    };
+
+    @Test
+    public void testStringWidth()
+    {
+        exportGraphic("simple", "stringWidth", new GraphicsExporter()
+        {
+            @Override
+            public void draw(Graphics2D gfx) throws IOException, FontFormatException
+            {
+                Font font2 = Font.createFont(Font.TRUETYPE_FONT,
+                                PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
+                        .deriveFont(20f);
+
+                gfx.setFont(font2);
+                String myTestString = "This is my funny test string...";
+                int x = 20;
+                int y = 40;
+                FontMetrics fontMetrics = gfx.getFontMetrics();
+                gfx.setColor(new Color(0x66AAAAEE));
+                gfx.fillRect(x, y, fontMetrics.stringWidth(myTestString), fontMetrics.getHeight());
+
+                gfx.setColor(Color.GREEN);
+                gfx.drawString(myTestString, 20, 40);
+                for (int i = 0; i < myTestString.length(); i++)
+                {
+                    int w = fontMetrics.charWidth(myTestString.charAt(i));
+                    gfx.setColor(debugColors[i % debugColors.length]);
+                    gfx.drawRect(x, y, w, fontMetrics.getHeight());
+                    x += w;
+                }
+            }
+        });
+    }
+
+	@Test
+	public void testLineWithRotation() {
+		exportGraphic("simple", "lineWithRotation", new GraphicsExporter() {
+			@Override
+			public void draw(Graphics2D gfx) {
+				gfx.setStroke(new BasicStroke(5f));
+
+				float centerX = 200;
+				float centerY = 200;
+
+				gfx.translate(centerX, centerY);
+				for (int i = 0; i < 360; i += 10) {
+					gfx.rotate(10 / 360f * Math.PI * 2);
+					gfx.setColor(debugColors[(i / 10) % debugColors.length]);
+					gfx.draw(new Line2D.Double(0, 0, 50, 0));
+				}
+			}
+		});
+	}
+
 }


=====================================
graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/RenderSVGsTest.java
=====================================
@@ -38,6 +38,13 @@ public class RenderSVGsTest extends PdfBoxGraphics2DTestBase
         renderSVG("watermark.svg", 0.4);
     }
 
+    @Test
+    public void testRotatedStrokes() throws IOException
+    {
+        renderSVG("strokeRotation.svg", 0.55);
+        renderSVG("dashedStrokeRotation.svg", 0.55);
+    }
+
     @Test
     public void renderFailureCases() throws IOException
     {


=====================================
graphics2d/src/test/java/de/rototor/pdfbox/graphics2d/SpecialColorsTest.java
=====================================
@@ -1,5 +1,8 @@
 package de.rototor.pdfbox.graphics2d;
 
+import java.io.File;
+import java.io.IOException;
+
 import org.apache.pdfbox.cos.*;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
@@ -13,9 +16,6 @@ import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.util.Matrix;
 import org.junit.Test;
 
-import java.io.File;
-import java.io.IOException;
-
 /**
  * Generates some PDFs with a special color scodix. In one PDF the painted
  * rectangle is not visible, because its complete clipped out. What is this good
@@ -75,13 +75,22 @@ public class SpecialColorsTest {
 
 		final PDSeparation scodix = getScodixSeperationColor();
 		pdfBoxGraphics2D.setColor(new PdfBoxGraphics2DColor(new PDColor(new float[] { 1 }, scodix), 255, true));
-		pdfBoxGraphics2D.fillRoundRect(10, 10, 100, 100, 20, 20);
+		pdfBoxGraphics2D.fillRoundRect(10, 10, 300, 300, 20, 20);
 
 		pdfBoxGraphics2D.dispose();
 
 		PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
 		Matrix matrix = new Matrix();
-		matrix.translate(0, 20);
+		matrix.translate(0, 210);
+		contentStream.transform(matrix);
+		contentStream.drawForm(appearanceStream);
+		matrix = new Matrix();
+		matrix.translate(150, 210);
+		contentStream.transform(matrix);
+		contentStream.drawForm(appearanceStream);
+		matrix = new Matrix();
+		matrix.translate(180, -220);
+		matrix.scale(0.5f, 0.5f);
 		contentStream.transform(matrix);
 		contentStream.drawForm(appearanceStream);
 		contentStream.close();


=====================================
graphics2d/src/test/resources/de/rototor/pdfbox/graphics2d/dashedStrokeRotation.svg
=====================================
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="" width="613" height="380" viewBox="0 0 613 380">
+  <g data-z-index="3">
+    <g data-z-index="4" transform="translate(598,258) rotate(90) scale(-1,1) scale(1 1)">
+      <rect x="166.56666666667002" y="220" width="21" height="156" fill="#9bda44" stroke="#000000" stroke-width="10" stroke-dasharray="80,30,10,30,10,30"/>
+    </g>
+  </g>
+</svg>


=====================================
graphics2d/src/test/resources/de/rototor/pdfbox/graphics2d/strokeRotation.svg
=====================================
@@ -0,0 +1,128 @@
+<?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">
+<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" width="613" zoomAndPan="magnify" style="" contentStyleType="text/css" viewBox="0 0 613 380" height="380" preserveAspectRatio="xMidYMid meet" version="1.1">
+  <g data-z-index="2">
+    <svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" style="overflow: visible;" elementId="3" data-z-index="7" version="1.0" width="1" preserveAspectRatio="xMidYMid meet" viewBox="0 0 75 75" height="1">
+      <g transform="translate(15000,15000)">
+        <g>
+          <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+        </g>
+        <g transform="rotate(15, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(30, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(45, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(60, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(75, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(90, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(105, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(120, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(135, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(150, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(165, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(180, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(195, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(210, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(225, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(240, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(255, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(270, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(285, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(300, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(315, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(330, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+        <g transform="rotate(345, 0, 0)">
+          <g>
+            <path stroke-width="500" d="M0 336 H12800" class="underline" stroke="#595959"/>
+          </g>
+        </g>
+      </g>
+    </svg>
+  </g>
+</svg>


=====================================
pom.xml
=====================================
@@ -6,7 +6,7 @@
 	<description>Graphics2D Bridge for Apache PDFBox</description>
 	<groupId>de.rototor.pdfbox</groupId>
 	<artifactId>pdfboxgraphics2d-parent</artifactId>
-	<version>0.35</version>
+	<version>0.38</version>
   	<packaging>pom</packaging>
 	<url>https://github.com/rototor/pdfbox-graphics2d</url>
 
@@ -41,7 +41,7 @@
 	<scm>
 		<url>https://github.com/rototor/pdfbox-graphics2d</url>
 		<connection>scm:git:https://github.com/rototor/pdfbox-graphics2d.git</connection>
-		<tag>pdfboxgraphics2d-parent-0.35</tag>
+		<tag>pdfboxgraphics2d-parent-0.38</tag>
 	</scm>
 
 	<distributionManagement>
@@ -59,7 +59,7 @@
 		<dependency>
 			<groupId>org.apache.pdfbox</groupId>
 			<artifactId>pdfbox</artifactId>
-			<version>2.0.25</version>
+			<version>2.0.26</version>
 		</dependency>
 		<dependency>
 			<groupId>junit</groupId>
@@ -78,13 +78,13 @@
 		<dependency>
 			<groupId>org.apache.xmlgraphics</groupId>
 			<artifactId>xmlgraphics-commons</artifactId>
-			<version>2.6</version>
+			<version>2.7</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
 			<groupId>com.twelvemonkeys.imageio</groupId>
 			<artifactId>imageio-jpeg</artifactId>
-			<version>3.6.4</version>
+			<version>3.8.2</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>



View it on GitLab: https://salsa.debian.org/java-team/libpdfbox-graphics2d-java/-/commit/e059c70e998de9dd2405ad217ce681c273ee7650

-- 
View it on GitLab: https://salsa.debian.org/java-team/libpdfbox-graphics2d-java/-/commit/e059c70e998de9dd2405ad217ce681c273ee7650
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20220530/620732b8/attachment-0001.htm>


More information about the debian-med-commit mailing list