From 745931168054ce95aae3d2bbe03706b9c836bdd0 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 29 Dec 2013 09:32:26 +0100 Subject: [PATCH] #390 Reload list of fonts to import: using Win32FontManager --- .../jpexs/decompiler/flash/gui/FontPanel.java | 1 - .../decompiler/flash/helpers/FontHelper.java | 45 +++++++++++++++++++ .../decompiler/flash/tags/base/FontTag.java | 4 +- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java index fda4a0257..9fa5b30a7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.tags.DefineTextTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.TextTag; diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java b/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java new file mode 100644 index 000000000..ffb18033e --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/FontHelper.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +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; + +/** + * + * @author JPEXS + */ +public class FontHelper { + + public static String[] getInstalledFontFamilyNames() { + if (Platform.isWindows()) { + try { + Class clW32Fm = Class.forName("sun.awt.Win32FontManager"); + Class clSunFm = Class.forName("sun.font.SunFontManager"); + Object fm = clW32Fm.newInstance(); + return (String[]) clSunFm.getDeclaredMethod("getInstalledFontFamilyNames", Locale.class).invoke(fm, Locale.getDefault()); + } catch (Throwable ex) { + // 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 15de56975..39ba5ce65 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.helpers.FontHelper; import com.jpexs.decompiler.flash.tags.DefineText2Tag; import com.jpexs.decompiler.flash.tags.DefineTextTag; import com.jpexs.decompiler.flash.tags.Tag; @@ -28,7 +29,6 @@ import com.jpexs.decompiler.flash.types.TEXTRECORD; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import java.awt.Color; import java.awt.Font; -import java.awt.GraphicsEnvironment; import java.awt.Point; import java.awt.font.FontRenderContext; import java.awt.font.GlyphMetrics; @@ -179,7 +179,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable } public static void reload() { - fontNamesArray = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); + fontNamesArray = FontHelper.getInstalledFontFamilyNames(); fontNames = Arrays.asList(fontNamesArray); if (fontNames.contains("Times New Roman")) { defaultFontName = "Times New Roman";