DrawingML to Skiasharp arcTo conversion problem (Covert PowerPoint Vector Graphics)

47 Views Asked by At

I tried to convert some shapes (PresetGeometry) from PowerPoint, which is DrawingML format, to image file through Skiasharp, everything works fine until I tried to convert arcTo function.

Here is the function that I'm using: path, Target SKPath wR: Width radius, hR: Height radius, stAng: Start angle (in 60,000ths of a degree), swAng: Swing angle (in 60,000ths of a degree), w: Image total width, h: Image total height, refW: Path reference width (Some paths have w & h attribute, if they are provided, they will be passed in), refH: Path reference height


        public static void ArcTo(SKPath path, double wR, double hR, double stAng, double swAng, double w, double h, double? refW = null, double? refH = null)
        {
            // Converting to the rect of the oval
            float rectW = refW != null? (float)((wR) / (double)refW * w * 2): (float)(wR * 2);
            float rectH = refH != null? (float)((hR) / (double)refH * h * 2): (float)(hR * 2);
            
            // Convert stAng in radians
            double angle = (stAng / 60000) * (Math.PI / 180.0);

            // Get the starting point, center of the oval is (0, 0)
            float degreeCoorX = (float)Math.Cos(angle) * (rectW / 2);
            float degreeCoorY = (float)Math.Sin(angle) * (rectH / 2);

            // Top left is (0, 0)
            float degreeCoorTopLeftX = degreeCoorX + rectW / 2;
            float degreeCoorTopLeftY = degreeCoorY + rectH / 2;

            // Get the starting position from top left
            float startingX = path.LastPoint.X - degreeCoorTopLeftX;
            float startingY = path.LastPoint.Y - degreeCoorTopLeftY;

            SKRect rect = new SKRect(startingX, startingY, startingX + rectW, startingY + rectH);

            // Draw it
            path.ArcTo(rect, (float)(stAng / 60000), (float)(swAng / 60000), false);
        }

Powerpoint version: Powerpoint Cloud shape

My version: My version using Skiasharp

This is the source I reference

And I converted to it:


            SKPath path = new SKPath();
            double il = w * 2977 / 21600;
            double it = h * 3262 / 21600;
            double ir = w * 17087 / 21600;
            double ib = h * 17337 / 21600;
            double g27 = w * 67 / 21600;
            double g28 = h * 21577 / 21600;
            double g29 = w * 21582 / 21600;
            double g30 = h * 1235 / 21600;

            path.MoveTo((float)w * 3900 / 43200, (float)h * 14370 / 43200);
            ArcTo(path, 6753, 9190, -11429249, 7426832, w, h, 43200, 43200);
            ArcTo(path, 5333, 7267, -8646143, 5396714, w, h, 43200, 43200);
            ArcTo(path, 4365, 5945, -8748475, 5983381, w, h, 43200, 43200);
            ArcTo(path, 4857, 6595, -7859164, 7034504, w, h, 43200, 43200);
            ArcTo(path, 5333, 7273, -4722533, 6541615, w, h, 43200, 43200);
            ArcTo(path, 6775, 9220, -2776035, 7816140, w, h, 43200, 43200);
            ArcTo(path, 5785, 7867, 37501, 6842000, w, h, 43200, 43200);
            ArcTo(path, 6752, 9215, 1347096, 6910353, w, h, 43200, 43200);
            ArcTo(path, 7720, 10543, 3974558, 4542661, w, h, 43200, 43200);
            ArcTo(path, 4360, 5918, -16496525, 8804134, w, h, 43200, 43200);
            ArcTo(path, 4345, 5945, -14809710, 9151131, w, h, 43200, 43200);
            path.Close();

            path.MoveTo((float)w * 4693 / 43200, (float)h * 26177 / 43200);
            ArcTo(path, 4345, 5945, 5204520, 1585770, w, h, 43200, 43200);
            path.MoveTo((float)w * 6928 / 43200, (float)h * 34899 / 43200);
            ArcTo(path, 4360, 5918, 4416628, 686848, w, h, 43200, 43200);
            path.MoveTo((float)w * 16478 / 43200, (float)h * 39090 / 43200);
            ArcTo(path, 6752, 9215, 8257449, 844866, w, h, 43200, 43200);
            path.MoveTo((float)w * 28827 / 43200, (float)h * 34751 / 43200);
            ArcTo(path, 6752, 9215, 387196, 959901, w, h, 43200, 43200);
            path.MoveTo((float)w * 34129 / 43200, (float)h * 22954 / 43200);
            ArcTo(path, 5785, 7867, -4217541, 4255042, w, h, 43200, 43200);
            path.MoveTo((float)w * 41798 / 43200, (float)h * 15354 / 43200);
            ArcTo(path, 5333, 7273, 1819082, 1665090, w, h, 43200, 43200);
            path.MoveTo((float)w * 38324 / 43200, (float)h * 5426 / 43200);
            ArcTo(path, 4857, 6595, -824660, 891534, w, h, 43200, 43200);
            path.MoveTo((float)w * 29078 / 43200, (float)h * 3952 / 43200);
            ArcTo(path, 4857, 6595, -8950887, 1091722, w, h, 43200, 43200);
            path.MoveTo((float)w * 22141 / 43200, (float)h * 4720 / 43200);
            ArcTo(path, 4365, 5945, -9809656, 1061181, w, h, 43200, 43200);
            path.MoveTo((float)w * 14000 / 43200, (float)h * 5192 / 43200);
            ArcTo(path, 6753, 9190, -4002417, 739161, w, h, 43200, 43200);
            path.MoveTo((float)w * 4127 / 43200, (float)h * 15789 / 43200);
            ArcTo(path, 6753, 9190, 9459261, 711490, w, h, 43200, 43200);
            return path;

It took me a day to figure out and I still don't have any idea, thanks in advance!

0

There are 0 best solutions below