Esempio n. 1
0
        public static string Decode(byte[] data)
        {
            if (data == null || data.Length <= 0)
            {
                return("");
            }
            //MemoryStream stream = new MemoryStream(data);
            //BinaryReaderFont reader = new BinaryReaderFont(stream);
            CFFStream stream = new CFFStream();

            stream.Push(data);
            CSValue value      = new CSValue();
            int     stackCount = 0;
            int     stemCount  = 0;
            int     length     = data.Length;

            StringBuilder builder = new StringBuilder();

            while (stream.Position < length)
            {
                ReadValue(stream, value, stemCount);
                if (value.isOperator)
                {
                    string name = ToOperatorName(value);
                    if (name.Contains("stem"))
                    {
                        stemCount += stackCount / 2;
                    }
                    builder.Append(name);
                    if (name.Contains("mask"))
                    {
                        stemCount += stackCount / 2;
                        for (int i = 0; i < value.trails.Length; i++)
                        {
                            builder.AppendFormat(" 0x{0:X2}", value.trails[i]);
                        }
                    }
                    builder.AppendLine();
                    stackCount = 0;
                    continue;
                }
                stackCount++;
                builder.AppendFormat("{0} ", value.value);
            }

            //reader.Close();
            //stream.Close();
            //reader.Dispose();
            //stream.Dispose();
            return(builder.ToString());
        }
Esempio n. 2
0
        public GraphicsPath CreateGlyph(byte[] data, bool hasWidth)
        {
            if (data == null || data.Length <= 0)
            {
                return(null);
            }
            stream.Push(data);
            //CSValue value = new CSValue();
            //int length = data.Length;
            int isHinting = 0;
            int width     = 0;

            path      = new GraphicsPath(FillMode.Alternate);
            stemCount = 0;

            //GraphicsPath temp = new GraphicsPath(FillMode.Alternate);
            //List<PointF> points = new List<PointF>();


            while (true)
            {
                if (stream.HasNext() == false)
                {
                    stream.Pop();
                    if (stream.Depth < 1)
                    {
                        break;
                    }
                }
                ReadValue(stream, value, stemCount);
                if (value.isOperator == false)
                {
                    stack.Add(value.value);
                    continue;
                }
                // endchar
                if (value.value == 14)
                {
                    stack.Clear();
                    break;
                }
                if (hasWidth)
                {
                    if (value.value != 10 && value.value != 29)
                    {
                        width = stack[0];
                        stack.RemoveAt(0);
                        hasWidth = false;
                    }
                }

                /*
                 * if (isHinting == 1) {
                 *      isHinting--;
                 *      Exec(value, stack, temp, ref point);
                 *      stack.Clear();
                 *      continue;
                 * }
                 */
                if (isHinting > 0)
                {
                    switch (value.value)
                    {
                    case 21:
                    case 22:
                    case 4:
                        isHinting--;
                        break;
                    }
                }
                //if (isHinting == 0) {
                Exec(value);
                //} else {
                //	Exec(value);
                //}
            }
            path.CloseFigure();
            stream.Clear();
            stack.Clear();
            point.X = 0;
            point.Y = 0;

            GraphicsPath result = path;

            path = null;
            return(result);
        }