mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 19:00:47 +00:00
Issue #390 Reload list of fonts to import
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String> fontNames = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
|
||||
|
||||
public boolean handle(FontTag font, List<Tag> 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);
|
||||
|
||||
@@ -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<String> availableFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
|
||||
|
||||
List<SHAPE> 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());
|
||||
|
||||
@@ -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<String> 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<SHAPERECORD> 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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user