排版
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
}*/
|
}*/
|
||||||
html, body, form, .full-home, #printArea, .canvas-area {
|
html, body, form, .full-home, #printArea, .canvas-area {
|
||||||
height: auto !important;
|
height: auto !important;
|
||||||
width: 210mm !important;
|
width: auto !important;
|
||||||
overflow: visible !important; /*必須為 visible */
|
overflow: visible !important; /*必須為 visible */
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
|
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
|
||||||
],
|
],
|
||||||
async init() {
|
async init() {
|
||||||
console.log("init");
|
|
||||||
let HTTP_HOST = "<%=UrlHost()%>";
|
let HTTP_HOST = "<%=UrlHost()%>";
|
||||||
this.http_host = HTTP_HOST;
|
this.http_host = HTTP_HOST;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@@ -197,13 +197,25 @@
|
|||||||
render() {
|
render() {
|
||||||
let self = this;
|
let self = this;
|
||||||
let canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-row align-items-center position-relative" ></div>`)
|
let canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-row align-items-center position-relative" ></div>`)
|
||||||
|
let nowPageWidth = 0;
|
||||||
|
let tabletpaper;
|
||||||
this.printData.forEach(x => {
|
this.printData.forEach(x => {
|
||||||
let style = this.allStyle.find(y => y.styleID == x.style);
|
let style = self.allStyle.find(y => y.styleID == x.style);
|
||||||
console.log("style:", style);
|
|
||||||
let size = this.allSize.find(y => y.paperID == style.paperSize);
|
|
||||||
|
|
||||||
|
let size = self.allSize.find(y => y.paperID == style.paperSize);
|
||||||
|
|
||||||
let tabletpaper = $(` <div class="tablet-paper">
|
if ((nowPageWidth + parseFloat(size.width)) > 297) {
|
||||||
|
$(canvas).css("width", "297" + "mm");
|
||||||
|
$(canvas).css("height", "210" + "mm");
|
||||||
|
$(canvas).css("break-after", "page");
|
||||||
|
$(canvas).css("page-break-after", "always");
|
||||||
|
$(canvas).append(tabletpaper);
|
||||||
|
$("#printArea").append(canvas);
|
||||||
|
canvas = $(` <div class="canvas-area flex-grow-1 overflow-auto d-flex flex-row align-items-center position-relative" ></div>`)
|
||||||
|
nowPageWidth = 0;
|
||||||
|
}
|
||||||
|
nowPageWidth = nowPageWidth + parseFloat(size.width);
|
||||||
|
tabletpaper = $(` <div class="tablet-paper">
|
||||||
</div>`)
|
</div>`)
|
||||||
let img = self.bg.find(y => y.name == style.backendImg);
|
let img = self.bg.find(y => y.name == style.backendImg);
|
||||||
tabletpaper.css({
|
tabletpaper.css({
|
||||||
@@ -221,17 +233,20 @@
|
|||||||
|
|
||||||
let mid_items = tablet.mid_items;
|
let mid_items = tablet.mid_items;
|
||||||
let left_items = tablet.left_items;
|
let left_items = tablet.left_items;
|
||||||
console.log("mid_items:", mid_items)
|
|
||||||
let details = this.allStyleDetails.filter(y => y.styleID == x.style);
|
let details = this.allStyleDetails.filter(y => y.styleID == x.style);
|
||||||
let mid = [];
|
let mid = [];
|
||||||
mid_items.forEach(y => {
|
mid_items.forEach(y => {
|
||||||
mid.push(y.fam_name);
|
mid.push(y.fam_name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("details:", details);
|
||||||
details.forEach(d => {
|
details.forEach(d => {
|
||||||
if (d.isActive != "hidden") {
|
if (d.isActive != "hidden") {
|
||||||
console.log(d);
|
//console.log(d);
|
||||||
|
let { newFontSize, newTxtWidth } = self.scaleFontSize(mid, style, d)
|
||||||
let html = "";
|
let html = "";
|
||||||
if (d.elementID = 'title1') {
|
if (d.elementID === 'title1') {
|
||||||
let $namelist = $(`<div class='nameList'></div>`).css({
|
let $namelist = $(`<div class='nameList'></div>`).css({
|
||||||
"writing-mode": "vertical rl",
|
"writing-mode": "vertical rl",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -242,24 +257,29 @@
|
|||||||
height: `${d.height}px`,
|
height: `${d.height}px`,
|
||||||
border: "0px solid #ccc",
|
border: "0px solid #ccc",
|
||||||
padding: "1px",
|
padding: "1px",
|
||||||
"font-family": "Kaiti",
|
"font-family": "DFKai-sb",
|
||||||
"letter-spacing": "0.1em",
|
"letter-spacing": "0.1em",
|
||||||
"column-gap": "1px",
|
"column-gap": "1px",
|
||||||
"row-gap": "1px",
|
"row-gap": "1px",
|
||||||
"align-items": "center",
|
"align-items": "center",
|
||||||
|
"justify-content":"center"
|
||||||
});
|
});
|
||||||
|
|
||||||
mid.forEach(z => {
|
mid.forEach(z => {
|
||||||
|
|
||||||
let $span = $(`<span>${z}</span>`).css({
|
let $span = $(`<span>${z}</span>`).css({
|
||||||
display: "block",
|
display: "block",
|
||||||
"min-height": `${d.textHeight}px`,
|
"min-height": `${d.textHeight}px`,
|
||||||
"max-height": `${d.height}px`,
|
"max-height": `${d.height}px`,
|
||||||
width: `${d.textWidth}px`,
|
//width: newTxtWidth +"px", //`${d.textWidth}px`,
|
||||||
"text-align": "justify",
|
"text-align": "justify",
|
||||||
"text-align-last": "justify",
|
"text-align-last": "justify",
|
||||||
"margin-bottom": "20px",
|
"margin-bottom": "20px",
|
||||||
"margin-left": "5px",
|
"margin-left": "5px",
|
||||||
"text-justify": "inter-character",
|
"text-justify": "inter-character",
|
||||||
|
//"font-size": newFontSize + "px",
|
||||||
"z-index": 10000,
|
"z-index": 10000,
|
||||||
|
"word-break": "break-all"
|
||||||
});
|
});
|
||||||
$namelist.append($span);
|
$namelist.append($span);
|
||||||
});
|
});
|
||||||
@@ -267,28 +287,29 @@
|
|||||||
html = $namelist;
|
html = $namelist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(mid, newFontSize, newTxtWidth)
|
||||||
let content = $(`<div class="tablet-element vertical-text "></div>`)
|
let content = $(`<div class="tablet-element vertical-text "></div>`)
|
||||||
.css({
|
.css({
|
||||||
position: "absolute", left: d.startX + "mm", top: d.startY + "mm", fontSize: d.fontSize + 'pt', fontFamily: d.fontFamily, "z-index": 9999, visibility: d.isActive
|
position: "absolute", left: d.startX + "mm", top: d.startY + "mm", fontSize: newFontSize + 'pt',
|
||||||
|
fontFamily: d.fontFamily, "font-weight": "bold", "z-index": 9999, visibility: d.isActive,
|
||||||
|
//"text-align": "justify","text-align-last": "justify",
|
||||||
//position: "absolute", left: el.startX + "mm", top: el.startY + "mm", fontSize: el.fontSize + 'pt', fontFamily: el.fontFamily, "z-index": 9999, visibility: el.isActive
|
//position: "absolute", left: el.startX + "mm", top: el.startY + "mm", fontSize: el.fontSize + 'pt', fontFamily: el.fontFamily, "z-index": 9999, visibility: el.isActive
|
||||||
})
|
})
|
||||||
.html(html);
|
.html(html);
|
||||||
tabletpaper.append(content);
|
tabletpaper.append(content);
|
||||||
|
html = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
$(canvas).append(tabletpaper);
|
|
||||||
console.log(size.width,size.height);
|
|
||||||
let pageStyle = `<style id="pageStyle">
|
let pageStyle = `<style id="pageStyle">
|
||||||
|
|
||||||
|
|
||||||
@media print{
|
@media print{
|
||||||
:host {
|
:host {
|
||||||
width:auto !important;
|
width:auto !important;
|
||||||
height:auto !important;
|
height:auto !important;
|
||||||
}
|
}
|
||||||
@page {
|
@page {
|
||||||
size:210mm 297mm !important;
|
size:297mm 210mm landscape !important;
|
||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
.tablet-paper {
|
.tablet-paper {
|
||||||
@@ -301,45 +322,49 @@
|
|||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
}
|
}
|
||||||
|
.tablet-paper .tablet-element .nameList{
|
||||||
|
justify-content:center !important;
|
||||||
|
}
|
||||||
|
.tablet-paper .tablet-element span{
|
||||||
|
word-break: break-all !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
$("#pageStyle").remove();
|
$("#pageStyle").remove();
|
||||||
$("head").append(pageStyle
|
$("head").append(pageStyle);
|
||||||
);
|
|
||||||
$(canvas).css("width", "210" + "mm");
|
$(canvas).append(tabletpaper);
|
||||||
$(canvas).css("height","297"+ "mm");
|
$(canvas).css("width", "297" + "mm");
|
||||||
|
$(canvas).css("height", "210" + "mm");
|
||||||
$("#printArea").append(canvas);
|
$("#printArea").append(canvas);
|
||||||
//this.bindKeyEvent();
|
//this.bindKeyEvent();
|
||||||
});
|
});
|
||||||
$(".tablet-element").draggable({
|
$(".tablet-element").draggable({
|
||||||
start(e, ui) {
|
start(e, ui) {
|
||||||
console.log("gogogogo");
|
//console.log("gogogogo");
|
||||||
},
|
},
|
||||||
stop(e, ui) {
|
stop(e, ui) {
|
||||||
console.log(ui.position.left, ui.position.top);
|
//console.log(ui.position.left, ui.position.top);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".tablet-element").on("click", function (e) {
|
$(".tablet-element").on("click", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(this);
|
|
||||||
self.selected = $(this);
|
self.selected = $(this);
|
||||||
let fontSize = $(this).css("fontSize");
|
let fontSize = $(this).css("fontSize");
|
||||||
let fontFamily = $(this).css("fontFamily");
|
let fontFamily = $(this).css("fontFamily");
|
||||||
let left = $(this).css("left");
|
let left = $(this).css("left");
|
||||||
let top = $(this).css("top");
|
let top = $(this).css("top");
|
||||||
console.log(fontSize, fontFamily, left, top);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".tablet-element").on("contextmenu", function (e) {
|
$(".tablet-element").on("contextmenu", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(this);
|
|
||||||
self.selected = $(this);
|
self.selected = $(this);
|
||||||
let fontSize = $(this).css("fontSize");
|
let fontSize = $(this).css("fontSize");
|
||||||
let fontFamily = $(this).css("fontFamily");
|
let fontFamily = $(this).css("fontFamily");
|
||||||
|
let textWidth = $(this).find("span").first().css("width");
|
||||||
let left = $(this).css("left");
|
let left = $(this).css("left");
|
||||||
let top = $(this).css("top");
|
let top = $(this).css("top");
|
||||||
console.log(fontSize, fontFamily, left, top);
|
|
||||||
$("#customMenu").css({
|
$("#customMenu").css({
|
||||||
top: e.pageY + "px",
|
top: e.pageY + "px",
|
||||||
left: (e.pageX + 30) + "px"
|
left: (e.pageX + 30) + "px"
|
||||||
@@ -349,16 +374,69 @@
|
|||||||
$("#textX").val(self.fix2(left * 0.265));
|
$("#textX").val(self.fix2(left * 0.265));
|
||||||
$("#textY").val(self.fix2(top * 0.265));
|
$("#textY").val(self.fix2(top * 0.265));
|
||||||
$("#fontSize").val(fontSize);
|
$("#fontSize").val(fontSize);
|
||||||
//$("#textWidth").val("");
|
$("#textWidth").val(textWidth);
|
||||||
// Show the custom div
|
|
||||||
$("#customMenu").show();
|
$("#customMenu").show();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fix2(val) {
|
fix2(val) {
|
||||||
return Number.parseFloat(val).toFixed(2);
|
return Number.parseFloat(val).toFixed(2);
|
||||||
},
|
},
|
||||||
|
getTextWidth(text,font) {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
const context = canvas.getContext("2d");
|
||||||
|
context.font = font;
|
||||||
|
const metrics = context.measureText(text);
|
||||||
|
return metrics.width/2;
|
||||||
|
},
|
||||||
|
scaleFontSize(txtContent, style, dStyle) {
|
||||||
|
let newTxtWidth = dStyle.textWidth;
|
||||||
|
let newFontSize = dStyle.fontSize;
|
||||||
|
//console.log(newFontSize, newTxtWidth)
|
||||||
|
//自動判斷縮小字型的規則,要同時縮小間距
|
||||||
|
console.log("A:", dStyle, dStyle.fontSize)
|
||||||
|
if (dStyle.elementID === 'title1') {//表示是一般正名,也就是牌位正中間的一般格式,排法是上下上下
|
||||||
|
if (txtContent.length > 8) {//這要做成參數,讓使用者設定
|
||||||
|
switch (txtContent.length - 8) {
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
newTxtWidth = this.getTextWidth("講中文", (parseInt(dStyle.fontSize) - 2) + " " + "DFKai-sb");
|
||||||
|
newFontSize = (parseInt(dStyle.fontSize) - 2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
newTxtWidth = this.getTextWidth("講中文", (parseInt(dStyle.fontSize) - 4) + " " + "DFKai-sb");
|
||||||
|
newFontSize = (parseInt(dStyle.fontSize) - 4);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
newTxtWidth = this.getTextWidth("講中文", (parseInt(dStyle.fontSize) - 6) + " " + "DFKai-sb");
|
||||||
|
newFontSize = (parseInt(dStyle.fontSize) - 6);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
newTxtWidth = this.getTextWidth("講中文", (parseInt(dStyle.fontSize) - 8) + " " + "DFKai-sb");
|
||||||
|
newFontSize = (parseInt(dStyle.fontSize) - 8);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.log(txtContent,style,dStyle)
|
||||||
|
//console.log(newFontSize,newTxtWidth)
|
||||||
|
return { newFontSize, newTxtWidth }
|
||||||
|
},
|
||||||
|
breakWord(txtContent, style, dStyle) {
|
||||||
|
//自動判斷斷字
|
||||||
|
//1. by 特定字 2.by長度
|
||||||
|
|
||||||
|
},
|
||||||
async changeLocation() {
|
async changeLocation() {
|
||||||
console.log(this.selected);
|
|
||||||
$(this.selected).css("left", $("#textX").val() + "mm");
|
$(this.selected).css("left", $("#textX").val() + "mm");
|
||||||
$(this.selected).css("top", $("#textY").val() + "mm");
|
$(this.selected).css("top", $("#textY").val() + "mm");
|
||||||
},
|
},
|
||||||
@@ -367,11 +445,9 @@
|
|||||||
},
|
},
|
||||||
async changeWidth() {
|
async changeWidth() {
|
||||||
let nameList = $(this.selected).find(".nameList").first();
|
let nameList = $(this.selected).find(".nameList").first();
|
||||||
console.log("nameList:", nameList);
|
|
||||||
|
|
||||||
if (nameList) {
|
if (nameList) {
|
||||||
let spans = $(nameList).find("span");
|
let spans = $(nameList).find("span");
|
||||||
console.log(spans);
|
|
||||||
if (spans) {
|
if (spans) {
|
||||||
spans.each(function (index, x) {
|
spans.each(function (index, x) {
|
||||||
$(x).css("width", $("#textWidth").val())
|
$(x).css("width", $("#textWidth").val())
|
||||||
@@ -441,7 +517,7 @@
|
|||||||
/* 關鍵:修正 Ctrl+P 空白問題 */
|
/* 關鍵:修正 Ctrl+P 空白問題 */
|
||||||
@media print {
|
@media print {
|
||||||
@page {
|
@page {
|
||||||
size: 210mm 272mm portrait;
|
size: 297mm 210mm landscape;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
html, body, form, .full-home, #printArea, .canvas-area {
|
html, body, form, .full-home, #printArea, .canvas-area {
|
||||||
|
|||||||
Reference in New Issue
Block a user