'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsSystem.Collections.GenericImportsSystem.LinqImports GCTEXT = GrapeCity.Documents.Text '' Shows how to render private use Unicode characters (PUA) with custom EUDC fonts (.tte).PublicClassEUDCFunctionCreatePDF(ByVal stream AsStream) AsInteger'' Test string using EUDC codes and two regular chars (& and !): 0xE620 0xE621 0xE622 0xE624 & 0xE623 !Consttstr = "&!"'' Set up:Dim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.GraphicsDim tf = NewTextFormat() With {.FontSize = 20}Dim rc = Util.AddNote("This sample demonstrates how to render private use Unicode characters (PUA) with custom EUDC fonts (.tte)." + vbLf +"A GrapeCity.Documents.Text.Font can be created from an EUDC .tte file, " +"and linked to one or more fonts using Font.AddEudcFont() method.", page)Constdy = 36.0FDim ip = NewPointF(rc.X, rc.Bottom + dy / 2) '' Use FontCollection to allow fetching fonts by family names:Dim fc = NewFontCollection() '' Assign the font collection to the graphics so that MeasureString/DrawString'' methods on the graphics can find fallback fonts: g.FontCollection = fc '' Register some regular fonts with the FontCollection: fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerif-Regular.ttf")) fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf")) fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSerifSC-Regular.ttf")) fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSans-Light.ttf")) fc.RegisterFont(Path.Combine("Resources", "Fonts", "NotoSans-Condensed.ttf")) '' Tell the font collection to use Noto Serif as a fallback: fc.AppendFallbackFonts(fc.FindFamilyName("Noto Serif")) '' Using Arial font renders the test string as empty rectangles, as suitable glyphs are not present in Noto Sans: tf.Font = fc.FindFamilyName("Noto Sans", False, False) g.DrawString($"Noto Sans: {tstr} (no EUDC font has been linked yet)", tf, ip) ip.Y += dy '' Load two custom EUDC fonts:Dim eudcF0 = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Eudc0.tte"))Dim eudcF1 = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "Eudc1.tte")) '' Link one EUDC font to Noto Sans - now in strings rendered with Noto Sans, EUDC chars will be looked up in this font:Dim fnt = fc.FindFamilyName("Noto Sans") fnt.AddEudcFont(eudcF0)'' Ditto for Noto Serif font: fnt = fc.FindFamilyName("Noto Serif") fnt.AddEudcFont(eudcF0)'' Link another EUDC font to Noto Sans Light: fnt = fc.FindFamilyName("Noto Sans Light") fnt.AddEudcFont(eudcF1) '' Render strings with EUDC chars using fonts to which our custom EUDC font is linked: tf.Font = fc.FindFamilyName("Noto Sans", False, False) g.DrawString($"Noto Sans, linked with Eudc0.tte: {tstr}", tf, ip) ip.Y += dy tf.Font = fc.FindFileName("NotoSerif-Regular.ttf") g.DrawString($"Noto Sans, fallback via Noto Serif: {tstr}", tf, ip) ip.Y += dy tf.Font = fc.FindFamilyName("Noto Sans Condensed") g.DrawString($"Noto Sans Condensed, fallback via Noto Serif: {tstr}", tf, ip) ip.Y += dy tf.Font = fc.FindFamilyName("Noto Sans Light") g.DrawString($"Noto Sans Light, linked with Eudc1.tte: {tstr}", tf, ip) ip.Y += dy '' FontCollection adds some services (like font lookup by family name),'' but EUDC fonts can be linked to fonts that are not in a collection: fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "VLADIMIR.TTF")) fnt.AddEudcFont(eudcF0) tf.Font = fnt g.DrawString($"VLADIMIR Font, linked with Eudc0.tte: {tstr}", tf, ip) ip.Y += dy'''' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass