Recent

Author Topic: LAMW jcanvas setfont  (Read 221 times)

Mongkey

  • Sr. Member
  • ****
  • Posts: 429
LAMW jcanvas setfont
« on: December 09, 2023, 12:37:37 pm »
 :) i got error on setting this up:
java code
Code: Pascal  [Select][+][-]
  1.         public void SetFont(String _fontName) {
  2.                 Typeface customfont = Typeface.createFromAsset( controls.activity.getAssets(), _fontName);
  3.                 paint.setTypeface(customfont);
  4.         }
  5.  

on widget
Code: Pascal  [Select][+][-]
  1. procedure SetFont(_fontName: string);
  2.  
  3. procedure jCanvas.SetFont(_fontName: string);
  4. begin
  5.   //in designing component state: set value here...
  6.   if FInitialized then
  7.      jCanvas_SetFont(gApp.jni.jEnv, FjObject, _fontName);
  8. end;
  9.  

on bridge
Code: Pascal  [Select][+][-]
  1. procedure jCanvas_SetFont(env: PJNIEnv; _jcanvas: JObject; _fontName: string);
  2.  
  3. procedure jCanvas_SetFont(env: PJNIEnv; _jcanvas: JObject; _fontName: string);
  4. var
  5.   jParams: array[0..0] of jValue;
  6.   jMethod: jMethodID=nil;
  7.   jCls: jClass=nil;
  8. label
  9.   _exceptionOcurred;
  10. begin
  11.  
  12.   if (env = nil) or (_jcanvas = nil) then exit;
  13.   jCls:= env^.GetObjectClass(env, _jcanvas);
  14.   if jCls = nil then goto _exceptionOcurred;
  15.   jMethod:= env^.GetMethodID(env, jCls, 'SetFont', '(Ljava/lang/String;)V');
  16.   if jMethod = nil then begin env^.DeleteLocalRef(env, jCls); goto _exceptionOcurred; end;
  17.  
  18.   jParams[0].l:= env^.NewStringUTF(env, PChar(_fontName));
  19.  
  20.   env^.CallVoidMethodA(env, _jcanvas, jMethod, @jParams);
  21. env^.DeleteLocalRef(env,jParams[0].l);
  22.  
  23.   env^.DeleteLocalRef(env, jCls);
  24.  
  25.   _exceptionOcurred: jni_ExceptionOccurred(env);
  26. end;
  27.  

thank you

 

TinyPortal © 2005-2018