コード例 #1
0
        public void ExtractIconsToSVG(string inputFilePath)
        {
            CorelDRAW.Application cdr = new CorelDRAW.Application();
            cdr.OpenDocument(inputFilePath, 1);
            /** obtem todas as paginas do arquivo atual **/
            CorelDRAW.Pages  pages = cdr.ActiveDocument.Pages;
            CorelDRAW.Layers layers;
            // int pageCount = 0;
            /** varre todas as paginas do arquivo atual **/
            foreach (Page correntPage in pages)
            {
                /** obtem todas as camadas da pagina atual **/
                layers = correntPage.AllLayers;
                /** varre todas as camadas de cada pagina **/
                foreach (Layer correntLayer in layers)
                {
                    /** verifica se o nome da camada corrent é Camada 1 **/
                    if (correntLayer.Name.Equals("Camada 1"))
                    {
                        CorelDRAW.TreeNode nodes = correntLayer.TreeNode;
                        foreach (CorelDRAW.TreeNode filhos in nodes.Children)
                        {
                            if (filhos.ShapeType.Equals(CorelDRAW.cdrShapeType.cdrCurveShape))
                            {
                                filhos.Shape.Selected = true;
                                var iconName = GenerateSlug(filhos.Shape.Name.Replace('-', ' '));

                                var outFile = Path.GetDirectoryName(inputFilePath) + $"/{iconName}.svg";
                                rtbLogView.Text += outFile + "\r\n";
                                var filer = CorelDRAW.cdrFilter.cdrSVG;
                                cdr.ActiveDocument.Export(outFile, filer, CorelDRAW.cdrExportRange.cdrSelection);
                                filhos.Shape.Selected = false;
                            }
                        }
                    }
                }
                break;
            }
        }
コード例 #2
0
        void genIcon(List <IconSize> iconSizes, string uri, int typeURI)
        {
            string           folder        = "";
            List <TextShape> iconNames     = new List <TextShape>();
            List <Rect>      iconPositions = new List <Rect>();
            List <string>    cdrFiles      = new List <string>();

            CorelDRAW.Application cdr = new CorelDRAW.Application();

            if (typeURI.Equals(URI_FOLDER_TYPE))
            {
                folder = uri;
                /** Obtem uma lista de todos arquivos da pasta **/
                string[] files = Directory.GetFiles(uri);

                /** cria uma lista contendo apenas arquivos CDR **/
                foreach (string file in files)
                {
                    if (file.Contains(".cdr"))
                    {
                        cdrFiles.Add(file);
                    }
                }
            }
            else if (typeURI.Equals(URI_FILE_TYPE))
            {
                folder = Path.GetDirectoryName(uri);
                if (uri.Contains(".cdr"))
                {
                    cdrFiles.Add(uri);
                }
            }

            /** executa para todos os arquivos CDR da pasta **/
            for (int i = 0; i < cdrFiles.Count; i++)
            {
                string correntFile = cdrFiles[i];
                cdr.OpenDocument(correntFile, 1);
                /** obtem todas as paginas do arquivo atual **/
                CorelDRAW.Pages  pages = cdr.ActiveDocument.Pages;
                CorelDRAW.Layers layers;
                // int pageCount = 0;
                /** varre todas as paginas do arquivo atual **/
                foreach (Page correntPage in pages)
                {
                    /** obtem todas as camadas da pagina atual **/
                    layers = correntPage.AllLayers;
                    /** varre todas as camadas de cada pagina **/
                    foreach (Layer correntLayer in layers)
                    {
                        /** verifica se o nome da camada corrent é Camada 1 **/
                        if (correntLayer.Name.Equals("Camada 1"))
                        {
                            CorelDRAW.TreeNode nodes = correntLayer.TreeNode;
                            foreach (CorelDRAW.TreeNode filhos in nodes.Children)
                            {
                                if (filhos.ShapeType.Equals(CorelDRAW.cdrShapeType.cdrTextShape))
                                {
                                    iconNames.Add(new TextShape(filhos.Shape.BoundingBox, filhos.Shape.Text.Contents));
                                }
                                if (filhos.ShapeType.Equals(CorelDRAW.cdrShapeType.cdrRectangleShape))
                                {
                                    iconPositions.Add(filhos.Shape.BoundingBox);
                                }
                            }
                        }
                    }
                    break;
                }

                /** Converte os icones para PNG com o tamanho determinado pela lista de tamanhos de icones **/
                for (int j = 0; j < iconSizes.Count; j++)
                {
                    if (!Directory.Exists(folder + @"\" + iconSizes[j].folderName))
                    {
                        Directory.CreateDirectory(folder + @"\" + iconSizes[j].folderName);
                    }

                    for (int h = 0; h < iconPositions.Count; h++)
                    {
                        string outputFile = "";
                        Rect   ExportArea = null;

                        for (int l = 0; l < iconNames.Count; l++)
                        {
                            if (iconNames[l].BoundingBox.x == iconPositions[h].x)
                            {
                                ExportArea = iconPositions[h];
                                outputFile = folder + @"\" + iconSizes[j].folderName + @"\" + iconNames[l].Text.Trim() + ".png";// Path.GetFileNameWithoutExtension(CDRFile)
                                CorelDRAW.cdrFilter      filer            = CorelDRAW.cdrFilter.cdrPNG;
                                CorelDRAW.cdrExportRange cdrCurrentPage   = CorelDRAW.cdrExportRange.cdrCurrentPage;
                                CorelDRAW.cdrImageType   cdrRGBColorImage = CorelDRAW.cdrImageType.cdrRGBColorImage;
                                int Width       = iconSizes[j].Width;
                                int Height      = iconSizes[j].Height;
                                int resolutionX = 72;
                                int resolutionY = 72;
                                CorelDRAW.cdrAntiAliasingType cdrNoAntiAliasing = CorelDRAW.cdrAntiAliasingType.cdrNormalAntiAliasing;
                                bool Dithered        = false;
                                bool Transparent     = true;
                                bool UseColorProfile = true;
                                bool MaintainLayers  = false;
                                CorelDRAW.cdrCompressionType cdrCompressionNone = CorelDRAW.cdrCompressionType.cdrCompressionNone;
                                StructPaletteOptions         PaletteOptions     = null;

                                cdr.ActiveDocument.ExportBitmap(outputFile, filer, cdrCurrentPage, cdrRGBColorImage,
                                                                Width, Height, resolutionX, resolutionY,
                                                                cdrNoAntiAliasing,
                                                                Dithered,
                                                                Transparent,
                                                                UseColorProfile,
                                                                MaintainLayers,
                                                                cdrCompressionNone,
                                                                PaletteOptions, ExportArea).Finish();
                            }
                        }
                    }
                }

                cdr.ActiveDocument.Close();
            }
            cdr.Quit();
        }