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

namespace GcWordWeb.Samples
    // This sample shows how to embed a True Type font from a .ttf font file,
    // and add a paragraph run to a DOCX file using that font.
    // The font in this sample is not very common, so without embedding it
    // the document will not display correctly on many systems.
    public class EmbedFontFile
        public GcWordDocument CreateDocx()
            var doc = new GcWordDocument();
            // Add a paragraph and a run with some text to the document:
            var p = doc.Body.Paragraphs.Add();
            var run = p.GetRange().Runs.Add("the quick brown fox jumps over the lazy dog");
            run.Font.Size = 24;
            // Load font from a .ttf file and set it as the font of the sample text:
            var font = GrapeCity.Documents.Text.Font.FromFile(Path.Combine("Resources", "Fonts", "SEGA.ttf"));
            // Assign the run's font to the font loaded from the file:
            run.Font.Name = font.FontFamilyName;
            // This embeds the font into the document, without this line the document won't display correctly
            // on a system that does not have the SEGA.ttf font installed:
            doc.Fonts.Add(font, true);

            // Done:
            return doc;