Moves FreeType font creation into CreateFontIndirect in LCL-CustomDrawn non-native text

git-svn-id: trunk@35690 -
This commit is contained in:
sekelsenmat 2012-03-03 20:38:23 +00:00
parent 6ade22b5c6
commit 96193a39b6
5 changed files with 67 additions and 26 deletions

View File

@ -40,8 +40,10 @@ uses
{$ifdef WinCE}aygshell,{$endif}
// Widgetset
customdrawnproc,
{$ifndef CD_UseNativeText}
// LazFreeType
LazFreeTypeIntfDrawer, LazFreeType, EasyLazFreeType,
{$endif}
// LCL
customdrawn_common, customdrawncontrols, customdrawndrawers,
lazcanvas, lazregions, lazdeviceapis,
@ -84,6 +86,17 @@ type
end;
{$endif}
{ TLazCDCustomFont }
TLazCDCustomFont = class(TFPCustomFont)
public
{$ifndef CD_UseNativeText}
FTFont: TFreeTypeFont;
{$endif}
constructor Create; override;
destructor Destroy; override;
end;
{ TCDWidgetSet }
TCDWidgetSet = class(TWidgetSet)
@ -382,6 +395,25 @@ const
{$ifdef CD_Cocoa}
const
CDBackendNativeHandle = nhtCocoaNSWindow;
{ TLazCDCustomFont }
constructor TLazCDCustomFont.Create;
begin
inherited Create;
{$ifndef CD_UseNativeText}
FTFont := TFreeTypeFont.Create;
{$endif}
end;
destructor TLazCDCustomFont.Destroy;
begin
{$ifndef CD_UseNativeText}
FTFont.Free;
{$endif}
inherited Destroy;
end;
{$define CD_HasNativeFormHandle}
{$endif}

View File

@ -538,7 +538,7 @@ end;
------------------------------------------------------------------------------}
function TCDWidgetSet.CreateFontIndirectEx(const LogFont: TLogFont; const LongFontName: string): HFONT;
var
lFont: TFPCustomFont;
lFont: TLazCDCustomFont;
// FamilyName: string;
begin
{$ifdef VerboseCDDrawing}
@ -546,9 +546,16 @@ begin
[LongFontName, LogFont.lfHeight]));
{$endif}
lFont := TFPCustomFont.Create;
lFont := TLazCDCustomFont.Create;
Result := HFONT(lFont);
{$ifndef CD_UseNativeText}
lFont.ftFont.Name := BackendGetFontPath(LogFont, LongFontName);
lFont.ftFont.Hinted := true;
lFont.ftFont.ClearType := true;
lFont.ftFont.Quality := grqHighQuality;
{$endif}
(*const
QStyleStategy: array [DEFAULT_QUALITY..CLEARTYPE_NATURAL_QUALITY] of QFontStyleStrategy = (
{ DEFAULT_QUALITY } QFontPreferDefault,
@ -2192,17 +2199,12 @@ begin
// Preparations finished, draw it using LazFreeType
FTDrawer := TIntfFreeTypeDrawer.Create(lDestIntfImage);
ftFont := TFreeTypeFont.Create; //only one font at once for now...
ftFont := TFreeTypeFont(lDestCanvas.ExtraFontData);
try
ftFont.Name := BackendGetFontPath(DC);
ftFont.Hinted := true;
ftFont.ClearType := true;
ftFont.Quality := grqHighQuality;
RealX := X + lDestCanvas.WindowOrg.X + lDestCanvas.BaseWindowOrg.X;
RealY := Y + lDestCanvas.WindowOrg.Y + lDestCanvas.BaseWindowOrg.Y;
RealY := Y + lDestCanvas.WindowOrg.Y + lDestCanvas.BaseWindowOrg.Y + lFontSize;
FTDrawer.DrawText(Str, ftFont, RealX, RealY, colBlack, 255);
finally
ftFont.Free;
FTDrawer.Free;
end;
@ -5308,6 +5310,9 @@ begin
Result := HGDIOBJ(TLazCanvas(DC).AssignedFont);
TLazCanvas(DC).AssignFontData(lFont); // := doesn't work and Assign() raises exceptions
TLazCanvas(DC).AssignedFont := lFont;
{$ifndef CD_UseNativeText}
TLazCanvas(DC).ExtraFontData := TLazCDCustomFont(lFont).FTFont;
{$endif}
end
else if aObject is TFPCustomPen then
begin

View File

@ -156,9 +156,16 @@ begin
if LogFont.lfStrikeOut>0 then Include(cf.Style, cfs_Strikeout);
cf.Antialiased:=logFont.lfQuality>=ANTIALIASED_QUALITY;
Result:=HFONT(cf);
end;
end;*)
function Create32BitAlphaBitmap(ABitmap, AMask: TCocoaBitmap): TCocoaBitmap;
{$ifndef CD_UseNativeText}
function TCDWidgetSet.BackendGetFontPath(const LogFont: TLogFont; const LongFontName: string): string;
begin
Result := '/Library/Fonts/Arial.ttf';
end;
{$endif}
(*function Create32BitAlphaBitmap(ABitmap, AMask: TCocoaBitmap): TCocoaBitmap;
var
ARawImage: TRawImage;
Desc: TRawImageDescription absolute ARawimage.Description;
@ -384,11 +391,6 @@ begin
lazdc := TLazCanvas(DC);
lazdc.AlphaBlend(ScreenDC, X, Y, 0, 0, ScreenBitmapWidth, ScreenBitmapHeight);
end;
{$else}
function TCDWidgetSet.BackendGetFontPath(DC: HDC): string;
begin
Result := '/Library/Fonts/Arial.ttf';
end;
{$endif}
(*{------------------------------------------------------------------------------

View File

@ -628,9 +628,16 @@ begin
Result := HCURSOR(TQtCursor.Create(APixmap, IconInfo^.xHotspot, IconInfo^.yHotspot));
QPixmap_destroy(APixmap);
end;
end;
end;*)
{------------------------------------------------------------------------------
{$ifndef CD_UseNativeText}
function TCDWidgetSet.BackendGetFontPath(const LogFont: TLogFont; const LongFontName: string): string;
begin
Result := '/Library/Fonts/Arial.ttf';
end;
{$endif}
(*{------------------------------------------------------------------------------
Function: CreatePatternBrush
Params: HBITMAP
Returns: HBRUSH
@ -2084,11 +2091,6 @@ begin
Result := True; }
end;
{$else}
function TCDWidgetSet.BackendGetFontPath(DC: HDC): string;
begin
Result := '/Library/Fonts/Arial.ttf';
end;
{$endif}
(*{------------------------------------------------------------------------------

View File

@ -63,6 +63,9 @@ function CreateCompatibleDC(DC: HDC): HDC; override;
//function CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN; override;
function CreateFontIndirect(const LogFont: TLogFont): HFONT; override;
function CreateFontIndirectEx(const LogFont: TLogFont; const LongFontName: string): HFONT; override;
{$ifndef CD_UseNativeText}
function BackendGetFontPath(const LogFont: TLogFont; const LongFontName: string): string;
{$endif}
function CreateIconIndirect(IconInfo: PIconInfo): HICON; override;
//function CreatePatternBrush(ABitmap: HBITMAP): HBRUSH; override;
function CreatePenIndirect(const LogPen: TLogPen): HPEN; override;
@ -91,9 +94,6 @@ function EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont; Callback: FontEnumExPr
function ExtCreatePen(dwPenStyle, dwWidth: DWord; const lplb: TLogBrush; dwStyleCount: DWord; lpStyle: PDWord): HPEN; override;
function ExtSelectClipRGN(dc: hdc; rgn : hrgn; Mode : Longint) : Integer; override;*)
function ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; override;
{$ifndef CD_UseNativeText}
function BackendGetFontPath(DC: HDC): string;
{$endif}
function FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean; override;
//function FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool; override;