Skip to content

Commit

Permalink
Set fontProvider for document.
Browse files Browse the repository at this point in the history
Reorder ProcessHTMLElement conditions.
  • Loading branch information
claudiamurialdo committed Sep 25, 2023
1 parent 7b772de commit 3424951
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected override void init(ref int gxYPage, ref int gxXPage, int pageWidth, in
pdfDocument = new PdfDocument(writer);
pdfDocument.SetDefaultPageSize(this.pageSize);
document = new Document(pdfDocument);
document.SetFontProvider(new DefaultFontProvider());

}
catch (PdfException de)
Expand Down Expand Up @@ -775,7 +776,7 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
try
{
ConverterProperties converterProperties = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider();
FontProvider fontProvider = document.GetFontProvider();
if (IsTrueType(baseFont))
{
Hashtable locations = GetFontLocations();
Expand All @@ -794,7 +795,6 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
}
}
}
document.SetFontProvider(fontProvider);
converterProperties.SetFontProvider(fontProvider);
bottomAux = (float)convertScale(bottom);
topAux = (float)convertScale(top);
Expand Down Expand Up @@ -960,12 +960,13 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
private void ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosition, IBlockElement blockElement)
{
Div div = blockElement as Div;
if (div != null) {
if (div != null)
{
// Iterate through the children of the Div and process each child element recursively
foreach (IElement child in div.GetChildren())
if (child is IBlockElement)
ProcessHTMLElement(htmlRectangle, currentYPosition, (IBlockElement)child);

}

float blockElementHeight = GetBlockElementHeight(blockElement, htmlRectangle);
Expand All @@ -976,55 +977,42 @@ private void ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosit
return;
}

Paragraph p = blockElement as Paragraph;
Table table = blockElement as Table;
List list = blockElement as List;
Link anchor = blockElement as Link;
if (anchor != null)
Image image = blockElement as Image;
if (p != null)
{
anchor.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add((IBlockElement) anchor);
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;
return;
p.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add(p);
}

List list = blockElement as List;
if (list != null)
else if (table != null)
{
table.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add(table);
}
else if (list != null)
{
// This is a hack for the specific case of rendering a list as cb.Add(list) fails to add numeration to each element but document.Add(list) fails to
// consider the numeration of each element as part of it. Solution is to use document.Add(list) and move the list to the right.
float numWidth = new Paragraph("1. ").CreateRendererSubTree().SetParent(document.GetRenderer()).Layout(new LayoutContext(new LayoutArea(this.getPage(), htmlRectangle))).GetOccupiedArea().GetBBox().GetHeight();
list.SetFixedPosition(this.getPage(), htmlRectangle.GetX() + numWidth, currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());

document.Add(list);
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;
return;
}

Table table = blockElement as Table;
if (table != null)
{
table.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add(table);
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;
return;
}

Paragraph p = blockElement as Paragraph;
if (p != null)
else if (anchor != null)
{
p.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add(p);
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;
return;
anchor.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add((IBlockElement)anchor);
}

Image image = blockElement as Image;
if (image != null)
else if (image != null)
{
image.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth());
document.Add(image);
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;
return;
}
currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight;

return;
}

private float GetBlockElementHeight(IBlockElement blockElement, Rectangle htmlRectangle)
Expand Down

0 comments on commit 3424951

Please sign in to comment.