Alejandro Acuña
2024-10-25 bf65497ed7abf9c669eb3cc0ba219dfa4494b759
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using GrapeCity.Documents.Svg;
using System.Drawing;
using System.Collections.Generic;
 
namespace WorkWithSvgShapes
{
    class Program
    {
        static void Main(string[] args)
        {
            //Open the existing image
            var svg = GcSvgDocument.FromFile(@"GrapeCityLogo.svg");
 
            //Change color of the elements in the image
            for (int i = 0; i <= 2; i++)
            { 
                var el = svg.GetElementsByClass("st"+ i);
                foreach (var e in el)
                {
                    e.Fill = new SvgPaint(Color.FromArgb(56, 93, 171));
                }                
            }
            
 
            //Update logomark
            
            //Translate
            var elementLogo = svg.GetElementByID("logo");
            elementLogo.Transform = new List<SvgTransform>()
                {
                    new SvgTranslateTransform()
                    {
                        TranslateX = new SvgLength(14),
                        TranslateY = new SvgLength(2),
                    }
                };
            //Change color and Add Border
            elementLogo.Fill = new SvgPaint(Color.FromArgb(102, 153, 204));
            elementLogo.Stroke = new SvgPaint(Color.FromArgb(56, 93, 171));
 
 
            //Translate and Rotate Alphabet "e"
            var elements = svg.GetElementsByClass("st1");
            var elementE = elements[5];
            if (elementE != null && elementE is SvgPathElement)
            {
                elementE.FillOpacity = 0.5f;
                elementE.Transform = new List<SvgTransform>()
                {
                    new SvgTranslateTransform()
                    {
                        TranslateX = new SvgLength(2.3f),
                        TranslateY = new SvgLength(62),
                    },
                    new SvgRotateTransform()
                    {
                        Angle = new SvgAngle(-30)
                    }
                };
            }
 
            //Draw rectangle around the Alphabet "e"
            var parent_of_elementE = elementE.Parent;
            if (parent_of_elementE is SvgGroupElement g)
            {
                var rect = new SvgRectElement()
                {
                    X = new SvgLength(109.6f, SvgLengthUnits.Pixels),
                    Y = new SvgLength(17.2f, SvgLengthUnits.Pixels),
                    Width = new SvgLength(16f, SvgLengthUnits.Pixels),
                    Height = new SvgLength(17.2f, SvgLengthUnits.Pixels),
                    StrokeWidth = new SvgLength(0.5f, SvgLengthUnits.Pixels),
                    Stroke = new SvgPaint(Color.FromArgb(56, 93, 171)),
                    Fill = new SvgPaint(SvgColor.Transparent)
                };
                g.Children.Add(rect);
            }
 
            //Adjust Alphabet "C" to fit the rotated "e"
            var elementC = elements[2];
            if (elementC != null && elementC is SvgPathElement)
            {
                elementC.Transform = new List<SvgTransform>()
                {
                    new SvgTranslateTransform()
                    {
                        TranslateX = new SvgLength(0.8f),
                        TranslateY = new SvgLength(0.2f),
                    }
                };
            }
 
            //Save SVG
            svg.Save("GrapeCityLogo_New.svg");
 
            //Create a viewbox instance
            SvgViewBox view = new SvgViewBox();
 
            //Horizontal Layout 250 x 75
            svg.RootSvg.Width = new SvgLength(250, SvgLengthUnits.Pixels);
            svg.RootSvg.Height = new SvgLength(75, SvgLengthUnits.Pixels);
            //Scale to fit the horizontal layout
            view.MinX = 15;
            view.MinY = 5;
            view.Width = 180;
            view.Height = 40;
            svg.RootSvg.ViewBox = view;
            svg.Save("GrapeCityLogo_Horizontal.svg");
 
 
            //Vertical logo Layout
            //Crop for Logomark and remove the other elements
           
            foreach (var node in svg.RootSvg.Children)
            {
                if(node is SvgGroupElement gr)
                {
                    gr.Children.RemoveAt(1);
                }
            }
           
            //Configure the vertical Layout dimensions 
            svg.RootSvg.Width = new SvgLength(160, SvgLengthUnits.Pixels);
            svg.RootSvg.Height = new SvgLength(160, SvgLengthUnits.Pixels);
 
            //Scale to fit the logomark in the vertical layout
            view.MinX = 20.5f;
            view.MinY = 20;
            view.Width = 36;
            view.Height = 17;
            svg.RootSvg.ViewBox = view;
            svg.Save("GrapeCityLogo_Vertical.svg");
        }
 
 
    }
}