LazUtils: Allow hints to reveal a bug in TFreeTypeGlyph. Formatting.

git-svn-id: trunk@63130 -
This commit is contained in:
juha 2020-05-09 18:34:49 +00:00
parent 77a9fd307d
commit 8946cd3dd1
2 changed files with 22 additions and 16 deletions

View File

@ -727,14 +727,14 @@ begin
f := TFreeTypeFont(Afont);
if ftaTop in AAlign then
y += AFont.Ascent
y += AFont.Ascent
else if ftaVerticalCenter in AALign then
y += AFont.Ascent - AFont.LineFullHeight*0.5
y += AFont.Ascent - AFont.LineFullHeight*0.5
else if ftaBottom in AAlign then
y += AFont.Ascent - AFont.LineFullHeight;
y += AFont.Ascent - AFont.LineFullHeight;
if ftaCenter in AAlign then
x -= f.CharWidthFromGlyph(AGlyph)*0.5
x -= f.CharWidthFromGlyph(AGlyph)*0.5
else if ftaRight in AAlign then
x -= f.CharWidthFromGlyph(AGlyph);
@ -743,10 +743,9 @@ end;
{ TFreeTypeGlyph }
{$push}
{$hints off}
function TFreeTypeGlyph.GetBounds: TRect;
var metrics: TT_Glyph_Metrics;
var
metrics: TT_Glyph_Metrics;
begin
TT_Get_Glyph_Metrics(FGlyphData, metrics);
with metrics.bbox do
@ -755,21 +754,24 @@ begin
end;
function TFreeTypeGlyph.GetAdvance: single;
var metrics: TT_Glyph_Metrics;
var
metrics: TT_Glyph_Metrics;
begin
TT_Get_Glyph_Metrics(FGlyphData, metrics);
result := metrics.advance/64;
end;
function TFreeTypeGlyph.GetBoundsWithOffset(x, y: single): TRect;
var metrics: TT_Glyph_Metrics;
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);
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;
{$pop}
constructor TFreeTypeGlyph.Create(AFont: TFreeTypeFont; AIndex: integer);
begin

View File

@ -243,8 +243,10 @@ function IncludeFullGrainMin(minValue: integer; Grain: integer): integer;
begin
if minValue mod Grain <> 0 then
begin
if minValue > 0 then result := minValue - (minValue mod Grain)
else result := minValue - (Grain - (-minValue) mod Grain);
if minValue > 0 then
result := minValue - (minValue mod Grain)
else
result := minValue - (Grain - (-minValue) mod Grain);
end else
result := minValue;
end;
@ -253,8 +255,10 @@ function IncludeFullGrainMax(maxValue: integer; Grain: integer): integer;
begin
if maxValue mod Grain <> Grain-1 then
begin
if maxValue > 0 then result := maxValue + (Grain-1 - (maxValue mod Grain))
else result := maxValue + (((-maxValue) mod Grain) - 1);
if maxValue > 0 then
result := maxValue + (Grain-1 - (maxValue mod Grain))
else
result := maxValue + (((-maxValue) mod Grain) - 1);
end
else
result := maxValue;