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

View File

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

View File

@ -171,6 +171,7 @@ begin
// Read all method IDs
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
end;

View File

@ -2179,23 +2179,45 @@ end;*)
------------------------------------------------------------------------------}
function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
{var
WideStr: WideString;
QtDC: TQtDeviceContext absolute DC;
B: Boolean; }
var
lJavaString: jstring;
begin
{$ifdef VerboseCDWinAPI}
WriteLn('[WinAPI ExtTextOut]');
{$ifdef VerboseCDText}
DebugLn(Format('[WinAPI ExtTextOut] DC=%x javaEnvRef=%x Str=%s', [DC, PtrInt(javaEnvRef), StrPas(Str)]));
{$endif}
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;
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);
if Str <> nil then
@ -4129,8 +4151,8 @@ function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
QtDC: TQtDeviceContext absolute DC;
FontWeight: Integer;}
begin
{$ifdef VerboseCDWinAPI}
DebugLn('[WinAPI GetTextMetrics]');
{$ifdef VerboseCDText}
DebugLn(Format('[WinAPI GetTextMetrics] DC=%x javaEnvRef=%x', [DC, PtrInt(javaEnvRef)]));
{$endif}
Result := IsValidDC(DC);