Beispiel #1
0
        private void parseFont(List <IPDFPageOperation> operations)
        {
            for (int i = operations.Count - 1; i >= 0; --i)
            {
                if (operations[i] is TextFont)
                {
                    PDFDictionary fontDict = Owner.GetAcroFormFont(((TextFont)operations[i]).FontName.Substring(1));
                    float         fontSize = ((TextFont)operations[i]).FontSize;
                    if (fontDict != null)
                    {
                        _font = new Font(FontBase.Instance(fontDict));
                    }
                    else
                    {
                        _font = new Font(StandardFonts.Helvetica, 8);
                    }

                    _font.Size = fontSize;
                    break;
                }
            }

            if (_font == null)
            {
                _font = new Font(StandardFonts.Helvetica, 12);
            }
            _font.ChangedFontSize += changedFontSize;
        }
Beispiel #2
0
        public static FontBase AddFontFromFile(string fileName)
        {
            byte[]   buf  = FontDataLoader.LoadFontFromFile(fileName);
            FontBase font = loadFromBuffer(buf, 0);

            _fromFile.Add(font);
            return(font);
        }
Beispiel #3
0
        public static FontBase AddFontFromStream(Stream stream)
        {
            byte[] buf = new byte[stream.Length];
            stream.Position = 0;
            FontBase font = loadFromBuffer(buf, 0);

            _fromFile.Add(font);
            return(font);
        }
Beispiel #4
0
        private static void changeFont(ref TextState currentTextState, Resources resources, TextFont textFont)
        {
            IPDFObject obj = resources.GetResource(textFont.FontName, ResourceType.Font);

            if (obj is PDFDictionary)
            {
                currentTextState.FontBase = FontBase.Instance(obj as PDFDictionary);
            }
            currentTextState.FontSize = textFont.FontSize;
        }
Beispiel #5
0
 public CoordinateText(PointF coordinate, StringBuilder text, FontBase fontBase, float fontSize, float textWidth, float textHeight, int weight, float scale)
 {
     _text       = text;
     _coordinate = coordinate;
     _weight     = weight;
     _textWidth  = textWidth;
     _fontBase   = fontBase;
     _textHeight = textHeight;
     _fontSize   = fontSize;
     _scale      = scale;
 }
Beispiel #6
0
 public TextState(TextState textState)
 {
     m_charSpace = textState.m_charSpace;
     m_wordSpace = textState.m_wordSpace;
     m_scale     = textState.m_scale;
     m_leading   = textState.m_leading;
     m_fontSize  = textState.m_fontSize;
     m_render    = textState.m_render;
     m_rize      = textState.m_rize;
     m_fontBase  = textState.m_fontBase;
 }
Beispiel #7
0
 public TextState()
 {
     m_charSpace = 0.0f;
     m_wordSpace = 0.0f;
     m_scale     = 100.0f;
     m_leading   = 0.0f;
     m_fontSize  = 0.0f;
     m_render    = TextRenderingModes.Fill;
     m_rize      = 0.0f;
     m_fontBase  = null;
 }
Beispiel #8
0
 public void setDefault()
 {
     m_charSpace = 0.0f;
     m_wordSpace = 0.0f;
     m_scale     = 100.0f;
     m_leading   = 0.0f;
     m_fontSize  = 0.0f;
     m_render    = TextRenderingModes.Fill;
     m_rize      = 0.0f;
     m_fontBase  = null;
 }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the standard font with specified properties.
        /// </summary>
        /// <param name="standardFont">The Bytescout.PDF.StandardFonts value that specifies the standard font.</param>
        /// <param name="emSize" href="http://msdn.microsoft.com/en-us/library/system.single.aspx">The em-size, in points, of the font.</param>
        /// <param name="underline" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be underlined.</param>
        /// <param name="strikeout" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be stroked out.</param>
        public Font(StandardFonts standardFont, float emSize, bool underline, bool strikeout)
        {
            if (emSize < 0)
            {
                throw new ArgumentOutOfRangeException("emSize");
            }

            _baseFont  = FontsManager.AddStandardFont(standardFont, underline, strikeout);
            _size      = emSize;
            _bold      = _baseFont.RealBold;
            _italic    = _baseFont.RealItalic;
            _underline = underline;
            _strikeout = strikeout;
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new Bytescout.PDF.Font using a specified properties.
        /// </summary>
        /// <param name="fontName" href="http://msdn.microsoft.com/en-us/library/system.string.aspx">The name of the font.</param>
        /// <param name="emSize" href="http://msdn.microsoft.com/en-us/library/system.single.aspx">The em-size, in points, of the font.</param>
        /// <param name="bold" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be bold.</param>
        /// <param name="italic" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be italic.</param>
        /// <param name="underline" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be underlined.</param>
        /// <param name="strikeout" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be stroked out.</param>
        public Font(string fontName, float emSize, bool bold, bool italic, bool underline, bool strikeout)
        {
            if (emSize < 0)
            {
                throw new ArgumentOutOfRangeException("emSize");
            }

            _baseFont  = FontsManager.AddFont(fontName, bold, italic);
            _strikeout = strikeout;
            _underline = underline;
            _size      = emSize;
            _bold      = bold;
            _italic    = italic;
        }
Beispiel #11
0
        public static void Release()
        {
            for (int i = 0; i < _fromFile.Count; ++i)
            {
                _fromFile[i].CreateFontDictionary();
            }

            FontBase[] fonts = new FontBase[_fonts.Count];
            _fonts.Values.CopyTo(fonts, 0);
            for (int i = 0; i < fonts.Length; ++i)
            {
                fonts[i].CreateFontDictionary();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Creates a Bytescout.PDF.Font from the specified data stream.
        /// </summary>
        /// <param name="stream" href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx">A System.IO.Stream that contains the data for this Bytescout.PDF.Font.</param>
        /// <param name="emSize" href="http://msdn.microsoft.com/en-us/library/system.single.aspx">The em-size, in points, of the font.</param>
        /// <param name="underline" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be underlined.</param>
        /// <param name="strikeout" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be stroked out.</param>
        /// <returns cref="Font">The Bytescout.PDF.Font this method creates.</returns>
        public static Font FromStream(System.IO.Stream stream, float emSize, bool underline, bool strikeout)
        {
            if (emSize < 0)
            {
                throw new ArgumentOutOfRangeException("emSize");
            }

            FontBase fnt  = FontsManager.AddFontFromStream(stream);
            Font     font = new Font(fnt);

            font._strikeout = strikeout;
            font._underline = underline;
            font.Size       = emSize;
            return(font);
        }
Beispiel #13
0
        /// <summary>
        /// Creates a Bytescout.PDF.Font from the specified file.
        /// </summary>
        /// <param name="fileName" href="http://msdn.microsoft.com/en-us/library/system.string.aspx">A string that contains the name of the file from which to create the Bytescout.PDF.Font.</param>
        /// <param name="emSize" href="http://msdn.microsoft.com/en-us/library/system.single.aspx">The em-size, in points, of the font.</param>
        /// <param name="underline" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be underlined.</param>
        /// <param name="strikeout" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">If set to true, the initialized font will be stroked out.</param>
        /// <returns cref="Font">The Bytescout.PDF.Font this method creates.</returns>
        public static Font FromFile(string fileName, float emSize, bool underline, bool strikeout)
        {
            if (emSize < 0)
            {
                throw new ArgumentOutOfRangeException("emSize");
            }

            FontBase fnt  = FontsManager.AddFontFromFile(fileName);
            Font     font = new Font(fnt);

            font._strikeout = strikeout;
            font._underline = underline;
            font.Size       = emSize;
            return(font);
        }
Beispiel #14
0
        public static FontBase AddFont(string fontName, bool bold, bool italic)
        {
            LOGFONT lf = FontDataLoader.GetLOGFONT(fontName, bold, italic);

            if (_fonts.ContainsKey(lf))
            {
                return(_fonts[lf]);
            }

            uint ttc;

            byte[]   data = FontDataLoader.LoadFont(lf, out ttc);
            FontBase font = loadFromBuffer(data, ttc);

            _fonts.Add(lf, font);

            return(font);
        }
Beispiel #15
0
 internal Font(FontBase baseFont)
 {
     _baseFont = baseFont;
 }
Beispiel #16
0
        public static string convertText(List <CoordinateText> listStrings)
        {
            if (listStrings.Count == 0)
            {
                return("");
            }

            StringBuilder text = new StringBuilder();

            listStrings.Sort(new ComparerText());

            /*for (int i = 0; i < listStrings.Count - 1; ++i)
             * {
             *  if (listStrings[i].Coordinate.X + listStrings[i].TextWidth > listStrings[i + 1].Coordinate.X)
             *  {
             *      if (isNextInLine(listStrings[i], listStrings[i + 1]))
             *      {
             *          if (mergeString(listStrings[i], listStrings[i + 1]) == 0)
             *              listStrings.RemoveAt(i + 1);
             *          else
             *              listStrings.RemoveAt(i);
             *          --i;
             *      }
             *  }
             * }*/

            float middleX = 0.0f;
            float middleY = 0.0f;
            int   count   = 0;
            float minX    = listStrings[0].Coordinate.X;
            float minY    = listStrings[0].Coordinate.Y;

            for (int i = 0; i < listStrings.Count; ++i)
            {
                middleX += listStrings[i].TextWidth;
                count   += listStrings[i].Text.Length;
                middleY += listStrings[i].TextHeight;
                if (listStrings[i].Coordinate.X < minX)
                {
                    minX = listStrings[i].Coordinate.X;
                }
                if (minY < listStrings[i].Coordinate.Y)
                {
                    minY = listStrings[i].Coordinate.Y;
                }
            }

            middleX /= count;

            for (int i = 0; i < listStrings.Count - 1; ++i)
            {
                if (listStrings[i].Coordinate.X + listStrings[i].TextWidth < listStrings[i + 1].Coordinate.X)
                {
                    if (listStrings[i].TextWidth < listStrings[i].Text.Length * middleX)
                    {
                        if (isNextInLine(listStrings[i], listStrings[i + 1]))
                        {
                            if (listStrings[i + 1].Coordinate.X < listStrings[i].Coordinate.X + listStrings[i].Text.Length * middleX)
                            {
                                if ((float)Math.Abs(listStrings[i + 1].Coordinate.X - listStrings[i].Coordinate.X) != 0)
                                {
                                    middleX = (float)Math.Abs(listStrings[i + 1].Coordinate.X - listStrings[i].Coordinate.X) / listStrings[i].Text.Length;
                                }
                            }
                        }
                    }
                }
            }

            middleY /= listStrings.Count;

            float currentCoordinateY = minY;
            int   countSpace         = 0;
            int   countSimbols       = 0;

            if (listStrings[0].Coordinate.X - minX > 0)
            {
                countSpace = round((listStrings[0].Coordinate.X - minX) / middleX);
            }
            text.Append(' ', countSpace);
            float currentHeight = listStrings[0].TextHeight;

            text.Append(listStrings[0].Text);
            countSimbols += listStrings[0].Text.Length + countSpace;
            FontBase currentFont        = listStrings[0].FontBase;
            float    currentFontSize    = listStrings[0].FontSize;
            float    currentCoordinateX = listStrings[0].Coordinate.X;
            float    currentScale       = listStrings[0].Scale;

            for (int i = 1; i < listStrings.Count; ++i)
            {
                if (currentCoordinateY != listStrings[i].Coordinate.Y)
                {
                    if (listStrings[i].Coordinate.X < listStrings[i - 1].Coordinate.X)
                    {
                        if (Math.Abs(currentCoordinateY - listStrings[i].Coordinate.Y) > middleY * 2)
                        {
                            text.Append("\r\n");
                        }
                        text.Append("\r\n");
                        countSimbols = 0;
                        countSpace   = round((listStrings[i].Coordinate.X - minX) / middleX) - countSimbols;
                        if (countSpace < 0)
                        {
                            countSpace = 0;
                        }
                        text.Append(' ', countSpace);
                    }
                    else
                    {
                        if (currentCoordinateY - currentHeight / 2 < listStrings[i].Coordinate.Y)
                        {
                            if (currentFont == listStrings[i].FontBase)
                            {
                                countSpace = getCountSpaceEx(listStrings, i, middleX, minX, countSimbols);
                                if (countSpace < 0)
                                {
                                    countSpace = 0;
                                }
                                if (countSpace > 2)
                                {
                                    countSpace = round((listStrings[i].Coordinate.X - minX) / middleX) - countSimbols;
                                }
                                if (countSpace < 0)
                                {
                                    countSpace = 0;
                                }
                                text.Append(' ', countSpace);
                            }
                            else
                            {
                                countSpace = getCountSpaceEx(listStrings, i, middleX, minX, countSimbols);
                                if (countSpace < 0)
                                {
                                    countSpace = 0;
                                }
                                text.Append(' ', countSpace);
                            }
                        }
                        else
                        {
                            if (Math.Abs(currentCoordinateY - listStrings[i].Coordinate.Y) > middleY * 2)
                            {
                                text.Append("\r\n");
                            }
                            text.Append("\r\n");
                            countSimbols = 0;
                            countSpace   = round((listStrings[i].Coordinate.X - minX) / middleX) - countSimbols;
                            if (countSpace < 0)
                            {
                                countSpace = 0;
                            }
                            text.Append(' ', countSpace);
                        }
                    }
                }
                else
                {
                    if (currentFont == listStrings[i].FontBase)
                    {
                        countSpace = getCountSpaceEx(listStrings, i, middleX, minX, countSimbols);
                        if (countSpace < 0)
                        {
                            countSpace = 0;
                        }
                        if (countSpace > 2)
                        {
                            countSpace = round((listStrings[i].Coordinate.X - minX) / middleX) - countSimbols;
                        }
                        if (countSpace < 0)
                        {
                            countSpace = 0;
                        }
                        text.Append(' ', countSpace);
                    }
                    else
                    {
                        countSpace = getCountSpaceEx(listStrings, i, middleX, minX, countSimbols);
                        if (countSpace < 0)
                        {
                            countSpace = 0;
                        }
                        text.Append(' ', countSpace);
                    }
                }

                text.Append(listStrings[i].Text);
                countSimbols      += listStrings[i].Text.Length + countSpace;
                currentCoordinateY = listStrings[i].Coordinate.Y;
                currentHeight      = listStrings[i].TextHeight;
                currentFont        = listStrings[i].FontBase;
                currentCoordinateX = listStrings[i].Coordinate.X;
                currentFontSize    = listStrings[i].FontSize;
                currentScale       = listStrings[i].Scale;
            }

            return(text.ToString());
        }