| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- namespace QuestPDF.VisualTests;
- public class TextStyleTests
- {
- private static readonly IEnumerable<Color> FontColor_Values = [ Colors.Red.Darken3, Colors.Green.Darken3, Colors.Blue.Darken3 ];
-
- [Test, TestCaseSource(nameof(FontColor_Values))]
- public void FontsColor(Color fontColor)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be displayed in different ");
- text.Span("font colors").FontColor(fontColor);
- text.Span(".");
- });
- });
- }
-
- private static readonly IEnumerable<Color> BackgroundColor_Values = [ Colors.Red.Lighten4, Colors.Green.Lighten4, Colors.Blue.Lighten4 ];
-
- [Test, TestCaseSource(nameof(BackgroundColor_Values))]
- public void BackgroundColor(Color backgroundColor)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be displayed with different ");
- text.Span("background colors").BackgroundColor(backgroundColor);
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontSize([Values(12, 16, 24)] float fontSize)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be displayed in different ");
- text.Span($"font sizes ({fontSize}pt)").FontSize(fontSize);
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void LineHeight([Values(0.75f, 1f, 1.5f)] float lineHeight)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(400)
- .Text(text =>
- {
- text.Span($"Line height: {lineHeight}\n\n").Bold().FontColor(Colors.Blue.Darken2);
- text.Span(Placeholders.LoremIpsum()).LineHeight(lineHeight);
- });
- });
- }
-
- [Test]
- public void WordSpacing([Values(-0.1f, 0f, 0.25f, 1f)] float wordSpacing)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(400)
- .Text(text =>
- {
- text.Span($"Word spacing: {wordSpacing}\n\n").Bold().FontColor(Colors.Blue.Darken2);
- text.Span(Placeholders.LoremIpsum()).WordSpacing(wordSpacing);
- });
- });
- }
-
- [Test]
- public void LetterSpacing([Values(-0.1f, 0f, 0.1f, 0.25f)] float letterSpacing)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(400)
- .Text(text =>
- {
- text.Span($"Letter spacing: {letterSpacing}\n\n").Bold().FontColor(Colors.Blue.Darken2);
- text.Span(Placeholders.LoremIpsum()).LetterSpacing(letterSpacing);
- });
- });
- }
-
- [Test]
- public void Italic()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("The ");
- text.Span("italic effect").Italic();
- text.Span(" slants the letters slightly to the right.");
- });
- });
- }
-
- #region Font Decoration
-
- [Test]
- public void FontDecoration_Underline()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be decorated with ");
- text.Span("an underline").Underline().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Strikethrough()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be decorated with ");
- text.Span("a strikeout").Strikethrough().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Overline()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text can be decorated with ");
- text.Span("an overline").Overline().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Combined()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Text may have ");
- text.Span("multiple decoration")
- .Underline()
- .Strikethrough()
- .Overline()
- .DecorationThickness(2)
- .DecorationColor(Colors.Blue.Medium);
-
- text.Span(" applied to it.");
- });
- });
- }
-
- private static readonly IEnumerable<Color> FontDecoration_Color_Values = [ Colors.Red.Medium, Colors.Green.Medium, Colors.Blue.Medium ];
-
- [Test, TestCaseSource(nameof(FontDecoration_Color_Values))]
- public void FontDecoration_Color(Color decorationColor)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("The color of ");
- text.Span("the text decoration").Underline().DecorationDashed().DecorationThickness(2).DecorationColor(decorationColor);
- text.Span(" can be changed.");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Thickness([Values(1f, 2f, 3f)] float thickness)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("The thickness of ");
- text.Span("the text decoration").Underline().DecorationWavy().DecorationThickness(thickness).DecorationColor(Colors.Red.Medium);
- text.Span(" can be changed.");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Solid()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a solid-line text decoration").Underline().DecorationSolid();
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Double()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a double-line text decoration").Underline().DecorationDouble();
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Wavy()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a wavy-line text decoration").Underline().DecorationWavy();
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Dotted()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a dotted text decoration").Underline().DecorationDotted();
- text.Span(".");
- });
- });
- }
-
- [Test]
- public void FontDecoration_Dashed()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a dashed text decoration").Underline().DecorationDashed();
- text.Span(".");
- });
- });
- }
-
- #endregion
-
- #region Font Weight
-
- [Test]
- public void FontWeight_200_ExtraLight()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("an extra-light").ExtraLight().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_300_Light()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a light").Light().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_400_Regular()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a regular").NormalWeight().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_500_Medium()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a medium").Medium().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_600_SemiBold()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a semi-bold").SemiBold().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_700_Bold()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("a bold").Bold().BackgroundColor(Colors.Grey.Lighten3);
- text.Span(" font weight.");
- });
- });
- }
-
- [Test]
- public void FontWeight_800_ExtraBold()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("This example shows ");
- text.Span("an extra-bold").ExtraBold().BackgroundColor(Colors.Grey.Lighten3 );
- text.Span(" font weight.");
- });
- });
- }
-
- #endregion
-
- #region Font Position
-
- [Test]
- public void FontPosition_Subscript()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Chemical formula of sulfuric acid: H");
- text.Span("2").Subscript();
- text.Span("SO");
- text.Span("4").Subscript();
- text.Span(".");
- });
- });
- }
- [Test]
- public void FontPosition_Superscript()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text(text =>
- {
- text.Span("Enstein's equation: E=mc");
- text.Span("2").Superscript();
- });
- });
- }
-
- #endregion
-
- #region Font Features
-
- [Test]
- public void FontFeatures_StandardLigatures_Enabled()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text("final")
- .EnableFontFeature(FontFeatures.StandardLigatures);
- });
- }
- [Test]
- public void FontFeatures_StandardLigatures_Disabled()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Text("final")
- .DisableFontFeature(FontFeatures.StandardLigatures);
- });
- }
-
- #endregion
- }
|