customdrawnws: Adds more stub code to the text metrics to prevent crashes. Updates the non-android example for the second form

git-svn-id: trunk@34174 -
This commit is contained in:
sekelsenmat 2011-12-14 09:46:26 +00:00
parent 7bd71b2eab
commit 52611f279a
5 changed files with 75 additions and 71 deletions

View File

@ -91,7 +91,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="2"> <Units Count="3">
<Unit0> <Unit0>
<Filename Value="nonandroidtest.lpr"/> <Filename Value="nonandroidtest.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -105,6 +105,12 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/> <UnitName Value="mainform"/>
</Unit1> </Unit1>
<Unit2>
<Filename Value="secondform.pas"/>
<IsPartOfProject Value="True"/>
<HasResources Value="True"/>
<UnitName Value="secondform"/>
</Unit2>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -4,13 +4,14 @@ program nonandroidtest;
uses uses
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, mainform; Forms, mainform, secondform;
{$R *.res} {$R *.res}
begin begin
Application.Initialize; Application.Initialize;
Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run; Application.Run;
end. end.

View File

@ -1,10 +1,10 @@
object Form2: TForm2 object Form2: TForm2
Left = 323 Left = 323
Height = 240 Height = 259
Top = 171 Top = 171
Width = 320 Width = 320
Caption = 'Form2' Caption = 'Form2'
ClientHeight = 240 ClientHeight = 259
ClientWidth = 320 ClientWidth = 320
LCLVersion = '0.9.31' LCLVersion = '0.9.31'
object Button1: TButton object Button1: TButton

View File

@ -5,7 +5,8 @@ unit secondform;
interface interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ComCtrls;
type type

View File

@ -2164,10 +2164,8 @@ end;*)
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
{var var
WideStr: WideString; LazDC: TLazCanvas absolute DC;
QtDC: TQtDeviceContext absolute DC;
B: Boolean; }
begin begin
{$ifdef VerboseCDWinAPI} {$ifdef VerboseCDWinAPI}
DebugLn('[WinAPI ExtTextOut]'); DebugLn('[WinAPI ExtTextOut]');
@ -2175,6 +2173,11 @@ begin
Result := False; Result := False;
if Rect <> nil then
begin
Rect^ := Bounds(0, 0, 0, 0);
end;
{if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then {if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then
exit; exit;
@ -4058,21 +4061,19 @@ end;
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCDWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; function TCDWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
{var var
WideStr: WideString; LazDC: TLazCanvas absolute DC;
QtDC: TQtDeviceContext absolute DC; }
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseCDWinAPI}
WriteLn('[WinAPI GetTextExtentPoint]'); DebugLn('[WinAPI GetTextExtentPoint]');
{$endif} {$endif}
Result := False; Result := False;
{ if not IsValidDC(DC) then Exit; if not IsValidDC(DC) then Exit;
WideStr := GetUtf8String(Str); Size.cx := 0;
Size.cx := QtDC.Metrics.width(@WideStr, Count); Size.cy := 0;
Size.cy := QtDC.Metrics.height; }
Result := True; Result := True;
end; end;
@ -4084,69 +4085,64 @@ end;
Returns: If successfull Returns: If successfull
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean; function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
{var var
QtFontMetrics: TQtFontMetrics; LazDC: TLazCanvas absolute DC;
{ QtFontMetrics: TQtFontMetrics;
FontFamily: WideString; FontFamily: WideString;
QtDC: TQtDeviceContext absolute DC;
FontWeight: Integer; } FontWeight: Integer; }
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseCDWinAPI}
WriteLn('[WinAPI GetTextMetrics]'); DebugLn('[WinAPI GetTextMetrics]');
{$endif} {$endif}
Result := IsValidDC(DC); Result := False;
(* if Result then if not IsValidDC(DC) then Exit;
begin
QtFontMetrics := QtDC.Metrics;
TM.tmHeight := QtFontMetrics.height;
TM.tmAscent := QtFontMetrics.ascent;
TM.tmDescent := QtFontMetrics.descent;
TM.tmInternalLeading := 0;
TM.tmExternalLeading := QtFontMetrics.leading;
{this is due qt bug in fontmetrics::averageCharWidth() under Mac
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=169440 }
{$IFDEF DARWIN}
TM.tmAveCharWidth := QtFontMetrics.charWidth('x',0);
{$ELSE}
TM.tmAveCharWidth := QtFontMetrics.averageCharWidth;
{$ENDIF}
TM.tmMaxCharWidth := QtFontMetrics.maxWidth; //QtFontMetrics := QtDC.Metrics;
FontWeight := QtDC.font.getWeight; TM.tmHeight := 0;//QtFontMetrics.height;
case FontWeight of TM.tmAscent := 0;//QtFontMetrics.ascent;
25: TM.tmWeight := FW_LIGHT; TM.tmDescent := 0;//QtFontMetrics.descent;
50: TM.tmWeight := FW_NORMAL; TM.tmInternalLeading := 0;
63: TM.tmWeight := FW_SEMIBOLD; { TM.tmExternalLeading := QtFontMetrics.leading;
75: TM.tmWeight := FW_BOLD; TM.tmAveCharWidth := QtFontMetrics.charWidth('x',0);
87: TM.tmWeight := FW_HEAVY;
else
TM.tmWeight := Round(FontWeight * 9.5);
end;
TM.tmOverhang := 0;
TM.tmDigitizedAspectX := 0;
TM.tmDigitizedAspectY := 0;
TM.tmFirstChar := 'a';
TM.tmLastChar := 'z';
TM.tmDefaultChar := 'x';
TM.tmBreakChar := '?';
TM.tmItalic := Ord(QtDC.Font.getItalic);
TM.tmUnderlined := Ord(QtDC.Font.getUnderline);
TM.tmStruckOut := Ord(QtDC.Font.getStrikeOut);
QtDC.font.family(@FontFamily); TM.tmMaxCharWidth := QtFontMetrics.maxWidth;
FontWeight := QtDC.font.getWeight;
{ Defaults to a TrueType font. case FontWeight of
Note that the meaning of the FIXED_PITCH constant is the opposite of 25: TM.tmWeight := FW_LIGHT;
the name implies, according to MSDN docs. Just a small inconsistency 50: TM.tmWeight := FW_NORMAL;
on Windows API that we have to mimic. } 63: TM.tmWeight := FW_SEMIBOLD;
if QtDC.font.fixedPitch then 75: TM.tmWeight := FW_BOLD;
TM.tmPitchAndFamily := TRUETYPE_FONTTYPE 87: TM.tmWeight := FW_HEAVY;
else else
TM.tmPitchAndFamily := FIXED_PITCH or TRUETYPE_FONTTYPE; TM.tmWeight := Round(FontWeight * 9.5);
end;}
TM.tmOverhang := 0;
TM.tmDigitizedAspectX := 0;
TM.tmDigitizedAspectY := 0;
TM.tmFirstChar := 'a';
TM.tmLastChar := 'z';
TM.tmDefaultChar := 'x';
TM.tmBreakChar := '?';
{ TM.tmItalic := Ord(QtDC.Font.getItalic);
TM.tmUnderlined := Ord(QtDC.Font.getUnderline);
TM.tmStruckOut := Ord(QtDC.Font.getStrikeOut);}
TM.tmCharSet := DEFAULT_CHARSET; // QtDC.font.family(@FontFamily);
end;*)
{ Defaults to a TrueType font.
Note that the meaning of the FIXED_PITCH constant is the opposite of
the name implies, according to MSDN docs. Just a small inconsistency
on Windows API that we have to mimic. }
{ if QtDC.font.fixedPitch then
TM.tmPitchAndFamily := TRUETYPE_FONTTYPE
else}
TM.tmPitchAndFamily := FIXED_PITCH or TRUETYPE_FONTTYPE;
TM.tmCharSet := DEFAULT_CHARSET;
Result := True;
end; end;
{$endif} {$endif}