GlowEffect.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This example shows how to add glow effect to text and shapes in a DOCX.
  15. public class GlowEffect
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20.  
  21. // Custom text glow:
  22. var style0 = doc.Styles.Add("style0", StyleType.Paragraph);
  23. style0.Font.Size = 48;
  24. // apply 5 point accent 6 glow effect to the text
  25. Glow glow = style0.Font.Effects.Glow;
  26. glow.Radius = 5f;
  27. glow.Color.ThemeColor = ThemeColorId.Accent6;
  28. glow.Color.Transparency = 0.6f;
  29. doc.Body.Paragraphs.Add("Custom text glow.", style0);
  30.  
  31. // Built-in text glow:
  32. var style1 = doc.Styles.Add("style1", StyleType.Paragraph);
  33. style1.Font.Size = 48;
  34. // apply 5 point accent 5 glow effect to the text
  35. style1.Font.Effects.ApplyBuiltInGlow(BuiltInGlowId.Radius5Accent5);
  36. doc.Body.Paragraphs.Add("Built-in text glow.", style1);
  37.  
  38. // Shape glow - direct:
  39. var p = doc.Body.Paragraphs.Add();
  40. var run = p.GetRange().Runs.Add();
  41. var shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star5);
  42. shape.Fill.Type = FillType.Solid;
  43. shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
  44. // apply 18 point accent 6 glow effect to the shape
  45. shape.Effects.ApplyBuiltInGlow(BuiltInGlowId.Radius18Accent6);
  46. p.GetRange().Runs.Add("Shape glow - direct.", doc.Styles[BuiltInStyleId.Strong]);
  47.  
  48. // Shape Glow - shapes style - direct color in format scheme’s effect:
  49. p = doc.Body.Paragraphs.Add();
  50. p.Style.ParagraphFormat.Spacing.SpaceBefore = 30;
  51. run = p.GetRange().Runs.Add();
  52. shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star5);
  53. shape.Fill.Type = FillType.Solid;
  54. shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
  55. // apply 18 point accent 6 glow effect to the shape's style
  56. var fmtEffect = doc.Theme.FormatScheme.Effects.Add();
  57. fmtEffect.ApplyBuiltInGlow(BuiltInGlowId.Radius18Accent6);
  58. shape.Style.Effects.ThemeEffects = fmtEffect;
  59. p.GetRange().Runs.Add("Shape Glow - shapes style - direct color in format scheme’s effect.", doc.Styles[BuiltInStyleId.Strong]);
  60.  
  61. // Shape Glow - shapes style - placeholder color in format scheme’s effect:
  62. p = doc.Body.Paragraphs.Add();
  63. p.Style.ParagraphFormat.Spacing.SpaceBefore = 30;
  64. run = p.GetRange().Runs.Add();
  65. shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star5);
  66. shape.Fill.Type = FillType.Solid;
  67. shape.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
  68. //
  69. fmtEffect = doc.Theme.FormatScheme.Effects.Add();
  70. fmtEffect.Glow.Color.ThemeColor = ThemeColorId.None;
  71. // apply 18 point accent 6 glow effect to the shape's style
  72. fmtEffect.Glow.Radius = 18f;
  73. shape.Style.Effects.PlaceholderColor.ThemeColor = ThemeColorId.Accent6;
  74. shape.Style.Effects.PlaceholderColor.Transparency = 0.6f;
  75. shape.Style.Effects.ThemeEffects = fmtEffect;
  76. p.GetRange().Runs.Add("Shape Glow - shapes style - placeholder color in format scheme’s effect.", doc.Styles[BuiltInStyleId.Strong]);
  77.  
  78. // Done:
  79. return doc;
  80. }
  81. }
  82. }
  83.