View Issue Details

IDProjectCategoryView StatusLast Update
0037022LazarusLazUtilspublic2020-05-09 10:06
Reportercircular Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.0.8 
Summary0037022: LazFreeType glyph bounds incorrect
DescriptionThe bounds of the glyph are not computed correctly. It is due to 2 additional debug points added that need to be ignored when computing the bounds.

To fix, I suggest to add a parameter to the TT_Get_Outline_BBox function indicating the number of "phantom" points.

Steps To ReproduceRun attached sample project and look at white area.
Additional Information  (*****************************************************************)
  (* Compute an outline's bounding box *)
  (* *)
  function TT_Get_Outline_BBox( var out : TT_Outline;
                                var bbox : TT_Bbox;
                                nbPhantomPoints : integer ) : TT_Error;
  var
    x, y : TT_Pos;
    n : Int;
  begin

    with bbox do
    begin
      xMin := $7FFFFFFF;
      xMax := -$80000000;
      yMin := $7FFFFFFF;
      yMax := -$80000000;

      for n := 0 to out.n_points-1-nbPhantomPoints do
      begin
        x := out.points^[n].x;
        if x < xMin then xMin := x;
        if x > xMax then xMax := x;
        y := out.points^[n].y;
        if y < yMin then yMin := y;
        if y > yMax then yMax := y;
      end;
    end;

    TT_Get_Outline_BBox := TT_Err_Ok;
  end;
TagsNo tags attached.
Fixed in Revisionr63126
LazTarget-
Widgetset
Attached Files

Activities

circular

2020-05-05 13:07

developer  

testfreetype2.zip (163,722 bytes)
glyph_box_bug.png (5,145 bytes)   
glyph_box_bug.png (5,145 bytes)   
glyph_box_fixed.png (5,334 bytes)   
glyph_box_fixed.png (5,334 bytes)   

circular

2020-05-08 10:47

developer   ~0122669

Here is the patch
bounding_box.diff (2,116 bytes)   
Index: components/lazutils/lazfreetype.pas
===================================================================
--- components/lazutils/lazfreetype.pas	(révision 63125)
+++ components/lazutils/lazfreetype.pas	(copie de travail)
@@ -347,7 +347,8 @@
   (*  Get an outline's bounding box                                *)
   (*                                                               *)
   function TT_Get_Outline_BBox( var out  : TT_Outline;
-                                var bbox : TT_Bbox     ) : TT_Error;
+                                var bbox : TT_Bbox;
+                                nbPhantomPoints : integer = 0 ) : TT_Error;
 
   (*****************************************************************)
   (*  Create a new glyph outline                                   *)
@@ -1337,7 +1338,8 @@
   (*  Compute an outline's bounding box                            *)
   (*                                                               *)
   function TT_Get_Outline_BBox( var out  : TT_Outline;
-                                var bbox : TT_Bbox     ) : TT_Error;
+                                var bbox : TT_Bbox;
+                                nbPhantomPoints : integer ) : TT_Error;
   var
     x,    y    : TT_Pos;
     n          : Int;
@@ -1350,7 +1352,7 @@
       yMin := $7FFFFFFF;
       yMax := -$80000000;
 
-      for n := 0 to out.n_points-1 do
+      for n := 0 to out.n_points-1-nbPhantomPoints do
       begin
         x := out.points^[n].x;
         if x < xMin then xMin := x;
Index: components/lazutils/ttgload.pas
===================================================================
--- components/lazutils/ttgload.pas	(révision 63125)
+++ components/lazutils/ttgload.pas	(copie de travail)
@@ -1233,7 +1233,7 @@
    glyph^.outline.n_contours  := num_contours;
    glyph^.outline.second_pass := true;
 
-   TT_Get_Outline_BBox( glyph^.outline, glyph^.metrics.bbox );
+   TT_Get_Outline_BBox( glyph^.outline, glyph^.metrics.bbox, 2 );
 
    glyph^.metrics.horiBearingX := glyph^.metrics.bbox.xMin - subglyph^.pp1.x;
    glyph^.metrics.horiBearingY := glyph^.metrics.bbox.yMax;
bounding_box.diff (2,116 bytes)   

Juha Manninen

2020-05-09 10:06

developer   ~0122679

Applied, thanks.

Issue History

Date Modified Username Field Change
2020-05-05 13:07 circular New Issue
2020-05-05 13:07 circular File Added: testfreetype2.zip
2020-05-05 13:07 circular File Added: glyph_box_bug.png
2020-05-05 13:07 circular File Added: glyph_box_fixed.png
2020-05-08 10:43 circular File Deleted: bounding_box.diff
2020-05-08 10:47 circular Note Added: 0122669
2020-05-08 10:47 circular File Added: bounding_box.diff
2020-05-08 23:10 Juha Manninen Assigned To => Juha Manninen
2020-05-08 23:10 Juha Manninen Status new => assigned
2020-05-09 10:06 Juha Manninen Status assigned => resolved
2020-05-09 10:06 Juha Manninen Resolution open => fixed
2020-05-09 10:06 Juha Manninen Fixed in Revision => r63126
2020-05-09 10:06 Juha Manninen LazTarget => -
2020-05-09 10:06 Juha Manninen Note Added: 0122679