Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }