Fixed #2116 DefineEditText display - correct getting fonts

Fixed #2116 DefineEditText display - apostroph decoding
This commit is contained in:
Jindra Petřík
2023-11-06 23:19:12 +01:00
parent 27a9809255
commit d5dab2bb60
3 changed files with 18 additions and 10 deletions

View File

@@ -851,13 +851,14 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
return null;
}
public FontTag getFontByNameInTag(String fontName) {
public FontTag getFontByNameInTag(String fontName, boolean bold, boolean italic) {
if (fontName == null) {
return null;
}
for (Tag t : getTags()) {
if (t instanceof FontTag) {
if (fontName.equals(((FontTag) t).getFontNameIntag())) {
FontTag ft = (FontTag) t;
if (fontName.equals(ft.getFontNameIntag()) && ft.isBold() == bold && ft.isItalic() == italic) {
return (FontTag) t;
}
}

View File

@@ -415,7 +415,7 @@ public class DefineEditTextTag extends TextTag {
case "b":
style = style.clone();
style.bold = true;
styles.add(style);
styles.add(style);
break;
case "i":
style = style.clone();
@@ -454,12 +454,7 @@ public class DefineEditTextTag extends TextTag {
String face = unescape(attributes.getValue("face"));
if (face != null && face.length() > 0) {
style.fontFace = face;
FontTag insideFont = swf.getFontByNameInTag(face);
style.font = insideFont;
if (insideFont != null) {
style.fontFace = null;
}
style.fontFace = face;
}
String letterspacing = unescape(attributes.getValue("letterSpacing"));
@@ -512,6 +507,7 @@ public class DefineEditTextTag extends TextTag {
txt = txt.replace("/{entity-gt}", ">");
txt = txt.replace("/{entity-quot}", "\"");
txt = txt.replace("/{entity-amp}", "&");
txt = txt.replace("/{entity-apos}", "'");
return txt;
}
@@ -519,6 +515,12 @@ public class DefineEditTextTag extends TextTag {
public void characters(char[] ch, int start, int length) throws SAXException {
String txt = unescape(new String(ch, start, length));
TextStyle style = styles.peek();
if (style.fontFace != null) {
style.font = swf.getFontByNameInTag(style.fontFace, style.bold, style.italic);
if (style.font == null) {
style.fontFace = null;
}
}
addCharacters(ret, txt, style);
}
};
@@ -528,6 +530,7 @@ public class DefineEditTextTag extends TextTag {
str = str.replace(">", "/{entity-gt}");
str = str.replace(""", "/{entity-quot}");
str = str.replace("&", "/{entity-amp}");
str = str.replace("'", "/{entity-apos}");
str = str.replace("&", "&");
str = "<!DOCTYPE html [\n"
@@ -1096,7 +1099,7 @@ public class DefineEditTextTag extends TextTag {
ge.glyphAdvance = ge.glyphIndex == -1 ? (int) Math.round(SWF.unitDivisor * FontTag.getSystemFontAdvance(fontName, fontStyle, (int) (lastStyle.fontHeight / SWF.unitDivisor), c, lastStyle.kerning ? nextChar : null))
: (int) Math.round(font.getGlyphAdvance(ge.glyphIndex) / font.getDivider() * lastStyle.fontHeight / 1024);
ge.glyphAdvance += lastStyle.letterSpacing * SWF.unitDivisor;
if (lastStyle.kerning) {
if (lastStyle.kerning && font != null && font.hasLayout()) {
if (nextChar != null) {
ge.glyphAdvance += font.getCharKerningAdjustment(c, nextChar) / font.getDivider();
}