BoldItalicEmulation.vb
''
'' このコードは、DioDocs for PDF のサンプルの一部として提供されています。
'' © MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' 通常のフォントを使用するときに太字または斜体のエミュレーションを制御する方法を示します。
Public Class BoldItalicEmulation
Function CreatePDF(ByVal stream As Stream) As Integer
Dim fc = New FontCollection()
'' フォントディレクトリを登録
'' fc.RegisterDirectory(Path.Combine("Resources", "Fonts"));
'' または、より細かく制御するために個別のフォントを登録
fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerifJP-Regular.ttf"))
fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerifJP-Bold.ttf"))
fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerif-Italic.ttf"))
fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerif-BoldItalic.ttf"))
fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
Dim doc = New GcPdfDocument()
Dim g = doc.NewPage().Graphics
Dim rc = Util.AddNote(
"TextFormat.FontStyleでは、太字または斜体のフォントを適用するのではなく、" +
"太字または斜体のエミュレーションを有効にすることができます。", doc.Pages.Last)
'' テキストの挿入位置。
Dim ip = New PointF(rc.Left, rc.Bottom + 36)
Dim tf = New TextFormat()
'' 非太字/非斜体のフォントを取得します。
tf.Font = fc.FindFamilyName("Noto Serif JP", False, False)
tf.FontSize = 16
g.DrawString($"通常のフォント: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
'' 同じ(標準の)フォントを使用して、太字と斜体をエミュレートした文字列を描画します。
tf.FontStyle = GCTEXT.FontStyle.Bold
g.DrawString($"太字をエミュレーション: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.FontStyle = GCTEXT.FontStyle.Italic
g.DrawString($"斜体をエミュレーション: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.FontStyle = GCTEXT.FontStyle.BoldItalic
g.DrawString($"太字と斜体をエミュレーション: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
''
'' フォントの "実際の" 太字/斜体の変種を使用して、いくつかの文字列を描画します。
tf.FontStyle = GCTEXT.FontStyle.Regular
tf.Font = fc.FindFamilyName("Noto Serif JP", True, False)
g.DrawString($"実際の太字フォントを適用: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.Font = fc.FindFamilyName("Noto Serif JP", False, False)
g.DrawString($"実際の斜体フォントを適用: ", tf, ip)
ip.X += 202
tf.Font = fc.FindFamilyName("Noto Serif", False, True)
g.DrawString($"{tf.Font.FullFontName}", tf, ip)
ip.X -= 202
ip.Y += 36
tf.Font = fc.FindFamilyName("Noto Serif JP", False, False)
g.DrawString($"実際の太字/斜体フォントを適用: ", tf, ip)
ip.X += 238
tf.Font = fc.FindFamilyName("Noto Serif", True, True)
g.DrawString($"{tf.Font.FullFontName}", tf, ip)
''
'' PDF ドキュメントを保存します。
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class