|
@@ -41,19 +41,28 @@ export const transformPaper = (
|
|
|
|
|
|
export const getCoverPaperScale = (cover: ImageData, paperKey: PaperKey) => {
|
|
|
let pixelScale = (cover.widthRaw! / cover.width) * cover.proportion!.scale;
|
|
|
- console.log(cover.width, cover.height)
|
|
|
+ console.log(cover.width, cover.height);
|
|
|
const realPixelScale = paperConfigs[paperKey].scale;
|
|
|
return realPixelScale * pixelScale;
|
|
|
};
|
|
|
|
|
|
-export const setCoverPaperScale = (cover: ImageData, paperKey: PaperKey, scale: number) => {
|
|
|
+export const setCoverPaperScale = (
|
|
|
+ cover: ImageData,
|
|
|
+ paperKey: PaperKey,
|
|
|
+ scale: number
|
|
|
+) => {
|
|
|
const realPixelScale = paperConfigs[paperKey].scale;
|
|
|
- cover.width = cover.widthRaw! / ((scale / realPixelScale) /cover.proportion!.scale)
|
|
|
- cover.height = (cover.heightRaw! / cover.widthRaw!) * cover.width
|
|
|
- console.log(cover.width, cover.height)
|
|
|
-}
|
|
|
+ cover.width =
|
|
|
+ cover.widthRaw! / (scale / realPixelScale / cover.proportion!.scale);
|
|
|
+ cover.height = (cover.heightRaw! / cover.widthRaw!) * cover.width;
|
|
|
+ console.log(cover.width, cover.height);
|
|
|
+};
|
|
|
|
|
|
-export const genTabulationData = async (paperKey: PaperKey, compass?: number, cover?: TabCover | null) => {
|
|
|
+export const genTabulationData = async (
|
|
|
+ paperKey: PaperKey,
|
|
|
+ compass?: number,
|
|
|
+ cover?: TabCover | null
|
|
|
+) => {
|
|
|
const { margin, size } = getPaperConfig(
|
|
|
paperConfigs[paperKey].size,
|
|
|
paperConfigs[paperKey].scale
|
|
@@ -74,22 +83,21 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
fontColor: "#000000",
|
|
|
};
|
|
|
const valueColl = { ...nameColl, width: w2 };
|
|
|
+ const tableTemp: Record<string, string> =
|
|
|
+ window.platform.getTableTemp().table;
|
|
|
|
|
|
const data = {
|
|
|
...getBaseItem(),
|
|
|
- content: [
|
|
|
- [{ ...nameColl, content: "案发时间" }, valueColl],
|
|
|
- [{ ...nameColl, content: "案发地点" }, valueColl],
|
|
|
- [{ ...nameColl, content: "绘图单位" }, valueColl],
|
|
|
- [{ ...nameColl, content: "绘图人" }, valueColl],
|
|
|
- [{ ...nameColl, content: "绘图时间" }, valueColl],
|
|
|
- ],
|
|
|
+ content: Object.entries(tableTemp).map(([name, value]) => [
|
|
|
+ { ...nameColl, content: name },
|
|
|
+ { ...valueColl, content: value },
|
|
|
+ ]),
|
|
|
fontSize: getRealPixel(4, paperKey),
|
|
|
key: tableTableKey,
|
|
|
width: nameColl.width + valueColl.width,
|
|
|
height: nameColl.height * 5,
|
|
|
mat: [1, 0, 0, 1, 0, 0],
|
|
|
- fill: null
|
|
|
+ fill: null,
|
|
|
};
|
|
|
|
|
|
const pos = getFixPosition(
|
|
@@ -111,7 +119,7 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
const tableCoverScale = tableCoverWidth / tableCoverHeight;
|
|
|
|
|
|
let width: number, height: number;
|
|
|
-
|
|
|
+
|
|
|
if (rectScale > tableCoverScale) {
|
|
|
width = transformPaper(tableCoverWidth, paperKey, "a4");
|
|
|
height = width / rectScale;
|
|
@@ -136,7 +144,7 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
width,
|
|
|
height,
|
|
|
mat: [1, 0, 0, 1, 0, 0],
|
|
|
- itemName: '比例'
|
|
|
+ itemName: "比例",
|
|
|
};
|
|
|
const pos = getFixPosition(
|
|
|
{
|
|
@@ -150,13 +158,13 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
coverData.mat[5] = pos.y;
|
|
|
|
|
|
const scale = getCoverPaperScale(coverData, paperKey);
|
|
|
- setCoverPaperScale(coverData, paperKey, Math.round(scale / 10) * 10 || 10)
|
|
|
+ setCoverPaperScale(coverData, paperKey, Math.round(scale / 10) * 10 || 10);
|
|
|
return coverData;
|
|
|
};
|
|
|
|
|
|
const getCoverScale = (cover: ImageData) => {
|
|
|
const scale = (cover.widthRaw! / cover.width) * cover.proportion!.scale;
|
|
|
- console.log(cover)
|
|
|
+ console.log(cover);
|
|
|
const text = {
|
|
|
...getBaseItem(),
|
|
|
content: `1:${scale}`,
|
|
@@ -179,7 +187,7 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
const getTitle = () => {
|
|
|
const title = {
|
|
|
...getBaseItem(),
|
|
|
- content: "默认标题",
|
|
|
+ content: window.platform.getTableTemp().title,
|
|
|
width: getRealPixel(90, paperKey),
|
|
|
heihgt: getRealPixel(14.4, paperKey),
|
|
|
fontSize: getRealPixel(12, paperKey),
|
|
@@ -197,25 +205,29 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
};
|
|
|
|
|
|
const getCompass = async () => {
|
|
|
- const mat = new Transform().rotate(MathUtils.degToRad(compass!))
|
|
|
- const style =await getIconStyle('./icons/compass.svg', getRealPixel(37.3366 / 2.3, paperKey), getRealPixel(60 / 2.3, paperKey))
|
|
|
-
|
|
|
+ const mat = new Transform().rotate(MathUtils.degToRad(compass!));
|
|
|
+ const style = await getIconStyle(
|
|
|
+ "./icons/compass.svg",
|
|
|
+ getRealPixel(37.3366 / 2.3, paperKey),
|
|
|
+ getRealPixel(60 / 2.3, paperKey)
|
|
|
+ );
|
|
|
+
|
|
|
const data: IconData = {
|
|
|
...getBaseItem(),
|
|
|
...style,
|
|
|
disableDelete: true,
|
|
|
- itemName: '指南针',
|
|
|
+ itemName: "指南针",
|
|
|
coverOpcatiy: 0,
|
|
|
strokeScaleEnabled: false,
|
|
|
key: tableCompassKey,
|
|
|
mat: mat.m,
|
|
|
- name: '指南针'
|
|
|
+ name: "指南针",
|
|
|
};
|
|
|
- console.error('指南针', data)
|
|
|
-
|
|
|
+ console.error("指南针", data);
|
|
|
+
|
|
|
const pos = getFixPosition(
|
|
|
{
|
|
|
- right: getRealPixel(8, paperKey) + margin[1] ,
|
|
|
+ right: getRealPixel(8, paperKey) + margin[1],
|
|
|
top: getRealPixel(42, paperKey) + margin[2],
|
|
|
},
|
|
|
data,
|
|
@@ -224,26 +236,31 @@ export const genTabulationData = async (paperKey: PaperKey, compass?: number, co
|
|
|
data.mat[4] = pos.x;
|
|
|
data.mat[5] = pos.y;
|
|
|
return data;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
const data: DrawData = {
|
|
|
table: [getTable()],
|
|
|
text: [getTitle()],
|
|
|
- }
|
|
|
- const image = await getCover()
|
|
|
+ };
|
|
|
+ const image = await getCover();
|
|
|
if (image) {
|
|
|
- data.image = [image]
|
|
|
- data.text!.push(getCoverScale(image))
|
|
|
+ data.image = [image];
|
|
|
+ data.text!.push(getCoverScale(image));
|
|
|
}
|
|
|
if (compass !== undefined) {
|
|
|
- data.icon = [await getCompass()]
|
|
|
+ data.icon = [await getCompass()];
|
|
|
}
|
|
|
|
|
|
- return data
|
|
|
+ return data;
|
|
|
};
|
|
|
|
|
|
-export const repTabulationStore = async (paperKey: PaperKey, compass?: number, cover?: TabCover, store?: StoreData) => {
|
|
|
- const repData = await genTabulationData(paperKey, compass, cover)
|
|
|
+export const repTabulationStore = async (
|
|
|
+ paperKey: PaperKey,
|
|
|
+ compass?: number,
|
|
|
+ cover?: TabCover,
|
|
|
+ store?: StoreData
|
|
|
+) => {
|
|
|
+ const repData = await genTabulationData(paperKey, compass, cover);
|
|
|
const layer = store?.layers && store?.layers[defaultLayer];
|
|
|
|
|
|
if (!layer) {
|
|
@@ -255,51 +272,56 @@ export const repTabulationStore = async (paperKey: PaperKey, compass?: number, c
|
|
|
},
|
|
|
layers: {
|
|
|
...(store?.layers || {}),
|
|
|
- [defaultLayer]: repData
|
|
|
- }
|
|
|
- }
|
|
|
+ [defaultLayer]: repData,
|
|
|
+ },
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
if (repData.image?.length) {
|
|
|
- const imageData = repData.image[0]
|
|
|
- const images = layer.image || []
|
|
|
- const imageNdx = images.findIndex(item => item.key === imageData.key)
|
|
|
-
|
|
|
+ const imageData = repData.image[0];
|
|
|
+ const images = layer.image || [];
|
|
|
+ const imageNdx = images.findIndex((item) => item.key === imageData.key);
|
|
|
+
|
|
|
if (~imageNdx) {
|
|
|
- images[imageNdx] = imageData
|
|
|
+ images[imageNdx] = imageData;
|
|
|
images[imageNdx] = {
|
|
|
...imageData,
|
|
|
- mat: images[imageNdx].mat
|
|
|
- }
|
|
|
+ mat: images[imageNdx].mat,
|
|
|
+ };
|
|
|
} else {
|
|
|
- images.push(imageData)
|
|
|
+ images.push(imageData);
|
|
|
}
|
|
|
- layer.image = images
|
|
|
-
|
|
|
+ layer.image = images;
|
|
|
|
|
|
- const scaleData = repData.text!.find(item => item.key === tableCoverScaleKey)!
|
|
|
- const texts = layer.text || []
|
|
|
- const textNdx = texts.findIndex(item => item.key === scaleData.key)
|
|
|
+ const scaleData = repData.text!.find(
|
|
|
+ (item) => item.key === tableCoverScaleKey
|
|
|
+ )!;
|
|
|
+ const texts = layer.text || [];
|
|
|
+ const textNdx = texts.findIndex((item) => item.key === scaleData.key);
|
|
|
if (~textNdx) {
|
|
|
- texts[textNdx].content = scaleData.content
|
|
|
+ texts[textNdx].content = scaleData.content;
|
|
|
} else {
|
|
|
- texts.push(scaleData)
|
|
|
+ texts.push(scaleData);
|
|
|
}
|
|
|
- layer.text = texts
|
|
|
+ layer.text = texts;
|
|
|
}
|
|
|
if (repData.icon) {
|
|
|
- const iconData = repData.icon[0]
|
|
|
- const icons = layer.icon || []
|
|
|
- const iconNdx = icons.findIndex(item => item.key === iconData.key)
|
|
|
+ const iconData = repData.icon[0];
|
|
|
+ const icons = layer.icon || [];
|
|
|
+ const iconNdx = icons.findIndex((item) => item.key === iconData.key);
|
|
|
if (~iconNdx) {
|
|
|
- icons[iconNdx] = iconData
|
|
|
+ icons[iconNdx] = iconData;
|
|
|
} else {
|
|
|
- icons.push(iconData)
|
|
|
+ icons.push(iconData);
|
|
|
}
|
|
|
- layer.icon = icons
|
|
|
+ layer.icon = icons;
|
|
|
+ }
|
|
|
+ if (import.meta.env.DEV) {
|
|
|
+ layer.table = repData.table
|
|
|
+ layer.text = repData.text
|
|
|
}
|
|
|
|
|
|
- store.layers[defaultLayer] = layer
|
|
|
+ store.layers[defaultLayer] = layer;
|
|
|
|
|
|
return store;
|
|
|
-}
|
|
|
+};
|