ConvertToBytes() private method

private ConvertToBytes ( int char1 ) : byte[]
char1 int
return byte[]
Exemplo n.º 1
0
 public override byte[] ConvertToBytes(String text)
 {
     if (cjkMirror != null)
     {
         return(cjkMirror.ConvertToBytes(text));
     }
     else if (isType0)
     {
         char[] chars = text.ToCharArray();
         int    len   = chars.Length;
         byte[] b     = new byte[len * 2];
         int    bptr  = 0;
         for (int k = 0; k < len; ++k)
         {
             int[] ws;
             metrics.TryGetValue((int)chars[k], out ws);
             if (ws != null)
             {
                 int g = ws[0];
                 b[bptr++] = (byte)(g / 256);
                 b[bptr++] = (byte)g;
             }
         }
         if (bptr == b.Length)
         {
             return(b);
         }
         else
         {
             byte[] nb = new byte[bptr];
             System.Array.Copy(b, 0, nb, 0, bptr);
             return(nb);
         }
     }
     else
     {
         char[] cc  = text.ToCharArray();
         byte[] b   = new byte[cc.Length];
         int    ptr = 0;
         for (int k = 0; k < cc.Length; ++k)
         {
             if (uni2byte.ContainsKey(cc[k]))
             {
                 b[ptr++] = (byte)uni2byte[cc[k]];
             }
         }
         if (ptr == b.Length)
         {
             return(b);
         }
         else
         {
             byte[] b2 = new byte[ptr];
             System.Array.Copy(b, 0, b2, 0, ptr);
             return(b2);
         }
     }
 }
Exemplo n.º 2
0
        /** 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.
         * @param text the text to convert
         * @return the conversion
         */
        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[((int)b[k]) & 0xff] = 1;
                }
                break;
            }

            case BaseFont.FONT_TYPE_CJK: {
                int len = text.Length;
                if (cjkFont.IsIdentity())
                {
                    foreach (char c in text)
                    {
                        cjkTag[c] = 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];
                        }
                        cjkTag[cjkFont.GetCidCode(val)] = 0;
                    }
                }
                b = cjkFont.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 int[] { 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 = (int)text[k];
                        }
                        metrics = ttu.GetMetricsTT(val);
                        if (metrics == null)
                        {
                            continue;
                        }
                        int m0 = metrics[0];
                        int gl = m0;
                        if (!longTag.ContainsKey(gl))
                        {
                            longTag[gl] = new int[] { 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);
        }
Exemplo n.º 3
0
        /** 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.
         * @param text the text to convert
         * @return the conversion
         */
        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[((int)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 int[] { metrics[0], metrics[1], ttu.GetUnicodeDifferences(b[k] & 0xff) };
                        glyph[i++]          = (char)metrics[0];
                    }
                }
                else
                {
                    for (int k = 0; k < len; ++k)
                    {
                        char c = text[k];
                        metrics = ttu.GetMetricsTT(c);
                        if (metrics == null)
                        {
                            continue;
                        }
                        int m0 = metrics[0];
                        int gl = m0;
                        if (!longTag.ContainsKey(gl))
                        {
                            longTag[gl] = new int[] { m0, metrics[1], c }
                        }
                        ;
                        glyph[i++] = (char)m0;
                    }
                }
                string s = new String(glyph, 0, i);
                b = System.Text.Encoding.GetEncoding(CJKFont.CJK_ENCODING).GetBytes(s);
                break;
            }
            }
            return(b);
        }