EmbedFonts.vb
''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.Collections.Generic
Imports System.IO
Imports GrapeCity.Documents.Word

'' This sample shows how to embed font data into a DOCX.
Public Class EmbedFonts
    Function CreateDocx() As GcWordDocument
        Const myFontName1 As String = "My Font 1"
        Const myFontName2 As String = "My Font 2"

        Dim doc = New GcWordDocument()

        Dim p = doc.Body.Paragraphs.Add()
        Dim run = p.GetRange().Runs.Add($"Text rendered using embedded font ""{myFontName1}"".")
        run.Font.Name = myFontName1

        p = doc.Body.Paragraphs.Add()
        run = p.GetRange().Runs.Add($"Text rendered using embedded font ""{myFontName2}"".")
        run.Font.Name = myFontName2

        Dim font1 = doc.Fonts.Add(myFontName1)
        font1.CharSet = FontCharSet.Ansi
        font1.Family = GrapeCity.Documents.Word.FontFamily.Roman
        font1.Pitch = FontPitch.Variable
        font1.Panose = New List(Of Byte) From {2, 2, 6, 3, 5, 4, 5, 2, 3, 4}
        font1.Signature.CodePageRange1 = &H1FFUI
        font1.Signature.CodePageRange2 = 0UI
        font1.Signature.UnicodeRange1 = &HE0002EFFUI
        font1.Signature.UnicodeRange2 = &HC000785BUI
        font1.Signature.UnicodeRange3 = 9UI
        font1.Signature.UnicodeRange4 = 0UI
        Dim data1 As Byte() = File.ReadAllBytes(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf"))
        font1.Embedded.Add(EmbeddedFontType.Regular, FontDataType.ObfuscatedTrueTypeFont, data1)

        Dim font2 = doc.Fonts.Add(myFontName2)
        font2.CharSet = FontCharSet.Ansi
        font2.Family = GrapeCity.Documents.Word.FontFamily.Swiss
        font2.Pitch = FontPitch.Variable
        font2.Panose = New List(Of Byte) From {2, 11, 8, 3, 2, 2, 3, 2, 3, 4}
        font2.Signature.CodePageRange1 = &H1FFUI
        font2.Signature.CodePageRange2 = 0UI
        font2.Signature.UnicodeRange1 = &HE0002EFFUI
        font2.Signature.UnicodeRange2 = &HC000785BUI
        font2.Signature.UnicodeRange3 = 9UI
        font2.Signature.UnicodeRange4 = 0UI
        Dim data2 As Byte() = File.ReadAllBytes(Path.Combine("Resources", "Fonts", "NotoSans-BoldItalic.ttf"))
        font2.Embedded.Add(EmbeddedFontType.BoldItalic, FontDataType.ObfuscatedTrueTypeFont, data2)

        Return doc
    End Function
End Class