2022-11-05 19:54:20 +01:00
using System ;
2021-09-14 00:16:16 +02:00
using System.Linq ;
2021-09-14 02:02:45 +02:00
using System.Text ;
2021-08-25 03:40:16 +02:00
using NUnit.Framework ;
2022-09-08 13:23:59 +02:00
using QuestPDF.Elements.Text ;
2021-08-09 22:35:39 +02:00
using QuestPDF.Examples.Engine ;
using QuestPDF.Fluent ;
using QuestPDF.Helpers ;
using QuestPDF.Infrastructure ;
2023-01-29 22:00:10 +01:00
using SkiaSharp ;
2021-08-09 22:35:39 +02:00
namespace QuestPDF.Examples
{
public class TextExamples
{
2021-10-01 01:44:42 +02:00
[Test]
2022-05-22 20:25:11 +02:00
public void SimpleText ()
2021-10-01 01:44:42 +02:00
{
RenderingTest
. Create ()
2022-05-22 20:25:11 +02:00
. PageSize ( 500 , 100 )
2021-10-23 02:59:47 +02:00
2021-10-01 01:44:42 +02:00
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 5 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-10-01 01:44:42 +02:00
. Border ( 1 )
. Padding ( 10 )
2022-05-22 20:25:11 +02:00
. Text ( Placeholders . Paragraph ());
});
}
[Test]
public void SimpleTextBlock ()
{
RenderingTest
. Create ()
. PageSize ( 600 , 300 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 5 )
. MinimalBox ()
. Border ( 1 )
. MaxWidth ( 300 )
. Padding ( 10 )
2021-10-01 01:44:42 +02:00
. Text ( text =>
{
2022-03-12 19:17:38 +01:00
text . DefaultTextStyle ( TextStyle . Default . FontSize ( 20 ));
2021-10-01 01:44:42 +02:00
text . Span ( "This is a normal text, followed by an " );
2022-03-12 19:17:38 +01:00
text . Span ( "underlined red text" ). FontColor ( Colors . Red . Medium ). Underline ();
2022-03-12 12:17:00 +01:00
text . Span ( "." );
2021-10-01 01:44:42 +02:00
});
});
}
2022-04-12 18:49:34 +02:00
[Test]
2022-05-09 16:32:59 +02:00
public void TextWeight ()
2022-04-12 18:49:34 +02:00
{
RenderingTest
2022-05-09 16:32:59 +02:00
. Create ()
. PageSize ( 500 , 500 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
2022-04-12 18:49:34 +02:00
. MinimalBox ()
. Border ( 1 )
2022-05-09 16:32:59 +02:00
. Padding ( 20 )
. Text ( text =>
{
text . DefaultTextStyle ( x => x . FontFamily ( Fonts . Calibri ). FontSize ( 20 ));
text . Line ( "Thin" ). Thin ();
text . Line ( "ExtraLight" ). ExtraLight ();
text . Line ( "Light" ). Light ();
text . Line ( "NormalWeight" ). NormalWeight ();
text . Line ( "Medium" ). Medium ();
text . Line ( "SemiBold" ). SemiBold ();
text . Line ( "Bold" ). Bold ();
text . Line ( "ExtraBold" ). ExtraBold ();
text . Line ( "Black" ). Black ();
text . Line ( "ExtraBlack" ). ExtraBlack ();
});
});
}
[Test]
public void LineHeight ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 700 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. Column ( column =>
{
var lineHeights = new [] { 0.8f , 1f , 1.5f };
var paragraph = Placeholders . Paragraph ();
foreach ( var lineHeight in lineHeights )
{
column
. Item ()
. Border ( 1 )
. Padding ( 10 )
. Text ( paragraph )
. FontSize ( 16 )
. LineHeight ( lineHeight );
}
});
});
}
2022-11-03 16:45:49 +01:00
[Test]
public void LetterSpacing ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 700 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. Column ( column =>
{
2022-12-10 17:34:07 +01:00
var letterSpacing = new [] { - 0.1f , 0f , 0.2f };
var paragraph = Placeholders . Sentence (). ToUpper ();
2022-11-03 16:45:49 +01:00
foreach ( var spacing in letterSpacing )
{
column
. Item ()
. Border ( 1 )
. Padding ( 10 )
. Column ( nestedColumn =>
{
nestedColumn . Item ()
. Text ( paragraph )
. FontSize ( 16 )
. LetterSpacing ( spacing );
nestedColumn . Item ()
2022-12-10 17:34:07 +01:00
. Text ( $"Letter spacing of {spacing} em" )
2022-11-03 16:45:49 +01:00
. FontSize ( 10 )
. Italic ()
. FontColor ( Colors . Blue . Medium );
});
2022-12-10 17:34:07 +01:00
2022-11-03 16:45:49 +01:00
}
2022-11-18 15:32:04 +01:00
});
});
}
[Test]
public void LetterSpacing_Arabic ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 700 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 50 )
. Column ( column =>
{
2022-12-10 17:34:07 +01:00
var letterSpacing = new [] { - 0.1f , 0f , 0.2f };
2022-11-18 15:32:04 +01:00
var paragraph = "ينا الألم. في بعض الأحيان ونظراً للالتزامات التي يفرضها علينا" ;
foreach ( var spacing in letterSpacing )
{
column
. Item ()
. Border ( 1 )
. Padding ( 10 )
. Column ( nestedColumn =>
{
nestedColumn . Item ()
. Text ( paragraph )
. FontSize ( 16 )
. FontFamily ( Fonts . Calibri )
. LetterSpacing ( spacing );
nestedColumn . Item ()
2022-12-10 17:34:07 +01:00
. Text ( $"Letter spacing of {spacing} em" )
2022-11-18 15:32:04 +01:00
. FontSize ( 10 )
. Italic ()
. FontColor ( Colors . Blue . Medium );
});
}
});
});
}
[Test]
public void LetterSpacing_Unicode ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 700 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 50 )
. Column ( column =>
{
2022-12-10 17:34:07 +01:00
var letterSpacing = new [] { 0f , 0.5f };
2022-11-18 15:32:04 +01:00
var paragraph = "Ţ̴̡̧̤̮̺̤̗͎̱̹͙͎͖͂̿̓́̉̊̀̍͜h̵̞̘͇̾̎̏̅į̵̹̖͔͉̰̎̉̄̐̏͑͂̅̃̃͘͝s̷͓͉̭̭̯̬̥̻̰̩̦̑̀̀͌́̒̍̒̌̇͛̀͛́̎ ̷̡̡̟͕̳̺̝̼͇͔̬̟̖͍̈́̽͜͝͝i̶͔͚̟̊̐͛́͛̄̌ṡ̸̡̤̪͙͍̥͙̟̼̝̰̥͈̿̓̄̿̓͠ ̶̢̦̙͍̯̖̱̰̯͕͔͎̯̝̎͑t̸͖̲̱̼̎͐̎̉̾̎̾̌̅̔̏͘ȩ̶̝̫̙͓̙̣̔̀̌̔̋̂̑̈́̏̀̈͘̕͜͝s̸̫̝̮̻̼͐̅̄̎̎̑͝ț̷̨̢̨̻͈̮̞̆͗̓͊̃̌͂̑̉̕̕͜͝͝" ;
2022-12-10 17:34:07 +01:00
2022-11-18 15:32:04 +01:00
foreach ( var spacing in letterSpacing )
{
column . Item ()
2022-12-10 17:34:07 +01:00
. Text ( $"Letter spacing of {spacing} em" )
2022-11-18 15:32:04 +01:00
. FontSize ( 10 )
. Italic ()
. FontColor ( Colors . Blue . Medium );
column . Item ()
. PaddingVertical ( 50 )
. Text ( paragraph )
. FontSize ( 16 )
. FontFamily ( Fonts . Calibri )
. LetterSpacing ( spacing );
}
2022-11-03 16:45:49 +01:00
});
});
}
2022-05-09 16:32:59 +02:00
[Test]
public void SuperscriptSubscript_Simple ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 500 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. MinimalBox ()
. Border ( 1 )
. Padding ( 20 )
2022-04-12 18:49:34 +02:00
. Text ( text =>
{
2022-05-06 20:55:18 +02:00
text . DefaultTextStyle ( x => x . FontSize ( 20 ));
2022-05-09 16:32:59 +02:00
text . ParagraphSpacing ( 10 );
var highlight = TextStyle . Default . BackgroundColor ( Colors . Green . Lighten3 );
text . Span ( "E=mc" ). Style ( highlight );
text . Span ( "2" ). Superscript (). Style ( highlight );
text . Span ( " is the equation of mass– energy equivalence." );
2022-04-12 18:49:34 +02:00
text . EmptyLine ();
2022-05-09 16:32:59 +02:00
text . Span ( "H" ). Style ( highlight );
text . Span ( "2" ). Subscript (). Style ( highlight );
text . Span ( "O" ). Style ( highlight );
text . Span ( " is the chemical formula for water." );
2022-05-06 20:55:18 +02:00
});
2022-05-09 16:32:59 +02:00
});
2022-05-06 20:55:18 +02:00
}
2022-05-09 16:32:59 +02:00
2022-05-06 20:55:18 +02:00
[Test]
public void SuperscriptSubscript_Effects ()
{
RenderingTest
. Create ()
. PageSize ( 800 , 400 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 25 )
. DefaultTextStyle ( x => x . FontSize ( 30 ))
. Column ( column =>
{
column . Spacing ( 25 );
column . Item (). Text ( text =>
{
text . DefaultTextStyle ( x => x . Underline ());
text . Span ( "Underline of the superscript (E = mc" );
text . Span ( "2" ). Superscript ();
text . Span ( ") should be at the same height as for normal text." );
});
column . Item (). Text ( text =>
{
text . DefaultTextStyle ( x => x . Underline ());
text . Span ( "Underline of the subscript(H" );
text . Span ( "2" ). Subscript ();
text . Span ( "O) should be slightly lower than a normal text." );
});
column . Item (). Text ( text =>
{
text . DefaultTextStyle ( x => x . Strikethrough ());
text . Span ( "Strikethrough of both superscript (E=mc" );
text . Span ( "2" ). Superscript ();
text . Span ( ") and subscript(H" );
text . Span ( "2" ). Subscript ();
text . Span ( "O) should be visible in the middle of the text." );
});
2022-04-12 18:49:34 +02:00
});
});
}
2021-10-01 01:44:42 +02:00
[Test]
public void ParagraphSpacing ()
{
RenderingTest
. Create ()
2022-05-22 20:25:11 +02:00
. PageSize ( 500 , 500 )
2021-10-01 01:44:42 +02:00
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 5 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-10-01 01:44:42 +02:00
. Border ( 1 )
. Padding ( 10 )
. Text ( text =>
{
2022-05-22 20:25:11 +02:00
text . Line ( Placeholders . Paragraph ());
2021-10-01 01:44:42 +02:00
});
});
}
[Test]
public void CustomElement ()
{
RenderingTest
. Create ()
. PageSize ( 500 , 200 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 5 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-10-01 01:44:42 +02:00
. Border ( 1 )
. Padding ( 10 )
. Text ( text =>
{
2022-03-13 22:47:06 +01:00
text . DefaultTextStyle ( TextStyle . Default . FontSize ( 20 ));
2021-10-01 01:44:42 +02:00
text . Span ( "This is a random image aligned to the baseline: " );
text . Element ()
. PaddingBottom (- 6 )
. Height ( 24 )
. Width ( 48 )
. Image ( Placeholders . Image );
text . Span ( "." );
});
});
}
2021-08-09 22:35:39 +02:00
[Test]
public void TextElements ()
{
RenderingTest
. Create ()
2021-08-25 03:40:16 +02:00
. PageSize ( PageSizes . A4 )
2021-08-09 22:35:39 +02:00
. ProducePdf ()
2021-08-27 01:55:20 +02:00
. ShowResults ()
2021-08-09 22:35:39 +02:00
. Render ( container =>
{
2021-08-25 03:40:16 +02:00
container
. Padding ( 20 )
2021-09-12 21:01:10 +02:00
. Padding ( 10 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-08-25 03:40:16 +02:00
. Border ( 1 )
. Padding ( 5 )
2021-09-12 21:01:10 +02:00
. Padding ( 10 )
2021-08-25 03:40:16 +02:00
. Text ( text =>
{
2021-09-12 21:01:10 +02:00
text . DefaultTextStyle ( TextStyle . Default );
2021-09-12 21:37:46 +02:00
text . AlignLeft ();
2021-09-12 21:01:10 +02:00
text . ParagraphSpacing ( 10 );
2021-09-14 02:02:45 +02:00
text . Line ( Placeholders . LoremIpsum ());
2021-09-12 21:01:10 +02:00
2022-03-08 17:27:30 +01:00
text . Span ( $"This is target text that should show up. {DateTime.UtcNow:T} > This is a short sentence that will be wrapped into second line hopefully, right? <" ). Underline ();
2021-09-14 02:02:45 +02:00
});
});
}
[Test]
2022-01-09 00:11:34 +01:00
public void Textcolumn ()
2021-09-14 02:02:45 +02:00
{
RenderingTest
. Create ()
. PageSize ( PageSizes . A4 )
. ProducePdf ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. Padding ( 10 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-09-14 02:02:45 +02:00
. Border ( 1 )
. Padding ( 5 )
. Padding ( 10 )
. Text ( text =>
{
text . DefaultTextStyle ( TextStyle . Default );
text . AlignLeft ();
text . ParagraphSpacing ( 10 );
foreach ( var i in Enumerable . Range ( 1 , 100 ))
text . Line ( $"{i}: {Placeholders.Paragraph()}" );
2021-09-12 21:01:10 +02:00
});
});
}
2021-09-12 21:37:46 +02:00
[Test]
public void SpaceIssue ()
{
RenderingTest
. Create ()
. PageSize ( PageSizes . A4 )
. ProducePdf ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. Padding ( 10 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-09-12 21:37:46 +02:00
. Border ( 1 )
. Padding ( 5 )
. Padding ( 10 )
. Text ( text =>
{
2022-03-08 17:27:30 +01:00
text . DefaultTextStyle ( x => x . Bold ());
2021-09-12 21:37:46 +02:00
text . DefaultTextStyle ( TextStyle . Default );
text . AlignLeft ();
text . ParagraphSpacing ( 10 );
text . Span ( Placeholders . LoremIpsum ());
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
2021-09-12 21:37:46 +02:00
text . Span ( "This text is a normal text, " );
2022-03-08 17:27:30 +01:00
text . Span ( "this is a bold text, " ). Bold ();
2022-03-11 13:23:36 +01:00
text . Span ( "this is a red and underlined text, " ). FontColor ( Colors . Red . Medium ). Underline ();
text . Span ( "and this is slightly bigger text." ). FontSize ( 16 );
2021-09-12 21:37:46 +02:00
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
2021-09-12 21:37:46 +02:00
text . Span ( "The new text element also supports injecting custom content between words: " );
2022-03-12 12:17:00 +01:00
text . Element (). PaddingBottom (- 4 ). Height ( 16 ). Width ( 32 ). Image ( Placeholders . Image );
2021-09-12 21:37:46 +02:00
text . Span ( "." );
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
2021-09-12 21:37:46 +02:00
text . Span ( "This is page number " );
text . CurrentPageNumber ();
text . Span ( " out of " );
text . TotalPages ();
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
2021-09-12 21:37:46 +02:00
2022-03-12 19:20:01 +01:00
text . Hyperlink ( "Please visit QuestPDF website" , "https://www.questpdf.com" );
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
text . Span ( Placeholders . Paragraphs ());
2021-09-12 21:37:46 +02:00
2021-09-13 01:06:06 +02:00
text . EmptyLine ();
2022-03-08 17:27:30 +01:00
text . Span ( Placeholders . Paragraphs ()). Italic ();
2021-09-13 01:06:06 +02:00
text . Line ( "This is target text that does not show up. " + Placeholders . Paragraph ());
2021-09-12 21:37:46 +02:00
});
});
}
2021-09-13 01:06:06 +02:00
2021-09-12 21:01:10 +02:00
[Test]
2021-09-13 01:06:06 +02:00
public void HugeList ()
2021-09-12 21:01:10 +02:00
{
RenderingTest
. Create ()
2021-09-13 01:06:06 +02:00
. PageSize ( PageSizes . A4 )
. ProducePdf ()
2021-09-12 21:01:10 +02:00
. ShowResults ()
. Render ( container =>
{
container
2021-09-13 01:06:06 +02:00
. Padding ( 20 )
2021-09-12 21:01:10 +02:00
. Padding ( 10 )
2022-01-06 00:22:07 +01:00
. MinimalBox ()
2021-09-12 21:01:10 +02:00
. Border ( 1 )
2021-09-13 01:06:06 +02:00
. Padding ( 5 )
2021-09-12 21:01:10 +02:00
. Padding ( 10 )
. Text ( text =>
{
2022-05-26 00:42:50 +02:00
text . DefaultTextStyle ( TextStyle . Default . FontSize ( 20 ). BackgroundColor ( Colors . Red . Lighten4 ));
2021-09-12 21:01:10 +02:00
text . AlignLeft ();
text . ParagraphSpacing ( 10 );
2021-09-13 01:06:06 +02:00
text . Span ( "This text is a normal text, " );
2022-03-08 17:27:30 +01:00
text . Span ( "this is a bold text, " ). Bold ();
2022-03-11 13:23:36 +01:00
text . Span ( "this is a red and underlined text, " ). FontColor ( Colors . Red . Medium ). Underline ();
text . Span ( "and this is slightly bigger text." ). FontSize ( 16 );
2021-09-13 01:06:06 +02:00
text . Span ( "The new text element also supports injecting custom content between words: " );
2022-03-12 12:17:00 +01:00
text . Element (). PaddingBottom (- 4 ). Height ( 16 ). Width ( 32 ). Image ( Placeholders . Image );
2021-09-13 01:06:06 +02:00
text . Span ( "." );
text . EmptyLine ();
foreach ( var i in Enumerable . Range ( 1 , 100 ))
{
text . Line ( $"{i}: {Placeholders.Paragraph()}" );
2022-05-26 00:42:50 +02:00
text . Hyperlink ( "Please visit QuestPDF website. " , "https://www.questpdf.com" );
2021-09-13 01:06:06 +02:00
text . Span ( "This is page number " );
text . CurrentPageNumber ();
text . Span ( " out of " );
text . TotalPages ();
2021-09-30 22:48:39 +02:00
text . EmptyLine ();
2021-09-13 01:06:06 +02:00
}
2021-08-25 03:40:16 +02:00
});
2021-08-09 22:35:39 +02:00
});
}
2022-03-08 18:33:34 +01:00
[Test]
public void MeasureIssueWhenSpaceAtLineEnd ()
{
// issue 135
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
2022-03-13 22:47:06 +01:00
page . PageColor ( Colors . White );
2022-03-08 18:33:34 +01:00
page . Size ( PageSizes . A4 );
2022-03-12 19:20:01 +01:00
page . Content (). Text ( "This is a specially crafted sentence with a specially chosen length for demonstration of the bug that occurs ;;;;;. " ). FontSize ( 11 ). BackgroundColor ( Colors . Red . Lighten3 );
2022-03-12 12:17:00 +01:00
});
});
}
[Test]
public void EmptyText ()
{
// issue 135
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
2022-03-13 22:47:06 +01:00
page . PageColor ( Colors . White );
2022-03-12 12:17:00 +01:00
page . Size ( PageSizes . A4 );
2022-03-12 19:20:01 +01:00
page . Content (). Text ( " " ). FontSize ( 11 ). BackgroundColor ( Colors . Red . Lighten3 );
2022-03-12 12:17:00 +01:00
});
});
}
[Test]
public void Whitespaces ()
{
// issue 135
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
2022-03-13 22:47:06 +01:00
page . PageColor ( Colors . White );
2022-03-12 12:17:00 +01:00
page . Size ( PageSizes . A4 );
2022-03-12 19:20:01 +01:00
page . Content (). Text ( " x " ). FontSize ( 11 ). BackgroundColor ( Colors . Red . Lighten3 );
2022-03-08 18:33:34 +01:00
});
});
}
2022-03-15 11:55:59 +01:00
[Test]
public void DrawingNullTextShouldNotThrowException ()
{
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
page . PageColor ( Colors . White );
page . Size ( PageSizes . A4 );
page . Content (). Column ( column =>
{
2022-10-08 09:07:03 +03:00
column . Item (). Text (( string ) null );
2022-03-15 11:55:59 +01:00
column . Item (). Text ( text =>
{
text . Span ( null );
text . Line ( null );
text . Hyperlink ( null , "http://www.questpdf.com" );
text . TotalPages (). Format ( x => null );
});
});
});
});
}
2022-03-26 02:58:55 +01:00
[Test]
public void BreakingLongWord ()
{
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
page . PageColor ( Colors . White );
page . Size ( PageSizes . A4 );
page . Content (). Column ( column =>
{
2022-10-08 09:07:03 +03:00
column . Item (). Text (( string ) null );
2022-03-26 02:58:55 +01:00
column . Item (). Text ( text =>
{
2022-03-26 03:34:31 +01:00
text . DefaultTextStyle ( x => x . BackgroundColor ( Colors . Red . Lighten3 ). FontSize ( 24 ));
text . Span ( " " + Placeholders . LoremIpsum ());
2022-05-05 23:52:17 +02:00
text . Span ( " 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 " ). WrapAnywhere ();
2022-03-26 02:58:55 +01:00
});
});
});
});
}
2022-06-12 23:48:38 +02:00
[Test]
public void TextShaping_Unicode ()
{
RenderingTest
. Create ()
. PageSize ( 600 , 100 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 35 )
. MinimalBox ()
. Background ( Colors . Grey . Lighten2 )
. Text ( text =>
{
text . DefaultTextStyle ( TextStyle . Default . FontSize ( 20 ));
text . Span ( "Complex Unicode structure: " );
2022-07-30 21:30:04 +02:00
text . Span ( "T̶̖̔͆͆̽̔ḩ̷̼̫̐̈́̀͜͝͝ì̶͇̤͓̱̣͇͓͉̎s̵̡̟̹͍̜͉̗̾͛̈̐́͋͂͝͠ͅ ̴̨͙͍͇̭̒͗̀́͝ì̷̡̺͉̼̏̏̉̌͝s̷͍͙̗̰̖͙̈̑̂̔͑͊̌̓̊̇͜ ̶̛̼͚͊̅͘ṭ̷̨̘̣̙̖͉͌̏̂̅͑̄̽̕͝ȅ̶̲̲̙̭͈̬̣͔̝͔̈́͝s̸̢̯̪̫͓̭̮̓̀͆͜ț̸̢͉̞̥̤̏̌̓͝" ). FontFamily ( Fonts . Calibri ). FontColor ( Colors . Red . Medium );
2022-06-12 23:48:38 +02:00
text . Span ( "." );
});
});
}
[Test]
public void TextShaping_Arabic ()
{
RenderingTest
. Create ()
2022-10-02 19:50:50 +02:00
. PageSize ( 250 , 100 )
2022-06-12 23:48:38 +02:00
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 25 )
. MinimalBox ()
. Background ( Colors . Grey . Lighten2 )
2022-10-02 19:50:50 +02:00
. Text ( "خوارزمية ترتيب" )
2022-07-30 21:30:04 +02:00
. FontFamily ( Fonts . Calibri )
2022-10-02 19:50:50 +02:00
. FontSize ( 30 );
2022-06-12 23:48:38 +02:00
});
}
2022-09-08 13:23:59 +02:00
[Test]
public void FontFallback ()
{
RenderingTest
. Create ()
2022-09-10 23:27:27 +02:00
. ProduceImages ()
2022-09-08 13:23:59 +02:00
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
page . PageColor ( Colors . White );
2022-09-10 23:27:27 +02:00
page . DefaultTextStyle ( x => x
. Fallback ( y => y . FontFamily ( "Segoe UI Emoji" )
. Fallback ( y => y . FontFamily ( "Microsoft YaHei" ))));
2022-09-08 13:23:59 +02:00
page . Size ( PageSizes . A4 );
page . Content (). Text ( t =>
{
t . Line ( "This is normal text." );
t . EmptyLine ();
2022-09-10 23:27:27 +02:00
2022-09-08 13:23:59 +02:00
t . Line ( "Following line should use font fallback:" );
t . Line ( "中文文本" );
t . EmptyLine ();
2022-09-10 23:27:27 +02:00
2022-09-08 13:23:59 +02:00
t . Line ( "The following line contains a mix of known and unknown characters." );
t . Line ( "Mixed line: This 中文 is 文文 a mixed 本 本 line 本 中文文本!" );
t . EmptyLine ();
t . Line ( "Emojis work out of the box because of font fallback: 😊😅🥳👍❤😍👌" );
});
});
});
}
2022-10-01 00:18:31 +02:00
2022-10-21 12:05:45 +02:00
[Test]
public void WordWrappingStability ()
{
// instruction: check if any characters repeat when performing the word-wrapping algorithm
RenderingTest
. Create ()
. PageSize ( PageSizes . A4 )
. ProducePdf ()
. ShowResults ()
. Render ( container =>
{
var text = "Lorem ipsum dolor sit amet consectetuer" ;
container
. Padding ( 20 )
. Column ( column =>
{
column . Spacing ( 10 );
foreach ( var width in Enumerable . Range ( 25 , 200 ))
{
column
. Item ()
. MaxWidth ( width )
. Background ( Colors . Grey . Lighten3 )
. Text ( text );
}
});
});
}
2022-11-05 19:54:20 +01:00
2022-10-01 00:18:31 +02:00
[Test]
2022-11-07 12:43:55 +01:00
public void AdvancedLanguagesSupport ()
{
RenderingTest
. Create ()
. PageSize ( new PageSize ( 400 , 400 ))
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
var text = "في المعلوماتية أو الرياضيات، خوارزمية الترتيب هي خوارزمية تمكن من تنظيم مجموعة عناصر حسب ترتيب محدد." ;
container
. Padding ( 20 )
. ContentFromRightToLeft ()
. Text ( text )
. FontFamily ( Fonts . Calibri )
. FontSize ( 22 );
});
}
[Test]
public void WordWrappingWhenRightToLeft ()
2022-10-01 00:18:31 +02:00
{
RenderingTest
. Create ()
2022-10-02 19:50:50 +02:00
. PageSize ( new PageSize ( 1000 , 500 ))
2022-10-01 00:18:31 +02:00
. ProducePdf ()
. ShowResults ()
. Render ( container =>
{
2022-10-02 19:50:50 +02:00
var text = "في المعلوماتية أو الرياضيات، خوارزمية الترتيب هي خوارزمية تمكن من تنظيم مجموعة عناصر حسب ترتيب محدد." ;
2022-10-01 00:18:31 +02:00
container
. Padding ( 25 )
. ContentFromRightToLeft ()
. Column ( column =>
{
column . Spacing ( 20 );
2022-10-02 19:50:50 +02:00
foreach ( var size in new [] { 36 , 34 , 32 , 30 , 15 })
2022-10-01 00:18:31 +02:00
{
column
. Item ()
. ShowEntire ()
. MaxWidth ( size * 25 )
. Background ( Colors . Grey . Lighten3 )
. MinimalBox ()
. Background ( Colors . Grey . Lighten2 )
. Text ( text )
. FontSize ( 20 )
2022-10-02 19:50:50 +02:00
. FontFamily ( "Segoe UI" );
2022-10-01 00:18:31 +02:00
}
});
});
}
2022-11-07 12:22:38 +01:00
[Test]
public void ForcingTextDirection ()
{
RenderingTest
. Create ()
. PageSize ( new PageSize ( 1000 , 500 ))
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 10 )
. DefaultTextStyle ( x => x . FontSize ( 24 ). FontFamily ( "Calibri" ))
. Column ( column =>
{
column . Spacing ( 10 );
var word = "الجوريتم" ;
var definition = "algorithm in Arabic" ;
var text = $"{word} - {definition}" ;
// text direction is automatically detected using the first word
column . Item (). Text ( text );
// it is possible to force specific content direction
column . Item (). Text ( text ). DirectionFromLeftToRight ();
column . Item (). Text ( text ). DirectionFromRightToLeft ();
// to combine text in various content directions, split it into segments
column . Item (). Text ( text =>
{
text . Span ( word );
text . Span ( " - " );
text . Span ( definition );
});
});
});
}
2023-01-29 22:00:10 +01:00
[Test]
public void DetectSpanPositionExample ()
{
RenderingTest
. Create ()
. PageSize ( new PageSize ( 650 , 800 ))
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
var fontSize = 20 ;
var paint = new SKPaint
{
Color = SKColors . Red ,
TextSize = fontSize
};
var fontMetrics = paint . FontMetrics ;
var start = 0f ;
var end = 0f ;
// corner case: what if text is paged? clamp start and end?
container
. Padding ( 25 )
. DefaultTextStyle ( x => x . FontSize ( fontSize ). FontFamily ( "Calibri" ))
. Layers ( layers =>
{
layers . PrimaryLayer (). Text ( text =>
{
text . Span ( Placeholders . Paragraph ());
text . Span ( " - " );
// record start
text . Element (). Width ( 0 ). Height ( 0 )
. Canvas (( canvas , size ) => start = canvas . TotalMatrix . TransY / canvas . TotalMatrix . ScaleY );
text . Span ( Placeholders . LoremIpsum ()). BackgroundColor ( Colors . Red . Lighten4 );
// record end
text . Element (). Width ( 0 ). Height ( 0 )
. Canvas (( canvas , size ) => end = canvas . TotalMatrix . TransY / canvas . TotalMatrix . ScaleY );
text . Span ( " - " );
text . Span ( Placeholders . Paragraph ());
});
layers . Layer (). Canvas (( canvas , size ) =>
{
canvas . Save ();
canvas . Translate (- canvas . TotalMatrix . TransX / canvas . TotalMatrix . ScaleX , - canvas . TotalMatrix . TransY / canvas . TotalMatrix . ScaleY );
canvas . DrawRect ( 10 , start + fontMetrics . Ascent , 5 , end - start + ( fontMetrics . Bottom - fontMetrics . Ascent ), paint );
canvas . Restore ();
});
});
});
}
2023-04-16 11:42:38 +02:00
[Test]
public void InconsistentLineHeightWhenUsingNewLineTest ()
{
RenderingTest
. Create ()
. PageSize ( PageSizes . A4 )
. ProduceImages ()
. ShowResults ()
. Render ( container =>
{
container
. Padding ( 20 )
. Background ( Colors . Grey . Lighten4 )
. Text ( text =>
{
text . DefaultTextStyle ( x => x . FontSize ( 16 ));
text . Line ( Placeholders . Paragraph ());
text . Line ( "" );
text . Line ( Placeholders . Paragraph ());
text . Line ( Placeholders . Label ()). FontSize ( 48 );
text . Line ( Placeholders . Paragraph ());
text . Line ( "" );
text . Line ( Placeholders . Paragraph ());
});
});
}
2023-04-22 09:57:07 +02:00
[Test]
public void FontFallback_Nested ()
{
RenderingTest
. Create ()
. ProduceImages ()
. ShowResults ()
. RenderDocument ( container =>
{
container . Page ( page =>
{
page . Margin ( 50 );
page . PageColor ( Colors . White );
page . Size ( PageSizes . A5 . Landscape ());
page . DefaultTextStyle ( x => x
. FontSize ( 24 )
. Bold ()
. FontFamily ( "Times New Roman" )
. Fallback ( y => y
. FontFamily ( "Microsoft YaHei" )
. Underline ()
. BackgroundColor ( Colors . Red . Lighten2 )));
page . Content (). Text ( text =>
{
text . Line ( "Default times new roman 中文文本 text." );
text . Line ( "Normal weight and green 中文文本 text." ). NormalWeight (). BackgroundColor ( Colors . Green . Lighten2 );
text . Line ( "Strikethrough without underline 中文文本 text." ). Strikethrough (). Underline ( false );
text . Line ( "Lato italic 中文文本 text." ). FontFamily ( "Lato" ). Italic ();
});
});
});
}
2021-08-09 22:35:39 +02:00
}
}