vmrocha#31117
I'm trying to write program using GraphicsMill that will generate a PDF with a specific size. What is the best way to draw an ArtText that will fill the maximum area available as possible without having to stretch it? I'm trying to guess what is the best font size doing an exhaustive search for the font size starting on 1. That's not efficient at all and can take a lot of time depending on the target size. Do you have something to recommend?
Imports Aurigma.GraphicsMill
Imports Aurigma.GraphicsMill.AdvancedDrawing
Imports Aurigma.GraphicsMill.AdvancedDrawing.Art
Imports Aurigma.GraphicsMill.AdvancedDrawing.Effects
Imports Aurigma.GraphicsMill.Codecs
Imports DPointF = System.Drawing.PointF
Imports DRectangleF = System.Drawing.RectangleF
(...)
Private Shared Sub UpdateFontSize(options As WarpedTextOptions, graphics As Graphics, targetRect As DRectangleF)
Dim unionBlackbox As New DRectangleF
Dim targetRectPixels As New DRectangleF(
UnitConverter.ConvertUnitsToPixels(options.DPI, targetRect.X, Unit.Point),
UnitConverter.ConvertUnitsToPixels(options.DPI, targetRect.Y, Unit.Point),
UnitConverter.ConvertUnitsToPixels(options.DPI, targetRect.Width, Unit.Point),
UnitConverter.ConvertUnitsToPixels(options.DPI, targetRect.Height, Unit.Point))
options.TextFontSize = 1
Do
options.TextFontSize = options.TextFontSize + 1
Dim artText = GetArtText(options, graphics)
Dim textBlackBox = artText.GetBlackBox()
Dim shadowBlackbox As New DRectangleF(textBlackBox.Location, textBlackBox.Size)
shadowBlackbox.Inflate(options.Shadow.SizePixels, options.Shadow.SizePixels)
shadowBlackbox.Offset(options.Shadow.OffsetXPixels, options.Shadow.OffsetYPixels)
unionBlackbox = DRectangleF.Union(textBlackBox, shadowBlackbox)
Loop While unionBlackbox.Width < targetRectPixels.Width AndAlso unionBlackbox.Height < targetRectPixels.Height
options.TextFontSize = options.TextFontSize - 1
End Sub
(...)