From 9645315d8707952cfb794475f1f0ca66239c2a21 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Mon, 12 Dec 2011 16:46:11 +0000 Subject: [PATCH] customdrawn-android: Improves the native text, not yet working git-svn-id: trunk@34135 - --- lcl/interfaces/customdrawn/customdrawnint.pas | 3 +- .../customdrawn/customdrawnobject_android.inc | 21 ++++- .../customdrawn/customdrawnwinapi_android.inc | 77 +++++++++++++++---- 3 files changed, 83 insertions(+), 18 deletions(-) diff --git a/lcl/interfaces/customdrawn/customdrawnint.pas b/lcl/interfaces/customdrawn/customdrawnint.pas index 5238a116c7..85c9fcc4b2 100644 --- a/lcl/interfaces/customdrawn/customdrawnint.pas +++ b/lcl/interfaces/customdrawn/customdrawnint.pas @@ -35,7 +35,7 @@ uses {$ifdef CD_Cocoa}MacOSAll, CocoaAll, CocoaPrivate, CocoaGDIObjects,{$endif} {$ifdef CD_X11}X, XLib, XUtil, customdrawn_x11proc,{unitxft, Xft font support}{$endif} {$ifdef CD_Android} - cmem, customdrawn_androidproc, jni, bitmap, log, + customdrawn_androidproc, jni, bitmap, log, {$endif} // Widgetset customdrawnproc, @@ -241,6 +241,7 @@ var javaField_lclbutton1: JfieldID=nil; javaField_lclbutton2: JfieldID=nil; javaField_lclbutton3: JfieldID=nil; + javaField_lclbitmap: JfieldID=nil; // Methods of our Activity javaMethod_LCLDoGetTextBounds: jmethodid = nil; diff --git a/lcl/interfaces/customdrawn/customdrawnobject_android.inc b/lcl/interfaces/customdrawn/customdrawnobject_android.inc index 0c8c822d3c..c749cb357e 100644 --- a/lcl/interfaces/customdrawn/customdrawnobject_android.inc +++ b/lcl/interfaces/customdrawn/customdrawnobject_android.inc @@ -175,7 +175,7 @@ begin if javaEnvRef^^.RegisterNatives(javaEnvRef, javaActivityClass, @NativeMethods[0],length(NativeMethods))<0 then begin __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; // Read all field IDs @@ -190,6 +190,7 @@ begin JavaField_lclbutton1 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton1', 'I'); JavaField_lclbutton2 := javaEnvRef^^.GetFieldID(javaEnvRef, javaActivityClass, 'lclbutton2', '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 begin __android_log_write(ANDROID_LOG_FATAL, 'lclapp', 'javaEnvRef^.GetFieldID failed for lcltext'); @@ -227,6 +228,18 @@ begin // Setup DebugLn DebugLnProc := @AndroidDebugLn; 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; {------------------------------------------------------------------------------ @@ -238,7 +251,11 @@ end; ------------------------------------------------------------------------------} procedure TCDWidgetSet.BackendDestroy; begin - + {$ifdef CD_UseNativeText} + // Free the dummy screen DC + ScreenImage.Free; + ScreenDC.Free; + {$endif} end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc b/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc index a90921239f..18136d80ca 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc @@ -2180,9 +2180,17 @@ function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; var lJavaString: jstring; + lJavaBitmap: jobject; + pixels: PCardinal; + lImage: TLazIntfImage = nil; + lCanvas: TLazCanvas = nil; + lWidth, lHeight: jint; + lDestCanvas: TLazCanvas; + lDestX, lDestY: Integer; begin {$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} Result := False; @@ -2194,24 +2202,57 @@ begin if not IsValidDC(DC) then Exit; + lDestCanvas := TLazCanvas(DC); + lDestX := X + lDestCanvas.BaseWindowOrg.X; + lDestY := Y + lDestCanvas.BaseWindowOrg.Y; + if (javaEnvRef = nil) then Exit; // Prepare the input lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str); javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString); - // Call the method + // Call the method to measure the text javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds); - // Call the method + // Call the method to draw the text javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDrawText); -{ // Read the output - Size.cx := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclwidth); - Size.cy := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclheight);} + // Get the bitmap with the text + lJavaBitmap := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityObject, javaField_lclbitmap); + lWidth := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclwidth); + lHeight := javaEnvRef^^.GetLongField(javaEnvRef, javaActivityObject, javaField_lclheight); {$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} Result := True; @@ -4032,24 +4073,31 @@ begin ColorRefToTQColor(TColorRef(QtDC.vTextColor), Color); TQColorToColorRef(Color, Result); end; -end; +end;*) +{$ifdef CD_UseNativeText} {------------------------------------------------------------------------------ Function: GetTextExtentExPoint Params: http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx 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 ): Boolean; -var +{var i: Integer; w: Integer; AStr: WideString; - Accu: Integer; + Accu: Integer;} begin + {$ifdef VerboseCDText} + DebugLn(Format('[WinAPI GetTextExtentExPoint] DC=%x javaEnvRef=%x Str=%s', + [DC, PtrInt(javaEnvRef), StrPas(Str)])); + {$endif} Result := False; - if not IsValidDC(DC) then Exit; + Size.cx := 200; + Size.cy := 200; +{ if not IsValidDC(DC) then Exit; with TQtDeviceContext(DC) do begin AStr := GetUtf8String(Str); @@ -4097,11 +4145,10 @@ begin PartialWidths[i] := Size.cx; end; end; - end; + end;} Result := True; -end;*) +end; -{$ifdef CD_UseNativeText} {------------------------------------------------------------------------------ Function: GetTextExtentPoint Params: none