コード例 #1
0
        /// <summary>
        /// Converts the text into bytes to be placed in the document.
        /// The conversion is done according to the font and the encoding and the characters
        /// used are stored.
        /// </summary>
        /// <param name="text">the text to convert</param>
        /// <returns>the conversion</returns>
        internal byte[] ConvertToBytes(string text)
        {
            byte[] b = null;
            switch (_fontType)
            {
            case BaseFont.FONT_TYPE_T3:
                return(_baseFont.ConvertToBytes(text));

            case BaseFont.FONT_TYPE_T1:
            case BaseFont.FONT_TYPE_TT:
            {
                b = _baseFont.ConvertToBytes(text);
                int len = b.Length;
                for (int k = 0; k < len; ++k)
                {
                    _shortTag[b[k] & 0xff] = 1;
                }
                break;
            }

            case BaseFont.FONT_TYPE_CJK:
            {
                int len = text.Length;
                for (int k = 0; k < len; ++k)
                {
                    _cjkTag[_cjkFont.GetCidCode(text[k])] = 0;
                }
                b = _baseFont.ConvertToBytes(text);
                break;
            }

            case BaseFont.FONT_TYPE_DOCUMENT:
            {
                b = _baseFont.ConvertToBytes(text);
                break;
            }

            case BaseFont.FONT_TYPE_TTUNI:
            {
                int    len     = text.Length;
                int[]  metrics = null;
                char[] glyph   = new char[len];
                int    i       = 0;
                if (_symbolic)
                {
                    b   = PdfEncodings.ConvertToBytes(text, "symboltt");
                    len = b.Length;
                    for (int k = 0; k < len; ++k)
                    {
                        metrics = _ttu.GetMetricsTt(b[k] & 0xff);
                        if (metrics == null)
                        {
                            continue;
                        }
                        _longTag[metrics[0]] = new[] { metrics[0], metrics[1], _ttu.GetUnicodeDifferences(b[k] & 0xff) };
                        glyph[i++]           = (char)metrics[0];
                    }
                }
                else
                {
                    for (int k = 0; k < len; ++k)
                    {
                        int val;
                        if (Utilities.IsSurrogatePair(text, k))
                        {
                            val = Utilities.ConvertToUtf32(text, k);
                            k++;
                        }
                        else
                        {
                            val = text[k];
                        }
                        metrics = _ttu.GetMetricsTt(val);
                        if (metrics == null)
                        {
                            continue;
                        }
                        int m0 = metrics[0];
                        int gl = m0;
                        if (!_longTag.ContainsKey(gl))
                        {
                            _longTag[gl] = new[] { m0, metrics[1], val }
                        }
                        ;
                        glyph[i++] = (char)m0;
                    }
                }
                string s = new string(glyph, 0, i);
                b = PdfEncodings.ConvertToBytes(s, CjkFont.CJK_ENCODING);
                break;
            }
            }
            return(b);
        }