Exemplo n.º 1
0
 public static System.Drawing.SizeF Measure(this string text, Font font, API.Alignment alignment, int maxWidth = int.MaxValue)
 {
     try
     {
         var key  = new TextMeasureKey(text, font, maxWidth, alignment);
         var size = _measurements.GetOrAdd(key,
                                           k =>
         {
             var format = alignment.GetFormat(maxWidth != int.MaxValue);
             lock (DesktopBitmapTextDraw.GraphicsLocker)
             {
                 return(_graphics.Value.MeasureString(k.Text, k.Font, k.MaxWidth, format));
             }
         });
         return(size);
     }
     catch (ObjectDisposedException)
     {
         return(SizeF.Empty);
     }
 }