LazUtils: Initialize LazFreeType variables. Prevent range errors. Issue #37033, patch from circular.

git-svn-id: trunk@63134 -
This commit is contained in:
juha 2020-05-10 18:55:24 +00:00
parent e3a0380ebe
commit da1e9bb5c1
2 changed files with 40 additions and 18 deletions

View File

@ -747,30 +747,37 @@ function TFreeTypeGlyph.GetBounds: TRect;
var var
metrics: TT_Glyph_Metrics; metrics: TT_Glyph_Metrics;
begin begin
TT_Get_Glyph_Metrics(FGlyphData, metrics); if TT_Get_Glyph_Metrics(FGlyphData, metrics) = TT_Err_Ok then
with metrics.bbox do with metrics.bbox do
result := rect(IncludeFullGrainMin(xMin,64) div 64,IncludeFullGrainMin(-yMax,64) div 64, result := rect(IncludeFullGrainMin(xMin,64) div 64,IncludeFullGrainMin(-yMax,64) div 64,
(IncludeFullGrainMax(xMax,64)+1) div 64,(IncludeFullGrainMax(-yMin,64)+1) div 64); (IncludeFullGrainMax(xMax,64)+1) div 64,(IncludeFullGrainMax(-yMin,64)+1) div 64)
else
result := TRect.Empty;
end; end;
function TFreeTypeGlyph.GetAdvance: single; function TFreeTypeGlyph.GetAdvance: single;
var var
metrics: TT_Glyph_Metrics; metrics: TT_Glyph_Metrics;
begin begin
TT_Get_Glyph_Metrics(FGlyphData, metrics); if TT_Get_Glyph_Metrics(FGlyphData, metrics) = TT_Err_Ok then
result := metrics.advance/64; result := metrics.advance/64
else
result := 0;
end; end;
function TFreeTypeGlyph.GetBoundsWithOffset(x, y: single): TRect; function TFreeTypeGlyph.GetBoundsWithOffset(x, y: single): TRect;
var var
metrics: TT_Glyph_Metrics; metrics: TT_Glyph_Metrics;
begin begin
TT_Get_Glyph_Metrics(FGlyphData, metrics); if TT_Get_Glyph_Metrics(FGlyphData, metrics) = TT_Err_Ok then
with metrics.bbox do begin
result := rect(IncludeFullGrainMin(xMin+round(x*64), 64) div 64, with metrics.bbox do
IncludeFullGrainMin(-yMax+round(y*64),64) div 64, result := rect(IncludeFullGrainMin(xMin+round(x*64),64) div 64,
(IncludeFullGrainMax(xMax+round(x*64), 64)+1) div 64, IncludeFullGrainMin(-yMax+round(y*64),64) div 64,
(IncludeFullGrainMax(-yMin+round(y*64),64)+1) div 64); (IncludeFullGrainMax(xMax+round(x*64),64)+1) div 64,
(IncludeFullGrainMax(-yMin+round(y*64),64)+1) div 64);
end else
result := TRect.Empty;
end; end;
constructor TFreeTypeGlyph.Create(AFont: TFreeTypeFont; AIndex: integer); constructor TFreeTypeGlyph.Create(AFont: TFreeTypeFont; AIndex: integer);

View File

@ -254,13 +254,13 @@ const
(* Get a glyph's metrics *) (* Get a glyph's metrics *)
(* *) (* *)
function TT_Get_Glyph_Metrics( _glyph : TT_Glyph; function TT_Get_Glyph_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Glyph_Metrics ) : TT_Error; out gmetrics : TT_Glyph_Metrics ) : TT_Error;
(*****************************************************************) (*****************************************************************)
(* Get a glyph's big metrics *) (* Get a glyph's big metrics *)
(* *) (* *)
function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph; function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Big_Glyph_Metrics out gmetrics : TT_Big_Glyph_Metrics
) : TT_Error; ) : TT_Error;
(*****************************************************************) (*****************************************************************)
@ -1027,7 +1027,7 @@ uses
(* *) (* *)
(* *) (* *)
function TT_Get_Glyph_Metrics( _glyph : TT_Glyph; function TT_Get_Glyph_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Glyph_Metrics ) : TT_Error; out gmetrics : TT_Glyph_Metrics ) : TT_Error;
var var
glyph : PGlyph; glyph : PGlyph;
begin begin
@ -1041,14 +1041,17 @@ uses
TT_Get_Glyph_Metrics := TT_Err_Ok; TT_Get_Glyph_Metrics := TT_Err_Ok;
end end
else else
TT_Get_Glyph_Metrics := TT_Err_Invalid_Glyph_Handle; begin
fillchar(gmetrics, sizeof(gmetrics), 0);
TT_Get_Glyph_Metrics := TT_Err_Invalid_Glyph_Handle;
end;
end; end;
(*****************************************************************) (*****************************************************************)
(* Get a glyph's big metrics *) (* Get a glyph's big metrics *)
(* *) (* *)
function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph; function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Big_Glyph_Metrics out gmetrics : TT_Big_Glyph_Metrics
) : TT_Error; ) : TT_Error;
var var
glyph : PGlyph; glyph : PGlyph;
@ -1060,7 +1063,10 @@ uses
TT_Get_Glyph_Big_Metrics := TT_Err_Ok; TT_Get_Glyph_Big_Metrics := TT_Err_Ok;
end end
else else
TT_Get_Glyph_Big_Metrics := TT_Err_Invalid_Glyph_Handle; begin
fillchar(gmetrics, sizeof(gmetrics), 0);
TT_Get_Glyph_Big_Metrics := TT_Err_Invalid_Glyph_Handle;
end;
end; end;
(*****************************************************************) (*****************************************************************)
@ -1345,6 +1351,15 @@ uses
n : Int; n : Int;
begin begin
if out.n_points-nbPhantomPoints <= 0 then
with bbox do
begin
xMin := 0;
xMax := 0;
yMin := 0;
yMax := 0;
end
else
with bbox do with bbox do
begin begin
xMin := $7FFFFFFF; xMin := $7FFFFFFF;