Example #1
0
 public virtual void ReleaseGraphicsState()
 {
     if (!graphicsStateIsPreserved)
     {
         gs = null;
     }
 }
Example #2
0
 /// <param name="path">The path to be rendered.</param>
 /// <param name="operation">
 /// One of the possible combinations of
 /// <see cref="STROKE"/>
 /// and
 /// <see cref="FILL"/>
 /// values or
 /// <see cref="NO_OP"/>
 /// </param>
 /// <param name="rule">
 /// Either
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// or
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.EVEN_ODD"/>
 /// .
 /// </param>
 /// <param name="isClip">True indicates that current path modifies the clipping path, false - if not.</param>
 /// <param name="clipRule">
 /// Either
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// or
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.EVEN_ODD"/>
 /// .
 /// </param>
 /// <param name="gs">The graphics state.</param>
 public PathRenderInfo(Path path, int operation, int rule, bool isClip, int clipRule, CanvasGraphicsState gs
                       )
 {
     this.path         = path;
     this.operation    = operation;
     this.rule         = rule;
     this.gs           = gs;
     this.isClip       = isClip;
     this.clippingRule = clipRule;
 }
Example #3
0
 /// <summary>Creates a new TextRenderInfo object</summary>
 /// <param name="str">the PDF string that should be displayed</param>
 /// <param name="gs">the graphics state (note: at this time, this is not immutable, so don't cache it)</param>
 /// <param name="textMatrix">the text matrix at the time of the render operation</param>
 /// <param name="canvasTagHierarchy">the marked content tags sequence, if available</param>
 public TextRenderInfo(PdfString str, CanvasGraphicsState gs, Matrix textMatrix, Stack <CanvasTag> canvasTagHierarchy
                       )
 {
     this.@string = str;
     this.textToUserSpaceTransformMatrix = textMatrix.Multiply(gs.GetCtm());
     this.gs = gs;
     this.canvasTagHierarchy = JavaCollectionsUtil.UnmodifiableList <CanvasTag>(new List <CanvasTag>(canvasTagHierarchy
                                                                                                     ));
     this.fontMatrix = gs.GetFont().GetFontMatrix();
 }
Example #4
0
 /// <summary>Used for creating sub-TextRenderInfos for each individual character</summary>
 /// <param name="parent">the parent TextRenderInfo</param>
 /// <param name="string">the content of a TextRenderInfo</param>
 /// <param name="horizontalOffset">the unscaled horizontal offset of the character that this TextRenderInfo represents
 ///     </param>
 private TextRenderInfo(iText.Kernel.Pdf.Canvas.Parser.Data.TextRenderInfo parent, PdfString @string, float
                        horizontalOffset)
 {
     this.@string = @string;
     this.textToUserSpaceTransformMatrix = new Matrix(horizontalOffset, 0).Multiply(parent.textToUserSpaceTransformMatrix
                                                                                    );
     this.gs = parent.gs;
     this.canvasTagHierarchy = parent.canvasTagHierarchy;
     this.fontMatrix         = gs.GetFont().GetFontMatrix();
 }
Example #5
0
 /// <summary>Create an ImageRenderInfo</summary>
 /// <param name="ctm">the coordinate transformation matrix at the time the image is rendered</param>
 /// <param name="imageStream">image stream object</param>
 /// <param name="resourceName"/>
 /// <param name="colorSpaceDictionary">the color space dictionary from resources which are associated with the image
 ///     </param>
 /// <param name="isInline">defines if the encountered image was inline</param>
 public ImageRenderInfo(Stack <CanvasTag> canvasTagHierarchy, CanvasGraphicsState gs, Matrix ctm, PdfStream
                        imageStream, PdfName resourceName, PdfDictionary colorSpaceDictionary, bool isInline)
     : base(gs)
 {
     this.canvasTagHierarchy = JavaCollectionsUtil.UnmodifiableList <CanvasTag>(new List <CanvasTag>(canvasTagHierarchy
                                                                                                     ));
     this.resourceName         = resourceName;
     this.ctm                  = ctm;
     this.image                = new PdfImageXObject(imageStream);
     this.colorSpaceDictionary = colorSpaceDictionary;
     this.isInline             = isInline;
 }
 /// <param name="gs">The graphics state.</param>
 /// <param name="path">The path to be rendered.</param>
 /// <param name="operation">
 /// One of the possible combinations of
 /// <see cref="STROKE"/>
 /// and
 /// <see cref="FILL"/>
 /// values or
 /// <see cref="NO_OP"/>
 /// </param>
 /// <param name="rule">
 /// Either
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// or
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.EVEN_ODD"/>.
 /// </param>
 /// <param name="isClip">True indicates that current path modifies the clipping path, false - if not.</param>
 /// <param name="clipRule">
 /// Either
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// or
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.EVEN_ODD"/>.
 /// </param>
 public PathRenderInfo(Stack <CanvasTag> canvasTagHierarchy, CanvasGraphicsState gs, Path path, int operation
                       , int rule, bool isClip, int clipRule)
     : base(gs)
 {
     this.canvasTagHierarchy = JavaCollectionsUtil.UnmodifiableList <CanvasTag>(new List <CanvasTag>(canvasTagHierarchy
                                                                                                     ));
     this.path         = path;
     this.operation    = operation;
     this.rule         = rule;
     this.isClip       = isClip;
     this.clippingRule = clipRule;
 }
Example #7
0
        public override void CheckShowTextIsoConformance(Object obj, PdfResources resources)
        {
            CanvasGraphicsState gState = (CanvasGraphicsState)obj;
            bool fill   = false;
            bool stroke = false;

            switch (gState.GetTextRenderingMode())
            {
            case PdfCanvasConstants.TextRenderingMode.STROKE:
            case PdfCanvasConstants.TextRenderingMode.STROKE_CLIP: {
                stroke = true;
                break;
            }

            case PdfCanvasConstants.TextRenderingMode.FILL:
            case PdfCanvasConstants.TextRenderingMode.FILL_CLIP: {
                fill = true;
                break;
            }

            case PdfCanvasConstants.TextRenderingMode.FILL_STROKE:
            case PdfCanvasConstants.TextRenderingMode.FILL_STROKE_CLIP: {
                stroke = true;
                fill   = true;
                break;
            }
            }
            IsoKey drawMode = IsoKey.DRAWMODE_FILL;

            if (fill && stroke)
            {
                drawMode = IsoKey.DRAWMODE_FILL_STROKE;
            }
            else
            {
                if (fill)
                {
                    drawMode = IsoKey.DRAWMODE_FILL;
                }
                else
                {
                    if (stroke)
                    {
                        drawMode = IsoKey.DRAWMODE_STROKE;
                    }
                }
            }
            if (fill || stroke)
            {
                CheckIsoConformance(gState, drawMode, resources);
            }
        }
        private void WriteText(String @operator, IList <PdfObject> operands, PdfArray cleanedText, PdfCanvas canvas
                               )
        {
            CanvasGraphicsState canvasGs = canvas.GetGraphicsState();
            bool newLineShowText         = "'".Equals(@operator) || "\"".Equals(@operator);

            if (newLineShowText)
            {
                if (canvasGs.GetLeading() != currLeading)
                {
                    canvas.SetLeading((float)currLeading);
                }
                // after new line operator, removed text shift doesn't matter
                removedTextShift = null;
            }
            PdfTextArray tjShiftArray = null;

            if (removedTextShift != null)
            {
                float tjShift = (float)removedTextShift * 1000 / (canvasGs.GetFontSize() * canvasGs.GetHorizontalScaling()
                                                                  / 100);
                tjShiftArray = new PdfTextArray();
                tjShiftArray.Add(new PdfNumber(tjShift));
            }
            if (cleanedText != null)
            {
                if (newLineShowText)
                {
                    // char spacing and word spacing are set via writeNotAppliedTextStateParams() method
                    canvas.NewlineText();
                }
                if (removedTextShift != null)
                {
                    tjShiftArray.AddAll(cleanedText);
                    cleanedText = tjShiftArray;
                }
                canvas.ShowText(cleanedText);
            }
            else
            {
                if (removedTextShift != null)
                {
                    canvas.ShowText(tjShiftArray);
                }
                PdfCleanUpProcessor.WriteOperands(canvas, operands);
            }
        }
Example #9
0
        public override void CheckExtGState(CanvasGraphicsState extGState)
        {
            if (extGState.GetTransferFunction() != null)
            {
                throw new PdfAConformanceException(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_KEY
                                                   );
            }
            PdfObject transferFunction2 = extGState.GetTransferFunction2();

            if (transferFunction2 != null && !PdfName.Default.Equals(transferFunction2))
            {
                throw new PdfAConformanceException(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_2_KEY_WITH_A_VALUE_OTHER_THAN_DEFAULT
                                                   );
            }
            CheckRenderingIntent(extGState.GetRenderingIntent());
            PdfObject softMask = extGState.GetSoftMask();

            if (softMask != null && !PdfName.None.Equals(softMask))
            {
                throw new PdfAConformanceException(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_EXTGSTATE);
            }
            PdfObject bm = extGState.GetBlendMode();

            if (bm != null && !PdfName.Normal.Equals(bm) && !PdfName.Compatible.Equals(bm))
            {
                throw new PdfAConformanceException(PdfAConformanceException.BLEND_MODE_SHALL_HAVE_VALUE_NORMAL_OR_COMPATIBLE
                                                   );
            }
            float?ca = extGState.GetStrokeOpacity();

            if (ca != null && ca != 1)
            {
                throw new PdfAConformanceException(PdfAConformanceException.TRANSPARENCY_IS_NOT_ALLOWED_CA_SHALL_BE_EQUAL_TO_1
                                                   );
            }
            ca = extGState.GetFillOpacity();
            if (ca != null && ca != 1)
            {
                throw new PdfAConformanceException(PdfAConformanceException.TRANSPARENCY_IS_NOT_ALLOWED_AND_CA_SHALL_BE_EQUAL_TO_1
                                                   );
            }
        }
Example #10
0
        public override void CheckExtGState(CanvasGraphicsState extGState)
        {
            if (extGState.GetTransferFunction() != null)
            {
                throw new PdfAConformanceException(PdfAConformanceException.AnExtgstateDictionaryShallNotContainTheTrKey);
            }
            PdfObject transferFunction2 = extGState.GetTransferFunction2();

            if (transferFunction2 != null && !PdfName.Default.Equals(transferFunction2))
            {
                throw new PdfAConformanceException(PdfAConformanceException.AnExtgstateDictionaryShallNotContainTheTR2KeyWithAValueOtherThanDefault
                                                   );
            }
            CheckRenderingIntent(extGState.GetRenderingIntent());
            PdfObject softMask = extGState.GetSoftMask();

            if (softMask != null && !PdfName.None.Equals(softMask))
            {
                throw new PdfAConformanceException(PdfAConformanceException.TheSmaskKeyIsNotAllowedInExtgstate);
            }
            PdfObject bm = extGState.GetBlendMode();

            if (bm != null && !PdfName.Normal.Equals(bm) && !PdfName.Compatible.Equals(bm))
            {
                throw new PdfAConformanceException(PdfAConformanceException.BlendModeShallHhaveValueNormalOrCompatible);
            }
            float?ca = extGState.GetStrokeOpacity();

            if (ca != null && ca != 1)
            {
                throw new PdfAConformanceException(PdfAConformanceException.TransparencyIsNotAllowedCAShallBeEqualTo1);
            }
            ca = extGState.GetFillOpacity();
            if (ca != null && ca != 1)
            {
                throw new PdfAConformanceException(PdfAConformanceException.TransparencyIsNotAllowedCaShallBeEqualTo1);
            }
        }
Example #11
0
 /// <summary>
 /// Performs a number of checks on the graphics state, among others ISO
 /// 19005-1 section 6.2.8 and 6.4 and ISO 19005-2 section 6.2.5 and 6.2.10.
 /// </summary>
 /// <remarks>
 /// Performs a number of checks on the graphics state, among others ISO
 /// 19005-1 section 6.2.8 and 6.4 and ISO 19005-2 section 6.2.5 and 6.2.10.
 /// This method will be abstract in the update 7.2
 /// </remarks>
 /// <param name="extGState">the graphics state to be checked</param>
 /// <param name="contentStream">current content stream</param>
 public virtual void CheckExtGState(CanvasGraphicsState extGState, PdfStream contentStream)
 {
 }
Example #12
0
 public abstract void CheckExtGState(CanvasGraphicsState extGState);
Example #13
0
 /// <summary>
 /// If the operation is
 /// <see cref="NO_OP"/>
 /// then the rule is ignored,
 /// otherwise
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// is used by default.
 /// With this constructor path is considered as not modifying clipping path.
 /// See
 /// <see cref="PathRenderInfo(iText.Kernel.Geom.Path, int, int, bool, int, iText.Kernel.Pdf.Canvas.CanvasGraphicsState)
 ///     "/>
 /// </summary>
 public PathRenderInfo(Path path, int operation, CanvasGraphicsState gs)
     : this(path, operation, PdfCanvasConstants.FillingRule.NONZERO_WINDING, false, PdfCanvasConstants.FillingRule
            .NONZERO_WINDING, gs)
 {
 }
Example #14
0
 public override void CheckExtGState(CanvasGraphicsState extGState)
 {
     CheckExtGState(extGState, null);
 }
Example #15
0
 /// <param name="path">The path to be rendered.</param>
 /// <param name="ctm">The path to be rendered.</param>
 public ClippingPathInfo(CanvasGraphicsState gs, Path path, Matrix ctm)
     : base(gs)
 {
     this.path = path;
     this.ctm  = ctm;
 }
Example #16
0
 /// <summary>
 /// If the operation is
 /// <see cref="NO_OP"/>
 /// then the rule is ignored,
 /// otherwise
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// is used by default.
 /// </summary>
 /// <remarks>
 /// If the operation is
 /// <see cref="NO_OP"/>
 /// then the rule is ignored,
 /// otherwise
 /// <see cref="iText.Kernel.Pdf.Canvas.PdfCanvasConstants.FillingRule.NONZERO_WINDING"/>
 /// is used by default.
 /// With this constructor path is considered as not modifying clipping path.
 /// <para />
 /// See
 /// <see cref="PathRenderInfo(System.Collections.Generic.Stack{E}, iText.Kernel.Pdf.Canvas.CanvasGraphicsState, iText.Kernel.Geom.Path, int, int, bool, int)
 ///     "/>
 /// </remarks>
 public PathRenderInfo(Stack <CanvasTag> canvasTagHierarchy, CanvasGraphicsState gs, Path path, int operation
                       )
     : this(canvasTagHierarchy, gs, path, operation, PdfCanvasConstants.FillingRule.NONZERO_WINDING, false, PdfCanvasConstants.FillingRule
            .NONZERO_WINDING)
 {
 }
Example #17
0
 public void SetCanvasGraphicsState(CanvasGraphicsState gs)
 {
     this.currentGs = gs;
 }
Example #18
0
 public AbstractRenderInfo(CanvasGraphicsState gs)
 {
     this.gs = gs;
 }
Example #19
0
 public virtual void PreserveGraphicsState()
 {
     CheckGraphicsState();
     this.graphicsStateIsPreserved = true;
     gs = new CanvasGraphicsState(gs);
 }