Minimum stroke width should be 1 px

This commit is contained in:
Jindra Petřík
2022-10-25 20:32:25 +02:00
parent 691f296a55
commit db60fed17f
8 changed files with 19 additions and 17 deletions

View File

@@ -97,7 +97,7 @@ public class BitmapExporter extends ShapeExporterBase {
private double thicknessScaleX;
private double thicknessScaleY;
private double realZoom;
private double unzoom;
private static boolean linearGradientColorWarnignShown = false;
@@ -154,9 +154,9 @@ public class BitmapExporter extends ShapeExporterBase {
}
}
public static void export(int shapeNum, SWF swf, SHAPE shape, Color defaultColor, SerializableImage image, Matrix transformation, Matrix strokeTransformation, ColorTransform colorTransform, boolean scaleStrokes) {
public static void export(int shapeNum, SWF swf, SHAPE shape, Color defaultColor, SerializableImage image, double unzoom, Matrix transformation, Matrix strokeTransformation, ColorTransform colorTransform, boolean scaleStrokes) {
BitmapExporter exporter = new BitmapExporter(shapeNum, swf, shape, defaultColor, colorTransform);
exporter.exportTo(image, transformation, strokeTransformation, scaleStrokes);
exporter.exportTo(image, unzoom, transformation, strokeTransformation, scaleStrokes);
}
private BitmapExporter(int shapeNum, SWF swf, SHAPE shape, Color defaultColor, ColorTransform colorTransform) {
@@ -165,7 +165,7 @@ public class BitmapExporter extends ShapeExporterBase {
this.defaultColor = defaultColor;
}
private void exportTo(SerializableImage image, Matrix transformation, Matrix strokeTransformation, boolean scaleStrokes) {
private void exportTo(SerializableImage image, double unzoom, Matrix transformation, Matrix strokeTransformation, boolean scaleStrokes) {
this.image = image;
this.scaleStrokes = scaleStrokes;
ExportRectangle bounds = new ExportRectangle(shape.getBounds());
@@ -177,6 +177,7 @@ public class BitmapExporter extends ShapeExporterBase {
at.preConcatenate(AffineTransform.getScaleInstance(1 / SWF.unitDivisor, 1 / SWF.unitDivisor));
graphics.setTransform(at);
defaultStroke = graphics.getStroke();
this.unzoom = unzoom;
super.export();
}
@@ -187,10 +188,11 @@ public class BitmapExporter extends ShapeExporterBase {
thicknessScaleX = Math.abs(p11.x - p00.x);
thicknessScaleY = Math.abs(p11.y - p00.y);
Matrix transPre = transformation.preConcatenate(Matrix.getScaleInstance(1 / SWF.unitDivisor, 1 / SWF.unitDivisor));
/*Matrix transPre = transformation.preConcatenate(Matrix.getScaleInstance(1 / SWF.unitDivisor, 1 / SWF.unitDivisor));
p00 = transPre.transform(0, 0);
p11 = transPre.transform(1, 1);
realZoom = p00.distanceTo(p11);
realZoom = p00.distanceTo(p11) / Math.sqrt(2);
System.out.println("realZoom=" + realZoom);*/
}
public SerializableImage getImage() {
@@ -427,10 +429,9 @@ public class BitmapExporter extends ShapeExporterBase {
}
}
//always display minimum strokem of 1 pixel, no matter how zoomed it is
if (thickness * realZoom < 1) {
//thickness = 1 / realZoom;
//TODO: fix for #1684
//always display minimum stroke of 1 pixel, no matter how zoomed it is
if (thickness * unzoom < 1 * SWF.unitDivisor) {
thickness = 1 * SWF.unitDivisor / unzoom;
}
if (joinStyle == BasicStroke.JOIN_MITER) {

View File

@@ -1149,7 +1149,7 @@ public class SvgImporter {
st = (DefineShape4Tag) (new SvgImporter().importSvg(st, svgDataS, false));
swf.addTag(st);
SerializableImage si = new SerializableImage(480, 360, BufferedImage.TYPE_4BYTE_ABGR);
BitmapExporter.export(st.getShapeNum(), swf, st.shapes, Color.yellow, si, new Matrix(), new Matrix(), null, true);
BitmapExporter.export(st.getShapeNum(), swf, st.shapes, Color.yellow, si, 1, new Matrix(), new Matrix(), null, true);
List<Tag> li = new ArrayList<>();
li.add(st);
ImageIO.write(si.getBufferedImage(), "PNG", new File(name + ".imported.png"));

View File

@@ -234,7 +234,7 @@ public abstract class ImageTag extends DrawableTag {
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, SerializableImage fullImage, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes, int drawMode) {
BitmapExporter.export(1, swf, getShape(), null, image, transformation, strokeTransformation, colorTransform, true);
BitmapExporter.export(1, swf, getShape(), null, image, unzoom, transformation, strokeTransformation, colorTransform, true);
}
@Override

View File

@@ -320,7 +320,7 @@ public abstract class MorphShapeTag extends DrawableTag {
// todo: Currently the generated image is not cached, because the cache
// key contains the hashCode of the finalRecord object, and it is always
// recreated
BitmapExporter.export(getShapeNum() == 2 ? 4 : 1, swf, shape, null, image, transformation, strokeTransformation, colorTransform, scaleStrokes);
BitmapExporter.export(getShapeNum() == 2 ? 4 : 1, swf, shape, null, image, unzoom, transformation, strokeTransformation, colorTransform, scaleStrokes);
}
@Override

View File

@@ -191,7 +191,7 @@ public abstract class ShapeTag extends DrawableTag implements LazyObject {
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, SerializableImage fullImage, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes, int drawMode) {
BitmapExporter.export(getShapeNum(), swf, getShapes(), null, image, transformation, strokeTransformation, colorTransform, scaleStrokes);
BitmapExporter.export(getShapeNum(), swf, getShapes(), null, image, unzoom, transformation, strokeTransformation, colorTransform, scaleStrokes);
if (Configuration._debugMode.get()) { // show control points
List<GeneralPath> paths = PathExporter.export(getShapeNum(), swf, getShapes());
double[] coords = new double[6];

View File

@@ -422,7 +422,7 @@ public abstract class TextTag extends DrawableTag {
Graphics2D g = (Graphics2D) image.getGraphics();
Matrix mat = transformation.clone();
mat = mat.concatenate(new Matrix(textMatrix));
BitmapExporter.export(1, swf, getBorderShape(borderColor, fillColor, rect), null, image, mat, mat, colorTransform, true);
BitmapExporter.export(1, swf, getBorderShape(borderColor, fillColor, rect), null, image, 1 /*FIXME??*/, mat, mat, colorTransform, true);
}
public static void drawBorderHtmlCanvas(SWF swf, StringBuilder result, RGB borderColor, RGB fillColor, RECT rect, MATRIX textMatrix, ColorTransform colorTransform, double unitDivisor) {
@@ -512,7 +512,7 @@ public abstract class TextTag extends DrawableTag {
}
if (shape != null) {
BitmapExporter.export(1, swf, shape, textColor2, image, mat, mat, colorTransform, true);
BitmapExporter.export(1, swf, shape, textColor2, image, 1 /*FIXME??*/, mat, mat, colorTransform, true);
if (SHAPERECORD.DRAW_BOUNDING_BOX) {
RGB borderColor = new RGBA(Color.black);
RGB fillColor = new RGBA(new Color(255, 255, 255, 0));

View File

@@ -219,7 +219,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
Matrix transformation = Matrix.getTranslateInstance(px, py);
transformation.scale(ratio);
BitmapExporter.export(shapeNum, swf, shape, color, image, transformation, transformation, colorTransform, true);
BitmapExporter.export(shapeNum, swf, shape, color, image, 1 /*FIXME??*/, transformation, transformation, colorTransform, true);
// draw bounding boxes
if (DRAW_BOUNDING_BOX) {