code format, organize imports

This commit is contained in:
Jindra Petřík
2014-10-25 21:32:16 +02:00
parent 8fd683d019
commit bcfb4a1c01
17 changed files with 86 additions and 119 deletions

View File

@@ -1047,8 +1047,8 @@ public final class SWF implements TreeItem, Timelined {
for (int r = ret.size() - 1; r >= 0; r--) {
TreeNode node = ret.get(r);
TreeItem item = node.getItem();
if (!(item instanceof DefineSpriteTag
TreeItem item = node.getItem();
if (!(item instanceof DefineSpriteTag
|| item instanceof DefineButtonTag
|| item instanceof DefineButton2Tag
|| item instanceof DoInitActionTag
@@ -1080,7 +1080,7 @@ public final class SWF implements TreeItem, Timelined {
if (path == null) {
path = "";
}
String[] pathParts = path.contains(".") ? path.split("\\.") : new String[]{ path };
String[] pathParts = path.contains(".") ? path.split("\\.") : new String[]{path};
List<TreeNode> items = ret;
for (int pos = 0; pos < pathParts.length - 1; pos++) {
String pathPart = pathParts[pos];
@@ -1139,7 +1139,7 @@ public final class SWF implements TreeItem, Timelined {
ret.addAll(frames);
for (int i = ret.size() - 1; i >= 0; i--) {
TreeNode node = ret.get(i);
TreeItem item = node.getItem();
TreeItem item = node.getItem();
if (item instanceof ASMSource) {
ASMSource ass = (ASMSource) item;
if (ass.containsSource()) {

View File

@@ -400,11 +400,11 @@ public class SWFOutputStream extends OutputStream {
nBits = enlargeBitCountS(nBits, xMax);
nBits = enlargeBitCountS(nBits, yMin);
nBits = enlargeBitCountS(nBits, yMax);
if (Configuration.debugCopy.get()) {
nBits = Math.max(nBits, value.nbits);
}
writeUB(5, nBits);
writeSB(nBits, xMin);
writeSB(nBits, xMax);
@@ -569,7 +569,7 @@ public class SWFOutputStream extends OutputStream {
if (Configuration.debugCopy.get()) {
nBits = Math.max(nBits, value.nScaleBits);
}
writeUB(5, nBits);
writeSB(nBits, value.scaleX);
writeSB(nBits, value.scaleY);
@@ -583,7 +583,7 @@ public class SWFOutputStream extends OutputStream {
if (Configuration.debugCopy.get()) {
nBits = Math.max(nBits, value.nRotateBits);
}
writeUB(5, nBits);
writeSB(nBits, value.rotateSkew0);
writeSB(nBits, value.rotateSkew1);
@@ -624,11 +624,11 @@ public class SWFOutputStream extends OutputStream {
Nbits = enlargeBitCountS(Nbits, value.greenAddTerm);
Nbits = enlargeBitCountS(Nbits, value.blueAddTerm);
}
if (Configuration.debugCopy.get()) {
Nbits = Math.max(Nbits, value.nbits);
}
writeUB(4, Nbits);
if (value.hasMultTerms) {
writeSB(Nbits, value.redMultTerm);
@@ -669,7 +669,7 @@ public class SWFOutputStream extends OutputStream {
if (Configuration.debugCopy.get()) {
Nbits = Math.max(Nbits, value.nbits);
}
writeUB(4, Nbits);
if (value.hasMultTerms) {
writeSB(Nbits, value.redMultTerm);

View File

@@ -467,7 +467,7 @@ public class Configuration {
}
return result;
}
public static Map<String, String> getFontIdToFaceMap() {
String fonts = fontPairing.get();
if (fonts == null) {
@@ -478,7 +478,7 @@ public class Configuration {
for (String pair : fonts.split("::")) {
if (!pair.isEmpty()) {
String[] splittedPair = pair.split("=");
result.put(splittedPair[0], splittedPair.length<3?"":splittedPair[2]);
result.put(splittedPair[0], splittedPair.length < 3 ? "" : splittedPair[2]);
}
}
return result;
@@ -489,8 +489,8 @@ public class Configuration {
Map<String, String> fontPairs = getFontIdToFamilyMap();
fontPairs.put(key, installedFontFamily);
fontPairs.put(fontName, installedFontFamily);
Map<String,String> facePairs = getFontIdToFaceMap();
Map<String, String> facePairs = getFontIdToFaceMap();
facePairs.put(key, installedFontFace);
facePairs.put(fontName, installedFontFace);
StringBuilder sb = new StringBuilder();
@@ -499,7 +499,7 @@ public class Configuration {
if (i != 0) {
sb.append("::");
}
sb.append(pair.getKey()).append("=").append(pair.getValue()).append("=").append(facePairs.containsKey(pair.getKey())?facePairs.get(pair.getKey()):"");
sb.append(pair.getKey()).append("=").append(pair.getValue()).append("=").append(facePairs.containsKey(pair.getKey()) ? facePairs.get(pair.getKey()) : "");
i++;
}
fontPairing.set(sb.toString());

View File

@@ -24,7 +24,6 @@ import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.RetryTask;
import com.jpexs.decompiler.flash.RunnableIOEx;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.exporters.modes.FontExportMode;
import com.jpexs.decompiler.flash.exporters.settings.FontExportSettings;
import com.jpexs.decompiler.flash.exporters.shape.PathExporter;
@@ -114,7 +113,7 @@ public class FontExporter {
List<SHAPE> shapes = t.getGlyphShapeTable();
final double divider = t.getDivider();
File ttfFile = file;
if (mode == FontExportMode.WOFF) {
@@ -126,8 +125,8 @@ public class FontExporter {
f.getEngine().setCopyrightYear(cop == null ? "" : cop);
f.setAuthor(ApplicationInfo.shortApplicationVerName);
f.setVersion("1.0");
f.setVersion("1.0");
f.setAscender(Math.round(t.getAscent() / divider));
f.setDescender(Math.round(t.getDescent() / divider));
@@ -179,13 +178,13 @@ public class FontExporter {
char c = t.glyphToChar(i);
if (contours.isEmpty()) {
continue;
}
}
final FGlyph g = f.addGlyph(c);
double adv = t.getGlyphAdvance(i);
if (adv != -1) {
g.setAdvanceWidth((int) Math.round(adv / divider));
} else {
g.setAdvanceWidth((int)Math.round(t.getGlyphWidth(i) / divider + 100));
g.setAdvanceWidth((int) Math.round(t.getGlyphWidth(i) / divider + 100));
}
for (FPoint[] cnt : contours) {
if (cnt.length == 0) {

View File

@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.AppResources;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Field;
@@ -30,17 +29,18 @@ 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<>();
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");
Class<?> clFmFactory = Class.forName("sun.font.FontManagerFactory");
Object fm = clFmFactory.getDeclaredMethod("getInstance").invoke(null);
Class<?> clFm = Class.forName("sun.font.SunFontManager");
@@ -52,7 +52,7 @@ public class FontHelper {
//Delete cached family names
Field allFamField = clFm.getDeclaredField("allFamilies");
allFamField.setAccessible(true);
allFamField.set(fm,null);
allFamField.set(fm, null);
//Delete cached fonts
Field allFonField = clFm.getDeclaredField("allFonts");
@@ -60,34 +60,34 @@ public class FontHelper {
allFonField.set(fm, null);
fonts = (Font[]) clFm.getDeclaredMethod("getAllInstalledFonts").invoke(fm);
} catch (Throwable ex) {
} catch (Throwable ex) {
//ignore
}
if(fonts == null){
if (fonts == null) {
fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
}
for(Font f:fonts){
}
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)){
if (Arrays.asList("Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif").contains(fam)) {
continue;
}
if(!ret.containsKey(fam)){
if (!ret.containsKey(fam)) {
ret.put(fam, new HashMap<String, Font>());
}
String face = getFontFace(f);
String face = getFontFace(f);
ret.get(f.getFamily()).put(face, f);
}
return ret;
}
public static String getFontFace(Font f){
public static String getFontFace(Font f) {
String fam = f.getFamily(Locale.getDefault());
String face = f.getFontName(Locale.getDefault());
if(face.startsWith(fam)){
if (face.startsWith(fam)) {
face = face.substring(fam.length()).trim();
}
if(face.startsWith(".")){
}
if (face.startsWith(".")) {
face = face.substring(1);
}
return face;

View File

@@ -260,7 +260,7 @@ public class DefineEditTextTag extends TextTag {
char firstChar = size.charAt(0);
if (firstChar != '+' && firstChar != '-') {
int fontSize = Integer.parseInt(size);
style.fontHeight = (int)Math.round(fontSize * (style.font == null ? 1 : style.font.getDivider()));
style.fontHeight = (int) Math.round(fontSize * (style.font == null ? 1 : style.font.getDivider()));
style.fontLeading = leading;
} else {
// todo: parse relative sizes

View File

@@ -102,9 +102,6 @@ public class DefineFont2Tag extends FontTag {
return fontBoundsTable.get(glyphIndex);
}
@Override
public double getGlyphAdvance(int glyphIndex) {
if (fontFlagsHasLayout) {
@@ -380,7 +377,7 @@ public class DefineFont2Tag extends FontTag {
public void addCharacter(char character, Font font) {
int fontStyle = getFontStyle();
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, fontStyle, (int)Math.round(getDivider() * 1024), character);
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, fontStyle, (int) Math.round(getDivider() * 1024), character);
int code = (int) character;
int pos = -1;

View File

@@ -16,7 +16,6 @@
*/
package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.abc.CopyOutputStream;
@@ -377,7 +376,7 @@ public class DefineFont3Tag extends FontTag {
}
}
int fontStyle = getFontStyle();
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, fontStyle, (int)Math.round(getDivider() * 1024), character);
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, fontStyle, (int) Math.round(getDivider() * 1024), character);
int code = (int) character;
int pos = -1;
boolean exists = false;
@@ -438,8 +437,6 @@ public class DefineFont3Tag extends FontTag {
return fontBoundsTable.get(glyphIndex);
}
@Override
public int getGlyphKerningAdjustment(int glyphIndex, int nextGlyphIndex) {
if (glyphIndex == -1 || nextGlyphIndex == -1) {

View File

@@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPE;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
@@ -268,7 +267,7 @@ public class DefineFontTag extends FontTag {
@Override
public void addCharacter(char character, Font font) {
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, getFontStyle(), (int)Math.round(getDivider() * 1024), character);
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, getFontStyle(), (int) Math.round(getDivider() * 1024), character);
List<Integer> codeTable = new ArrayList<>();
ensureFontInfo();
if (fontInfoTag != null) {
@@ -324,5 +323,5 @@ public class DefineFontTag extends FontTag {
public int getGlyphKerningAdjustment(int glyphIndex, int nextGlyphIndex) {
return 0;
}
}

View File

@@ -460,7 +460,7 @@ public class DefineText2Tag extends TextTag {
glyphBits = Math.max(glyphBits, this.glyphBits);
advanceBits = Math.max(advanceBits, this.advanceBits);
}
sos.writeUI8(glyphBits);
sos.writeUI8(advanceBits);
for (TEXTRECORD tr : textRecords) {

View File

@@ -472,7 +472,7 @@ public class DefineTextTag extends TextTag {
glyphBits = Math.max(glyphBits, this.glyphBits);
advanceBits = Math.max(advanceBits, this.advanceBits);
}
sos.writeUI8(glyphBits);
sos.writeUI8(advanceBits);
for (TEXTRECORD tr : textRecords) {

View File

@@ -205,7 +205,6 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource {
return pathParts[pathParts.length - 1];
}
@Override
public GraphTextWriter getActionSourcePrefix(GraphTextWriter writer) {
return writer;

View File

@@ -22,29 +22,18 @@ import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
import com.jpexs.decompiler.flash.helpers.FontHelper;
import com.jpexs.decompiler.flash.tags.DefineFont2Tag;
import com.jpexs.decompiler.flash.tags.DefineFontNameTag;
import com.jpexs.decompiler.flash.tags.DefineText2Tag;
import com.jpexs.decompiler.flash.tags.DefineTextTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.gfx.DefineCompactedFont;
import com.jpexs.decompiler.flash.timeline.DepthState;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
import com.jpexs.decompiler.flash.types.KERNINGRECORD;
import com.jpexs.decompiler.flash.types.LANGCODE;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPE;
import com.jpexs.decompiler.flash.types.TEXTRECORD;
import com.jpexs.decompiler.flash.types.gfx.FontType;
import com.jpexs.decompiler.flash.types.gfx.GlyphInfoType;
import com.jpexs.decompiler.flash.types.gfx.GlyphType;
import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.SerializableImage;
import java.awt.Color;
import java.awt.Font;
@@ -54,15 +43,10 @@ import java.awt.font.FontRenderContext;
import java.awt.font.GlyphMetrics;
import java.awt.font.GlyphVector;
import java.awt.geom.Area;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
@@ -120,7 +104,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
public abstract int getLeading();
public static Map<String,Map<String,Font>> installedFonts;
public static Map<String, Map<String, Font>> installedFonts;
public static String defaultFontName;
@@ -352,15 +336,11 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
sb.append("\t}\r\n");
return sb.toString();
}
public RECT getGlyphBounds(int glyphIndex) {
return getGlyphShapeTable().get(glyphIndex).getBounds();
}
}
public FontTag toClassicFont() {
return this;
}

View File

@@ -70,7 +70,7 @@ public class ContourType implements Serializable {
edges = edgesList.toArray(new EdgeType[edgesList.size()]);
}
public ContourType(GFxInputStream sis,long fontOffset) throws IOException {
public ContourType(GFxInputStream sis, long fontOffset) throws IOException {
moveToX = sis.readSI15("moveToX");
moveToY = sis.readSI15("moveToY");
long numEdgesRef = sis.readUI30("numEdgesRef");
@@ -80,10 +80,10 @@ public class ContourType implements Serializable {
int numEdges;
if (isReference) {
long referencePos = numEdgesRef;
sis.setPos(fontOffset+referencePos);
numEdges = (int)(sis.readUI30("numEdges") >> 1);
}else{
numEdges = (int)numEdgesRef;
sis.setPos(fontOffset + referencePos);
numEdges = (int) (sis.readUI30("numEdges") >> 1);
} else {
numEdges = (int) numEdgesRef;
}
edges = new EdgeType[(int) numEdges];

View File

@@ -74,10 +74,10 @@ public class FontType implements Serializable {
for (int i = 0; i < glyphInfo.size(); i++) {
sis.setPos(glyphInfo.get(i).globalOffset + offset);
sis.newDumpLevel("glyphType", "GlyphType");
glyphs.add(new GlyphType(sis,offset));
glyphs.add(new GlyphType(sis, offset));
sis.endDumpLevel();
}
sis.setPos(pos);
}

View File

@@ -234,9 +234,9 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
}
public static SHAPE systemFontCharacterToSHAPE(final String fontName, final int fontStyle, int fontSize, char character) {
return fontCharacterToSHAPE(new Font(FontTag.getFontNameWithFallback(fontName),Font.PLAIN,10), fontStyle, fontSize, character);
return fontCharacterToSHAPE(new Font(FontTag.getFontNameWithFallback(fontName), Font.PLAIN, 10), fontStyle, fontSize, character);
}
public static SHAPE fontCharacterToSHAPE(final Font font, final int fontStyle, int fontSize, char character) {
int multiplier = 1;
if (fontSize > 1024) {
@@ -244,7 +244,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
fontSize = 1024;
}
List<SHAPERECORD> retList = new ArrayList<>();
Font f = font.deriveFont(fontStyle, fontSize);
Font f = font.deriveFont(fontStyle, fontSize);
GlyphVector v = f.createGlyphVector((new JPanel()).getFontMetrics(f).getFontRenderContext(), "" + character);
Shape shp = v.getOutline();
double[] points = new double[6];