Issue #389 Selecting font face while characters import

Issue #701 Importing from TTF file
Improved Font panel / Font embed dialog
Reloading installed fonts for other than windows systems
Removed xito Table Layout, using Oracle Table Layout instead
This commit is contained in:
Jindra Petřík
2014-10-25 20:58:32 +02:00
parent 1985ccb594
commit 8fd683d019
25 changed files with 665 additions and 4835 deletions
@@ -12,34 +12,84 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.flash.helpers;
import com.sun.jna.Platform;
import com.jpexs.decompiler.flash.AppResources;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class FontHelper {
/**
* Gets all available fonts in the system
* @return Map<FamilyName,Map<FontNAme,Font>>
*/
public static Map<String,Map<String,Font>> getInstalledFonts(){
Map<String,Map<String,Font>> ret = new HashMap<>();
Font fonts[] = null;
try {
Class<?> clFmFactory = Class.forName("sun.font.FontManagerFactory");
Object fm = clFmFactory.getDeclaredMethod("getInstance").invoke(null);
Class<?> clFm = Class.forName("sun.font.SunFontManager");
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()) {
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);
}
//Delete cached installed names
Field inField = clFm.getDeclaredField("installedNames");
inField.setAccessible(true);
inField.set(null, null);
//Delete cached family names
Field allFamField = clFm.getDeclaredField("allFamilies");
allFamField.setAccessible(true);
allFamField.set(fm,null);
//Delete cached fonts
Field allFonField = clFm.getDeclaredField("allFonts");
allFonField.setAccessible(true);
allFonField.set(fm, null);
fonts = (Font[]) clFm.getDeclaredMethod("getAllInstalledFonts").invoke(fm);
} catch (Throwable ex) {
//ignore
}
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
if(fonts == null){
fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
for(Font f:fonts){
String fam = f.getFamily(Locale.getDefault());
//Do not want Java logical fonts
if(Arrays.asList("Dialog","DialogInput","Monospaced","Serif","SansSerif").contains(fam)){
continue;
}
if(!ret.containsKey(fam)){
ret.put(fam, new HashMap<String, Font>());
}
String face = getFontFace(f);
ret.get(f.getFamily()).put(face, f);
}
return ret;
}
public static String getFontFace(Font f){
String fam = f.getFamily(Locale.getDefault());
String face = f.getFontName(Locale.getDefault());
if(face.startsWith(fam)){
face = face.substring(fam.length()).trim();
}
if(face.startsWith(".")){
face = face.substring(1);
}
return face;
}
}