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

View File

@ -254,13 +254,13 @@ const
(* Get a glyph's metrics *)
(* *)
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 *)
(* *)
function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Big_Glyph_Metrics
out gmetrics : TT_Big_Glyph_Metrics
) : TT_Error;
(*****************************************************************)
@ -1027,7 +1027,7 @@ uses
(* *)
(* *)
function TT_Get_Glyph_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Glyph_Metrics ) : TT_Error;
out gmetrics : TT_Glyph_Metrics ) : TT_Error;
var
glyph : PGlyph;
begin
@ -1041,14 +1041,17 @@ uses
TT_Get_Glyph_Metrics := TT_Err_Ok;
end
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;
(*****************************************************************)
(* Get a glyph's big metrics *)
(* *)
function TT_Get_Glyph_Big_Metrics( _glyph : TT_Glyph;
var gmetrics : TT_Big_Glyph_Metrics
out gmetrics : TT_Big_Glyph_Metrics
) : TT_Error;
var
glyph : PGlyph;
@ -1060,7 +1063,10 @@ uses
TT_Get_Glyph_Big_Metrics := TT_Err_Ok;
end
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;
(*****************************************************************)
@ -1345,6 +1351,15 @@ uses
n : Int;
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
begin
xMin := $7FFFFFFF;