all codes are writen in Kotlin (#1452)

This commit is contained in:
lishaoxia1985
2019-12-16 02:28:34 +08:00
committed by Yair Morgenstern
parent 5d75c3d65e
commit e937ea0af1
14 changed files with 321 additions and 425 deletions

View File

@ -29,14 +29,19 @@ class NativeFont @JvmOverloads constructor(paint: NativeFontPaint = NativeFontPa
private fun createListener() {
var className = "core.java.nativefont.NativeFont"
if (Gdx.app.type == Application.ApplicationType.Desktop) {
className += "Desktop"
} else if (Gdx.app.type == Application.ApplicationType.Android) {
className += "Android"
} else if (Gdx.app.type == Application.ApplicationType.iOS) {
className += if (robovm) "IOS" else "IOSMoe"
} else if (Gdx.app.type == Application.ApplicationType.WebGL) {
className += "Html"
when (Gdx.app.type) {
Application.ApplicationType.Desktop -> {
className += "Desktop"
}
Application.ApplicationType.Android -> {
className += "Android"
}
Application.ApplicationType.iOS -> {
className += if (robovm) "IOS" else "IOSMoe"
}
Application.ApplicationType.WebGL -> {
className += "Html"
}
}
listener = try {
val claz = Gdx.app.javaClass.classLoader.loadClass(className) as Class<out NativeFontListener>
@ -163,7 +168,7 @@ class NativeFont @JvmOverloads constructor(paint: NativeFontPaint = NativeFontPa
val date = emojiSet[css]
appendEmoji(c2.toString() + "", date!!.path, date.size)
} else {
putGlyph(c2, listener!!.getFontPixmap(txt, paint))
putGlyph(c2, listener!!.getFontPixmap(txt, paint!!))
}
}

View File

@ -1,11 +0,0 @@
package core.java.nativefont;
import com.badlogic.gdx.graphics.Pixmap;
/**
* Created by tian on 2016/10/2.
*/
public interface NativeFontListener {
Pixmap getFontPixmap(String str, NativeFontPaint freePaint);
}

View File

@ -0,0 +1,10 @@
package core.java.nativefont
import com.badlogic.gdx.graphics.Pixmap
/**
* Created by tian on 2016/10/2.
*/
interface NativeFontListener {
fun getFontPixmap(txt: String, vpaint: NativeFontPaint): Pixmap
}

View File

@ -1,146 +0,0 @@
package core.java.nativefont;
import com.badlogic.gdx.graphics.Color;
/**
* Created by tian on 2016/10/2.
*/
public class NativeFontPaint {
private int textSize = 30;// 字号
private Color color = Color.WHITE;// 颜色
private boolean isFakeBoldText = false;// 是否粗体
private boolean isUnderlineText = false;// 是否下划线
private boolean isStrikeThruText = false;// 是否删除线
private Color strokeColor = null;// 描边颜色
private int strokeWidth = 3;// 描边宽度
private String ttfName = "";
public String getName() {
StringBuffer name = new StringBuffer();
name.append(ttfName).append("_").append(textSize).append("_").append(color.toIntBits())
.append("_").append(booleanToInt(isFakeBoldText)).append("_")
.append(booleanToInt(isUnderlineText));
if (strokeColor != null) {
name.append("_").append(strokeColor.toIntBits()).append("_").append(strokeWidth);
}
return name.toString();
}
private int booleanToInt(boolean b) {
return b == true ? 0 : 1;
}
public NativeFontPaint() {
}
public NativeFontPaint(String ttfName, int textSize, Color color, Color stroke, int strokeWidth,
boolean bold, boolean line, boolean thru) {
this.ttfName = ttfName;
this.textSize = textSize;
this.color = color;
this.strokeColor = stroke;
this.strokeWidth = strokeWidth;
this.isFakeBoldText = bold;
this.isUnderlineText = line;
this.isStrikeThruText = thru;
}
public NativeFontPaint(String ttfName) {
this.ttfName = ttfName;
}
public NativeFontPaint(String ttfName, int size) {
this.ttfName = ttfName;
this.textSize = size;
}
public NativeFontPaint(String ttfName, int size, Color color) {
this.ttfName = ttfName;
this.textSize = size;
this.color = color;
}
public NativeFontPaint(String ttfName, Color color) {
this.ttfName = ttfName;
this.color = color;
}
public NativeFontPaint(int size) {
this.textSize = size;
}
public NativeFontPaint(Color color) {
this.color = color;
}
public NativeFontPaint(int size, Color color) {
this.textSize = size;
this.color = color;
}
public int getTextSize() {
return textSize;
}
public void setTextSize(int textSize) {
this.textSize = textSize;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public boolean getFakeBoldText() {
return isFakeBoldText;
}
public void setFakeBoldText(boolean isFakeBoldText) {
this.isFakeBoldText = isFakeBoldText;
}
public boolean getUnderlineText() {
return isUnderlineText;
}
public void setUnderlineText(boolean isUnderlineText) {
this.isUnderlineText = isUnderlineText;
}
public boolean getStrikeThruText() {
return isStrikeThruText;
}
public void setStrikeThruText(boolean isStrikeThruText) {
this.isStrikeThruText = isStrikeThruText;
}
public Color getStrokeColor() {
return strokeColor;
}
public void setStrokeColor(Color strokeColor) {
this.strokeColor = strokeColor;
}
public int getStrokeWidth() {
return strokeWidth;
}
public void setStrokeWidth(int strokeWidth) {
this.strokeWidth = strokeWidth;
}
public void setTTFName(String ttfName) {
this.ttfName = ttfName;
}
public String getTTFName() {
return ttfName;
}
}

View File

@ -0,0 +1,79 @@
package core.java.nativefont
import com.badlogic.gdx.graphics.Color
/**
* Created by tian on 2016/10/2.
*/
class NativeFontPaint {
var textSize = 30 // 字号
var color = Color.WHITE // 颜色
var fakeBoldText = false // 是否粗体
var underlineText = false // 是否下划线
var strikeThruText = false // 是否删除线
var strokeColor: Color? = null // 描边颜色
var strokeWidth = 3 // 描边宽度
var tTFName = ""
val name: String
get() {
val name = StringBuffer()
name.append(tTFName).append("_").append(textSize).append("_").append(color.toIntBits())
.append("_").append(booleanToInt(fakeBoldText)).append("_")
.append(booleanToInt(underlineText))
if (strokeColor != null) {
name.append("_").append(strokeColor!!.toIntBits()).append("_").append(strokeWidth)
}
return name.toString()
}
private fun booleanToInt(b: Boolean): Int {
return if (b == true) 0 else 1
}
constructor() {}
constructor(ttfName: String, textSize: Int, color: Color, stroke: Color?, strokeWidth: Int,
bold: Boolean, line: Boolean, thru: Boolean) {
tTFName = ttfName
this.textSize = textSize
this.color = color
strokeColor = stroke
this.strokeWidth = strokeWidth
fakeBoldText = bold
underlineText = line
strikeThruText = thru
}
constructor(ttfName: String) {
tTFName = ttfName
}
constructor(ttfName: String, size: Int) {
tTFName = ttfName
textSize = size
}
constructor(ttfName: String, size: Int, color: Color) {
tTFName = ttfName
textSize = size
this.color = color
}
constructor(ttfName: String, color: Color) {
tTFName = ttfName
this.color = color
}
constructor(size: Int) {
textSize = size
}
constructor(color: Color) {
this.color = color
}
constructor(size: Int, color: Color) {
textSize = size
this.color = color
}
}