customdrawn-android: Advances the text drawing code

git-svn-id: trunk@33909 -
This commit is contained in:
sekelsenmat 2011-12-02 17:06:32 +00:00
parent 066a73b5a2
commit 4e01a5e817
4 changed files with 67 additions and 20 deletions

View File

@ -10,7 +10,9 @@ import android.view.*;
public class LCLActivity extends Activity public class LCLActivity extends Activity
{ {
// -------------------------------------------
// Our drawing surface // Our drawing surface
// -------------------------------------------
private class LCLSurface extends SurfaceView private class LCLSurface extends SurfaceView
{ {
public LCLSurface(Context context) public LCLSurface(Context context)
@ -30,9 +32,9 @@ public class LCLActivity extends Activity
//Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth) //Log.v("lclproject", "LCLSurface.onDraw width=" + Integer.toString(lWidth)
// + " height=" + Integer.toString(lHeight)); // + " height=" + Integer.toString(lHeight));
Bitmap lclbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888); Bitmap localbitmap = Bitmap.createBitmap(lWidth, lHeight, Bitmap.Config.ARGB_8888);
LCLDrawToBitmap(lWidth, lHeight, lclbitmap); LCLDrawToBitmap(lWidth, lHeight, localbitmap);
canvas.drawBitmap(lclbitmap, 0, 0, null); canvas.drawBitmap(localbitmap, 0, 0, null);
} }
@ -44,6 +46,10 @@ public class LCLActivity extends Activity
} }
} }
// -------------------------------------------
// Activity Events
// -------------------------------------------
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
@ -57,39 +63,56 @@ public class LCLActivity extends Activity
LCLOnCreate(this); LCLOnCreate(this);
} }
// -------------------------------------------
// JNI table of Pascal functions // JNI table of Pascal functions
// -------------------------------------------
public native int LCLDrawToBitmap(int width, int height, Bitmap bitmap); public native int LCLDrawToBitmap(int width, int height, Bitmap bitmap);
public native int LCLOnTouch(float x, float y, int action); public native int LCLOnTouch(float x, float y, int action);
public native int LCLOnCreate(LCLActivity lclactivity); public native int LCLOnCreate(LCLActivity lclactivity);
// -------------------------------------------
// Functions exported to the Pascal side // Functions exported to the Pascal side
// -------------------------------------------
// input: String lcltext // input: String lcltext
// output: int lclwidth, int lclheight // output: int lclwidth, int lclheight
public void LCLDoGetTextBounds() public void LCLDoGetTextBounds()
{ {
Paint paint = new Paint(); Paint localpaint = new Paint();
Rect bounds = new Rect(); Rect localbounds = new Rect();
paint.getTextBounds(lcltext, 0, lcltext.length(), bounds); localpaint.getTextBounds(lcltext, 0, lcltext.length(), localbounds);
lclwidth = bounds.width(); lclwidth = localbounds.width();
lclheight = bounds.height(); lclheight = localbounds.height();
} }
// input: String lcltext, int lclwidth, int lclheight
// output: lclbitmap
public void LCLDoDrawText()
{
lclbitmap = Bitmap.createBitmap(lclwidth, lclheight, Bitmap.Config.ARGB_8888);
Canvas localcanvas = new Canvas(lclbitmap);
Paint localpaint = new Paint();
localcanvas.drawText(lcltext, 0, 0, localpaint);
}
// -------------------------------------------
// Fields exported to the Pascal side for easier data communication // Fields exported to the Pascal side for easier data communication
// -------------------------------------------
public String lcltext; public String lcltext;
public int lclwidth; public int lclwidth;
public int lclheight; public int lclheight;
public Bitmap lclbitmap;
static static
{ {
try try
{ {
Log.i("lclproject", "Trying to load liblclapp.so"); Log.i("lclapp", "Trying to load liblclapp.so");
System.loadLibrary("lclapp"); System.loadLibrary("lclapp");
} }
catch(UnsatisfiedLinkError ule) catch(UnsatisfiedLinkError ule)
{ {
Log.e("lclproject", "WARNING: Could not load liblclapp.so"); Log.e("lclapp", "WARNING: Could not load liblclapp.so");
ule.printStackTrace(); ule.printStackTrace();
} }
} }

View File

@ -219,6 +219,7 @@ var
// Methods of our Activity // Methods of our Activity
javaMethod_LCLDoGetTextBounds: jmethodid = nil; javaMethod_LCLDoGetTextBounds: jmethodid = nil;
javaMethod_LCLDoDrawText: jmethodid = nil;
// This is utilized to store the information such as invalidate requests in events // This is utilized to store the information such as invalidate requests in events
eventResult: jint; eventResult: jint;

View File

@ -171,6 +171,7 @@ begin
// Read all method IDs // Read all method IDs
javaMethod_LCLDoGetTextBounds := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoGetTextBounds', '()V'); javaMethod_LCLDoGetTextBounds := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoGetTextBounds', '()V');
javaMethod_LCLDoDrawText := javaEnvRef^^.GetMethodID(javaEnvRef, javaActivityClass, 'LCLDoDrawText', '()V');
result:=JNI_VERSION_1_4;// 1_6 is another option result:=JNI_VERSION_1_4;// 1_6 is another option
end; end;

View File

@ -2179,23 +2179,45 @@ 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; lJavaString: jstring;
QtDC: TQtDeviceContext absolute DC;
B: Boolean; }
begin begin
{$ifdef VerboseCDWinAPI} {$ifdef VerboseCDText}
WriteLn('[WinAPI ExtTextOut]'); DebugLn(Format('[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s', [DC, PtrInt(javaEnvRef), StrPas(Str)]));
{$endif} {$endif}
Result := False; Result := False;
{ if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then if (Str = nil) or (Str = '') then Exit;
if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then
exit; exit;
if not IsValidDC(DC) then Exit; if not IsValidDC(DC) then Exit;
if ((Options and ETO_OPAQUE) <> 0) then if (javaEnvRef = nil) then Exit;
// Prepare the input
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
// Call the method
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
// Call the method
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);}
{$ifdef VerboseCDText}
DebugLn('[WinAPI ExtTextOut]');
{$endif}
Result := True;
{ if ((Options and ETO_OPAQUE) <> 0) then
QtDC.fillRect(Rect^.Left, Rect^.Top, Rect^.Right - Rect^.Left, Rect^.Bottom - Rect^.Top); QtDC.fillRect(Rect^.Left, Rect^.Top, Rect^.Right - Rect^.Left, Rect^.Bottom - Rect^.Top);
if Str <> nil then if Str <> nil then
@ -4129,8 +4151,8 @@ function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
QtDC: TQtDeviceContext absolute DC; QtDC: TQtDeviceContext absolute DC;
FontWeight: Integer;} FontWeight: Integer;}
begin begin
{$ifdef VerboseCDWinAPI} {$ifdef VerboseCDText}
DebugLn('[WinAPI GetTextMetrics]'); DebugLn(Format('[WinAPI GetTextMetrics] DC=%x javaEnvRef=%x', [DC, PtrInt(javaEnvRef)]));
{$endif} {$endif}
Result := IsValidDC(DC); Result := IsValidDC(DC);