In DsWord, shape formatting can be applied by using either of the two ways below:
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.
DsWord provides a wide range of predefined preset and themed styles, of which:
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:
C# |
Copy Code |
---|---|
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:
C# |
Copy Code |
---|---|
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"); |
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:
C# |
Copy Code |
---|---|
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"); |
Limitations
Effects and derived classes (EffectsDAG, EffectsList) and custom geometry of shapes are not supported.