正在查找 J2ME 汉字字库的项目

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>&copy; 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();
			}
		}
        
    }

   
}
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值