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");
|
}
|
|
|
}
|
}
|