Beispiel #1
0
        public virtual void FillRectangleT(double x1, double y1, double x2, double y2)
        {
            GFXPath rc = new GFXPath();

            rc.MoveTo(x1, y1);
            rc.LineTo(x2, y1);
            rc.LineTo(x2, y2);
            rc.LineTo(x1, y2);
            rc.CloseSubPath();
            FillPathT(rc);
        }
Beispiel #2
0
        private static GFNGlyph ParseGlyph(string val)
        {
            string[]       atoms = val.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            Stack <double> stack = new Stack <double>();
            GFXPath        path  = new GFXPath();
            double         num;
            double?        dx = null;
            double         x, y, bulge, xctl1, yctl1, xctl2, yctl2;



            foreach (string atom in atoms)
            {
                if (double.TryParse(atom, NumberStyles.Float, CultureInfo.InvariantCulture, out num))
                {
                    stack.Push(num);
                }
                else
                { //not a number, assume operator
                    switch (atom)
                    {
                    case "dx":
                        dx = stack.Pop();
                        break;

                    case "m":       //move to
                        y = stack.Pop();
                        x = stack.Pop();
                        path.MoveTo(x, y);
                        break;

                    case "l":       //line to
                        y = stack.Pop();
                        x = stack.Pop();
                        path.LineTo(x, y);
                        break;

                    case "a":       //arc to
                        bulge = stack.Pop();
                        y     = stack.Pop();
                        x     = stack.Pop();
                        path.ArcTo(x, y, bulge);
                        break;

                    case "c":     //curve to
                        y     = stack.Pop();
                        x     = stack.Pop();
                        yctl2 = stack.Pop();
                        xctl2 = stack.Pop();
                        yctl1 = stack.Pop();
                        xctl1 = stack.Pop();
                        path.BezierTo(xctl1, yctl1, xctl2, yctl2, x, y);
                        break;

                    default:
                        throw new Exception("Invalid font program operator '" + atom + "'");
                    }
                }
            }

            if (dx == null)
            {
                throw new Exception("Glyph missing dx operator");
            }

            return(new GFNGlyph(path, (double)dx));
        }