From ec4418c987e8b2100ad874c7ad3f248fd470613e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Mon, 23 Sep 2013 20:57:17 +0200 Subject: [PATCH] Issue #395 Fixed adding characters to GFx fonts No to all fix (Adding characters when exists) --- .../jpexs/decompiler/flash/gui/MainFrame.java | 3 ++- .../flash/tags/GFxDefineCompactedFont.java | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 88628a849..acb56b4c8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -2315,7 +2315,8 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel if (opt == 3) { notoall = true; } - } else if (yestoall) { + } + if (yestoall) { opt = 0; //yes } else if (notoall) { opt = 1; //no diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/GFxDefineCompactedFont.java b/trunk/src/com/jpexs/decompiler/flash/tags/GFxDefineCompactedFont.java index 5d34a5b34..eee399835 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/GFxDefineCompactedFont.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/GFxDefineCompactedFont.java @@ -105,7 +105,7 @@ public class GFxDefineCompactedFont extends FontTag implements DrawableTag { * @return Bytes of data */ @Override - public byte[] getData(int version) { + public byte[] getData(int version) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = baos; SWFOutputStream sos = new SWFOutputStream(os, version); @@ -205,8 +205,12 @@ public class GFxDefineCompactedFont extends FontTag implements DrawableTag { int code = (int) character; int pos = -1; + boolean exists = false; for (int i = 0; i < font.glyphInfo.size(); i++) { - if (font.glyphInfo.get(i).glyphCode > code) { + if (font.glyphInfo.get(i).glyphCode >= code) { + if (font.glyphInfo.get(i).glyphCode == code) { + exists = true; + } pos = i; break; } @@ -215,13 +219,21 @@ public class GFxDefineCompactedFont extends FontTag implements DrawableTag { pos = font.glyphInfo.size(); } - FontTag.shiftGlyphIndices(fontId, pos, tags); + if (!exists) { + FontTag.shiftGlyphIndices(fontId, pos, tags); + } Font fnt = new Font(fontName, fontStyle, 20 * font.nominalSize); int advance = (int) Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX()); - font.glyphInfo.add(pos, new GlyphInfoType(code, advance, 0)); - font.glyphs.add(pos, new GlyphType(shp.shapeRecords)); - shapeCache.add(pos, font.glyphs.get(pos).toSHAPE()); + if (!exists) { + font.glyphInfo.add(pos, new GlyphInfoType(code, advance, 0)); + font.glyphs.add(pos, new GlyphType(shp.shapeRecords)); + shapeCache.add(pos, font.glyphs.get(pos).toSHAPE()); + } else { + font.glyphInfo.set(pos, new GlyphInfoType(code, advance, 0)); + font.glyphs.set(pos, new GlyphType(shp.shapeRecords)); + shapeCache.set(pos, font.glyphs.get(pos).toSHAPE()); + } imageCache.remove("font" + fontId); }