@@ -202,6 +202,8 @@ public class PdfCanvas {
202
202
203
203
private static readonly PdfSpecialCs . Pattern pattern = new PdfSpecialCs . Pattern ( ) ;
204
204
205
+ private const float IDENTITY_MATRIX_EPS = 1e-4f ;
206
+
205
207
/// <summary>a LIFO stack of graphics state saved states.</summary>
206
208
protected internal Stack < CanvasGraphicsState > gsStack = new Stack < CanvasGraphicsState > ( ) ;
207
209
@@ -1820,6 +1822,10 @@ public virtual PdfXObject AddImage(ImageData image, iText.Kernel.Geom.Rectangle
1820
1822
/// <param name="asInline">true if to add image as in-line</param>
1821
1823
/// <returns>the created imageXObject or null in case of in-line image (asInline = true)</returns>
1822
1824
/// <seealso cref="ConcatMatrix(double, double, double, double, double, double)"/>
1825
+ /// <seealso cref="iText.Kernel.Pdf.Xobject.PdfXObject.CalculateProportionallyFitRectangleWithWidth(iText.Kernel.Pdf.Xobject.PdfXObject, float, float, float)
1826
+ /// "/>
1827
+ /// <seealso cref="iText.Kernel.Pdf.Xobject.PdfXObject.CalculateProportionallyFitRectangleWithHeight(iText.Kernel.Pdf.Xobject.PdfXObject, float, float, float)
1828
+ /// "/>
1823
1829
public virtual PdfXObject AddImageFittedIntoRectangle ( ImageData image , iText . Kernel . Geom . Rectangle rect , bool
1824
1830
asInline ) {
1825
1831
return AddImageWithTransformationMatrix ( image , rect . GetWidth ( ) , 0 , 0 , rect . GetHeight ( ) , rect . GetX ( ) , rect .
@@ -1992,7 +1998,7 @@ public virtual PdfXObject AddImage(ImageData image, float x, float y, float heig
1992
1998
public virtual iText . Kernel . Pdf . Canvas . PdfCanvas AddXObjectWithTransformationMatrix ( PdfXObject xObject , float
1993
1999
a , float b , float c , float d , float e , float f ) {
1994
2000
if ( xObject is PdfFormXObject ) {
1995
- return AddFormWithTransformationMatrix ( ( PdfFormXObject ) xObject , a , b , c , d , e , f ) ;
2001
+ return AddFormWithTransformationMatrix ( ( PdfFormXObject ) xObject , a , b , c , d , e , f , true ) ;
1996
2002
}
1997
2003
else {
1998
2004
if ( xObject is PdfImageXObject ) {
@@ -2093,6 +2099,10 @@ public virtual iText.Kernel.Pdf.Canvas.PdfCanvas AddXObject(PdfXObject xObject,
2093
2099
/// <param name="xObject">the xObject to add</param>
2094
2100
/// <param name="rect">the rectangle in which the xObject will be fitted</param>
2095
2101
/// <returns>the current canvas</returns>
2102
+ /// <seealso cref="iText.Kernel.Pdf.Xobject.PdfXObject.CalculateProportionallyFitRectangleWithWidth(iText.Kernel.Pdf.Xobject.PdfXObject, float, float, float)
2103
+ /// "/>
2104
+ /// <seealso cref="iText.Kernel.Pdf.Xobject.PdfXObject.CalculateProportionallyFitRectangleWithHeight(iText.Kernel.Pdf.Xobject.PdfXObject, float, float, float)
2105
+ /// "/>
2096
2106
public virtual iText . Kernel . Pdf . Canvas . PdfCanvas AddXObjectFittedIntoRectangle ( PdfXObject xObject , iText . Kernel . Geom . Rectangle
2097
2107
rect ) {
2098
2108
if ( xObject is PdfFormXObject ) {
@@ -2278,7 +2288,7 @@ public virtual iText.Kernel.Pdf.Canvas.PdfCanvas AddXObject(PdfXObject xObject,
2278
2288
/// <returns>the current canvas</returns>
2279
2289
public virtual iText . Kernel . Pdf . Canvas . PdfCanvas AddXObject ( PdfXObject xObject ) {
2280
2290
if ( xObject is PdfFormXObject ) {
2281
- return AddFormWithTransformationMatrix ( ( PdfFormXObject ) xObject , 1 , 0 , 0 , 1 , 0 , 0 ) ;
2291
+ return AddFormWithTransformationMatrix ( ( PdfFormXObject ) xObject , 1 , 0 , 0 , 1 , 0 , 0 , false ) ;
2282
2292
}
2283
2293
else {
2284
2294
if ( xObject is PdfImageXObject ) {
@@ -2499,11 +2509,17 @@ protected internal virtual void AddInlineImage(PdfImageXObject imageXObject, flo
2499
2509
/// <param name="d">an element of the transformation matrix</param>
2500
2510
/// <param name="e">an element of the transformation matrix</param>
2501
2511
/// <param name="f">an element of the transformation matrix</param>
2512
+ /// <param name="writeIdentityMatrix">
2513
+ /// true if the matrix is written in any case, otherwise if the
2514
+ /// <see cref="IsIdentityMatrix(float, float, float, float, float, float)"/>
2515
+ /// method indicates
2516
+ /// that the matrix is identity, the matrix will not be written
2517
+ /// </param>
2502
2518
/// <returns>current canvas</returns>
2503
2519
private iText . Kernel . Pdf . Canvas . PdfCanvas AddFormWithTransformationMatrix ( PdfFormXObject form , float a , float
2504
- b , float c , float d , float e , float f ) {
2520
+ b , float c , float d , float e , float f , bool writeIdentityMatrix ) {
2505
2521
SaveState ( ) ;
2506
- if ( ! iText . Kernel . Pdf . Canvas . PdfCanvas . IsIdentityMatrix ( a , b , c , d , e , f ) ) {
2522
+ if ( writeIdentityMatrix || ! iText . Kernel . Pdf . Canvas . PdfCanvas . IsIdentityMatrix ( a , b , c , d , e , f ) ) {
2507
2523
ConcatMatrix ( a , b , c , d , e , f ) ;
2508
2524
}
2509
2525
PdfName name = resources . AddForm ( form ) ;
@@ -2525,7 +2541,7 @@ private iText.Kernel.Pdf.Canvas.PdfCanvas AddFormWithTransformationMatrix(PdfFor
2525
2541
/// <param name="e">an element of the transformation matrix</param>
2526
2542
/// <param name="f">an element of the transformation matrix</param>
2527
2543
/// <returns>current canvas</returns>
2528
- [ System . ObsoleteAttribute ( @"will be removed in 7.2, useAddFormWithTransformationMatrix(iText.Kernel.Pdf.Xobject.PdfFormXObject, float, float, float, float, float, float) instead"
2544
+ [ System . ObsoleteAttribute ( @"will be removed in 7.2, useAddFormWithTransformationMatrix(iText.Kernel.Pdf.Xobject.PdfFormXObject, float, float, float, float, float, float, bool ) instead"
2529
2545
) ]
2530
2546
private iText . Kernel . Pdf . Canvas . PdfCanvas AddForm ( PdfFormXObject form , float a , float b , float c , float d ,
2531
2547
float e , float f ) {
@@ -2556,7 +2572,7 @@ private iText.Kernel.Pdf.Canvas.PdfCanvas AddFormAt(PdfFormXObject form, float x
2556
2572
float [ ] result = iText . Kernel . Pdf . Canvas . PdfCanvas . CalculateTransformationMatrix ( rectMin , rectMax , bBoxMin
2557
2573
, bBoxMax ) ;
2558
2574
return AddFormWithTransformationMatrix ( form , result [ 0 ] , result [ 1 ] , result [ 2 ] , result [ 3 ] , result [ 4 ] , result
2559
- [ 5 ] ) ;
2575
+ [ 5 ] , false ) ;
2560
2576
}
2561
2577
2562
2578
/// <summary>
@@ -2641,7 +2657,7 @@ private iText.Kernel.Pdf.Canvas.PdfCanvas AddFormFittedIntoRectangle(PdfFormXObj
2641
2657
float [ ] result = iText . Kernel . Pdf . Canvas . PdfCanvas . CalculateTransformationMatrix ( rectMin , rectMax , bBoxMin
2642
2658
, bBoxMax ) ;
2643
2659
return AddFormWithTransformationMatrix ( form , result [ 0 ] , result [ 1 ] , result [ 2 ] , result [ 3 ] , result [ 4 ] , result
2644
- [ 5 ] ) ;
2660
+ [ 5 ] , false ) ;
2645
2661
}
2646
2662
2647
2663
/// <summary>
@@ -2829,9 +2845,8 @@ private static float[] CalculateTransformationMatrix(Vector expectedMin, Vector
2829
2845
}
2830
2846
2831
2847
private static bool IsIdentityMatrix ( float a , float b , float c , float d , float e , float f ) {
2832
- return JavaUtil . FloatCompare ( a , 1 ) == 0 && JavaUtil . FloatCompare ( b , 0 ) == 0 && JavaUtil . FloatCompare ( c , 0 )
2833
- == 0 && JavaUtil . FloatCompare ( d , 1 ) == 0 && JavaUtil . FloatCompare ( e , 0 ) == 0 && JavaUtil . FloatCompare
2834
- ( f , 0 ) == 0 ;
2848
+ return Math . Abs ( 1 - a ) < IDENTITY_MATRIX_EPS && Math . Abs ( b ) < IDENTITY_MATRIX_EPS && Math . Abs ( c ) < IDENTITY_MATRIX_EPS
2849
+ && Math . Abs ( 1 - d ) < IDENTITY_MATRIX_EPS && Math . Abs ( e ) < IDENTITY_MATRIX_EPS && Math . Abs ( f ) < IDENTITY_MATRIX_EPS ;
2835
2850
}
2836
2851
}
2837
2852
}
0 commit comments