#390 Reload list of fonts to import: using Win32FontManager

This commit is contained in:
Honfika
2013-12-29 09:32:26 +01:00
parent b9ed651893
commit 7459311680
3 changed files with 47 additions and 3 deletions
@@ -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;
@@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
@@ -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";