''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) 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
'' Sample shows how to control bold and/or italic emulation when using normal fonts.
Public Class BoldItalicEmulation
Function CreatePDF(ByVal stream As Stream) As Integer
Dim fc = New FontCollection()
fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
Dim doc = New GcPdfDocument()
Dim g = doc.NewPage().Graphics
Dim rc = Util.AddNote(
"TextFormat.FontStyle enables using Bold and/or Italic emulation" + vbLf +
"on a regular (not a bold/italic) font.", doc.Pages.Last)
'' Text insertion point:
Dim ip = New PointF(rc.Left, rc.Bottom + 36)
Dim tf = New TextFormat()
'' We specifically get a non-bold/non-italic version of the font:
tf.Font = fc.FindFamilyName("Times New Roman", False, False)
tf.FontSize = 16
g.DrawString($"Regular Times font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
'' Draw some strings using the same (regular) font but emulating bold and italic:
tf.FontStyle = GCTEXT.FontStyle.Bold
g.DrawString($"Bold emulation using font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.FontStyle = GCTEXT.FontStyle.Italic
g.DrawString($"Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.FontStyle = GCTEXT.FontStyle.BoldItalic
g.DrawString($"Bold+Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
''
'' Now we render some strings using the "real" bold/italic variants of the font:
tf.FontStyle = GCTEXT.FontStyle.Regular
tf.Font = fc.FindFamilyName("Times New Roman", True, False)
g.DrawString($"Using real bold font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.Font = fc.FindFamilyName("Times New Roman", False, True)
g.DrawString($"Using real italic font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
tf.Font = fc.FindFamilyName("Times New Roman", True, True)
g.DrawString($"Using real bold italic font: {tf.Font.FullFontName}", tf, ip)
ip.Y += 36
''
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class