BoldItalicEmulation.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Text
  9. Imports GCTEXT = GrapeCity.Documents.Text
  10. Imports GCDRAW = GrapeCity.Documents.Drawing
  11.  
  12. '' Sample shows how to control bold and/or italic emulation when using normal fonts.
  13. Public Class BoldItalicEmulation
  14. Function CreatePDF(ByVal stream As Stream) As Integer
  15. Dim fc = New FontCollection()
  16. fc.RegisterDirectory(Path.Combine("Resources", "Fonts"))
  17. Dim doc = New GcPdfDocument()
  18. Dim g = doc.NewPage().Graphics
  19. Dim rc = Util.AddNote(
  20. "TextFormat.FontStyle enables using Bold and/or Italic emulation" + vbLf +
  21. "on a regular (not a bold/italic) font.", doc.Pages.Last)
  22. '' Text insertion point:
  23. Dim ip = New PointF(rc.Left, rc.Bottom + 36)
  24. Dim tf = New TextFormat()
  25. '' We specifically get a non-bold/non-italic version of the font:
  26. tf.Font = fc.FindFamilyName("Times New Roman", False, False)
  27. tf.FontSize = 16
  28. g.DrawString($"Regular Times font: {tf.Font.FullFontName}", tf, ip)
  29. ip.Y += 36
  30. '' Draw some strings using the same (regular) font but emulating bold and italic:
  31. tf.FontStyle = GCTEXT.FontStyle.Bold
  32. g.DrawString($"Bold emulation using font: {tf.Font.FullFontName}", tf, ip)
  33. ip.Y += 36
  34. tf.FontStyle = GCTEXT.FontStyle.Italic
  35. g.DrawString($"Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
  36. ip.Y += 36
  37. tf.FontStyle = GCTEXT.FontStyle.BoldItalic
  38. g.DrawString($"Bold+Italic emulation using font: {tf.Font.FullFontName}", tf, ip)
  39. ip.Y += 36
  40. ''
  41. '' Now we render some strings using the "real" bold/italic variants of the font:
  42. tf.FontStyle = GCTEXT.FontStyle.Regular
  43. tf.Font = fc.FindFamilyName("Times New Roman", True, False)
  44. g.DrawString($"Using real bold font: {tf.Font.FullFontName}", tf, ip)
  45. ip.Y += 36
  46. tf.Font = fc.FindFamilyName("Times New Roman", False, True)
  47. g.DrawString($"Using real italic font: {tf.Font.FullFontName}", tf, ip)
  48. ip.Y += 36
  49. tf.Font = fc.FindFamilyName("Times New Roman", True, True)
  50. g.DrawString($"Using real bold italic font: {tf.Font.FullFontName}", tf, ip)
  51. ip.Y += 36
  52. ''
  53. '' Done:
  54. doc.Save(stream)
  55. Return doc.Pages.Count
  56. End Function
  57. End Class
  58.