[]
In GcWord, shape formatting can be applied by using either of the two ways below:
LineFormat and FillFormat properties
Shape styles
If LineFormat and FillFormat properties of a shape are not defined, the fill and line styles (shape styles) are used. But these shape styles are not picked up automatically (in absence of LineFormat and FillFormat properties). The shape styles are only applied when ApplyThemedStyle method is used.
Hence, ApplyThemedStyle method resets original shape formatting and force shape styles to be applied instead. Whereas ApplyPreset method overwrites its FillFormat and LineFormat properties to define a new formatting of shape.
GcWord provides a wide range of predefined preset and themed styles, of which:
Presets can be applied on shapes and pictures both
Themed styles can be applied only on shapes
Shape class provides overloaded ApplyPreset methods where LineShapePreset parameter defines presets for non-fillable shapes like lines,curves etc. and ShapePreset parameter defines preset of colored shape and outline fills.
To apply preset on a non-fillable shape:
Add an arc to a Word document by using Add method of ShapeCollection class and pass GeometryType.Arc as its parameter.
Apply a preset on shape by using ApplyPreset method and set LineShapePreset enumeration to Accent2ColorSolidDashArrowTail.
var doc = new GcWordDocument();
var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(200, 300, GeometryType.Arc);
//Apply LineShapePreset as ShapePreset is not applicable to Arc
shape.ApplyPreset(LineShapePreset.Accent2ColorSolidDashArrowTail);
doc.Save("ShapePreset.docx");
Picture class provides ApplyPreset method to set preset on a picture.
To apply preset on a picture:
Add a picture to a Word document by using Add method of PictureCollection class and set image's path as a parameter to SetImage method.
Apply a preset on picture by using ApplyPreset method and set PicturePreset enumeration to BeveledOvalBlack.
var doc = new GcWordDocument();
var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
var pic = run.GetRange().Pictures.Add();
pic.ImageData.SetImage(new Uri("Resources/folder.png"), "image/png");
//Apply picture preset
pic.ApplyPreset(PicturePreset.BeveledOvalBlack);
doc.Save("PicturePreset.docx");
Note: Picture presets use heavy Effects, which are not supported currently. Hence, its results do not look like Word.
Shape class provides overloaded ApplyThemedStyle methods where ThemeLineStyle parameter defines themed styles for non-fillable shapes like lines,curves etc. and ThemeShapeStyle parameter defines themed styles of colored shape and outline fills.
To apply themed style on a shape:
Add a rounded rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.RoundRectangle as its parameter.
Apply predefined themed style on shape by using ApplyThemedStyle method and set ThemeShapedStyle enumeration to Light1SolidFillAccent5WiderOutline.
var doc = new GcWordDocument();
var run = doc.Body.Paragraphs.Add().GetRange().Runs.Add();
var shape = run.GetRange().Shapes.Add(200, 300, GeometryType.RoundRectangle);
//Apply predefined themed style
shape.ApplyThemedStyle(ThemedShapeStyle.Light1SolidFillAccent5WiderOutline);
//Now shape has Fill.SolidFill.ThemeColor == ThemeColorId.Light1
//And outline Line.Fill.SolidFill colored to ThemeColor.Accent5
doc.Save("ApplyShapeStyle.docx");
Note: In case of applying presets and themed styles on shapes, the use of appropriate overload method depends on the GeometryType of the Shape. If selected overload is not applicable to the shape's geometry, it will return false.
Limitations
Effects and derived classes (EffectsDAG, EffectsList) and custom geometry of shapes are not supported.