refactor: font size and split fields
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import type { Dimensions } from '../types';
|
||||
|
||||
export interface DimensionOptions {
|
||||
size: string;
|
||||
sizeW: number;
|
||||
sizeH: number;
|
||||
bleed: string;
|
||||
padding: string;
|
||||
grid: string;
|
||||
gridW: number;
|
||||
gridH: number;
|
||||
fontSize?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析卡牌尺寸和网格配置
|
||||
*/
|
||||
export function calculateDimensions(options: DimensionOptions): Dimensions {
|
||||
const [width, height] = options.size.split('x').map(Number);
|
||||
const [bleedW, bleedH] = options.bleed.includes('x')
|
||||
? options.bleed.split('x').map(Number)
|
||||
: [Number(options.bleed), Number(options.bleed)];
|
||||
@@ -20,19 +22,16 @@ export function calculateDimensions(options: DimensionOptions): Dimensions {
|
||||
: [Number(options.padding), Number(options.padding)];
|
||||
|
||||
// 实际卡牌尺寸(含出血)
|
||||
const cardWidth = width + bleedW * 2;
|
||||
const cardHeight = height + bleedH * 2;
|
||||
const cardWidth = options.sizeW + bleedW * 2;
|
||||
const cardHeight = options.sizeH + bleedH * 2;
|
||||
|
||||
// 网格区域尺寸(减去 padding)
|
||||
const gridAreaWidth = width - padW * 2;
|
||||
const gridAreaHeight = height - padH * 2;
|
||||
|
||||
// 解析网格
|
||||
const [gridW, gridH] = options.grid.split('x').map(Number);
|
||||
const gridAreaWidth = options.sizeW - padW * 2;
|
||||
const gridAreaHeight = options.sizeH - padH * 2;
|
||||
|
||||
// 每个网格单元的尺寸(mm)
|
||||
const cellWidth = gridAreaWidth / gridW;
|
||||
const cellHeight = gridAreaHeight / gridH;
|
||||
const cellWidth = gridAreaWidth / options.gridW;
|
||||
const cellHeight = gridAreaHeight / options.gridH;
|
||||
|
||||
// 网格区域起点(相对于卡牌左上角,含 bleed 和 padding)
|
||||
const gridOriginX = bleedW + padW;
|
||||
@@ -45,10 +44,11 @@ export function calculateDimensions(options: DimensionOptions): Dimensions {
|
||||
gridAreaHeight,
|
||||
cellWidth,
|
||||
cellHeight,
|
||||
gridW,
|
||||
gridH,
|
||||
gridW: options.gridW,
|
||||
gridH: options.gridH,
|
||||
gridOriginX,
|
||||
gridOriginY
|
||||
gridOriginY,
|
||||
fontSize: options.fontSize ?? 3
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user