Examples of GlyphPage


Examples of com.badlogic.gdx.tools.hiero.unicodefont.GlyphPage

    out.println("common lineHeight=" + unicodeFont.getLineHeight() + " base=" + unicodeFont.getAscent() + " scaleW="
      + pageWidth + " scaleH=" + pageHeight + " pages=" + unicodeFont.getGlyphPages().size() + " packed=0");

    int pageIndex = 0, glyphCount = 0;
    for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) {
      GlyphPage page = (GlyphPage)pageIter.next();
      String fileName;
      if (pageIndex == 0 && !pageIter.hasNext())
        fileName = outputName + ".png";
      else
        fileName = outputName + (pageIndex + 1) + ".png";
      out.println("page id=" + pageIndex + " file=\"" + fileName + "\"");
      glyphCount += page.getGlyphs().size();
      pageIndex++;
    }

    out.println("chars count=" + glyphCount);

    // Always output space entry (codepoint 32).
    int[] glyphMetrics = getGlyphMetrics(font, 32);
    int xAdvance = glyphMetrics[1];
    out.println("char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=" + unicodeFont.getAscent()
      + "    xadvance=" + xAdvance + "     page=0  chnl=0 ");

    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.getU() * pageWidth) + "     y="
          + (int)(glyph.getV() * 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)
      System.out.println("Kerning information could not be output because a TTF font file was not specified.");
    else {
      Kerning kerning = new Kerning();
      try {
        kerning.load(Gdx.files.internal(ttfFileRef).read(), font.getSize());
      } catch (IOException ex) {
        System.out.println("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);
        }
      }
      out.println("kernings count=" + kerning.getCount());
      for (Iterator iter = kernings.iterator(); iter.hasNext();) {
        KerningPair pair = (KerningPair)iter.next();
        out.println("kerning first=" + pair.firstCodePoint + "  second=" + pair.secondCodePoint + "  amount=" + pair.offset);
      }
    }
    out.close();

    int width = unicodeFont.getGlyphPageWidth();
    int height = unicodeFont.getGlyphPageHeight();
    IntBuffer buffer = BufferUtils.createIntBuffer(width * height);
    BufferedImage pageImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    int[] row = new int[width];

    pageIndex = 0;
    for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) {
      GlyphPage page = (GlyphPage)pageIter.next();
      String fileName;
      if (pageIndex == 0 && !pageIter.hasNext())
        fileName = outputName + ".png";
      else
        fileName = outputName + (pageIndex + 1) + ".png";

      page.getTexture().bind();
      buffer.clear();
      GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buffer);
      WritableRaster raster = pageImage.getRaster();
      for (int y = 0; y < height; y++) {
        buffer.get(row);
View Full Code Here

Examples of org.newdawn.slick.font.GlyphPage

    Collections.sort(queuedGlyphs, heightComparator);

    // Add to existing pages.
    for (Iterator iter = glyphPages.iterator(); iter.hasNext();) {
      GlyphPage glyphPage = (GlyphPage)iter.next();
      maxGlyphsToLoad -= glyphPage.loadGlyphs(queuedGlyphs, maxGlyphsToLoad);
      if (maxGlyphsToLoad == 0 || queuedGlyphs.isEmpty())
        return true;
    }

    // Add to new pages.
    while (!queuedGlyphs.isEmpty()) {
      GlyphPage glyphPage = new GlyphPage(this, glyphPageWidth, glyphPageHeight);
      glyphPages.add(glyphPage);
      maxGlyphsToLoad -= glyphPage.loadGlyphs(queuedGlyphs, maxGlyphsToLoad);
      if (maxGlyphsToLoad == 0) return true;
    }

    return true;
  }
View Full Code Here

Examples of org.newdawn.slick.font.GlyphPage

  public void clearGlyphs () {
    for (int i = 0; i < PAGES; i++)
      glyphs[i] = null;

    for (Iterator iter = glyphPages.iterator(); iter.hasNext();) {
      GlyphPage page = (GlyphPage)iter.next();
      try {
        page.getImage().destroy();
      } catch (SlickException ignored) {
      }
    }
    glyphPages.clear();
View Full Code Here

Examples of org.newdawn.slick.font.GlyphPage

    Collections.sort(queuedGlyphs, heightComparator);

    // Add to existing pages.
    for (Iterator iter = glyphPages.iterator(); iter.hasNext();) {
      GlyphPage glyphPage = (GlyphPage)iter.next();
      maxGlyphsToLoad -= glyphPage.loadGlyphs(queuedGlyphs, maxGlyphsToLoad);
      if (maxGlyphsToLoad == 0 || queuedGlyphs.isEmpty())
        return true;
    }

    // Add to new pages.
    while (!queuedGlyphs.isEmpty()) {
      GlyphPage glyphPage = new GlyphPage(this, glyphPageWidth, glyphPageHeight);
      glyphPages.add(glyphPage);
      maxGlyphsToLoad -= glyphPage.loadGlyphs(queuedGlyphs, maxGlyphsToLoad);
      if (maxGlyphsToLoad == 0) return true;
    }

    return true;
  }
View Full Code Here

Examples of org.newdawn.slick.font.GlyphPage

  public void clearGlyphs () {
    for (int i = 0; i < PAGES; i++)
      glyphs[i] = null;

    for (Iterator iter = glyphPages.iterator(); iter.hasNext();) {
      GlyphPage page = (GlyphPage)iter.next();
      try {
        page.getImage().destroy();
      } catch (SlickException ignored) {
      }
    }
    glyphPages.clear();
View Full Code Here

Examples of org.newdawn.slick.font.GlyphPage

    out.println("common lineHeight=" + unicodeFont.getLineHeight() + " base=26 scaleW=" + pageWidth + " scaleH=" + pageHeight
      + " pages=" + unicodeFont.getGlyphPages().size() + " packed=0");

    int pageIndex = 0, glyphCount = 0;
    for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) {
      GlyphPage page = (GlyphPage)pageIter.next();
      String fileName;
      if (pageIndex == 0 && !pageIter.hasNext())
        fileName = outputName + ".png";
      else
        fileName = outputName + (pageIndex + 1) + ".png";
      out.println("page id=" + pageIndex + " file=\"" + fileName + "\"");
      glyphCount += page.getGlyphs().size();
      pageIndex++;
    }

    out.println("chars count=" + glyphCount);

    // Always output space entry (codepoint 32).
    int[] glyphMetrics = getGlyphMetrics(font, 32);
    int xAdvance = glyphMetrics[1];
    out.println("char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=" + unicodeFont.getAscent()
      + "    xadvance=" + xAdvance + "     page=0  chnl=0 ");

    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);
        }
      }
      out.println("kernings count=" + kerning.getCount());
      for (Iterator iter = kernings.iterator(); iter.hasNext();) {
        KerningPair pair = (KerningPair)iter.next();
        out.println("kerning first=" + pair.firstCodePoint + "  second=" + pair.secondCodePoint + "  amount=" + pair.offset);
      }
    }
    out.close();

    pageIndex = 0;
    ImageIOWriter imageWriter = new ImageIOWriter();
    for (Iterator pageIter = unicodeFont.getGlyphPages().iterator(); pageIter.hasNext();) {
      GlyphPage page = (GlyphPage)pageIter.next();
      String fileName;
      if (pageIndex == 0 && !pageIter.hasNext())
        fileName = outputName + ".png";
      else
        fileName = outputName + (pageIndex + 1) + ".png";
      File imageOutputFile = new File(outputDir, fileName);
      FileOutputStream imageOutput = new FileOutputStream(imageOutputFile);
      try {
        imageWriter.saveImage(page.getImage(), "png", imageOutput, true);
      } finally {
        imageOutput.close();
      }
      // Flip output image.
      Image image = new ImageIcon(imageOutputFile.getAbsolutePath()).getImage();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.