Example #1
0
 private void ParseShapes(List<Shape> shapes)
 {
     Shapes = new List<DrawShape>();
     Paths = new List<DrawPath>();
     foreach (Shape s in shapes)
     {
         uint strokeIndex = (s.Stroke == null) ? 0 : (uint)s.Stroke.UserData;
         uint fillIndex = (s.Fill == null) ? 0 : (uint)s.Fill.UserData;
         DrawPath path = new DrawPath(new List<IShapeData>(s.ShapeData)); // clones data
         int pathIndex = Paths.IndexOf(path);
         if (pathIndex == -1)
         {
             Paths.Add(path);
             pathIndex = Paths.Count - 1;
         }
         DrawShape ds = new DrawShape(strokeIndex, fillIndex, (uint)pathIndex);
         Shapes.Add(ds);
     }
 }
Example #2
0
 private void ParseShapes(List <Shape> shapes)
 {
     Shapes = new List <DrawShape>();
     Paths  = new List <DrawPath>();
     foreach (Shape s in shapes)
     {
         uint     strokeIndex = (s.Stroke == null) ? 0 : (uint)s.Stroke.UserData;
         uint     fillIndex   = (s.Fill == null) ? 0 : (uint)s.Fill.UserData;
         DrawPath path        = new DrawPath(new List <IShapeData>(s.ShapeData)); // clones data
         int      pathIndex   = Paths.IndexOf(path);
         if (pathIndex == -1)
         {
             Paths.Add(path);
             pathIndex = Paths.Count - 1;
         }
         DrawShape ds = new DrawShape(strokeIndex, fillIndex, (uint)pathIndex);
         Shapes.Add(ds);
     }
 }
Example #3
0
        private void WritePath(DrawPath path)
        {
            int count = 0;
            List <SegmentType> types  = new List <SegmentType>();
            List <int>         values = new List <int>();

            Point prevPoint = Point.Empty;

            for (int i = 0; i < path.Segments.Count; i++)
            {
                IShapeData sd = path.Segments[i];

                // moveTo
                if (sd.StartPoint != prevPoint)
                {
                    types.Add(SegmentType.Move);
                    values.Add((int)(sd.StartPoint.X * DrawObject.twips));
                    values.Add((int)(sd.StartPoint.Y * DrawObject.twips));
                    count += 2;
                }

                types.Add(sd.SegmentType);

                switch (sd.SegmentType)
                {
                case SegmentType.Line:
                    values.Add((int)(sd.EndPoint.X * DrawObject.twips));
                    values.Add((int)(sd.EndPoint.Y * DrawObject.twips));
                    count += 2;
                    break;

                case SegmentType.QuadraticBezier:
                    QuadBezier qb = (QuadBezier)sd;
                    values.Add((int)(qb.Control.X * DrawObject.twips));
                    values.Add((int)(qb.Control.Y * DrawObject.twips));
                    values.Add((int)(qb.EndPoint.X * DrawObject.twips));
                    values.Add((int)(qb.EndPoint.Y * DrawObject.twips));
                    count += 4;
                    break;

                case SegmentType.CubicBezier:
                    CubicBezier cb = (CubicBezier)sd;
                    values.Add((int)(cb.Control0.X * DrawObject.twips));
                    values.Add((int)(cb.Control0.Y * DrawObject.twips));
                    values.Add((int)(cb.Control1.X * DrawObject.twips));
                    values.Add((int)(cb.Control1.Y * DrawObject.twips));
                    values.Add((int)(cb.EndPoint.X * DrawObject.twips));
                    values.Add((int)(cb.EndPoint.Y * DrawObject.twips));
                    count += 6;
                    break;
                }

                prevPoint = sd.EndPoint;
            }

            uint dataBits = MinBits(values);

            WriteNBitsCount(dataBits);
            WriteBits(types.Count, 11);

            int[] lens     = new int[] { 2, 2, 4, 6 };
            int   valIndex = 0;

            for (int i = 0; i < types.Count; i++)
            {
                // types  M:0 L:1 Q:2 C:3
                int type = (int)types[i];
                WriteBits(type, 2);
                // data
                for (int j = 0; j < lens[type]; j++)
                {
                    WriteBits(values[valIndex++], dataBits);
                }
            }
        }
Example #4
0
        private void WritePath(DrawPath path)
        {
            int count = 0;
            List<SegmentType> types = new List<SegmentType>();
            List<int> values = new List<int>();

            Point prevPoint = Point.Empty;
            for (int i = 0; i < path.Segments.Count; i++)
            {
                IShapeData sd = path.Segments[i];

                // moveTo
                if (sd.StartPoint != prevPoint)
                {
                    types.Add(SegmentType.Move);
                    values.Add((int)(sd.StartPoint.X * DrawObject.twips));
                    values.Add((int)(sd.StartPoint.Y * DrawObject.twips));
                    count += 2;
                }

                types.Add(sd.SegmentType);

                switch (sd.SegmentType)
                {
                    case SegmentType.Line:
                        values.Add((int)(sd.EndPoint.X * DrawObject.twips));
                        values.Add((int)(sd.EndPoint.Y * DrawObject.twips));
                        count += 2;
                        break;

                    case SegmentType.QuadraticBezier:
                        QuadBezier qb = (QuadBezier)sd;
                        values.Add((int)(qb.Control.X * DrawObject.twips));
                        values.Add((int)(qb.Control.Y * DrawObject.twips));
                        values.Add((int)(qb.EndPoint.X * DrawObject.twips));
                        values.Add((int)(qb.EndPoint.Y * DrawObject.twips));
                        count += 4;
                        break;

                    case SegmentType.CubicBezier:
                        CubicBezier cb = (CubicBezier)sd;
                        values.Add((int)(cb.Control0.X * DrawObject.twips));
                        values.Add((int)(cb.Control0.Y * DrawObject.twips));
                        values.Add((int)(cb.Control1.X * DrawObject.twips));
                        values.Add((int)(cb.Control1.Y * DrawObject.twips));
                        values.Add((int)(cb.EndPoint.X * DrawObject.twips));
                        values.Add((int)(cb.EndPoint.Y * DrawObject.twips));
                        count += 6;
                        break;
                }

                prevPoint = sd.EndPoint;
            }

            uint dataBits = MinBits(values);
            WriteNBitsCount(dataBits);
            WriteBits(types.Count, 11);

            int[] lens = new int[]{2,2,4,6};
            int valIndex = 0;
            for (int i = 0; i < types.Count; i++)
            {
                // types  M:0 L:1 Q:2 C:3
                int type = (int)types[i];
                WriteBits(type, 2);
                // data
                for (int j = 0; j < lens[type]; j++)
                {
                    WriteBits(values[valIndex++], dataBits);
                }
            }
        }