2626using iText . Layout . Properties ;
2727using iText . Layout . Splitting ;
2828using log4net ;
29- using NetTopologySuite . Utilities ;
30- using static iText . Kernel . Pdf . Colorspace . PdfPattern ;
3129using Path = System . IO . Path ;
32- using Text = iText . Layout . Element . Text ;
3330
3431namespace GeneXus . Printer
3532{
3633
37- public class GxReportBuilderPdf7 : GxReportBuilderPdf
34+ public class GxReportBuilderPdf8 : GxReportBuilderPdf
3835 {
3936 static ILog log = log4net . LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
40- public GxReportBuilderPdf7 ( ) { }
41- public GxReportBuilderPdf7 ( string appPath , Stream outputStream )
37+ public GxReportBuilderPdf8 ( ) { }
38+ public GxReportBuilderPdf8 ( string appPath , Stream outputStream )
4239 {
4340
44- _pdfReport = new com . genexus . reports . PDFReportItextSharp7 ( appPath ) ;
41+ _pdfReport = new com . genexus . reports . PDFReportItext8 ( appPath ) ;
4542 if ( outputStream != null )
4643 {
4744 _pdfReport . setOutputStream ( outputStream ) ;
@@ -54,7 +51,7 @@ public GxReportBuilderPdf7(string appPath, Stream outputStream)
5451namespace com . genexus . reports
5552{
5653
57- public class PDFReportItextSharp7 : PDFReportItextBase
54+ public class PDFReportItext8 : PDFReportItextBase
5855 {
5956
6057 static ILog log = log4net . LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
@@ -78,7 +75,7 @@ public class PDFReportItextSharp7 : PDFReportItextBase
7875 private Boolean fontBold ;
7976 private Boolean fontItalic ;
8077
81- public PDFReportItextSharp7 ( String appPath ) : base ( appPath )
78+ public PDFReportItext8 ( String appPath ) : base ( appPath )
8279 {
8380 documentImages = new Dictionary < string , Image > ( ) ;
8481 }
@@ -777,6 +774,28 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
777774 {
778775 try
779776 {
777+ ConverterProperties converterProperties = new ConverterProperties ( ) ;
778+ FontProvider fontProvider = new DefaultFontProvider ( ) ;
779+ if ( IsTrueType ( baseFont ) )
780+ {
781+ Hashtable locations = GetFontLocations ( ) ;
782+ foreach ( string fontName in locations . Keys )
783+ {
784+ string fontPath = ( string ) locations [ fontName ] ;
785+ if ( string . IsNullOrEmpty ( fontPath ) )
786+ {
787+ MSPDFFontDescriptor fontDescriptor = new MSPDFFontDescriptor ( ) ;
788+ fontPath = fontDescriptor . getTrueTypeFontLocation ( fontName ) ;
789+ }
790+ if ( ! string . IsNullOrEmpty ( fontPath ) )
791+ {
792+
793+ fontProvider . AddFont ( fontPath ) ;
794+ }
795+ }
796+ }
797+ document . SetFontProvider ( fontProvider ) ;
798+ converterProperties . SetFontProvider ( fontProvider ) ;
780799 bottomAux = ( float ) convertScale ( bottom ) ;
781800 topAux = ( float ) convertScale ( top ) ;
782801 float drawingPageHeight = this . pageSize . GetTop ( ) - topMargin - bottomMargin ;
@@ -792,12 +811,11 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
792811 PdfCanvas htmlPdfCanvas = new PdfCanvas ( pdfPage ) ;
793812 Canvas htmlCanvas = new Canvas ( canvas , htmlRectangle ) ;
794813
795- ConverterProperties converterProperties = new ConverterProperties ( ) ;
796- converterProperties . SetFontProvider ( new DefaultFontProvider ( ) ) ;
814+
797815 //Iterate over the elements (a.k.a the parsed HTML string) and handle each case accordingly
798- IList < IElement > elements = HtmlConverter . ConvertToElements ( sTxt , new ConverterProperties ( ) ) ;
816+ IList < IElement > elements = HtmlConverter . ConvertToElements ( sTxt , converterProperties ) ;
799817 foreach ( IElement element in elements )
800- ProcessHTMLElement ( htmlRectangle , yPosition , ( IBlockElement ) element ) ;
818+ ProcessHTMLElement ( htmlRectangle , yPosition , ( IBlockElement ) element , fontProvider ) ;
801819 }
802820 catch ( Exception ex1 )
803821 {
@@ -939,14 +957,14 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b
939957 }
940958 }
941959
942- private void ProcessHTMLElement ( Rectangle htmlRectangle , YPosition currentYPosition , IBlockElement blockElement )
960+ private void ProcessHTMLElement ( Rectangle htmlRectangle , YPosition currentYPosition , IBlockElement blockElement , FontProvider fontProvider )
943961 {
944962 Div div = blockElement as Div ;
945963 if ( div != null ) {
946964 // Iterate through the children of the Div and process each child element recursively
947965 foreach ( IElement child in div . GetChildren ( ) )
948966 if ( child is IBlockElement )
949- ProcessHTMLElement ( htmlRectangle , currentYPosition , ( IBlockElement ) child ) ;
967+ ProcessHTMLElement ( htmlRectangle , currentYPosition , ( IBlockElement ) child , fontProvider ) ;
950968
951969 }
952970
0 commit comments