Exemplo n.º 1
0
        static string DoConvert2(string name, string rawSVG, string transDefFile, bool includeOriginal, int turdSize, decimal minX, decimal minY)
        {
            //1.Apply target Transformations SVG on the source SVG
            //2.Use SVG File to CreateBitmap Object
            //3.Generate SVG File with Transformations
            //4.Return target SVG path

            //Step#1
            string svgWithTrans = ApplyTransformations(rawSVG, transDefFile);

            //Step#2
            Bitmap bitmap         = LoadAsBitmap(svgWithTrans);
            bool   targtDirection = TargetSVGDirection(rawSVG);

            //Step#3
            string targetSVG  = PotraceWrapper.AsSVG(bitmap, Size, false, false, turdSize, false);
            string targetSVG2 = PotraceWrapper.AsSVG(bitmap, Size, false, true, turdSize, false);

            //Step#4
            string targetPath = ExtractPath(targetSVG);

            targetPath = Translate(targetPath, minX, minY, ",", "");

            if (genDebugFiles)
            {
                File.WriteAllText(DebugFile("rawSVG", ".svg", name), rawSVG);
                File.WriteAllText(DebugFile("svgWithTrans", ".svg", name), svgWithTrans);
                bitmap.Save(DebugFile("svgWithTrans", ".bmp", name));

                File.WriteAllText(DebugFile("targetSVG", ".svg", name), targetSVG);
                File.WriteAllText(DebugFile("targetSVG2", ".svg", name), targetSVG2);
            }

            return(targetPath);
        }
Exemplo n.º 2
0
        static bool DoConvert(string glifFile, string targetGlif, string transDefFile, bool includeOriginal, int turdSize)
        {
            //1.Convert glifFile to RawSVG Stream
            //2.Apply target Transformations SVG
            //3.Use SVG File to CreateBitmap Object
            //4.Generate SVG File with Transformations
            //5.Translate Origin based on ViewBox of RawSVG
            //6.Generate glifFile from SVGFile.

            //Step#1
            string rawSVG = ConvertToSVG(glifFile);

            if (string.IsNullOrEmpty(rawSVG))
            {
                return(false);
            }

            //Step#2&3
            string svgWithTrans = ApplyTransformations(rawSVG, transDefFile);

            //Step#3
            Bitmap bitmap = LoadAsBitmap(svgWithTrans);

            {
                string name = new FileInfo(glifFile).Name;
                bitmap.Save(DebugFile("svgWithTrans", ".bmp", name), ImageFormat.Bmp);
            }

            bool targtDirection = TargetDirection(glifFile);

            //Step#4
            string svg  = PotraceWrapper.AsSVG(bitmap, Size, false, false, turdSize, false);
            string svg2 = PotraceWrapper.AsSVG(bitmap, Size, false, true, turdSize, false);

            //Step#5
            ViewBox VB   = ExtractViewBox(rawSVG);           //Can be made part of ConvertToSVG of Step#1
            string  path = GetPath(svg);

            path = Translate(path, VB.MinX, VB.MinY, " ", " ");

            //Step#6
            string targetGlifContent = ConvertToGilf(path, glifFile, includeOriginal);

            File.WriteAllText(targetGlif, targetGlifContent);


            if (genDebugFiles)
            {
                string name = new FileInfo(glifFile).Name;

                File.WriteAllText(DebugFile("rawSVG", ".svg", name), rawSVG);
                File.WriteAllText(DebugFile("svgWithTrans", ".svg", name), svgWithTrans);
                bitmap.Save(DebugFile("svgWithTrans", ".bmp", name), ImageFormat.Bmp);

                File.WriteAllText(DebugFile("targetSVG", ".svg", name), svg);
                File.WriteAllText(DebugFile("targetSVG2", ".svg", name), svg2);
                File.WriteAllText(DebugFile("targetglif", ".glif", name), targetGlifContent);

                string targetglifSVG = ConvertToSVG(DebugFile("targetglif", ".glif", name));
                File.WriteAllText(DebugFile("targetglifSVG", ".svg", name), targetglifSVG);
            }

            return(true);
        }