2
0
Эх сурвалжийг харах

Fix build and enhanced tests

Marcin Ziąbek 1 жил өмнө
parent
commit
6aa519d2c6

+ 10 - 2
Source/QuestPDF.UnitTests/TextStyleTests.cs

@@ -18,14 +18,17 @@ namespace QuestPDF.UnitTests
                 .Default
                 .FontSize(20)
                 .FontFamily("Arial", "Microsoft YaHei")
-                .BackgroundColor(Colors.Green.Lighten2);
+                .BackgroundColor(Colors.Green.Lighten2)
+                .EnableFontFeature(FontFeatures.StandardLigatures);
 
             var spanTextStyle = TextStyle
                 .Default
                 .FontFamily("Times New Roman", "Arial", "Calibri")
                 .Bold()
                 .Strikethrough()
-                .BackgroundColor(Colors.Red.Lighten2);
+                .BackgroundColor(Colors.Red.Lighten2)
+                .DisableFontFeature(FontFeatures.StandardLigatures)
+                .EnableFontFeature(FontFeatures.Kerning);
             
             // act
             var targetStyle = spanTextStyle.ApplyInheritedStyle(defaultTextStyle).ApplyGlobalStyle();
@@ -38,6 +41,11 @@ namespace QuestPDF.UnitTests
                 FontFamilies = new[] { "Times New Roman", "Arial", "Calibri", "Microsoft YaHei", "Lato" },
                 FontWeight = FontWeight.Bold,
                 BackgroundColor = Colors.Red.Lighten2,
+                FontFeatures = new[]
+                {
+                    (FontFeatures.Kerning, true),
+                    (FontFeatures.StandardLigatures, false)
+                },
                 HasStrikethrough = true
             };
 

+ 2 - 2
Source/QuestPDF/Elements/Text/TextBlock.cs

@@ -65,7 +65,7 @@ namespace QuestPDF.Elements.Text
                 return SpacePlan.Empty();
             
             if (availableSpace.IsNegative())
-                return SpacePlan.Wrap();
+                return SpacePlan.Wrap("The available space is negative.");
 
             // if the text block does not contain any items, or all items are null, return SpacePlan.Empty
             // but if the text block contains only whitespace, return SpacePlan.FullRender with zero width and font-based height
@@ -77,7 +77,7 @@ namespace QuestPDF.Elements.Text
                 
                 return requiredHeight < availableSpace.Height + Size.Epsilon 
                     ? SpacePlan.FullRender(0, requiredHeight) 
-                    : SpacePlan.Wrap();
+                    : SpacePlan.Wrap("The available vertical space is not sufficient to render even a single line of text.");
             }
             
             Initialize();

+ 10 - 5
Source/QuestPDF/Infrastructure/TextStyleManager.cs

@@ -90,7 +90,7 @@ namespace QuestPDF.Infrastructure
             if (property is TextStyleProperty.FontFamilies)
                 value = new ArrayContainer<string>(value);
             
-            if (property is TextStyleProperty.FontFamilies or TextStyleProperty.FontFeatures)
+            if (property is TextStyleProperty.FontFeatures)
                 value = new ArrayContainer<TextStyleFontFeature>(value);
             
             var cacheKey = (origin.Id, property, value);
@@ -185,10 +185,15 @@ namespace QuestPDF.Infrastructure
                 
                 if (origin.FontFeatures?.SequenceEqual(newValue) == true)
                     return origin;
-                
-                newTextStyle.FontFeatures = overrideValue 
-                    ? newValue 
-                    : oldValue.Concat(newValue).GroupBy(x => x.Name).Select(x => x.First()).ToArray();
+
+                var extendedSet = overrideValue
+                    ? newValue.Concat(oldValue)
+                    : oldValue.Concat(newValue);
+                
+                newTextStyle.FontFeatures = extendedSet
+                    .GroupBy(x => x.Name)
+                    .Select(x => x.First())
+                    .ToArray();
 
                 TextStyles.Add(newTextStyle);
                 return newTextStyle;