Exemplo n.º 1
0
        /// <summary>
        /// Builds a pattern from a linear gradient brush.
        /// </summary>
        public static PdfShadingPattern BuildPatternFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush, XMatrix transform)
        {
            LinearShadingBuilder builder = new LinearShadingBuilder(context);
            PdfShadingPattern    pattern = builder.BuildShadingPattern(brush, transform);

            return(pattern);
        }
Exemplo n.º 2
0
        public static XPImage FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
        {
            ImageBuilder ib      = new ImageBuilder(context);
            XPImage      xpImage = ib.Build(brush);

            return(xpImage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a PdfTilingPattern pattern from a visual brush.
        /// </summary>
        public static PdfTilingPattern BuildFromVisualBrush(DocumentRenderingContext context, VisualBrush brush, XMatrix transform)
        {
            TilingPatternBuilder builder    = new TilingPatternBuilder(context);
            PdfTilingPattern     pdfPattern = builder.BuildPattern(brush, transform);

            return(pdfPattern);
        }
Exemplo n.º 4
0
        public static XPImageBrush Create(DocumentRenderingContext context, ImageBrush brush)
        {
            XPImageBrush xpImageBrush = new XPImageBrush(brush);

            xpImageBrush.Construct(context, brush);
            return(xpImageBrush);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Builds a shading pattern from an radial gradient brush.
        /// </summary>
        public static PdfShadingPattern BuildFromRadialGradientBrush(DocumentRenderingContext context, RadialGradientBrush brush, XRect boundingBox, XMatrix transform)
        {
            RadialShadingBuilder builder = new RadialShadingBuilder(context);
            PdfShadingPattern    pattern = builder.BuildPattern(brush, boundingBox, transform);

            return(pattern);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Builds a shading from a linear gradient brush.
        /// </summary>
        public static PdfShading BuildShadingFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush)
        {
            LinearShadingBuilder builder = new LinearShadingBuilder(context);
            PdfShading           shading = builder.BuildShading(brush);

            return(shading);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Builds a form XObject from a linear gradient brush that uses transparency.
        /// </summary>
        public static PdfFormXObject BuildFormFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush, PathGeometry geometry)
        {
            LinearShadingBuilder builder = new LinearShadingBuilder(context);
            PdfFormXObject       pdfForm = builder.BuildForm(brush, geometry);

            return(pdfForm);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfContentWriter"/> class
 /// for creating a content stream of the specified page.
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, PdfPage page) // , XGraphics gfx, XGraphicsPdfPageOptions options)
 {
   this.context = context;
   this.page = page;
   this.contentStreamDictionary = page;
   //this.colorMode = page.document.Options.ColorMode;
   //this.options = options;
   this.content = new StringBuilder();
   this.graphicsState = new PdfGraphicsState(this);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfContentWriter"/> class
 /// for creating a content stream of the specified page.
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, PdfPage page) // , XGraphics gfx, XGraphicsPdfPageOptions options)
 {
     this.context = context;
     this.page    = page;
     this.contentStreamDictionary = page;
     //this.colorMode = page.document.Options.ColorMode;
     //this.options = options;
     this.content       = new StringBuilder();
     this.graphicsState = new PdfGraphicsState(this);
 }
Exemplo n.º 10
0
 /// <summary>
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, PdfDictionary contentDictionary)
 {
   if (!(contentDictionary is IContentStream))
     throw new ArgumentException("contentDictionary must implement IContentStream.");
   this.context = context;
   this.contentDictionary = contentDictionary;
   this.contentStreamDictionary = (IContentStream)contentDictionary;
   this.renderMode = RenderMode.Default;
   //this.colorMode = page.document.Options.ColorMode;
   //this.options = options;
   this.content = new StringBuilder();
   this.graphicsState = new PdfGraphicsState(this);
 }
Exemplo n.º 11
0
 /// <summary>
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, PdfDictionary contentDictionary)
 {
     if (!(contentDictionary is IContentStream))
     {
         throw new ArgumentException("contentDictionary must implement IContentStream.");
     }
     this.context                 = context;
     this.contentDictionary       = contentDictionary;
     this.contentStreamDictionary = (IContentStream)contentDictionary;
     this.renderMode              = RenderMode.Default;
     //this.colorMode = page.document.Options.ColorMode;
     //this.options = options;
     this.content       = new StringBuilder();
     this.graphicsState = new PdfGraphicsState(this);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Creates an XForm from an image brush.
        /// </summary>
        public static XForm FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
        {
            XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
            XImage  ximage  = xpImage.XImage;
            double  width   = ximage.PixelWidth;
            double  height  = ximage.PixelHeight;

            // view box in point
            // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
            XRect box   = new XRect(0, 0, width, height);
            XForm xform = new XForm(context.PdfDocument, box);

            PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);

            Debug.Assert(ximage != null);

            PdfFormXObject pdfForm = xform.PdfForm;

            pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

            //formWriter.Size = brush.Viewport.Size;
            formWriter.BeginContentRaw();

            string  imageID = formWriter.Resources.AddImage(new PdfImage(context.PdfDocument, ximage));
            XMatrix matrix  = new XMatrix();
            double  scaleX  = brush.Viewport.Width / brush.Viewbox.Width * 4 / 3 * ximage.PointWidth;
            double  scaleY  = brush.Viewport.Height / brush.Viewbox.Height * 4 / 3 * ximage.PointHeight;

            matrix.TranslatePrepend(-brush.Viewbox.X, -brush.Viewbox.Y);
            matrix.ScalePrepend(scaleX, scaleY);
            matrix.TranslatePrepend(brush.Viewport.X / scaleX, brush.Viewport.Y / scaleY);

            matrix = new XMatrix(width, 0, 0, -height, 0, height);
            formWriter.WriteLiteral("q\n");
            // TODO:WriteClip(path.Data);
            //formWriter.WriteLiteral("{0:0.###} 0 0 -{1:0.###} {2:0.###} {3:0.###} cm 100 Tz {4} Do Q\n",
            //  matrix.M11, matrix.M22, matrix.OffsetX, matrix.OffsetY + brush.Viewport.Height, imageID);
            formWriter.WriteMatrix(matrix);
            formWriter.WriteLiteral(imageID + " Do Q\n");

            formWriter.EndContent();

            return(xform);
        }
Exemplo n.º 13
0
    void Construct(DocumentRenderingContext context, ImageBrush brush)
    {
      FixedPage fpage = brush.GetParent<FixedPage>();
      if (fpage == null)
        Debug.Assert(false);

      FixedPayload payload = fpage.Document.Payload;  // TODO: find better way to get FixedPayload
      //Debug.Assert(Object.Equals(payload, Context.


      this.form = XFormBuilder.FromImageBrush(context, brush);

      // Get the font object.
      // Important: font.PdfFont is not yet defined here on the first call
      //string uriString = brush.ImageSource;
      //BitmapSource bitmapSource = payload.GetImage(uriString);

      //XPImage xpImage = new XPImage(bitmapSource);
    }
Exemplo n.º 14
0
    /// <summary>
    /// Creates an XForm from an image brush.
    /// </summary>
    public static XForm FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
    {
      XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
      XImage ximage = xpImage.XImage;
      double width = ximage.PixelWidth;
      double height = ximage.PixelHeight;

      // view box in point
      // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
      XRect box = new XRect(0, 0, width, height);
      XForm xform = new XForm(context.PdfDocument, box);

      PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);

      Debug.Assert(ximage != null);

      PdfFormXObject pdfForm = xform.PdfForm;
      pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContentRaw();

      string imageID = formWriter.Resources.AddImage(new PdfImage(context.PdfDocument, ximage));
      XMatrix matrix = new XMatrix();
      double scaleX = brush.Viewport.Width / brush.Viewbox.Width * 4 / 3 * ximage.PointWidth;
      double scaleY = brush.Viewport.Height / brush.Viewbox.Height * 4 / 3 * ximage.PointHeight;
      matrix.TranslatePrepend(-brush.Viewbox.X, -brush.Viewbox.Y);
      matrix.ScalePrepend(scaleX, scaleY);
      matrix.TranslatePrepend(brush.Viewport.X / scaleX, brush.Viewport.Y / scaleY);

      matrix = new XMatrix(width, 0, 0, -height, 0, height);
      formWriter.WriteLiteral("q\n");
      // TODO:WriteClip(path.Data);
      //formWriter.WriteLiteral("{0:0.###} 0 0 -{1:0.###} {2:0.###} {3:0.###} cm 100 Tz {4} Do Q\n",
      //  matrix.M11, matrix.M22, matrix.OffsetX, matrix.OffsetY + brush.Viewport.Height, imageID);
      formWriter.WriteMatrix(matrix);
      formWriter.WriteLiteral(imageID + " Do Q\n");

      formWriter.EndContent();

      return xform;
    }
Exemplo n.º 15
0
        void Construct(DocumentRenderingContext context, ImageBrush brush)
        {
            FixedPage fpage = brush.GetParent <FixedPage>();

            if (fpage == null)
            {
                Debug.Assert(false);
            }

            FixedPayload payload = fpage.Document.Payload; // TODO: find better way to get FixedPayload

            //Debug.Assert(Object.Equals(payload, Context.


            this.form = XFormBuilder.FromImageBrush(context, brush);

            // Get the font object.
            // Important: font.PdfFont is not yet defined here on the first call
            //string uriString = brush.ImageSource;
            //BitmapSource bitmapSource = payload.GetImage(uriString);

            //XPImage xpImage = new XPImage(bitmapSource);
        }
Exemplo n.º 16
0
    /// <summary>
    /// Creates an XForm from a visual brush.
    /// </summary>
    public static XForm FromVisualBrush(DocumentRenderingContext context, VisualBrush brush)
    {
      //XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
      //XImage ximage = xpImage.XImage;
      double width = brush.Viewport.Width;
      double height = brush.Viewport.Height;

      // view box in point
      // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
      XRect box = new XRect(0, 0, width, height);
      XForm xform = new XForm(context.PdfDocument, box);

      PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);
      PdfFormXObject pdfForm = xform.PdfForm;
      pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

      //formWriter.Size = brush.Viewport.Size;
      formWriter.BeginContent(false);
      formWriter.WriteElement(brush.Visual);
      formWriter.EndContent();

      return xform;
    }
Exemplo n.º 17
0
        /// <summary>
        /// Creates an XForm from a visual brush.
        /// </summary>
        public static XForm FromVisualBrush(DocumentRenderingContext context, VisualBrush brush)
        {
            //XPImage xpImage = ImageBuilder.FromImageBrush(context, brush);
            //XImage ximage = xpImage.XImage;
            double width  = brush.Viewport.Width;
            double height = brush.Viewport.Height;

            // view box in point
            // XRect box = new XRect(brush.Viewbox.X * 0.75, brush.Viewbox.Y * 0.75, brush.Viewbox.Width * 0.75, brush.Viewbox.Height * 0.75);
            XRect box   = new XRect(0, 0, width, height);
            XForm xform = new XForm(context.PdfDocument, box);

            PdfContentWriter formWriter = new PdfContentWriter(context, xform, RenderMode.Default);
            PdfFormXObject   pdfForm    = xform.PdfForm;

            pdfForm.Elements.SetMatrix(PdfFormXObject.Keys.Matrix, new XMatrix());

            //formWriter.Size = brush.Viewport.Size;
            formWriter.BeginContent(false);
            formWriter.WriteElement(brush.Visual);
            formWriter.EndContent();

            return(xform);
        }
Exemplo n.º 18
0
        internal void RenderPage(PdfPage page, FixedPage fixedPage)
        {
            this.page = page;

            context = new DocumentRenderingContext(page.Owner);

            //this.page.Width = fixedPage.Width;
            //this.page.Height = fixedPage.Height;

            //this.gsStack = new GraphicsStateStack(this);
            PdfContent content = null;

            //switch (options)
            //{
            //  case XGraphicsPdfPageOptions.Replace:
            //    page.Contents.Elements.Clear();
            //    goto case XGraphicsPdfPageOptions.Append;

            //  case XGraphicsPdfPageOptions.Prepend:
            //    content = page.Contents.PrependContent();
            //    break;

            //  case XGraphicsPdfPageOptions.Append:
            content = page.Contents.AppendContent();
            //    break;
            //}
            page.RenderContent = content;

            writer = new PdfContentWriter(context, this.page);

            //Initialize();

            writer.BeginContent(false);
            writer.WriteElements(fixedPage.Content);
            writer.EndContent();
        }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TilingPatternBuilder"/> class.
 /// </summary>
 TilingPatternBuilder(DocumentRenderingContext context) :
     base(context)
 { }
Exemplo n.º 20
0
 /// <summary>
 /// Builds a PdfTilingPattern pattern from a visual brush.
 /// </summary>
 public static PdfTilingPattern BuildFromVisualBrush(DocumentRenderingContext context, VisualBrush brush, XMatrix transform)
 {
     TilingPatternBuilder builder = new TilingPatternBuilder(context);
     PdfTilingPattern pdfPattern = builder.BuildPattern(brush, transform);
     return pdfPattern;
 }
Exemplo n.º 21
0
    /// <summary>
    /// A first hack to do the job...
    /// </summary>
    public static void RenderPage_Test01(PdfPage page, string xpsFilename)
    {
      //XpsDocument xpsdoc = new XpsDocument(xpsFilename, System.IO.FileAccess.Read);
      //FixedDocument fds = xpsdoc.GetFixedDocument();
      //DocumentReferenceCollection docrefs = fds.References;
      //DocumentReference docref = docrefs[0];
      //Uri uri1 = docref.Source;
      //FixedDocument fixeddoc = docref.GetDocument(false);
      //PageContent content = fixeddoc.Pages[0];
      //Uri uri2 = content.Source;
      //FixedPage fixedPage = content.Child;
      //xpsdoc.Close();
      // /Documents/1/Pages/1.fpage

      try
      {
#if true
        XpsDocument doc = XpsDocument.Open(xpsFilename);
        FixedPage fpage = doc.GetDocument().GetFixedPage(0);

        //ZipPackage pack = ZipPackage.Open(xpsFilename) as ZipPackage;
        Uri uri = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative);
        ZipPackagePart part = doc.Package.GetPart(uri) as ZipPackagePart;
        using (Stream stream = part.GetStream())
        {
          using (StreamReader sr = new StreamReader(stream))
          {
            string xml = sr.ReadToEnd();
#if true
            string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsFilename), IOPath.GetFileNameWithoutExtension(xpsFilename)) + ".xml";
            using (StreamWriter sw = new StreamWriter(xmlPath))
            {
              sw.Write(xml);
            }
#endif
            DocumentRenderingContext context = new DocumentRenderingContext(page.Owner);
            //XpsElement el = PdfSharp.Xps.Parsing.XpsParser.Parse(xml);
            PdfRenderer renderer = new PdfRenderer();
            renderer.RenderPage(page, fpage);
          }
        }
#else
        ZipPackage pack = ZipPackage.Open(xpsFilename) as ZipPackage;
        Uri uri = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative);
        ZipPackagePart part = pack.GetPart(uri) as ZipPackagePart;
        using (Stream stream = part.GetStream())
        {
          using (StreamReader sr = new StreamReader(stream))
          {
            string xml = sr.ReadToEnd();
#if true
            string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsFilename), IOPath.GetFileNameWithoutExtension(xpsFilename)) + ".xml";
            using (StreamWriter sw = new StreamWriter(xmlPath))
            {
              sw.Write(xml);
            }
#endif
            XpsElement el = PdfSharp.Xps.Parsing.XpsParser.Parse(xml);
            PdfRenderer renderer = new PdfRenderer();
            renderer.RenderPage(page, el as PdfSharp.Xps.XpsModel.FixedPage);
          }
        }
#endif
      }
      catch
      {
        //DaSt :
      }
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="RadialShadingBuilder"/> class.
 /// </summary>
 RadialShadingBuilder(DocumentRenderingContext context) :
   base(context)
 { }
Exemplo n.º 23
0
 ImageBuilder(DocumentRenderingContext context) :
     base(context)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RadialShadingBuilder"/> class.
 /// </summary>
 RadialShadingBuilder(DocumentRenderingContext context) :
     base(context)
 {
 }
Exemplo n.º 25
0
 protected PdfPart(DocumentRenderingContext drc)
 {
   this.drc = drc;
 }
Exemplo n.º 26
0
 XFormBuilder(DocumentRenderingContext context)
   : base(context)
 {
 }
Exemplo n.º 27
0
 protected PdfPart(DocumentRenderingContext drc)
 {
     this.drc = drc;
 }
Exemplo n.º 28
0
 ImageBrushPart(DocumentRenderingContext drc)
     : base(drc)
 {
 }
 /// <summary>
 /// Builds a pattern from a linear gradient brush.
 /// </summary>
 public static PdfShadingPattern BuildPatternFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush, XMatrix transform)
 {
   LinearShadingBuilder builder = new LinearShadingBuilder(context);
   PdfShadingPattern pattern = builder.BuildShadingPattern(brush, transform);
   return pattern;
 }
Exemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuilderBase"/> class.
 /// </summary>
 protected BuilderBase(DocumentRenderingContext context)
 {
   this.context = context;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuilderBase"/> class.
 /// </summary>
 protected BuilderBase(DocumentRenderingContext context)
 {
     this.context = context;
 }
 /// <summary>
 /// Builds a form XObject from a linear gradient brush that uses transparency.
 /// </summary>
 public static PdfFormXObject BuildFormFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush, PathGeometry geometry)
 {
   LinearShadingBuilder builder = new LinearShadingBuilder(context);
   PdfFormXObject pdfForm = builder.BuildForm(brush, geometry);
   return pdfForm;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuilderBase"/> class.
 /// </summary>
 protected PatternOrShadingBuilder(DocumentRenderingContext context)
     : base(context)
 {
 }
Exemplo n.º 34
0
 ImageBrushPart(DocumentRenderingContext drc)
   : base(drc)
 {
 }
Exemplo n.º 35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TilingPatternBuilder"/> class.
 /// </summary>
 TilingPatternBuilder(DocumentRenderingContext context) :
     base(context)
 {
 }
 /// <summary>
 /// Builds a shading pattern from an radial gradient brush.
 /// </summary>
 public static PdfShadingPattern BuildFromRadialGradientBrush(DocumentRenderingContext context, RadialGradientBrush brush, XRect boundingBox, XMatrix transform)
 {
   RadialShadingBuilder builder = new RadialShadingBuilder(context);
   PdfShadingPattern pattern = builder.BuildPattern(brush, boundingBox, transform);
   return pattern;
 }
Exemplo n.º 37
0
 public static XPImageBrush Create(DocumentRenderingContext context, ImageBrush brush)
 {
   XPImageBrush xpImageBrush = new XPImageBrush(brush);
   xpImageBrush.Construct(context, brush);
   return xpImageBrush;
 }
Exemplo n.º 38
0
 public static XPImage FromImageBrush(DocumentRenderingContext context, ImageBrush brush)
 {
   ImageBuilder ib = new ImageBuilder(context);
   XPImage xpImage = ib.Build(brush);
   return xpImage;
 }
Exemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuilderBase"/> class.
 /// </summary>
 protected PatternOrShadingBuilder(DocumentRenderingContext context)
   : base(context)
 { }
 /// <summary>
 /// Builds a shading from a linear gradient brush.
 /// </summary>
 public static PdfShading BuildShadingFromLinearGradientBrush(DocumentRenderingContext context, LinearGradientBrush brush)
 {
   LinearShadingBuilder builder = new LinearShadingBuilder(context);
   PdfShading shading = builder.BuildShading(brush);
   return shading;
 }