排版
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
}*/
|
||||
html, body, form, .full-home, #printArea, .canvas-area {
|
||||
height: auto !important;
|
||||
width: 210mm !important;
|
||||
width: auto !important;
|
||||
overflow: visible !important; /*必須為 visible */
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
@@ -107,7 +107,7 @@
|
||||
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
|
||||
],
|
||||
async init() {
|
||||
console.log("init");
|
||||
|
||||
let HTTP_HOST = "<%=UrlHost()%>";
|
||||
this.http_host = HTTP_HOST;
|
||||
await Promise.all([
|
||||
@@ -197,13 +197,25 @@
|
||||
render() {
|
||||
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 nowPageWidth = 0;
|
||||
let tabletpaper;
|
||||
this.printData.forEach(x => {
|
||||
let style = this.allStyle.find(y => y.styleID == x.style);
|
||||
console.log("style:", style);
|
||||
let size = this.allSize.find(y => y.paperID == style.paperSize);
|
||||
let style = self.allStyle.find(y => y.styleID == x.style);
|
||||
|
||||
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>`)
|
||||
let img = self.bg.find(y => y.name == style.backendImg);
|
||||
tabletpaper.css({
|
||||
@@ -221,17 +233,20 @@
|
||||
|
||||
let mid_items = tablet.mid_items;
|
||||
let left_items = tablet.left_items;
|
||||
console.log("mid_items:", mid_items)
|
||||
|
||||
let details = this.allStyleDetails.filter(y => y.styleID == x.style);
|
||||
let mid = [];
|
||||
mid_items.forEach(y => {
|
||||
mid.push(y.fam_name);
|
||||
});
|
||||
|
||||
console.log("details:", details);
|
||||
details.forEach(d => {
|
||||
if (d.isActive != "hidden") {
|
||||
console.log(d);
|
||||
//console.log(d);
|
||||
let { newFontSize, newTxtWidth } = self.scaleFontSize(mid, style, d)
|
||||
let html = "";
|
||||
if (d.elementID = 'title1') {
|
||||
if (d.elementID === 'title1') {
|
||||
let $namelist = $(`<div class='nameList'></div>`).css({
|
||||
"writing-mode": "vertical rl",
|
||||
display: "flex",
|
||||
@@ -242,24 +257,29 @@
|
||||
height: `${d.height}px`,
|
||||
border: "0px solid #ccc",
|
||||
padding: "1px",
|
||||
"font-family": "Kaiti",
|
||||
"font-family": "DFKai-sb",
|
||||
"letter-spacing": "0.1em",
|
||||
"column-gap": "1px",
|
||||
"row-gap": "1px",
|
||||
"align-items": "center",
|
||||
"justify-content":"center"
|
||||
});
|
||||
|
||||
mid.forEach(z => {
|
||||
|
||||
let $span = $(`<span>${z}</span>`).css({
|
||||
display: "block",
|
||||
"min-height": `${d.textHeight}px`,
|
||||
"max-height": `${d.height}px`,
|
||||
width: `${d.textWidth}px`,
|
||||
//width: newTxtWidth +"px", //`${d.textWidth}px`,
|
||||
"text-align": "justify",
|
||||
"text-align-last": "justify",
|
||||
"margin-bottom": "20px",
|
||||
"margin-left": "5px",
|
||||
"text-justify": "inter-character",
|
||||
//"font-size": newFontSize + "px",
|
||||
"z-index": 10000,
|
||||
"word-break": "break-all"
|
||||
});
|
||||
$namelist.append($span);
|
||||
});
|
||||
@@ -267,28 +287,29 @@
|
||||
html = $namelist;
|
||||
}
|
||||
|
||||
console.log(mid, newFontSize, newTxtWidth)
|
||||
let content = $(`<div class="tablet-element vertical-text "></div>`)
|
||||
.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
|
||||
})
|
||||
.html(html);
|
||||
tabletpaper.append(content);
|
||||
html = "";
|
||||
}
|
||||
|
||||
})
|
||||
$(canvas).append(tabletpaper);
|
||||
console.log(size.width,size.height);
|
||||
|
||||
let pageStyle = `<style id="pageStyle">
|
||||
|
||||
|
||||
@media print{
|
||||
:host {
|
||||
width:auto !important;
|
||||
height:auto !important;
|
||||
}
|
||||
@page {
|
||||
size:210mm 297mm !important;
|
||||
size:297mm 210mm landscape !important;
|
||||
margin:0;
|
||||
}
|
||||
.tablet-paper {
|
||||
@@ -301,45 +322,49 @@
|
||||
margin: 0 !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();
|
||||
$("head").append(pageStyle
|
||||
);
|
||||
$(canvas).css("width", "210" + "mm");
|
||||
$(canvas).css("height","297"+ "mm");
|
||||
$("head").append(pageStyle);
|
||||
|
||||
$(canvas).append(tabletpaper);
|
||||
$(canvas).css("width", "297" + "mm");
|
||||
$(canvas).css("height", "210" + "mm");
|
||||
$("#printArea").append(canvas);
|
||||
//this.bindKeyEvent();
|
||||
});
|
||||
$(".tablet-element").draggable({
|
||||
start(e, ui) {
|
||||
console.log("gogogogo");
|
||||
//console.log("gogogogo");
|
||||
},
|
||||
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) {
|
||||
e.preventDefault();
|
||||
console.log(this);
|
||||
self.selected = $(this);
|
||||
let fontSize = $(this).css("fontSize");
|
||||
let fontFamily = $(this).css("fontFamily");
|
||||
let left = $(this).css("left");
|
||||
let top = $(this).css("top");
|
||||
console.log(fontSize, fontFamily, left, top);
|
||||
});
|
||||
|
||||
$(".tablet-element").on("contextmenu", function (e) {
|
||||
e.preventDefault();
|
||||
console.log(this);
|
||||
self.selected = $(this);
|
||||
let fontSize = $(this).css("fontSize");
|
||||
let fontFamily = $(this).css("fontFamily");
|
||||
let textWidth = $(this).find("span").first().css("width");
|
||||
let left = $(this).css("left");
|
||||
let top = $(this).css("top");
|
||||
console.log(fontSize, fontFamily, left, top);
|
||||
$("#customMenu").css({
|
||||
top: e.pageY + "px",
|
||||
left: (e.pageX + 30) + "px"
|
||||
@@ -349,16 +374,69 @@
|
||||
$("#textX").val(self.fix2(left * 0.265));
|
||||
$("#textY").val(self.fix2(top * 0.265));
|
||||
$("#fontSize").val(fontSize);
|
||||
//$("#textWidth").val("");
|
||||
// Show the custom div
|
||||
$("#textWidth").val(textWidth);
|
||||
$("#customMenu").show();
|
||||
});
|
||||
},
|
||||
fix2(val) {
|
||||
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() {
|
||||
console.log(this.selected);
|
||||
$(this.selected).css("left", $("#textX").val() + "mm");
|
||||
$(this.selected).css("top", $("#textY").val() + "mm");
|
||||
},
|
||||
@@ -367,11 +445,9 @@
|
||||
},
|
||||
async changeWidth() {
|
||||
let nameList = $(this.selected).find(".nameList").first();
|
||||
console.log("nameList:", nameList);
|
||||
|
||||
if (nameList) {
|
||||
let spans = $(nameList).find("span");
|
||||
console.log(spans);
|
||||
if (spans) {
|
||||
spans.each(function (index, x) {
|
||||
$(x).css("width", $("#textWidth").val())
|
||||
@@ -441,7 +517,7 @@
|
||||
/* 關鍵:修正 Ctrl+P 空白問題 */
|
||||
@media print {
|
||||
@page {
|
||||
size: 210mm 272mm portrait;
|
||||
size: 297mm 210mm landscape;
|
||||
margin: 0;
|
||||
}
|
||||
html, body, form, .full-home, #printArea, .canvas-area {
|
||||
|
||||
Reference in New Issue
Block a user