PdfSharp.Xps.Rendering.PdfContentWriter.WriteClip C# (CSharp) Méthode

WriteClip() public méthode

Writes the specified PathGeometry as intersection with the current clip path to the content stream.
public WriteClip ( PdfSharp.Xps.XpsModel.PathGeometry geo ) : void
geo PdfSharp.Xps.XpsModel.PathGeometry
Résultat void
    public void WriteClip(PathGeometry geo)
    {
      BeginGraphic();

      WriteGeometry(geo);

      if (geo.FillRule == FillRule.NonZero)
        WriteLiteral("W n\n");
      else
        WriteLiteral("W* n\n");
    }

Same methods

PdfContentWriter::WriteClip ( PdfSharp.Drawing.XRect rect ) : void

Usage Example

Exemple #1
0
        /// <summary>
        /// Builds a PdfFormXObject from the specified brush.
        /// // If a gradient contains transparency, a soft mask is created an added to the specified graphic state.
        /// </summary>
        PdfFormXObject BuildForm(RadialGradientBrush brush, PathGeometry geometry)
        {
            PdfFormXObject pdfForm = Context.PdfDocument.Internals.CreateIndirectObject <PdfFormXObject>();

            // HACK
            pdfForm.Elements.SetRectangle(PdfFormXObject.Keys.BBox, new PdfRectangle(0, 640, 480, 0));

            // Transparency group of the form
            //<<
            //  /I true
            //  /K false
            //  /S /Transparency
            //  /Type /Group
            //>>
            PdfTransparencyGroupAttributes tgPrimaryForm = Context.PdfDocument.Internals.CreateIndirectObject <PdfTransparencyGroupAttributes>();

            // not set by Acrobat: tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");
            tgPrimaryForm.Elements.SetBoolean(PdfTransparencyGroupAttributes.Keys.I, true);
            tgPrimaryForm.Elements.SetBoolean(PdfTransparencyGroupAttributes.Keys.K, false);
            pdfForm.Elements.SetReference(PdfFormXObject.Keys.Group, tgPrimaryForm);

            // Shading
            PdfShading shading = BuildShading(brush, 1, 1);

            // ExtGState
            //<<
            //  /AIS false
            //  /BM /Normal
            //  /ca 1
            //  /CA 1
            //  /op false
            //  /OP false
            //  /OPM 1
            //  /SA true
            //  /SMask 22 0 R
            //  /Type /ExtGState
            //>>
            PdfExtGState pdfExtGState = Context.PdfDocument.Internals.CreateIndirectObject <PdfExtGState>();

            pdfExtGState.SetDefault1();

            // Soft mask
            PdfSoftMask softmask = BuildSoftMask(brush);

            pdfExtGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);

            // PdfFormXObject
            //<<
            //  /BBox [200.118 369.142 582.795 -141.094]
            //  /Group 11 0 R
            //  /Length 117
            //  /Matrix [1 0 0 1 0 0]
            //  /Resources
            //  <<
            //    /ColorSpace
            //    <<
            //      /CS0 8 0 R
            //    >>
            //    /ExtGState
            //    <<
            //      /GS0 23 0 R
            //    >>
            //    /Shading
            //    <<
            //      /Sh0 14 0 R
            //    >>
            //  >>
            //  /Subtype /Form
            //>>
            //stream
            //q
            //203.868 365.392 157.5 -97.5 re
            //W* n
            //q
            //0 g
            //1 i
            ///GS0 gs
            //0.75 0 0 -0.75 200.1181183 369.1417236 cm
            //BX /Sh0 sh EX Q
            //Q
            //endstream
            PdfContentWriter writer = new PdfContentWriter(Context, pdfForm);

            writer.BeginContentRaw();
            // Acrobat 8 clips to bounding box, so we should do
            writer.WriteClip(geometry);
            //writer.WriteGraphicsState(extGState);
            //writer.WriteLiteral("0 g\n");
            writer.WriteLiteral(writer.Resources.AddExtGState(pdfExtGState) + " gs\n");

            XMatrix transform = new XMatrix(); //(brush.Viewport.Width / viewBoxForm.width, 0, 0, brush.Viewport.Height / viewBoxForm.height, 0, 0);

            writer.WriteMatrix(transform);
            writer.WriteLiteral("BX " + writer.Resources.AddShading(shading) + " sh EX\n");
            writer.EndContent();

            return(pdfForm);
        }
All Usage Examples Of PdfSharp.Xps.Rendering.PdfContentWriter::WriteClip