Auto calculate edgeBounds of DefineShape4 during SVG import

This commit is contained in:
Jindra Petřík
2022-12-28 17:31:13 +01:00
parent e18575f2cd
commit 0fd892739d
6 changed files with 44 additions and 30 deletions

View File

@@ -196,6 +196,9 @@ public class SvgImporter {
st.shapes = shapes;
if (!fill) {
st.shapeBounds = shapes.getBounds(st.getShapeNum());
if (st instanceof DefineShape4Tag) {
((DefineShape4Tag)st).edgeBounds = shapes.getEdgeBounds();
}
}
st.setModified(true);
@@ -516,7 +519,7 @@ public class SvgImporter {
x0 = x;
y0 = y;
}
applyStyleGradients(SHAPERECORD.getBounds(newRecords, shapes.lineStyles, shapeNum), scrStyle, transform2, shapeNum, style);
applyStyleGradients(SHAPERECORD.getBounds(newRecords, shapes.lineStyles, shapeNum, false), scrStyle, transform2, shapeNum, style);
shapes.shapeRecords.addAll(newRecords);
}

View File

@@ -334,7 +334,7 @@ public abstract class TextTag extends DrawableTag {
LINESTYLEARRAY lsa = new LINESTYLEARRAY();
lsa.lineStyles = new LINESTYLE[0];
lsa.lineStyles2 = new LINESTYLE2[0];
RECT rect = SHAPERECORD.getBounds(glyphs.get(entry.glyphIndex).shapeRecords, lsa, 1);
RECT rect = SHAPERECORD.getBounds(glyphs.get(entry.glyphIndex).shapeRecords, lsa, 1, false);
rect.Xmax = (int) Math.round(((double) rect.Xmax * textHeight) / (font.getDivider() * 1024));
rect.Xmin = (int) Math.round(((double) rect.Xmin * textHeight) / (font.getDivider() * 1024));
rect.Ymax = (int) Math.round(((double) rect.Ymax * textHeight) / (font.getDivider() * 1024));

View File

@@ -77,7 +77,11 @@ public class SHAPE implements NeedsCharacters, Serializable {
LINESTYLEARRAY lsa = new LINESTYLEARRAY();
lsa.lineStyles = new LINESTYLE[0];
lsa.lineStyles2 = new LINESTYLE2[0];
return SHAPERECORD.getBounds(shapeRecords, lsa, shapeNum);
return SHAPERECORD.getBounds(shapeRecords, lsa, shapeNum, false);
}
public RECT getEdgeBounds() {
return SHAPERECORD.getBounds(shapeRecords, null, 1, true);
}
public Shape getOutline(int shapeNum, SWF swf, boolean stroked) {

View File

@@ -100,7 +100,7 @@ public class SHAPEWITHSTYLE extends SHAPE implements NeedsCharacters, Serializab
@Override
public RECT getBounds(int shapeNum) {
return SHAPERECORD.getBounds(shapeRecords, lineStyles, shapeNum);
return SHAPERECORD.getBounds(shapeRecords, lineStyles, shapeNum, false);
}

View File

@@ -52,7 +52,7 @@ public class GlyphType implements Serializable {
LINESTYLEARRAY lsa = new LINESTYLEARRAY();
lsa.lineStyles = new LINESTYLE[0];
lsa.lineStyles2 = new LINESTYLE2[0];
RECT bounds = SHAPERECORD.getBounds(records, lsa, 1);
RECT bounds = SHAPERECORD.getBounds(records, lsa, 1, false);
boundingBox = new int[4];
boundingBox[0] = bounds.Xmin;
boundingBox[1] = bounds.Ymin;

View File

@@ -80,7 +80,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
public abstract void flip();
public static RECT getBounds(List<SHAPERECORD> records, LINESTYLEARRAY lineStyles, int shapeNum) {
public static RECT getBounds(List<SHAPERECORD> records, LINESTYLEARRAY lineStyles, int shapeNum, boolean edgeBounds) {
int x = 0;
int y = 0;
int max_x = 0;
@@ -92,7 +92,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
int lineWidth = 0;
int lineWidthHalf = 0;
for (SHAPERECORD r : records) {
if (r instanceof StyleChangeRecord) {
if (!edgeBounds && (r instanceof StyleChangeRecord)) {
StyleChangeRecord style = (StyleChangeRecord) r;
if (style.stateNewStyles) {
lineStyles = style.lineStyles;
@@ -121,11 +121,13 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
if (y2 > max_y) {
max_y = y2;
}
if (x2 + lineWidthHalf > max_x) {
max_x = x2 + lineWidthHalf;
}
if (y2 + lineWidthHalf > max_y) {
max_y = y2 + lineWidthHalf;
if (!edgeBounds) {
if (x2 + lineWidthHalf > max_x) {
max_x = x2 + lineWidthHalf;
}
if (y2 + lineWidthHalf > max_y) {
max_y = y2 + lineWidthHalf;
}
}
if (started) {
if (y2 < min_y) {
@@ -135,12 +137,13 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
min_x = x2;
}
if (y2 - lineWidthHalf < min_y) {
min_y = y2 - lineWidthHalf;
}
if (x2 - lineWidthHalf < min_x) {
min_x = x2 - lineWidthHalf;
if (!edgeBounds) {
if (y2 - lineWidthHalf < min_y) {
min_y = y2 - lineWidthHalf;
}
if (x2 - lineWidthHalf < min_x) {
min_x = x2 - lineWidthHalf;
}
}
}
}
@@ -153,11 +156,13 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
if (y > max_y) {
max_y = y;
}
if (x + lineWidthHalf > max_x) {
max_x = x + lineWidthHalf;
}
if (y + lineWidthHalf > max_y) {
max_y = y + lineWidthHalf;
if (!edgeBounds) {
if (x + lineWidthHalf > max_x) {
max_x = x + lineWidthHalf;
}
if (y + lineWidthHalf > max_y) {
max_y = y + lineWidthHalf;
}
}
if (r.isMove()) {
started = true;
@@ -170,11 +175,13 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
min_x = x;
}
if (y - lineWidthHalf < min_y) {
min_y = y - lineWidthHalf;
}
if (x - lineWidthHalf < min_x) {
min_x = x - lineWidthHalf;
if (!edgeBounds) {
if (y - lineWidthHalf < min_y) {
min_y = y - lineWidthHalf;
}
if (x - lineWidthHalf < min_x) {
min_x = x - lineWidthHalf;
}
}
}
}
@@ -206,7 +213,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
lsa.lineStyles = new LINESTYLE[0];
lsa.lineStyles2 = new LINESTYLE2[0];
for (SHAPE s : shapes) {
RECT r = SHAPERECORD.getBounds(s.shapeRecords, lsa, shapeNum);
RECT r = SHAPERECORD.getBounds(s.shapeRecords, lsa, shapeNum, false);
if (r.Xmax < r.Xmin || r.Ymax < r.Ymin) {
continue;
}
@@ -262,7 +269,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
// shapeNum: 1
SHAPE shape = shapes.get(pos);
List<SHAPERECORD> records = shape.shapeRecords;
RECT bounds = SHAPERECORD.getBounds(records, lsa, shapeNum);
RECT bounds = SHAPERECORD.getBounds(records, lsa, shapeNum, false);
int w1 = bounds.getWidth();
int h1 = bounds.getHeight();