LazFreeType: Move Hinted property to the TFreeTypeRenderableFont. Implement hinting for centered text.

Based on patch by "circular".

git-svn-id: trunk@40130 -
This commit is contained in:
ask 2013-02-02 23:14:39 +00:00
parent c74596dc57
commit 3c8243bd4c

View File

@ -151,6 +151,8 @@ type
function GetDescent: single; virtual; abstract; function GetDescent: single; virtual; abstract;
function GetLineSpacing: single; virtual; abstract; function GetLineSpacing: single; virtual; abstract;
procedure DefaultWordBreakHandler(var ABefore, AAfter: string); procedure DefaultWordBreakHandler(var ABefore, AAfter: string);
function GetHinted: boolean; virtual; abstract;
procedure SetHinted(const AValue: boolean); virtual; abstract;
public public
function TextWidth(AText: string): single; virtual; abstract; function TextWidth(AText: string): single; virtual; abstract;
function TextHeight(AText: string): single; virtual; abstract; function TextHeight(AText: string): single; virtual; abstract;
@ -163,6 +165,7 @@ type
property Descent: single read GetDescent; property Descent: single read GetDescent;
property LineSpacing: single read GetLineSpacing; property LineSpacing: single read GetLineSpacing;
property LineFullHeight: single read GetLineFullHeight; property LineFullHeight: single read GetLineFullHeight;
property Hinted: boolean read GetHinted write SetHinted;
property OnWordBreak: TFreeTypeWordBreakHandler read FWordBreakHandler write FWordBreakHandler; property OnWordBreak: TFreeTypeWordBreakHandler read FWordBreakHandler write FWordBreakHandler;
end; end;
@ -206,7 +209,6 @@ type
function GetVersionNumber: string; function GetVersionNumber: string;
procedure SetDPI(const AValue: integer); procedure SetDPI(const AValue: integer);
procedure SetFreeTypeStyles(AValue: TFreeTypeStyles); procedure SetFreeTypeStyles(AValue: TFreeTypeStyles);
procedure SetHinted(const AValue: boolean);
procedure SetLineFullHeight(AValue: single); procedure SetLineFullHeight(AValue: single);
procedure SetStyleAsString(AValue: string); procedure SetStyleAsString(AValue: string);
procedure UpdateFace(const AName: String); procedure UpdateFace(const AName: String);
@ -238,6 +240,8 @@ type
function GetAscent: single; override; function GetAscent: single; override;
function GetDescent: single; override; function GetDescent: single; override;
function GetLineSpacing: single; override; function GetLineSpacing: single; override;
procedure SetHinted(const AValue: boolean); override;
function GetHinted: boolean; override;
procedure OnDestroyFontItem; procedure OnDestroyFontItem;
procedure FetchNames; procedure FetchNames;
function GetCollection: TCustomFreeTypeFontCollection; function GetCollection: TCustomFreeTypeFontCollection;
@ -518,6 +522,7 @@ end;
procedure TFreeTypeDrawer.DrawText(AText: string; procedure TFreeTypeDrawer.DrawText(AText: string;
AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor; AAlign: TFreeTypeAlignments); AFont: TFreeTypeRenderableFont; x, y: single; AColor: TFPColor; AAlign: TFreeTypeAlignments);
var idx : integer; var idx : integer;
delta: single;
begin begin
if not (ftaBaseline in AAlign) then if not (ftaBaseline in AAlign) then
begin begin
@ -541,10 +546,13 @@ begin
if not (ftaLeft in AAlign) then if not (ftaLeft in AAlign) then
begin begin
delta := 0;
if ftaCenter in AAlign then if ftaCenter in AAlign then
x -= AFont.TextWidth(AText)/2 else delta := -AFont.TextWidth(AText)/2 else
if ftaRight in AAlign then if ftaRight in AAlign then
x -= AFont.TextWidth(AText); delta := -AFont.TextWidth(AText);
if AFont.Hinted then delta := round(delta);
x += delta;
end; end;
DrawText(AText, AFont, x,y, AColor); DrawText(AText, AFont, x,y, AColor);
end; end;
@ -961,6 +969,11 @@ begin
FGlyphTable.FreeAndClear; FGlyphTable.FreeAndClear;
end; end;
function TFreeTypeFont.GetHinted: boolean;
begin
result := FHinted;
end;
procedure TFreeTypeFont.SetLineFullHeight(AValue: single); procedure TFreeTypeFont.SetLineFullHeight(AValue: single);
var Ratio: single; var Ratio: single;
begin begin