use of var3d.net.center.freefont.FreePaint in project var3dframe by Var3D.
the class VGame method create.
public void create() {
// 数据存储实例化
save = Gdx.app.getPreferences(getProjectName());
// 劫持系统返回键
Gdx.input.setCatchBackKey(true);
// 触控实例化
multiplexer = new InputMultiplexer();
//
Gdx.input.setInputProcessor(multiplexer);
stageTop = new StageTop(this);
stageTop.setOff();
isMusic = save.getBoolean("isMusic", true);
isSound = save.getBoolean("isSound", true);
// 全球化字体方案
if (bundle == null)
bundle = new VBundle(var3dListener);
// 创建一个默认动态文本
FreeBitmapFont font = new FreeBitmapFont(this, new FreePaint(getDefaultFontSize()));
font.appendText("01234567890LoadingC" + getHeap());
fonts.put("font", font);
setStageLoad(StageLoad.class);
init();
var3dListener.create();
}
use of var3d.net.center.freefont.FreePaint in project var3dframe by Var3D.
the class Game method init.
@Override
public void init() {
// openAutoScreenshots(5,StageTest.class);//开启自动截图
// 不设置这一句无法使用R.strings.xxxxx的形式使用多语言,但可以使用其他在assets里的资源
setResources(R.class);
// openProtect("image");//加密image文件夹资源
// unProtect("image");
// showFps();//显示fps
setFont("test", new FreeBitmapFont(this, new FreePaint(R.font.DroidSans)));
// 设置入口界面
setStage(StageTest.class);
}
use of var3d.net.center.freefont.FreePaint in project var3dframe by Var3D.
the class VDesktopLauncher method getFontPixmap.
public Pixmap getFontPixmap(String txt, FreePaint vpaint) {
Font font = getFont(vpaint);
FontMetrics fm = metrics.get(vpaint.getName());
int strWidth = fm.stringWidth(txt);
int strHeight = fm.getAscent() + fm.getDescent();
if (strWidth == 0) {
strWidth = strHeight = vpaint.getTextSize();
}
BufferedImage bi = new BufferedImage(strWidth, strHeight, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setFont(font);
if (vpaint.getStrokeColor() != null) {
// 描边
GlyphVector v = font.createGlyphVector(fm.getFontRenderContext(), txt);
Shape shape = v.getOutline();
g.setColor(getColor(vpaint.getColor()));
g.translate(0, fm.getAscent());
g.fill(shape);
g.setStroke(new BasicStroke(vpaint.getStrokeWidth()));
g.setColor(getColor(vpaint.getStrokeColor()));
g.draw(shape);
} else if (vpaint.getUnderlineText() == true) {
// 下划线
AttributedString as = new AttributedString(txt);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
g.setColor(getColor(vpaint.getColor()));
g.drawString(as.getIterator(), 0, fm.getAscent());
} else if (vpaint.getStrikeThruText() == true) {
// 删除线
AttributedString as = new AttributedString(txt);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
g.setColor(getColor(vpaint.getColor()));
g.drawString(as.getIterator(), 0, fm.getAscent());
} else {
// 普通
g.setColor(getColor(vpaint.getColor()));
g.drawString(txt, 0, fm.getAscent());
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
ImageIO.write(bi, "png", buffer);
} catch (IOException e) {
e.printStackTrace();
}
Pixmap pixmap = new Pixmap(buffer.toByteArray(), 0, buffer.toByteArray().length);
return pixmap;
}
use of var3d.net.center.freefont.FreePaint in project var3dframe by Var3D.
the class VAndroidLauncher method getFontPixmap.
public Pixmap getFontPixmap(String txt, FreePaint vpaint) {
Paint paint = new Paint();
if (!vpaint.getTTFName().equals("")) {
// Typeface fontFace = fontFaces.get(vpaint.getTTFName());
Typeface fontFace = Typeface.createFromAsset(getAssets(), vpaint.getTTFName() + (vpaint.getTTFName().endsWith(".ttf") ? "" : ".ttf"));
fontFaces.put(vpaint.getTTFName(), fontFace);
paint.setTypeface(fontFace);
}
paint.setAntiAlias(true);
paint.setTextSize(vpaint.getTextSize());
FontMetrics fm = paint.getFontMetrics();
int w = (int) paint.measureText(txt);
int h = (int) (fm.descent - fm.ascent);
if (w == 0) {
w = h = vpaint.getTextSize();
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// 如果是描边类型
if (vpaint.getStrokeColor() != null) {
// 绘制外层
paint.setColor(getColor(vpaint.getStrokeColor()));
// 描边宽度
paint.setStrokeWidth(vpaint.getStrokeWidth());
// 描边种类
paint.setStyle(Style.FILL_AND_STROKE);
// 外层text采用粗体
paint.setFakeBoldText(true);
canvas.drawText(txt, 0, -fm.ascent, paint);
paint.setFakeBoldText(false);
} else {
paint.setUnderlineText(vpaint.getUnderlineText());
paint.setStrikeThruText(vpaint.getStrikeThruText());
paint.setFakeBoldText(vpaint.getFakeBoldText());
}
// 绘制内层
paint.setStrokeWidth(0);
paint.setColor(getColor(vpaint.getColor()));
canvas.drawText(txt, 0, -fm.ascent, paint);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, buffer);
byte[] encodedData = buffer.toByteArray();
Pixmap pixmap = new Pixmap(encodedData, 0, encodedData.length);
bitmap = null;
canvas = null;
return pixmap;
}
Aggregations