|
|
|
@ -10,23 +10,23 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
@Slf4j |
|
|
|
@Data |
|
|
|
public class CoordinateTransformer { |
|
|
|
|
|
|
|
|
|
|
|
private String orientation; |
|
|
|
private CanvasSize canvasSize; |
|
|
|
private TransformConfig config; |
|
|
|
|
|
|
|
|
|
|
|
public CoordinateTransformer(String orientation, CanvasSize canvasSize) { |
|
|
|
this.orientation = orientation != null ? orientation : "portrait"; |
|
|
|
this.canvasSize = canvasSize; |
|
|
|
this.config = getConfig(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取转换配置 |
|
|
|
*/ |
|
|
|
private TransformConfig getConfig() { |
|
|
|
TransformConfig config = new TransformConfig(); |
|
|
|
|
|
|
|
|
|
|
|
if ("landscape".equals(this.orientation)) { |
|
|
|
config.setScaleX(1.0); |
|
|
|
config.setScaleY(1.0); |
|
|
|
@ -39,10 +39,10 @@ public class CoordinateTransformer { |
|
|
|
config.setOffsetX(0.0); |
|
|
|
config.setOffsetY(0.0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return config; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 将画布坐标转换为ZPL坐标 |
|
|
|
*/ |
|
|
|
@ -53,14 +53,15 @@ public class CoordinateTransformer { |
|
|
|
(int) Math.round(canvasY * config.getScaleY()) |
|
|
|
); |
|
|
|
} else { |
|
|
|
int width = canvasSize.getWidth(); |
|
|
|
// 横向打印需要坐标旋转变换 |
|
|
|
return new ZplCoordinate( |
|
|
|
(int) Math.round(canvasX * config.getScaleX()), |
|
|
|
(int) Math.round(canvasY * config.getScaleY()) |
|
|
|
(int) Math.round(canvasY * config.getScaleX()), |
|
|
|
(int) Math.round((width-canvasX-100) * config.getScaleY()) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 将ZPL坐标转换为画布坐标 |
|
|
|
*/ |
|
|
|
@ -78,14 +79,14 @@ public class CoordinateTransformer { |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 验证坐标是否在画布范围内 |
|
|
|
*/ |
|
|
|
public boolean isInBounds(int x, int y) { |
|
|
|
return x >= 0 && x <= canvasSize.getWidth() && y >= 0 && y <= canvasSize.getHeight(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 将坐标限制在画布范围内 |
|
|
|
*/ |
|
|
|
@ -95,7 +96,7 @@ public class CoordinateTransformer { |
|
|
|
Math.max(0, Math.min(y, canvasSize.getHeight() - elementHeight)) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 画布尺寸 |
|
|
|
*/ |
|
|
|
@ -105,7 +106,7 @@ public class CoordinateTransformer { |
|
|
|
private int height; |
|
|
|
private String name; |
|
|
|
private String description; |
|
|
|
|
|
|
|
|
|
|
|
public CanvasSize(int width, int height, String name, String description) { |
|
|
|
this.width = width; |
|
|
|
this.height = height; |
|
|
|
@ -113,7 +114,7 @@ public class CoordinateTransformer { |
|
|
|
this.description = description; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 转换配置 |
|
|
|
*/ |
|
|
|
@ -124,7 +125,7 @@ public class CoordinateTransformer { |
|
|
|
private double offsetX; |
|
|
|
private double offsetY; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* ZPL坐标 |
|
|
|
*/ |
|
|
|
@ -132,13 +133,13 @@ public class CoordinateTransformer { |
|
|
|
public static class ZplCoordinate { |
|
|
|
private int x; |
|
|
|
private int y; |
|
|
|
|
|
|
|
|
|
|
|
public ZplCoordinate(int x, int y) { |
|
|
|
this.x = x; |
|
|
|
this.y = y; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 画布坐标 |
|
|
|
*/ |
|
|
|
@ -146,10 +147,10 @@ public class CoordinateTransformer { |
|
|
|
public static class CanvasCoordinate { |
|
|
|
private int x; |
|
|
|
private int y; |
|
|
|
|
|
|
|
|
|
|
|
public CanvasCoordinate(int x, int y) { |
|
|
|
this.x = x; |
|
|
|
this.y = y; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |