mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-04 15:14:49 +00:00
small refactorings
This commit is contained in:
@@ -85,6 +85,7 @@ import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.BMPFile;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
|
||||
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
@@ -197,10 +198,8 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.FileImageOutputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import net.kroo.elliot.GifSequenceWriter;
|
||||
import org.monte.media.VideoFormatKeys;
|
||||
import org.monte.media.avi.AVIWriter;
|
||||
@@ -1280,13 +1279,10 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
imageData = Helper.readStream(image.getImageData());
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(image.getImage().getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
ImageHelper.write(image.getImage().getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
imageData = baos.toByteArray();
|
||||
}
|
||||
String base64ImgData = DatatypeConverter.printBase64Binary(imageData);
|
||||
String base64ImgData = Helper.byteArrayToBase64String(imageData);
|
||||
fos.write(Utf8Helper.getBytes("var imageObj" + c + " = document.createElement(\"img\");\r\nimageObj" + c + ".src=\"data:image/" + format + ";base64," + base64ImgData + "\";\r\n"));
|
||||
}
|
||||
fos.write(Utf8Helper.getBytes("function " + getTypePrefix(ch) + c + "(ctx,ctrans,frame,ratio,time){\r\n"));
|
||||
@@ -1534,7 +1530,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
File f = new File(foutdir + File.separator + (fframes.get(fi) + 1) + ".png");
|
||||
ImageIO.write(frameImages.next(), "PNG", f);
|
||||
ImageHelper.write(frameImages.next(), "PNG", new FileOutputStream(f));
|
||||
ret.add(f);
|
||||
}
|
||||
}, handler).run();
|
||||
|
||||
@@ -97,7 +97,7 @@ import java.util.logging.Logger;
|
||||
public class Action implements GraphSourceItem {
|
||||
|
||||
private static final int INFORM_LISTENER_RESOLUTION = 100;
|
||||
|
||||
|
||||
private boolean ignored = false;
|
||||
/**
|
||||
* Action type identifier
|
||||
|
||||
@@ -19,10 +19,7 @@ package com.jpexs.decompiler.flash.configuration;
|
||||
import com.jpexs.decompiler.flash.ApplicationInfo;
|
||||
import com.jpexs.decompiler.flash.helpers.CodeFormatting;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.utf8.Utf8InputStreamReader;
|
||||
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -30,7 +27,6 @@ import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.AccessController;
|
||||
|
||||
@@ -22,15 +22,16 @@ import com.jpexs.decompiler.flash.RunnableIOEx;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ImageExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.settings.ImageExportSettings;
|
||||
import com.jpexs.decompiler.flash.helpers.BMPFile;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -77,7 +78,7 @@ public class ImageExporter {
|
||||
if (ffileFormat.equals("bmp")) {
|
||||
BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file);
|
||||
} else {
|
||||
ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file);
|
||||
ImageHelper.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), new FileOutputStream(file));
|
||||
}
|
||||
}
|
||||
}, handler).run();
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.BMPFile;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
|
||||
@@ -45,7 +46,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -114,7 +114,7 @@ public class ShapeExporter {
|
||||
m.scale(settings.zoom);
|
||||
st.toImage(0, 0, 0, null, 0, img, m, new CXFORMWITHALPHA());
|
||||
if (settings.mode == ShapeExportMode.PNG) {
|
||||
ImageIO.write(img.getBufferedImage(), "PNG", new FileOutputStream(file));
|
||||
ImageHelper.write(img.getBufferedImage(), "PNG", new FileOutputStream(file));
|
||||
} else {
|
||||
BMPFile.saveBitmap(img.getBufferedImage(), file);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* 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.exporters.commonshape;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
@@ -32,7 +33,6 @@ import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Logger;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -213,7 +213,7 @@ public class SVGExporter {
|
||||
public void addStyle(String fontFace, byte[] data, FontExportMode mode) {
|
||||
if (!fontFaces.contains(fontFace)) {
|
||||
fontFaces.add(fontFace);
|
||||
fontFaces.add(fontFace);
|
||||
String base64Data = Helper.byteArrayToBase64String(data);
|
||||
String value = getStyle().getTextContent();
|
||||
value += Helper.newLine;
|
||||
value += " @font-face {" + Helper.newLine;
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.exporters.morphshape;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
@@ -33,11 +34,8 @@ import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -130,13 +128,10 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
|
||||
imageData = Helper.readStream(image.getImageData());
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img.getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
ImageHelper.write(img.getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
imageData = baos.toByteArray();
|
||||
}
|
||||
String base64ImgData = DatatypeConverter.printBase64Binary(imageData);
|
||||
String base64ImgData = Helper.byteArrayToBase64String(imageData);
|
||||
path.setAttribute("style", "fill:url(#" + patternId + ")");
|
||||
Element pattern = exporter.createElement("pattern");
|
||||
pattern.setAttribute("id", patternId);
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.exporters.shape;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
@@ -33,11 +34,8 @@ import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -128,13 +126,10 @@ public class SVGShapeExporter extends DefaultSVGShapeExporter {
|
||||
imageData = Helper.readStream(image.getImageData());
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img.getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
ImageHelper.write(img.getBufferedImage(), format.toUpperCase(Locale.ENGLISH), baos);
|
||||
imageData = baos.toByteArray();
|
||||
}
|
||||
String base64ImgData = DatatypeConverter.printBase64Binary(imageData);
|
||||
String base64ImgData = Helper.byteArrayToBase64String(imageData);
|
||||
path.setAttribute("style", "fill:url(#" + patternId + ")");
|
||||
Element pattern = exporter.createElement("pattern");
|
||||
pattern.setAttribute("id", patternId);
|
||||
|
||||
@@ -118,14 +118,14 @@ public class FontHelper {
|
||||
withKerningAttrs.put(TextAttribute.FONT, font);
|
||||
withKerningAttrs.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
|
||||
Font withKerningFont = Font.getFont(withKerningAttrs);
|
||||
GlyphVector withKerningVector = withKerningFont.layoutGlyphVector((new JPanel()).getFontMetrics(withKerningFont).getFontRenderContext(), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
GlyphVector withKerningVector = withKerningFont.layoutGlyphVector(getFontRenderContext(withKerningFont), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
int withKerningX = withKerningVector.getGlyphLogicalBounds(1).getBounds().x;
|
||||
|
||||
Map<AttributedCharacterIterator.Attribute, Object> noKerningAttrs = new HashMap<>();
|
||||
noKerningAttrs.put(TextAttribute.FONT, font);
|
||||
noKerningAttrs.put(TextAttribute.KERNING, 0);
|
||||
Font noKerningFont = Font.getFont(noKerningAttrs);
|
||||
GlyphVector noKerningVector = noKerningFont.layoutGlyphVector((new JPanel()).getFontMetrics(noKerningFont).getFontRenderContext(), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
GlyphVector noKerningVector = noKerningFont.layoutGlyphVector(getFontRenderContext(noKerningFont), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
int noKerningX = noKerningVector.getGlyphLogicalBounds(1).getBounds().x;
|
||||
return withKerningX - noKerningX;
|
||||
}
|
||||
@@ -162,6 +162,18 @@ public class FontHelper {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static float getFontAdvance(Font font, char ch) {
|
||||
return createGlyphVector(font, ch).getGlyphMetrics(0).getAdvanceX();
|
||||
}
|
||||
|
||||
public static GlyphVector createGlyphVector(Font font, char ch) {
|
||||
return font.createGlyphVector(getFontRenderContext(font), new char[]{ch});
|
||||
}
|
||||
|
||||
private static FontRenderContext getFontRenderContext(Font font) {
|
||||
return (new JPanel()).getFontMetrics(font).getFontRenderContext();
|
||||
}
|
||||
|
||||
private static List<KerningPair> getFontKerningPairsOneChar(List<Character> availableChars, Font font, char firstChar) {
|
||||
List<KerningPair> ret = new ArrayList<>();
|
||||
|
||||
@@ -177,7 +189,7 @@ public class FontHelper {
|
||||
withKerningAttrs.put(TextAttribute.FONT, font);
|
||||
withKerningAttrs.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
|
||||
Font withKerningFont = Font.getFont(withKerningAttrs);
|
||||
GlyphVector withKerningVector = withKerningFont.layoutGlyphVector((new JPanel()).getFontMetrics(withKerningFont).getFontRenderContext(), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
GlyphVector withKerningVector = withKerningFont.layoutGlyphVector(getFontRenderContext(withKerningFont), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
int withKerningX[] = new int[availableChars.size()];
|
||||
for (int i = 0; i < availableChars.size(); i++) {
|
||||
withKerningX[i] = withKerningVector.getGlyphLogicalBounds(i * 2 + 1).getBounds().x;
|
||||
@@ -187,7 +199,7 @@ public class FontHelper {
|
||||
noKerningAttrs.put(TextAttribute.FONT, font);
|
||||
noKerningAttrs.put(TextAttribute.KERNING, 0);
|
||||
Font noKerningFont = Font.getFont(noKerningAttrs);
|
||||
GlyphVector noKerningVector = noKerningFont.layoutGlyphVector((new JPanel()).getFontMetrics(noKerningFont).getFontRenderContext(), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
GlyphVector noKerningVector = noKerningFont.layoutGlyphVector(getFontRenderContext(noKerningFont), chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
|
||||
for (int i = 0; i < availableChars.size(); i++) {
|
||||
int noKerningX = noKerningVector.getGlyphLogicalBounds(i * 2 + 1).getBounds().x;
|
||||
int kerning = withKerningX[i] - noKerningX;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ImageHelper {
|
||||
|
||||
public static BufferedImage read(InputStream input) throws IOException {
|
||||
return ImageIO.read(input);
|
||||
}
|
||||
|
||||
public static void write(BufferedImage image, String formatName, OutputStream output) throws IOException {
|
||||
ImageIO.write(image, formatName, output);
|
||||
}
|
||||
|
||||
public static void write(BufferedImage image, String formatName, ByteArrayOutputStream output) {
|
||||
try {
|
||||
ImageIO.write(image, formatName, output);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ImageHelper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.jpexs.decompiler.flash.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
@@ -25,7 +26,6 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -36,9 +36,9 @@ public class ImageImporter extends TagImporter {
|
||||
public Tag importImage(ImageTag it, byte[] newData) throws IOException {
|
||||
|
||||
if (newData[0] == 'B' && newData[1] == 'M') {
|
||||
BufferedImage b = ImageIO.read(new ByteArrayInputStream(newData));
|
||||
BufferedImage b = ImageHelper.read(new ByteArrayInputStream(newData));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(b, "PNG", baos);
|
||||
ImageHelper.write(b, "PNG", baos);
|
||||
newData = baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.jpexs.decompiler.flash.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape3Tag;
|
||||
@@ -31,7 +32,6 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -43,9 +43,9 @@ public class ShapeImporter {
|
||||
SWF swf = st.getSwf();
|
||||
|
||||
if (newData[0] == 'B' && newData[1] == 'M') {
|
||||
BufferedImage b = ImageIO.read(new ByteArrayInputStream(newData));
|
||||
BufferedImage b = ImageHelper.read(new ByteArrayInputStream(newData));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(b, "PNG", baos);
|
||||
ImageHelper.write(b, "PNG", baos);
|
||||
newData = baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.AloneTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -31,7 +32,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(getImageData());
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage ret = image == null ? null : new SerializableImage(image);
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.AloneTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -31,7 +32,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
if (ImageTag.getImageFormat(data).equals("jpg")) {
|
||||
SerializableImage image = new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
byte[] ba = new byte[image.getWidth() * image.getHeight()];
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) 255;
|
||||
@@ -94,7 +94,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
} else {
|
||||
stream = new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
}
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
BufferedImage image = ImageHelper.read(stream);
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
return img;
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.AloneTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
@@ -31,7 +32,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -96,7 +96,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength()));
|
||||
BufferedImage image = ImageHelper.read(new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength()));
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
return img;
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.AloneTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.ALPHABITMAPDATA;
|
||||
@@ -39,7 +40,6 @@ import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@@ -92,7 +92,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA();
|
||||
bitmapFormat = FORMAT_32BIT_ARGB;
|
||||
bitmapWidth = image.getWidth();
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.AloneTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BITMAPDATA;
|
||||
@@ -41,7 +42,6 @@ import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)));
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
bitmapFormat = FORMAT_24BIT_RGB;
|
||||
bitmapWidth = image.getWidth();
|
||||
bitmapHeight = image.getHeight();
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
@@ -29,7 +30,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
} else {
|
||||
baos.write(jpegData.getArray(), jpegData.getPos(), jpegData.getLength());
|
||||
}
|
||||
SerializableImage ret = new SerializableImage(ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
SerializableImage ret = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.helpers.FontHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.FontTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.KERNINGRECORD;
|
||||
@@ -36,7 +37,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -420,10 +420,10 @@ public class DefineFont2Tag extends FontTag {
|
||||
Font fnt = new Font(fontName, fontStyle, 1024);
|
||||
if (!exists) {
|
||||
fontBoundsTable.add(pos, shp.getBounds());
|
||||
fontAdvanceTable.add(pos, (int) getDivider() * Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX()));
|
||||
fontAdvanceTable.add(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character)));
|
||||
} else {
|
||||
fontBoundsTable.set(pos, shp.getBounds());
|
||||
fontAdvanceTable.set(pos, (int) getDivider() * Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX()));
|
||||
fontAdvanceTable.set(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character)));
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.abc.CopyOutputStream;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.helpers.FontHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.FontTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.KERNINGRECORD;
|
||||
@@ -40,7 +41,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class DefineFont3Tag extends FontTag {
|
||||
|
||||
@@ -423,10 +423,10 @@ public class DefineFont3Tag extends FontTag {
|
||||
Font fnt = new Font(fontName, fontStyle, 1024); //Not multiplied with divider as it causes problems to create font with height around 20k
|
||||
if (!exists) {
|
||||
fontBoundsTable.add(pos, shp.getBounds());
|
||||
fontAdvanceTable.add(pos, (int) getDivider() * Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX()));
|
||||
fontAdvanceTable.add(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character)));
|
||||
} else {
|
||||
fontBoundsTable.set(pos, shp.getBounds());
|
||||
fontAdvanceTable.set(pos, (int) getDivider() * Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX()));
|
||||
fontAdvanceTable.set(pos, (int) getDivider() * Math.round(FontHelper.getFontAdvance(fnt, character)));
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
|
||||
@@ -360,9 +360,9 @@ public class DefineText2Tag extends TextTag {
|
||||
txtSb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
txt = txtSb.toString();
|
||||
|
||||
|
||||
TEXTRECORD tr = new TEXTRECORD();
|
||||
textRecords.add(tr);
|
||||
if (fontId > -1) {
|
||||
|
||||
@@ -366,7 +366,7 @@ public class DefineTextTag extends TextTag {
|
||||
txtSb.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
txt = txtSb.toString();
|
||||
|
||||
TEXTRECORD tr = new TEXTRECORD();
|
||||
|
||||
@@ -197,11 +197,11 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
|
||||
if (tr.styleFlagsHasFont) {
|
||||
curFontId = tr.fontId;
|
||||
}
|
||||
|
||||
|
||||
if (curFontId != fontId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (GLYPHENTRY en : tr.glyphEntries) {
|
||||
if (en == null) { //Currently edited
|
||||
continue;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MissingCharacterHandler {
|
||||
public boolean getIgnoreMissingCharacters() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean handle(TextTag textTag, FontTag font, char character) {
|
||||
String fontName = font.getFontNameIntag();
|
||||
if (!FontTag.installedFontsByFamily.containsKey(fontName)) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags.gfx;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.helpers.FontHelper;
|
||||
import com.jpexs.decompiler.flash.tags.DefineFont2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.DrawableTag;
|
||||
@@ -45,7 +46,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -180,7 +180,7 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag {
|
||||
}
|
||||
|
||||
Font fnt = cfont.deriveFont(fontStyle, Math.round(font.nominalSize * d));
|
||||
int advance = (int) Math.round(fnt.createGlyphVector((new JPanel()).getFontMetrics(fnt).getFontRenderContext(), "" + character).getGlyphMetrics(0).getAdvanceX());
|
||||
int advance = (int) Math.round(FontHelper.getFontAdvance(fnt, character));
|
||||
if (!exists) {
|
||||
font.glyphInfo.add(pos, new GlyphInfoType(code, advance, 0));
|
||||
font.glyphs.add(pos, new GlyphType(shp.shapeRecords));
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.FontHelper;
|
||||
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
@@ -41,7 +42,6 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -243,7 +243,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
|
||||
}
|
||||
List<SHAPERECORD> retList = new ArrayList<>();
|
||||
Font f = font.deriveFont(fontSize);
|
||||
GlyphVector v = f.createGlyphVector((new JPanel()).getFontMetrics(f).getFontRenderContext(), "" + character);
|
||||
GlyphVector v = FontHelper.createGlyphVector(f, character);
|
||||
Shape shp = v.getOutline();
|
||||
double[] points = new double[6];
|
||||
int lastX = 0;
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import com.jpexs.decompiler.flash.tags.CSMTextSettingsTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineButtonCxformTag;
|
||||
@@ -124,7 +125,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Source;
|
||||
@@ -1354,11 +1354,7 @@ public class XFLConverter {
|
||||
// do not store the image in cache during xfl conversion
|
||||
imageTag.clearCache();
|
||||
String format = imageTag.getImageFormat();
|
||||
try {
|
||||
ImageIO.write(image.getBufferedImage(), format.toUpperCase(), baos);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
ImageHelper.write(image.getBufferedImage(), format.toUpperCase(), baos);
|
||||
String symbolFile = "bitmap" + symbol.getCharacterId() + "." + imageTag.getImageFormat();
|
||||
files.put(symbolFile, baos.toByteArray());
|
||||
String mediaLinkStr = "<DOMBitmapItem name=\"" + symbolFile + "\" sourceLastImported=\"" + getTimestamp() + "\" externalFileSize=\"" + baos.toByteArray().length + "\"";
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
/**
|
||||
* Class with helper method
|
||||
@@ -797,7 +798,7 @@ public class Helper {
|
||||
public static String getDecompilationSkippedComment() {
|
||||
return "// " + AppResources.translate("decompilation.skipped");
|
||||
}
|
||||
|
||||
|
||||
public static void appendTimeoutComment(GraphTextWriter writer, int timeout) {
|
||||
writer.appendNoHilight("/*").newLine();
|
||||
writer.appendNoHilight(" * ").appendNoHilight(AppResources.translate("decompilationError")).newLine();
|
||||
@@ -863,6 +864,10 @@ public class Helper {
|
||||
return area;
|
||||
}
|
||||
|
||||
public static String byteArrayToBase64String(byte[] data) {
|
||||
return DatatypeConverter.printBase64Binary(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats double value (removes .0 from end)
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.ImageHelper;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
@@ -30,7 +31,6 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Hashtable;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -144,13 +144,13 @@ public class SerializableImage implements Serializable {
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
try {
|
||||
ImageIO.write(image, "png", out);
|
||||
ImageHelper.write(image, "png", out);
|
||||
} catch (Exception ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
image = ImageIO.read(in);
|
||||
image = ImageHelper.read(in);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user