guiFont.java :  » UnTagged » roiding » com » roiding » rdict » dict » Android Open Source

Android Open Source » UnTagged » roiding 
roiding » com » roiding » rdict » dict » guiFont.java
package com.roiding.rdict.dict;

import java.util.Vector;

public class guiFont {
  private static final guiFont Instance = new guiFont();

  // public fileLog log = null;
  private DictFile fc = null;

  private final int VIEW_SIZE = 256;
  private final int MIN_FORMAT_CODE = 0xF800;
  private final int DICT_FONTYINBIAO = MIN_FORMAT_CODE + 1;
  private final int CHAR_CACHE_MAX_SIZE = 2000;

  private fontYB fontYb = fontYB.getInstance();

  private Vector view[];

  // private Image img[];

  private guiFont() {
    // log = new fileLog("guiFont.txt");
    view = new Vector[VIEW_SIZE];
    // img = new Image[VIEW_SIZE];
    fc = new DictFile();
  }

  public static guiFont getInstance() {
    return Instance;
  }

  public void initGuiFont() {

    for (int i = 0; i < 1; i++) {
      String str = null;
      str = new String("/font/font0/font" + Integer.toString(i) + ".png");
      // img[i] = fc.readImage(str);
      str = null;
    }
    // freeMemory = Runtime.getRuntime().freeMemory();
    // totalMemory = Runtime.getRuntime().totalMemory();

  }

  public void drawmat(char[] mat, int w, int h, int x, int y, int color) {
    int i, j, k, nc, cols;

    w = (w + 7) / 8 * 8;
    nc = 0;
    for (i = 0; i < h; i++) {
      cols = 0;
      for (k = 0; k < w / 8; k++) {
        for (j = 0; j < 8; j++) {
          if (!((mat[nc] & (0x80 >> j)) == 0)) {
            // g.setColor(color);
            // g.drawLine(x + cols, y + i, x + cols, y + i);
          }
          cols++;
        }
        nc++;
      }
    }
  }

  public void close() {
    /*
     * for(int i = 0; i < VIEW_SIZE; i++) { view[i] = null; } for(int i = 0;
     * i < VIEW_SIZE; i++) { img[i] = null; }
     */
    // log.close();
  }

  public void drawChar(char c, int x, int y) {
    // log.traceString("drawChar()-----> begin");
    // Image img = getFontImage(c);
    short i = (short) ((c >> 8) & 0x00ff);

    // Image imgTmp = null;
    // imgTmp = getImageObject(i);
    // int value = (int) (c & 0x00ff);
    // // log.traceInt("value", value);
    // int pic_x = 12 * (value % 16);
    // int pic_y = 12 * (value / 16);
    // Image out = null;
    // try {
    // out = Image.createImage(imgTmp, pic_x, pic_y, 12, 12, 0);
    // } catch (Exception e) {
    // // log.traceString(e.toString());
    // System.out.println(e.toString());
    // }
    // try {
    // g.drawImage(out, x, y, Graphics.TOP | Graphics.LEFT);
    // } catch (Exception e) {
    // // log.traceString(e.toString());
    // System.out.println(e.toString());
    // }
    // out = null;
    // imgTmp = null;
  }

  public void drawFontImage(char c, int x, int y) {
    // log.traceString("drawFontImage()-----> begin");
    // Image img = getFontImage(c);
    short i = (short) ((c >> 8) & 0x00ff);
    // log.traceChar(c);
    // log.traceInt("AAAAAaaaaa", view[i].size());
    // log.traceInt("i", i);
    // for (int j = 0; j < view[i].size(); j++) {
    // charMap cm = null;
    // cm = (charMap) view[i].elementAt(j);
    // // log.traceString(cm.toString());
    // if (cm.c == c) {
    // // log.traceString("if (cm.c == c)");
    // if (cm.img == null) {
    // // log.traceString("if (cm.img == null)");
    // return;
    // }
    // try {
    // g.drawImage(cm.img, x, y, Graphics.TOP | Graphics.LEFT);
    // // log.traceString("draw OK");
    // } catch (Exception e) {
    // // log.traceString(e.toString());
    // }
    // cm = null;
    // return;
    // }
    // cm = null;
    // }
    // log.traceString("drawFontImage()-----> end");

  }

  public short getFontPropertyXSize(char c, int fontId) {
    if (fontId == DICT_FONTYINBIAO) {
      return fontYb.getCharInfo(c).XSize;
    }
    GUI_CHARINFO charInfo = new GUI_CHARINFO();
    charInfo.XSize = (short) getFontWidth(c);
    return charInfo.XSize;
  }

  public GUI_CHARINFO getFontProperty(char c, int fontId) {
    // log.traceString("getFontProperty()-----> begin");
    if (fontId == DICT_FONTYINBIAO) {
      return fontYb.getCharInfo(c);
    }
    GUI_CHARINFO charInfo = null;
    charInfo = new GUI_CHARINFO();
    charInfo.XSize = (short) getFontWidth(c);
    // log.traceString("getFontProperty()-----> end");
    return charInfo;
  }

  public void creatCharMap(char c) {
    // log.traceString("creatCharMap()-----> begin");
    short i = (short) ((c >> 8) & 0x00ff);

    if (view[i] == null) {
      view[i] = new Vector();
    }
    for (int j = 0; j < view[i].size(); j++) {
      charMap tmp = null;
      tmp = (charMap) view[i].elementAt(j);
      if (tmp.c == c) {
        tmp = null;
        return;
      }
      tmp = null;
    }
    charMap cm = null;
    cm = new charMap();
    cm.c = c;
    view[i].addElement(cm);
    cm = null;
    // log.traceString("creatCharMap()-----> end");
  }

  public void clearCharCache(int len) {
    int i = 0;
    int j = 0;
    int size = len;
    for (i = 0; i < VIEW_SIZE; i++) {
      if (view[i] != null) {
        size += view[i].size();
      }
      if (size > CHAR_CACHE_MAX_SIZE) {
        break;
      }
    }
    for (; i < VIEW_SIZE; i++) {
      if (view[i] != null) {
        for (j = 0; j < view[i].size(); j++) {
          charMap cm = null;
          cm = (charMap) view[i].elementAt(j);
          // cm.img = null;
          cm = null;
        }
        view[i].removeAllElements();
        view[i] = null;
      }
    }
    System.gc();
  }

  public void creatCharImg() {
    // log.traceString("creatCharImg()-----> begin");
    int i = 0;
    int j = 0;
    for (i = 0; i < VIEW_SIZE; i++) {
      if (view[i] != null) {
        // Image imgTmp = null;
        for (j = 0; j < view[i].size(); j++) {
          charMap cm = null;
          cm = (charMap) view[i].elementAt(j);
          // if (cm.img != null) {
          // continue;
          // }
          // if (imgTmp == null) {
          // imgTmp = getImageObject(i);
          // }
          // if (imgTmp == null) {
          // break;
          // }
          int value = (int) (cm.c & 0x00ff);
          // log.traceInt("value", value);
          int pic_x = 12 * (value % 16);
          int pic_y = 12 * (value / 16);
          // Image out = null;
          // try {
          // out = Image
          // .createImage(imgTmp, pic_x, pic_y, 12, 12, 0);
          // } catch (Exception e) {
          // // log.traceString(e.toString());
          // System.out.println(e.toString());
          // }
          // cm.img = out;
        }
        // imgTmp = null;
      }
    }
    // log.traceString("creatCharImg()-----> end");
  }

  // private Image getImageObject(int i) {
  // if (img[i] != null) {
  // return img[i];
  // } else {
  // for (int j = (VIEW_SIZE - 1); j >= 0; j--) {
  // if (img[j] != null) {
  // img[j] = null;
  // break;
  // }
  // }
  // int dir = i / 16;
  // int file = i % 16;
  // String str = null;
  // str = new String("/font/font" + Integer.toString(dir) + "/font"
  // + Integer.toString(file) + ".png");
  // img[i] = fc.readImage(str);
  // /*
  // * try{ img[i] = Image.createImage(str); }catch(Exception e) {
  // * //log.traceString(e.toString());
  // * System.out.println(e.toString()); }
  // */
  // return img[i];
  // }
  // }

  private int getFontWidth(char c) {
    int i = (int) ((c >> 12) & 0x000f);
    int j = (int) c;
    switch (i) {
    case 0:
      return getFontWidth0(j);
    case 1:
      return getFontWidth1(j);
    case 2:
      return getFontWidth2(j);
    case 3:
      return getFontWidth3(j);
    case 4:
      return getFontWidth4(j);
    case 5:
      return 12;
    case 6:
      return 12;
    case 7:
      return 12;
    case 8:
      return 12;
    case 9:
      return getFontWidth9(j);
    case 10:
      return getFontWidth10(j);
    case 11:
      return 12;
    case 12:
      return 12;
    case 13:
      return getFontWidth13(j);
    case 14:
      return getFontWidth14(j);
    case 15:
      return getFontWidth15(j);
    }
    return 0;

  }

  private int getFontWidth0(int i) {
    if ((i >= 0) && (i <= 0))
      return 12;
    if ((i >= 1) && (i <= 12))
      return 6;
    if ((i >= 13) && (i <= 13))
      return 0;
    if ((i >= 14) && (i <= 166))
      return 6;
    if ((i >= 167) && (i <= 168))
      return 12;
    if ((i >= 169) && (i <= 175))
      return 6;
    if ((i >= 176) && (i <= 177))
      return 12;
    if ((i >= 178) && (i <= 179))
      return 6;
    if ((i >= 180) && (i <= 180))
      return 12;
    if ((i >= 181) && (i <= 181))
      return 6;
    if ((i >= 182) && (i <= 182))
      return 12;
    if ((i >= 183) && (i <= 214))
      return 6;
    if ((i >= 215) && (i <= 215))
      return 12;
    if ((i >= 216) && (i <= 246))
      return 6;
    if ((i >= 247) && (i <= 247))
      return 12;
    if ((i >= 248) && (i <= 460))
      return 6;
    if ((i >= 461) && (i <= 461))
      return 12;
    if ((i >= 462) && (i <= 462))
      return 6;
    if ((i >= 463) && (i <= 463))
      return 12;
    if ((i >= 464) && (i <= 464))
      return 6;
    if ((i >= 465) && (i <= 465))
      return 12;
    if ((i >= 466) && (i <= 466))
      return 6;
    if ((i >= 467) && (i <= 467))
      return 12;
    if ((i >= 468) && (i <= 468))
      return 6;
    if ((i >= 469) && (i <= 469))
      return 12;
    if ((i >= 470) && (i <= 470))
      return 6;
    if ((i >= 471) && (i <= 471))
      return 12;
    if ((i >= 472) && (i <= 472))
      return 6;
    if ((i >= 473) && (i <= 473))
      return 12;
    if ((i >= 474) && (i <= 474))
      return 6;
    if ((i >= 475) && (i <= 475))
      return 12;
    if ((i >= 476) && (i <= 500))
      return 6;
    if ((i >= 501) && (i <= 501))
      return 12;
    if ((i >= 502) && (i <= 713))
      return 6;
    if ((i >= 714) && (i <= 715))
      return 12;
    if ((i >= 716) && (i <= 719))
      return 6;
    if ((i >= 720) && (i <= 720))
      return 12;
    if ((i >= 721) && (i <= 912))
      return 6;
    if ((i >= 913) && (i <= 929))
      return 12;
    if ((i >= 930) && (i <= 930))
      return 6;
    if ((i >= 931) && (i <= 937))
      return 12;
    if ((i >= 938) && (i <= 944))
      return 6;
    if ((i >= 945) && (i <= 961))
      return 12;
    if ((i >= 962) && (i <= 962))
      return 6;
    if ((i >= 963) && (i <= 969))
      return 12;
    if ((i >= 970) && (i <= 1024))
      return 6;
    if ((i >= 1025) && (i <= 1025))
      return 8;
    if ((i >= 1026) && (i <= 1039))
      return 6;
    if ((i >= 1040) && (i <= 1040))
      return 10;
    if ((i >= 1041) && (i <= 1043))
      return 8;
    if ((i >= 1044) && (i <= 1044))
      return 9;
    if ((i >= 1045) && (i <= 1045))
      return 8;
    if ((i >= 1046) && (i <= 1046))
      return 12;
    if ((i >= 1047) && (i <= 1047))
      return 7;
    if ((i >= 1048) && (i <= 1049))
      return 10;
    if ((i >= 1050) && (i <= 1050))
      return 8;
    if ((i >= 1051) && (i <= 1053))
      return 10;
    if ((i >= 1054) && (i <= 1054))
      return 8;
    if ((i >= 1055) && (i <= 1055))
      return 9;
    if ((i >= 1056) && (i <= 1059))
      return 8;
    if ((i >= 1060) && (i <= 1060))
      return 10;
    if ((i >= 1061) && (i <= 1061))
      return 8;
    if ((i >= 1062) && (i <= 1062))
      return 10;
    if ((i >= 1063) && (i <= 1063))
      return 9;
    if ((i >= 1064) && (i <= 1065))
      return 12;
    if ((i >= 1066) && (i <= 1067))
      return 10;
    if ((i >= 1068) && (i <= 1069))
      return 8;
    if ((i >= 1070) && (i <= 1070))
      return 12;
    if ((i >= 1071) && (i <= 1071))
      return 8;
    if ((i >= 1072) && (i <= 1075))
      return 6;
    if ((i >= 1076) && (i <= 1076))
      return 7;
    if ((i >= 1077) && (i <= 1077))
      return 6;
    if ((i >= 1078) && (i <= 1078))
      return 8;
    if ((i >= 1079) && (i <= 1086))
      return 6;
    if ((i >= 1087) && (i <= 1087))
      return 8;
    if ((i >= 1088) && (i <= 1088))
      return 7;
    if ((i >= 1089) && (i <= 1091))
      return 6;
    if ((i >= 1092) && (i <= 1092))
      return 8;
    if ((i >= 1093) && (i <= 1093))
      return 6;
    if ((i >= 1094) && (i <= 1094))
      return 7;
    if ((i >= 1095) && (i <= 1095))
      return 6;
    if ((i >= 1096) && (i <= 1096))
      return 8;
    if ((i >= 1097) && (i <= 1097))
      return 9;
    if ((i >= 1098) && (i <= 1098))
      return 8;
    if ((i >= 1099) && (i <= 1099))
      return 7;
    if ((i >= 1100) && (i <= 1101))
      return 6;
    if ((i >= 1102) && (i <= 1102))
      return 8;
    if ((i >= 1103) && (i <= 4095))
      return 6;
    return 0;
  }

  private int getFontWidth1(int i) {
    if ((i >= 4352) && (i <= 4601)) {
      return 12;
    } else {
      return 6;
    }
  }

  private int getFontWidth2(int i) {
    if (((i >= 8193) && (i <= 8193)) || ((i >= 8195) && (i <= 8195))
        || ((i >= 8208) && (i <= 8208)) || ((i >= 8213) && (i <= 8214))
        || ((i >= 8216) && (i <= 8217)) || ((i >= 8220) && (i <= 8221))
        || ((i >= 8224) && (i <= 8225)) || ((i >= 8229) && (i <= 8230))
        || ((i >= 8240) && (i <= 8240)) || ((i >= 8242) && (i <= 8243))
        || ((i >= 8251) && (i <= 8251)) || ((i >= 8451) && (i <= 8451))
        || ((i >= 8470) && (i <= 8470)) || ((i >= 8481) && (i <= 8481))
        || ((i >= 8491) && (i <= 8491)) || ((i >= 8544) && (i <= 8578))
        || ((i >= 8592) && (i <= 8595)) || ((i >= 8658) && (i <= 8658))
        || ((i >= 8660) && (i <= 8660)) || ((i >= 8704) && (i <= 8704))
        || ((i >= 8706) && (i <= 8707)) || ((i >= 8711) && (i <= 8712))
        || ((i >= 8715) && (i <= 8715)) || ((i >= 8721) && (i <= 8721))
        || ((i >= 8730) && (i <= 8730)) || ((i >= 8733) && (i <= 8736))
        || ((i >= 8741) && (i <= 8741)) || ((i >= 8743) && (i <= 8748))
        || ((i >= 8750) && (i <= 8750)) || ((i >= 8756) && (i <= 8757))
        || ((i >= 8765) && (i <= 8765)) || ((i >= 8786) && (i <= 8786))
        || ((i >= 8800) && (i <= 8801)) || ((i >= 8806) && (i <= 8807))
        || ((i >= 8810) && (i <= 8811)) || ((i >= 8834) && (i <= 8835))
        || ((i >= 8838) && (i <= 8839)) || ((i >= 8869) && (i <= 8869))
        || ((i >= 8895) && (i <= 8895)) || ((i >= 8978) && (i <= 8978))
        || ((i >= 9312) && (i <= 9450)) || ((i >= 9472) && (i <= 9475))
        || ((i >= 9484) && (i <= 9484)) || ((i >= 9487) && (i <= 9488))
        || ((i >= 9491) && (i <= 9492)) || ((i >= 9495) && (i <= 9496))
        || ((i >= 9499) && (i <= 9501)) || ((i >= 9504) && (i <= 9504))
        || ((i >= 9507) && (i <= 9509)) || ((i >= 9512) && (i <= 9512))
        || ((i >= 9515) && (i <= 9516)) || ((i >= 9519) && (i <= 9520))
        || ((i >= 9523) && (i <= 9524)) || ((i >= 9527) && (i <= 9528))
        || ((i >= 9531) && (i <= 9532)) || ((i >= 9535) && (i <= 9535))
        || ((i >= 9538) && (i <= 9538)) || ((i >= 9547) && (i <= 9547))
        || ((i >= 9632) && (i <= 9633)) || ((i >= 9650) && (i <= 9651))
        || ((i >= 9660) && (i <= 9661)) || ((i >= 9670) && (i <= 9671))
        || ((i >= 9675) && (i <= 9675)) || ((i >= 9678) && (i <= 9679))
        || ((i >= 9711) && (i <= 9711)) || ((i >= 9728) && (i <= 9747))
        || ((i >= 9754) && (i <= 9784)) || ((i >= 9789) && (i <= 9823))
        || ((i >= 9832) && (i <= 9832)) || ((i >= 9834) && (i <= 9834))
        || ((i >= 9837) && (i <= 9837)) || ((i >= 9839) && (i <= 9839))
        || ((i >= 9985) && (i <= 9988)) || ((i >= 9990) && (i <= 9993))
        || ((i >= 9996) && (i <= 10023))
        || ((i >= 10025) && (i <= 10059))
        || ((i >= 10061) && (i <= 10061))
        || ((i >= 10063) && (i <= 10066))
        || ((i >= 10070) && (i <= 10070))
        || ((i >= 10072) && (i <= 10078))
        || ((i >= 10081) && (i <= 10087))
        || ((i >= 10102) && (i <= 10132))
        || ((i >= 10136) && (i <= 10159))
        || ((i >= 10161) && (i <= 10174)))
      return 12;
    else
      return 6;
  }

  private int getFontWidth3(int i) {
    if ((i >= 12288) && (i <= 12329))
      return 12;
    if ((i >= 12330) && (i <= 12335))
      return 6;
    if ((i >= 12336) && (i <= 12343))
      return 12;
    if ((i >= 12344) && (i <= 12352))
      return 6;
    if ((i >= 12353) && (i <= 12435))
      return 11;
    if ((i >= 12436) && (i <= 12436))
      return 12;
    if ((i >= 12437) && (i <= 12442))
      return 6;
    if ((i >= 12443) && (i <= 12446))
      return 11;
    if ((i >= 12447) && (i <= 12448))
      return 6;
    if ((i >= 12449) && (i <= 12534))
      return 11;
    if ((i >= 12535) && (i <= 12538))
      return 12;
    if ((i >= 12539) && (i <= 12542))
      return 11;
    if ((i >= 12543) && (i <= 12548))
      return 6;
    if ((i >= 12549) && (i <= 12585))
      return 12;
    if ((i >= 12586) && (i <= 12592))
      return 6;
    if ((i >= 12593) && (i <= 12686))
      return 12;
    if ((i >= 12687) && (i <= 12799))
      return 6;
    if ((i >= 12800) && (i <= 12828))
      return 12;
    if ((i >= 12829) && (i <= 12831))
      return 6;
    if ((i >= 12832) && (i <= 12867))
      return 12;
    if ((i >= 12868) && (i <= 12895))
      return 6;
    if ((i >= 12896) && (i <= 12923))
      return 12;
    if ((i >= 12924) && (i <= 12926))
      return 6;
    if ((i >= 12927) && (i <= 12976))
      return 12;
    if ((i >= 12977) && (i <= 12991))
      return 6;
    if ((i >= 12992) && (i <= 13003))
      return 12;
    if ((i >= 13004) && (i <= 13007))
      return 6;
    if ((i >= 13008) && (i <= 13054))
      return 12;
    if ((i >= 13055) && (i <= 13055))
      return 6;
    if ((i >= 13056) && (i <= 13174))
      return 12;
    if ((i >= 13175) && (i <= 13178))
      return 6;
    if ((i >= 13179) && (i <= 13277))
      return 12;
    if ((i >= 13278) && (i <= 13279))
      return 6;
    if ((i >= 13280) && (i <= 13310))
      return 12;
    if ((i >= 13311) && (i <= 13311))
      return 6;
    if ((i >= 13312) && (i <= 16383))
      return 12;
    return 0;
  }

  private int getFontWidth4(int i) {
    if ((i >= 19894) && (i <= 19967))
      return 6;
    else
      return 12;
  }

  private int getFontWidth9(int i) {
    if ((i >= 40870) && (i <= 40959))
      return 6;
    else
      return 12;
  }

  private int getFontWidth10(int i) {
    if ((i >= 40960) && (i <= 44031))
      return 6;
    else
      return 12;
  }

  private int getFontWidth13(int i) {
    if ((i >= 55204) && (i <= 57343))
      return 6;
    else
      return 12;

  }

  private int getFontWidth14(int i) {
    if (((i >= 57379) && (i <= 57379)) || ((i >= 57382) && (i <= 57386))
        || ((i >= 57392) && (i <= 57396))
        || ((i >= 57398) && (i <= 57399))
        || ((i >= 57408) && (i <= 57408))
        || ((i >= 59367) && (i <= 59379))
        || ((i >= 59413) && (i <= 59492)))
      return 12;
    else
      return 6;
  }

  private int getFontWidth15(int i) {
    if (((i >= 63744) && (i <= 64045)) || ((i >= 65072) && (i <= 65073))
        || ((i >= 65075) && (i <= 65092))
        || ((i >= 65097) && (i <= 65106))
        || ((i >= 65108) && (i <= 65111))
        || ((i >= 65113) && (i <= 65126))
        || ((i >= 65128) && (i <= 65131))
        || ((i >= 65281) && (i <= 65374))
        || ((i >= 65504) && (i <= 65510))
        || ((i >= 65532) && (i <= 65532)))
      return 12;
    else
      return 6;
  }
}

class charMap {
  public char c;
  // public Image img = null;
}

class GUI_CHARINFO {
  public short XSize = 0;
  public char pData[] = null;
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.