Compare commits
3 Commits
element-proxy
...
2021.09
| Author | SHA1 | Date | |
|---|---|---|---|
| 2772b5b4a4 | |||
| 3dfe7a59e0 | |||
| df5c5524ee |
@@ -92,8 +92,8 @@ namespace QuestPDF.Examples
|
|||||||
|
|
||||||
var lineFrom = chapterPointers[index];
|
var lineFrom = chapterPointers[index];
|
||||||
var lineTo = chapterPointers[index + 1] - 1;
|
var lineTo = chapterPointers[index + 1] - 1;
|
||||||
|
|
||||||
var lines = book.Skip(lineFrom + 1).Take(lineTo - lineFrom).Where(x => !string.IsNullOrWhiteSpace(x))
|
var lines = book.Skip(lineFrom + 1).Take(lineTo - lineFrom).Where(x => !string.IsNullOrWhiteSpace(x));
|
||||||
var content = string.Join(Environment.NewLine, lines);
|
var content = string.Join(Environment.NewLine, lines);
|
||||||
|
|
||||||
yield return new BookChapter
|
yield return new BookChapter
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using QuestPDF.Examples.Engine;
|
using QuestPDF.Examples.Engine;
|
||||||
using QuestPDF.Fluent;
|
using QuestPDF.Fluent;
|
||||||
@@ -14,19 +15,52 @@ namespace QuestPDF.Examples
|
|||||||
{
|
{
|
||||||
RenderingTest
|
RenderingTest
|
||||||
.Create()
|
.Create()
|
||||||
.PageSize(PageSizes.A4)
|
.PageSize(500, 400)
|
||||||
.FileName()
|
.FileName()
|
||||||
.ProducePdf()
|
.ProduceImages()
|
||||||
.ShowResults()
|
.ShowResults()
|
||||||
.Render(container =>
|
.Render(container =>
|
||||||
{
|
{
|
||||||
container
|
container
|
||||||
.Padding(20)
|
.Padding(10)
|
||||||
.Box()
|
.Box()
|
||||||
.Border(1)
|
.Border(1)
|
||||||
.Padding(5)
|
.Padding(10)
|
||||||
.Text(text =>
|
.Text(text =>
|
||||||
{
|
{
|
||||||
|
text.DefaultTextStyle(TextStyle.Default);
|
||||||
|
text.AlignLeft();
|
||||||
|
text.ParagraphSpacing(10);
|
||||||
|
|
||||||
|
text.Span(Placeholders.LoremIpsum());
|
||||||
|
|
||||||
|
text.NewLine();
|
||||||
|
|
||||||
|
text.Span("This text is a normal text, ");
|
||||||
|
text.Span("this is a bold text, ", TextStyle.Default.Bold());
|
||||||
|
text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
|
||||||
|
text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
|
||||||
|
|
||||||
|
text.NewLine();
|
||||||
|
|
||||||
|
text.Span("The new text element also supports injecting custom content between words: ");
|
||||||
|
text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
|
||||||
|
text.Span(".");
|
||||||
|
|
||||||
|
text.NewLine();
|
||||||
|
|
||||||
|
text.Span("This is page number ");
|
||||||
|
text.CurrentPageNumber();
|
||||||
|
text.Span(" out of ");
|
||||||
|
text.TotalPages();
|
||||||
|
|
||||||
|
text.NewLine();
|
||||||
|
|
||||||
|
text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
|
||||||
|
|
||||||
|
text.NewLine();
|
||||||
|
|
||||||
|
/*
|
||||||
text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
|
text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
|
||||||
text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
|
text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
|
||||||
text.Span("And tiny \r\n teeny-tiny. ", TextStyle.Default.Size(6));
|
text.Span("And tiny \r\n teeny-tiny. ", TextStyle.Default.Size(6));
|
||||||
@@ -50,7 +84,37 @@ namespace QuestPDF.Examples
|
|||||||
// foreach (var i in Enumerable.Range(1, 100))
|
// foreach (var i in Enumerable.Range(1, 100))
|
||||||
// {
|
// {
|
||||||
// text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
|
// text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
|
||||||
// }
|
// }*/
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PageNumber()
|
||||||
|
{
|
||||||
|
RenderingTest
|
||||||
|
.Create()
|
||||||
|
.PageSize(500, 400)
|
||||||
|
.FileName()
|
||||||
|
.ProduceImages()
|
||||||
|
.ShowResults()
|
||||||
|
.Render(container =>
|
||||||
|
{
|
||||||
|
container
|
||||||
|
.Padding(10)
|
||||||
|
.Box()
|
||||||
|
.Border(1)
|
||||||
|
.Padding(10)
|
||||||
|
.Text(text =>
|
||||||
|
{
|
||||||
|
text.DefaultTextStyle(TextStyle.Default);
|
||||||
|
text.AlignLeft();
|
||||||
|
text.ParagraphSpacing(10);
|
||||||
|
|
||||||
|
text.Span("This is page number ");
|
||||||
|
text.CurrentPageNumber();
|
||||||
|
text.Span(" out of ");
|
||||||
|
text.TotalPages();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,13 @@ namespace QuestPDF.Elements.Text.Items
|
|||||||
var fontMetrics = Style.ToFontMetrics();
|
var fontMetrics = Style.ToFontMetrics();
|
||||||
|
|
||||||
var startIndex = request.StartIndex;
|
var startIndex = request.StartIndex;
|
||||||
|
|
||||||
while (startIndex + 1 < Text.Length && Text[startIndex] == space)
|
if (request.IsFirstLineElement)
|
||||||
startIndex++;
|
{
|
||||||
|
while (startIndex + 1 < Text.Length && Text[startIndex] == space)
|
||||||
|
startIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
if (Text.Length == 0)
|
if (Text.Length == 0)
|
||||||
{
|
{
|
||||||
return new TextMeasurementResult
|
return new TextMeasurementResult
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using QuestPDF.Drawing.SpacePlan;
|
using QuestPDF.Drawing.SpacePlan;
|
||||||
using QuestPDF.Elements.Text.Calculation;
|
using QuestPDF.Elements.Text.Calculation;
|
||||||
@@ -62,14 +63,9 @@ namespace QuestPDF.Elements.Text
|
|||||||
{
|
{
|
||||||
widthOffset = 0f;
|
widthOffset = 0f;
|
||||||
|
|
||||||
var emptySpace = availableSpace.Width - line.Width;
|
var alignmentOffset = GetAlignmentOffset(line.Width);
|
||||||
|
|
||||||
if (Alignment == HorizontalAlignment.Center)
|
Canvas.Translate(new Position(alignmentOffset, 0));
|
||||||
emptySpace /= 2f;
|
|
||||||
|
|
||||||
if (Alignment != HorizontalAlignment.Left)
|
|
||||||
Canvas.Translate(new Position(emptySpace, 0));
|
|
||||||
|
|
||||||
Canvas.Translate(new Position(0, -line.Ascent));
|
Canvas.Translate(new Position(0, -line.Ascent));
|
||||||
|
|
||||||
foreach (var item in line.Elements)
|
foreach (var item in line.Elements)
|
||||||
@@ -92,12 +88,10 @@ namespace QuestPDF.Elements.Text
|
|||||||
widthOffset += item.Measurement.Width;
|
widthOffset += item.Measurement.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Alignment != HorizontalAlignment.Right)
|
Canvas.Translate(new Position(-alignmentOffset, 0));
|
||||||
Canvas.Translate(new Position(emptySpace, 0));
|
Canvas.Translate(new Position(-line.Width, line.Ascent));
|
||||||
|
|
||||||
Canvas.Translate(new Position(-line.Width - emptySpace, line.Ascent));
|
|
||||||
|
|
||||||
Canvas.Translate(new Position(0, line.LineHeight));
|
Canvas.Translate(new Position(0, line.LineHeight));
|
||||||
|
|
||||||
heightOffset += line.LineHeight;
|
heightOffset += line.LineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +110,22 @@ namespace QuestPDF.Elements.Text
|
|||||||
|
|
||||||
if (!RenderingQueue.Any())
|
if (!RenderingQueue.Any())
|
||||||
ResetState();
|
ResetState();
|
||||||
|
|
||||||
|
float GetAlignmentOffset(float lineWidth)
|
||||||
|
{
|
||||||
|
if (Alignment == HorizontalAlignment.Left)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
var emptySpace = availableSpace.Width - lineWidth;
|
||||||
|
|
||||||
|
if (Alignment == HorizontalAlignment.Right)
|
||||||
|
return emptySpace;
|
||||||
|
|
||||||
|
if (Alignment == HorizontalAlignment.Center)
|
||||||
|
return emptySpace / 2;
|
||||||
|
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TextLine> DivideTextItemsIntoLines(float availableWidth, float availableHeight)
|
public IEnumerable<TextLine> DivideTextItemsIntoLines(float availableWidth, float availableHeight)
|
||||||
|
|||||||
@@ -30,13 +30,5 @@
|
|||||||
if (obj.GetType() != this.GetType()) return false;
|
if (obj.GetType() != this.GetType()) return false;
|
||||||
return Equals((Size) obj);
|
return Equals((Size) obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
unchecked
|
|
||||||
{
|
|
||||||
return (Width.GetHashCode() * 397) ^ Height.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user