View Issue Details

IDProjectCategoryView StatusLast Update
0036459FPCfpReportpublic2019-12-20 20:58
ReporterAndi FriessAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformDell XPSOSWin10 / 64 ProOS VersionWin10 / 64 Pro
Product Version3.3.1Product Buildfixes 3.2 
Target VersionFixed in Version3.3.1 
Summary0036459: fpreport: HTML Tags for bold are not correct rendered in pdf
DescriptionBold text in a memo overwrites the following text in this field. (The following text is not shifted)

The attached fix make the calculation correct.

Reason : see https://forum.lazarus.freepascal.org/index.php/topic,47708.msg343387.html#msg343387
in procedure TFPReportCustomMemo.HTMLOnFoundText(Text: string); the calculation of the textsize and textheight is based on the wrong font
Steps To Reproduceopen attached report in the reportdesigner (from Lazarus), make a preview and export to pdf.
TagsNo tags attached.
Fixed in Revision43701
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • m-d-sd report.zip (3,775 bytes)
  • before.jpg (82,439 bytes)
    before.jpg (82,439 bytes)
  • after.jpg (40,033 bytes)
    after.jpg (40,033 bytes)
  • fpreport.pp.patch (4,203 bytes)
    Index: packages/fcl-report/src/fpreport.pp
    ===================================================================
    --- packages/fcl-report/src/fpreport.pp	(revision 43561)
    +++ packages/fcl-report/src/fpreport.pp	(working copy)
    @@ -1944,9 +1944,11 @@
         function    PixelsToMM(APixels: single): single; inline;
         function    mmToPixels(mm: single): integer; inline;
         { Result is in millimeters. }
    -    function    TextHeight(const AText: string; out ADescender: TFPReportUnits): TFPReportUnits;
    +    function TextHeight(const AText, FontName: string; FontSize: Integer; out
    +      ADescender: TFPReportUnits): TFPReportUnits;
         { Result is in millimeters. }
    -    function    TextWidth(const AText: string): TFPReportUnits;
    +    function TextWidth(const AText, FontName: string; FontSize: Integer
    +      ): TFPReportUnits;
         procedure   SetLinkColor(AValue: TFPReportColor);
         procedure   SetTextAlignment(AValue: TFPReportTextAlignment);
         procedure   SetOptions(const AValue: TFPReportMemoOptions);
    @@ -4467,8 +4469,8 @@
     
         FCurTextBlock.FontName := lNewFontName;
     
    -    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text);
    -    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, lDescender);
    +    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size);
    +    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text,FCurTextBlock.FontName, Font.Size, lDescender);
         FCurTextBlock.Descender := lDescender;
     
         // get X offset from previous textblocks
    @@ -4495,7 +4497,7 @@
       Result := Round(mm * (gTTFontCache.DPI / cMMperInch));
     end;
     
    -function TFPReportCustomMemo.TextHeight(const AText: string; out ADescender: TFPReportUnits): TFPReportUnits;
    +function TFPReportCustomMemo.TextHeight(const AText, FontName: string; FontSize: Integer; out ADescender: TFPReportUnits): TFPReportUnits;
     var
       lHeight: single;
       lDescenderHeight: single;
    @@ -4502,12 +4504,11 @@
       lFC: TFPFontCacheItem;
     
     begin
    -  // TODO: FontName might need to change to TextBlock.FontName.
    -  lFC := gTTFontCache.FindFont(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
    +  lFC := gTTFontCache.FindFont(FontName); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
       if not Assigned(lFC) then
    -    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [Font.Name]);
    +    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [FontName]);
       { Both lHeight and lDescenderHeight are in pixels }
    -  lHeight := lFC.TextHeight(AText, Font.Size, lDescenderHeight);
    +  lHeight := lFC.TextHeight(AText, FontSize, lDescenderHeight);
     
       { convert pixels to mm. }
       ADescender := PixelsToMM(lDescenderHeight);
    @@ -4514,17 +4515,17 @@
       Result := PixelsToMM(lHeight);
     end;
     
    -function TFPReportCustomMemo.TextWidth(const AText: string): TFPReportUnits;
    +function TFPReportCustomMemo.TextWidth(const AText, FontName: string; FontSize: Integer): TFPReportUnits;
     var
       lWidth: single;
       lFC: TFPFontCacheItem;
     begin
       // TODO: FontName might need to change to TextBlock.FontName.
    -  lFC := gTTFontCache.FindFont(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
    +  lFC := gTTFontCache.FindFont(FontName); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
       if not Assigned(lFC) then
    -    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [Font.Name]);
    +    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [FontName]);
       { result is in pixels }
    -  lWidth := lFC.TextWidth(AText, Font.Size);
    +  lWidth := lFC.TextWidth(AText, FontSize);
     
       { convert pixels to mm. }
       Result := PixelsToMM(lWidth);
    @@ -4644,8 +4645,8 @@
       try
         FCurTextBlock.Text := AText;
         FCurTextBlock.FontName := Font.Name;
    -    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text);
    -    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, lDescender);
    +    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size);
    +    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size, lDescender);
         FCurTextBlock.Descender := lDescender;
     
         // get X offset from previous textblocks
    
    fpreport.pp.patch (4,203 bytes)

Activities

Andi Friess

2019-12-19 13:00

reporter  

m-d-sd report.zip (3,775 bytes)
before.jpg (82,439 bytes)
before.jpg (82,439 bytes)
after.jpg (40,033 bytes)
after.jpg (40,033 bytes)
fpreport.pp.patch (4,203 bytes)
Index: packages/fcl-report/src/fpreport.pp
===================================================================
--- packages/fcl-report/src/fpreport.pp	(revision 43561)
+++ packages/fcl-report/src/fpreport.pp	(working copy)
@@ -1944,9 +1944,11 @@
     function    PixelsToMM(APixels: single): single; inline;
     function    mmToPixels(mm: single): integer; inline;
     { Result is in millimeters. }
-    function    TextHeight(const AText: string; out ADescender: TFPReportUnits): TFPReportUnits;
+    function TextHeight(const AText, FontName: string; FontSize: Integer; out
+      ADescender: TFPReportUnits): TFPReportUnits;
     { Result is in millimeters. }
-    function    TextWidth(const AText: string): TFPReportUnits;
+    function TextWidth(const AText, FontName: string; FontSize: Integer
+      ): TFPReportUnits;
     procedure   SetLinkColor(AValue: TFPReportColor);
     procedure   SetTextAlignment(AValue: TFPReportTextAlignment);
     procedure   SetOptions(const AValue: TFPReportMemoOptions);
@@ -4467,8 +4469,8 @@
 
     FCurTextBlock.FontName := lNewFontName;
 
-    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text);
-    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, lDescender);
+    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size);
+    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text,FCurTextBlock.FontName, Font.Size, lDescender);
     FCurTextBlock.Descender := lDescender;
 
     // get X offset from previous textblocks
@@ -4495,7 +4497,7 @@
   Result := Round(mm * (gTTFontCache.DPI / cMMperInch));
 end;
 
-function TFPReportCustomMemo.TextHeight(const AText: string; out ADescender: TFPReportUnits): TFPReportUnits;
+function TFPReportCustomMemo.TextHeight(const AText, FontName: string; FontSize: Integer; out ADescender: TFPReportUnits): TFPReportUnits;
 var
   lHeight: single;
   lDescenderHeight: single;
@@ -4502,12 +4504,11 @@
   lFC: TFPFontCacheItem;
 
 begin
-  // TODO: FontName might need to change to TextBlock.FontName.
-  lFC := gTTFontCache.FindFont(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
+  lFC := gTTFontCache.FindFont(FontName); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
   if not Assigned(lFC) then
-    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [Font.Name]);
+    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [FontName]);
   { Both lHeight and lDescenderHeight are in pixels }
-  lHeight := lFC.TextHeight(AText, Font.Size, lDescenderHeight);
+  lHeight := lFC.TextHeight(AText, FontSize, lDescenderHeight);
 
   { convert pixels to mm. }
   ADescender := PixelsToMM(lDescenderHeight);
@@ -4514,17 +4515,17 @@
   Result := PixelsToMM(lHeight);
 end;
 
-function TFPReportCustomMemo.TextWidth(const AText: string): TFPReportUnits;
+function TFPReportCustomMemo.TextWidth(const AText, FontName: string; FontSize: Integer): TFPReportUnits;
 var
   lWidth: single;
   lFC: TFPFontCacheItem;
 begin
   // TODO: FontName might need to change to TextBlock.FontName.
-  lFC := gTTFontCache.FindFont(Font.Name); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
+  lFC := gTTFontCache.FindFont(FontName); // we are doing a PostScript Name lookup (it contains Bold, Italic info)
   if not Assigned(lFC) then
-    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [Font.Name]);
+    raise EReportFontNotFound.CreateFmt(SErrFontNotFound, [FontName]);
   { result is in pixels }
-  lWidth := lFC.TextWidth(AText, Font.Size);
+  lWidth := lFC.TextWidth(AText, FontSize);
 
   { convert pixels to mm. }
   Result := PixelsToMM(lWidth);
@@ -4644,8 +4645,8 @@
   try
     FCurTextBlock.Text := AText;
     FCurTextBlock.FontName := Font.Name;
-    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text);
-    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, lDescender);
+    FCurTextBlock.Width := TextWidth(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size);
+    FCurTextBlock.Height := TextHeight(FCurTextBlock.Text, FCurTextBlock.FontName, Font.Size, lDescender);
     FCurTextBlock.Descender := lDescender;
 
     // get X offset from previous textblocks
fpreport.pp.patch (4,203 bytes)

Michael Van Canneyt

2019-12-20 16:29

administrator   ~0119974

Checked & Applied patch, thank you very much !

Issue History

Date Modified Username Field Change
2019-12-19 13:00 Andi Friess New Issue
2019-12-19 13:00 Andi Friess Status new => assigned
2019-12-19 13:00 Andi Friess Assigned To => Michael Van Canneyt
2019-12-19 13:00 Andi Friess File Added: m-d-sd report.zip
2019-12-19 13:00 Andi Friess File Added: before.jpg
2019-12-19 13:00 Andi Friess File Added: after.jpg
2019-12-19 13:00 Andi Friess File Added: fpreport.pp.patch
2019-12-20 16:29 Michael Van Canneyt Status assigned => resolved
2019-12-20 16:29 Michael Van Canneyt Resolution open => fixed
2019-12-20 16:29 Michael Van Canneyt Fixed in Version => 3.3.1
2019-12-20 16:29 Michael Van Canneyt Fixed in Revision => 43701
2019-12-20 16:29 Michael Van Canneyt FPCTarget => 3.2.0
2019-12-20 16:29 Michael Van Canneyt Note Added: 0119974
2019-12-20 20:58 Andi Friess Status resolved => closed