@Override protected Json getJsonLoader(FileHandle skinFile) { Json json = super.getJsonLoader(skinFile); Serializer<BitmapFont> defaultSerializer = json .getSerializer(BitmapFont.class); json.setSerializer(BitmapFont.class, new TTFBitmapFontSerializer(this, assets, defaultSerializer, skinFile)); return json; }
private TTFBitmapFontSerializer(ExtendedSkin skin, Assets assets, Serializer<BitmapFont> defaultSerializer, FileHandle skinFile) { this.defaultSerializer = defaultSerializer; this.skinFile = skinFile; this.assets = assets; this.skin = skin; }
protected Json getJsonLoader (final FileHandle skinFile) { Json loader = super.getJsonLoader(skinFile); final Serializer<BitmapFont> originialSerializer = loader.getSerializer(BitmapFont.class); loader.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() { @SuppressWarnings("rawtypes") public BitmapFont read (Json json, JsonValue jsonData, Class type) { String path = json.readValue("file", String.class, jsonData); FileHandle fontFile = skinFile.parent().child(path); if (!fontFile.exists()) { fontFile = Gdx.files.internal(path); } if (!fontFile.exists()) { throw new SerializationException("Font file not found: " + fontFile); } boolean isTrueType = "ttf".equals(fontFile.extension()); if (isTrueType) { Boolean markupEnabled = json.readValue("markupEnabled", Boolean.class, false, jsonData); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = json.readValue("size", int.class, -1, jsonData); parameter.borderWidth = json.readValue("borderWidth", int.class, 0, jsonData); parameter.color= json.readValue("color", Color.class, Color.WHITE, jsonData); parameter.borderColor= json.readValue("borderColor", Color.class, Color.BLACK, jsonData); parameter.borderStraight = json.readValue("borderStraight", boolean.class, false, jsonData); parameter.shadowOffsetX = json.readValue("shadowOffsetX", int.class, 0, jsonData); parameter.shadowOffsetY = json.readValue("shadowOffsetY", int.class, 0, jsonData); parameter.shadowColor = json.readValue("shadowColor", Color.class, new Color(0, 0, 0, 0.75f), jsonData); parameter.flip = json.readValue("flip", Boolean.class, false, jsonData); parameter.packer = getPacker(); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile); BitmapFont font = generator.generateFont(parameter); generator.dispose(); font.getData().markupEnabled = markupEnabled; return font; } else { return originialSerializer.read(json, jsonData, type); } } }); return loader; }