ReflectionEffect.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 reflection effect to text and shapes in a DOCX.
  15. public class ReflectionEffect
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20.  
  21. // Custom text reflection:
  22. var style0 = doc.Styles.Add("style0", StyleType.Paragraph);
  23. style0.Font.Size = 48;
  24. // apply top half touching reflection effect to the text
  25. Reflection reflection = style0.Font.Effects.Reflection;
  26. reflection.Distance = 0f;
  27. reflection.Angle = 90f;
  28. reflection.Blur = 0.5f;
  29. reflection.Alignment = RectangleAlignment.BottomLeft;
  30. reflection.ScaleX = 100f;
  31. reflection.ScaleY = -100f;
  32. reflection.SkewX = 0f;
  33. reflection.SkewY = 0f;
  34. reflection.StartOpacity = 60f;
  35. reflection.EndOpacity = 0.9f;
  36. reflection.StartOpacityPosition = 0f;
  37. reflection.EndOpacityPosition = 58f;
  38. reflection.OpacityAngle = 90f;
  39. doc.Body.Paragraphs.Add("Custom text reflection.", style0);
  40.  
  41. // Built-in text reflection (visually the same as the custom reflection above):
  42. var style1 = doc.Styles.Add("style1", StyleType.Paragraph);
  43. style1.Font.Size = 48;
  44. // apply top half touching reflection effect to the text
  45. style1.Font.Effects.ApplyBuiltInReflection(BuiltInReflectionId.HalfTouching);
  46. doc.Body.Paragraphs.Add("Built-in text reflection.", style1);
  47.  
  48. // Shape reflection - direct effects:
  49. Paragraph p = doc.Body.Paragraphs.Add();
  50. Run run = p.GetRange().Runs.Add();
  51. Shape shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Heptagon);
  52. shape.Fill.Type = FillType.Solid;
  53. shape.Fill.SolidFill.RGB = Color.PeachPuff;
  54. shape.Line.Width = 4;
  55. shape.Line.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
  56. shape.Effects.ApplyBuiltInReflection(BuiltInReflectionId.TightTouching);
  57. p.GetRange().Runs.Add("Shape reflection - direct effects.", doc.Styles[BuiltInStyleId.Strong]);
  58.  
  59. // Shape reflection - style effects:
  60. p = doc.Body.Paragraphs.Add();
  61. p.Style.ParagraphFormat.Spacing.SpaceBefore = 50;
  62. run = p.GetRange().Runs.Add();
  63. shape = shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Heptagon);
  64. shape.Fill.Type = FillType.Solid;
  65. shape.Fill.SolidFill.RGB = Color.PeachPuff;
  66. shape.Line.Width = 4;
  67. shape.Line.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
  68. // Apply tight touching reflection effect to the new effect record:
  69. var fmtEffect = doc.Theme.FormatScheme.Effects.Add();
  70. fmtEffect.ApplyBuiltInReflection(BuiltInReflectionId.TightTouching);
  71. // Apply new effect style to shape:
  72. shape.Style.Effects.ThemeEffects = fmtEffect;
  73. p.GetRange().Runs.Add("Shape reflection - style effects.", doc.Styles[BuiltInStyleId.Strong]);
  74.  
  75. // Done:
  76. return doc;
  77. }
  78. }
  79. }
  80.