gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src_libs/com/badlogic/gdx/tools/hiero/unicodefont/HieroSettings.java
| a62d533 | 1 | /******************************************************************************* |
| a62d533 | 2 | * Copyright 2011 See AUTHORS file. |
| a62d533 | 3 | * |
| a62d533 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| a62d533 | 5 | * you may not use this file except in compliance with the License. |
| a62d533 | 6 | * You may obtain a copy of the License at |
| a62d533 | 7 | * |
| a62d533 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| a62d533 | 9 | * |
| a62d533 | 10 | * Unless required by applicable law or agreed to in writing, software |
| a62d533 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| a62d533 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| a62d533 | 13 | * See the License for the specific language governing permissions and |
| a62d533 | 14 | * limitations under the License. |
| a62d533 | 15 | ******************************************************************************/ |
| a62d533 | 16 | |
| a62d533 | 17 | package com.badlogic.gdx.tools.hiero.unicodefont; |
| a62d533 | 18 | |
| a62d533 | 19 | import java.io.BufferedReader; |
| a62d533 | 20 | import java.io.File; |
| a62d533 | 21 | import java.io.FileOutputStream; |
| a62d533 | 22 | import java.io.IOException; |
| a62d533 | 23 | import java.io.InputStreamReader; |
| a62d533 | 24 | import java.io.PrintStream; |
| a62d533 | 25 | import java.util.ArrayList; |
| a62d533 | 26 | import java.util.Iterator; |
| a62d533 | 27 | import java.util.List; |
| a62d533 | 28 | |
| a62d533 | 29 | import com.badlogic.gdx.Gdx; |
| a62d533 | 30 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect; |
| a62d533 | 31 | import com.badlogic.gdx.tools.hiero.unicodefont.effects.ConfigurableEffect.Value; |
| a62d533 | 32 | import com.badlogic.gdx.utils.GdxRuntimeException; |
| a62d533 | 33 | |
| a62d533 | 34 | /** Holds the settings needed to configure a UnicodeFont. |
| a62d533 | 35 | * @author Nathan Sweet */ |
| a62d533 | 36 | public class HieroSettings {
|
| a62d533 | 37 | private String fontName = "Arial"; |
| a62d533 | 38 | private int fontSize = 12; |
| a62d533 | 39 | private boolean bold = false, italic = false; |
| a62d533 | 40 | private int paddingTop, paddingLeft, paddingBottom, paddingRight, paddingAdvanceX, paddingAdvanceY; |
| a62d533 | 41 | private int glyphPageWidth = 512, glyphPageHeight = 512; |
| a62d533 | 42 | private String glyphText = ""; |
| a62d533 | 43 | private final List effects = new ArrayList(); |
| a62d533 | 44 | private boolean nativeRendering; |
| a62d533 | 45 | |
| a62d533 | 46 | public HieroSettings () {
|
| a62d533 | 47 | } |
| a62d533 | 48 | |
| a62d533 | 49 | /** @param hieroFileRef The file system or classpath location of the Hiero settings file. */ |
| a62d533 | 50 | public HieroSettings (String hieroFileRef) {
|
| a62d533 | 51 | try {
|
| a62d533 | 52 | BufferedReader reader = new BufferedReader(new InputStreamReader(Gdx.files.absolute(hieroFileRef).read())); |
| a62d533 | 53 | while (true) {
|
| a62d533 | 54 | String line = reader.readLine(); |
| a62d533 | 55 | if (line == null) break; |
| a62d533 | 56 | line = line.trim(); |
| a62d533 | 57 | if (line.length() == 0) continue; |
| a62d533 | 58 | String[] pieces = line.split("=", 2);
|
| a62d533 | 59 | String name = pieces[0].trim(); |
| a62d533 | 60 | String value = pieces[1]; |
| a62d533 | 61 | if (name.equals("font.name")) {
|
| a62d533 | 62 | fontName = value; |
| a62d533 | 63 | } else if (name.equals("font.size")) {
|
| a62d533 | 64 | fontSize = Integer.parseInt(value); |
| a62d533 | 65 | } else if (name.equals("font.bold")) {
|
| a62d533 | 66 | bold = Boolean.parseBoolean(value); |
| a62d533 | 67 | } else if (name.equals("font.italic")) {
|
| a62d533 | 68 | italic = Boolean.parseBoolean(value); |
| a62d533 | 69 | } else if (name.equals("pad.top")) {
|
| a62d533 | 70 | paddingTop = Integer.parseInt(value); |
| a62d533 | 71 | } else if (name.equals("pad.right")) {
|
| a62d533 | 72 | paddingRight = Integer.parseInt(value); |
| a62d533 | 73 | } else if (name.equals("pad.bottom")) {
|
| a62d533 | 74 | paddingBottom = Integer.parseInt(value); |
| a62d533 | 75 | } else if (name.equals("pad.left")) {
|
| a62d533 | 76 | paddingLeft = Integer.parseInt(value); |
| a62d533 | 77 | } else if (name.equals("pad.advance.x")) {
|
| a62d533 | 78 | paddingAdvanceX = Integer.parseInt(value); |
| a62d533 | 79 | } else if (name.equals("pad.advance.y")) {
|
| a62d533 | 80 | paddingAdvanceY = Integer.parseInt(value); |
| a62d533 | 81 | } else if (name.equals("glyph.page.width")) {
|
| a62d533 | 82 | glyphPageWidth = Integer.parseInt(value); |
| a62d533 | 83 | } else if (name.equals("glyph.page.height")) {
|
| a62d533 | 84 | glyphPageHeight = Integer.parseInt(value); |
| a62d533 | 85 | } else if (name.equals("glyph.native.rendering")) {
|
| a62d533 | 86 | nativeRendering = Boolean.parseBoolean(value); |
| a62d533 | 87 | } else if (name.equals("glyph.text")) {
|
| a62d533 | 88 | glyphText = value; |
| a62d533 | 89 | } else if (name.equals("effect.class")) {
|
| a62d533 | 90 | try {
|
| a62d533 | 91 | effects.add(Class.forName(value).newInstance()); |
| a62d533 | 92 | } catch (Throwable ex) {
|
| a62d533 | 93 | throw new GdxRuntimeException("Unable to create effect instance: " + value, ex);
|
| a62d533 | 94 | } |
| a62d533 | 95 | } else if (name.startsWith("effect.")) {
|
| a62d533 | 96 | // Set an effect value on the last added effect. |
| a62d533 | 97 | name = name.substring(7); |
| a62d533 | 98 | ConfigurableEffect effect = (ConfigurableEffect)effects.get(effects.size() - 1); |
| a62d533 | 99 | List values = effect.getValues(); |
| a62d533 | 100 | for (Iterator iter = values.iterator(); iter.hasNext();) {
|
| a62d533 | 101 | Value effectValue = (Value)iter.next(); |
| a62d533 | 102 | if (effectValue.getName().equals(name)) {
|
| a62d533 | 103 | effectValue.setString(value); |
| a62d533 | 104 | break; |
| a62d533 | 105 | } |
| a62d533 | 106 | } |
| a62d533 | 107 | effect.setValues(values); |
| a62d533 | 108 | } |
| a62d533 | 109 | } |
| a62d533 | 110 | reader.close(); |
| a62d533 | 111 | } catch (Throwable ex) {
|
| a62d533 | 112 | throw new GdxRuntimeException("Unable to load Hiero font file: " + hieroFileRef, ex);
|
| a62d533 | 113 | } |
| a62d533 | 114 | } |
| a62d533 | 115 | |
| a62d533 | 116 | /** @see UnicodeFont#getPaddingTop() */ |
| a62d533 | 117 | public int getPaddingTop () {
|
| a62d533 | 118 | return paddingTop; |
| a62d533 | 119 | } |
| a62d533 | 120 | |
| a62d533 | 121 | /** @see UnicodeFont#setPaddingTop(int) */ |
| a62d533 | 122 | public void setPaddingTop (int paddingTop) {
|
| a62d533 | 123 | this.paddingTop = paddingTop; |
| a62d533 | 124 | } |
| a62d533 | 125 | |
| a62d533 | 126 | /** @see UnicodeFont#getPaddingLeft() */ |
| a62d533 | 127 | public int getPaddingLeft () {
|
| a62d533 | 128 | return paddingLeft; |
| a62d533 | 129 | } |
| a62d533 | 130 | |
| a62d533 | 131 | /** @see UnicodeFont#setPaddingLeft(int) */ |
| a62d533 | 132 | public void setPaddingLeft (int paddingLeft) {
|
| a62d533 | 133 | this.paddingLeft = paddingLeft; |
| a62d533 | 134 | } |
| a62d533 | 135 | |
| a62d533 | 136 | /** @see UnicodeFont#getPaddingBottom() */ |
| a62d533 | 137 | public int getPaddingBottom () {
|
| a62d533 | 138 | return paddingBottom; |
| a62d533 | 139 | } |
| a62d533 | 140 | |
| a62d533 | 141 | /** @see UnicodeFont#setPaddingBottom(int) */ |
| a62d533 | 142 | public void setPaddingBottom (int paddingBottom) {
|
| a62d533 | 143 | this.paddingBottom = paddingBottom; |
| a62d533 | 144 | } |
| a62d533 | 145 | |
| a62d533 | 146 | /** @see UnicodeFont#getPaddingRight() */ |
| a62d533 | 147 | public int getPaddingRight () {
|
| a62d533 | 148 | return paddingRight; |
| a62d533 | 149 | } |
| a62d533 | 150 | |
| a62d533 | 151 | /** @see UnicodeFont#setPaddingRight(int) */ |
| a62d533 | 152 | public void setPaddingRight (int paddingRight) {
|
| a62d533 | 153 | this.paddingRight = paddingRight; |
| a62d533 | 154 | } |
| a62d533 | 155 | |
| a62d533 | 156 | /** @see UnicodeFont#getPaddingAdvanceX() */ |
| a62d533 | 157 | public int getPaddingAdvanceX () {
|
| a62d533 | 158 | return paddingAdvanceX; |
| a62d533 | 159 | } |
| a62d533 | 160 | |
| a62d533 | 161 | /** @see UnicodeFont#setPaddingAdvanceX(int) */ |
| a62d533 | 162 | public void setPaddingAdvanceX (int paddingAdvanceX) {
|
| a62d533 | 163 | this.paddingAdvanceX = paddingAdvanceX; |
| a62d533 | 164 | } |
| a62d533 | 165 | |
| a62d533 | 166 | /** @see UnicodeFont#getPaddingAdvanceY() */ |
| a62d533 | 167 | public int getPaddingAdvanceY () {
|
| a62d533 | 168 | return paddingAdvanceY; |
| a62d533 | 169 | } |
| a62d533 | 170 | |
| a62d533 | 171 | /** @see UnicodeFont#setPaddingAdvanceY(int) */ |
| a62d533 | 172 | public void setPaddingAdvanceY (int paddingAdvanceY) {
|
| a62d533 | 173 | this.paddingAdvanceY = paddingAdvanceY; |
| a62d533 | 174 | } |
| a62d533 | 175 | |
| a62d533 | 176 | /** @see UnicodeFont#getGlyphPageWidth() */ |
| a62d533 | 177 | public int getGlyphPageWidth () {
|
| a62d533 | 178 | return glyphPageWidth; |
| a62d533 | 179 | } |
| a62d533 | 180 | |
| a62d533 | 181 | /** @see UnicodeFont#setGlyphPageWidth(int) */ |
| a62d533 | 182 | public void setGlyphPageWidth (int glyphPageWidth) {
|
| a62d533 | 183 | this.glyphPageWidth = glyphPageWidth; |
| a62d533 | 184 | } |
| a62d533 | 185 | |
| a62d533 | 186 | /** @see UnicodeFont#getGlyphPageHeight() */ |
| a62d533 | 187 | public int getGlyphPageHeight () {
|
| a62d533 | 188 | return glyphPageHeight; |
| a62d533 | 189 | } |
| a62d533 | 190 | |
| a62d533 | 191 | /** @see UnicodeFont#setGlyphPageHeight(int) */ |
| a62d533 | 192 | public void setGlyphPageHeight (int glyphPageHeight) {
|
| a62d533 | 193 | this.glyphPageHeight = glyphPageHeight; |
| a62d533 | 194 | } |
| a62d533 | 195 | |
| a62d533 | 196 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 197 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 198 | public String getFontName() {
|
| a62d533 | 199 | return fontName; |
| a62d533 | 200 | } |
| a62d533 | 201 | |
| a62d533 | 202 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 203 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 204 | public void setFontName(String fontName) {
|
| a62d533 | 205 | this.fontName = fontName; |
| a62d533 | 206 | } |
| a62d533 | 207 | |
| a62d533 | 208 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 209 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 210 | public int getFontSize () {
|
| a62d533 | 211 | return fontSize; |
| a62d533 | 212 | } |
| a62d533 | 213 | |
| a62d533 | 214 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 215 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 216 | public void setFontSize (int fontSize) {
|
| a62d533 | 217 | this.fontSize = fontSize; |
| a62d533 | 218 | } |
| a62d533 | 219 | |
| a62d533 | 220 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 221 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 222 | public boolean isBold () {
|
| a62d533 | 223 | return bold; |
| a62d533 | 224 | } |
| a62d533 | 225 | |
| a62d533 | 226 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 227 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 228 | public void setBold (boolean bold) {
|
| a62d533 | 229 | this.bold = bold; |
| a62d533 | 230 | } |
| a62d533 | 231 | |
| a62d533 | 232 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 233 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 234 | public boolean isItalic () {
|
| a62d533 | 235 | return italic; |
| a62d533 | 236 | } |
| a62d533 | 237 | |
| a62d533 | 238 | /** @see UnicodeFont#UnicodeFont(String, int, boolean, boolean) |
| a62d533 | 239 | * @see UnicodeFont#UnicodeFont(java.awt.Font, int, boolean, boolean) */ |
| a62d533 | 240 | public void setItalic (boolean italic) {
|
| a62d533 | 241 | this.italic = italic; |
| a62d533 | 242 | } |
| a62d533 | 243 | |
| a62d533 | 244 | /** @see UnicodeFont#getEffects() */ |
| a62d533 | 245 | public List getEffects () {
|
| a62d533 | 246 | return effects; |
| a62d533 | 247 | } |
| a62d533 | 248 | |
| a62d533 | 249 | public boolean getNativeRendering () {
|
| a62d533 | 250 | return nativeRendering; |
| a62d533 | 251 | } |
| a62d533 | 252 | |
| a62d533 | 253 | public void setNativeRendering (boolean nativeRendering) {
|
| a62d533 | 254 | this.nativeRendering = nativeRendering; |
| a62d533 | 255 | } |
| a62d533 | 256 | |
| a62d533 | 257 | public String getGlyphText () {
|
| a62d533 | 258 | return this.glyphText.replace("\\n", "\n");
|
| a62d533 | 259 | } |
| a62d533 | 260 | |
| a62d533 | 261 | public void setGlyphText (String text) {
|
| a62d533 | 262 | this.glyphText = text.replace("\n", "\\n");
|
| a62d533 | 263 | } |
| a62d533 | 264 | |
| a62d533 | 265 | /** Saves the settings to a file. |
| a62d533 | 266 | * @throws IOException if the file could not be saved. */ |
| a62d533 | 267 | public void save (File file) throws IOException {
|
| a62d533 | 268 | PrintStream out = new PrintStream(new FileOutputStream(file)); |
| a62d533 | 269 | out.println("font.name=" + fontName);
|
| a62d533 | 270 | out.println("font.size=" + fontSize);
|
| a62d533 | 271 | out.println("font.bold=" + bold);
|
| a62d533 | 272 | out.println("font.italic=" + italic);
|
| a62d533 | 273 | out.println(); |
| a62d533 | 274 | out.println("pad.top=" + paddingTop);
|
| a62d533 | 275 | out.println("pad.right=" + paddingRight);
|
| a62d533 | 276 | out.println("pad.bottom=" + paddingBottom);
|
| a62d533 | 277 | out.println("pad.left=" + paddingLeft);
|
| a62d533 | 278 | out.println("pad.advance.x=" + paddingAdvanceX);
|
| a62d533 | 279 | out.println("pad.advance.y=" + paddingAdvanceY);
|
| a62d533 | 280 | out.println(); |
| a62d533 | 281 | out.println("glyph.native.rendering=" + nativeRendering);
|
| a62d533 | 282 | out.println("glyph.page.width=" + glyphPageWidth);
|
| a62d533 | 283 | out.println("glyph.page.height=" + glyphPageHeight);
|
| a62d533 | 284 | out.println("glyph.text=" + glyphText);
|
| a62d533 | 285 | out.println(); |
| a62d533 | 286 | for (Iterator iter = effects.iterator(); iter.hasNext();) {
|
| a62d533 | 287 | ConfigurableEffect effect = (ConfigurableEffect)iter.next(); |
| a62d533 | 288 | out.println("effect.class=" + effect.getClass().getName());
|
| a62d533 | 289 | for (Iterator iter2 = effect.getValues().iterator(); iter2.hasNext();) {
|
| a62d533 | 290 | Value value = (Value)iter2.next(); |
| a62d533 | 291 | out.println("effect." + value.getName() + "=" + value.getString());
|
| a62d533 | 292 | } |
| a62d533 | 293 | out.println(); |
| a62d533 | 294 | } |
| a62d533 | 295 | out.close(); |
| a62d533 | 296 | } |
| a62d533 | 297 | } |