/**
         * <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);
                }
            }
        }
        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;
        }
        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;
        }
        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");
            }
        }
Example #5
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;
        }
        private void BuildTextBlockPage2(
            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...
            fonts::Font   mainFont      = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int           stepCount     = 5;
            int           step          = (int)(pageSize.Height) / (stepCount + 1);
            BlockComposer blockComposer = new BlockComposer(composer);

            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Block line alignment");
                blockComposer.End();
            }

            // Drawing the text block...
            {
                fonts::Font       sampleFont         = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
                entities::Image   sampleImage        = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg"));
                xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document);

                IList <LineAlignmentEnum> lineAlignments = new List <LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum)));
                float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2);
                float frameWidth  = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count;
                int   imageSize   = 7;
                for (int index = 0, length = lineAlignments.Count; index < length; index++)
                {
                    LineAlignmentEnum lineAlignment = lineAlignments[index];

                    for (int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++)
                    {
                        LineAlignmentEnum imageAlignment = lineAlignments[imageIndex];

                        for (int index2 = 0, length2 = 2; index2 < length2; index2++)
                        {
                            RectangleF frame = new RectangleF(
                                30 + (frameWidth + 5) * imageIndex,
                                100 + (frameHeight + 5) * (index * 2 + index2),
                                frameWidth,
                                frameHeight
                                );

                            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                            {
                                composer.SetFont(mainFont, 3);
                                blockComposer.ShowText("Text: " + lineAlignment);
                                blockComposer.ShowBreak();
                                blockComposer.ShowText("Image: " + imageAlignment);
                            }
                            blockComposer.End();

                            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Middle);
                            {
                                composer.SetFont(sampleFont, 3);
                                blockComposer.ShowText("Previous row boundary.");
                                blockComposer.ShowBreak();
                                composer.SetFont(sampleFont, index2 == 0 ? 3 : 6);
                                blockComposer.ShowText("Alignment:");
                                composer.SetFont(sampleFont, index2 == 0 ? 6 : 3);
                                blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment);
                                blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment);
                                blockComposer.ShowBreak();
                                composer.SetFont(sampleFont, 3);
                                blockComposer.ShowText("Next row boundary.");
                            }
                            blockComposer.End();

                            composer.BeginLocalState();
                            {
                                composer.SetLineWidth(0.1f);
                                composer.SetLineDash(new LineDash(new double[] { 1, 4 }, 4));
                                composer.DrawRectangle(blockComposer.Frame);
                                composer.Stroke();
                            }
                            composer.End();

                            composer.BeginLocalState();
                            {
                                composer.SetLineWidth(0.1f);
                                composer.SetLineDash(new LineDash(new double[] { 1, 1 }, 1));
                                composer.DrawRectangle(blockComposer.BoundBox);
                                composer.Stroke();
                            }
                            composer.End();
                        }
                    }
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
        private void BuildTextBlockPage4(
            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...
            fonts::Font   mainFont      = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int           stepCount     = 5;
            int           step          = (int)pageSize.Height / (stepCount + 1);
            BlockComposer blockComposer = new BlockComposer(composer);

            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Unspaced block");
                blockComposer.End();
            }

            // Drawing the text block...
            {
                fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
                composer.SetFont(sampleFont, 15);

                float topMargin = 100;
                float boxMargin = 30;
                float boxWidth  = pageSize.Width - boxMargin * 2;
                float boxHeight = (pageSize.Height - topMargin - boxMargin - boxMargin) / 2;
                {
                    RectangleF frame = new RectangleF(
                        boxMargin,
                        topMargin,
                        boxWidth,
                        boxHeight
                        );
                    blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                    // Add text until the frame area is completely filled!
                    while (blockComposer.ShowText("DemonstratingHowUnspacedTextIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0)
                    {
                        ;
                    }
                    blockComposer.End();

                    composer.BeginLocalState();
                    {
                        composer.SetLineWidth(0.2);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                        composer.DrawRectangle(frame);
                        composer.Stroke();
                    }
                    composer.End();
                }
                {
                    RectangleF frame = new RectangleF(
                        boxMargin,
                        topMargin + boxHeight + boxMargin,
                        boxWidth,
                        boxHeight
                        );
                    blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                    // Add text until the frame area is completely filled!
                    while (blockComposer.ShowText(" DemonstratingHowUnspacedTextWithLeadingSpaceIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0)
                    {
                        ;
                    }
                    blockComposer.End();

                    composer.BeginLocalState();
                    {
                        composer.SetLineWidth(0.2);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                        composer.DrawRectangle(frame);
                        composer.Stroke();
                    }
                    composer.End();
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Example #8
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;
        }
Example #9
0
        private void BuildSimpleTextPage(
            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. Inserting contents...
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            32
            );

              XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
              YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
              int step = (int)(pageSize.Height) / ((xAlignments.Length-1) * yAlignments.Length+1);

              BlockComposer blockComposer = new BlockComposer(composer);
              RectangleF frame = new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step/2
            );
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle);
              blockComposer.ShowText("Simple alignment");
              blockComposer.End();

              frame = new RectangleF(
            30,
            pageSize.Height-step/2,
            pageSize.Width-60,
            step/2 -10
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Bottom);
              composer.SetFont(composer.State.Font,10);
              blockComposer.ShowText(
            "NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
              + "NOTE: The rotation parameter can be freely defined as a floating point value."
            );
              blockComposer.End();

              composer.SetFont(composer.State.Font,12);
              int x = 30;
              int y = step;
              int alignmentIndex = 0;
              foreach(XAlignmentEnum xAlignment
            in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
              {
            /*
              NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
              applying the justified alignment has no effect (it degrades to center alignment);
              in order to get such an effect, use BlockComposer instead.
            */
            if(xAlignment.Equals(XAlignmentEnum.Justify))
              continue;

            foreach(YAlignmentEnum yAlignment
              in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
            {
              if(alignmentIndex % 2 == 0)
              {
            composer.BeginLocalState();
            composer.SetFillColor(BackColor);
            composer.DrawRectangle(
              new RectangleF(
                0,
                y-step/2,
                pageSize.Width,
                step
                )
              );
            composer.Fill();
            composer.End();
              }

              composer.ShowText(
            xAlignment + " " + yAlignment + ":",
            new PointF(x,y),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );

              y+=step;
              alignmentIndex++;
            }
              }

              float rotationStep = 0;
              float rotation = 0;
              for(
            int columnIndex = 0;
            columnIndex < 2;
            columnIndex++
            )
              {
            switch(columnIndex)
            {
              case 0:
            x = 200;
            rotationStep = 0;
            break;
              case 1:
            x = (int)pageSize.Width / 2 + 100;
            rotationStep = 360 / ((xAlignments.Length-1) * yAlignments.Length-1);
            break;
            }
            y = step;
            rotation = 0;
            foreach(XAlignmentEnum xAlignment
              in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
              /*
            NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
            applying the justified alignment has no effect (it degrades to center alignment);
            in order to get such an effect, use BlockComposer instead.
              */
              if(xAlignment.Equals(XAlignmentEnum.Justify))
            continue;

              foreach(YAlignmentEnum yAlignment
            in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
              {
            float startArcAngle = 0;
            switch(xAlignment)
            {
              case XAlignmentEnum.Left:
                // OK -- NOOP.
                break;
              case XAlignmentEnum.Right:
              case XAlignmentEnum.Center:
                startArcAngle = 180;
                break;
            }

            composer.DrawArc(
              new RectangleF(
                x-10,
                y-10,
                20,
                20
                ),
              startArcAngle,
              startArcAngle+rotation
              );

            DrawText(
              composer,
              "PDF Clown",
              new PointF(x,y),
              xAlignment,
              yAlignment,
              rotation
              );
            y+=step;
            rotation+=rotationStep;
              }
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #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);
            }
              }
        }
Example #11
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();
              }
            }
              }
        }
Example #12
0
        private void BuildTextBlockPage3(
            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...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int stepCount = 5;
              int step = (int)(pageSize.Height) / (stepCount + 1);

              // 3.1. Drawing the page title...
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Block line space");
            blockComposer.End();
              }

              // 3.2. Drawing the text blocks...
              fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
              int x = 30;
              int y = (int)(step * 1.1);
              blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative;
              for(int index = 0; index < stepCount; index++)
              {
            float relativeLineSpace = 0.5f * index;
            blockComposer.LineSpace.Value = relativeLineSpace;

            composer.SetFont(mainFont, 12);
            composer.ShowText(
              relativeLineSpace + ":",
              new PointF(x,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );

            composer.SetFont(sampleFont, 10);
            RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f);
            blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
            blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\").");
            blockComposer.End();

            composer.BeginLocalState();
            {
              composer.SetLineWidth(0.2);
              composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
              composer.DrawRectangle(frame);
              composer.Stroke();
            }
            composer.End();

            y+=step;
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #13
0
        private void BuildTextBlockPage4(
            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...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int stepCount = 5;
              int step = (int)pageSize.Height / (stepCount + 1);
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Unspaced block");
            blockComposer.End();
              }

              // Drawing the text block...
              {
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            composer.SetFont(sampleFont, 15);

            float topMargin = 100;
            float boxMargin = 30;
            float boxWidth = pageSize.Width - boxMargin * 2;
            float boxHeight = (pageSize.Height - topMargin - boxMargin - boxMargin) / 2;
            {
              RectangleF frame = new RectangleF(
            boxMargin,
            topMargin,
            boxWidth,
            boxHeight
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              // Add text until the frame area is completely filled!
              while(blockComposer.ShowText("DemonstratingHowUnspacedTextIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0);
              blockComposer.End();

              composer.BeginLocalState();
              {
            composer.SetLineWidth(0.2);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
            composer.DrawRectangle(frame);
            composer.Stroke();
              }
              composer.End();
            }
            {
              RectangleF frame = new RectangleF(
            boxMargin,
            topMargin + boxHeight + boxMargin,
            boxWidth,
            boxHeight
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              // Add text until the frame area is completely filled!
              while(blockComposer.ShowText(" DemonstratingHowUnspacedTextWithLeadingSpaceIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0);
              blockComposer.End();

              composer.BeginLocalState();
              {
            composer.SetLineWidth(0.2);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
            composer.DrawRectangle(frame);
            composer.Stroke();
              }
              composer.End();
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #14
0
        private void BuildTextBlockPage2(
            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...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int stepCount = 5;
              int step = (int)(pageSize.Height) / (stepCount + 1);
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Block line alignment");
            blockComposer.End();
              }

              // Drawing the text block...
              {
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            entities::Image sampleImage = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg"));
            xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document);

            IList<LineAlignmentEnum> lineAlignments = new List<LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum)));
            float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2);
            float frameWidth = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count;
            int imageSize = 7;
            for(int index = 0, length = lineAlignments.Count; index < length; index++)
            {
              LineAlignmentEnum lineAlignment = lineAlignments[index];

              for(int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++)
              {
            LineAlignmentEnum imageAlignment = lineAlignments[imageIndex];

            for(int index2 = 0, length2 = 2; index2 < length2; index2++)
            {
              RectangleF frame = new RectangleF(
                30 + (frameWidth + 5) * imageIndex,
                100 + (frameHeight + 5) * (index * 2 + index2),
                frameWidth,
                frameHeight
                );

              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              {
                composer.SetFont(mainFont, 3);
                blockComposer.ShowText("Text: " + lineAlignment);
                blockComposer.ShowBreak();
                blockComposer.ShowText("Image: " + imageAlignment);
              }
              blockComposer.End();

              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle);
              {
                composer.SetFont(sampleFont, 3);
                blockComposer.ShowText("Previous row boundary.");
                blockComposer.ShowBreak();
                composer.SetFont(sampleFont, index2 == 0 ? 3 : 6);
                blockComposer.ShowText("Alignment:");
                composer.SetFont(sampleFont, index2 == 0 ? 6 : 3);
                blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment);
                blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment);
                blockComposer.ShowBreak();
                composer.SetFont(sampleFont, 3);
                blockComposer.ShowText("Next row boundary.");
              }
              blockComposer.End();

              composer.BeginLocalState();
              {
                composer.SetLineWidth(0.1f);
                composer.SetLineDash(new LineDash(new double[]{1,4}, 4));
                composer.DrawRectangle(blockComposer.Frame);
                composer.Stroke();
              }
              composer.End();

              composer.BeginLocalState();
              {
                composer.SetLineWidth(0.1f);
                composer.SetLineDash(new LineDash(new double[]{1,1}, 1));
                composer.DrawRectangle(blockComposer.BoundBox);
                composer.Stroke();
              }
              composer.End();
            }
              }
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #15
0
        private void BuildTextBlockPage(
            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...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int step;
              {
            XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
            YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
            step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length+1);
              }
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Block alignment");
            blockComposer.End();
              }

              // Drawing the text blocks...
              fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
              int x = 30;
              int y = (int)(step*1.2);
              foreach(XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
              {
            foreach(YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
            {
              composer.SetFont(mainFont, 12);
              composer.ShowText(
            xAlignment + " " + yAlignment + ":",
            new PointF(x,y),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );

              composer.SetFont(sampleFont, 10);
              for(int index = 0; index < 2; index++)
              {
            int frameX;
            switch(index)
            {
              case 0:
                frameX = 150;
                blockComposer.Hyphenation = false;
                break;
              case 1:
                frameX = 360;
                blockComposer.Hyphenation = true;
                break;
              default:
                throw new Exception();
            }

            RectangleF frame = new RectangleF(
              frameX,
              y-step*.4f,
              200,
              step*.8f
              );
            blockComposer.Begin(frame,xAlignment,yAlignment);
            blockComposer.ShowText(
              "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details."
              );
            blockComposer.End();

            composer.BeginLocalState();
            composer.SetLineWidth(0.2f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
            composer.DrawRectangle(frame);
            composer.Stroke();
            composer.End();
              }

              y+=step;
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #16
0
        private void BuildCurvesPage(
            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("Curves");
            blockComposer.End();
              }

              // 3.1. Arcs.
              {
            float y = 100;
            for(
              int rowIndex = 0;
              rowIndex < 4;
              rowIndex++
              )
            {
              int angleStep = 45;
              int startAngle = 0;
              int endAngle = angleStep;
              float x = 100;
              float diameterX;
              float diameterY;
              switch(rowIndex)
              {
            case 0: default:
              diameterX = 40;
              diameterY = 40;
              break;
            case 1:
              diameterX = 40;
              diameterY = 20;
              break;
            case 2:
              diameterX = 20;
              diameterY = 40;
              break;
            case 3:
              diameterX = 40;
              diameterY = 40;
              break;
              }
              for(
            int index = 0,
              length = 360/angleStep;
            index < length;
            index++
            )
              {
            RectangleF arcFrame = new RectangleF((float)x,(float)y,(float)diameterX,(float)diameterY);

            // Drawing the arc frame...
            composer.BeginLocalState();
            composer.SetLineWidth(0.25f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            composer.DrawRectangle(arcFrame);
            composer.Stroke();
            composer.End();

            // Draw the arc!
            composer.DrawArc(arcFrame,startAngle,endAngle);
            composer.Stroke();

            endAngle += angleStep;
            switch(rowIndex)
            {
              case 3:
                startAngle += angleStep;
                break;
            }

            x += 50;
              }

              y += diameterY + 10;
            }
              }

              // 3.2. Circle.
              {
            RectangleF arcFrame = new RectangleF(100, 300, 100, 100);

            // Drawing the circle frame...
            composer.BeginLocalState();
            composer.SetLineWidth(0.25f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            composer.DrawRectangle(arcFrame);
            composer.Stroke();
            composer.End();

            // Drawing the circle...
            composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red));
            composer.DrawEllipse(arcFrame);
            composer.FillStroke();
              }

              // 3.3. Horizontal ellipse.
              {
            RectangleF arcFrame = new RectangleF(210, 300, 100, 50);

            // Drawing the ellipse frame...
            composer.BeginLocalState();
            composer.SetLineWidth(0.25f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            composer.DrawRectangle(arcFrame);
            composer.Stroke();
            composer.End();

            // Drawing the ellipse...
            composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green));
            composer.DrawEllipse(arcFrame);
            composer.FillStroke();
              }

              // 3.4. Vertical ellipse.
              {
            RectangleF arcFrame = new RectangleF(320, 300, 50, 100);

            // Drawing the ellipse frame...
            composer.BeginLocalState();
            composer.SetLineWidth(0.25f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            composer.DrawRectangle(arcFrame);
            composer.Stroke();
            composer.End();

            // Drawing the ellipse...
            composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue));
            composer.DrawEllipse(arcFrame);
            composer.FillStroke();
              }

              // 3.5. Spirals.
              {
            float y = 500;
            float spiralWidth = 100;
            composer.SetLineWidth(.5f);
            for(
              int rowIndex = 0;
              rowIndex < 3;
              rowIndex++
              )
            {
              float x = 150;
              float branchWidth = .5f;
              float branchRatio = 1;
              for(
            int spiralIndex = 0;
            spiralIndex < 4;
            spiralIndex++
            )
              {
            float spiralTurnsCount;
            switch(rowIndex)
            {
              case 0: default:
                spiralTurnsCount = spiralWidth/(branchWidth*8);
                break;
              case 1:
                spiralTurnsCount = (float)(spiralWidth/(branchWidth*8*(spiralIndex*1.15+1)));
                break;
            }
            switch(rowIndex)
            {
              case 2:
                composer.SetLineDash(new LineDash(new double[]{10,5}));
                composer.SetLineCap(LineCapEnum.Round);
                break;
              default:
                break;
            }

            composer.DrawSpiral(
              new PointF((float)x,(float)y),
              0,
              360*spiralTurnsCount,
              branchWidth,
              branchRatio
              );
            composer.Stroke();

            x += spiralWidth + 10;

            switch(rowIndex)
            {
              case 0: default:
                branchWidth += 1;
                break;
              case 1:
                branchRatio += .035f;
                break;
            }
            switch(rowIndex)
            {
              case 2:
                composer.SetLineWidth(composer.State.LineWidth+.5f);
                break;
            }
              }

              y += spiralWidth + 10;
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Example #17
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;
        }
Example #18
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");
              }
        }
Example #19
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;
        }
        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();
        }
Example #21
0
        private FormXObject BuildTemplate(Document document, DateTime creationDate)
        {
            // Create a template (form)!
            FormXObject template     = new FormXObject(document, document.PageSize.Value);
            SKSize      templateSize = template.Size;

            // Get form content stream!
            PrimitiveComposer composer = new PrimitiveComposer(template);

            // Showing the header image inside the common content stream...
            // Instantiate a jpeg image object!
            entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).

            // Show the image inside the common content stream!
            composer.ShowXObject(
                image.ToXObject(document),
                new SKPoint(0, 0),
                new SKSize(templateSize.Width - 50, 125)
                );

            // Showing the 'PdfClown' label inside the common content stream...
            composer.BeginLocalState();
            composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
            // Set the font to use!
            composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Times, true, false), 120);
            // Show the text!
            composer.ShowText(
                "PdfClown",
                new SKPoint(
                    0,
                    templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
                    )
                );

            // Drawing the side rectangle...
            composer.DrawRectangle(
                SKRect.Create(
                    (float)templateSize.Width - 50,
                    0,
                    50,
                    (float)templateSize.Height
                    )
                );
            composer.Fill();
            composer.End();

            // Showing the side text inside the common content stream...
            composer.BeginLocalState();
            {
                composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Helvetica, false, false), 8);
                composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
                composer.BeginLocalState();
                {
                    composer.Rotate(
                        90,
                        new SKPoint(
                            templateSize.Width - 50,
                            templateSize.Height - 25
                            )
                        );
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(
                        SKRect.Create(0, 0, 300, 50),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle
                        );
                    {
                        blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
                        blockComposer.ShowBreak();
                        blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
                    }
                    blockComposer.End();
                }
                composer.End();
            }
            composer.End();

            composer.Flush();

            return(template);
        }
        private void BuildSimpleTextPage(
            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. Inserting contents...
            // Set the font to use!
            composer.SetFont(
                new fonts::StandardType1Font(
                    document,
                    fonts::StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    ),
                32
                );

            XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
            YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
            int step = (int)(pageSize.Height) / ((xAlignments.Length - 1) * yAlignments.Length + 1);

            BlockComposer blockComposer = new BlockComposer(composer);
            RectangleF    frame         = new RectangleF(
                30,
                0,
                pageSize.Width - 60,
                step / 2
                );

            blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            blockComposer.ShowText("Simple alignment");
            blockComposer.End();

            frame = new RectangleF(
                30,
                pageSize.Height - step / 2,
                pageSize.Width - 60,
                step / 2 - 10
                );
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            composer.SetFont(composer.State.Font, 10);
            blockComposer.ShowText(
                "NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
                + "NOTE: The rotation parameter can be freely defined as a floating point value."
                );
            blockComposer.End();

            composer.SetFont(composer.State.Font, 12);
            int x = 30;
            int y = step;
            int alignmentIndex = 0;

            foreach (XAlignmentEnum xAlignment
                     in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
                /*
                 * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
                 * applying the justified alignment has no effect (it degrades to center alignment);
                 * in order to get such an effect, use BlockComposer instead.
                 */
                if (xAlignment.Equals(XAlignmentEnum.Justify))
                {
                    continue;
                }

                foreach (YAlignmentEnum yAlignment
                         in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                {
                    if (alignmentIndex % 2 == 0)
                    {
                        composer.BeginLocalState();
                        composer.SetFillColor(BackColor);
                        composer.DrawRectangle(
                            new RectangleF(
                                0,
                                y - step / 2,
                                pageSize.Width,
                                step
                                )
                            );
                        composer.Fill();
                        composer.End();
                    }

                    composer.ShowText(
                        xAlignment + " " + yAlignment + ":",
                        new PointF(x, y),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle,
                        0
                        );

                    y += step;
                    alignmentIndex++;
                }
            }

            float rotationStep = 0;
            float rotation     = 0;

            for (
                int columnIndex = 0;
                columnIndex < 2;
                columnIndex++
                )
            {
                switch (columnIndex)
                {
                case 0:
                    x            = 200;
                    rotationStep = 0;
                    break;

                case 1:
                    x            = (int)pageSize.Width / 2 + 100;
                    rotationStep = 360 / ((xAlignments.Length - 1) * yAlignments.Length - 1);
                    break;
                }
                y        = step;
                rotation = 0;
                foreach (XAlignmentEnum xAlignment
                         in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
                {
                    /*
                     * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
                     * applying the justified alignment has no effect (it degrades to center alignment);
                     * in order to get such an effect, use BlockComposer instead.
                     */
                    if (xAlignment.Equals(XAlignmentEnum.Justify))
                    {
                        continue;
                    }

                    foreach (YAlignmentEnum yAlignment
                             in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                    {
                        float startArcAngle = 0;
                        switch (xAlignment)
                        {
                        case XAlignmentEnum.Left:
                            // OK -- NOOP.
                            break;

                        case XAlignmentEnum.Right:
                        case XAlignmentEnum.Center:
                            startArcAngle = 180;
                            break;
                        }

                        composer.DrawArc(
                            new RectangleF(
                                x - 10,
                                y - 10,
                                20,
                                20
                                ),
                            startArcAngle,
                            startArcAngle + rotation
                            );

                        DrawText(
                            composer,
                            "PDF Clown",
                            new PointF(x, y),
                            xAlignment,
                            yAlignment,
                            rotation
                            );
                        y        += step;
                        rotation += rotationStep;
                    }
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Example #23
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();
                    }
                }
            }
        }
Example #24
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();
        }
        private void BuildCurvesPage(
            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("Curves");
                blockComposer.End();
            }

            // 3.1. Arcs.
            {
                float y = 100;
                for (
                    int rowIndex = 0;
                    rowIndex < 4;
                    rowIndex++
                    )
                {
                    int   angleStep  = 45;
                    int   startAngle = 0;
                    int   endAngle   = angleStep;
                    float x          = 100;
                    float diameterX;
                    float diameterY;
                    switch (rowIndex)
                    {
                    case 0:
                    default:
                        diameterX = 40;
                        diameterY = 40;
                        break;

                    case 1:
                        diameterX = 40;
                        diameterY = 20;
                        break;

                    case 2:
                        diameterX = 20;
                        diameterY = 40;
                        break;

                    case 3:
                        diameterX = 40;
                        diameterY = 40;
                        break;
                    }
                    for (
                        int index = 0,
                        length = 360 / angleStep;
                        index < length;
                        index++
                        )
                    {
                        RectangleF arcFrame = new RectangleF((float)x, (float)y, (float)diameterX, (float)diameterY);

                        // Drawing the arc frame...
                        composer.BeginLocalState();
                        composer.SetLineWidth(0.25f);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                        composer.DrawRectangle(arcFrame);
                        composer.Stroke();
                        composer.End();

                        // Draw the arc!
                        composer.DrawArc(arcFrame, startAngle, endAngle);
                        composer.Stroke();

                        endAngle += angleStep;
                        switch (rowIndex)
                        {
                        case 3:
                            startAngle += angleStep;
                            break;
                        }

                        x += 50;
                    }

                    y += diameterY + 10;
                }
            }

            // 3.2. Circle.
            {
                RectangleF arcFrame = new RectangleF(100, 300, 100, 100);

                // Drawing the circle frame...
                composer.BeginLocalState();
                composer.SetLineWidth(0.25f);
                composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                composer.DrawRectangle(arcFrame);
                composer.Stroke();
                composer.End();

                // Drawing the circle...
                composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red));
                composer.DrawEllipse(arcFrame);
                composer.FillStroke();
            }

            // 3.3. Horizontal ellipse.
            {
                RectangleF arcFrame = new RectangleF(210, 300, 100, 50);

                // Drawing the ellipse frame...
                composer.BeginLocalState();
                composer.SetLineWidth(0.25f);
                composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                composer.DrawRectangle(arcFrame);
                composer.Stroke();
                composer.End();

                // Drawing the ellipse...
                composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green));
                composer.DrawEllipse(arcFrame);
                composer.FillStroke();
            }

            // 3.4. Vertical ellipse.
            {
                RectangleF arcFrame = new RectangleF(320, 300, 50, 100);

                // Drawing the ellipse frame...
                composer.BeginLocalState();
                composer.SetLineWidth(0.25f);
                composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                composer.DrawRectangle(arcFrame);
                composer.Stroke();
                composer.End();

                // Drawing the ellipse...
                composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue));
                composer.DrawEllipse(arcFrame);
                composer.FillStroke();
            }

            // 3.5. Spirals.
            {
                float y           = 500;
                float spiralWidth = 100;
                composer.SetLineWidth(.5f);
                for (
                    int rowIndex = 0;
                    rowIndex < 3;
                    rowIndex++
                    )
                {
                    float x           = 150;
                    float branchWidth = .5f;
                    float branchRatio = 1;
                    for (
                        int spiralIndex = 0;
                        spiralIndex < 4;
                        spiralIndex++
                        )
                    {
                        float spiralTurnsCount;
                        switch (rowIndex)
                        {
                        case 0:
                        default:
                            spiralTurnsCount = spiralWidth / (branchWidth * 8);
                            break;

                        case 1:
                            spiralTurnsCount = (float)(spiralWidth / (branchWidth * 8 * (spiralIndex * 1.15 + 1)));
                            break;
                        }
                        switch (rowIndex)
                        {
                        case 2:
                            composer.SetLineDash(new LineDash(new double[] { 10, 5 }));
                            composer.SetLineCap(LineCapEnum.Round);
                            break;

                        default:
                            break;
                        }

                        composer.DrawSpiral(
                            new PointF((float)x, (float)y),
                            0,
                            360 * spiralTurnsCount,
                            branchWidth,
                            branchRatio
                            );
                        composer.Stroke();

                        x += spiralWidth + 10;

                        switch (rowIndex)
                        {
                        case 0:
                        default:
                            branchWidth += 1;
                            break;

                        case 1:
                            branchRatio += .035f;
                            break;
                        }
                        switch (rowIndex)
                        {
                        case 2:
                            composer.SetLineWidth(composer.State.LineWidth + .5f);
                            break;
                        }
                    }

                    y += spiralWidth + 10;
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Example #26
0
        public override ContentObject ToInlineObject(
      PrimitiveComposer composer
      )
        {
            ContentObject barcodeObject = composer.BeginLocalState();
              {
            fonts::Font font = new fonts::StandardType1Font(
              composer.Scanner.Contents.Document,
              fonts::StandardType1Font.FamilyEnum.Helvetica,
              false,
              false
              );
            double fontSize = (DigitGlyphWidth / font.GetWidth(code.Substring(0,1), 1));

            // 1. Bars.
            {
              double elementX = DigitWidth;
              int[] elementWidths = GetElementWidths();

              double guardBarIndentY = DigitHeight / 2;
              bool isBar = true;
              for(
            int elementIndex = 0;
            elementIndex < elementWidths.Length;
            elementIndex++
            )
              {
            double elementWidth = elementWidths[elementIndex];
            // Dark element?
            /*
              NOTE: EAN symbol elements alternate bars to spaces.
            */
            if(isBar)
            {
              composer.DrawRectangle(
                new RectangleF(
                  (float)elementX,
                  0,
                  (float)elementWidth,
                  (float)(BarHeight + (
                    // Guard bar?
                    Array.BinarySearch<int>(GuardBarIndexes, elementIndex) >= 0
                      ? guardBarIndentY // Guard bar.
                      : 0 // Symbol character.
                    ))
                  )
                );
            }

            elementX += elementWidth;
            isBar = !isBar;
              }
              composer.Fill();
            }

            // 2. Digits.
            {
              composer.SetFont(font,fontSize);
              double digitY = BarHeight + (DigitHeight - (font.GetAscent(fontSize))) / 2;
              // Showing the digits...
              for(
            int digitIndex = 0;
            digitIndex < 13;
            digitIndex++
            )
              {
            string digit = code.Substring(digitIndex, 1);
            double pX = DigitGlyphXs[digitIndex] // Digit position.
              - font.GetWidth(digit,fontSize) / 2; // Centering.
            // Show the current digit!
            composer.ShowText(
              digit,
              new PointF((float)pX,(float)digitY)
              );
              }
            }
            composer.End();
              }
              return barcodeObject;
        }
        private void BuildTextBlockPage(
            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...
            fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int         step;
            {
                XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
                YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
                step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length + 1);
            }
            BlockComposer blockComposer = new BlockComposer(composer);
            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Block alignment");
                blockComposer.End();
            }

            // Drawing the text blocks...
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            int         x          = 30;
            int         y          = (int)(step * 1.2);

            foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
                foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                {
                    composer.SetFont(mainFont, 12);
                    composer.ShowText(
                        xAlignment + " " + yAlignment + ":",
                        new PointF(x, y),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle,
                        0
                        );

                    composer.SetFont(sampleFont, 10);
                    for (int index = 0; index < 2; index++)
                    {
                        int frameX;
                        switch (index)
                        {
                        case 0:
                            frameX = 150;
                            blockComposer.Hyphenation = false;
                            break;

                        case 1:
                            frameX = 360;
                            blockComposer.Hyphenation = true;
                            break;

                        default:
                            throw new Exception();
                        }

                        RectangleF frame = new RectangleF(
                            frameX,
                            y - step * .4f,
                            200,
                            step * .8f
                            );
                        blockComposer.Begin(frame, xAlignment, yAlignment);
                        blockComposer.ShowText(
                            "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details."
                            );
                        blockComposer.End();

                        composer.BeginLocalState();
                        composer.SetLineWidth(0.2f);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                        composer.DrawRectangle(frame);
                        composer.Stroke();
                        composer.End();
                    }

                    y += step;
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Example #28
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();
                }
            }
        }
        private void BuildTextBlockPage3(
            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...
            fonts::Font mainFont  = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int         stepCount = 5;
            int         step      = (int)(pageSize.Height) / (stepCount + 1);

            // 3.1. Drawing the page title...
            BlockComposer blockComposer = new BlockComposer(composer);
            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Block line space");
                blockComposer.End();
            }

            // 3.2. Drawing the text blocks...
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            int         x          = 30;
            int         y          = (int)(step * 1.1);

            blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative;
            for (int index = 0; index < stepCount; index++)
            {
                float relativeLineSpace = 0.5f * index;
                blockComposer.LineSpace.Value = relativeLineSpace;

                composer.SetFont(mainFont, 12);
                composer.ShowText(
                    relativeLineSpace + ":",
                    new PointF(x, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );

                composer.SetFont(sampleFont, 10);
                RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f);
                blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\").");
                blockComposer.End();

                composer.BeginLocalState();
                {
                    composer.SetLineWidth(0.2);
                    composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                    composer.DrawRectangle(frame);
                    composer.Stroke();
                }
                composer.End();

                y += step;
            }

            // 4. Flush the contents into the page!
            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);
        }
Example #31
0
        public override ContentObject ToInlineObject(PrimitiveComposer composer)
        {
            ContentObject barcodeObject = composer.BeginLocalState();

            {
                fonts::Font font     = fonts::PdfType1Font.Load(composer.Scanner.Contents.Document, fonts::PdfType1Font.FamilyEnum.Helvetica, false, false);
                double      fontSize = (DigitGlyphWidth / font.GetWidth(code.Substring(0, 1), 1));

                // 1. Bars.
                {
                    double elementX      = DigitWidth;
                    int[]  elementWidths = GetElementWidths();

                    double guardBarIndentY = DigitHeight / 2;
                    bool   isBar           = true;
                    for (int elementIndex = 0; elementIndex < elementWidths.Length; elementIndex++)
                    {
                        double elementWidth = elementWidths[elementIndex];
                        // Dark element?

                        /*
                         * NOTE: EAN symbol elements alternate bars to spaces.
                         */
                        if (isBar)
                        {
                            composer.DrawRectangle(
                                SKRect.Create(
                                    (float)elementX,
                                    0,
                                    (float)elementWidth,
                                    (float)(BarHeight + (
                                                // Guard bar?
                                                Array.BinarySearch <int>(GuardBarIndexes, elementIndex) >= 0
                                    ? guardBarIndentY // Guard bar.
                                    : 0               // Symbol character.
                                                ))
                                    )
                                );
                        }

                        elementX += elementWidth;
                        isBar     = !isBar;
                    }
                    composer.Fill();
                }

                // 2. Digits.
                {
                    composer.SetFont(font, fontSize);
                    double digitY = BarHeight + (DigitHeight - (font.GetAscent(fontSize))) / 2;
                    // Showing the digits...
                    for (int digitIndex = 0; digitIndex < 13; digitIndex++)
                    {
                        string digit = code.Substring(digitIndex, 1);
                        double pX    = DigitGlyphXs[digitIndex]              // Digit position.
                                       - font.GetWidth(digit, fontSize) / 2; // Centering.
                                                                             // Show the current digit!
                        composer.ShowText(
                            digit,
                            new SKPoint((float)pX, (float)digitY)
                            );
                    }
                }
                composer.End();
            }
            return(barcodeObject);
        }
Example #32
0
        private FormXObject BuildTemplate(
            Document document,
            DateTime creationDate
            )
        {
            // Create a template (form)!
              FormXObject template = new FormXObject(document, document.PageSize.Value);
              SizeF templateSize = template.Size;

              // Get form content stream!
              PrimitiveComposer composer = new PrimitiveComposer(template);

              // Showing the header image inside the common content stream...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).
              // Show the image inside the common content stream!
              composer.ShowXObject(
            image.ToXObject(document),
            new PointF(0,0),
            new SizeF(templateSize.Width - 50, 125)
            );

              // Showing the 'PDFClown' label inside the common content stream...
              composer.BeginLocalState();
              composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Times,
              true,
              false
              ),
            120
            );
              // Show the text!
              composer.ShowText(
            "PDFClown",
            new PointF(
              0,
              templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
              )
            );

              // Drawing the side rectangle...
              composer.DrawRectangle(
            new RectangleF(
              (float)templateSize.Width - 50,
              0,
              50,
              (float)templateSize.Height
              )
            );
              composer.Fill();
              composer.End();

              // Showing the side text inside the common content stream...
              composer.BeginLocalState();
              {
            composer.SetFont(
              new fonts::StandardType1Font(
            document,
            fonts::StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              8
              );
            composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
            composer.BeginLocalState();
            {
              composer.Rotate(
            90,
            new PointF(
              templateSize.Width - 50,
              templateSize.Height - 25
              )
            );
              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(
            new RectangleF(0,0,300,50),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle
            );
              {
            blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
            blockComposer.ShowBreak();
            blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
              }
              blockComposer.End();
            }
            composer.End();
              }
              composer.End();

              composer.Flush();

              return template;
        }