SomeCommonStyles.cs
//
// This code is part of GrapeCity Documents for Word samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.Drawing;
using System.IO;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Imaging;

namespace GcWordWeb.Samples
{
    // This sample demonstrates how to use built-in styles
    // to format a document.
    public class SomeCommonStyles
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();
            var sec = doc.Body.Sections.First;
            var pars = sec.GetRange().Paragraphs;

            // Title:
            pars.Add("Some Common Built-in Styles (Title)", doc.Styles[BuiltInStyleId.Title]);

            // Title:
            pars.Add("Demonstration of some of the built-in styles. (Subtitle)", doc.Styles[BuiltInStyleId.Subtitle]);

            // Headings 1-4:
            var heading1 = pars.Add("Heading 1", doc.Styles[BuiltInStyleId.Heading1]);
            var heading2 = pars.Add("Heading 2", doc.Styles[BuiltInStyleId.Heading2]);
            var heading3 = pars.Add("Heading 3", doc.Styles[BuiltInStyleId.Heading3]);
            var heading4 = pars.Add("Heading 4", doc.Styles[BuiltInStyleId.Heading4]);

            // Normal Text:
            pars.Add("This and the following 'lorem impum' paragraph use the 'Normal' style.");
            pars.Add(SmallPara());

            // Quote:
            pars.Add("The next paragraph uses the 'Quote' style:");
            var p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.Quote]);
            p.Style.ParagraphFormat.KeepTogether = true;

            // Intense Quote:
            pars.Add("The next paragraph uses the 'Intense Quote' style:");
            p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.IntenseQuote]);
            p.Style.ParagraphFormat.KeepTogether = true;

            // Intense Quote:
            pars.Add("The next paragraph uses the 'List Paragraph' style:");
            p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.ListParagraph]);
            p.Style.ParagraphFormat.KeepTogether = true;

            // Character styles:
            p = pars.Add("In this paragraph we demonstrate some of the built-in character styles. ");
            var runs = p.GetRange().Runs;
            runs.Add("This run uses the 'Strong' style. ", doc.Styles[BuiltInStyleId.Strong]);
            runs.Add("A run of normal text. ");
            runs.Add("This run uses 'Emphasis' style. ", doc.Styles[BuiltInStyleId.Emphasis]);
            runs.Add("A run of normal text. ");
            runs.Add("This run uses 'Intense Emphasis' style. ", doc.Styles[BuiltInStyleId.IntenseEmphasis]);
            runs.Add("A run of normal text. ");
            runs.Add("This run uses 'Subtle Emphasis' style. ", doc.Styles[BuiltInStyleId.SubtleEmphasis]);

            pars.Add("The End.");

            // Done:
            return doc;

            string SmallPara()
            {
                return Util.LoremIpsumPar(2, 3, 4, 5);
            }
        }
    }
}