mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-14 14:39:20 +02:00
customdrawn-android: Improves the native text, not yet working
git-svn-id: trunk@34135 -
This commit is contained in:
parent
50adae92e1
commit
9645315d87
@ -35,7 +35,7 @@ uses
|
|||||||
{$ifdef CD_Cocoa}MacOSAll, CocoaAll, CocoaPrivate, CocoaGDIObjects,{$endif}
|
{$ifdef CD_Cocoa}MacOSAll, CocoaAll, CocoaPrivate, CocoaGDIObjects,{$endif}
|
||||||
{$ifdef CD_X11}X, XLib, XUtil, customdrawn_x11proc,{unitxft, Xft font support}{$endif}
|
{$ifdef CD_X11}X, XLib, XUtil, customdrawn_x11proc,{unitxft, Xft font support}{$endif}
|
||||||
{$ifdef CD_Android}
|
{$ifdef CD_Android}
|
||||||
cmem, customdrawn_androidproc, jni, bitmap, log,
|
customdrawn_androidproc, jni, bitmap, log,
|
||||||
{$endif}
|
{$endif}
|
||||||
// Widgetset
|
// Widgetset
|
||||||
customdrawnproc,
|
customdrawnproc,
|
||||||
@ -241,6 +241,7 @@ var
|
|||||||
javaField_lclbutton1: JfieldID=nil;
|
javaField_lclbutton1: JfieldID=nil;
|
||||||
javaField_lclbutton2: JfieldID=nil;
|
javaField_lclbutton2: JfieldID=nil;
|
||||||
javaField_lclbutton3: JfieldID=nil;
|
javaField_lclbutton3: JfieldID=nil;
|
||||||
|
javaField_lclbitmap: JfieldID=nil;
|
||||||
|
|
||||||
// Methods of our Activity
|
// Methods of our Activity
|
||||||
javaMethod_LCLDoGetTextBounds: jmethodid = nil;
|
javaMethod_LCLDoGetTextBounds: jmethodid = nil;
|
||||||
|
@ -175,7 +175,7 @@ begin
|
|||||||
if javaEnvRef^^.RegisterNatives(javaEnvRef, javaActivityClass, @NativeMethods[0],length(NativeMethods))<0 then
|
if javaEnvRef^^.RegisterNatives(javaEnvRef, javaActivityClass, @NativeMethods[0],length(NativeMethods))<0 then
|
||||||
begin
|
begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL, 'lclapp', 'javaEnvRef^.RegisterNatives failed');
|
__android_log_write(ANDROID_LOG_FATAL, 'lclapp', 'javaEnvRef^.RegisterNatives failed');
|
||||||
Exit(JNI_ERR);
|
// Exit(JNI_ERR); Don't exit if exporting the native method fails because it works without this too
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Read all field IDs
|
// Read all field IDs
|
||||||
@ -190,6 +190,7 @@ begin
|
|||||||
JavaField_lclbutton1 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton1', 'I');
|
JavaField_lclbutton1 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton1', 'I');
|
||||||
JavaField_lclbutton2 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton2', 'I');
|
JavaField_lclbutton2 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton2', 'I');
|
||||||
JavaField_lclbutton3 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton3', 'I');
|
JavaField_lclbutton3 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton3', 'I');
|
||||||
|
JavaField_lclbitmap := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbitmap', 'Landroid/graphics/Bitmap;');
|
||||||
if not assigned(JavaField_lcltext) then
|
if not assigned(JavaField_lcltext) then
|
||||||
begin
|
begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL, 'lclapp', 'javaEnvRef^.GetFieldID failed for lcltext');
|
__android_log_write(ANDROID_LOG_FATAL, 'lclapp', 'javaEnvRef^.GetFieldID failed for lcltext');
|
||||||
@ -227,6 +228,18 @@ begin
|
|||||||
// Setup DebugLn
|
// Setup DebugLn
|
||||||
DebugLnProc := @AndroidDebugLn;
|
DebugLnProc := @AndroidDebugLn;
|
||||||
DebugOutProc := @AccumulatingDebugOut;
|
DebugOutProc := @AccumulatingDebugOut;
|
||||||
|
|
||||||
|
{$ifdef CD_UseNativeText}
|
||||||
|
// Create the dummy screen DC
|
||||||
|
ScreenBitmapRawImage.Init;
|
||||||
|
ScreenBitmapHeight := 100;
|
||||||
|
ScreenBitmapWidth := 100;
|
||||||
|
ScreenBitmapRawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(ScreenBitmapWidth, ScreenBitmapHeight);
|
||||||
|
ScreenBitmapRawImage.CreateData(True);
|
||||||
|
ScreenImage := TLazIntfImage.Create(0, 0);
|
||||||
|
ScreenImage.SetRawImage(ScreenBitmapRawImage);
|
||||||
|
ScreenDC := TLazCanvas.Create(ScreenImage);
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -238,7 +251,11 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TCDWidgetSet.BackendDestroy;
|
procedure TCDWidgetSet.BackendDestroy;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef CD_UseNativeText}
|
||||||
|
// Free the dummy screen DC
|
||||||
|
ScreenImage.Free;
|
||||||
|
ScreenDC.Free;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
@ -2180,9 +2180,17 @@ 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
|
||||||
lJavaString: jstring;
|
lJavaString: jstring;
|
||||||
|
lJavaBitmap: jobject;
|
||||||
|
pixels: PCardinal;
|
||||||
|
lImage: TLazIntfImage = nil;
|
||||||
|
lCanvas: TLazCanvas = nil;
|
||||||
|
lWidth, lHeight: jint;
|
||||||
|
lDestCanvas: TLazCanvas;
|
||||||
|
lDestX, lDestY: Integer;
|
||||||
begin
|
begin
|
||||||
{$ifdef VerboseCDText}
|
{$ifdef VerboseCDText}
|
||||||
DebugLn(Format('[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s', [DC, PtrInt(javaEnvRef), StrPas(Str)]));
|
DebugLn(Format(':>[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s X=%d Y=%d',
|
||||||
|
[DC, PtrInt(javaEnvRef), StrPas(Str), X, Y]));
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
Result := False;
|
Result := False;
|
||||||
@ -2194,24 +2202,57 @@ begin
|
|||||||
|
|
||||||
if not IsValidDC(DC) then Exit;
|
if not IsValidDC(DC) then Exit;
|
||||||
|
|
||||||
|
lDestCanvas := TLazCanvas(DC);
|
||||||
|
lDestX := X + lDestCanvas.BaseWindowOrg.X;
|
||||||
|
lDestY := Y + lDestCanvas.BaseWindowOrg.Y;
|
||||||
|
|
||||||
if (javaEnvRef = nil) then Exit;
|
if (javaEnvRef = nil) then Exit;
|
||||||
|
|
||||||
// Prepare the input
|
// Prepare the input
|
||||||
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
||||||
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
||||||
|
|
||||||
// Call the method
|
// Call the method to measure the text
|
||||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
|
||||||
|
|
||||||
// Call the method
|
// Call the method to draw the text
|
||||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText);
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText);
|
||||||
|
|
||||||
{ // Read the output
|
// Get the bitmap with the text
|
||||||
Size.cx := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclwidth);
|
lJavaBitmap := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityObject, javaField_lclbitmap);
|
||||||
Size.cy := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclheight);}
|
lWidth := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclwidth);
|
||||||
|
lHeight := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclheight);
|
||||||
|
|
||||||
{$ifdef VerboseCDText}
|
{$ifdef VerboseCDText}
|
||||||
DebugLn('[WinAPI ExtTextOut]');
|
DebugLn(Format(':[WinAPI ExtTextOut] lDestX=%d lDestY=%d lWidth=%d lHeight=%d',
|
||||||
|
[lDestX, lDestY, lWidth, lHeight]));
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
// ---------------------------
|
||||||
|
// Now copy it pixel per pixel
|
||||||
|
// ---------------------------
|
||||||
|
|
||||||
|
// Lock the
|
||||||
|
AndroidBitmap_lockPixels(javaEnvRef, lJavaBitmap, @pixels);
|
||||||
|
|
||||||
|
// Prepare the non-native image and canvas
|
||||||
|
UpdateControlLazImageAndCanvas(lImage, lCanvas, lWidth, lHeight, clfRGBA32, pixels, True, False);
|
||||||
|
|
||||||
|
{$ifdef VerboseCDText}DebugLn(':[WinAPI ExtTextOut] Before CanvasCopyRect');{$endif}
|
||||||
|
// Execute the copy
|
||||||
|
lDestCanvas.CanvasCopyRect(lCanvas, lDestX, lDestY, 0, 0, lWidth-1, lHeight-1); // try also AlphaBlend
|
||||||
|
|
||||||
|
{$ifdef VerboseCDText}DebugLn(':[WinAPI ExtTextOut] After CanvasCopyRect');{$endif}
|
||||||
|
// Release the bitmap lock
|
||||||
|
AndroidBitmap_unlockPixels(javaEnvRef, lJavaBitmap);
|
||||||
|
{$ifdef VerboseCDText}DebugLn(':[WinAPI ExtTextOut] After AndroidBitmap_unlockPixels');{$endif}
|
||||||
|
lCanvas.Free;
|
||||||
|
{$ifdef VerboseCDText}DebugLn(':[WinAPI ExtTextOut] B');{$endif}
|
||||||
|
lImage.Free;
|
||||||
|
{$ifdef VerboseCDText}DebugLn(':[WinAPI ExtTextOut] C');{$endif}
|
||||||
|
|
||||||
|
{$ifdef VerboseCDText}
|
||||||
|
DebugLn(':<[WinAPI ExtTextOut]');
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
@ -4032,24 +4073,31 @@ begin
|
|||||||
ColorRefToTQColor(TColorRef(QtDC.vTextColor), Color);
|
ColorRefToTQColor(TColorRef(QtDC.vTextColor), Color);
|
||||||
TQColorToColorRef(Color, Result);
|
TQColorToColorRef(Color, Result);
|
||||||
end;
|
end;
|
||||||
end;
|
end;*)
|
||||||
|
|
||||||
|
{$ifdef CD_UseNativeText}
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: GetTextExtentExPoint
|
Function: GetTextExtentExPoint
|
||||||
Params: http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx
|
Params: http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx
|
||||||
Returns: True on success
|
Returns: True on success
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TQtWidgetSet.GetTextExtentExPoint(DC: HDC; Str: PChar; Count,
|
function TCDWidgetSet.GetTextExtentExPoint(DC: HDC; Str: PChar; Count,
|
||||||
MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize
|
MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize
|
||||||
): Boolean;
|
): Boolean;
|
||||||
var
|
{var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
w: Integer;
|
w: Integer;
|
||||||
AStr: WideString;
|
AStr: WideString;
|
||||||
Accu: Integer;
|
Accu: Integer;}
|
||||||
begin
|
begin
|
||||||
|
{$ifdef VerboseCDText}
|
||||||
|
DebugLn(Format('[WinAPI GetTextExtentExPoint] DC=%x javaEnvRef=%x Str=%s',
|
||||||
|
[DC, PtrInt(javaEnvRef), StrPas(Str)]));
|
||||||
|
{$endif}
|
||||||
Result := False;
|
Result := False;
|
||||||
if not IsValidDC(DC) then Exit;
|
Size.cx := 200;
|
||||||
|
Size.cy := 200;
|
||||||
|
{ if not IsValidDC(DC) then Exit;
|
||||||
with TQtDeviceContext(DC) do
|
with TQtDeviceContext(DC) do
|
||||||
begin
|
begin
|
||||||
AStr := GetUtf8String(Str);
|
AStr := GetUtf8String(Str);
|
||||||
@ -4097,11 +4145,10 @@ begin
|
|||||||
PartialWidths[i] := Size.cx;
|
PartialWidths[i] := Size.cx;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;}
|
||||||
Result := True;
|
Result := True;
|
||||||
end;*)
|
end;
|
||||||
|
|
||||||
{$ifdef CD_UseNativeText}
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: GetTextExtentPoint
|
Function: GetTextExtentPoint
|
||||||
Params: none
|
Params: none
|
||||||
|
Loading…
Reference in New Issue
Block a user