Package org.newdawn.slick.font

Examples of org.newdawn.slick.font.Glyph


    if (effects.isEmpty())
      throw new IllegalStateException("The UnicodeFont must have at least one effect before any glyphs can be loaded.");

    for (Iterator iter = queuedGlyphs.iterator(); iter.hasNext();) {
      Glyph glyph = (Glyph)iter.next();
      int codePoint = glyph.getCodePoint();

      // Don't load an image for a glyph with nothing to display.
      if (glyph.getWidth() == 0 || codePoint == ' ') {
        iter.remove();
        continue;
      }

      // Only load the first missing glyph.
      if (glyph.isMissing()) {
        if (missingGlyph != null) {
          if (glyph != missingGlyph) iter.remove();
          continue;
        }
        missingGlyph = glyph;
View Full Code Here


      if (charIndex > endIndex) break;

      int codePoint = text.codePointAt(charIndex);

      Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
      Glyph glyph = getGlyph(vector.getGlyphCode(glyphIndex), codePoint, bounds, vector, glyphIndex);

      if (startNewLine && codePoint != '\n') {
        extraX = -bounds.x;
        startNewLine = false;
      }

      Image image = glyph.getImage();
      if (image == null && missingGlyph != null && glyph.isMissing()) image = missingGlyph.getImage();
      if (image != null) {
        // Draw glyph, only binding a new glyph page texture when necessary.
        Texture texture = image.getTexture();
        if (lastBind != null && lastBind != texture) {
          GL.glEnd();
View Full Code Here

   * @return The glyph requested
   */
  private Glyph getGlyph (int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index) {
    if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) {
      // GlyphVector#getGlyphCode sometimes returns negative numbers on OS X.
      return new Glyph(codePoint, bounds, vector, index, this) {
        public boolean isMissing () {
          return true;
        }
      };
    }
    int pageIndex = glyphCode / PAGE_SIZE;
    int glyphIndex = glyphCode & (PAGE_SIZE - 1);
    Glyph glyph = null;
    Glyph[] page = glyphs[pageIndex];
    if (page != null) {
      glyph = page[glyphIndex];
      if (glyph != null) return glyph;
    } else
      page = glyphs[pageIndex] = new Glyph[PAGE_SIZE];
    // Add glyph so size information is available and queue it so its image can be loaded later.
    glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, this);
    queuedGlyphs.add(glyph);
    return glyph;
  }
View Full Code Here

    if (effects.isEmpty())
      throw new IllegalStateException("The UnicodeFont must have at least one effect before any glyphs can be loaded.");

    for (Iterator iter = queuedGlyphs.iterator(); iter.hasNext();) {
      Glyph glyph = (Glyph)iter.next();
      int codePoint = glyph.getCodePoint();

      // Don't load an image for a glyph with nothing to display.
      if (glyph.getWidth() == 0 || codePoint == ' ') {
        iter.remove();
        continue;
      }

      // Only load the first missing glyph.
      if (glyph.isMissing()) {
        if (missingGlyph != null) {
          if (glyph != missingGlyph) iter.remove();
          continue;
        }
        missingGlyph = glyph;
View Full Code Here

      if (charIndex > endIndex) break;

      int codePoint = text.codePointAt(charIndex);

      Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
      Glyph glyph = getGlyph(vector.getGlyphCode(glyphIndex), codePoint, bounds, vector, glyphIndex);

      if (startNewLine && codePoint != '\n') {
        extraX = -bounds.x;
        startNewLine = false;
      }

      Image image = glyph.getImage();
      if (image == null && missingGlyph != null && glyph.isMissing()) image = missingGlyph.getImage();
      if (image != null) {
        // Draw glyph, only binding a new glyph page texture when necessary.
        Texture texture = image.getTexture();
        if (lastBind != null && lastBind != texture) {
          GL.glEnd();
View Full Code Here

   * @return The glyph requested
   */
  private Glyph getGlyph (int glyphCode, int codePoint, Rectangle bounds, GlyphVector vector, int index) {
    if (glyphCode < 0 || glyphCode >= MAX_GLYPH_CODE) {
      // GlyphVector#getGlyphCode sometimes returns negative numbers on OS X.
      return new Glyph(codePoint, bounds, vector, index, this) {
        public boolean isMissing () {
          return true;
        }
      };
    }
    int pageIndex = glyphCode / PAGE_SIZE;
    int glyphIndex = glyphCode & (PAGE_SIZE - 1);
    Glyph glyph = null;
    Glyph[] page = glyphs[pageIndex];
    if (page != null) {
      glyph = page[glyphIndex];
      if (glyph != null) return glyph;
    } else
      page = glyphs[pageIndex] = new Glyph[PAGE_SIZE];
    // Add glyph so size information is available and queue it so its image can be loaded later.
    glyph = page[glyphIndex] = new Glyph(codePoint, bounds, vector, index, this);
    queuedGlyphs.add(glyph);
    return glyph;
  }
View Full Code Here

    pageIndex = 0;
    List allGlyphs = new ArrayList(512);
    for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) {
      GlyphPage page = (GlyphPage)pageIter.next();
      for (Iterator glyphIter = page.getGlyphs().iterator(); glyphIter.hasNext();) {
        Glyph glyph = (Glyph)glyphIter.next();

        glyphMetrics = getGlyphMetrics(font, glyph.getCodePoint());
        int xOffset = glyphMetrics[0];
        xAdvance = glyphMetrics[1];

        out.println("char id=" + glyph.getCodePoint() + "   " + "x="
          + (int)(glyph.getImage().getTextureOffsetX() * pageWidth) + "     y="
          + (int)(glyph.getImage().getTextureOffsetY() * pageHeight) + "     width=" + glyph.getWidth() + "     height="
          + glyph.getHeight() + "     xoffset=" + xOffset + "     yoffset=" + glyph.getYOffset() + "    xadvance="
          + xAdvance + "     page=" + pageIndex + "  chnl=0 ");
      }
      allGlyphs.addAll(page.getGlyphs());
      pageIndex++;
    }

    String ttfFileRef = unicodeFont.getFontFile();
    if (ttfFileRef == null)
      Log.warn("Kerning information could not be output because a TTF font file was not specified.");
    else {
      Kerning kerning = new Kerning();
      try {
        kerning.load(ResourceLoader.getResourceAsStream(ttfFileRef), font.getSize());
      } catch (IOException ex) {
        Log.warn("Unable to read kerning information from font: " + ttfFileRef);
      }

      Map glyphCodeToCodePoint = new HashMap();
      for (Iterator iter = allGlyphs.iterator(); iter.hasNext();) {
        Glyph glyph = (Glyph)iter.next();
        glyphCodeToCodePoint.put(new Integer(getGlyphCode(font, glyph.getCodePoint())), new Integer(glyph.getCodePoint()));
      }

      List kernings = new ArrayList(256);
      class KerningPair {
        public int firstCodePoint, secondCodePoint, offset;
      }
      for (Iterator iter1 = allGlyphs.iterator(); iter1.hasNext();) {
        Glyph firstGlyph = (Glyph)iter1.next();
        int firstGlyphCode = getGlyphCode(font, firstGlyph.getCodePoint());
        int[] values = kerning.getValues(firstGlyphCode);
        if (values == null) continue;
        for (int i = 0; i < values.length; i++) {
          Integer secondCodePoint = (Integer)glyphCodeToCodePoint.get(new Integer(values[i] & 0xffff));
          if (secondCodePoint == null) continue; // We may not be outputting the second character.
          int offset = values[i] >> 16;
          KerningPair pair = new KerningPair();
          pair.firstCodePoint = firstGlyph.getCodePoint();
          pair.secondCodePoint = secondCodePoint.intValue();
          pair.offset = offset;
          kernings.add(pair);
        }
      }
View Full Code Here

TOP

Related Classes of org.newdawn.slick.font.Glyph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.