ReflectionEffect.cs
//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
{
    // This example shows how to add reflection effect to text and shapes in a DOCX.
    public class ReflectionEffect
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();

            // 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("Custom text reflection.", style0);

            // Built-in text reflection (visually the same as the custom reflection above):
            var style1 = doc.Styles.Add("style1", StyleType.Paragraph);
            style1.Font.Size = 48;
            // apply top half touching reflection effect to the text
            style1.Font.Effects.ApplyBuiltInReflection(BuiltInReflectionId.HalfTouching);
            doc.Body.Paragraphs.Add("Built-in text reflection.", style1);

            // Shape reflection - direct effects:
            Paragraph p = doc.Body.Paragraphs.Add();
            Run run = p.GetRange().Runs.Add();
            Shape shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Heptagon);
            shape.Fill.Type = FillType.Solid;
            shape.Fill.SolidFill.RGB = Color.PeachPuff;
            shape.Line.Width = 4;
            shape.Line.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
            shape.Effects.ApplyBuiltInReflection(BuiltInReflectionId.TightTouching);
            p.GetRange().Runs.Add("Shape reflection - direct effects.", doc.Styles[BuiltInStyleId.Strong]);

            // Shape reflection - style effects:
            p = doc.Body.Paragraphs.Add();
            p.Style.ParagraphFormat.Spacing.SpaceBefore = 50;
            run = p.GetRange().Runs.Add();
            shape = shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Heptagon);
            shape.Fill.Type = FillType.Solid;
            shape.Fill.SolidFill.RGB = Color.PeachPuff;
            shape.Line.Width = 4;
            shape.Line.Fill.SolidFill.ThemeColor = ThemeColorId.Accent1;
            // Apply tight touching reflection effect to the new effect record:
            var fmtEffect = doc.Theme.FormatScheme.Effects.Add();
            fmtEffect.ApplyBuiltInReflection(BuiltInReflectionId.TightTouching);
            // Apply new effect style to shape:
            shape.Style.Effects.ThemeEffects = fmtEffect;
            p.GetRange().Runs.Add("Shape reflection - style effects.", doc.Styles[BuiltInStyleId.Strong]);

            // Done:
            return doc;
        }
    }
}