2012-06-07 2 views
1

drawChar 함수로 그려지는 문자의 크기를 변경하는 것에 대한 질문이 있습니다.char 크기 글꼴 수정

내가 가진 솔루션을 발견 :

setFont(Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_BOLD, Font.SIZE_LARGE)); 

을하지만, 문자의 크기 만 3 가능성이 있습니다.
크기를 늘리는 방법이 있습니까?
아니면 가능하지 않습니까?

답변

0

사용자 정의 고정 폭 글꼴을 사용할 수 있습니다. 당신이 페인트와 http://smallandadaptive.blogspot.com.br/2008/12/custom-monospaced-font.html에서 코드 아래에 사용할 수있는 모든 문자와 PNG 파일을 만듭니다

여기
 

    public class MonospacedFont { 

    private Image image; 
    private char firstChar; 
    private int numChars; 
    private int charWidth; 

    public MonospacedFont(Image image, char firstChar, int numChars) { 
     if (image == null) { 
      throw new IllegalArgumentException("image == null"); 
     } 
     // the first visible Unicode character is '!' (value 33) 
     if (firstChar <= 33) { 
      throw new IllegalArgumentException("firstChar <= 33"); 
     } 
     // there must be at lease one character on the image 
     if (numChars <= 0) { 
      throw new IllegalArgumentException("numChars <= 0"); 
     } 
     this.image = image; 
     this.firstChar = firstChar; 
     this.numChars = numChars; 
     this.charWidth = image.getWidth()/this.numChars; 
    } 

    public void drawString (Graphics g, String text, int x, int y) { 
     // store current Graphics clip area to restore later 
     int clipX = g.getClipX(); 
     int clipY = g.getClipY(); 
     int clipWidth = g.getClipWidth(); 
     int clipHeight = g.getClipHeight(); 
     char [] chars = text.toCharArray(); 

     for (int i = 0; i < chars.length; i++) { 
      int charIndex = chars[i] - this.firstChar; 
      // current char exists on the image 
      if (charIndex >= 0 && charIndex <= this.numChars) { 
       g.setClip(x, y, this.charWidth, this.image.getHeight()); 
       g.drawImage(image, x - (charIndex * this.charWidth), y, Graphics.TOP | Graphics.LEFT); 
       x += this.charWidth; 
      } 
     } 

     // restore initial clip area 
     g.setClip(clipX, clipY, clipWidth, clipHeight); 
    } 
    } 

이 클래스를 사용하는 샘플 코드입니다.

 

    Image img; 
    try { 
     img = Image.createImage("/monospaced_3_5.PNG"); 
     MonospacedFont mf = new MonospacedFont(img, '0', 10); 
     mf.drawString(g, "", 40, 40); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

+0

답장을 보내주십시오. 숫자마다 하나의 비트 맵을 그리는 다른 솔루션을 선택했습니다. – Jazys