diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java b/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java index 880959147..3959ef6c4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java @@ -16,7 +16,11 @@ */ package com.jpexs.decompiler.flash.helpers; +import com.sun.jna.Platform; import java.awt.GraphicsEnvironment; +import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -26,7 +30,7 @@ public class FontHelper { public static String[] getInstalledFontFamilyNames() { // todo: cannot load newly installed fonts, so this feature is disabled until i find a solution for font loading problem - /*if (Platform.isWindows()) { + if (Platform.isWindows()) { try { Class clW32Fm = Class.forName("sun.awt.Win32FontManager"); Class clSunFm = Class.forName("sun.font.SunFontManager"); @@ -36,7 +40,7 @@ public class FontHelper { // catch everything to avoid class not found problems, because Win32FontManager is an internal proprietary API Logger.getLogger(FontHelper.class.getName()).log(Level.SEVERE, null, ex); } - }*/ + } return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java index 39ba5ce65..42cd86238 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -190,6 +190,20 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable } } + public static String getFontNameWithFallback(String fontName) { + if (fontNames.contains(fontName)) { + return fontName; + } + if (fontNames.contains("Times New Roman")) { + return "Times New Roman"; + } + if (fontNames.contains("Arial")) { + return "Arial"; + } + //Fallback to DIALOG + return "Dialog"; + } + public static String isFontInstalled(String fontName) { if (fontNames.contains(fontName)) { return fontName; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java index 6f877237e..d15da9d10 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java @@ -18,8 +18,6 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.tags.Tag; import java.awt.Font; -import java.awt.GraphicsEnvironment; -import java.util.Arrays; import java.util.List; /** @@ -28,11 +26,9 @@ import java.util.List; */ public class MissingCharacterHandler { - protected static List fontNames = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); - public boolean handle(FontTag font, List tags, char character) { String fontName = font.getFontName(tags); - if (!fontNames.contains(fontName)) { + if (!FontTag.fontNames.contains(fontName)) { return false; } Font f = new Font(fontName, font.getFontStyle(), 18); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 53afc1858..30bb6d0c8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -29,13 +29,11 @@ import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; import java.awt.RenderingHints; import java.awt.font.LineMetrics; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -95,8 +93,6 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { double descent = 0; double lineDistance = 0; - List availableFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); - List glyphs = new ArrayList<>(); boolean firstLine = true; double top = 0; @@ -121,13 +117,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { glyphs = font.getGlyphShapeTable(); if (!font.hasLayout()) { - String fontName = font.getFontName(tags); - if (!availableFonts.contains(fontName)) { - fontName = "Times New Roman"; - } - if (!availableFonts.contains(fontName)) { - fontName = "Arial"; - } + String fontName = FontTag.getFontNameWithFallback(font.getFontName(tags)); aFont = new Font(fontName, font.getFontStyle(), textHeight / 20); fontMetrics = bi.getGraphics().getFontMetrics(aFont); LineMetrics lm = fontMetrics.getLineMetrics("A", bi.getGraphics()); diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java index 19ba5a0dd..f768709b4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; import com.jpexs.decompiler.flash.types.FILLSTYLE; @@ -39,7 +40,6 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; import java.awt.LinearGradientPaint; import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.Point; @@ -59,7 +59,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -938,7 +937,6 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali } return ret; } - private static List existingFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); public static SHAPE systemFontCharacterToSHAPE(final String fontName, final int fontStyle, int fontSize, char character) { int multiplier = 1; @@ -947,21 +945,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali fontSize = 1024; } List retList = new ArrayList<>(); - String[] defaultFonts = new String[]{"Times New Roman", "Arial"}; - Font f = null; - if (existingFonts.contains(fontName)) { - f = new Font(fontName, fontStyle, fontSize); - } else { - for (String defName : defaultFonts) { - if (existingFonts.contains(defName)) { - f = new Font(defName, fontStyle, fontSize); - break; - } - } - } - if (f == null) { - f = new Font("Dialog", fontStyle, fontSize); //Fallback to DIALOG - } + Font f = new Font(FontTag.getFontNameWithFallback(fontName), fontStyle, fontSize); GlyphVector v = f.createGlyphVector((new JPanel()).getFontMetrics(f).getFontRenderContext(), "" + character); Shape shp = v.getOutline(); double[] points = new double[6]; diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 455edb7bd..182994e27 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -93,7 +93,6 @@ import com.jpexs.decompiler.flash.types.sound.MP3FRAME; import com.jpexs.decompiler.graph.ExportMode; import com.jpexs.helpers.utf8.Utf8Helper; import java.awt.Font; -import java.awt.GraphicsEnvironment; import java.awt.Point; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -2254,7 +2253,6 @@ public class XFLConverter { FontTag font = null; String fontName = null; String psFontName = null; - String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); int textHeight = -1; RGB textColor = null; RGBA textColorA = null;