Advances the support for setting the font size in Android

git-svn-id: trunk@34323 -
This commit is contained in:
sekelsenmat 2011-12-20 13:12:14 +00:00
parent b22aa36ab3
commit 96d5e480cc
4 changed files with 37 additions and 6 deletions

View File

@ -24,6 +24,12 @@ procedure TCDWidgetSet.CDSetFocusToControl(ALCLControl, AIntfControl: TWinContro
var
lForm, OldFocusedControl: TWinControl;
begin
{$ifdef VerboseCDForms}
if FocusedControl <> nil then DebugLn('[TCDWidgetSet.CDSetFocusToControl] OldFocusedControl=%s:%s', [FocusedControl.Name, FocusedControl.ClassName]);
if FocusedIntfControl <> nil then DebugLn('[TCDWidgetSet.CDSetFocusToControl] OldIntfFocusedControl=%s:%s', [FocusedIntfControl.Name, FocusedIntfControl.ClassName]);
if ALCLControl <> nil then DebugLn('[TCDWidgetSet.CDSetFocusToControl] ALCLControl=%s:%s', [ALCLControl.Name, ALCLControl.ClassName]);
if AIntfControl <> nil then DebugLn('[TCDWidgetSet.CDSetFocusToControl] AIntfControl=%s:%s', [AIntfControl.Name, AIntfControl.ClassName]);
{$endif}
OldFocusedControl := FocusedControl;
if ALCLControl = nil then Exit;
lForm := GetParentForm(ALCLControl);

View File

@ -804,6 +804,7 @@ begin
// Add it to our list
AddTimer(lTimer);
DebugLn(Format('[TCDWidgetSet.CreateTimer] Result=%x', [PtrInt(Result)]));
end;
{------------------------------------------------------------------------------
@ -815,7 +816,7 @@ function TCDWidgetSet.DestroyTimer(TimerHandle: THandle) : boolean;
var
lTimer: TCDTimer;
begin
DebugLn('[TCDWidgetSet.DestroyTimer]');
DebugLn(Format('[TCDWidgetSet.DestroyTimer] TimerHandle=%x', [PtrInt(TimerHandle)]));
Result := False;
lTimer := TCDTimer(TimerHandle);
@ -830,6 +831,7 @@ begin
// Remove from the list
RemoveTimer(lTimer);
lTimer.Free;
Result := True;
end;

View File

@ -2186,6 +2186,7 @@ var
lCanvas: TLazCanvas = nil;
lWidth, lHeight: jint;
lDestCanvas: TLazCanvas;
lFontSize: Integer;
begin
{$ifdef VerboseCDText}
DebugLn(Format(':>[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s X=%d Y=%d',
@ -2200,15 +2201,17 @@ begin
exit;
if not IsValidDC(DC) then Exit;
lDestCanvas := TLazCanvas(DC);
if (lDestCanvas.Font = nil) or (lDestCanvas.Font.Size = 0) then lFontSize := DefaultFontAndroidSize
else lFontSize := lDestCanvas.Font.Size;
if (javaEnvRef = nil) then Exit;
// Prepare the input
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, DefaultFontAndroidSize);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
// Call the method to measure the text
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
@ -4138,6 +4141,8 @@ end;
function TCDWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
var
lJavaString: jstring;
LazDC: TLazCanvas;
lFontSize: Integer;
begin
{$ifdef VerboseCDText}
DebugLn(Format('[WinAPI GetTextExtentPoint] DC=%x javaEnvRef=%x', [DC, PtrInt(javaEnvRef)]));
@ -4146,13 +4151,17 @@ begin
Result := False;
if not IsValidDC(DC) then Exit;
LazDC := TLazCanvas(DC);
if (LazDC.Font = nil) or (LazDC.Font.Size = 0) then lFontSize := DefaultFontAndroidSize
else lFontSize := LazDC.Font.Size;
if (javaEnvRef = nil) then Exit;
// Prepare the input
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, DefaultFontAndroidSize);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
// Call the method
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
@ -4178,6 +4187,8 @@ function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
var
lAverageCharWidth: Integer;
lJavaString: jstring;
LazDC: TLazCanvas;
lFontSize: Integer;
begin
{$ifdef VerboseCDText}
DebugLn(Format('[WinAPI GetTextMetrics] DC=%x javaEnvRef=%x', [DC, PtrInt(javaEnvRef)]));
@ -4186,13 +4197,17 @@ begin
Result := False;
if not IsValidDC(DC) then Exit;
LazDC := TLazCanvas(DC);
if (LazDC.Font = nil) or (LazDC.Font.Size = 0) then lFontSize := DefaultFontAndroidSize
else lFontSize := LazDC.Font.Size;
if (javaEnvRef = nil) then Exit;
// Prepare the input for getting the average width of a char
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, PChar('x'));
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, DefaultFontAndroidSize);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
// Call the method
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
@ -4202,7 +4217,7 @@ begin
// Prepare the input for getting the max height of a text and other metrics
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, PChar('Íg'));
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, DefaultFontAndroidSize);
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
// Call the method
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);

View File

@ -90,6 +90,7 @@ type
procedure SetWindowOrg(AValue: TPoint);
protected
procedure SetColor (x,y:integer; const AValue:TFPColor); override;
function DoCreateDefaultFont : TFPCustomFont; override;
// Routines broken/unimplemented/incompatible in FPC
procedure DoRectangle (const Bounds:TRect); override;
procedure DoRectangleFill (const Bounds:TRect); override;
@ -209,6 +210,13 @@ begin
{$endif}
end;
function TLazCanvas.DoCreateDefaultFont: TFPCustomFont;
begin
result := TFPEmptyFont.Create;
Result.Size := 0; // To allow it to use the default platform size
Result.FPColor := colBlack;
end;
// The coordinates utilized by DoRectangle in fcl-image are not TCanvas compatible
// so we reimplement it here
procedure TLazCanvas.DoRectangle (const Bounds:TRect);