修正排版

This commit is contained in:
2026-09-07 15:09:46 +08:00
parent 666b3e0c16
commit 22e7c008ef
2 changed files with 491 additions and 138 deletions
+21 -7
View File
@@ -373,17 +373,20 @@
mid = mid[0].split("暨");
mid[0] = mid[0] + "暨";
}
const init_fontSize = Number(d.fontSize) > 40 ? 40 : Number(d.fontSize);
//const init_size_px = init_fontSize * 1.333;
// 1. 初始判定與特例條件計算
let items = mid.map(name => {
let l = name.length;
let isShort = (l * 40) <= (th + (v_gap / 2));
//應該用初始最大值而不是40
let isShort = (l * init_fontSize) <= (th + (v_gap / 2));
return { name: name, l: l, isShort: isShort, isMulti: false, size: 0 };
});
let maxShortLen = Math.max(...items.filter(x => x.isShort).map(x => x.l), 1);
let allShort = items.every(x => x.isShort);
console.log("全短名:",items,allShort);
// 🚀 動態防呆:不寫死字數!用「實際字體大小」計算是否放得進半高。
// 這樣 13 個字會自動出局,而 3 個字的小牌位絕對能穩穩過關。
@@ -417,7 +420,7 @@
// 壓縮高度釋放空間 (支援反向放大字體)
if (isSpecial) {
if (isSpecial1 || isSpecial2) item_h = h / 2;
if (isSpecial4) item_h = (h / 2) - (v_gap / 2);
if (isSpecial4) item_h = (h / 2) - (v_gap )-2;
} else {
let natural_h = maxShortLen * size_px;
if (item_h > natural_h * 1.5) {
@@ -469,7 +472,18 @@
sizes = items.map(x => {
let final_s = x.size;
if (x.isShort) {
let max_s_for_th = Math.floor(th / (maxShortLen * 1.333));
//let max_s_for_th = Math.floor(th / (maxShortLen * 1.333));
//if (final_s > max_s_for_th) {
// final_s = max_s_for_th;
//}
// 🚀 關鍵修正:依照是否為特例,賦予實際可用的高度上限,解除原先 th 造成的字體壓抑
let available_h = th;
if (isSpecial) {
if (isSpecial1 || isSpecial2) available_h = h / 2;
if (isSpecial4) available_h = (h / 2) - v_gap - 2;
}
let max_s_for_th = Math.floor(available_h / (maxShortLen * 1.333));
if (final_s > max_s_for_th) {
final_s = max_s_for_th;
}
@@ -511,9 +525,9 @@
let flexDir = isSpecial2 ? "column" : "row";
let flexJustify = isSpecial ? "center" : "flex-start";
let flexAlign = "center";
if (isSpecial4) {
v_gap=Number(h)/4
}
//if (isSpecial4) {
// v_gap=Number(h)/4
//}
let $namelist = $(`<div class='nameList'></div>`).css({
"writing-mode": "vertical-rl",