Revision: 2458
http://sourceforge.net/p/swingme/code/2458
Author: yuranet
Date: 2021-06-16 13:13:55 +0000 (Wed, 16 Jun 2021)
Log Message:
-----------
can set font
Modified Paths:
--------------
iOSME/src/javax/microedition/lcdui/Graphics.java
iOSME/src/javax/microedition/lcdui/Image.java
iOSME/src/javax/microedition/m3g/Graphics3D.java
iOSME/src/net/yura/ios/iOSJpegEncoder.java
Property Changed:
----------------
iOSME/
Index: iOSME
===================================================================
--- iOSME 2021-06-15 18:28:15 UTC (rev 2457)
+++ iOSME 2021-06-16 13:13:55 UTC (rev 2458)
Property changes on: iOSME
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,2 ##
+build
+iOSME.iml
Modified: iOSME/src/javax/microedition/lcdui/Graphics.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Graphics.java 2021-06-15 18:28:15 UTC (rev 2457)
+++ iOSME/src/javax/microedition/lcdui/Graphics.java 2021-06-16 13:13:55 UTC (rev 2458)
@@ -1,21 +1,22 @@
package javax.microedition.lcdui;
import apple.corefoundation.c.CoreFoundation;
-import apple.corefoundation.enums.CFStringBuiltInEncodings;
import apple.corefoundation.opaque.CFAttributedStringRef;
-import apple.corefoundation.opaque.CFStringRef;
import apple.coregraphics.c.CoreGraphics;
import apple.coregraphics.opaque.CGColorRef;
import apple.coregraphics.opaque.CGContextRef;
+import apple.coregraphics.opaque.CGFontRef;
import apple.coregraphics.struct.CGPoint;
import apple.coregraphics.struct.CGRect;
import apple.coregraphics.struct.CGSize;
import apple.coretext.c.CoreText;
import apple.coretext.opaque.CTLineRef;
+import apple.foundation.NSAttributedString;
import apple.uikit.UIColor;
import apple.uikit.c.UIKit;
import javax.microedition.lcdui.game.Sprite;
import android.graphics.ColorMatrix;
+import org.moe.natj.objc.ObjCRuntime;
public class Graphics {
public static final int BASELINE = 64;
@@ -29,7 +30,7 @@
public static final int VCENTER = 2;
private CGContextRef context;
- private javax.microedition.lcdui.Font font;
+ private Font font;
private int tx, ty;
private int stroke;
@@ -70,6 +71,7 @@
public int getColor() {
//return paint.getColor();
+ // TODO keep local var
throw new UnsupportedOperationException();
}
@@ -131,7 +133,7 @@
UIKit.UIGraphicsBeginImageContext(imageRect.size());
UIKit.UIGraphicsPushContext(context);
- image.getBitmap().drawInRect(imageRect);
+ image.getUIImage().drawInRect(imageRect);
UIKit.UIGraphicsPopContext();
UIKit.UIGraphicsEndImageContext();
@@ -167,11 +169,14 @@
throw new UnsupportedOperationException();
}
- public javax.microedition.lcdui.Font getFont() {
+ public Font getFont() {
return font;
}
- public void setFont(javax.microedition.lcdui.Font font) {
+ public void setFont(Font font) {
+ // Use ObjCRuntime.cast or CRuntime.cast to cast between c types and oc types
+ // https://www.noisyfox.io/moe-native-types.html
+ CoreGraphics.CGContextSetFont(context, ObjCRuntime.cast(font.font, CGFontRef.class));
this.font = font;
}
@@ -180,25 +185,24 @@
int newy = y;
if (anchor == 0) {
- anchor = javax.microedition.lcdui.Graphics.TOP
- | javax.microedition.lcdui.Graphics.LEFT;
+ anchor = javax.microedition.lcdui.Graphics.TOP | javax.microedition.lcdui.Graphics.LEFT;
}
/*
- FontManager androidFont = FontManager.getFont(font);
- Paint paintFont = androidFont.getPaint();
if ((anchor & javax.microedition.lcdui.Graphics.TOP) != 0) {
newy -= androidFont.getFontMetricsInt().ascent;
- } else if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
+ }
+ else if ((anchor & javax.microedition.lcdui.Graphics.BOTTOM) != 0) {
newy -= androidFont.getFontMetricsInt().descent;
}
+
if ((anchor & javax.microedition.lcdui.Graphics.HCENTER) != 0) {
newx -= paintFont.measureText(str) / 2;
- } else if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
+ }
+ else if ((anchor & javax.microedition.lcdui.Graphics.RIGHT) != 0) {
newx -= paintFont.measureText(str);
}
- paintFont.setColor(paint.getColor());
if (str.indexOf('\n')<0) {
canvas.drawText(str, tx+newx, ty+newy, paintFont);
}
@@ -212,18 +216,21 @@
}
*/
// not sure if its possible to do it this way
- //NSAttributedString attributedString = NSAttributedString.alloc().initWithString(str);
+ //CFStringRef stringRef = CoreFoundation.CFStringCreateWithCString(CoreFoundation.kCFAllocatorDefault(), str, CFStringBuiltInEncodings.UTF8);
+ //CFAttributedStringRef attributedStringRef = CoreFoundation.CFAttributedStringCreate(CoreFoundation.kCFAllocatorDefault(), stringRef, null);
+ //CTLineRef line = CoreText.CTLineCreateWithAttributedString(attributedStringRef);
+ // then draw string
+ //CoreFoundation.CFRelease(attributedStringRef);
+ //CoreFoundation.CFRelease(stringRef);
- CFStringRef stringRef = CoreFoundation.CFStringCreateWithCString(CoreFoundation.kCFAllocatorDefault(), str, CFStringBuiltInEncodings.UTF8);
- CFAttributedStringRef attributedStringRef = CoreFoundation.CFAttributedStringCreate(CoreFoundation.kCFAllocatorDefault(), stringRef, null);
- CTLineRef line = CoreText.CTLineCreateWithAttributedString(attributedStringRef);
- CoreGraphics.CGContextSetTextPosition(context, x, y);
+ NSAttributedString attributedString = NSAttributedString.alloc().initWithString(str);
+ CTLineRef line = CoreText.CTLineCreateWithAttributedString(ObjCRuntime.cast(attributedString, CFAttributedStringRef.class));
+
+ CoreGraphics.CGContextSetTextPosition(context, newx, newy);
CoreText.CTLineDraw(line, context);
CoreFoundation.CFRelease(line);
- CoreFoundation.CFRelease(attributedStringRef);
- CoreFoundation.CFRelease(stringRef);
}
public void clipRect(int x, int y, int w, int h) {
@@ -266,7 +273,6 @@
public void translate(int x, int y) {
tx += x;
ty += y;
- //canvas.translate(x, y);
dirtyClip = true;
}
@@ -447,7 +453,7 @@
int a = paint.getAlpha();
paint.setAlpha(0xFF); // we do not support alpha when drawing images
- canvas.drawBitmap(src.getBitmap(), srcRect, dstRect, paint);
+ canvas.drawBitmap(src.getUIImage(), srcRect, dstRect, paint);
paint.setAlpha(a);
canvas.restore();
@@ -510,9 +516,10 @@
}
public void scale(double sx, double sy) {
- // TODO this is not being done at the right location, tx,ty
+ CoreGraphics.CGContextTranslateCTM(context, tx, ty);
CoreGraphics.CGContextScaleCTM(context, sx, sy);
- //canvas.scale((float)sx, (float)sy,tx,ty);
+ CoreGraphics.CGContextTranslateCTM(context, - tx * sx, - ty * sy);
+
dirtyClip = true;
}
Modified: iOSME/src/javax/microedition/lcdui/Image.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Image.java 2021-06-15 18:28:15 UTC (rev 2457)
+++ iOSME/src/javax/microedition/lcdui/Image.java 2021-06-16 13:13:55 UTC (rev 2458)
@@ -185,7 +185,7 @@
this.bitmap = bitmap;
}
- public UIImage getBitmap() {
+ public UIImage getUIImage() {
return bitmap;
}
Modified: iOSME/src/javax/microedition/m3g/Graphics3D.java
===================================================================
--- iOSME/src/javax/microedition/m3g/Graphics3D.java 2021-06-15 18:28:15 UTC (rev 2457)
+++ iOSME/src/javax/microedition/m3g/Graphics3D.java 2021-06-16 13:13:55 UTC (rev 2458)
@@ -52,7 +52,7 @@
targetGraphics.setColor(background.getColor());
targetGraphics.fillRect(vpX, vpY, vpW, vpH);
} else {
- UIImage image = background.getImage().getImage().getBitmap();
+ UIImage image = background.getImage().getImage().getUIImage();
CGContextRef context = targetGraphics.getContext();
int tx = targetGraphics.getTranslateX();
int ty = targetGraphics.getTranslateY();
Modified: iOSME/src/net/yura/ios/iOSJpegEncoder.java
===================================================================
--- iOSME/src/net/yura/ios/iOSJpegEncoder.java 2021-06-15 18:28:15 UTC (rev 2457)
+++ iOSME/src/net/yura/ios/iOSJpegEncoder.java 2021-06-16 13:13:55 UTC (rev 2458)
@@ -17,7 +17,7 @@
@Override
public void complete() throws MediaException {
- NSData data = UIKit.UIImageJPEGRepresentation(image.getBitmap(), 0.95);
+ NSData data = UIKit.UIImageJPEGRepresentation(image.getUIImage(), 0.95);
// TODO there must be a better way to do this
byte[] bytes = data.bytes().getBytePtr().toByteArray((int)data.length());
try {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|