Exemplo n.º 1
0
 public Vector2f getOrigin(String text) {
   Vector2f result = fontSizes.get(text);
   if (result == null) {
     result = new Vector2f(stringWidth(text) / 2f, getHeight() / 2f);
     fontSizes.put(text, result);
   }
   return result;
 }
Exemplo n.º 2
0
 public TMXProperties putAll(TMXProperties tmx) {
   ObjectMap<String, Object> data = tmx.properties;
   for (Entries<String, Object> key = data.iterator(); key.hasNext(); ) {
     Entry<String, Object> entry = key.next();
     properties.put(entry.key, entry.value);
   }
   return this;
 }
Exemplo n.º 3
0
 public void close() {
   this.isClose = true;
   if (displayList != null) {
     displayList.close();
     displayList = null;
   }
   if (displays != null) {
     for (Display d : displays.values()) {
       if (d != null && d.cache != null) {
         d.cache.close();
         d.cache = null;
       }
     }
     displays.clear();
     displays = null;
   }
 }
Exemplo n.º 4
0
  public int getWidth(String text) {
    if (text == null) {
      return 0;
    }
    Display display = null;
    for (Display d : displays.values()) {
      if (d != null && text.equals(d.text)) {
        display = d;
        break;
      }
    }
    if (display != null && display.width != 0) {
      return display.width;
    }
    if (display == null) {
      display = new Display();
    }
    int width = 0;
    CharDef lastCharDef = null;
    for (int i = 0, n = text.length(); i < n; i++) {
      int id = text.charAt(i);
      if (id == '\n') {
        width = 0;
        continue;
      }
      if (id >= chars.length) {
        continue;
      }
      CharDef charDef = chars[id];
      if (charDef == null) {
        continue;
      }
      if (lastCharDef != null) {
        width += lastCharDef.getKerning(id);
      }
      lastCharDef = charDef;
      if (i < n - 1) {
        width += charDef.advance;
      } else {
        width += charDef.width;
      }
      display.width = MathUtils.max(display.width, width);
    }

    return display.width;
  }
Exemplo n.º 5
0
 public int getHeight(String text) {
   if (text == null) {
     return 0;
   }
   Display display = null;
   for (Display d : displays.values()) {
     if (d != null && text.equals(d.text)) {
       display = d;
       break;
     }
   }
   if (display != null && display.height != 0) {
     return display.height;
   }
   if (display == null) {
     display = new Display();
   }
   int lines = 0;
   for (int i = 0; i < text.length(); i++) {
     int id = text.charAt(i);
     if (id == '\n') {
       lines++;
       display.height = 0;
       continue;
     }
     if (id == ' ') {
       continue;
     }
     CharDef charDef = chars[id];
     if (charDef == null) {
       continue;
     }
     display.height = MathUtils.max(charDef.height + charDef.yoffset, display.height);
   }
   display.height += lines * getLineHeight();
   return display.height;
 }
Exemplo n.º 6
0
  private void drawBatchString(
      float tx, float ty, String text, LColor c, int startIndex, int endIndex) {

    if (isClose) {
      return;
    }

    if (displays.size > DEFAULT_MAX_CHAR) {
      displays.clear();
    }

    lazyHashCode = 1;

    if (c != null) {
      lazyHashCode = LSystem.unite(lazyHashCode, c.r);
      lazyHashCode = LSystem.unite(lazyHashCode, c.g);
      lazyHashCode = LSystem.unite(lazyHashCode, c.b);
      lazyHashCode = LSystem.unite(lazyHashCode, c.a);
    }

    String key = text + lazyHashCode;

    Display display = displays.get(key);

    if (display == null) {

      int x = 0, y = 0;

      displayList.glBegin();
      displayList.setBatchPos(tx, ty);

      if (c != null) {
        displayList.setImageColor(c);
      }

      CharDef lastCharDef = null;
      char[] data = text.toCharArray();
      for (int i = 0; i < data.length; i++) {
        int id = data[i];
        if (id == '\n') {
          x = 0;
          y += getLineHeight();
          continue;
        }
        if (id >= chars.length) {
          continue;
        }
        CharDef charDef = chars[id];
        if (charDef == null) {
          continue;
        }

        if (lastCharDef != null) {
          x += lastCharDef.getKerning(id);
        }
        lastCharDef = charDef;

        if ((i >= startIndex) && (i <= endIndex)) {
          charDef.draw(x, y);
        }

        x += charDef.advance;
      }

      if (c != null) {
        displayList.setImageColor(LColor.white);
      }

      displayList.glEnd();

      display = new Display();

      display.cache = displayList.newBatchCache();
      display.text = text;
      display.width = 0;
      display.height = 0;

      displays.put(key, display);

    } else if (display.cache != null) {
      display.cache.x = tx;
      display.cache.y = ty;
      displayList.postCache(display.cache);
    }
  }
Exemplo n.º 7
0
  private void parse(String text) throws Exception {
    if (displays == null) {
      displays = new ObjectMap<String, Display>(DEFAULT_MAX_CHAR);
    } else {
      displays.clear();
    }
    StringTokenizer br = new StringTokenizer(text, LSystem.LS);
    info = br.nextToken();
    common = br.nextToken();
    page = br.nextToken();

    ObjectMap<Short, TArray<Short>> kerning = new ObjectMap<Short, TArray<Short>>(64);
    TArray<CharDef> charDefs = new TArray<CharDef>(DEFAULT_MAX_CHAR);

    int maxChar = 0;
    boolean done = false;
    for (; !done; ) {
      String line = br.nextToken();
      if (line == null) {
        done = true;
      } else {
        if (line.startsWith("chars c")) {
        } else if (line.startsWith("char")) {
          CharDef def = parseChar(line);
          if (def != null) {
            maxChar = MathUtils.max(maxChar, def.id);
            charDefs.add(def);
          }
        }
        if (line.startsWith("kernings c")) {
        } else if (line.startsWith("kerning")) {
          StringTokenizer tokens = new StringTokenizer(line, " =");
          tokens.nextToken();
          tokens.nextToken();
          short first = Short.parseShort(tokens.nextToken());
          tokens.nextToken();
          int second = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          int offset = Integer.parseInt(tokens.nextToken());
          TArray<Short> values = kerning.get(new Short(first));
          if (values == null) {
            values = new TArray<Short>();
            kerning.put(new Short(first), values);
          }
          values.add(new Short((short) ((offset << 8) | second)));
        }
      }
    }

    this.chars = new CharDef[maxChar + 1];

    for (Iterator<CharDef> iter = charDefs.iterator(); iter.hasNext(); ) {
      CharDef def = iter.next();
      chars[def.id] = def;
    }

    for (Entries<Short, TArray<Short>> iter = kerning.entries(); iter.hasNext(); ) {
      Entry<Short, TArray<Short>> entry = iter.next();
      short first = entry.key;
      TArray<Short> valueList = entry.value;
      short[] valueArray = new short[valueList.size];
      int i = 0;
      for (Iterator<Short> valueIter = valueList.iterator(); valueIter.hasNext(); i++) {
        valueArray[i] = (valueIter.next()).shortValue();
      }
      chars[first].kerning = valueArray;
    }
  }
Exemplo n.º 8
0
 public TMXProperties clear() {
   properties.clear();
   return this;
 }
Exemplo n.º 9
0
 public boolean contains(String key) {
   return properties.containsKey(key);
 }
Exemplo n.º 10
0
 @SuppressWarnings("unchecked")
 public <T> T get(String key) {
   return (T) properties.get(key);
 }
Exemplo n.º 11
0
 public TMXProperties put(String key, Object value) {
   properties.put(key, value);
   return this;
 }