'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsSystem.IOImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCTEXT = GrapeCity.Documents.TextImportsGrapeCity.Documents.Imaging '' This sample demonstrates how LineBreakingRules and TextExtensionStrategy affect automatic'' line wrapping and distributed justification.'' LineBreakingRules.Unicode and .Simplified may break inside a run of non-whitespace'' characters (e.g. between a Latin/digit run and an adjacent CJK run) to pack a line tighter;'' LineBreakingRules.WhiteSpace only wraps at whitespace, keeping such runs (hyphenated'' identifiers, codes, product names, file names, URLs) intact on one line instead.PublicClassTextJustifyRulesPublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap Dim regular = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSansJP-Regular.ttf"))Dim bold = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSerif-Bold.ttf")) Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi) Using g = bmp.CreateGraphics(Color.White) Dim tl = g.CreateTextLayout() tl.TextAlignment = TextAlignment.Distributed tl.JustifiedSpaceExtension = 0F tl.JustifiedTextExtension = 20F Dim tf = NewTextFormat() With {.FontSize = 14F, .Font = regular}Dim tfInfo = NewTextFormat() With {.FontSize = 9F, .Font = bold} Dim marginx AsSingle = 372, marginy AsSingle = 28 tl.MaxWidth = pixelSize.Width - marginx * 2Dim text = "1234567890-890-9876-54321-123986321 10abc9876 56A-345本列島で使われ456" Dim y AsSingle = marginy y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.EastAsianExcel y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.Excel y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.LineBreakingRules = LineBreakingRules.Simplified tl.WordBoundaryRules = WordBoundaryRules.Simplified tl.TextExtensionStrategy = TextExtensionStrategy.Default y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.EastAsianExcel y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.Excel y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.LineBreakingRules = LineBreakingRules.WhiteSpace tl.WordBoundaryRules = WordBoundaryRules.Unicode'' WordBoundaryRules has no WhiteSpace value - it only affects word-boundary lookups, not wrapping tl.TextExtensionStrategy = TextExtensionStrategy.Default y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.EastAsianExcel y = DrawText(g, tl, y, marginx, tf, tfInfo, text) tl.TextExtensionStrategy = TextExtensionStrategy.Excel y = DrawText(g, tl, y, marginx, tf, tfInfo, text)EndUsingReturn bmpEndFunction PrivateSharedFunctionDrawText(g AsGcGraphics, tl AsTextLayout, y AsSingle, marginx AsSingle, tf AsTextFormat, tfInfo AsTextFormat, text AsString) AsSingle Dim pt = NewPointF(marginx, y + 12) tl.Append(text, tf) tl.PerformLayout(True)Dim rc = NewRectangleF(pt, NewSizeF(tl.ContentWidth, tl.ContentHeight)) g.FillRectangle(rc, Color.PaleGoldenrod) g.DrawString($"LineBreakingRules.{tl.LineBreakingRules}, TextExtensionStrategy.{tl.TextExtensionStrategy}:", tfInfo, NewPointF(marginx / 2.0F, y)) g.DrawTextLayout(tl, pt) tl.Clear()Return rc.Bottom + 8EndFunctionEndClass