Просмотр исходного кода

Fixed rarely broken text alignment caused by too aggressive cache optimization.

Marcin Ziąbek 10 месяцев назад
Родитель
Сommit
36b4493169
1 измененных файлов с 1 добавлено и 6 удалено
  1. 1 6
      Source/QuestPDF/Elements/Text/TextBlock.cs

+ 1 - 6
Source/QuestPDF/Elements/Text/TextBlock.cs

@@ -482,10 +482,7 @@ namespace QuestPDF.Elements.Text
 
         private void CalculateParagraphMetrics(Size availableSpace)
         {
-            // optimization, invalidate cache when both:
-            // 1) the width for which cache was calculated is different from the provided width
-            // 2) provided width is different from the target width of the text component
-            if (AreDifferent(WidthForLineMetricsCalculation, availableSpace.Width) && AreDifferent(MaximumWidth, availableSpace.Width))
+            if (Math.Abs(WidthForLineMetricsCalculation - availableSpace.Width) > Size.Epsilon)
                 AreParagraphMetricsValid = false;
             
             if (AreParagraphMetricsValid) 
@@ -501,8 +498,6 @@ namespace QuestPDF.Elements.Text
             MaximumWidth = LineMetrics.Any() ? LineMetrics.Max(x => x.Width) : 0;
             
             AreParagraphMetricsValid = true;
-            
-            static bool AreDifferent(float x, float y) => Math.Abs(x - y) > Size.Epsilon;
         }
         
         private void CheckUnresolvedGlyphs()