Document Solutions for Word
Features / Shapes / Presets and Themed Styles
In This Topic
    Presets and Themed Styles
    In This Topic

    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:

    Apply Presets

    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:

    1. Add an arc to a Word document by using Add method of ShapeCollection class and pass GeometryType.Arc as its parameter.
    2. Apply a preset on shape by using ApplyPreset method and set LineShapePreset enumeration to Accent2ColorSolidDashArrowTail.
      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");
    Back to Top

    Picture class provides ApplyPreset method to set preset on a picture.

    To apply preset on a picture:

    1. 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.
    2. Apply a preset on picture by using ApplyPreset method and set PicturePreset enumeration to BeveledOvalBlack.
      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");
    Back to Top
    Note: Picture presets use heavy Effects, which are not supported currently. Hence, its results do not look like Word.

    Apply Themed Styles

    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:

    1. Add a rounded rectangle shape to a Word document by using Add method of ShapeCollection class and pass GeometryType.RoundRectangle as its parameter.
    2. Apply predefined themed style on shape by using ApplyThemedStyle method and set ThemeShapedStyle enumeration to Light1SolidFillAccent5WiderOutline.
      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");

    Back to Top

    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.