MWT - Micro Window Toolkit
http://j2me-mwt.sourceforge.net/
这里的字体,是通过图形来实现的。不适合汉字啊。
==============================
http://www.pstreets.com
这里有个汉字字库,不过,在 N70 上运行出错了。
在模拟器上倒是跑起来了。
找模拟器的文件目录时,花了好一段时间:
C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\myrms\filesystem
//------------------------------------------------------------------------------
// COPYRIGHT 2010 GUIDEBEE
// ALL RIGHTS RESERVED.
// GUIDEBEE CONFIDENTIAL PROPRIETARY
/ REVISIONS
// Date Name Tracking # Description
// --------- ------------------- ---------- --------------------------
// 25APR2010 James Shen Initial Creation
//--------------------------------- PACKAGE ------------------------------------
package biz.guidebee.example.drawing2d;
//--------------------------------- IMPORTS ------------------------------------
//import javax.microedition.io.*;
//import javax.microedition.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import biz.guidebee.drawing.Color;
import biz.guidebee.drawing.FontEx;
import biz.guidebee.drawing.Pen;
import biz.guidebee.example.Graphics2DMIDlet;
import biz.guidebee.geometry.AffineTransform;
import biz.guidebee.geometry.Rectangle;
//[------------------------------ MAIN CLASS ----------------------------------]
//--------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
// -------- ------------------- ------------- --------------------------
// 25APR2010 James Shen Initial Creation
/**
* This demo shows font direction and measure string.
* <p>
* <hr><b>© Copyright 2010 Guidebee, Inc. All Rights Reserved.</b>
* @version 1.00, 25/04/10
* @author Guidebee, Inc.
*/
public class Fonts extends Graphics2DMIDlet {
public void startApp() {
graphics2D.clear(Color.WHITE);
AffineTransform matrix = new AffineTransform();
graphics2D.setAffineTransform(matrix);
try {
//FontEx font = FontEx.getSystemFont();
FontEx font = new FontEx( this.getClass().getResourceAsStream("songti.fon") );
// //String fontName = "file:///root1/fonts/songti.fon"; //模拟器
// String fontName = "file://localhost/E:/FONTS/SONGTI.FON"; //N70
// StreamConnection fconn = (StreamConnection) Connector.open(fontName);
// FontEx font = new FontEx(fconn.openInputStream());
int fontSize = 32;
char[] longLine = "汉国".toCharArray();
//char[] longLine = "hello".toCharArray();
int stringWidth = font.charsWidth(fontSize, longLine, 0, longLine.length,
FontEx.TEXT_DIR_LR);
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
graphics2D.setDefaultPen(new Pen(Color.BLUE, 1));
Rectangle rectangle = new Rectangle((canvasWidth - stringWidth) / 2,
(canvasHeight - 16) / 2, stringWidth, 16);
graphics2D.drawRectangle(null, rectangle);
graphics2D.setTextDirection(FontEx.TEXT_DIR_LR);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, rectangle.x,
rectangle.y + fontSize);
graphics2D.setDefaultPen(new Pen(Color.GREEN, 1));
graphics2D.setTextDirection(FontEx.TEXT_DIR_RL);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, rectangle.x + stringWidth,
rectangle.y + fontSize * 2);
graphics2D.setDefaultPen(new Pen(Color.RED, 1));
graphics2D.setTextDirection(FontEx.TEXT_DIR_TB);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, 16,
16);
graphics2D.invalidate();
} catch (Exception e) {
try {
FontEx font = FontEx.getSystemFont();
int fontSize = 12;
char[] longLine = e.getMessage().toCharArray();
int stringWidth = font.charsWidth(fontSize, longLine, 0, longLine.length,
FontEx.TEXT_DIR_LR);
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
graphics2D.setDefaultPen(new Pen(Color.BLUE, 1));
Rectangle rectangle = new Rectangle((canvasWidth - stringWidth) / 2,
(canvasHeight - 16) / 2, stringWidth, 16);
graphics2D.drawRectangle(null, rectangle);
graphics2D.setTextDirection(FontEx.TEXT_DIR_LR);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, rectangle.x,
rectangle.y + fontSize);
graphics2D.setDefaultPen(new Pen(Color.GREEN, 1));
graphics2D.setTextDirection(FontEx.TEXT_DIR_RL);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, rectangle.x + stringWidth,
rectangle.y + fontSize * 2);
graphics2D.setDefaultPen(new Pen(Color.RED, 1));
graphics2D.setTextDirection(FontEx.TEXT_DIR_TB);
graphics2D.drawChars(font, fontSize, longLine, 0, longLine.length, 16,
16);
graphics2D.invalidate();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}