CharsAndFonts.vb
- ''
- '' This code is part of Document Solutions for Imaging demos.
- '' Copyright (c) MESCIUS inc. All rights reserved.
- ''
- Imports System.IO
- Imports System.Drawing
- Imports System.Numerics
- Imports GrapeCity.Documents.Drawing
- Imports GrapeCity.Documents.Text
- Imports GrapeCity.Documents.Imaging
- Imports GCTEXT = GrapeCity.Documents.Text
- Imports GCDRAW = GrapeCity.Documents.Drawing
-
- '' This sample shows how to draw text using different fonts (.ttf, .otf, .woff)
- '' and characters with codes greater than 0xFFFF.
- Public Class CharsAndFonts
- Function GenerateImage(
- ByVal pixelSize As Size,
- ByVal dpi As Single,
- ByVal opaque As Boolean,
- Optional ByVal sampleParams As String() = Nothing) As GcBitmap
-
- Dim garlicFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Woff", "Garlicembrace.woff"))
- Dim foglihtenFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FoglihtenNo07.otf"))
- Dim pericFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "peric.ttf"))
- Dim emojiFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "seguiemj.ttf"))
- Dim timesFont = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf"))
- Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)
- Using g = bmp.CreateGraphics(Color.White)
- Dim tf = New TextFormat With
- {
- .Font = garlicFont,
- .FontSize = 40
- }
- g.DrawString("Garlicembrace.woff", tf, New RectangleF(4, 4, 500, 50))
-
- tf = New TextFormat With
- {
- .Font = timesFont,
- .FontSize = 40
- }
- g.DrawString("Times New Roman", tf, New RectangleF(4, 64, 580, 50))
-
- Dim tl = g.CreateTextLayout()
- tf = New TextFormat With
- {
- .Font = foglihtenFont,
- .FontSize = 40
- }
- tl.Append("FoglihtenNo07.otf", tf)
- g.DrawTextLayout(tl, New PointF(4, 139))
-
- tf = New TextFormat With
- {
- .Font = pericFont,
- .FontSize = 40
- }
- g.DrawString("peric.ttf", tf, New RectangleF(4, 190, 500, 50))
-
- Dim pals = emojiFont.CreateFontTables(TableTag.CpalDraw).GetPalettes()
- tf = New TextFormat With
- {
- .Font = emojiFont,
- .FontSize = 40,
- .Palette = pals(0)
- }
- Dim s1 As String = Char.ConvertFromUtf32(&H1F433)
- Dim s2 As String = Char.ConvertFromUtf32(&H1F349)
- Dim s3 As String = Char.ConvertFromUtf32(&H1F367)
- g.DrawString($"seguiemj.ttf {s1}{s2}{s3}", tf, New RectangleF(4, 240, 550, 50))
- End Using
- Return bmp
- End Function
- End Class
-