Пример #1
0
        internal override byte[] Contents()
        {
            PdfBoundingBox bounding_box = new PdfBoundingBox(Rectange, Page.Area.Height);

            return(Util.StringToBytes(
                       $"q\n" +
                       $"{bounding_box.Width} 0 0 {bounding_box.Height} {bounding_box.LLx} {bounding_box.LLy} cm\n" +
                       $"{ElementName} Do\n" +
                       $"Q\n"));
        }
Пример #2
0
 public PdfFontMetrics(string font_name, string family_name, bool is_fixed_pitch, bool is_bold, bool is_italic, double italic_angle, int ul_pos, int ul_th, int bb_llx, int bb_lly, int bb_urx, int bb_ury)
 {
     FontName           = font_name;
     FamilyName         = family_name;
     IsFixedPitch       = is_fixed_pitch;
     IsBold             = is_bold;
     IsItalic           = is_italic;
     ItalicAngle        = italic_angle;
     UnderlinePosition  = ul_pos;
     UnderlineThickness = ul_th;
     FontBBox           = new PdfBoundingBox(bb_llx, bb_lly, bb_urx, bb_ury);
     glyphMetrics       = new Dictionary <int, PdfGlyphMetrics>();
     kerningPairs       = new Dictionary <int, int>();
 }
Пример #3
0
 public PdfGlyphMetrics(string glyph_name, int width, int llx, int lly, int urx, int ury)
 {
     GlyphName = glyph_name;
     Width     = width;
     BBox      = new PdfBoundingBox(llx, lly, urx, ury);
 }
Пример #4
0
        internal override byte[] Contents()
        {
            Refresh();
            List <byte>    contents     = new List <byte>();
            PdfBoundingBox bounding_box = CalcBoundingBox(_abs_rectangle);
            var            rotation     = CalcRotation();

            // aplicar matriz de transformação
            if ((BoxLayout != null) || ((_lines_out?.Length ?? 0) > 0))
            {
                byte[] ctm_bytes = Util.StringToBytes(
                    $"q\n" +
                    $"{Util.FormatDouble(rotation.a)}\x20" +
                    $"{Util.FormatDouble(rotation.b)}\x20" +
                    $"{Util.FormatDouble(rotation.c)}\x20" +
                    $"{Util.FormatDouble(rotation.d)}\x20" +
                    $"{Util.FormatDouble(bounding_box.LLx)}\x20" +
                    $"{Util.FormatDouble(bounding_box.LLy)}\x20" +
                    $"cm\n");
                contents.AddRange(ctm_bytes);
            }

            // desenhar retânguilo
            if (BoxLayout != null)
            {
                contents.AddRange(DrawBox(BoxLayout, bounding_box.Width, bounding_box.Height));
            }

            // escrever linhas de texto
            if ((_lines_out?.Length ?? 0) > 0)
            {
                // início do bloco de texto
                contents.AddRange(Util.StringToBytes($"BT\n"));
                double pos_x = -CalcTextStartX(_text_width);
                double pos_y = -CalcTextStartY(_text_height);

                // plotar linhas de texto de baixo para cima
                foreach (var line_out in _lines_out)
                {
                    byte[] pdf_string = Encoding.GetEncoding(line_out.CodePage).GetBytes(line_out.Text);
                    double line_x     = CalcTextX(line_out.HAlign, line_out.Width);

                    if (line_out.Color != null)
                    {
                        contents.AddRange(Util.StringToBytes(
                                              $"{Util.FormatDouble(line_out.Color.Red)} {Util.FormatDouble(line_out.Color.Green)} {Util.FormatDouble(line_out.Color.Blue)} rg\n"
                                              ));
                    }

                    contents.AddRange(Util.StringToBytes(
                                          $"{line_out.FontName} {line_out.TextScale} Tf\n" +
                                          $"{Util.FormatDouble(line_out.WordSpacing)} Tw\n" +
                                          $"{Util.FormatDouble(line_x - pos_x)} {Util.FormatDouble(line_out.Y - pos_y)} Td\n" +
                                          $"("));
                    foreach (byte text_byte in pdf_string)
                    {
                        if ((text_byte == 0x28) || (text_byte == 0x29) || (text_byte == 0x5c))
                        {
                            contents.Add((byte)'\\');
                        }
                        contents.Add(text_byte);
                    }
                    contents.AddRange(Util.StringToBytes($") Tj\n"));
                    pos_x = line_x;
                    pos_y = line_out.Y;
                }

                // finalizar texto
                contents.AddRange(Util.StringToBytes($"ET\n"));
            }

            // restaurar estado gráfico
            if ((BoxLayout != null) || ((_lines_out?.Length ?? 0) > 0))
            {
                contents.AddRange(Util.StringToBytes($"Q\n"));
            }

            return(contents.ToArray());
        }