示例#1
0
        /// <summary>
        /// Gets the ascent of a
        /// <c>String</c>
        /// in points. The ascent will always be
        /// greater than or equal to zero even if all the characters have a lower ascent.
        /// </summary>
        /// <param name="text">
        /// the
        /// <c>String</c>
        /// to get the ascent of
        /// </param>
        /// <param name="fontSize">the font size</param>
        /// <returns>the ascent in points</returns>
        public virtual int GetAscent(String text, float fontSize)
        {
            int max = 0;

            for (int k = 0; k < text.Length; ++k)
            {
                int ch;
                if (TextUtil.IsSurrogatePair(text, k))
                {
                    ch = TextUtil.ConvertToUtf32(text, k);
                    k++;
                }
                else
                {
                    ch = text[k];
                }
                int[] bbox = GetGlyph(ch).GetBbox();
                if (bbox != null && bbox[3] > max)
                {
                    max = bbox[3];
                }
                else
                {
                    if (bbox == null && GetFontProgram().GetFontMetrics().GetTypoAscender() > max)
                    {
                        max = GetFontProgram().GetFontMetrics().GetTypoAscender();
                    }
                }
            }
            return((int)(max * fontSize / FontProgram.UNITS_NORMALIZATION));
        }
示例#2
0
        /// <summary>
        /// Gets the descent of a
        /// <c>String</c>
        /// in points. The descent will always be
        /// less than or equal to zero even if all the characters have an higher descent.
        /// </summary>
        /// <param name="text">
        /// the
        /// <c>String</c>
        /// to get the descent of
        /// </param>
        /// <param name="fontSize">the font size</param>
        /// <returns>the descent in points</returns>
        public virtual int GetDescent(String text, float fontSize)
        {
            int min = 0;

            for (int k = 0; k < text.Length; ++k)
            {
                int ch;
                if (TextUtil.IsSurrogatePair(text, k))
                {
                    ch = TextUtil.ConvertToUtf32(text, k);
                    k++;
                }
                else
                {
                    ch = text[k];
                }
                Glyph glyph = GetGlyph(ch);
                if (glyph != null)
                {
                    int[] bbox = glyph.GetBbox();
                    if (bbox != null && bbox[1] < min)
                    {
                        min = bbox[1];
                    }
                    else
                    {
                        if (bbox == null && GetFontProgram().GetFontMetrics().GetTypoDescender() < min)
                        {
                            min = GetFontProgram().GetFontMetrics().GetTypoDescender();
                        }
                    }
                }
            }
            return((int)(min * fontSize / FontProgram.UNITS_NORMALIZATION));
        }
示例#3
0
        public override byte[] ConvertToBytes(String text)
        {
            int len = text.Length;

            char[] glyphs = new char[len];
            int    i      = 0;

            if (fontProgram.IsFontSpecific())
            {
                byte[] b = PdfEncodings.ConvertToBytes(text, "symboltt");
                len = b.Length;
                for (int k = 0; k < len; ++k)
                {
                    Glyph glyph = fontProgram.GetGlyph(b[k] & 0xff);
                    if (glyph != null && !longTag.ContainsKey(glyph.GetCode()))
                    {
                        longTag[glyph.GetCode()] = new int[] { glyph.GetCode(), glyph.GetWidth(), glyph.HasValidUnicode() ? glyph.
                                                               GetUnicode() : 0 };
                        glyphs[i++] = (char)cmapEncoding.GetCmapCode(glyph.GetCode());
                    }
                }
            }
            else
            {
                for (int k = 0; k < len; ++k)
                {
                    int val;
                    if (TextUtil.IsSurrogatePair(text, k))
                    {
                        val = TextUtil.ConvertToUtf32(text, k);
                        k++;
                    }
                    else
                    {
                        val = text[k];
                    }
                    Glyph glyph = fontProgram.GetGlyph(val);
                    if (glyph == null)
                    {
                        glyph = fontProgram.GetGlyphByCode(0);
                    }
                    if (!longTag.ContainsKey(glyph.GetCode()))
                    {
                        longTag[glyph.GetCode()] = new int[] { glyph.GetCode(), glyph.GetWidth(), glyph.HasValidUnicode() ? glyph.
                                                               GetUnicode() : 0 };
                    }
                    glyphs[i++] = (char)cmapEncoding.GetCmapCode(glyph.GetCode());
                }
            }
            return(PdfEncodings.ConvertToBytes(new String(glyphs, 0, i), PdfEncodings.UNICODE_BIG_UNMARKED));
        }
示例#4
0
 internal override void AddChar(String mark, CMapObject code)
 {
     if (code.IsNumber())
     {
         int    codePoint;
         String s = ToUnicodeString(mark, true);
         if (TextUtil.IsSurrogatePair(s, 0))
         {
             codePoint = TextUtil.ConvertToUtf32(s, 0);
         }
         else
         {
             codePoint = (int)s[0];
         }
         map.Put(codePoint, (int)code.GetValue());
     }
 }
示例#5
0
        /// <summary>Returns the width of a string of this font in 1000 normalized units.</summary>
        /// <param name="text">a string content.</param>
        /// <returns>a width of string in Text Space.</returns>
        public virtual int GetWidth(String text)
        {
            int total = 0;

            for (int i = 0; i < text.Length; i++)
            {
                int ch;
                if (TextUtil.IsSurrogatePair(text, i))
                {
                    ch = TextUtil.ConvertToUtf32(text, i);
                    i++;
                }
                else
                {
                    ch = text[i];
                }
                Glyph glyph = GetGlyph(ch);
                if (glyph != null)
                {
                    total += glyph.GetWidth();
                }
            }
            return(total);
        }
示例#6
0
        public override GlyphLine CreateGlyphLine(String content)
        {
            IList <Glyph> glyphs = new List <Glyph>();

            if (cidFontType == CID_FONT_TYPE_0)
            {
                int len = content.Length;
                if (cmapEncoding.IsDirect())
                {
                    for (int k = 0; k < len; ++k)
                    {
                        Glyph glyph = fontProgram.GetGlyphByCode((int)content[k]);
                        if (glyph != null)
                        {
                            glyphs.Add(glyph);
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < len; ++k)
                    {
                        int ch;
                        if (TextUtil.IsSurrogatePair(content, k))
                        {
                            ch = TextUtil.ConvertToUtf32(content, k);
                            k++;
                        }
                        else
                        {
                            ch = content[k];
                        }
                        glyphs.Add(GetGlyph(ch));
                    }
                }
            }
            else
            {
                if (cidFontType == CID_FONT_TYPE_2)
                {
                    TrueTypeFont ttf = (TrueTypeFont)fontProgram;
                    int          len = content.Length;
                    if (ttf.IsFontSpecific())
                    {
                        byte[] b = PdfEncodings.ConvertToBytes(content, "symboltt");
                        len = b.Length;
                        for (int k = 0; k < len; ++k)
                        {
                            Glyph glyph = fontProgram.GetGlyph(b[k] & 0xff);
                            if (glyph != null)
                            {
                                glyphs.Add(glyph);
                            }
                        }
                    }
                    else
                    {
                        for (int k = 0; k < len; ++k)
                        {
                            int val;
                            if (TextUtil.IsSurrogatePair(content, k))
                            {
                                val = TextUtil.ConvertToUtf32(content, k);
                                k++;
                            }
                            else
                            {
                                val = content[k];
                            }
                            glyphs.Add(GetGlyph(val));
                        }
                    }
                }
                else
                {
                    throw new PdfException("font.has.no.suitable.cmap");
                }
            }
            return(new GlyphLine(glyphs));
        }