/**
         * <summary>Scans a content level looking for text.</summary>
         */
        /*
         * NOTE: Page contents are represented by a sequence of content objects,
         * possibly nested into multiple levels.
         */
        private void Extract(
            ContentScanner level,
            PrimitiveComposer composer
            )
        {
            if (level == null)
            {
                return;
            }

            while (level.MoveNext())
            {
                ContentObject content = level.Current;
                if (content is Text)
                {
                    ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper;
                    int colorIndex = 0;
                    foreach (ContentScanner.TextStringWrapper textString in text.TextStrings)
                    {
                        RectangleF textStringBox = textString.Box.Value;
                        Console.WriteLine(
                            "Text ["
                            + "x:" + Math.Round(textStringBox.X) + ","
                            + "y:" + Math.Round(textStringBox.Y) + ","
                            + "w:" + Math.Round(textStringBox.Width) + ","
                            + "h:" + Math.Round(textStringBox.Height)
                            + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text
                            );

                        // Drawing text character bounding boxes...
                        colorIndex = (colorIndex + 1) % textCharBoxColors.Length;
                        composer.SetStrokeColor(textCharBoxColors[colorIndex]);
                        foreach (TextChar textChar in textString.TextChars)
                        {
                            /*
                             * NOTE: You can get further text information
                             * (font, font size, text color, text rendering mode)
                             * through textChar.style.
                             */
                            composer.DrawRectangle(textChar.Box);
                            composer.Stroke();
                        }

                        // Drawing text string bounding box...
                        composer.BeginLocalState();
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }));
                        composer.SetStrokeColor(textStringBoxColor);
                        composer.DrawRectangle(textString.Box.Value);
                        composer.Stroke();
                        composer.End();
                    }
                }
                else if (content is ContainerObject)
                {
                    // Scan the inner level!
                    Extract(level.ChildLevel, composer);
                }
            }
        }
Exemplo n.º 2
0
        private void Apply(
            ComboBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

            if (appearance == null)
            {
                widget.Appearance = appearance = new Appearance(document);
            }

            widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");

            FormXObject normalAppearanceState;

            {
                SizeF size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float      lineWidth = 1;
                RectangleF frame     = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(
                    new StandardType1Font(
                        document,
                        StandardType1Font.FamilyEnum.Helvetica,
                        false,
                        false
                        ),
                    FontSize
                    );
                composer.ShowText(
                    (string)field.Value,
                    new PointF(0, size.Height / 2),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 3
0
        private void Apply(
            PushButton field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

            if (appearance == null)
            {
                widget.Appearance = appearance = new Appearance(document);
            }

            FormXObject normalAppearanceState;

            {
                SizeF size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float      lineWidth = 1;
                RectangleF frame     = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                string title = (string)field.Value;
                if (title != null)
                {
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
                    composer.SetFillColor(ForeColor);
                    composer.SetFont(
                        new StandardType1Font(
                            document,
                            StandardType1Font.FamilyEnum.Helvetica,
                            true,
                            false
                            ),
                        size.Height * 0.5
                        );
                    blockComposer.ShowText(title);
                    blockComposer.End();
                }

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 4
0
        private void Apply(
            ListBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;
            {
                PdfDictionary widgetDataObject = widget.BaseDataObject;
                widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");
                widgetDataObject[PdfName.MK] = new PdfDictionary(
                    new PdfName[]
                {
                    PdfName.BG,
                    PdfName.BC
                },
                    new PdfDirectObject[]
                {
                    new PdfArray(new PdfDirectObject[] { PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9) }),
                    new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default })
                }
                    );
            }

            FormXObject normalAppearanceState;

            {
                SKSize size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginLocalState();
                if (GraphicsVisibile)
                {
                    composer.DrawRectangle(frame, 5);
                    composer.Clip(); // Ensures that the visible content is clipped within the rounded frame.
                }
                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(
                    new StandardType1Font(
                        document,
                        StandardType1Font.FamilyEnum.Helvetica,
                        false,
                        false
                        ),
                    FontSize
                    );
                double y = 3;
                foreach (ChoiceItem item in field.Items)
                {
                    composer.ShowText(
                        item.Text,
                        new SKPoint(0, (float)y)
                        );
                    y += FontSize * 1.175;
                    if (y > size.Height)
                    {
                        break;
                    }
                }
                composer.End();
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 5
0
        private void Apply(
      CheckBox field
      )
        {
            Document document = field.Document;
              foreach(Widget widget in field.Widgets)
              {
            {
              PdfDictionary widgetDataObject = widget.BaseDataObject;
              widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg");
              widgetDataObject[PdfName.MK] = new PdfDictionary(
            new PdfName[]
            {
              PdfName.BG,
              PdfName.BC,
              PdfName.CA
            },
            new PdfDirectObject[]
            {
              new PdfArray(new PdfDirectObject[]{PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412)}),
              new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default}),
              new PdfString("4")
            }
            );
              widgetDataObject[PdfName.BS] = new PdfDictionary(
            new PdfName[]
            {
              PdfName.W,
              PdfName.S
            },
            new PdfDirectObject[]
            {
              PdfReal.Get(0.8),
              PdfName.S
            }
            );
              widgetDataObject[PdfName.H] = PdfName.P;
            }

            Appearance appearance = widget.Appearance;
            if(appearance == null)
            {widget.Appearance = appearance = new Appearance(document);}

            SizeF size = widget.Box.Size;

            AppearanceStates normalAppearance = appearance.Normal;
            FormXObject onState = new FormXObject(document, size);
            normalAppearance[PdfName.Yes] = onState;

              //TODO:verify!!!
              //   appearance.getRollover().put(PdfName.Yes,onState);
              //   appearance.getDown().put(PdfName.Yes,onState);
              //   appearance.getRollover().put(PdfName.Off,offState);
              //   appearance.getDown().put(PdfName.Off,offState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            {
              PrimitiveComposer composer = new PrimitiveComposer(onState);

              if(GraphicsVisibile)
              {
            composer.BeginLocalState();
            composer.SetLineWidth(lineWidth);
            composer.SetFillColor(BackColor);
            composer.SetStrokeColor(ForeColor);
            composer.DrawRectangle(frame, 5);
            composer.FillStroke();
            composer.End();
              }

              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle);
              composer.SetFillColor(ForeColor);
              composer.SetFont(
            new StandardType1Font(
              document,
              StandardType1Font.FamilyEnum.ZapfDingbats,
              true,
              false
              ),
            size.Height * 0.8
            );
              blockComposer.ShowText(new String(new char[]{CheckSymbol}));
              blockComposer.End();

              composer.Flush();
            }

            FormXObject offState = new FormXObject(document, size);
            normalAppearance[PdfName.Off] = offState;
            {
              if(GraphicsVisibile)
              {
            PrimitiveComposer composer = new PrimitiveComposer(offState);

            composer.BeginLocalState();
            composer.SetLineWidth(lineWidth);
            composer.SetFillColor(BackColor);
            composer.SetStrokeColor(ForeColor);
            composer.DrawRectangle(frame, 5);
            composer.FillStroke();
            composer.End();

            composer.Flush();
              }
            }
              }
        }
Exemplo n.º 6
0
        private void Apply(
      ListBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              {
            PdfDictionary widgetDataObject = widget.BaseDataObject;
            widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");
            widgetDataObject[PdfName.MK] = new PdfDictionary(
              new PdfName[]
              {
            PdfName.BG,
            PdfName.BC
              },
              new PdfDirectObject[]
              {
            new PdfArray(new PdfDirectObject[]{PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9)}),
            new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default})
              }
              );
              }

              FormXObject normalAppearanceState;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            if(GraphicsVisibile)
            {
              composer.BeginLocalState();
              composer.SetLineWidth(lineWidth);
              composer.SetFillColor(BackColor);
              composer.SetStrokeColor(ForeColor);
              composer.DrawRectangle(frame, 5);
              composer.FillStroke();
              composer.End();
            }

            composer.BeginLocalState();
            if(GraphicsVisibile)
            {
              composer.DrawRectangle(frame, 5);
              composer.Clip(); // Ensures that the visible content is clipped within the rounded frame.
            }
            composer.BeginMarkedContent(PdfName.Tx);
            composer.SetFont(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            double y = 3;
            foreach(ChoiceItem item in field.Items)
            {
              composer.ShowText(
            item.Text,
            new PointF(0, (float)y)
            );
              y += FontSize * 1.175;
              if(y > size.Height)
            break;
            }
            composer.End();
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 7
0
        private void Apply(
      ComboBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");

              FormXObject normalAppearanceState;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            if(GraphicsVisibile)
            {
              composer.BeginLocalState();
              composer.SetLineWidth(lineWidth);
              composer.SetFillColor(BackColor);
              composer.SetStrokeColor(ForeColor);
              composer.DrawRectangle(frame, 5);
              composer.FillStroke();
              composer.End();
            }

            composer.BeginMarkedContent(PdfName.Tx);
            composer.SetFont(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            composer.ShowText(
              (string)field.Value,
              new PointF(0,size.Height/2),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 8
0
        private void Apply(
      PushButton field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              FormXObject normalAppearanceState;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            if(GraphicsVisibile)
            {
              composer.BeginLocalState();
              composer.SetLineWidth(lineWidth);
              composer.SetFillColor(BackColor);
              composer.SetStrokeColor(ForeColor);
              composer.DrawRectangle(frame, 5);
              composer.FillStroke();
              composer.End();
            }

            string title = (string)field.Value;
            if(title != null)
            {
              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle);
              composer.SetFillColor(ForeColor);
              composer.SetFont(
            new StandardType1Font(
              document,
              StandardType1Font.FamilyEnum.Helvetica,
              true,
              false
              ),
            size.Height * 0.5
            );
              blockComposer.ShowText(title);
              blockComposer.End();
            }

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 9
0
        /*
         * TODO: refresh should happen just before serialization, on document event (e.g. OnWrite())
         */
        private void RefreshAppearance(
            )
        {
            FormXObject normalAppearance;
            RectangleF  box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF();
            {
                AppearanceStates normalAppearances = Appearance.Normal;
                normalAppearance = normalAppearances[null];
                if (normalAppearance != null)
                {
                    normalAppearance.Box = box;
                    normalAppearance.BaseDataObject.Body.SetLength(0);
                }
                else
                {
                    normalAppearances[null] = normalAppearance = new FormXObject(Document, box);
                }
            }

            PrimitiveComposer composer = new PrimitiveComposer(normalAppearance);

            {
                float          yOffset    = box.Height - Page.Box.Height;
                MarkupTypeEnum markupType = MarkupType;
                switch (markupType)
                {
                case MarkupTypeEnum.Highlight:
                {
                    ExtGState defaultExtGState;
                    {
                        ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates;
                        defaultExtGState = extGStates[HighlightExtGStateName];
                        if (defaultExtGState == null)
                        {
                            if (extGStates.Count > 0)
                            {
                                extGStates.Clear();
                            }

                            extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document);
                            defaultExtGState.AlphaShape        = false;
                            defaultExtGState.BlendMode         = new List <BlendModeEnum>(new BlendModeEnum[] { BlendModeEnum.Multiply });
                        }
                    }

                    composer.ApplyState(defaultExtGState);
                    composer.SetFillColor(Color);
                    {
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight);
                            composer.DrawCurve(
                                new PointF(points[3].X, points[3].Y + yOffset),
                                new PointF(points[0].X, points[0].Y + yOffset),
                                new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset),
                                new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset)
                                );
                            composer.DrawLine(
                                new PointF(points[1].X, points[1].Y + yOffset)
                                );
                            composer.DrawCurve(
                                new PointF(points[2].X, points[2].Y + yOffset),
                                new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset),
                                new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset)
                                );
                            composer.Fill();
                        }
                    }
                }
                break;

                case MarkupTypeEnum.Squiggly:
                {
                    composer.SetStrokeColor(Color);
                    composer.SetLineCap(LineCapEnum.Round);
                    composer.SetLineJoin(LineJoinEnum.Round);
                    {
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    lineWidth       = markupBoxHeight * .05f;
                            float    step            = markupBoxHeight * .125f;
                            float    boxXOffset      = points[3].X;
                            float    boxYOffset      = points[3].Y + yOffset - lineWidth;
                            bool     phase           = false;
                            composer.SetLineWidth(lineWidth);
                            for (float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step)
                            {
                                PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset);
                                if (x == 0)
                                {
                                    composer.StartPath(point);
                                }
                                else
                                {
                                    composer.DrawLine(point);
                                }
                                phase = !phase;
                            }
                        }
                        composer.Stroke();
                    }
                }
                break;

                case MarkupTypeEnum.StrikeOut:
                case MarkupTypeEnum.Underline:
                {
                    composer.SetStrokeColor(Color);
                    {
                        float lineYRatio = 0;
                        switch (markupType)
                        {
                        case MarkupTypeEnum.StrikeOut:
                            lineYRatio = .5f;
                            break;

                        case MarkupTypeEnum.Underline:
                            lineYRatio = .9f;
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    boxYOffset      = markupBoxHeight * lineYRatio + yOffset;
                            composer.SetLineWidth(markupBoxHeight * .065);
                            composer.DrawLine(
                                new PointF(points[3].X, points[0].Y + boxYOffset),
                                new PointF(points[2].X, points[1].Y + boxYOffset)
                                );
                        }
                        composer.Stroke();
                    }
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
            composer.Flush();
        }
Exemplo n.º 10
0
        /**
          <summary>Scans a content level looking for text.</summary>
        */
        /*
          NOTE: Page contents are represented by a sequence of content objects,
          possibly nested into multiple levels.
        */
        private void Extract(
            ContentScanner level,
            PrimitiveComposer composer
            )
        {
            if(level == null)
            return;

              while(level.MoveNext())
              {
            ContentObject content = level.Current;
            if(content is Text)
            {
              ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper;
              int colorIndex = 0;
              foreach(ContentScanner.TextStringWrapper textString in text.TextStrings)
              {
            RectangleF textStringBox = textString.Box.Value;
            Console.WriteLine(
              "Text ["
                + "x:" + Math.Round(textStringBox.X) + ","
                + "y:" + Math.Round(textStringBox.Y) + ","
                + "w:" + Math.Round(textStringBox.Width) + ","
                + "h:" + Math.Round(textStringBox.Height)
                + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text
                );

            // Drawing text character bounding boxes...
            colorIndex = (colorIndex + 1) % textCharBoxColors.Length;
            composer.SetStrokeColor(textCharBoxColors[colorIndex]);
            foreach(TextChar textChar in textString.TextChars)
            {
              /*
                NOTE: You can get further text information
                (font, font size, text color, text rendering mode)
                through textChar.style.
              */
              composer.DrawRectangle(textChar.Box);
              composer.Stroke();
            }

            // Drawing text string bounding box...
            composer.BeginLocalState();
            composer.SetLineDash(new LineDash(new double[]{5,5}));
            composer.SetStrokeColor(textStringBoxColor);
            composer.DrawRectangle(textString.Box.Value);
            composer.Stroke();
            composer.End();
              }
            }
            else if(content is ContainerObject)
            {
              // Scan the inner level!
              Extract(level.ChildLevel, composer);
            }
              }
        }
Exemplo n.º 11
0
        /*
          TODO: refresh should happen just before serialization, on document event (e.g. OnWrite())
        */
        private void RefreshAppearance(
      )
        {
            FormXObject normalAppearance;
              RectangleF box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF();
              {
            AppearanceStates normalAppearances = Appearance.Normal;
            normalAppearance = normalAppearances[null];
            if(normalAppearance != null)
            {
              normalAppearance.Box = box;
              normalAppearance.BaseDataObject.Body.SetLength(0);
            }
            else
            {normalAppearances[null] = normalAppearance = new FormXObject(Document, box);}
              }

              PrimitiveComposer composer = new PrimitiveComposer(normalAppearance);
              {
            float yOffset = box.Height - Page.Box.Height;
            MarkupTypeEnum markupType = MarkupType;
            switch(markupType)
            {
              case MarkupTypeEnum.Highlight:
              {
            ExtGState defaultExtGState;
            {
              ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates;
              defaultExtGState = extGStates[HighlightExtGStateName];
              if(defaultExtGState == null)
              {
                if(extGStates.Count > 0)
                {extGStates.Clear();}

                extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document);
                defaultExtGState.AlphaShape = false;
                defaultExtGState.BlendMode = new List<BlendModeEnum>(new BlendModeEnum[]{BlendModeEnum.Multiply});
              }
            }

            composer.ApplyState(defaultExtGState);
            composer.SetFillColor(Color);
            {
              foreach(Quad markupBox in MarkupBoxes)
              {
                PointF[] points = markupBox.Points;
                float markupBoxHeight = points[3].Y - points[0].Y;
                float markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight);
                composer.DrawCurve(
                  new PointF(points[3].X, points[3].Y + yOffset),
                  new PointF(points[0].X, points[0].Y + yOffset),
                  new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset),
                  new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset)
                  );
                composer.DrawLine(
                  new PointF(points[1].X, points[1].Y + yOffset)
                  );
                composer.DrawCurve(
                  new PointF(points[2].X, points[2].Y + yOffset),
                  new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset),
                  new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset)
                  );
                composer.Fill();
              }
            }
              }
            break;
              case MarkupTypeEnum.Squiggly:
              {
            composer.SetStrokeColor(Color);
            composer.SetLineCap(LineCapEnum.Round);
            composer.SetLineJoin(LineJoinEnum.Round);
            {
              foreach(Quad markupBox in MarkupBoxes)
              {
                PointF[] points = markupBox.Points;
                float markupBoxHeight = points[3].Y - points[0].Y;
                float lineWidth = markupBoxHeight * .02f;
                float step = markupBoxHeight * .125f;
                float boxXOffset = points[3].X;
                float boxYOffset = points[3].Y + yOffset - lineWidth;
                bool phase = false;
                composer.SetLineWidth(lineWidth);
                for(float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step)
                {
                  PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset);
                  if(x == 0)
                  {composer.StartPath(point);}
                  else
                  {composer.DrawLine(point);}
                  phase = !phase;
                }
              }
              composer.Stroke();
            }
              }
            break;
              case MarkupTypeEnum.StrikeOut:
              case MarkupTypeEnum.Underline:
              {
            composer.SetStrokeColor(Color);
            {
              float lineYRatio = 0;
              switch(markupType)
              {
                case MarkupTypeEnum.StrikeOut:
                  lineYRatio = .575f;
                  break;
                case MarkupTypeEnum.Underline:
                  lineYRatio = .85f;
                  break;
                default:
                  throw new NotImplementedException();
              }
              foreach(Quad markupBox in MarkupBoxes)
              {
                PointF[] points = markupBox.Points;
                float markupBoxHeight = points[3].Y - points[0].Y;
                float boxYOffset = markupBoxHeight * lineYRatio + yOffset;
                composer.SetLineWidth(markupBoxHeight * .065);
                composer.DrawLine(
                  new PointF(points[3].X, points[0].Y + boxYOffset),
                  new PointF(points[2].X, points[1].Y + boxYOffset)
                  );
              }
              composer.Stroke();
            }
              }
            break;
              default:
            throw new NotImplementedException();
            }
              }
              composer.Flush();
        }
Exemplo n.º 12
0
        private void Apply(
            CheckBox field
            )
        {
            Document document = field.Document;

            foreach (Widget widget in field.Widgets)
            {
                {
                    PdfDictionary widgetDataObject = widget.BaseDataObject;
                    widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg");
                    widgetDataObject[PdfName.MK] = new PdfDictionary(
                        new PdfName[]
                    {
                        PdfName.BG,
                        PdfName.BC,
                        PdfName.CA
                    },
                        new PdfDirectObject[]
                    {
                        new PdfArray(new PdfDirectObject[] { new PdfReal(0.9412), new PdfReal(0.9412), new PdfReal(0.9412) }),
                        new PdfArray(new PdfDirectObject[] { new PdfInteger(0), new PdfInteger(0), new PdfInteger(0) }),
                        new PdfString("4")
                    }
                        );
                    widgetDataObject[PdfName.BS] = new PdfDictionary(
                        new PdfName[]
                    {
                        PdfName.W,
                        PdfName.S
                    },
                        new PdfDirectObject[]
                    {
                        new PdfReal(0.8),
                        PdfName.S
                    }
                        );
                    widgetDataObject[PdfName.H] = PdfName.P;
                }

                Appearance appearance = widget.Appearance;
                if (appearance == null)
                {
                    widget.Appearance = appearance = new Appearance(document);
                }

                AppearanceStates normalAppearance = appearance.Normal;
                FormXObject      onState          = new FormXObject(document);
                normalAppearance[PdfName.Yes] = onState;

                //TODO:verify!!!
                //   appearance.getRollover().put(PdfName.Yes,onState);
                //   appearance.getDown().put(PdfName.Yes,onState);
                //   appearance.getRollover().put(PdfName.Off,offState);
                //   appearance.getDown().put(PdfName.Off,offState);

                SizeF      size  = widget.Box.Size;
                RectangleF frame = new RectangleF(0, 0, size.Width, size.Height);
                {
                    onState.Size = new Size((int)size.Width, (int)size.Height);

                    PrimitiveComposer composer = new PrimitiveComposer(onState);

                    composer.BeginLocalState();
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame);
                    composer.FillStroke();
                    composer.End();

                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(frame, AlignmentXEnum.Center, AlignmentYEnum.Middle);
                    composer.SetFillColor(ForeColor);
                    composer.SetFont(
                        new StandardType1Font(
                            document,
                            StandardType1Font.FamilyEnum.ZapfDingbats,
                            true,
                            false
                            ),
                        size.Height * 0.8f
                        );
                    blockComposer.ShowText(new String(new char[] { CheckSymbol }));
                    blockComposer.End();

                    composer.Flush();
                }

                FormXObject offState = new FormXObject(document);
                normalAppearance[PdfName.Off] = offState;
                {
                    offState.Size = new Size((int)size.Width, (int)size.Height);

                    PrimitiveComposer composer = new PrimitiveComposer(offState);

                    composer.BeginLocalState();
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame);
                    composer.FillStroke();
                    composer.End();

                    composer.Flush();
                }
            }
        }
Exemplo n.º 13
0
        private void BuildSteps(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SizeF pageSize
            )
        {
            composer.SetFont(ResourceName_DefaultFont,32);
              RectangleF frame = new RectangleF(
            0,
            0,
            pageSize.Width,
            pageSize.Height
            );

              // Step 0.
              {
            colors[0] = new colorSpaces::DeviceRGBColor(30 / 255d, 10 / 255d, 0);
            composer.SetFillColor(colors[0]);
            composer.SetStrokeColor(colors[0]);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 0",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[0] = GetStepNote(composer,"default");
              }

              // Step 1.
              {
            colors[1] = new colorSpaces::DeviceRGBColor(80 / 255d, 25 / 255d, 0);
            composer.SetFillColor(colors[1]);
            composer.SetStrokeColor(colors[1]);

            // Transform the coordinate space, applying translation!
            composer.Translate(72,72);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 1",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[1] = GetStepNote(composer,"after translate(72,72)");
              }

              // Step 2.
              {
            colors[2] = new colorSpaces::DeviceRGBColor(130 / 255d, 45 / 255d, 0);
            composer.SetFillColor(colors[2]);
            composer.SetStrokeColor(colors[2]);

            // Transform the coordinate space, applying clockwise rotation!
            composer.Rotate(-20);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the coordinate space origin mark!
            composer.ShowText("Origin 2");

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 2",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[2] = GetStepNote(composer,"after rotate(20)");
              }

              // Step 3.
              {
            colors[3] = new colorSpaces::DeviceRGBColor(180 / 255d, 60 / 255d, 0);
            composer.SetFillColor(colors[3]);
            composer.SetStrokeColor(colors[3]);

            // Transform the coordinate space, applying translation and scaling!
            composer.Translate(0,72);
            composer.Scale(.5f,.5f);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 3",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[3] = GetStepNote(composer,"after translate(0,72) and scale(.5,.5)");
              }

              // Step 4.
              {
            colors[4] = new colorSpaces::DeviceRGBColor(230 / 255d, 75 / 255d, 0);
            composer.SetFillColor(colors[4]);
            composer.SetStrokeColor(colors[4]);

            // Transform the coordinate space, restoring its initial CTM!
            composer.Add(
              ModifyCTM.GetResetCTM(
            composer.Scanner.State
            )
              );

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 4",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[4] = GetStepNote(composer,"after resetting CTM");
              }
        }
Exemplo n.º 14
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

              // 2. Create a content composer for the page!
              PrimitiveComposer composer = new PrimitiveComposer(page);

              // 3. Drawing the page contents...
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            32
            );

              {
            BlockComposer blockComposer = new BlockComposer(composer);
            blockComposer.Begin(new RectangleF(30,0,pageSize.Width-60,50),XAlignmentEnum.Center,YAlignmentEnum.Middle);
            blockComposer.ShowText("Miscellaneous");
            blockComposer.End();
              }

              composer.BeginLocalState();
              composer.SetLineJoin(LineJoinEnum.Round);
              composer.SetLineCap(LineCapEnum.Round);

              // 3.1. Polygon.
              composer.DrawPolygon(
            new PointF[]
            {
              new PointF(100,200),
              new PointF(150,150),
              new PointF(200,150),
              new PointF(250,200)
            }
            );

              // 3.2. Polyline.
              composer.DrawPolyline(
            new PointF[]
            {
              new PointF(300,200),
              new PointF(350,150),
              new PointF(400,150),
              new PointF(450,200)
            }
            );

              composer.Stroke();

              // 3.3. Rectangle (both squared and rounded).
              int x = 50;
              int radius = 0;
              while(x < 500)
              {
            if(x > 300)
            {
              composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            }

            composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d));
            composer.DrawRectangle(
              new RectangleF(x, 250, 150, 100),
              radius // NOTE: radius parameter determines the rounded angle size.
              );
            composer.FillStroke();

            x += 175;
            radius += 10;
              }
              composer.End(); // End local state.

              composer.BeginLocalState();
              composer.SetFont(
            composer.State.Font,
            12
            );

              // 3.4. Line cap parameter.
              int y = 400;
              foreach(LineCapEnum lineCap
            in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum)))
              {
            composer.ShowText(
              lineCap + ":",
              new PointF(50,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.SetLineWidth(12);
            composer.SetLineCap(lineCap);
            composer.DrawLine(
              new PointF(120,y),
              new PointF(220,y)
              );
            composer.Stroke();

            composer.BeginLocalState();
            composer.SetLineWidth(1);
            composer.SetStrokeColor(DeviceRGBColor.White);
            composer.SetLineCap(LineCapEnum.Butt);
            composer.DrawLine(
              new PointF(120,y),
              new PointF(220,y)
              );
            composer.Stroke();
            composer.End(); // End local state.

            y += 30;
              }

              // 3.5. Line join parameter.
              y += 50;
              foreach(LineJoinEnum lineJoin
            in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum)))
              {
            composer.ShowText(
              lineJoin + ":",
              new PointF(50,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.SetLineWidth(12);
            composer.SetLineJoin(lineJoin);
            PointF[] points = new PointF[]
              {
            new PointF(120,y+25),
            new PointF(150,y-25),
            new PointF(180,y+25)
              };
            composer.DrawPolyline(points);
            composer.Stroke();

            composer.BeginLocalState();
            composer.SetLineWidth(1);
            composer.SetStrokeColor(DeviceRGBColor.White);
            composer.SetLineCap(LineCapEnum.Butt);
            composer.DrawPolyline(points);
            composer.Stroke();
            composer.End(); // End local state.

            y += 50;
              }
              composer.End(); // End local state.

              // 3.6. Clipping.
              /*
            NOTE: Clipping should be conveniently enclosed within a local state
            in order to easily resume the unaltered drawing area after the operation completes.
              */
              composer.BeginLocalState();
              composer.DrawPolygon(
            new PointF[]
            {
              new PointF(220,410),
              new PointF(300,490),
              new PointF(450,360),
              new PointF(430,520),
              new PointF(590,565),
              new PointF(420,595),
              new PointF(460,730),
              new PointF(380,650),
              new PointF(330,765),
              new PointF(310,640),
              new PointF(220,710),
              new PointF(275,570),
              new PointF(170,500),
              new PointF(275,510)
            }
            );
              composer.Clip();
              // Showing a clown image...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
              xObjects::XObject imageXObject = image.ToXObject(document);
              // Show the image!
              composer.ShowXObject(
            imageXObject,
            new PointF(170, 320),
            GeomUtils.Scale(imageXObject.Size, new SizeF(450,0))
            );
              composer.End(); // End local state.

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Exemplo n.º 15
0
        private void Apply(
            CheckBox field
            )
        {
            Document document = field.Document;

            foreach (Widget widget in field.Widgets)
            {
                {
                    PdfDictionary widgetDataObject = widget.BaseDataObject;
                    widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg");
                    widgetDataObject[PdfName.MK] = new PdfDictionary(
                        new PdfName[] { PdfName.BG, PdfName.BC, PdfName.CA },
                        new PdfDirectObject[]
                    {
                        new PdfArray(new PdfDirectObject[] { PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412) }),
                        new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default }),
                        new PdfString("4")
                    }
                        );
                    widgetDataObject[PdfName.BS] = new PdfDictionary(
                        new PdfName[] { PdfName.W, PdfName.S },
                        new PdfDirectObject[] { PdfReal.Get(0.8), PdfName.S }
                        );
                    widgetDataObject[PdfName.H] = PdfName.P;
                }

                Appearance       appearance       = widget.Appearance;
                AppearanceStates normalAppearance = appearance.Normal;
                SKSize           size             = widget.Box.Size;
                FormXObject      onState          = new FormXObject(document, size);
                normalAppearance[PdfName.Yes] = onState;

                //TODO:verify!!!
                //   appearance.getRollover().put(PdfName.Yes,onState);
                //   appearance.getDown().put(PdfName.Yes,onState);
                //   appearance.getRollover().put(PdfName.Off,offState);
                //   appearance.getDown().put(PdfName.Off,offState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                {
                    PrimitiveComposer composer = new PrimitiveComposer(onState);

                    if (GraphicsVisibile)
                    {
                        composer.BeginLocalState();
                        composer.SetLineWidth(lineWidth);
                        composer.SetFillColor(BackColor);
                        composer.SetStrokeColor(ForeColor);
                        composer.DrawRectangle(frame, 5);
                        composer.FillStroke();
                        composer.End();
                    }

                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
                    composer.SetFillColor(ForeColor);
                    composer.SetFont(
                        new StandardType1Font(
                            document,
                            StandardType1Font.FamilyEnum.ZapfDingbats,
                            true,
                            false
                            ),
                        size.Height * 0.8
                        );
                    blockComposer.ShowText(new String(new char[] { CheckSymbol }));
                    blockComposer.End();

                    composer.Flush();
                }

                FormXObject offState = new FormXObject(document, size);
                normalAppearance[PdfName.Off] = offState;
                {
                    if (GraphicsVisibile)
                    {
                        PrimitiveComposer composer = new PrimitiveComposer(offState);

                        composer.BeginLocalState();
                        composer.SetLineWidth(lineWidth);
                        composer.SetFillColor(BackColor);
                        composer.SetStrokeColor(ForeColor);
                        composer.DrawRectangle(frame, 5);
                        composer.FillStroke();
                        composer.End();

                        composer.Flush();
                    }
                }
            }
        }
        public FormXObject Build(
            )
        {
            bool   isRound         = type == TypeEnum.Round;
            bool   isStriped       = type == TypeEnum.Striped;
            double textScale       = .5;
            double borderWidth     = this.borderWidth.GetValue(width);
            double doubleBorderGap = borderDoubled ? borderWidth : 0;
            double fontSize        = 10;

            fontSize *= ((width - (isStriped ? 2 : doubleBorderGap * 2 + (borderWidth * (borderDoubled ? 1.5 : 1) * 2) + width * (isRound ?  .15 : .05))) / textScale) / font.GetWidth(text, fontSize);
            float height = (float)(isRound ? width : (font.GetAscent(fontSize) * 1.2 + doubleBorderGap * 2 + (borderWidth * (borderDoubled ? 1.5 : 1) * 2)));
            SizeF size   = new SizeF(width, height);

            FormXObject appearance = new FormXObject(document, size);

            {
                PrimitiveComposer composer = new PrimitiveComposer(appearance);
                if (color != null)
                {
                    composer.SetStrokeColor(color);
                    composer.SetFillColor(color);
                }
                composer.SetTextScale(textScale);
                composer.SetFont(font, fontSize);
                composer.ShowText(text, new PointF(size.Width / 2, (float)(size.Height / 2 - font.GetDescent(fontSize) * .4)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                double     borderRadius  = isRound ? 0 : this.borderRadius.GetValue((size.Width + size.Height) / 2);
                RectangleF prevBorderBox = appearance.Box;
                for (int borderStep = 0, borderStepLimit = (borderDoubled ? 2 : 1); borderStep < borderStepLimit; borderStep++)
                {
                    if (borderStep == 0)
                    {
                        composer.SetLineWidth(borderWidth);
                    }
                    else
                    {
                        composer.SetLineWidth(composer.State.LineWidth / 2);
                    }

                    float      lineWidth = (float)(borderStep > 0 ? composer.State.LineWidth / 2 : borderWidth);
                    float      marginY   = (float)(lineWidth / 2 + (borderStep > 0 ? composer.State.LineWidth + doubleBorderGap : 0));
                    float      marginX   = isStriped ? 0 : marginY;
                    RectangleF borderBox = new RectangleF(prevBorderBox.X + marginX, prevBorderBox.Y + marginY, prevBorderBox.Width - marginX * 2, prevBorderBox.Height - marginY * 2);

                    if (isRound)
                    {
                        composer.DrawEllipse(borderBox);
                    }
                    else
                    {
                        if (isStriped)
                        {
                            composer.DrawLine(new PointF(borderBox.Left, borderBox.Top), new PointF(borderBox.Right, borderBox.Top));
                            composer.DrawLine(new PointF(borderBox.Left, borderBox.Bottom), new PointF(borderBox.Right, borderBox.Bottom));
                        }
                        else
                        {
                            composer.DrawRectangle(borderBox, borderRadius * (1 - .5 * borderStep));
                        }
                    }
                    composer.Stroke();
                    prevBorderBox = borderBox;
                }
                composer.Flush();
            }
            return(appearance);
        }
Exemplo n.º 17
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

            document.Pages.Add(page);       // Puts the page in the pages collection.

            SizeF pageSize = page.Size;

            // 2. Create a content composer for the page!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            // 3. Drawing the page contents...
            composer.SetFont(
                new fonts::StandardType1Font(
                    document,
                    fonts::StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    ),
                32
                );

            {
                BlockComposer blockComposer = new BlockComposer(composer);
                blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle);
                blockComposer.ShowText("Miscellaneous");
                blockComposer.End();
            }

            composer.BeginLocalState();
            composer.SetLineJoin(LineJoinEnum.Round);
            composer.SetLineCap(LineCapEnum.Round);

            // 3.1. Polygon.
            composer.DrawPolygon(
                new PointF[]
            {
                new PointF(100, 200),
                new PointF(150, 150),
                new PointF(200, 150),
                new PointF(250, 200)
            }
                );

            // 3.2. Polyline.
            composer.DrawPolyline(
                new PointF[]
            {
                new PointF(300, 200),
                new PointF(350, 150),
                new PointF(400, 150),
                new PointF(450, 200)
            }
                );

            composer.Stroke();

            // 3.3. Rectangle (both squared and rounded).
            int x      = 50;
            int radius = 0;

            while (x < 500)
            {
                if (x > 300)
                {
                    composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                }

                composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d));
                composer.DrawRectangle(
                    new RectangleF(x, 250, 150, 100),
                    radius // NOTE: radius parameter determines the rounded angle size.
                    );
                composer.FillStroke();

                x      += 175;
                radius += 10;
            }
            composer.End(); // End local state.

            composer.BeginLocalState();
            composer.SetFont(
                composer.State.Font,
                12
                );

            // 3.4. Line cap parameter.
            int y = 400;

            foreach (LineCapEnum lineCap
                     in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum)))
            {
                composer.ShowText(
                    lineCap + ":",
                    new PointF(50, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.SetLineWidth(12);
                composer.SetLineCap(lineCap);
                composer.DrawLine(
                    new PointF(120, y),
                    new PointF(220, y)
                    );
                composer.Stroke();

                composer.BeginLocalState();
                composer.SetLineWidth(1);
                composer.SetStrokeColor(DeviceRGBColor.White);
                composer.SetLineCap(LineCapEnum.Butt);
                composer.DrawLine(
                    new PointF(120, y),
                    new PointF(220, y)
                    );
                composer.Stroke();
                composer.End(); // End local state.

                y += 30;
            }

            // 3.5. Line join parameter.
            y += 50;
            foreach (LineJoinEnum lineJoin
                     in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum)))
            {
                composer.ShowText(
                    lineJoin + ":",
                    new PointF(50, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.SetLineWidth(12);
                composer.SetLineJoin(lineJoin);
                PointF[] points = new PointF[]
                {
                    new PointF(120, y + 25),
                    new PointF(150, y - 25),
                    new PointF(180, y + 25)
                };
                composer.DrawPolyline(points);
                composer.Stroke();

                composer.BeginLocalState();
                composer.SetLineWidth(1);
                composer.SetStrokeColor(DeviceRGBColor.White);
                composer.SetLineCap(LineCapEnum.Butt);
                composer.DrawPolyline(points);
                composer.Stroke();
                composer.End(); // End local state.

                y += 50;
            }
            composer.End(); // End local state.

            // 3.6. Clipping.

            /*
             * NOTE: Clipping should be conveniently enclosed within a local state
             * in order to easily resume the unaltered drawing area after the operation completes.
             */
            composer.BeginLocalState();
            composer.DrawPolygon(
                new PointF[]
            {
                new PointF(220, 410),
                new PointF(300, 490),
                new PointF(450, 360),
                new PointF(430, 520),
                new PointF(590, 565),
                new PointF(420, 595),
                new PointF(460, 730),
                new PointF(380, 650),
                new PointF(330, 765),
                new PointF(310, 640),
                new PointF(220, 710),
                new PointF(275, 570),
                new PointF(170, 500),
                new PointF(275, 510)
            }
                );
            composer.Clip();
            // Showing a clown image...
            // Instantiate a jpeg image object!
            entities::Image   image        = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
            xObjects::XObject imageXObject = image.ToXObject(document);

            // Show the image!
            composer.ShowXObject(
                imageXObject,
                new PointF(170, 320),
                GeomUtils.Scale(imageXObject.Size, new SizeF(450, 0))
                );
            composer.End(); // End local state.

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Exemplo n.º 18
0
        private void BuildSteps(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SKSize pageSize
            )
        {
            composer.SetFont(ResourceName_DefaultFont, 32);
            SKRect frame = SKRect.Create(
                0,
                0,
                pageSize.Width,
                pageSize.Height
                );

            // Step 0.
            {
                colors[0] = new colorSpaces::DeviceRGBColor(30 / 255d, 10 / 255d, 0);
                composer.SetFillColor(colors[0]);
                composer.SetStrokeColor(colors[0]);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 0",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[0] = GetStepNote(composer, "default");
            }

            // Step 1.
            {
                colors[1] = new colorSpaces::DeviceRGBColor(80 / 255d, 25 / 255d, 0);
                composer.SetFillColor(colors[1]);
                composer.SetStrokeColor(colors[1]);

                // Transform the coordinate space, applying translation!
                composer.Translate(72, 72);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 1",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[1] = GetStepNote(composer, "after translate(72,72)");
            }

            // Step 2.
            {
                colors[2] = new colorSpaces::DeviceRGBColor(130 / 255d, 45 / 255d, 0);
                composer.SetFillColor(colors[2]);
                composer.SetStrokeColor(colors[2]);

                // Transform the coordinate space, applying clockwise rotation!
                composer.Rotate(-20);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the coordinate space origin mark!
                composer.ShowText("Origin 2");

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 2",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[2] = GetStepNote(composer, "after rotate(20)");
            }

            // Step 3.
            {
                colors[3] = new colorSpaces::DeviceRGBColor(180 / 255d, 60 / 255d, 0);
                composer.SetFillColor(colors[3]);
                composer.SetStrokeColor(colors[3]);

                // Transform the coordinate space, applying translation and scaling!
                composer.Translate(0, 72);
                composer.Scale(.5f, .5f);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 3",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[3] = GetStepNote(composer, "after translate(0,72) and scale(.5,.5)");
            }

            // Step 4.
            {
                colors[4] = new colorSpaces::DeviceRGBColor(230 / 255d, 75 / 255d, 0);
                composer.SetFillColor(colors[4]);
                composer.SetStrokeColor(colors[4]);

                // Transform the coordinate space, restoring its initial CTM!
                composer.Add(
                    ModifyCTM.GetResetCTM(
                        composer.Scanner.State
                        )
                    );

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 4",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[4] = GetStepNote(composer, "after resetting CTM");
            }
        }