Exemplo n.º 1
0
        private void DrawText(PrimitiveComposer composer, string value, SKPoint location, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, float rotation)
        {
            // Show the anchor point!
            DrawCross(composer, location);

            composer.BeginLocalState();
            composer.SetFillColor(SampleColor);
            // Show the text onto the page!
            Quad textFrame = composer.ShowText(
                value,
                location,
                xAlignment,
                yAlignment,
                rotation);

            composer.End();

            // Draw the frame binding the shown text!
            DrawFrame(composer, textFrame.GetPoints());

            composer.BeginLocalState();
            composer.SetFont(composer.State.Font, 8);
            // Draw the rotation degrees!
            composer.ShowText(
                "(" + ((int)rotation) + " degrees)",
                new SKPoint(location.X + 70, location.Y),
                XAlignmentEnum.Left,
                YAlignmentEnum.Middle,
                0
                );
            composer.End();
        }
Exemplo n.º 2
0
        /**
         * <summary>Begins a content block.</summary>
         * <param name="frame">Block boundaries.</param>
         * <param name="xAlignment">Horizontal alignment.</param>
         * <param name="yAlignment">Vertical alignment.</param>
         */
        public void Begin(
            RectangleF frame,
            XAlignmentEnum xAlignment,
            YAlignmentEnum yAlignment
            )
        {
            this.frame      = frame;
            this.xAlignment = xAlignment;
            this.yAlignment = yAlignment;
            lastFontSize    = 0;

            // Open the block local state!

            /*
             * NOTE: This device allows a fine-grained control over the block representation.
             * It MUST be coupled with a closing statement on block end.
             */
            container = baseComposer.BeginLocalState();

            boundBox = new RectangleF(
                frame.X,
                frame.Y,
                frame.Width,
                0
                );

            BeginRow();
        }
Exemplo n.º 3
0
        /**
         * <summary>Begins a content block.</summary>
         */
        public void Begin(
            RectangleF frame,
            AlignmentXEnum alignmentX,
            AlignmentYEnum alignmentY
            )
        {
            this.frame      = frame;
            this.alignmentX = alignmentX;
            this.alignmentY = alignmentY;

            // Open the block local state!

            /*
             * NOTE: This device allows a fine-grained control over the block representation.
             * It MUST be coupled with a closing statement on block end.
             */
            container = baseComposer.BeginLocalState();

            boundBox = new RectangleF(
                frame.X,
                frame.Y,
                frame.Width,
                0
                );

            BeginRow();
        }
Exemplo n.º 4
0
        public BlocoQrCodeNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y, Document context) : base(estilo)
        {
            var result = new MemoryStream();

            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("CONSULTA VIA LEITOR DE QR CODE", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            var bitmap = GerarQrCode.GerarQRCode(viewModel.QrCode);

            bitmap.Save(result, ImageFormat.Jpeg);
            result.Position = 0;
            org.pdfclown.documents.contents.entities.Image   image        = org.pdfclown.documents.contents.entities.Image.Get(result);
            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(context);

            primitiveComposer.ShowXObject(imageXObject, new PointF(140, y + 20), new SizeF(150, 150), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            if (viewModel.CalculoImposto.ValorAproximadoTributos > 0)
            // valor aproximado dos tributos
            {
                primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, 7);

                primitiveComposer.ShowText($"CONFORME LEI 12.741/2012 o valor aproximado dos tributos é {viewModel.CalculoImposto.ValorAproximadoTributos.Formatar()}", new PointF(140, y + 180), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Federais é {viewModel.CalculoImposto.ValorAproximadoTributosFederais.Formatar()}", new PointF(140, y + 190), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Estaduais é {viewModel.CalculoImposto.ValorAproximadoTributosEstaduais.Formatar()}", new PointF(140, y + 200), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            }
        }
Exemplo n.º 5
0
        public BlocoFormaPagamentoNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("FORMAS DE PAGAMENTO", new PointF(25, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText("VALOR PAGO", new PointF(250, y + 10), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //primitiveComposer.ShowText("Troco", new PointF(160, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);

            y = y + 10;

            foreach (var item in viewModel.Pagamento)
            {
                foreach (var detalhe in item.DetalhePagamento)
                {
                    y = y + 10;

                    primitiveComposer.ShowText(detalhe.FormaPagamento.FormaPagamentoToString(), new PointF(25, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
                    primitiveComposer.ShowText(detalhe.Valor.Formatar(), new PointF(250, y), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                }
            }

            Y_NFC = y + 10;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Renderiza o bloco para um XObject.
        /// </summary>
        public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject()
        {
            if (_RenderedObject == null)
            {
                _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size);

                PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject);
                var obj = composer.BeginLocalState();
                composer.SetLineWidth(DanfeDocumento.LineWidth);

                if (PossuiCabecalho)
                {
                    RectangleF rect = GetHeaderInnerRectangle();
                    //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho);
                    PrintCabecalho(composer);
                }

                ToXObjectInternal(composer);

                foreach (var campo in Campos)
                {
                    campo.Print(composer, Danfe.Font, Danfe.FontBold);
                }

                composer.Stroke();

                composer.End();
                composer.Flush();
            }

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

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

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

                        // Drawing text string bounding box...
                        composer.BeginLocalState();
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }));
                        composer.SetStrokeColor(textStringBoxColor);
                        composer.DrawRectangle(textString.Box.Value);
                        composer.Stroke();
                        composer.End();
                    }
                }
                else if (content is ContainerObject)
                {
                    // Scan the inner level!
                    Extract(level.ChildLevel, composer);
                }
            }
        }
Exemplo n.º 8
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;
        }
        public BlocoDestinatarioRemetenteNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(viewModel, estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);

            if (viewModel.Destinatario != null && !string.IsNullOrWhiteSpace(viewModel?.Destinatario?.CnpjCpf))
            {
                var dest = viewModel?.Destinatario;

                primitiveComposer.ShowText("CONSUMIDOR", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                if (!string.IsNullOrWhiteSpace(dest.RazaoSocial))
                {
                    if (dest.RazaoSocial.Length > 30)
                    {
                        primitiveComposer.ShowText(dest.RazaoSocial.Substring(0, 30), new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                        primitiveComposer.ShowText(dest.RazaoSocial.Substring(30), new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                        y = y + 10;
                    }
                    else
                    {
                        primitiveComposer.ShowText($"NOME: {dest.RazaoSocial}", new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                    }
                }

                primitiveComposer.ShowText($"CNPJ/CPF: {dest.CnpjCpf}", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);


                if (!string.IsNullOrWhiteSpace(dest.EnderecoLogadrouro) &&
                    !string.IsNullOrWhiteSpace(dest.EnderecoNumero) &&
                    !string.IsNullOrWhiteSpace(dest.EnderecoBairro) &&
                    !string.IsNullOrWhiteSpace(dest.Municipio))
                {
                    primitiveComposer.ShowText($"{dest.EnderecoLogadrouro}, {dest.EnderecoNumero}, {dest.EnderecoBairro}, {dest.Municipio} - {dest.EnderecoUf}", new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                }

                Y_NFC = y + 50;

                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
            else
            {
                primitiveComposer.ShowText("CONSUMIDOR NÃO IDENTIFICADO", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                Y_NFC = y + 20;

                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
        }
Exemplo n.º 10
0
 private void DrawFrame(PrimitiveComposer composer, SKPoint[] frameVertices)
 {
     composer.BeginLocalState();
     composer.SetLineWidth(0.2f);
     composer.SetLineDash(new LineDash(new float[] { 5 }, 5));
     composer.DrawPolygon(frameVertices);
     composer.Stroke();
     composer.End();
 }
Exemplo n.º 11
0
        private void Apply(
            PushButton field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

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

            FormXObject normalAppearanceState;

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

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

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

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 12
0
        public BlocoIdentificacaoEmitenteNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer) : base(viewModel, estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            int y = 0;

            var emitente = viewModel.Emitente;

            if (emitente.RazaoSocial.Length > 39)
            {
                primitiveComposer.ShowText(emitente.RazaoSocial.Substring(0, 39), new PointF(140, 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                primitiveComposer.ShowText(emitente.RazaoSocial.Substring(39), new PointF(140, 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                primitiveComposer.ShowText($"CNPJ - {Formatador.FormatarCnpj(emitente.CnpjCpf)}", new PointF(140, 30), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                y = 30;
            }
            else
            {
                primitiveComposer.ShowText(emitente.RazaoSocial, new PointF(140, 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                primitiveComposer.ShowText($"CNPJ - {Formatador.FormatarCnpj(emitente.CnpjCpf)}", new PointF(140, 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                y = 20;
            }

            primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteCampoConteudoNegrito.Tamanho);

            if (!string.IsNullOrWhiteSpace(emitente.EnderecoLogadrouro) &&
                !string.IsNullOrWhiteSpace(emitente.EnderecoNumero) &&
                !string.IsNullOrWhiteSpace(emitente.EnderecoBairro) &&
                !string.IsNullOrWhiteSpace(emitente.Municipio))
            {
                if (emitente.EnderecoLogadrouro.Length >= 25)
                {
                    primitiveComposer.ShowText($"{emitente.EnderecoLogadrouro.Substring(0, 25)}, {emitente.EnderecoNumero} - {emitente.EnderecoBairro} - {emitente.Municipio} - {emitente.EnderecoUf}",
                                               new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                }
                else
                {
                    primitiveComposer.ShowText($"{emitente.EnderecoLogadrouro}, {emitente.EnderecoNumero} - {emitente.EnderecoBairro} - {emitente.Municipio} - {emitente.EnderecoUf}",
                                               new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                }
            }
            primitiveComposer.DrawLine(new PointF(15, y + 20), new PointF(265, y + 20));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            primitiveComposer.Stroke();
            primitiveComposer.End();

            Y_NFC = y + 20;
        }
Exemplo n.º 13
0
        public BlocoProdutoServicoTotalNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();

            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("QNT. TOTAL DE ITENS", new PointF(25, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.QuantidadeTotal.ToString(), new PointF(250, y + 10), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            primitiveComposer.ShowText("VALOR DOS PRODUTOS", new PointF(25, y + 20), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorTotalProdutos.Formatar(), new PointF(250, y + 20), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            //if (viewModel.CalculoImposto.ValorFrete > 0)
            //{
            primitiveComposer.ShowText("Valor do Frete", new PointF(25, y + 30), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorFrete.Formatar(), new PointF(250, y + 30), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.ValorSeguro > 0)
            //{
            primitiveComposer.ShowText("Valor do Seguro", new PointF(25, y + 40), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorSeguro.Formatar(), new PointF(250, y + 40), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.OutrasDespesas > 0)
            //{
            primitiveComposer.ShowText("OUTRAS DESPESAS", new PointF(25, y + 50), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.OutrasDespesas.Formatar(), new PointF(250, y + 50), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.Desconto > 0)
            //{
            primitiveComposer.ShowText("DESCONTO (-)", new PointF(25, y + 60), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.Desconto.Formatar(), new PointF(250, y + 60), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            primitiveComposer.ShowText("VALOR TOTAL", new PointF(25, y + 70), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorTotalNota.Formatar(), new PointF(250, y + 70), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 80;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
Exemplo n.º 14
0
        public BlocoConsultaChaveNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("Consulta pela chave de acesso em", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.EndConsulta, new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText("CHAVE DE ACESSO", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.ChaveAcesso, new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 50;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
Exemplo n.º 15
0
        public BlocoInformacaoFiscal(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            if (viewModel.TipoAmbiente == 2)
            {
                primitiveComposer.BeginLocalState();
                primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteTamanhoMinimo + 1);
                primitiveComposer.ShowText("EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO - SEM VALOR FISCAL", new PointF(132.5F, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                Y_NFC = y + 20;
                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
            else
            {
                Y_NFC = y;
            }
        }
Exemplo n.º 16
0
        protected override void ToXObjectInternal(PrimitiveComposer composer)
        {
            EmpresaViewModel empresa = null;

            if (Danfe.Model.TipoNF == 1)
            {
                empresa = Danfe.Model.Emitente;
            }
            else if (Danfe.Model.TipoNF == 0)
            {
                empresa = Danfe.Model.Destinatario;
            }
            else
            {
                throw new Exception("Tipo de NF não suportado.");
            }

            BlockComposer bComp = new BlockComposer(composer);

            composer.SafeDrawRectangle(RetNumeracao);
            composer.SafeDrawRectangle(RetRecebemos);

            composer.SetFont(Danfe.Font, 6);
            bComp.SafeBegin(RetRecebemos.GetPaddedRectangleMm(1), XAlignmentEnum.Left, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("RECEBEMOS DE {0} OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO.", empresa.Nome));
            bComp.End();

            // Numeração da NFe
            composer.SafeDrawRectangle(RetNumeracao);
            composer.SetFont(Danfe.FontBold, 12);
            bComp.SafeBegin(RetNumeracao, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("NF-e\nNº {0}\nSérie {1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();

            composer.Stroke();

            // Linha pontilhada
            composer.BeginLocalState();
            composer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            composer.DrawLine(new PointF(InternalRectangle.Left, Size.Height - MargemLinhaPontilhada), new PointF(InternalRectangle.Right, Size.Height - MargemLinhaPontilhada));
            composer.Stroke();
            composer.End();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Print as linhas tracejadas na tabela, ignorando a última
        /// </summary>
        /// <param name="composer"></param>
        /// <param name="y">Lista com as posições y</param>
        /// <param name="xBegin"></param>
        /// <param name="xEnd"></param>
        private void PrintLinhasTracejadas(PrimitiveComposer composer, List <float> y, float xBegin, float xEnd)
        {
            if (xBegin < 0)
            {
                throw new ArgumentOutOfRangeException("xBegin");
            }

            if (xEnd > composer.Scanner.CanvasSize.Width)
            {
                throw new ArgumentOutOfRangeException("xEnd");
            }

            composer.BeginLocalState();
            composer.SetLineDash(new LineDash(new Double[] { 3, 2 }));
            for (int i = 0; i < y.Count - 1; i++)
            {
                composer.DrawLine(new PointF(xBegin, y[i]), new PointF(xEnd, y[i]));
            }

            composer.Stroke();
            composer.End();
        }
Exemplo n.º 18
0
        public BlocoIdentificacaoNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();

            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            primitiveComposer.ShowText($"Nº: {viewModel?.NfNumero}  Série: {viewModel?.NfSerie}", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteCampoConteudoNegrito.Tamanho);
            primitiveComposer.ShowText($"{viewModel?.DataHoraEmissao} - Via Consumidor", new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("PROTOCOLO DE AUTORIZAÇÃO", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText($"{viewModel.ProtocoloAutorizacao}", new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 50;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
Exemplo n.º 19
0
        private void PrintMarcaDAgua(String text)
        {
            PointF p = PointF.Empty;

            var blocoProdutos = BlocosSuperiores.FirstOrDefault(x => x is BlocoProdutos);

            if (blocoProdutos == null)
            {
                p = new PointF(_Danfe.Size.Width / 2f, _Danfe.Size.Height / 2f);
            }
            else
            {
                p.X = blocoProdutos.Posicao.X + blocoProdutos.Size.Width / 2F;
                p.Y = blocoProdutos.Posicao.Y + blocoProdutos.Size.Height / 2F;
            }

            _Composer.BeginLocalState();
            _Composer.SetFont(_Danfe.FontBold, 50);
            org.pdfclown.documents.contents.ExtGState state = new org.pdfclown.documents.contents.ExtGState(_Danfe.Document);
            state.FillAlpha = 0.3F;
            _Composer.ApplyState(state);
            _Composer.ShowText(text, p, XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            _Composer.End();
        }
Exemplo n.º 20
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);
              document.Pages.Add(page);

              PrimitiveComposer composer = new PrimitiveComposer(page);
              StandardType1Font font = new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Courier,
            true,
            false
            );
              composer.SetFont(font,12);

              // Note.
              composer.ShowText("Note annotation:", new Point(35,35));
              annotations::Note note = new annotations::Note(
            page,
            new Point(50, 50),
            "Note annotation"
            );
              note.IconType = annotations::Note.IconTypeEnum.Help;
              note.ModificationDate = new DateTime();
              note.IsOpen = true;

              // Callout.
              composer.ShowText("Callout note annotation:", new Point(35,85));
              annotations::CalloutNote calloutNote = new annotations::CalloutNote(
            page,
            new Rectangle(50, 100, 200, 24),
            "Callout note annotation"
            );
              calloutNote.Justification = JustificationEnum.Right;
              calloutNote.Line = new annotations::CalloutNote.LineObject(
            page,
            new Point(150,650),
            new Point(100,600),
            new Point(50,100)
            );

              // File attachment.
              composer.ShowText("File attachment annotation:", new Point(35,135));
              annotations::FileAttachment attachment = new annotations::FileAttachment(
            page,
            new Rectangle(50, 150, 12, 12),
            "File attachment annotation",
            FileSpecification.Get(
              EmbeddedFile.Get(
            document,
            GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")
            ),
              "happyGNU.jpg"
              )
            );
              attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

              composer.BeginLocalState();

              // Arrow line.
              composer.ShowText("Line annotation:", new Point(35,185));
              composer.SetFont(font,10);
              composer.ShowText("Arrow:", new Point(50,200));
              annotations::Line line = new annotations::Line(
            page,
            new Point(50, 260),
            new Point(200,210),
            "Arrow line annotation"
            );
              line.FillColor = new DeviceRGBColor(1,0,0);
              line.StartStyle = annotations::Line.LineEndStyleEnum.Circle;
              line.EndStyle = annotations::Line.LineEndStyleEnum.ClosedArrow;
              line.CaptionVisible = true;

              // Dimension line.
              composer.ShowText("Dimension:", new Point(300,200));
              line = new annotations::Line(
            page,
            new Point(300,220),
            new Point(500,220),
            "Dimension line annotation"
            );
              line.LeaderLineLength = 20;
              line.LeaderLineExtensionLength = 10;
              line.CaptionVisible = true;

              composer.End();

              // Scribble.
              composer.ShowText("Scribble annotation:", new Point(35,285));
              new annotations::Scribble(
            page,
            new RectangleF(50, 300, 100, 30),
            "Scribble annotation",
            new List<IList<PointF>>(
              new List<PointF>[]
              {
            new List<PointF>(
              new PointF[]
              {
                new PointF(50,300),
                new PointF(70,310),
                new PointF(100,320)
              }
              )
              }
              )
            );

              // Rectangle.
              composer.ShowText("Rectangle annotation:", new Point(35,335));
              annotations::Rectangle rectangle = new annotations::Rectangle(
            page,
            new Rectangle(50, 350, 100, 30),
            "Rectangle annotation"
            );
              rectangle.FillColor = new DeviceRGBColor(1,0,0);
              rectangle.Alpha = .25;

              // Ellipse.
              composer.ShowText("Ellipse annotation:", new Point(35,385));
              annotations::Ellipse ellipse = new annotations::Ellipse(
            page,
            new Rectangle(50, 400, 100, 30),
            "Ellipse annotation"
            );
              ellipse.FillColor = new DeviceRGBColor(0,0,1);

              // Rubber stamp.
              composer.ShowText("Rubber stamp annotation:", new Point(35,435));
              new annotations::RubberStamp(
            page,
            new Rectangle(50, 450, 100, 30),
            "Rubber stamp annotation",
            annotations::RubberStamp.IconTypeEnum.Approved
            );

              // Caret.
              composer.ShowText("Caret annotation:", new Point(35,485));
              annotations::Caret caret = new annotations::Caret(
            page,
            new Rectangle(50, 500, 100, 30),
            "Caret annotation"
            );
              caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph;

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

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

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

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

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

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
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();
        }
Exemplo n.º 24
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();
                    }
                }
            }
        }
Exemplo n.º 25
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.º 26
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

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

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

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

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

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

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

              composer.Stroke();

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

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

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

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

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

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

            y += 30;
              }

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

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

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

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

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Exemplo n.º 27
0
        private void Populate(Document document)
        {
            Page page = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer        composer = new PrimitiveComposer(page);
            fonts::StandardType1Font font     = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);

            composer.SetFont(font, 12);

            // Sticky note.
            composer.ShowText("Sticky note annotation:", new SKPoint(35, 35));
            new StickyNote(page, new SKPoint(50, 50), "Text of the Sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Note,
                Color    = DeviceRGBColor.Get(SKColors.Yellow),
                Popup    = new Popup(
                    page,
                    SKRect.Create(200, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    ),
                Author  = "Stefano",
                Subject = "Sticky note",
                IsOpen  = true
            };
            new StickyNote(page, new SKPoint(80, 50), "Text of the Help sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Help,
                Color    = DeviceRGBColor.Get(SKColors.Pink),
                Author   = "Stefano",
                Subject  = "Sticky note",
                Popup    = new Popup(
                    page,
                    SKRect.Create(400, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };
            new StickyNote(page, new SKPoint(110, 50), "Text of the Comment sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Comment,
                Color    = DeviceRGBColor.Get(SKColors.Green),
                Author   = "Stefano",
                Subject  = "Sticky note"
            };
            new StickyNote(page, new SKPoint(140, 50), "Text of the Key sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Key,
                Color    = DeviceRGBColor.Get(SKColors.Blue),
                Author   = "Stefano",
                Subject  = "Sticky note"
            };

            // Callout.
            composer.ShowText("Callout note annotation:", new SKPoint(35, 85));
            new FreeText(page, SKRect.Create(250, 90, 150, 70), "Text of the Callout note annotation")
            {
                Line = new FreeText.CalloutLine(
                    page,
                    new SKPoint(100, 100),
                    new SKPoint(150, 125),
                    new SKPoint(250, 125)
                    ),
                Type         = FreeText.TypeEnum.Callout,
                LineEndStyle = LineEndStyleEnum.OpenArrow,
                Border       = new Border(1),
                Color        = DeviceRGBColor.Get(SKColors.Yellow)
            };

            // File attachment.
            composer.ShowText("File attachment annotation:", new SKPoint(35, 135));
            new FileAttachment(
                page,
                SKRect.Create(50, 150, 15, 20),
                "Text of the File attachment annotation",
                FileSpecification.Get(
                    EmbeddedFile.Get(document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")),
                    "happyGNU.jpg")
                )
            {
                IconType = FileAttachment.IconTypeEnum.PaperClip,
                Author   = "Stefano",
                Subject  = "File attachment"
            };

            composer.ShowText("Line annotation:", new SKPoint(35, 185));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 10);

                // Arrow line.
                composer.ShowText("Arrow:", new SKPoint(50, 200));
                new Line(
                    page,
                    new SKPoint(50, 260),
                    new SKPoint(200, 210),
                    "Text of the Arrow line annotation",
                    DeviceRGBColor.Get(SKColors.Black))
                {
                    StartStyle     = LineEndStyleEnum.Circle,
                    EndStyle       = LineEndStyleEnum.ClosedArrow,
                    CaptionVisible = true,
                    FillColor      = DeviceRGBColor.Get(SKColors.Green),
                    Author         = "Stefano",
                    Subject        = "Arrow line"
                };

                // Dimension line.
                composer.ShowText("Dimension:", new SKPoint(300, 200));
                new Line(
                    page,
                    new SKPoint(300, 220),
                    new SKPoint(500, 220),
                    "Text of the Dimension line annotation",
                    DeviceRGBColor.Get(SKColors.Blue)
                    )
                {
                    LeaderLineLength          = 20,
                    LeaderLineExtensionLength = 10,
                    StartStyle     = LineEndStyleEnum.OpenArrow,
                    EndStyle       = LineEndStyleEnum.OpenArrow,
                    Border         = new Border(1),
                    CaptionVisible = true,
                    Author         = "Stefano",
                    Subject        = "Dimension line"
                };

                composer.End();
            }

            var path = new SKPath();

            path.MoveTo(new SKPoint(50, 320));
            path.LineTo(new SKPoint(70, 305));
            path.LineTo(new SKPoint(110, 335));
            path.LineTo(new SKPoint(130, 320));
            path.LineTo(new SKPoint(110, 305));
            path.LineTo(new SKPoint(70, 335));
            path.LineTo(new SKPoint(50, 320));
            // Scribble.
            composer.ShowText("Scribble annotation:", new SKPoint(35, 285));
            new Scribble(
                page,
                new List <SKPath> {
                path
            },
                "Text of the Scribble annotation",
                DeviceRGBColor.Get(SKColors.Orange))
            {
                Border  = new Border(1, new LineDash(new double[] { 5, 2, 2, 2 })),
                Author  = "Stefano",
                Subject = "Scribble"
            };

            // Rectangle.
            composer.ShowText("Rectangle annotation:", new SKPoint(35, 350));
            new PdfClown.Documents.Interaction.Annotations.Rectangle(
                page,
                SKRect.Create(50, 370, 100, 30),
                "Text of the Rectangle annotation")
            {
                Color   = DeviceRGBColor.Get(SKColors.Red),
                Border  = new Border(1, new LineDash(new double[] { 5 })),
                Author  = "Stefano",
                Subject = "Rectangle",
                Popup   = new Popup(
                    page,
                    SKRect.Create(200, 325, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };

            // Ellipse.
            composer.ShowText("Ellipse annotation:", new SKPoint(35, 415));
            new Ellipse(
                page,
                SKRect.Create(50, 440, 100, 30),
                "Text of the Ellipse annotation")
            {
                BorderEffect = new BorderEffect(BorderEffect.TypeEnum.Cloudy, 1),
                FillColor    = DeviceRGBColor.Get(SKColors.Cyan),
                Color        = DeviceRGBColor.Get(SKColors.Black),
                Author       = "Stefano",
                Subject      = "Ellipse"
            };

            // Rubber stamp.
            composer.ShowText("Rubber stamp annotations:", new SKPoint(35, 505));
            {
                fonts::Font stampFont = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf"));
                new Stamp(
                    page,
                    new SKPoint(75, 570),
                    "This is a round custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Round, "Done", 50, stampFont)
                    .Build()
                    )
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                new Stamp(
                    page,
                    new SKPoint(210, 570),
                    "This is a squared (and round-cornered) custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Squared, "Classified", 150, stampFont)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                }.Build()
                    )
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                fonts::Font stampFont2 = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "MgOpenCanonicaRegular.ttf"));
                new Stamp(
                    page,
                    new SKPoint(350, 570),
                    "This is a striped custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Striped, "Out of stock", 100, stampFont2)
                {
                    Color = DeviceRGBColor.Get(SKColors.Gray)
                }.Build()
                    )
                {
                    Rotation = 90,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                // Define the standard stamps template path!

                /*
                 * NOTE: The PDF specification defines several stamps (aka "standard stamps") whose rendering
                 * depends on the support of viewer applications. As such support isn't guaranteed, PDF Clown
                 * offers smooth, ready-to-use embedding of these stamps through the StampPath property of the
                 * document configuration: you can decide to point to the stamps directory of your Acrobat
                 * installation (e.g., in my GNU/Linux system it's located in
                 * "/opt/Adobe/Reader9/Reader/intellinux/plug_ins/Annotations/Stamps/ENU") or to the
                 * collection included in this distribution (std-stamps.pdf).
                 */
                document.Configuration.StampPath = GetResourcePath("../../pkg/templates/std-stamps.pdf");

                // Add a standard stamp, rotating it 15 degrees counterclockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 515),
                    null, // Default size is natural size.
                    "This is 'Confidential', a standard stamp",
                    StandardStampEnum.Confidential)
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };

                // Add a standard stamp, without rotation!
                new Stamp(
                    page,
                    new SKPoint(485, 580),
                    null, // Default size is natural size.
                    "This is 'SBApproved', a standard stamp",
                    StandardStampEnum.BusinessApproved)
                {
                    Author  = "Stefano",
                    Subject = "Standard stamp"
                };

                // Add a standard stamp, rotating it 10 degrees clockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 635),
                    new SKSize(0, 40), // This scales the width proportionally to the 40-unit height (you can obviously do also the opposite, defining only the width).
                    "This is 'SHSignHere', a standard stamp",
                    StandardStampEnum.SignHere)
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };
            }

            composer.ShowText("Text markup annotations:", new SKPoint(35, 650));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 8);

                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation", new SKPoint(35, 680)),
                    "Text of the Highlight annotation",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Author  = "Stefano",
                    Subject = "An highlight text markup!"
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation 2", new SKPoint(35, 695)).Inflate(0, 1),
                    "Text of the Highlight annotation 2",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Magenta)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation 3", new SKPoint(35, 710)).Inflate(0, 2),
                    "Text of the Highlight annotation 3",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Red)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation", new SKPoint(180, 680)),
                    "Text of the Squiggly annotation",
                    TextMarkup.MarkupTypeEnum.Squiggly);
                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation 2", new SKPoint(180, 695)).Inflate(0, 2.5f),
                    "Text of the Squiggly annotation 2",
                    TextMarkup.MarkupTypeEnum.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation 3", new SKPoint(180, 710)).Inflate(0, 3),
                    "Text of the Squiggly annotation 3",
                    TextMarkup.MarkupTypeEnum.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Pink)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation", new SKPoint(320, 680)),
                    "Text of the Underline annotation",
                    TextMarkup.MarkupTypeEnum.Underline
                    );
                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation 2", new SKPoint(320, 695)).Inflate(0, 2.5f),
                    "Text of the Underline annotation 2",
                    TextMarkup.MarkupTypeEnum.Underline
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation 3", new SKPoint(320, 710)).Inflate(0, 3),
                    "Text of the Underline annotation 3",
                    TextMarkup.MarkupTypeEnum.Underline
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation", new SKPoint(455, 680)),
                    "Text of the StrikeOut annotation",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    );
                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation 2", new SKPoint(455, 695)).Inflate(0, 2.5f),
                    "Text of the StrikeOut annotation 2",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation 3", new SKPoint(455, 710)).Inflate(0, 3),
                    "Text of the StrikeOut annotation 3",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

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

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

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

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

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

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

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

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

            SizeF size = widget.Box.Size;

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

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

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

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

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

              composer.Flush();
            }

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

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

            composer.Flush();
              }
            }
              }
        }
Exemplo n.º 30
0
        private void BuildLegend(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SizeF pageSize
            )
        {
            float maxCtmInversionApproximation;
              {
            float[] ctmInversionApproximations = new float[6];
            {
              float[] initialCtmValues, finalCtmValues;
              {
            ContentScanner.GraphicsState state = composer.Scanner.State;
            initialCtmValues = state.GetInitialCtm().Elements;
            finalCtmValues = state.Ctm.Elements;
              }
              for(
            int index = 0,
              length = finalCtmValues.Length;
            index < length;
            index++
            )
              {ctmInversionApproximations[index] = Math.Abs(finalCtmValues[index]) - initialCtmValues[index];}
            }
            maxCtmInversionApproximation = Max(ctmInversionApproximations);
              }

              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.LineSpace = new Length(.25, Length.UnitModeEnum.Relative);

              composer.BeginLocalState();
              composer.SetFillColor(
            new colorSpaces::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)
            );
              RectangleF frame = new RectangleF(
            18,
            18,
            pageSize.Width * .5f,
            pageSize.Height * .5f
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              composer.SetFont(ResourceName_DefaultFont,24);
              blockComposer.ShowText("Page coordinates sample");
              SizeF breakSize = new SizeF(0,8);
              blockComposer.ShowBreak(breakSize);
              composer.SetFont(ResourceName_DefaultFont,8);
              blockComposer.ShowText(
            "This sample shows the effects of the manipulation of the CTM (Current Transformation Matrix), "
              + "that is the mathematical device which affects the page coordinate system used to place "
              + "graphic contents onto the canvas."
            );
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText(
            "The following steps represent the operations applied to this page's CTM in order to alter it. "
              + "Each step writes the word \"Step\" at the lower-left corner of the current page frame:"
            );
              blockComposer.ShowBreak(breakSize);
              for(int i = 0; i < steps.Length; i++)
              {
            composer.SetFillColor(colors[i]);
            blockComposer.ShowText("Step " + i + ")");
            composer.SetFillColor(
              new colorSpaces::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)
              );
            blockComposer.ShowText(" " + steps[i]);
            blockComposer.ShowBreak(breakSize);
              }
              blockComposer.ShowText("Note that the approximation (" + maxCtmInversionApproximation + ") of the CTM components at step 4 is due to floating point precision limits; their exact values should be 1.0, 0.0, 0.0, 1.0, 0.0, 0.0.");
              blockComposer.End();
              composer.End();
        }
Exemplo n.º 31
0
 private void DrawFrame(
     PrimitiveComposer composer,
     PointF[] frameVertices
     )
 {
     composer.BeginLocalState();
       composer.SetLineWidth(0.2f);
       composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
       composer.DrawPolygon(frameVertices);
       composer.Stroke();
       composer.End();
 }
Exemplo n.º 32
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;
        }
Exemplo n.º 33
0
        private void DrawText(
            PrimitiveComposer composer,
            string value,
            PointF location,
            XAlignmentEnum xAlignment,
            YAlignmentEnum yAlignment,
            float rotation
            )
        {
            // Show the anchor point!
              DrawCross(composer,location);

              composer.BeginLocalState();
              composer.SetFillColor(SampleColor);
              // Show the text onto the page!
              Quad textFrame = composer.ShowText(
            value,
            location,
            xAlignment,
            yAlignment,
            rotation
            );
              composer.End();

              // Draw the frame binding the shown text!
              DrawFrame(
            composer,
            textFrame.Points
            );

              composer.BeginLocalState();
              composer.SetFont(composer.State.Font,8);
              // Draw the rotation degrees!
              composer.ShowText(
            "(" + ((int)rotation) + " degrees)",
            new PointF(
              location.X+70,
              location.Y
              ),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );
              composer.End();
        }
Exemplo n.º 34
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();
        }
Exemplo n.º 35
0
        private void Apply(
      ListBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

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

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

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

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

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

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 36
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();
        }
Exemplo n.º 37
0
        private void BuildLinks(
            Document document
            )
        {
            Pages pages = document.Pages;
              Page page = new Page(document);
              pages.Add(page);

              StandardType1Font font = new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Courier,
            true,
            false
            );

              PrimitiveComposer composer = new PrimitiveComposer(page);
              BlockComposer blockComposer = new BlockComposer(composer);

              /*
            2.1. Goto-URI link.
              */
              {
            blockComposer.Begin(new RectangleF(30,100,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle);
            composer.SetFont(font,12);
            blockComposer.ShowText("Go-to-URI link");
            composer.SetFont(font,8);
            blockComposer.ShowText("\nIt allows you to navigate to a network resource.");
            composer.SetFont(font,5);
            blockComposer.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository.");
            blockComposer.End();

            try
            {
              /*
            NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
              */
              annotations::Link link = new annotations::Link(
            page,
            new Rectangle(240,100,100,50),
            "Link annotation",
            new GoToURI(
              document,
              new Uri("http://www.sourceforge.net/projects/clown")
              )
            );
              link.Border = new annotations::Border(
            document,
            3,
            annotations::Border.StyleEnum.Beveled,
            null
            );
            }
            catch(Exception exception)
            {throw new Exception("",exception);}
              }

              /*
            2.2. Embedded-goto link.
              */
              {
            string filePath = PromptFileChoice("Please select a PDF file to attach");

            /*
              NOTE: These statements instruct PDF Clown to attach a PDF file to the current document.
              This is necessary in order to test the embedded-goto functionality,
              as you can see in the following link creation (see below).
            */
            int fileAttachmentPageIndex = page.Index;
            string fileAttachmentName = "attachedSamplePDF";
            string fileName = System.IO.Path.GetFileName(filePath);
            annotations::FileAttachment attachment = new annotations::FileAttachment(
              page,
              new Rectangle(0, -20, 10, 10),
              "File attachment annotation",
              FileSpecification.Get(
            EmbeddedFile.Get(
              document,
              filePath
              ),
            fileName
            )
              );
            attachment.Name = fileAttachmentName;
            attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

            blockComposer.Begin(new RectangleF(30,170,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle);
            composer.SetFont(font,12);
            blockComposer.ShowText("Go-to-embedded link");
            composer.SetFont(font,8);
            blockComposer.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file.");
            composer.SetFont(font,5);
            blockComposer.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ").");
            blockComposer.End();

            /*
              NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file
              attached inside the current document as described by the FileAttachment annotation on page 1 of the current document.
            */
            annotations::Link link = new annotations::Link(
              page,
              new Rectangle(240,170,100,50),
              "Link annotation",
              new GoToEmbedded(
            document,
            new GoToEmbedded.PathElement(
              document,
              fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document.
              fileAttachmentName, // Name of the file attachment annotation corresponding to the target document.
              null // No sub-target.
              ), // Target represents the document to go to.
            new RemoteDestination(
              document,
              1, // Show the page 2 of the target document.
              Destination.ModeEnum.Fit, // Show the target document page entirely on the screen.
              null,
              null
              ) // The destination must be within the target document.
            )
              );
            link.Border = new annotations::Border(
              document,
              1,
              annotations::Border.StyleEnum.Dashed,
              new LineDash(new double[]{8,5,2,5})
              );
              }

              /*
            2.3. Textual link.
              */
              {
            blockComposer.Begin(new RectangleF(30,240,200,50),XAlignmentEnum.Left,YAlignmentEnum.Middle);
            composer.SetFont(font,12);
            blockComposer.ShowText("Textual link");
            composer.SetFont(font,8);
            blockComposer.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text.");
            composer.SetFont(font,5);
            blockComposer.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page.");
            blockComposer.End();

            try
            {
              composer.BeginLocalState();
              composer.SetFont(font,10);
              composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue));
              composer.ShowText(
            "PDF Clown Project's repository at SourceForge.net",
            new PointF(240,265),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0,
            new GoToURI(
              document,
              new Uri("http://www.sourceforge.net/projects/clown")
              )
            );
              composer.ShowText(
            "PDF Clown Project's home page",
            new PointF(240,285),
            XAlignmentEnum.Left,
            YAlignmentEnum.Bottom,
            -90,
            new GoToURI(
              document,
              new Uri("http://www.pdfclown.org")
              )
            );
              composer.End();
            }
            catch
            {}
              }

              composer.Flush();
        }
Exemplo n.º 38
0
        private void BuildWelcomePage(
            Document document,
            FormXObject template
            )
        {
            // Add welcome 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;

              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Add the background template!
              composer.ShowXObject(template);
              // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
              /*
            NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
            Flow-level typographic features are currently not supported: block-level typographic features
            are the foundations upon which flow-level typographic features will sit.
              */
              BlockComposer blockComposer = new BlockComposer(composer);

              SizeF breakSize = new SizeF(0,20); // Size of a paragraph break.
              // Instantiate the page body's font!
              fonts::Font font = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "lazyDog.ttf")
            );

              // Showing the page title...
              // Define the box frame to force the page title within!
              RectangleF frame = new RectangleF(
            20,
            150,
            (float)pageSize.Width - 90,
            (float)pageSize.Height - 250
            );
              // Begin the block!
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Top);
              // Set the font to use!
              composer.SetFont(font,56);
              // Set the text rendering mode (outline only)!
              composer.SetTextRenderMode(TextRenderModeEnum.Stroke);
              // Show the page title!
              blockComposer.ShowText("Welcome");
              // End the block!
              blockComposer.End();

              // Showing the clown photo...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
              PointF imageLocation = new PointF(
            blockComposer.BoundBox.X + blockComposer.BoundBox.Width - image.Width,
            blockComposer.BoundBox.Y + blockComposer.BoundBox.Height + 25
            );
              // Show the image!
              composer.ShowXObject(
            image.ToXObject(document),
            imageLocation
            );

              RectangleF descriptionFrame = new RectangleF(
            imageLocation.X,
            imageLocation.Y + image.Height + 5,
            image.Width,
            20
            );

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            imageLocation.Y,
            blockComposer.BoundBox.Width - image.Width - 20,
            image.Height
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle);
              {
            composer.SetFont(font,30);
            blockComposer.ShowText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
            blockComposer.ShowBreak(XAlignmentEnum.Center);
            blockComposer.ShowText("Enjoy!");
              }
              blockComposer.End();

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            blockComposer.BoundBox.Y+blockComposer.BoundBox.Height,
            pageSize.Width - 90,
            pageSize.Height - 100 - (blockComposer.BoundBox.Y+blockComposer.BoundBox.Height)
            );
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              {
            composer.SetFont(font,14);
            blockComposer.ShowText("PS: As promised, since version 0.0.3 PDF Clown has supported");
            // Begin local state!
            /*
              NOTE: Local state is a powerful feature of PDF format as it lets you nest
              multiple graphics contexts on the graphics state stack.
            */
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
            }
            composer.End();
            blockComposer.ShowText(" along with");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" paragraph construction facilities");
            }
            composer.End();
            blockComposer.ShowText(" through the BlockComposer class.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.4 the content stream stack has been completed, providing ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("fully object-oriented access to the graphics objects that describe the contents on a page.");
            }
            composer.End();
            blockComposer.ShowText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.6 it has supported ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("Unicode");
            }
            composer.End();
            blockComposer.ShowText(" for OpenFont/TrueType fonts.");
            blockComposer.ShowBreak(breakSize);

            composer.SetFont(font,8);
            blockComposer.ShowText("This page was crafted with the nice");
            composer.BeginLocalState();
            {
              composer.SetFont(font,10);
              blockComposer.ShowText(" LazyDog font");
            }
            composer.End();
            blockComposer.ShowText(" (by Paul Neave, www.neave.com)");
              }
              blockComposer.End();

              blockComposer.Begin(descriptionFrame,XAlignmentEnum.Right,YAlignmentEnum.Top);
              {
            composer.SetFont(font,8);
            blockComposer.ShowText("Source: http://www.wikipedia.org/");
              }
              blockComposer.End();

              composer.Flush();
        }
Exemplo n.º 39
0
        /// <summary>
        /// Renderiza o bloco para um XObject.
        /// </summary>
        public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject()
        {
            if(_RenderedObject == null)
            {
                _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size);

                PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject);
                var obj = composer.BeginLocalState();
                composer.SetLineWidth(DanfeDocumento.LineWidth);

                if (PossuiCabecalho)
                {
                    RectangleF rect = GetHeaderInnerRectangle();
                    //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho);
                    PrintCabecalho(composer);
                }

                ToXObjectInternal(composer);

                foreach (var campo in Campos)
                {
                    campo.Print(composer, Danfe.Font, Danfe.FontBold);
                }

                composer.Stroke();

                composer.End();
                composer.Flush();
            }

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

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

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

            // Drawing text string bounding box...
            composer.BeginLocalState();
            composer.SetLineDash(new LineDash(new double[]{5,5}));
            composer.SetStrokeColor(textStringBoxColor);
            composer.DrawRectangle(textString.Box.Value);
            composer.Stroke();
            composer.End();
              }
            }
            else if(content is ContainerObject)
            {
              // Scan the inner level!
              Extract(level.ChildLevel, composer);
            }
              }
        }
Exemplo n.º 41
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;
        }
        /// <summary>
        /// Print as linhas tracejadas na tabela, ignorando a última
        /// </summary>
        /// <param name="composer"></param>
        /// <param name="y">Lista com as posições y</param>
        /// <param name="xBegin"></param>
        /// <param name="xEnd"></param>
        private void PrintLinhasTracejadas(PrimitiveComposer composer, List<float> y, float xBegin, float xEnd)
        {
            if (xBegin < 0)
            {
                throw new ArgumentOutOfRangeException("xBegin");
            }

            if (xEnd > composer.Scanner.CanvasSize.Width)
            {
                throw new ArgumentOutOfRangeException("xEnd");
            }

            composer.BeginLocalState();
            composer.SetLineDash(new LineDash(new Double[] { 3, 2 }));
            for (int i = 0; i < y.Count - 1; i++)
            {
                composer.DrawLine(new PointF(xBegin, y[i]), new PointF(xEnd, y[i]));
            }

            composer.Stroke();
            composer.End();
        }
Exemplo n.º 43
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

            SizeF pageSize = page.Size;

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

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

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

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

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

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

            composer.Stroke();

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

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

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

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

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

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

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

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

                y += 30;
            }

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

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

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

            // 3.6. Clipping.

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

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Exemplo n.º 44
0
        private void Build(
            Document document
            )
        {
            // Add a 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;

              // Create a content composer for the content stream!
              /*
            NOTE: There are several ways to add contents to a content stream:
            - adding content objects directly to the Contents collection;
            - adding content objects through a ContentScanner instance;
            - invoking basic drawing functions through a PrimitiveComposer instance;
            - invoking advanced static-positioning functions through a BlockComposer instance;
            - invoking advanced dynamic-positioning functions through a FlowComposer instance (currently not implemented yet).
              */
              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Wrap the content composer within a block filter!
              /*
            NOTE: The block filter is a basic typesetter. It exposes higher-level graphical
            functionalities (horizontal/vertical alignment, indentation, paragraph composition etc.)
            leveraging the content composer primitives.
            It's important to note that this is just an intermediate abstraction layer of the typesetting
            stack: further abstract levels could sit upon it, allowing the convenient treatment of
            typographic entities like titles, paragraphs, columns, tables, headers, footers etc.
            When such further abstract levels are available, the final user (developer of consuming
            applications) won't care any more of the details you can see here in the following code lines
            (such as bothering to select the first-letter font...).
              */
              BlockComposer blockComposer = new BlockComposer(composer);

              composer.BeginLocalState();
              // Define the block frame that will constrain our contents on the page canvas!
              RectangleF frame = new RectangleF(
            Margin_X,
            Margin_Y,
            (float)pageSize.Width - Margin_X * 2,
            (float)pageSize.Height - Margin_Y * 2
            );
              // Begin the title block!
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              fonts::Font decorativeFont = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")
            );
              composer.SetFont(decorativeFont,56);
              blockComposer.ShowText("Chapter 1");
              blockComposer.ShowBreak();
              composer.SetFont(decorativeFont,32);
              blockComposer.ShowText("Down the Rabbit-Hole");
              // End the title block!
              blockComposer.End();
              // Update the block frame in order to begin after the title!
              frame = new RectangleF(
            (float)blockComposer.BoundBox.X,
            (float)blockComposer.BoundBox.Y + blockComposer.BoundBox.Height,
            (float)blockComposer.BoundBox.Width,
            (float)pageSize.Height - Margin_Y - (blockComposer.BoundBox.Y + blockComposer.BoundBox.Height)
            );
              // Begin the body block!
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              fonts::Font bodyFont = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf")
            );
              composer.SetFont(bodyFont,14);
              composer.BeginLocalState();
              composer.SetFont(decorativeFont,28);
              blockComposer.ShowText("A");
              composer.End();
              blockComposer.ShowText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'");
              // Define new-paragraph first-line offset!
              SizeF breakSize = new SizeF(24,8); // Indentation (24pt) and top margin (8pt).
              // Begin a new paragraph!
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.");
              // Begin a new paragraph!
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
              // End the body block!
              blockComposer.End();
              composer.End();

              composer.BeginLocalState();
              composer.Rotate(
            90,
            new PointF(
              pageSize.Width - 50,
              pageSize.Height - 25
              )
            );
              blockComposer = new BlockComposer(composer);
              blockComposer.Begin(
            new RectangleF(0,0,300,50),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle
            );
              composer.SetFont(bodyFont,8);
              blockComposer.ShowText("Generated by PDF Clown on " + System.DateTime.Now);
              blockComposer.ShowBreak();
              blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
              blockComposer.End();
              composer.End();

              // Flush the contents into the page!
              composer.Flush();
        }
Exemplo n.º 45
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.º 46
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();
        }
Exemplo n.º 47
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();
        }
Exemplo n.º 48
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();
        }
Exemplo n.º 49
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();
        }
Exemplo n.º 50
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.º 51
0
        protected override void ToXObjectInternal(PrimitiveComposer composer)
        {
            EmpresaViewModel empresa = null;

            if(Danfe.Model.TipoNF == 1)
            {
                empresa = Danfe.Model.Emitente;
            }
            else if(Danfe.Model.TipoNF == 0)
            {
                empresa = Danfe.Model.Destinatario;
            }
            else
            {
                throw new Exception("Tipo de NF não suportado.");
            }

            BlockComposer bComp = new BlockComposer(composer);

            composer.SafeDrawRectangle(RetNumeracao);
            composer.SafeDrawRectangle(RetRecebemos);

            composer.SetFont(Danfe.Font, 6);
            bComp.SafeBegin(RetRecebemos.GetPaddedRectangleMm(1), XAlignmentEnum.Left, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("RECEBEMOS DE {0} OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO.", empresa.Nome));
            bComp.End();

            // Numeração da NFe
            composer.SafeDrawRectangle(RetNumeracao);
            composer.SetFont(Danfe.FontBold, 12);
            bComp.SafeBegin(RetNumeracao, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("NF-e\nNº {0}\nSérie {1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();

            composer.Stroke();

            // Linha pontilhada
            composer.BeginLocalState();
            composer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            composer.DrawLine(new PointF(InternalRectangle.Left, Size.Height - MargemLinhaPontilhada), new PointF(InternalRectangle.Right, Size.Height - MargemLinhaPontilhada));
            composer.Stroke();
            composer.End();
        }
Exemplo n.º 52
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.º 53
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);
        }
Exemplo n.º 54
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;
        }