List of usage examples for com.badlogic.gdx.files FileHandle writeString
public void writeString(String string, boolean append, String charset)
From source file:by.aleks.christmasboard.data.BitmapFontWriter.java
License:Apache License
/** Writes the given BitmapFontData to a file, using the specified <tt>pageRefs</tt> strings as the image paths for each texture * page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. * /*from w w w. j a v a2 s . com*/ * The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be * null to use default values. Ultimately, LibGDX ignores the "info" line when reading back fonts. * * Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by LibGDX's reader. For maximum * compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the * same size). * * @param fontData the bitmap font * @param pageRefs the references to each texture page image file, generally in the same folder as outFntFile * @param outFntFile the font file to save to (typically ends with '.fnt') * @param info the optional info for the file header; can be null * @param scaleW the width of your texture pages * @param scaleH the height of your texture pages */ public static void writeFont(BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, FontInfo info, int scaleW, int scaleH) { if (info == null) { info = new FontInfo(); info.face = outFntFile.nameWithoutExtension(); } int lineHeight = (int) fontData.lineHeight; int pages = pageRefs.length; int packed = 0; int base = (int) ((fontData.capHeight) + (fontData.flipped ? -fontData.ascent : fontData.ascent)); OutputFormat fmt = BitmapFontWriter.getOutputFormat(); boolean xml = fmt == OutputFormat.XML; StringBuilder buf = new StringBuilder(); if (xml) { buf.append("<font>\n"); } String xmlOpen = xml ? "\t<" : ""; String xmlCloseSelf = xml ? "/>" : ""; String xmlTab = xml ? "\t" : ""; String xmlClose = xml ? ">" : ""; String xmlQuote = xml ? "\"" : ""; String alphaChnlParams = xml ? " alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"" : " alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0"; //INFO LINE buf.append(xmlOpen).append("info face=\"").append(info.face == null ? "" : info.face.replaceAll("\"", "'")) .append("\" size=").append(quote(info.size)).append(" bold=").append(quote(info.bold ? 1 : 0)) .append(" italic=").append(quote(info.italic ? 1 : 0)).append(" charset=\"") .append(info.charset == null ? "" : info.charset).append("\" unicode=") .append(quote(info.unicode ? 1 : 0)).append(" stretchH=").append(quote(info.stretchH)) .append(" smooth=").append(quote(info.smooth ? 1 : 0)).append(" aa=").append(quote(info.aa)) .append(" padding=").append(xmlQuote).append(info.padding.up).append(",").append(info.padding.down) .append(",").append(info.padding.left).append(",").append(info.padding.right).append(xmlQuote) .append(" spacing=").append(xmlQuote).append(info.spacing.horizontal).append(",") .append(info.spacing.vertical).append(xmlQuote).append(xmlCloseSelf).append("\n"); //COMMON line buf.append(xmlOpen).append("common lineHeight=").append(quote(lineHeight)).append(" base=") .append(quote(base)).append(" scaleW=").append(quote(scaleW)).append(" scaleH=") .append(quote(scaleH)).append(" pages=").append(quote(pages)).append(" packed=") .append(quote(packed)).append(alphaChnlParams).append(xmlCloseSelf).append("\n"); if (xml) buf.append("\t<pages>\n"); //PAGES for (int i = 0; i < pageRefs.length; i++) { buf.append(xmlTab).append(xmlOpen).append("page id=").append(quote(i)).append(" file=\"") .append(pageRefs[i]).append("\"").append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</pages>\n"); //CHARS Array<Glyph> glyphs = new Array<Glyph>(256); for (int i = 0; i < fontData.glyphs.length; i++) { if (fontData.glyphs[i] == null) continue; for (int j = 0; j < fontData.glyphs[i].length; j++) { if (fontData.glyphs[i][j] != null) { glyphs.add(fontData.glyphs[i][j]); } } } buf.append(xmlOpen).append("chars count=").append(quote(glyphs.size)).append(xmlClose).append("\n"); //CHAR definitions for (int i = 0; i < glyphs.size; i++) { Glyph g = glyphs.get(i); buf.append(xmlTab).append(xmlOpen).append("char id=").append(quote(String.format("%-5s", g.id), true)) .append("x=").append(quote(String.format("%-5s", g.srcX), true)).append("y=") .append(quote(String.format("%-5s", g.srcY), true)).append("width=") .append(quote(String.format("%-5s", g.width), true)).append("height=") .append(quote(String.format("%-5s", g.height), true)).append("xoffset=") .append(quote(String.format("%-5s", g.xoffset), true)).append("yoffset=") .append(quote(String.format("%-5s", fontData.flipped ? g.yoffset : -(g.height + g.yoffset)), true)) .append("xadvance=").append(quote(String.format("%-5s", g.xadvance), true)).append("page=") .append(quote(String.format("%-5s", g.page), true)).append("chnl=").append(quote(0, true)) .append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</chars>\n"); //KERNINGS int kernCount = 0; StringBuilder kernBuf = new StringBuilder(); for (int i = 0; i < glyphs.size; i++) { for (int j = 0; j < glyphs.size; j++) { Glyph first = glyphs.get(i); Glyph second = glyphs.get(j); int kern = first.getKerning((char) second.id); if (kern != 0) { kernCount++; kernBuf.append(xmlTab).append(xmlOpen).append("kerning first=").append(quote(first.id)) .append(" second=").append(quote(second.id)).append(" amount=") .append(quote(kern, true)).append(xmlCloseSelf).append("\n"); } } } //KERN info buf.append(xmlOpen).append("kernings count=").append(quote(kernCount)).append(xmlClose).append("\n"); buf.append(kernBuf); if (xml) { buf.append("\t</kernings>\n"); buf.append("</font>"); } String charset = info.charset; if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset); }
From source file:com.sasluca.lcl.graphics.fonts.EXTBitmapFontWriter.java
License:Apache License
/** Writes the given BitmapFontData to a file, using the specified <tt>pageRefs</tt> strings as the image paths for each texture * page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. * * The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be * null to use default values. Ultimately, LibGDX ignores the "info" line when reading back fonts. * * Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by LibGDX's reader. For maximum * compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the * same size)./*from w w w . java 2s. c o m*/ * * @param fontData the bitmap font * @param pageRefs the references to each texture page image file, generally in the same folder as outFntFile * @param outFntFile the font file to save to (typically ends with '.fnt') * @param info the optional info for the file header; can be null * @param scaleW the width of your texture pages * @param scaleH the height of your texture pages */ public static void writeFont(BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, FontInfo info, int scaleW, int scaleH) { if (info == null) { info = new FontInfo(); info.face = outFntFile.nameWithoutExtension(); } int lineHeight = (int) fontData.lineHeight; int pages = pageRefs.length; int packed = 0; int base = (int) ((fontData.capHeight) + (fontData.flipped ? -fontData.ascent : fontData.ascent)); OutputFormat fmt = EXTBitmapFontWriter.getOutputFormat(); boolean xml = fmt == OutputFormat.XML; StringBuilder buf = new StringBuilder(); if (xml) { buf.append("<font>\n"); } String xmlOpen = xml ? "\t<" : ""; String xmlCloseSelf = xml ? "/>" : ""; String xmlTab = xml ? "\t" : ""; String xmlClose = xml ? ">" : ""; String xmlQuote = xml ? "\"" : ""; String alphaChnlParams = xml ? " alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"" : " alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0"; //INFO LINE buf.append(xmlOpen).append("info face=\"").append(info.face == null ? "" : info.face.replaceAll("\"", "'")) .append("\" size=").append(quote(info.size)).append(" bold=").append(quote(info.bold ? 1 : 0)) .append(" italic=").append(quote(info.italic ? 1 : 0)).append(" charset=\"") .append(info.charset == null ? "" : info.charset).append("\" unicode=") .append(quote(info.unicode ? 1 : 0)).append(" stretchH=").append(quote(info.stretchH)) .append(" smooth=").append(quote(info.smooth ? 1 : 0)).append(" aa=").append(quote(info.aa)) .append(" padding=").append(xmlQuote).append(info.padding.up).append(",").append(info.padding.down) .append(",").append(info.padding.left).append(",").append(info.padding.right).append(xmlQuote) .append(" spacing=").append(xmlQuote).append(info.spacing.horizontal).append(",") .append(info.spacing.vertical).append(xmlQuote).append(xmlCloseSelf).append("\n"); //COMMON line buf.append(xmlOpen).append("common lineHeight=").append(quote(lineHeight)).append(" base=") .append(quote(base)).append(" scaleW=").append(quote(scaleW)).append(" scaleH=") .append(quote(scaleH)).append(" pages=").append(quote(pages)).append(" packed=") .append(quote(packed)).append(alphaChnlParams).append(xmlCloseSelf).append("\n"); if (xml) buf.append("\t<pages>\n"); //PAGES for (int i = 0; i < pageRefs.length; i++) { buf.append(xmlTab).append(xmlOpen).append("page id=").append(quote(i)).append(" file=\"") .append(pageRefs[i]).append("\"").append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</pages>\n"); //CHARS Array<Glyph> glyphs = new Array<Glyph>(256); for (int i = 0; i < fontData.glyphs.length; i++) { if (fontData.glyphs[i] == null) continue; for (int j = 0; j < fontData.glyphs[i].length; j++) { if (fontData.glyphs[i][j] != null) { glyphs.add(fontData.glyphs[i][j]); } } } buf.append(xmlOpen).append("chars count=").append(quote(glyphs.size)).append(xmlClose).append("\n"); //CHAR definitions for (int i = 0; i < glyphs.size; i++) { Glyph g = glyphs.get(i); buf.append(xmlTab).append(xmlOpen).append("char id=").append(quote(String.format("%-5s", g.id), true)) .append("x=").append(quote(String.format("%-5s", g.srcX), true)).append("y=") .append(quote(String.format("%-5s", g.srcY), true)).append("width=") .append(quote(String.format("%-5s", g.width), true)).append("height=") .append(quote(String.format("%-5s", g.height), true)).append("xoffset=") .append(quote(String.format("%-5s", g.xoffset), true)).append("yoffset=") .append(quote(String.format("%-5s", fontData.flipped ? g.yoffset : -(g.height + g.yoffset)), true)) .append("xadvance=").append(quote(String.format("%-5s", g.xadvance), true)).append("page=") .append(quote(String.format("%-5s", g.page), true)).append("chnl=").append(quote(0, true)) .append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</chars>\n"); //KERNINGS int kernCount = 0; StringBuilder kernBuf = new StringBuilder(); for (int i = 0; i < glyphs.size; i++) { for (int j = 0; j < glyphs.size; j++) { Glyph first = glyphs.get(i); Glyph second = glyphs.get(j); int kern = first.getKerning((char) second.id); if (kern != 0) { kernCount++; kernBuf.append(xmlTab).append(xmlOpen).append("kerning first=").append(quote(first.id)) .append(" second=").append(quote(second.id)).append(" amount=") .append(quote(kern, true)).append(xmlCloseSelf).append("\n"); } } } //KERN info buf.append(xmlOpen).append("kernings count=").append(quote(kernCount)).append(xmlClose).append("\n"); buf.append(kernBuf); if (xml) { buf.append("\t</kernings>\n"); buf.append("</font>"); } String charset = info.charset; if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset); }
From source file:darkyenus.resourcepacker.util.FreeTypePacker.java
License:Apache License
public Array<FileHandle> generate(FreeTypeFontParameter parameter, FileHandle outputFolder) { final Array<FileHandle> resultFiles = new Array<>(FileHandle.class); if (!face.setPixelSizes(0, parameter.size)) throw new GdxRuntimeException("Couldn't set size for font"); // set general font data FreeType.SizeMetrics fontMetrics = face.getSize().getMetrics(); final int descender = FreeType.toInt(fontMetrics.getDescender()); final int lineHeight = FreeType.toInt(fontMetrics.getHeight()); final Array<CharacterData> glyphs = new Array<>(); FreeType.Stroker stroker = null;//ww w . j a v a2 s .c o m if (parameter.borderWidth > 0) { stroker = library.createStroker(); stroker.set((int) (parameter.borderWidth * 64f), parameter.borderStraight ? FreeType.FT_STROKER_LINECAP_BUTT : FreeType.FT_STROKER_LINECAP_ROUND, parameter.borderStraight ? FreeType.FT_STROKER_LINEJOIN_MITER_FIXED : FreeType.FT_STROKER_LINEJOIN_ROUND, 0); } if (parameter.codePoints == null) { for (int codePoint = 0; codePoint < 0x10FFFF; codePoint++) { createGlyph(codePoint, parameter, stroker, glyphs); } } else { parameter.codePoints.add(0); parameter.codePoints.add(' '); for (final IntSet.IntSetIterator it = parameter.codePoints.iterator(); it.hasNext;) { createGlyph(it.next(), parameter, stroker, glyphs); } } glyphs.sort(); // Guess needed texture size final int textureSize; { long totalSize2 = 0; for (CharacterData glyph : glyphs) { totalSize2 += glyph.pixmap.getWidth() * glyph.pixmap.getHeight(); } final double waste = 1.2; int totalSize = (int) Math.ceil(Math.sqrt(totalSize2 * waste)); int size = MathUtils.nextPowerOfTwo(totalSize); if (size > 4096) size = 4096; //System.out.println("Will use size: "+size); textureSize = size; } final PixmapPacker packer = new PixmapPacker(textureSize, textureSize, Pixmap.Format.RGBA8888, 1, false, new PixmapPacker.SkylineStrategy()); if (parameter.borderWidth > 0) { packer.setTransparentColor(parameter.borderColor); packer.getTransparentColor().a = 0; } else { packer.setTransparentColor(parameter.color); packer.getTransparentColor().a = 0; } //System.out.println("Generated "+glyphs.size+" glyphs"); for (CharacterData glyph : glyphs) { if (glyph.pixmap.getHeight() != 0 && glyph.pixmap.getWidth() != 0) { glyph.packed = packer.pack(glyph.pixmap); glyph.page = packer.getPages().size - 1; } } final int topToBaseline = lineHeight + descender; final StringBuilder fnt = new StringBuilder(); fnt.append("info face=\"").append(parameter.fontName).append("\" size=").append(parameter.size).append( " bold=0 italic=0 charset=\"\" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=1,1 outline=0"); fnt.append('\n'); fnt.append("common lineHeight=").append(lineHeight).append(" base=").append(topToBaseline) .append(" scaleW=").append(packer.getPageWidth()).append(" scaleH=").append(packer.getPageHeight()) .append(" pages=").append(packer.getPages().size) .append(" packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4"); fnt.append('\n'); { int pageNo = 0; final boolean addPageNumbers = packer.getPages().size > 1; for (PixmapPacker.Page page : packer.getPages()) { final FileHandle file = outputFolder .child(parameter.fontName + (addPageNumbers ? "_" + pageNo : "") + ".png"); resultFiles.add(file); PixmapIO.writePNG(file, page.getPixmap()); fnt.append("page id=").append(pageNo).append(" file=\"").append(file.name()).append("\""); fnt.append('\n'); pageNo++; } } for (CharacterData glyph : glyphs) { fnt.append("char"); fnt.append(" id=").append(glyph.codePoint); if (glyph.packed == null) { fnt.append(" x=0 y=0 width=0 height=0"); } else { fnt.append(" x=").append(MathUtils.round(glyph.packed.x)); fnt.append(" y=").append(MathUtils.round(glyph.packed.y)); fnt.append(" width=").append(MathUtils.round(glyph.packed.width)); fnt.append(" height=").append(MathUtils.round(glyph.packed.height)); } fnt.append(" xoffset=").append(glyph.offsetX); fnt.append(" yoffset=").append(topToBaseline - glyph.offsetY); fnt.append(" xadvance=").append(glyph.advanceX); fnt.append(" page=").append(glyph.page); fnt.append(" chnl=15"); fnt.append('\n'); } // Generate kerning. if (parameter.kerning) { fnt.append("kernings \n");//No count, not needed if (face.hasKerning()) { final int glyphsSize = glyphs.size; for (int i = 0; i < glyphsSize; i++) { final CharacterData first = glyphs.get(i); for (int ii = i; ii < glyphsSize; ii++) { final CharacterData second = glyphs.get(ii); int kerning = FreeType.toInt(face.getKerning(first.glyphIndex, second.glyphIndex, 0)); if (kerning != 0) { fnt.append("kerning first=").append(first.codePoint).append(" second=") .append(second.codePoint).append(" amount=").append(kerning).append('\n'); } kerning = FreeType.toInt(face.getKerning(second.glyphIndex, first.glyphIndex, 0)); if (kerning != 0) { fnt.append("kerning first=").append(second.codePoint).append(" second=") .append(first.codePoint).append(" amount=").append(kerning).append('\n'); } } } } else { //Try other means //First create mapping glyph -> char final IntIntMap glyphToCodePoint = new IntIntMap(); for (CharacterData glyph : glyphs) { glyphToCodePoint.put(glyph.glyphIndex, glyph.codePoint); } try { Kerning kerning = new Kerning(); kerning.load(fontFile.read(), parameter.size); final int pairCount = kerning.resultAmount.size; final int[] first = kerning.resultFirst.items; final int[] second = kerning.resultSecond.items; final int[] amount = kerning.resultAmount.items; for (int i = 0; i < pairCount; i++) { final int firstChar = glyphToCodePoint.get(first[i], -1); final int secondChar = glyphToCodePoint.get(second[i], -1); if (firstChar == -1 || secondChar == -1) { continue; } fnt.append("kerning first=").append(firstChar).append(" second=").append(secondChar) .append(" amount=").append(amount[i]).append('\n'); } } catch (Exception e) { throw new GdxRuntimeException("Failed to load kerning from advanced format", e); } } } final FileHandle fntFile = outputFolder.child(parameter.fontName + ".fnt"); fntFile.writeString(fnt.toString(), false, "UTF-8"); resultFiles.add(fntFile); if (stroker != null) stroker.dispose(); return resultFiles; }
From source file:es.eucm.ead.buildtools.GenerateFieldClasses.java
License:Open Source License
private static void writeClass(Files files, String classCode, String targetPackageName, String targetClassName, String targetDirectory) { FileHandle destDir = new FileHandle( files.internal(targetDirectory + targetPackageName.replaceAll("\\.", "/") + "/").file()); destDir.mkdirs();/*w w w . jav a 2 s.com*/ FileHandle destFile = destDir.child(targetClassName + ".java"); if (destFile.exists()) { destFile.delete(); } destFile.writeString(classCode, false, "UTF-8"); }
From source file:io.piotrjastrzebski.gdxuitest.BitmapFontWriter.java
License:Apache License
/** Writes the given BitmapFontData to a file, using the specified <tt>pageRefs</tt> strings as the image paths for each * texture page. The glyphs in BitmapFontData have a "page" id, which references the index of the pageRef you specify here. * * The FontInfo parameter is useful for cleaner output; such as including a size and font face name hint. However, it can be * null to use default values. LibGDX ignores most of the "info" line when reading back fonts, only padding is used. Padding * also affects the size, location, and offset of the glyphs that are output. * * Likewise, the scaleW and scaleH are only for cleaner output. They are currently ignored by LibGDX's reader. For maximum * compatibility with other BMFont tools, you should use the width and height of your texture pages (each page should be the * same size)./*w w w .j a v a 2s. com*/ * * @param fontData the bitmap font * @param pageRefs the references to each texture page image file, generally in the same folder as outFntFile * @param outFntFile the font file to save to (typically ends with '.fnt') * @param info the optional info for the file header; can be null * @param scaleW the width of your texture pages * @param scaleH the height of your texture pages */ public static void writeFont(BitmapFontData fontData, String[] pageRefs, FileHandle outFntFile, FontInfo info, int scaleW, int scaleH) { if (info == null) { info = new FontInfo(); info.face = outFntFile.nameWithoutExtension(); } int lineHeight = (int) fontData.lineHeight; int pages = pageRefs.length; int packed = 0; int base = (int) ((fontData.capHeight) + (fontData.flipped ? -fontData.ascent : fontData.ascent)); OutputFormat fmt = BitmapFontWriter.getOutputFormat(); boolean xml = fmt == OutputFormat.XML; StringBuilder buf = new StringBuilder(); if (xml) { buf.append("<font>\n"); } String xmlOpen = xml ? "\t<" : ""; String xmlCloseSelf = xml ? "/>" : ""; String xmlTab = xml ? "\t" : ""; String xmlClose = xml ? ">" : ""; String xmlQuote = xml ? "\"" : ""; String alphaChnlParams = xml ? " alphaChnl=\"0\" redChnl=\"0\" greenChnl=\"0\" blueChnl=\"0\"" : " alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0"; // INFO LINE buf.append(xmlOpen).append("info face=\"").append(info.face == null ? "" : info.face.replaceAll("\"", "'")) .append("\" size=").append(quote(info.size)).append(" bold=").append(quote(info.bold ? 1 : 0)) .append(" italic=").append(quote(info.italic ? 1 : 0)).append(" charset=\"") .append(info.charset == null ? "" : info.charset).append("\" unicode=") .append(quote(info.unicode ? 1 : 0)).append(" stretchH=").append(quote(info.stretchH)) .append(" smooth=").append(quote(info.smooth ? 1 : 0)).append(" aa=").append(quote(info.aa)) .append(" padding=").append(xmlQuote).append(info.padding.up).append(",").append(info.padding.right) .append(",").append(info.padding.down).append(",").append(info.padding.left).append(xmlQuote) .append(" spacing=").append(xmlQuote).append(info.spacing.horizontal).append(",") .append(info.spacing.vertical).append(xmlQuote).append(xmlCloseSelf).append("\n"); // COMMON line buf.append(xmlOpen).append("common lineHeight=").append(quote(lineHeight)).append(" base=") .append(quote(base)).append(" scaleW=").append(quote(scaleW)).append(" scaleH=") .append(quote(scaleH)).append(" pages=").append(quote(pages)).append(" packed=") .append(quote(packed)).append(alphaChnlParams).append(xmlCloseSelf).append("\n"); if (xml) buf.append("\t<pages>\n"); // PAGES for (int i = 0; i < pageRefs.length; i++) { buf.append(xmlTab).append(xmlOpen).append("page id=").append(quote(i)).append(" file=\"") .append(pageRefs[i]).append("\"").append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</pages>\n"); // CHARS Array<Glyph> glyphs = new Array<Glyph>(256); for (int i = 0; i < fontData.glyphs.length; i++) { if (fontData.glyphs[i] == null) continue; for (int j = 0; j < fontData.glyphs[i].length; j++) { if (fontData.glyphs[i][j] != null) { glyphs.add(fontData.glyphs[i][j]); } } } buf.append(xmlOpen).append("chars count=").append(quote(glyphs.size)).append(xmlClose).append("\n"); int padLeft = 0, padRight = 0, padTop = 0, padX = 0, padY = 0; if (info != null) { padTop = info.padding.up; padLeft = info.padding.left; padRight = info.padding.right; padX = padLeft + padRight; padY = info.padding.up + info.padding.down; } // CHAR definitions for (int i = 0; i < glyphs.size; i++) { Glyph g = glyphs.get(i); boolean empty = g.width == 0 || g.height == 0; buf.append(xmlTab).append(xmlOpen).append("char id=").append(quote(String.format("%-6s", g.id), true)) .append("x=").append(quote(String.format("%-5s", empty ? 0 : g.srcX - padLeft), true)) .append("y=").append(quote(String.format("%-5s", empty ? 0 : g.srcY - padRight), true)) .append("width=").append(quote(String.format("%-5s", empty ? 0 : g.width + padX), true)) .append("height=").append(quote(String.format("%-5s", empty ? 0 : g.height + padY), true)) .append("xoffset=").append(quote(String.format("%-5s", g.xoffset - padLeft), true)) .append("yoffset=") .append(quote( String.format("%-5s", fontData.flipped ? g.yoffset + padTop : -(g.height + (g.yoffset + padTop))), true)) .append("xadvance=").append(quote(String.format("%-5s", g.xadvance), true)).append("page=") .append(quote(String.format("%-5s", g.page), true)).append("chnl=").append(quote(0, true)) .append(xmlCloseSelf).append("\n"); } if (xml) buf.append("\t</chars>\n"); // KERNINGS int kernCount = 0; StringBuilder kernBuf = new StringBuilder(); for (int i = 0; i < glyphs.size; i++) { for (int j = 0; j < glyphs.size; j++) { Glyph first = glyphs.get(i); Glyph second = glyphs.get(j); int kern = first.getKerning((char) second.id); if (kern != 0) { kernCount++; kernBuf.append(xmlTab).append(xmlOpen).append("kerning first=").append(quote(first.id)) .append(" second=").append(quote(second.id)).append(" amount=") .append(quote(kern, true)).append(xmlCloseSelf).append("\n"); } } } // KERN info buf.append(xmlOpen).append("kernings count=").append(quote(kernCount)).append(xmlClose).append("\n"); buf.append(kernBuf); if (xml) { buf.append("\t</kernings>\n"); buf.append("</font>"); } String charset = info.charset; if (charset != null && charset.length() == 0) charset = null; outFntFile.writeString(buf.toString(), false, charset); }
From source file:sink.core.Sink.java
License:Apache License
public static void save() { Sink.log("Saving"); StringBuilder sb = new StringBuilder(); sb.append("{class:SceneJson,"); sb.append("background:\"" + sceneBackground + "\","); sb.append("music:\"" + sceneMusic + "\","); sb.append("transition:\"" + sceneTransition + "\","); sb.append("duration:" + sceneDuration + ","); for (int i = 0; i < interpolationsValue.length; i++) { if (sceneInterpolation.equals(interpolationsValue[i])) { sb.append("interpolation:" + Interpolations.values()[i].toString() + "}"); break; }// ww w. ja va 2 s. c om } sb.append("\n"); for (Actor actor : getChildren()) { if (actor.getName() != null) { sb.append(json.toJson(actor)); sb.append("\n"); } } FileHandle fh = Gdx.files.local(Asset.basePath + "scene/" + currentSceneName + ".json"); if (fh.exists()) fh.writeString(sb.toString(), false, "UTF-8"); Sink.log("Saved"); }