title fix

This commit is contained in:
2016-06-07 15:32:10 +02:00
parent a079d3b0ff
commit fc0e941470
5 changed files with 4806 additions and 4807 deletions
@@ -1,164 +1,164 @@
/*
* Copyright (C) 2010-2016 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.dumpview;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.TagStub;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class DumpInfo implements TreeItem {
public String name;
public String type;
public TagStub tagToResolve = null;
public Tag resolvedTag = null;
public Object previewValue;
public long startByte;
public int startBit;
public long lengthBytes;
public int lengthBits;
public DumpInfo parent;
private List<DumpInfo> childInfos;
public DumpInfo(String name, String type, Object value, long startByte, long lengthBytes) {
this.name = name;
this.type = type;
this.previewValue = value;
this.startByte = startByte;
this.lengthBytes = lengthBytes;
}
public DumpInfo(String name, String type, Object value, long startByte, int startBit, long lengthBytes, int lengthBits) {
this.name = name;
this.type = type;
this.previewValue = value;
this.startByte = startByte;
this.lengthBytes = lengthBytes;
this.startBit = startBit;
this.lengthBits = lengthBits;
}
public int getChildCount() {
return childInfos == null ? 0 : childInfos.size();
}
public List<DumpInfo> getChildInfos() {
if (childInfos == null) {
childInfos = new ArrayList<>();
}
return childInfos;
}
public void sortChildren() {
if (childInfos == null) {
return;
}
Collections.sort(childInfos, new Comparator<DumpInfo>() {
@Override
public int compare(DumpInfo o1, DumpInfo o2) {
int res = Long.compare(o1.startByte, o2.startByte);
if (res != 0) {
return res;
}
return Integer.compare(o1.startBit, o1.startBit);
}
});
}
public long getEndByte() {
int end = (int) startByte;
if (lengthBytes != 0) {
end += lengthBytes;
} else {
int bits = startBit + lengthBits;
end += bits / 8;
if (bits % 8 != 0) {
end++;
}
}
return end - 1;
}
@Override
public String toString() {
String value = previewValue == null ? "" : previewValue.toString();
return name + " (" + type + ")" + (value.isEmpty() ? "" : " = " + value);
}
public void resolveTag() {
if (tagToResolve != null) {
TagStub tagStub = tagToResolve;
try {
SWFInputStream sis = tagStub.getDataStream();
sis.seek(tagStub.getDataPos());
sis.dumpInfo = this;
resolvedTag = SWFInputStream.resolveTag(tagStub, 0, false, true, false);
} catch (InterruptedException | IOException ex) {
Logger.getLogger(DumpInfo.class.getName()).log(Level.SEVERE, null, ex);
}
tagToResolve = null;
}
}
public Tag getTag() {
resolveTag();
return resolvedTag;
}
@Override
public SWF getSwf() {
Tag tag = getTag();
if (tag != null) {
return tag.getSwf();
}
return null;
}
@Override
public boolean isModified() {
return false;
}
}
/*
* Copyright (C) 2010-2016 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.dumpview;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.TagStub;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class DumpInfo implements TreeItem {
public String name;
public String type;
public TagStub tagToResolve = null;
public Tag resolvedTag = null;
public Object previewValue;
public long startByte;
public int startBit;
public long lengthBytes;
public int lengthBits;
public DumpInfo parent;
private List<DumpInfo> childInfos;
public DumpInfo(String name, String type, Object value, long startByte, long lengthBytes) {
this.name = name;
this.type = type;
this.previewValue = value;
this.startByte = startByte;
this.lengthBytes = lengthBytes;
}
public DumpInfo(String name, String type, Object value, long startByte, int startBit, long lengthBytes, int lengthBits) {
this.name = name;
this.type = type;
this.previewValue = value;
this.startByte = startByte;
this.lengthBytes = lengthBytes;
this.startBit = startBit;
this.lengthBits = lengthBits;
}
public int getChildCount() {
return childInfos == null ? 0 : childInfos.size();
}
public List<DumpInfo> getChildInfos() {
if (childInfos == null) {
childInfos = new ArrayList<>();
}
return childInfos;
}
public void sortChildren() {
if (childInfos == null) {
return;
}
Collections.sort(childInfos, new Comparator<DumpInfo>() {
@Override
public int compare(DumpInfo o1, DumpInfo o2) {
int res = Long.compare(o1.startByte, o2.startByte);
if (res != 0) {
return res;
}
return Integer.compare(o1.startBit, o1.startBit);
}
});
}
public long getEndByte() {
int end = (int) startByte;
if (lengthBytes != 0) {
end += lengthBytes;
} else {
int bits = startBit + lengthBits;
end += bits / 8;
if (bits % 8 != 0) {
end++;
}
}
return end - 1;
}
@Override
public String toString() {
String value = previewValue == null ? "" : previewValue.toString();
return name + " (" + type + ")" + (value.isEmpty() ? "" : " = " + value);
}
public void resolveTag() {
if (tagToResolve != null) {
TagStub tagStub = tagToResolve;
try {
SWFInputStream sis = tagStub.getDataStream();
sis.seek(tagStub.getDataPos());
sis.dumpInfo = this;
resolvedTag = SWFInputStream.resolveTag(tagStub, 0, false, true, false);
} catch (InterruptedException | IOException ex) {
Logger.getLogger(DumpInfo.class.getName()).log(Level.SEVERE, null, ex);
}
tagToResolve = null;
}
}
public Tag getTag() {
resolveTag();
return resolvedTag;
}
@Override
public SWF getSwf() {
Tag tag = getTag();
if (tag != null) {
return tag.getSwf();
}
return DumpInfoSwfNode.getSwfNode(this).getSwf();
}
@Override
public boolean isModified() {
return false;
}
}
@@ -1,111 +1,112 @@
/*
* Copyright (C) 2010-2016 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.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.ABC;
import com.jpexs.decompiler.flash.abc.ABCInputStream;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit;
import com.jpexs.decompiler.flash.types.annotations.SWFField;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.helpers.ByteArrayRange;
import java.io.IOException;
/**
* Defines a series of ActionScript 3 bytecodes to be executed
*
* @author JPEXS
*/
@SWFVersion(from = 9)
public class DoABCTag extends Tag implements ABCContainerTag {
public static final int ID = 72;
public static final String NAME = "DoABC";
/**
* ActionScript 3 bytecodes
*/
@HideInRawEdit
@SWFField
private ABC abc;
/**
* Constructor
*
* @param swf
*/
public DoABCTag(SWF swf) {
super(swf, ID, NAME, null);
abc = new ABC(this);
}
/**
* Constructor
*
* @param sis
* @param data
* @throws IOException
*/
public DoABCTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
super(sis.getSwf(), ID, NAME, data);
readData(sis, data, 0, false, false, false);
}
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
ABCInputStream ais = new ABCInputStream(sis.getBaseStream());
// put it to the dumpview:
sis.readByteRangeEx(sis.available(), "abcBytes");
abc = new ABC(ais, swf, this);
}
/**
* Gets data bytes
*
* @param sos SWF output stream
* @throws java.io.IOException
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
abc.saveToStream(sos);
}
@Override
public ABC getABC() {
return abc;
}
@Override
public int compareTo(ABCContainerTag o) {
return 0;
}
@Override
public void setModified(boolean value) {
super.setModified(value);
if (value == false && !isModified()) {
ABC abc = getABC();
for (ScriptInfo si : abc.script_info) {
si.setModified(false);
}
}
}
}
/*
* Copyright (C) 2010-2016 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.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.ABC;
import com.jpexs.decompiler.flash.abc.ABCInputStream;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.types.annotations.HideInRawEdit;
import com.jpexs.decompiler.flash.types.annotations.SWFField;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.helpers.ByteArrayRange;
import java.io.IOException;
/**
* Defines a series of ActionScript 3 bytecodes to be executed
*
* @author JPEXS
*/
@SWFVersion(from = 9)
public class DoABCTag extends Tag implements ABCContainerTag {
public static final int ID = 72;
public static final String NAME = "DoABC";
/**
* ActionScript 3 bytecodes
*/
@HideInRawEdit
@SWFField
private ABC abc;
/**
* Constructor
*
* @param swf
*/
public DoABCTag(SWF swf) {
super(swf, ID, NAME, null);
abc = new ABC(this);
}
/**
* Constructor
*
* @param sis
* @param data
* @throws IOException
*/
public DoABCTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
super(sis.getSwf(), ID, NAME, data);
readData(sis, data, 0, false, false, false);
}
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
ABCInputStream ais = new ABCInputStream(sis.getBaseStream());
// put it to the dumpview:
sis.readByteRangeEx(sis.available(), "abcBytes");
abc = new ABC(ais, swf, this);
}
/**
* Gets data bytes
*
* @param sos SWF output stream
* @throws java.io.IOException
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
abc.saveToStream(sos);
}
@Override
public ABC getABC() {
return abc;
}
@Override
public int compareTo(ABCContainerTag o) {
return 0;
}
@Override
public void setModified(boolean value) {
super.setModified(value);
if (value == false && !isModified()) {
ABC abc = getABC();
for (ScriptInfo si : abc.script_info) {
si.setModified(false);
}
}
}
}
@@ -1,428 +1,428 @@
/*
* Copyright (C) 2010-2016 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.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.base.FontTag;
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.gfx.FontType;
import com.jpexs.decompiler.flash.types.gfx.GFxInputStream;
import com.jpexs.decompiler.flash.types.gfx.GFxOutputStream;
import com.jpexs.decompiler.flash.types.gfx.GlyphInfoType;
import com.jpexs.decompiler.flash.types.gfx.GlyphType;
import com.jpexs.decompiler.flash.types.gfx.KerningPairType;
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.MemoryInputStream;
import java.awt.Font;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public final class DefineCompactedFont extends FontTag {
public static final int ID = 1005;
public static final String NAME = "DefineCompactedFont";
public int fontId;
public List<FontType> fonts;
private List<SHAPE> shapeCache;
/**
* Gets data bytes
*
* @param sos SWF output stream
* @throws java.io.IOException
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
sos.writeUI16(fontId);
for (FontType ft : fonts) {
ft.write(new GFxOutputStream(sos));
}
}
/**
* Constructor
*
* @param swf
*/
public DefineCompactedFont(SWF swf) {
super(swf, ID, NAME, null);
fontId = swf.getNextCharacterId();
fonts = new ArrayList<>();
FontType ft = new FontType();
fonts.add(ft);
rebuildShapeCache();
}
/**
* Constructor
*
* @param sis
* @param data
* @throws IOException
*/
public DefineCompactedFont(SWFInputStream sis, ByteArrayRange data) throws IOException {
super(sis.getSwf(), ID, NAME, data);
readData(sis, data, 0, false, false, false);
}
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
fontId = sis.readUI16("fontId");
fonts = new ArrayList<>();
MemoryInputStream mis = sis.getBaseStream();
while (mis.available() > 0) {
GFxInputStream gis = new GFxInputStream(mis);
gis.dumpInfo = sis.dumpInfo;
gis.newDumpLevel("fontType", "FontType");
fonts.add(new FontType(gis));
gis.endDumpLevel();
}
sis.skipBytes(sis.available());
if (fonts.size() > 1) {
Logger.getLogger(DefineCompactedFont.class.getName()).log(Level.WARNING, "Compacted font has more than one FontType inside. This may cause problems while editing.");
}
rebuildShapeCache();
}
public void rebuildShapeCache() {
shapeCache = fonts.get(0).getGlyphShapes();
}
@Override
public String getFontNameIntag() {
StringBuilder ret = new StringBuilder();
for (int i = 0; i < fonts.size(); i++) {
if (i > 0) {
ret.append(", ");
}
ret.append(fonts.get(i).fontName);
}
return ret.toString();
}
@Override
public int getCharacterId() {
return fontId;
}
@Override
public void setCharacterId(int characterId) {
this.fontId = characterId;
}
@Override
public List<SHAPE> getGlyphShapeTable() {
return shapeCache;
}
@Override
public void addCharacter(char character, Font cfont) {
int fontStyle = getFontStyle();
FontType font = fonts.get(0);
double d = 1;
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(cfont, (int) (font.nominalSize * d), character);
int code = (int) character;
int pos = -1;
boolean exists = false;
for (int i = 0; i < font.glyphInfo.size(); i++) {
if (font.glyphInfo.get(i).glyphCode >= code) {
if (font.glyphInfo.get(i).glyphCode == code) {
exists = true;
}
pos = i;
break;
}
}
if (pos == -1) {
pos = font.glyphInfo.size();
}
if (!exists) {
shiftGlyphIndices(fontId, pos);
}
Font fnt = cfont.deriveFont(fontStyle, Math.round(font.nominalSize * d));
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));
shapeCache.add(pos, font.glyphs.get(pos).toSHAPE());
} else {
font.glyphInfo.set(pos, new GlyphInfoType(code, advance, 0));
font.glyphs.set(pos, new GlyphType(shp.shapeRecords));
shapeCache.set(pos, font.glyphs.get(pos).toSHAPE());
}
setModified(true);
getSwf().clearImageCache();
}
@Override
public void setAdvanceValues(Font font) {
throw new UnsupportedOperationException("Setting the advance values for DefineCompactedFont is not supported.");
}
@Override
public char glyphToChar(int glyphIndex) {
return (char) fonts.get(0).glyphInfo.get(glyphIndex).glyphCode;
}
@Override
public int charToGlyph(char c) {
FontType ft = fonts.get(0);
for (int i = 0; i < ft.glyphInfo.size(); i++) {
if (ft.glyphInfo.get(i).glyphCode == c) {
return i;
}
}
return -1;
}
@Override
public double getGlyphAdvance(int glyphIndex) {
return resize(fonts.get(0).glyphInfo.get(glyphIndex).advanceX);
}
@Override
public int getGlyphKerningAdjustment(int glyphIndex, int nextGlyphIndex) {
char c1 = glyphToChar(glyphIndex);
char c2 = glyphToChar(nextGlyphIndex);
return getCharKerningAdjustment(c1, c2);
}
@Override
public int getCharKerningAdjustment(char c1, char c2) {
for (KerningPairType kp : fonts.get(0).kerning) {
if (kp.char1 == c1 && kp.char2 == c2) {
return resize(kp.advance);
}
}
return 0;
}
@Override
public int getGlyphWidth(int glyphIndex) {
return resize(getGlyphShapeTable().get(glyphIndex).getBounds().getWidth());
}
@Override
public boolean isSmall() {
return false;
}
@Override
public boolean isBold() {
return (fonts.get(0).flags & FontType.FF_Bold) == FontType.FF_Bold;
}
@Override
public boolean isItalic() {
return (fonts.get(0).flags & FontType.FF_Italic) == FontType.FF_Italic;
}
@Override
public boolean isSmallEditable() {
return false;
}
@Override
public boolean isBoldEditable() {
return true;
}
@Override
public boolean isItalicEditable() {
return true;
}
@Override
public void setSmall(boolean value) {
}
@Override
public void setBold(boolean value) {
for (FontType font : fonts) {
font.flags &= FontType.FF_Bold;
if (!value) {
font.flags ^= FontType.FF_Bold;
}
}
}
@Override
public void setItalic(boolean value) {
for (FontType font : fonts) {
font.flags &= FontType.FF_Italic;
if (!value) {
font.flags ^= FontType.FF_Italic;
}
}
}
@Override
public double getDivider() {
return 1;
}
@Override
public int getAscent() {
return fonts.get(0).ascent;
}
@Override
public int getDescent() {
return fonts.get(0).descent;
}
@Override
public int getLeading() {
return fonts.get(0).leading;
}
@Override
public int getCharacterCount() {
FontType ft = fonts.get(0);
return ft.glyphInfo.size();
}
@Override
public String getCharacters() {
FontType ft = fonts.get(0);
StringBuilder ret = new StringBuilder(ft.glyphInfo.size());
for (GlyphInfoType gi : ft.glyphInfo) {
ret.append((char) gi.glyphCode);
}
return ret.toString();
}
@Override
public RECT getGlyphBounds(int glyphIndex) {
GlyphType gt = fonts.get(0).glyphs.get(glyphIndex);
return new RECT(resize(gt.boundingBox[0]), resize(gt.boundingBox[1]), resize(gt.boundingBox[2]), resize(gt.boundingBox[3]));
}
public SHAPE resizeShape(SHAPE shp) {
SHAPE ret = new SHAPE();
ret.numFillBits = 1;
ret.numLineBits = 0;
List<SHAPERECORD> recs = new ArrayList<>();
for (SHAPERECORD r : shp.shapeRecords) {
SHAPERECORD c = r.clone();
if (c instanceof StyleChangeRecord) {
StyleChangeRecord scr = (StyleChangeRecord) c;
scr.moveDeltaX = resize(scr.moveDeltaX);
scr.moveDeltaY = resize(scr.moveDeltaY);
scr.calculateBits();
}
if (c instanceof CurvedEdgeRecord) {
CurvedEdgeRecord cer = (CurvedEdgeRecord) c;
cer.controlDeltaX = resize(cer.controlDeltaX);
cer.controlDeltaY = resize(cer.controlDeltaY);
cer.anchorDeltaX = resize(cer.anchorDeltaX);
cer.anchorDeltaY = resize(cer.anchorDeltaY);
cer.calculateBits();
}
if (c instanceof StraightEdgeRecord) {
StraightEdgeRecord ser = (StraightEdgeRecord) c;
ser.deltaX = resize(ser.deltaX);
ser.deltaY = resize(ser.deltaY);
ser.calculateBits();
}
recs.add(c);
}
ret.shapeRecords = recs;
return ret;
}
protected int resize(double val) {
FontType ft = fonts.get(0);
return (int) Math.round(val * 1024.0 / ft.nominalSize);
}
@Override
public FontTag toClassicFont() {
DefineFont2Tag ret = new DefineFont2Tag(swf);
ret.fontID = getFontId();
ret.fontFlagsBold = isBold();
ret.fontFlagsItalic = isItalic();
ret.fontFlagsWideOffsets = true;
ret.fontFlagsWideCodes = true;
ret.fontFlagsHasLayout = true;
ret.fontAscent = (getAscent());
ret.fontDescent = (getDescent());
ret.fontLeading = (getLeading());
ret.fontAdvanceTable = new ArrayList<>();
ret.fontBoundsTable = new ArrayList<>();
ret.codeTable = new ArrayList<>();
ret.glyphShapeTable = new ArrayList<>();
List<SHAPE> shp = getGlyphShapeTable();
for (int g = 0; g < shp.size(); g++) {
ret.fontAdvanceTable.add(resize(getGlyphAdvance(g)));
ret.codeTable.add((int) glyphToChar(g));
SHAPE shpX = resizeShape(shp.get(g));
ret.glyphShapeTable.add(shpX);
ret.fontBoundsTable.add(getGlyphBounds(g));
}
ret.fontName = getFontNameIntag();
ret.languageCode = new LANGCODE(1);
ret.fontKerningTable = new ArrayList<>();
FontType ft = fonts.get(0);
for (int i = 0; i < ft.kerning.size(); i++) {
KERNINGRECORD kr = new KERNINGRECORD();
kr.fontKerningAdjustment = resize(ft.kerning.get(i).advance);
kr.fontKerningCode1 = ft.kerning.get(i).char1;
kr.fontKerningCode2 = ft.kerning.get(i).char2;
ret.fontKerningTable.add(kr);
}
return ret;
}
@Override
public boolean hasLayout() {
return true;
}
}
/*
* Copyright (C) 2010-2016 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.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.base.FontTag;
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.gfx.FontType;
import com.jpexs.decompiler.flash.types.gfx.GFxInputStream;
import com.jpexs.decompiler.flash.types.gfx.GFxOutputStream;
import com.jpexs.decompiler.flash.types.gfx.GlyphInfoType;
import com.jpexs.decompiler.flash.types.gfx.GlyphType;
import com.jpexs.decompiler.flash.types.gfx.KerningPairType;
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.MemoryInputStream;
import java.awt.Font;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public final class DefineCompactedFont extends FontTag {
public static final int ID = 1005;
public static final String NAME = "DefineCompactedFont";
public int fontId;
public List<FontType> fonts;
private List<SHAPE> shapeCache;
/**
* Gets data bytes
*
* @param sos SWF output stream
* @throws java.io.IOException
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
sos.writeUI16(fontId);
for (FontType ft : fonts) {
ft.write(new GFxOutputStream(sos));
}
}
/**
* Constructor
*
* @param swf
*/
public DefineCompactedFont(SWF swf) {
super(swf, ID, NAME, null);
fontId = swf.getNextCharacterId();
fonts = new ArrayList<>();
FontType ft = new FontType();
fonts.add(ft);
rebuildShapeCache();
}
/**
* Constructor
*
* @param sis
* @param data
* @throws IOException
*/
public DefineCompactedFont(SWFInputStream sis, ByteArrayRange data) throws IOException {
super(sis.getSwf(), ID, NAME, data);
readData(sis, data, 0, false, false, false);
}
@Override
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
fontId = sis.readUI16("fontId");
fonts = new ArrayList<>();
MemoryInputStream mis = sis.getBaseStream();
while (mis.available() > 0) {
GFxInputStream gis = new GFxInputStream(mis);
gis.dumpInfo = sis.dumpInfo;
gis.newDumpLevel("fontType", "FontType");
fonts.add(new FontType(gis));
gis.endDumpLevel();
}
sis.skipBytes(sis.available());
if (fonts.size() > 1) {
Logger.getLogger(DefineCompactedFont.class.getName()).log(Level.WARNING, "Compacted font has more than one FontType inside. This may cause problems while editing.");
}
rebuildShapeCache();
}
public void rebuildShapeCache() {
shapeCache = fonts.get(0).getGlyphShapes();
}
@Override
public String getFontNameIntag() {
StringBuilder ret = new StringBuilder();
for (int i = 0; i < fonts.size(); i++) {
if (i > 0) {
ret.append(", ");
}
ret.append(fonts.get(i).fontName);
}
return ret.toString();
}
@Override
public int getCharacterId() {
return fontId;
}
@Override
public void setCharacterId(int characterId) {
this.fontId = characterId;
}
@Override
public List<SHAPE> getGlyphShapeTable() {
return shapeCache;
}
@Override
public void addCharacter(char character, Font cfont) {
int fontStyle = getFontStyle();
FontType font = fonts.get(0);
double d = 1;
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(cfont, (int) (font.nominalSize * d), character);
int code = (int) character;
int pos = -1;
boolean exists = false;
for (int i = 0; i < font.glyphInfo.size(); i++) {
if (font.glyphInfo.get(i).glyphCode >= code) {
if (font.glyphInfo.get(i).glyphCode == code) {
exists = true;
}
pos = i;
break;
}
}
if (pos == -1) {
pos = font.glyphInfo.size();
}
if (!exists) {
shiftGlyphIndices(fontId, pos);
}
Font fnt = cfont.deriveFont(fontStyle, Math.round(font.nominalSize * d));
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));
shapeCache.add(pos, font.glyphs.get(pos).toSHAPE());
} else {
font.glyphInfo.set(pos, new GlyphInfoType(code, advance, 0));
font.glyphs.set(pos, new GlyphType(shp.shapeRecords));
shapeCache.set(pos, font.glyphs.get(pos).toSHAPE());
}
setModified(true);
getSwf().clearImageCache();
}
@Override
public void setAdvanceValues(Font font) {
throw new UnsupportedOperationException("Setting the advance values for DefineCompactedFont is not supported.");
}
@Override
public char glyphToChar(int glyphIndex) {
return (char) fonts.get(0).glyphInfo.get(glyphIndex).glyphCode;
}
@Override
public int charToGlyph(char c) {
FontType ft = fonts.get(0);
for (int i = 0; i < ft.glyphInfo.size(); i++) {
if (ft.glyphInfo.get(i).glyphCode == c) {
return i;
}
}
return -1;
}
@Override
public double getGlyphAdvance(int glyphIndex) {
return resize(fonts.get(0).glyphInfo.get(glyphIndex).advanceX);
}
@Override
public int getGlyphKerningAdjustment(int glyphIndex, int nextGlyphIndex) {
char c1 = glyphToChar(glyphIndex);
char c2 = glyphToChar(nextGlyphIndex);
return getCharKerningAdjustment(c1, c2);
}
@Override
public int getCharKerningAdjustment(char c1, char c2) {
for (KerningPairType kp : fonts.get(0).kerning) {
if (kp.char1 == c1 && kp.char2 == c2) {
return resize(kp.advance);
}
}
return 0;
}
@Override
public int getGlyphWidth(int glyphIndex) {
return resize(getGlyphShapeTable().get(glyphIndex).getBounds().getWidth());
}
@Override
public boolean isSmall() {
return false;
}
@Override
public boolean isBold() {
return (fonts.get(0).flags & FontType.FF_Bold) == FontType.FF_Bold;
}
@Override
public boolean isItalic() {
return (fonts.get(0).flags & FontType.FF_Italic) == FontType.FF_Italic;
}
@Override
public boolean isSmallEditable() {
return false;
}
@Override
public boolean isBoldEditable() {
return true;
}
@Override
public boolean isItalicEditable() {
return true;
}
@Override
public void setSmall(boolean value) {
}
@Override
public void setBold(boolean value) {
for (FontType font : fonts) {
font.flags &= FontType.FF_Bold;
if (!value) {
font.flags ^= FontType.FF_Bold;
}
}
}
@Override
public void setItalic(boolean value) {
for (FontType font : fonts) {
font.flags &= FontType.FF_Italic;
if (!value) {
font.flags ^= FontType.FF_Italic;
}
}
}
@Override
public double getDivider() {
return 1;
}
@Override
public int getAscent() {
return fonts.get(0).ascent;
}
@Override
public int getDescent() {
return fonts.get(0).descent;
}
@Override
public int getLeading() {
return fonts.get(0).leading;
}
@Override
public int getCharacterCount() {
FontType ft = fonts.get(0);
return ft.glyphInfo.size();
}
@Override
public String getCharacters() {
FontType ft = fonts.get(0);
StringBuilder ret = new StringBuilder(ft.glyphInfo.size());
for (GlyphInfoType gi : ft.glyphInfo) {
ret.append((char) gi.glyphCode);
}
return ret.toString();
}
@Override
public RECT getGlyphBounds(int glyphIndex) {
GlyphType gt = fonts.get(0).glyphs.get(glyphIndex);
return new RECT(resize(gt.boundingBox[0]), resize(gt.boundingBox[1]), resize(gt.boundingBox[2]), resize(gt.boundingBox[3]));
}
public SHAPE resizeShape(SHAPE shp) {
SHAPE ret = new SHAPE();
ret.numFillBits = 1;
ret.numLineBits = 0;
List<SHAPERECORD> recs = new ArrayList<>();
for (SHAPERECORD r : shp.shapeRecords) {
SHAPERECORD c = r.clone();
if (c instanceof StyleChangeRecord) {
StyleChangeRecord scr = (StyleChangeRecord) c;
scr.moveDeltaX = resize(scr.moveDeltaX);
scr.moveDeltaY = resize(scr.moveDeltaY);
scr.calculateBits();
}
if (c instanceof CurvedEdgeRecord) {
CurvedEdgeRecord cer = (CurvedEdgeRecord) c;
cer.controlDeltaX = resize(cer.controlDeltaX);
cer.controlDeltaY = resize(cer.controlDeltaY);
cer.anchorDeltaX = resize(cer.anchorDeltaX);
cer.anchorDeltaY = resize(cer.anchorDeltaY);
cer.calculateBits();
}
if (c instanceof StraightEdgeRecord) {
StraightEdgeRecord ser = (StraightEdgeRecord) c;
ser.deltaX = resize(ser.deltaX);
ser.deltaY = resize(ser.deltaY);
ser.calculateBits();
}
recs.add(c);
}
ret.shapeRecords = recs;
return ret;
}
protected int resize(double val) {
FontType ft = fonts.get(0);
return (int) Math.round(val * 1024.0 / ft.nominalSize);
}
@Override
public FontTag toClassicFont() {
DefineFont2Tag ret = new DefineFont2Tag(swf);
ret.fontID = getFontId();
ret.fontFlagsBold = isBold();
ret.fontFlagsItalic = isItalic();
ret.fontFlagsWideOffsets = true;
ret.fontFlagsWideCodes = true;
ret.fontFlagsHasLayout = true;
ret.fontAscent = (getAscent());
ret.fontDescent = (getDescent());
ret.fontLeading = (getLeading());
ret.fontAdvanceTable = new ArrayList<>();
ret.fontBoundsTable = new ArrayList<>();
ret.codeTable = new ArrayList<>();
ret.glyphShapeTable = new ArrayList<>();
List<SHAPE> shp = getGlyphShapeTable();
for (int g = 0; g < shp.size(); g++) {
ret.fontAdvanceTable.add(resize(getGlyphAdvance(g)));
ret.codeTable.add((int) glyphToChar(g));
SHAPE shpX = resizeShape(shp.get(g));
ret.glyphShapeTable.add(shpX);
ret.fontBoundsTable.add(getGlyphBounds(g));
}
ret.fontName = getFontNameIntag();
ret.languageCode = new LANGCODE(1);
ret.fontKerningTable = new ArrayList<>();
FontType ft = fonts.get(0);
for (int i = 0; i < ft.kerning.size(); i++) {
KERNINGRECORD kr = new KERNINGRECORD();
kr.fontKerningAdjustment = resize(ft.kerning.get(i).advance);
kr.fontKerningCode1 = ft.kerning.get(i).char1;
kr.fontKerningCode2 = ft.kerning.get(i).char2;
ret.fontKerningTable.add(kr);
}
return ret;
}
@Override
public boolean hasLayout() {
return true;
}
}
@@ -1,485 +1,484 @@
/*
* Copyright (C) 2010-2016 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.types.gfx;
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 java.io.IOException;
import java.io.Serializable;
/**
*
* @author JPEXS
*/
public class EdgeType implements Serializable {
private static final int[] sizes = new int[]{1, 2, 1, 2, 1, 2, 3, 4, 2, 3, 4, 5, 6, 7, 8, 9};
private static final int Edge_H12 = 0; // 2 bytes
private static final int Edge_H20 = 1; // 3 bytes
private static final int Edge_V12 = 2; // 2 bytes
private static final int Edge_V20 = 3; // 3 bytes
private static final int Edge_L6 = 4; // 2 bytes
private static final int Edge_L10 = 5; // 3 bytes
private static final int Edge_L14 = 6; // 4 bytes
private static final int Edge_L18 = 7; // 5 bytes
private static final int Edge_C5 = 8; // 3 bytes
private static final int Edge_C7 = 9; // 4 bytes
private static final int Edge_C9 = 10; // 5 bytes
private static final int Edge_C11 = 11; // 6 bytes
private static final int Edge_C13 = 12; // 7 bytes
private static final int Edge_C15 = 13; // 8 bytes
private static final int Edge_C17 = 14; // 9 bytes
private static final int Edge_C19 = 15; // 10 bytes
private static final int Edge_HLine = 0;
private static final int Edge_VLine = 1;
private static final int Edge_Line = 2;
private static final int Edge_Quad = 3;
public int[] data;
public EdgeType(boolean vertical, int v) {
data = new int[]{vertical ? Edge_VLine : Edge_HLine, v};
}
public EdgeType(int x, int y) {
data = new int[]{Edge_Line, x, y};
}
public EdgeType(int cx, int cy, int ax, int ay) {
data = new int[]{Edge_Quad, cx, cy, ax, ay};
}
@Override
public String toString() {
String ret = "[Edge data:";
for (int i = 0; i < data.length; i++) {
if (i > 0) {
ret += ", ";
}
ret += "" + data[i];
}
ret += "]";
return ret;
}
public EdgeType(GFxInputStream sis) throws IOException {
data = readEdge(sis);
/*if((raw[0]&0xf) == Edge_V20){
data[1] = 0;
}
if((raw[0]&0xf) == Edge_C17){
//System.out.println("========== 17 : "+toString()) ;
data[1] = 0;
data[2] = 0;
data[3] = 0;
data[4] = 0;
}*/
}
private static int SInt8(int val) {
/*boolean sign = (val & 0x80) == 0x80;
val = val & 0x7F;
if (sign) {
val = -val;
}
return val;*/
return (byte) val;
}
public SHAPERECORD toSHAPERECORD() {
int multiplier = 1;
StraightEdgeRecord ser;
CurvedEdgeRecord cer;
switch (data[0]) {
case Edge_HLine:
ser = new StraightEdgeRecord();
ser.generalLineFlag = false;
ser.deltaX = data[1] * multiplier;
ser.calculateBits();
return ser;
case Edge_VLine:
ser = new StraightEdgeRecord();
ser.generalLineFlag = false;
ser.vertLineFlag = true;
ser.deltaY = data[1] * multiplier;
ser.calculateBits();
return ser;
case Edge_Line:
ser = new StraightEdgeRecord();
ser.generalLineFlag = true;
ser.deltaX = data[1] * multiplier;
ser.deltaY = data[2] * multiplier;
ser.calculateBits();
return ser;
case Edge_Quad:
cer = new CurvedEdgeRecord();
cer.controlDeltaX = data[1] * multiplier;
cer.controlDeltaY = data[2] * multiplier;
cer.anchorDeltaX = data[3] * multiplier;
cer.anchorDeltaY = data[4] * multiplier;
cer.calculateBits();
return cer;
}
return null;
}
private int[] readEdge(GFxInputStream sis) throws IOException {
byte firstByte = (byte) sis.readUI8("firstByte");
int nb = sizes[firstByte & 0xF];
byte raw1, raw2, raw3, raw4, raw5, raw6, raw7, raw8, raw9;
raw1 = (byte) sis.readUI8("byte1");
int[] data = new int[5];
switch (firstByte & 0xF) {
case Edge_H12:
data[0] = Edge_HLine;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8(raw1 & 0xff) << 4);
break;
case Edge_H20:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_HLine;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 & 0xff) << 12);
break;
case Edge_V12:
data[0] = Edge_VLine;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8(raw1 & 0xff) << 4);
break;
case Edge_V20:
data[0] = Edge_VLine;
raw2 = (byte) sis.readUI8("byte2");
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 & 0xff) << 12);
break;
case Edge_L6:
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 6) >> 2);
data[2] = SInt8(raw1 & 0xff) >> 2;
break;
case Edge_L10:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 2) << 2);
data[2] = ((raw1 & 0xff) >> 6) | (SInt8((raw2 & 0xff)) << 2);
break;
case Edge_L14:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 6) << 6);
data[2] = ((raw2 & 0xff) >> 2) | (SInt8((raw3 & 0xff)) << 6);
break;
case Edge_L18:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 2) << 10);
data[2] = ((raw2 & 0xff) >> 6) | ((raw3 & 0xff) << 2) | (SInt8((raw4 & 0xff)) << 10);
break;
case Edge_C5:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 7) >> 3);
data[2] = SInt8((raw1 & 0xff) << 2) >> 3;
data[3] = ((raw1 & 0xff) >> 6) | (SInt8((raw2 & 0xff) << 5) >> 3);
data[4] = SInt8((raw2 & 0xff)) >> 3;
break;
case Edge_C7:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 5) >> 1);
data[2] = ((raw1 & 0xff) >> 3) | (SInt8((raw2 & 0xff) << 6) >> 1);
data[3] = ((raw2 & 0xff) >> 2) | (SInt8((raw3 & 0xff) << 7) >> 1);
data[4] = SInt8(raw3) >> 1;
break;
case Edge_C9:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 3) << 1);
data[2] = ((raw1 & 0xff) >> 5) | (SInt8((raw2 & 0xff) << 2) << 1);
data[3] = ((raw2 & 0xff) >> 6) | (SInt8((raw3 & 0xff) << 1) << 1);
data[4] = ((raw3 & 0xff) >> 7) | (SInt8(raw4 & 0xff) << 1);
break;
case Edge_C11:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 1) << 3);
data[2] = (raw1 >> 7) | ((raw2 & 0xff) << 1) | (SInt8((raw3 & 0xff) << 6) << 3);
data[3] = ((raw3 & 0xff) >> 2) | (SInt8((raw4 & 0xff) << 3) << 3);
data[4] = ((raw4 & 0xff) >> 5) | (SInt8(raw5 & 0xff) << 3);
break;
case Edge_C13:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 7) << 5);
data[2] = ((raw2 & 0xff) >> 1) | (SInt8((raw3 & 0xff) << 2) << 5);
data[3] = ((raw3 & 0xff) >> 6) | ((raw4 & 0xff) << 2) | (SInt8((raw5 & 0xff) << 5) << 5);
data[4] = ((raw5 & 0xff) >> 3) | (SInt8(raw6 & 0xff) << 5);
break;
case Edge_C15:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 5) << 7);
data[2] = ((raw2 & 0xff) >> 3) | ((raw3 & 0xff) << 5) | (SInt8((raw4 & 0xff) << 6) << 7);
data[3] = ((raw4 & 0xff) >> 2) | ((raw5 & 0xff) << 6) | (SInt8((raw6 & 0xff) << 7) << 7);
data[4] = ((raw6 & 0xff) >> 1) | (SInt8((raw7 & 0xff)) << 7);
break;
case Edge_C17:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
raw8 = (byte) sis.readUI8("byte8");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 3) << 9);
data[2] = ((raw2 & 0xff) >> 5) | ((raw3 & 0xff) << 3) | (SInt8((raw4 & 0xff) << 2) << 9);
data[3] = ((raw4 & 0xff) >> 6) | ((raw5 & 0xff) << 2) | (SInt8((raw6 & 0xff) << 1) << 9);
data[4] = ((raw6 & 0xff) >> 7) | ((raw7 & 0xff) << 1) | (SInt8(raw8 & 0xff) << 9);
break;
case Edge_C19:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
raw8 = (byte) sis.readUI8("byte8");
raw9 = (byte) sis.readUI8("byte9");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 << 1) << 11);
data[2] = ((raw2 & 0xff) >> 7) | ((raw3 & 0xff) << 1) | ((raw4 & 0xff) << 9) | (SInt8(raw5 << 6) << 11);
data[3] = ((raw5 & 0xff) >> 2) | ((raw6 & 0xff) << 6) | (SInt8(raw7 << 3) << 11);
data[4] = ((raw7 & 0xff) >> 5) | ((raw8 & 0xff) << 3) | (SInt8(raw9) << 11);
break;
}
return data;
}
public void write(GFxOutputStream sos) throws IOException {
int x;
int y;
int m1 = 1;
int m2 = 3;
int m3 = 7;
int m4 = 0xF;
int m5 = 0x1F;
int m6 = 0x3F;
int m7 = 0x7F;
switch (data[0]) {
case Edge_HLine:
x = data[1];
if (x >= GFxOutputStream.MinSInt12 && x <= GFxOutputStream.MaxSInt12) {
sos.writeUI8((x << 4) | Edge_H12);
sos.writeUI8(x >> 4);
return;
}
sos.writeUI8((x << 4) | Edge_H20);
sos.writeUI8(x >> 4);
sos.writeUI8(x >> 12);
break;
case Edge_VLine:
y = data[1];
if (y >= GFxOutputStream.MinSInt12 && y <= GFxOutputStream.MaxSInt12) {
sos.writeUI8((y << 4) | Edge_V12);
sos.writeUI8(y >> 4);
return;
}
sos.writeUI8((y << 4) | Edge_V20);
sos.writeUI8(y >> 4);
sos.writeUI8(y >> 12);
return;
case Edge_Line:
x = data[1];
y = data[2];
if (x >= GFxOutputStream.MinSInt6 && x <= GFxOutputStream.MaxSInt6 && y >= GFxOutputStream.MinSInt6 && y <= GFxOutputStream.MaxSInt6) {
sos.writeUI8((x << 4) | Edge_L6);
sos.writeUI8(((x >> 4) & m2) | (y << 2));
return;
}
if (x >= GFxOutputStream.MinSInt10 && x <= GFxOutputStream.MaxSInt10 && y >= GFxOutputStream.MinSInt10 && y <= GFxOutputStream.MaxSInt10) {
sos.writeUI8((x << 4) | Edge_L10);
sos.writeUI8(((x >> 4) & m6) | (y << 6));
sos.writeUI8(y >> 2);
return;
}
if (x >= GFxOutputStream.MinSInt14 && x <= GFxOutputStream.MaxSInt14 && y >= GFxOutputStream.MinSInt14 && y <= GFxOutputStream.MaxSInt14) {
sos.writeUI8((x << 4) | Edge_L14);
sos.writeUI8(x >> 4);
sos.writeUI8(((x >> 12) & m2) | (y << 2));
sos.writeUI8(y >> 6);
return;
}
sos.writeUI8((x << 4) | Edge_L18);
sos.writeUI8(x >> 4);
sos.writeUI8(((x >> 12) & m6) | (y << 6));
sos.writeUI8(y >> 2);
sos.writeUI8(y >> 10);
return;
case Edge_Quad:
int cx = data[1];
int cy = data[2];
int ax = data[3];
int ay = data[4];
int minV = cx;
int maxV = cx;
if (cy < minV) {
minV = cy;
}
if (cy > maxV) {
maxV = cy;
}
if (ax < minV) {
minV = ax;
}
if (ax > maxV) {
maxV = ax;
}
if (ay < minV) {
minV = ay;
}
if (ay > maxV) {
maxV = ay;
}
if (minV >= GFxOutputStream.MinSInt5 && maxV <= GFxOutputStream.MaxSInt5) {
sos.writeUI8(((cx << 4) | Edge_C5));
sos.writeUI8((((cx >> 4) & m1) | ((cy << 1) & m6) | (ax << 6)));
sos.writeUI8((((ax >> 2) & m3) | (ay << 3)));
return;
}
if (minV >= GFxOutputStream.MinSInt7 && maxV <= GFxOutputStream.MaxSInt7) {
sos.writeUI8(((cx << 4) | Edge_C7));
sos.writeUI8((((cx >> 4) & m3) | (cy << 3)));
sos.writeUI8((((cy >> 5) & m2) | (ax << 2)));
sos.writeUI8((((ax >> 6) & m1) | (ay << 1)));
return;
}
if (minV >= GFxOutputStream.MinSInt9 && maxV <= GFxOutputStream.MaxSInt9) {
sos.writeUI8(((cx << 4) | Edge_C9));
sos.writeUI8((((cx >> 4) & m5) | (cy << 5)));
sos.writeUI8((((cy >> 3) & m6) | (ax << 6)));
sos.writeUI8((((ax >> 2) & m7) | (ay << 7)));
sos.writeUI8(((ay >> 1)));
return;
}
if (minV >= GFxOutputStream.MinSInt11 && maxV <= GFxOutputStream.MaxSInt11) {
sos.writeUI8(((cx << 4) | Edge_C11));
sos.writeUI8((((cx >> 4) & m7) | (cy << 7)));
sos.writeUI8(((cy >> 1)));
sos.writeUI8((((cy >> 9) & m2) | (ax << 2)));
sos.writeUI8((((ax >> 6) & m5) | (ay << 5)));
sos.writeUI8(((ay >> 3)));
return;
}
if (minV >= GFxOutputStream.MinSInt13 && maxV <= GFxOutputStream.MaxSInt13) {
sos.writeUI8(((cx << 4) | Edge_C13));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m1) | (cy << 1)));
sos.writeUI8((((cy >> 7) & m6) | (ax << 6)));
sos.writeUI8(((ax >> 2)));
sos.writeUI8((((ax >> 10) & m3) | (ay << 3)));
sos.writeUI8(((ay >> 5)));
return;
}
if (minV >= GFxOutputStream.MinSInt15 && maxV <= GFxOutputStream.MaxSInt15) {
sos.writeUI8(((cx << 4) | Edge_C15));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m3) | (cy << 3)));
sos.writeUI8(((cy >> 5)));
sos.writeUI8((((cy >> 13) & m2) | (ax << 2)));
sos.writeUI8(((ax >> 6)));
sos.writeUI8((((ax >> 14) & m1) | (ay << 1)));
sos.writeUI8(((ay >> 7)));
return;
}
if (minV >= GFxOutputStream.MinSInt17 && maxV <= GFxOutputStream.MaxSInt17) {
sos.writeUI8(((cx << 4) | Edge_C17));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m5) | (cy << 5)));
sos.writeUI8(((cy >> 3)));
sos.writeUI8((((cy >> 11) & m6) | (ax << 6)));
sos.writeUI8(((ax >> 2)));
sos.writeUI8((((ax >> 10) & m7) | (ay << 7)));
sos.writeUI8(((ay >> 1)));
sos.writeUI8(((ay >> 9)));
return;
}
sos.writeUI8(((cx << 4) | Edge_C19));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m7) | (cy << 7)));
sos.writeUI8(((cy >> 1)));
sos.writeUI8(((cy >> 9)));
sos.writeUI8((((cy >> 17) & m2) | (ax << 2)));
sos.writeUI8(((ax >> 6)));
sos.writeUI8((((ax >> 14) & m5) | (ay << 5)));
sos.writeUI8(((ay >> 3)));
sos.writeUI8(((ay >> 11)));
}
}
}
/*
* Copyright (C) 2010-2016 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.types.gfx;
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 java.io.IOException;
import java.io.Serializable;
/**
*
* @author JPEXS
*/
public class EdgeType implements Serializable {
private static final int[] sizes = new int[]{1, 2, 1, 2, 1, 2, 3, 4, 2, 3, 4, 5, 6, 7, 8, 9};
private static final int Edge_H12 = 0; // 2 bytes
private static final int Edge_H20 = 1; // 3 bytes
private static final int Edge_V12 = 2; // 2 bytes
private static final int Edge_V20 = 3; // 3 bytes
private static final int Edge_L6 = 4; // 2 bytes
private static final int Edge_L10 = 5; // 3 bytes
private static final int Edge_L14 = 6; // 4 bytes
private static final int Edge_L18 = 7; // 5 bytes
private static final int Edge_C5 = 8; // 3 bytes
private static final int Edge_C7 = 9; // 4 bytes
private static final int Edge_C9 = 10; // 5 bytes
private static final int Edge_C11 = 11; // 6 bytes
private static final int Edge_C13 = 12; // 7 bytes
private static final int Edge_C15 = 13; // 8 bytes
private static final int Edge_C17 = 14; // 9 bytes
private static final int Edge_C19 = 15; // 10 bytes
private static final int Edge_HLine = 0;
private static final int Edge_VLine = 1;
private static final int Edge_Line = 2;
private static final int Edge_Quad = 3;
public int[] data;
public EdgeType(boolean vertical, int v) {
data = new int[]{vertical ? Edge_VLine : Edge_HLine, v};
}
public EdgeType(int x, int y) {
data = new int[]{Edge_Line, x, y};
}
public EdgeType(int cx, int cy, int ax, int ay) {
data = new int[]{Edge_Quad, cx, cy, ax, ay};
}
@Override
public String toString() {
String ret = "[Edge data:";
for (int i = 0; i < data.length; i++) {
if (i > 0) {
ret += ", ";
}
ret += "" + data[i];
}
ret += "]";
return ret;
}
public EdgeType(GFxInputStream sis) throws IOException {
data = readEdge(sis);
/*if((raw[0]&0xf) == Edge_V20){
data[1] = 0;
}
if((raw[0]&0xf) == Edge_C17){
//System.out.println("========== 17 : "+toString()) ;
data[1] = 0;
data[2] = 0;
data[3] = 0;
data[4] = 0;
}*/
}
private static int SInt8(int val) {
/*boolean sign = (val & 0x80) == 0x80;
val = val & 0x7F;
if (sign) {
val = -val;
}
return val;*/
return (byte) val;
}
public SHAPERECORD toSHAPERECORD() {
int multiplier = 1;
StraightEdgeRecord ser;
CurvedEdgeRecord cer;
switch (data[0]) {
case Edge_HLine:
ser = new StraightEdgeRecord();
ser.generalLineFlag = false;
ser.deltaX = data[1] * multiplier;
ser.calculateBits();
return ser;
case Edge_VLine:
ser = new StraightEdgeRecord();
ser.generalLineFlag = false;
ser.vertLineFlag = true;
ser.deltaY = data[1] * multiplier;
ser.calculateBits();
return ser;
case Edge_Line:
ser = new StraightEdgeRecord();
ser.generalLineFlag = true;
ser.deltaX = data[1] * multiplier;
ser.deltaY = data[2] * multiplier;
ser.calculateBits();
return ser;
case Edge_Quad:
cer = new CurvedEdgeRecord();
cer.controlDeltaX = data[1] * multiplier;
cer.controlDeltaY = data[2] * multiplier;
cer.anchorDeltaX = data[3] * multiplier;
cer.anchorDeltaY = data[4] * multiplier;
cer.calculateBits();
return cer;
}
return null;
}
private int[] readEdge(GFxInputStream sis) throws IOException {
byte firstByte = (byte) sis.readUI8("firstByte");
byte raw1, raw2, raw3, raw4, raw5, raw6, raw7, raw8, raw9;
raw1 = (byte) sis.readUI8("byte1");
int[] data = new int[5];
switch (firstByte & 0xF) {
case Edge_H12:
data[0] = Edge_HLine;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8(raw1 & 0xff) << 4);
break;
case Edge_H20:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_HLine;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 & 0xff) << 12);
break;
case Edge_V12:
data[0] = Edge_VLine;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8(raw1 & 0xff) << 4);
break;
case Edge_V20:
data[0] = Edge_VLine;
raw2 = (byte) sis.readUI8("byte2");
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 & 0xff) << 12);
break;
case Edge_L6:
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 6) >> 2);
data[2] = SInt8(raw1 & 0xff) >> 2;
break;
case Edge_L10:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 2) << 2);
data[2] = ((raw1 & 0xff) >> 6) | (SInt8((raw2 & 0xff)) << 2);
break;
case Edge_L14:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 6) << 6);
data[2] = ((raw2 & 0xff) >> 2) | (SInt8((raw3 & 0xff)) << 6);
break;
case Edge_L18:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
data[0] = Edge_Line;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 2) << 10);
data[2] = ((raw2 & 0xff) >> 6) | ((raw3 & 0xff) << 2) | (SInt8((raw4 & 0xff)) << 10);
break;
case Edge_C5:
raw2 = (byte) sis.readUI8("byte2");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 7) >> 3);
data[2] = SInt8((raw1 & 0xff) << 2) >> 3;
data[3] = ((raw1 & 0xff) >> 6) | (SInt8((raw2 & 0xff) << 5) >> 3);
data[4] = SInt8((raw2 & 0xff)) >> 3;
break;
case Edge_C7:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 5) >> 1);
data[2] = ((raw1 & 0xff) >> 3) | (SInt8((raw2 & 0xff) << 6) >> 1);
data[3] = ((raw2 & 0xff) >> 2) | (SInt8((raw3 & 0xff) << 7) >> 1);
data[4] = SInt8(raw3) >> 1;
break;
case Edge_C9:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 3) << 1);
data[2] = ((raw1 & 0xff) >> 5) | (SInt8((raw2 & 0xff) << 2) << 1);
data[3] = ((raw2 & 0xff) >> 6) | (SInt8((raw3 & 0xff) << 1) << 1);
data[4] = ((raw3 & 0xff) >> 7) | (SInt8(raw4 & 0xff) << 1);
break;
case Edge_C11:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | (SInt8((raw1 & 0xff) << 1) << 3);
data[2] = (raw1 >> 7) | ((raw2 & 0xff) << 1) | (SInt8((raw3 & 0xff) << 6) << 3);
data[3] = ((raw3 & 0xff) >> 2) | (SInt8((raw4 & 0xff) << 3) << 3);
data[4] = ((raw4 & 0xff) >> 5) | (SInt8(raw5 & 0xff) << 3);
break;
case Edge_C13:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 7) << 5);
data[2] = ((raw2 & 0xff) >> 1) | (SInt8((raw3 & 0xff) << 2) << 5);
data[3] = ((raw3 & 0xff) >> 6) | ((raw4 & 0xff) << 2) | (SInt8((raw5 & 0xff) << 5) << 5);
data[4] = ((raw5 & 0xff) >> 3) | (SInt8(raw6 & 0xff) << 5);
break;
case Edge_C15:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 5) << 7);
data[2] = ((raw2 & 0xff) >> 3) | ((raw3 & 0xff) << 5) | (SInt8((raw4 & 0xff) << 6) << 7);
data[3] = ((raw4 & 0xff) >> 2) | ((raw5 & 0xff) << 6) | (SInt8((raw6 & 0xff) << 7) << 7);
data[4] = ((raw6 & 0xff) >> 1) | (SInt8((raw7 & 0xff)) << 7);
break;
case Edge_C17:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
raw8 = (byte) sis.readUI8("byte8");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8((raw2 & 0xff) << 3) << 9);
data[2] = ((raw2 & 0xff) >> 5) | ((raw3 & 0xff) << 3) | (SInt8((raw4 & 0xff) << 2) << 9);
data[3] = ((raw4 & 0xff) >> 6) | ((raw5 & 0xff) << 2) | (SInt8((raw6 & 0xff) << 1) << 9);
data[4] = ((raw6 & 0xff) >> 7) | ((raw7 & 0xff) << 1) | (SInt8(raw8 & 0xff) << 9);
break;
case Edge_C19:
raw2 = (byte) sis.readUI8("byte2");
raw3 = (byte) sis.readUI8("byte3");
raw4 = (byte) sis.readUI8("byte4");
raw5 = (byte) sis.readUI8("byte5");
raw6 = (byte) sis.readUI8("byte6");
raw7 = (byte) sis.readUI8("byte7");
raw8 = (byte) sis.readUI8("byte8");
raw9 = (byte) sis.readUI8("byte9");
data[0] = Edge_Quad;
data[1] = ((firstByte & 0xff) >> 4) | ((raw1 & 0xff) << 4) | (SInt8(raw2 << 1) << 11);
data[2] = ((raw2 & 0xff) >> 7) | ((raw3 & 0xff) << 1) | ((raw4 & 0xff) << 9) | (SInt8(raw5 << 6) << 11);
data[3] = ((raw5 & 0xff) >> 2) | ((raw6 & 0xff) << 6) | (SInt8(raw7 << 3) << 11);
data[4] = ((raw7 & 0xff) >> 5) | ((raw8 & 0xff) << 3) | (SInt8(raw9) << 11);
break;
}
return data;
}
public void write(GFxOutputStream sos) throws IOException {
int x;
int y;
int m1 = 1;
int m2 = 3;
int m3 = 7;
int m4 = 0xF;
int m5 = 0x1F;
int m6 = 0x3F;
int m7 = 0x7F;
switch (data[0]) {
case Edge_HLine:
x = data[1];
if (x >= GFxOutputStream.MinSInt12 && x <= GFxOutputStream.MaxSInt12) {
sos.writeUI8((x << 4) | Edge_H12);
sos.writeUI8(x >> 4);
return;
}
sos.writeUI8((x << 4) | Edge_H20);
sos.writeUI8(x >> 4);
sos.writeUI8(x >> 12);
break;
case Edge_VLine:
y = data[1];
if (y >= GFxOutputStream.MinSInt12 && y <= GFxOutputStream.MaxSInt12) {
sos.writeUI8((y << 4) | Edge_V12);
sos.writeUI8(y >> 4);
return;
}
sos.writeUI8((y << 4) | Edge_V20);
sos.writeUI8(y >> 4);
sos.writeUI8(y >> 12);
return;
case Edge_Line:
x = data[1];
y = data[2];
if (x >= GFxOutputStream.MinSInt6 && x <= GFxOutputStream.MaxSInt6 && y >= GFxOutputStream.MinSInt6 && y <= GFxOutputStream.MaxSInt6) {
sos.writeUI8((x << 4) | Edge_L6);
sos.writeUI8(((x >> 4) & m2) | (y << 2));
return;
}
if (x >= GFxOutputStream.MinSInt10 && x <= GFxOutputStream.MaxSInt10 && y >= GFxOutputStream.MinSInt10 && y <= GFxOutputStream.MaxSInt10) {
sos.writeUI8((x << 4) | Edge_L10);
sos.writeUI8(((x >> 4) & m6) | (y << 6));
sos.writeUI8(y >> 2);
return;
}
if (x >= GFxOutputStream.MinSInt14 && x <= GFxOutputStream.MaxSInt14 && y >= GFxOutputStream.MinSInt14 && y <= GFxOutputStream.MaxSInt14) {
sos.writeUI8((x << 4) | Edge_L14);
sos.writeUI8(x >> 4);
sos.writeUI8(((x >> 12) & m2) | (y << 2));
sos.writeUI8(y >> 6);
return;
}
sos.writeUI8((x << 4) | Edge_L18);
sos.writeUI8(x >> 4);
sos.writeUI8(((x >> 12) & m6) | (y << 6));
sos.writeUI8(y >> 2);
sos.writeUI8(y >> 10);
return;
case Edge_Quad:
int cx = data[1];
int cy = data[2];
int ax = data[3];
int ay = data[4];
int minV = cx;
int maxV = cx;
if (cy < minV) {
minV = cy;
}
if (cy > maxV) {
maxV = cy;
}
if (ax < minV) {
minV = ax;
}
if (ax > maxV) {
maxV = ax;
}
if (ay < minV) {
minV = ay;
}
if (ay > maxV) {
maxV = ay;
}
if (minV >= GFxOutputStream.MinSInt5 && maxV <= GFxOutputStream.MaxSInt5) {
sos.writeUI8(((cx << 4) | Edge_C5));
sos.writeUI8((((cx >> 4) & m1) | ((cy << 1) & m6) | (ax << 6)));
sos.writeUI8((((ax >> 2) & m3) | (ay << 3)));
return;
}
if (minV >= GFxOutputStream.MinSInt7 && maxV <= GFxOutputStream.MaxSInt7) {
sos.writeUI8(((cx << 4) | Edge_C7));
sos.writeUI8((((cx >> 4) & m3) | (cy << 3)));
sos.writeUI8((((cy >> 5) & m2) | (ax << 2)));
sos.writeUI8((((ax >> 6) & m1) | (ay << 1)));
return;
}
if (minV >= GFxOutputStream.MinSInt9 && maxV <= GFxOutputStream.MaxSInt9) {
sos.writeUI8(((cx << 4) | Edge_C9));
sos.writeUI8((((cx >> 4) & m5) | (cy << 5)));
sos.writeUI8((((cy >> 3) & m6) | (ax << 6)));
sos.writeUI8((((ax >> 2) & m7) | (ay << 7)));
sos.writeUI8(((ay >> 1)));
return;
}
if (minV >= GFxOutputStream.MinSInt11 && maxV <= GFxOutputStream.MaxSInt11) {
sos.writeUI8(((cx << 4) | Edge_C11));
sos.writeUI8((((cx >> 4) & m7) | (cy << 7)));
sos.writeUI8(((cy >> 1)));
sos.writeUI8((((cy >> 9) & m2) | (ax << 2)));
sos.writeUI8((((ax >> 6) & m5) | (ay << 5)));
sos.writeUI8(((ay >> 3)));
return;
}
if (minV >= GFxOutputStream.MinSInt13 && maxV <= GFxOutputStream.MaxSInt13) {
sos.writeUI8(((cx << 4) | Edge_C13));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m1) | (cy << 1)));
sos.writeUI8((((cy >> 7) & m6) | (ax << 6)));
sos.writeUI8(((ax >> 2)));
sos.writeUI8((((ax >> 10) & m3) | (ay << 3)));
sos.writeUI8(((ay >> 5)));
return;
}
if (minV >= GFxOutputStream.MinSInt15 && maxV <= GFxOutputStream.MaxSInt15) {
sos.writeUI8(((cx << 4) | Edge_C15));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m3) | (cy << 3)));
sos.writeUI8(((cy >> 5)));
sos.writeUI8((((cy >> 13) & m2) | (ax << 2)));
sos.writeUI8(((ax >> 6)));
sos.writeUI8((((ax >> 14) & m1) | (ay << 1)));
sos.writeUI8(((ay >> 7)));
return;
}
if (minV >= GFxOutputStream.MinSInt17 && maxV <= GFxOutputStream.MaxSInt17) {
sos.writeUI8(((cx << 4) | Edge_C17));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m5) | (cy << 5)));
sos.writeUI8(((cy >> 3)));
sos.writeUI8((((cy >> 11) & m6) | (ax << 6)));
sos.writeUI8(((ax >> 2)));
sos.writeUI8((((ax >> 10) & m7) | (ay << 7)));
sos.writeUI8(((ay >> 1)));
sos.writeUI8(((ay >> 9)));
return;
}
sos.writeUI8(((cx << 4) | Edge_C19));
sos.writeUI8(((cx >> 4)));
sos.writeUI8((((cx >> 12) & m7) | (cy << 7)));
sos.writeUI8(((cy >> 1)));
sos.writeUI8(((cy >> 9)));
sos.writeUI8((((cy >> 17) & m2) | (ax << 2)));
sos.writeUI8(((ax >> 6)));
sos.writeUI8((((ax >> 14) & m5) | (ay << 5)));
sos.writeUI8(((ay >> 3)));
sos.writeUI8(((ay >> 11)));
}
}
}