Пример #1
0
        /// <summary>
        /// Writes PDF text element into file stream
        /// </summary>
        /// <param name="text">PDF text element</param>
        internal void Write(TextElement text)
        {
            var escapedText = TextAdapter.FixEscapes(text.Content);

            var pdfStreamBuilder = new StringBuilder();

            pdfStreamBuilder.AppendLine("q");
            pdfStreamBuilder.AppendLine("BT");
            pdfStreamBuilder.AppendFormatLine("{0} {1} Tf", text.Font.GetResourceReference(), TextAdapter.FormatFloat(text.FontSize));
            pdfStreamBuilder.AppendFormatLine("{0} rg", text.Color.ToPdfString());
            pdfStreamBuilder.AppendFormatLine("{0} {1} Td", TextAdapter.FormatFloat(text.X), TextAdapter.FormatFloat(text.Y));
            pdfStreamBuilder.AppendFormatLine("({0}) Tj", escapedText);
            pdfStreamBuilder.AppendLine("ET");
            pdfStreamBuilder.Append("Q");

            writeStreamedObject(text.ObjectId, pdfStreamBuilder.ToString());
        }
Пример #2
0
        /// <summary>
        /// Writes PDF rectangle element into file stream
        /// </summary>
        /// <param name="rectangle">PDF rectangle element</param>
        internal void Write(RectangleElement rectangle)
        {
            var x = TextAdapter.FormatFloat(rectangle.X);
            var y = TextAdapter.FormatFloat(rectangle.Y);
            var w = TextAdapter.FormatFloat(rectangle.X1 - rectangle.X);
            var h = TextAdapter.FormatFloat(rectangle.Y1 - rectangle.Y);

            var rectangleContent = new StringBuilder();

            rectangleContent.AppendLine("q");
            rectangleContent.Append(rectangle.Style.ToPdfString());
            rectangleContent.AppendFormatLine("{0} {1} {2} {3} re", x, y, w, h);
            rectangleContent.AppendLine("B");
            rectangleContent.Append("Q");

            writeStreamedObject(rectangle.ObjectId, rectangleContent.ToString());
        }
Пример #3
0
 public TextColumn(string name,
     TextAdapter adapter,
     IFormatProvider formatProvider,
     bool unique,
     bool primaryKey,
     bool nullable,
     int offset,
     int length)
 {
     this._Name = name;
     this._Adapter = adapter;
     this._Unique = unique;
     this._PrimaryKey = primaryKey;
     this._Nullable = nullable;
     this._FormatProvider = formatProvider;
     this._Position = -1;
     this._Offset = offset;
     this._Length = length;
 }
Пример #4
0
        /// <summary>
        /// Returns PDF string representation
        /// </summary>
        public string ToPdfString()
        {
            var styleBuilder = new StringBuilder();

            if (StrokeColor != null)
            {
                styleBuilder.AppendFormatLine("{0} RG", StrokeColor.ToPdfString());
            }

            if (FillColor != null)
            {
                styleBuilder.AppendFormatLine("{0} rg", FillColor.ToPdfString());
            }

            if (StrokeThickness != null)
            {
                styleBuilder.AppendFormatLine("{0} w", TextAdapter.FormatFloat(StrokeThickness.Value));
            }

            if (StrokeType != null)
            {
                switch (StrokeType)
                {
                case PdfLineType.OutlinedThin:
                    styleBuilder.AppendLine("[2 2] 0 d");
                    break;

                case PdfLineType.Outlined:
                    styleBuilder.AppendLine("[4 4] 0 d");
                    break;

                case PdfLineType.OutlinedBold:
                    styleBuilder.AppendLine("[6 6] 0 d");
                    break;
                }
            }

            return(styleBuilder.ToString());
        }
Пример #5
0
        private static void Main()
        {
            var t = new TextAdapter(new Memory());

            do
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write($"{t.BytePointer:00000} ${t.BytePointer:X4}> ");
                Console.ForegroundColor = ConsoleColor.Gray;
                var i = Console.ReadLine() ?? "";
                if (string.Compare(i.Trim(), "x", StringComparison.CurrentCulture) == 0)
                {
                    break;
                }
                var resp = t.Ask(i, out var success).Trim();
                Console.ForegroundColor = success ? ConsoleColor.DarkGray : ConsoleColor.Red;
                if (resp.Length > 0)
                {
                    Console.WriteLine(resp);
                }
            } while (true);
        }
Пример #6
0
        /// <summary>
        /// Writes PDF path into file stream
        /// </summary>
        /// <param name="path">PDF path element</param>
        internal void Write(PathElement path)
        {
            var x = TextAdapter.FormatFloat(path.X);
            var y = TextAdapter.FormatFloat(path.Y);

            var pathCoordinates = new List <string> {
                PATH_START_FORMAT.Args(x, y)
            };

            pathCoordinates.AddRange(path.Primitives.Select(p => p.ToPdfString()));

            var closeTag = path.IsClosed ? "B" : "S";

            var pathContent = new StringBuilder();

            pathContent.AppendLine("q");
            pathContent.Append(path.Style.ToPdfString());
            pathContent.AppendFormatLine(string.Join(Constants.SPACE, pathCoordinates));
            pathContent.AppendLine(closeTag);
            pathContent.Append("Q");

            writeStreamedObject(path.ObjectId, pathContent.ToString());
        }
Пример #7
0
        /// <summary>
        /// Writes PDF page into file stream
        /// </summary>
        /// <param name="page">PDF page</param>
        internal void Write(PdfPage page)
        {
            var resourcesBuilder = new StringBuilder();
            var elements         = string.Join(Constants.SPACE.ToString(), page.Elements.Select(p => p.GetReference()));
            var images           = string.Join(Constants.SPACE.ToString(), page.Elements.OfType <ImageElement>().Select(p => p.GetCoupledReference()));
            var fonts            = string.Join(Constants.SPACE, page.Fonts.Select(p => FONTS_REFERENCE_FORMAT.Args(p.GetResourceReference(), p.GetReference())));

            if (fonts.Length > 0)
            {
                resourcesBuilder.AppendFormat(" /Font <<{0}>> ", fonts);
            }
            if (images.Length > 0)
            {
                resourcesBuilder.AppendFormat(" /XObject <<{0}>> ", images);
            }

            var w = TextAdapter.FormatFloat(page.Width);
            var h = TextAdapter.FormatFloat(page.Height);

            writeBeginObject(page.ObjectId);
            writeBeginDictionary();
            writeDictionaryEntry("/Type", "/Page");
            writeDictionaryEntry("/UserUnit", TextAdapter.FormatFloat(page.UserUnit));
            writeDictionaryEntry("/Parent", page.Parent.GetReference());
            writeDictionaryEntry("/Resources", DICTIONARY_PDF_FORMAT.Args(resourcesBuilder));
            writeDictionaryEntry("/MediaBox", BOX_PDF_FORMAT.Args(w, h));
            writeDictionaryEntry("/CropBox", BOX_PDF_FORMAT.Args(w, h));
            writeDictionaryEntry("/Rotate", 0);
            writeDictionaryEntry("/ProcSet", PROC_SET_STRING);
            if (elements.Length > 0)
            {
                writeDictionaryEntry("/Contents", ARRAY_PDF_FORMAT.Args(elements));
            }
            writeEndDictionary();
            writeEndObject();
        }
Пример #8
0
 /// <summary>
 /// Returns PDF string representation on the line primitive
 /// </summary>
 /// <returns></returns>
 public override string ToPdfString()
 {
     return(LINE_TO_FORMAT.Args(TextAdapter.FormatFloat(EndX), TextAdapter.FormatFloat(EndY)));
 }