Document Solutions for Word
Features / Styles / Text Effect
In This Topic
    Text Effect
    In This Topic

    DsWord lets you set following effects to your text:

    Fill and Line Effect

    DsWord lets you apply effects to your fonts by using the Font.Fill and Font.Line properties. You can set both Fill and Line properties to NoFill, Solid or Gradient type only through Type property. The Type property accepts values from FillType enumeration.

    Font.Fill and Font.Color properties are interdependent. Following table demonstrates their dependency on each other:

    Font.Fill Font.Color
    Not specified Font.Fill takes the value from Font.Color as Solid type.
    Any of Font.Fill properties are specified. Font.Color uses Font.Fill.SolidFill properties.
    Font.Fill type is specified as Gradient. Font.Fill and Font.Color are independent of each other. DsWord uses Font.Fill to render the font. 

    In addition, you can also set the Font.Line property to give your fonts an outline effect. Font.Line and Font.Color are independent of each other.

    C#
    Copy Code
     // Specify gradient fill for the font:
     var fill = style.Font.Fill;
     fill.Type = FillType.Gradient;
     var gradient = fill.GradientFill;
     gradient.Angle = 64;
     gradient.Stops[0].Color.RGB = Color.LightSeaGreen;
     gradient.Stops[1].Color.RGB = Color.Orange;
     
     // Specify the outline for the font:
     var line = style.Font.Line;
     line.Width = 1;
     fill = line.Fill;
     fill.Type = FillType.Solid;
     fill.SolidFill.RGB = Color.Blue;
     
     // Add sample text with the new style:
     doc.Body.Paragraphs.Add("Font Fill and Line styles.", style);        

    Shadow Effect

    The shadow effect adds additional depth to your text. DsWord allows you to apply shadow effects to text using built-in shadow effects and using custom shadow effects. To apply built-in shadow effect to a text, you can use ApplyBuiltInShadow method of the TextEffects class that accepts BuiltInShadowId enum as its parameter. However, for applying custom shadow effect to a text, you can use OuterShadow type of the TextEffects class and set its properties.

    The code below shows how to apply built-in shadow to text using the ApplyBuiltInShadow method:

    C#
    Copy Code
    // apply top right offset shadow effect to the text
    style.Font.Effects.ApplyBuiltInShadow(BuiltInShadowId.OffsetTopRight);
    doc.Body.Paragraphs.Add("Font Shadow", style);

    The code below shows how to apply custom shadow to a text using the OuterShadow type:

    C#
    Copy Code
    // apply top right offset shadow effect to the text
    OuterShadow shadow = style.Font.Effects.Shadow;
    shadow.Alignment = RectangleAlignment.BottomLeft;
    shadow.Angle = 315f;
    shadow.Blur = 4f;
    shadow.Distance = 3f;
    shadow.ScaleX = 100f;
    shadow.ScaleY = 100f;
    shadow.SkewX = 0f;
    shadow.SkewY = 0f;
    shadow.Color.RGB = Color.Black;
    shadow.Color.Transparency = 0.6f;
    doc.Body.Paragraphs.Add("Font Shadow", style);

    Reflection Effect

    DsWord allows you to apply reflection effects to text using built-in reflection effects and custom reflection effects. To apply built-in reflection effect to a text, you can use ApplyBuiltInReflection method of the TextEffects class that accepts BuiltInReflectionId enum as its parameter. However, for applying custom reflection effect to a text, you can use Reflection type of the TextEffects class and set its properties.

    The code below shows how to apply built-in reflection to text using the ApplyBuiltInReflection method:

    C#
    Copy Code
    // apply top half touching reflection effect to the text
    style1.Font.Effects.ApplyBuiltInReflection(BuiltInReflectionId.HalfTouching);
    doc.Body.Paragraphs.Add("Font Reflection.", style1);

    The code below show how to apply custom reflection to text using the Reflection type:

    C#
    Copy Code
    // Custom text reflection:
    var style0 = doc.Styles.Add("style0", StyleType.Paragraph);
    style0.Font.Size = 48;
    // apply top half touching reflection effect to the text
    Reflection reflection = style0.Font.Effects.Reflection;
    reflection.Distance = 0f;
    reflection.Angle = 90f;
    reflection.Blur = 0.5f;
    reflection.Alignment = RectangleAlignment.BottomLeft;
    reflection.ScaleX = 100f;
    reflection.ScaleY = -100f;
    reflection.SkewX = 0f;
    reflection.SkewY = 0f;
    reflection.StartOpacity = 60f;
    reflection.EndOpacity = 0.9f;
    reflection.StartOpacityPosition = 0f;
    reflection.EndOpacityPosition = 58f;
    reflection.OpacityAngle = 90f;
    doc.Body.Paragraphs.Add("Font Reflection.", style0);

    To view the code in action, see Reflection Effect demo sample.

    Glow Format

    DsWord allows you to apply glow effects to text using built-in glow effects and custom glow effects. To apply built-in glow effect to a text, you can use ApplyBuiltInGlow method of the TextEffects class that accepts BuiltInGlowId enum as its parameter. However, for applying custom glow effect to a text, you can use Glow type of the TextEffects class and set its properties.

    The code below shows how to apply built-in glow to a shape using the ApplyBuiltInGlow method:

    C#
    Copy Code
    // apply 5 point accent 5 glow effect to the text
    style.Font.Effects.ApplyBuiltInGlow(BuiltInGlowId.Radius5Accent5);
    doc.Body.Paragraphs.Add("Font Glow", style);

    The code below shows how to apply custom glow effect to a shape:

    C#
    Copy Code
    // apply 5 point accent 6 glow effect to the text
    Glow glow = style.Font.Effects.Glow;
    glow.Radius = 5f;
    glow.Color.ThemeColor = ThemeColorId.Accent6;
    glow.Color.Transparency = 0.6f;
    doc.Body.Paragraphs.Add("Font Glow", style);

    To view the code in action, see Glow Effect Demo sample.

    3D Effect

    The 3D effects refer to the effects applied in three spatial dimensions: width, height, and depth. The 3D effects give the text a unique and artistic look. For applying 3D effects, DsWord provides the ThreeDFormat and ThreeDScene classes and the ApplyEffectsPreset method. The ApplyEffectsPreset method allows a user to add preset 3D effects. However, the ThreeDFormat and ThreeDScene classes allow a user to add custom 3D effects. DsWord also provides an IFixedFormattingBag interface for all text effects and allows a user to understand and control whether the text has a direct effect or is inherited from its parent.

    Preset 3D Effect Custom 3D Effect

     

    Refer to the following example code to add a preset 3D effect to the text:

    C#
    Copy Code
    // Initialize GcWordDocument.
    GcWordDocument doc = new GcWordDocument();
    
    // Add a paragraph to the document.
    Paragraph paragraph = doc.Body.Paragraphs.Add();
    Run run = paragraph.GetRange().Runs.Add("3D Effects");
    
    // Set font size.
    run.Font.Size = 72f;
    
    // Apply preset text 3D effect.
    run.Font.ApplyEffectsPreset(FontEffectsPreset.Preset5);
    
    // Save the Word document.
    doc.Save("Preset3DEffects.docx");

    Refer to the following example code to add a custom 3D effect to the text:

    C#
    Copy Code
    // Initialize GcWordDocument.
    GcWordDocument doc = new GcWordDocument();
    
    // Add a paragraph to the document.
    Paragraph paragraph = doc.Body.Paragraphs.Add();
    Run run = paragraph.GetRange().Runs.Add("3D Effects");
    
    // Set text style.
    GrapeCity.Documents.Word.Font font = run.Font;
    font.Size = 72f;
    font.Bold = true;
    font.Color.ThemeColor = ThemeColorId.Accent3;
    font.Line.Fill.Type = FillType.NoFill;
    
    // Apply 3D effect.
    ThreeDFormat threeD = font.Effects.ThreeDFormat;
    threeD.Material = MaterialType.Matte;
    threeD.Depth.Width = 4.5f;
    threeD.TopBevel.Type = BevelType.Angle;
    threeD.TopBevel.Width = 5f;
    threeD.TopBevel.Height = 1f;
    
    // Save the Word document.
    doc.Save("3DEffects.docx");

    Limitation

    DsWord does not support export of font fill and line, font shadow, reflection, and glow effects to PDF and images.