refactor: layer alignment
This commit is contained in:
@@ -3,15 +3,15 @@ import {CSV} from "../../utils/csv-loader";
|
||||
|
||||
/**
|
||||
* 解析 layers 字符串
|
||||
* 格式:body:1,7-5,8 title:1,1-4,1f6.6s
|
||||
* f[fontSize] 表示字体大小(可选),方向字母在最后(可选)
|
||||
* 格式:body:1,7-5,8 title:1,1-4,1f6.6sl
|
||||
* f[fontSize] 表示字体大小(可选),方向字母(可选),对齐字母 l/c/r(可选)
|
||||
*/
|
||||
export function parseLayers(layersStr: string): Layer[] {
|
||||
if (!layersStr) return [];
|
||||
|
||||
const layers: Layer[] = [];
|
||||
// 匹配:prop:x1,y1-x2,y2[ffontSize][direction]
|
||||
const regex = /(\w+):(\d+),(\d+)-(\d+),(\d+)(?:f([\d.]+))?([nsew])?/g;
|
||||
// 匹配:prop:x1,y1-x2,y2[ffontSize][direction][align]
|
||||
const regex = /(\w+):(\d+),(\d+)-(\d+),(\d+)(?:f([\d.]+))?([nsew])?([lcr])?/g;
|
||||
let match;
|
||||
|
||||
while ((match = regex.exec(layersStr)) !== null) {
|
||||
@@ -22,7 +22,8 @@ export function parseLayers(layersStr: string): Layer[] {
|
||||
x2: parseInt(match[4]),
|
||||
y2: parseInt(match[5]),
|
||||
fontSize: match[6] ? parseFloat(match[6]) : undefined,
|
||||
orientation: match[7] as 'n' | 's' | 'e' | 'w' | undefined
|
||||
orientation: match[7] as 'n' | 's' | 'e' | 'w' | undefined,
|
||||
align: match[8] as 'l' | 'c' | 'r' | undefined
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,6 +44,9 @@ export function formatLayers(layers: LayerConfig[]): string {
|
||||
if (l.orientation && l.orientation !== 'n') {
|
||||
str += l.orientation;
|
||||
}
|
||||
if (l.align) {
|
||||
str += l.align;
|
||||
}
|
||||
return str;
|
||||
})
|
||||
.join(' ');
|
||||
@@ -68,7 +72,8 @@ export function initLayerConfigsForSide(
|
||||
x2: existing?.x2 || 2,
|
||||
y2: existing?.y2 || 2,
|
||||
orientation: existing?.orientation,
|
||||
fontSize: existing?.fontSize
|
||||
fontSize: existing?.fontSize,
|
||||
align: existing?.align
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user