allow to copy advance values from system font to swf font

This commit is contained in:
2014-12-19 19:45:47 +01:00
parent 4333972e31
commit 20b4160024
9 changed files with 388 additions and 315 deletions
@@ -433,6 +433,26 @@ public class DefineFont2Tag extends FontTag {
setModified(true);
}
@Override
public void setAdvanceValues(Font font) {
boolean hasLayout = fontFlagsHasLayout;
fontFlagsHasLayout = true;
fontAdvanceTable = new ArrayList<>();
if (!hasLayout) {
fontBoundsTable = new ArrayList<>();
fontKerningTable = new ArrayList<>();
}
for (Integer character : codeTable) {
char ch = (char) (int) character;
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), ch);
fontBoundsTable.add(shp.getBounds());
int fontStyle = getFontStyle();
Font fnt = new Font(font.getFontName(), fontStyle, 1024); // Not multiplied with divider as it causes problems to create font with height around 20k
fontAdvanceTable.add((int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, ch)));
}
}
@Override
public String getCharacters(List<Tag> tags) {
StringBuilder ret = new StringBuilder();
@@ -420,7 +420,7 @@ public class DefineFont3Tag extends FontTag {
}
if (fontFlagsHasLayout) {
Font fnt = new Font(fontName, fontStyle, 1024); //Not multiplied with divider as it causes problems to create font with height around 20k
Font fnt = new Font(fontName, fontStyle, 1024); // Not multiplied with divider as it causes problems to create font with height around 20k
if (!exists) {
fontBoundsTable.add(pos, shp.getBounds());
fontAdvanceTable.add(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character)));
@@ -436,6 +436,26 @@ public class DefineFont3Tag extends FontTag {
setModified(true);
}
@Override
public void setAdvanceValues(Font font) {
boolean hasLayout = fontFlagsHasLayout;
fontFlagsHasLayout = true;
fontAdvanceTable = new ArrayList<>();
if (!hasLayout) {
fontBoundsTable = new ArrayList<>();
fontKerningTable = new ArrayList<>();
}
for (Integer character : codeTable) {
char ch = (char) (int) character;
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), ch);
fontBoundsTable.add(shp.getBounds());
int fontStyle = getFontStyle();
Font fnt = new Font(font.getFontName(), fontStyle, 1024); // Not multiplied with divider as it causes problems to create font with height around 20k
fontAdvanceTable.add((int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, ch)));
}
}
@Override
public String getCharacters(List<Tag> tags) {
StringBuilder ret = new StringBuilder();
@@ -321,6 +321,11 @@ public class DefineFontTag extends FontTag {
setModified(true);
}
@Override
public void setAdvanceValues(Font font) {
throw new UnsupportedOperationException("Setting the advance values for DefineFontTag is not supported.");
}
@Override
public String getCharacters(List<Tag> tags) {
StringBuilder ret = new StringBuilder();
@@ -67,6 +67,8 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
public abstract void addCharacter(char character, Font font);
public abstract void setAdvanceValues(Font font);
public abstract char glyphToChar(int glyphIndex);
public abstract int charToGlyph(char c);
@@ -195,6 +195,11 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag {
getSwf().clearImageCache();
}
@Override
public void setAdvanceValues(Font font) {
throw new UnsupportedOperationException("Setting the advance values for DefineCompactedFont is not supported.");
}
@Override
public char glyphToChar(int glyphIndex) {
return (char) fonts.get(0).glyphInfo.get(glyphIndex).glyphCode;