Browse Source

:art: fix https://github.com/siyuan-note/siyuan/issues/6300

Vanessa 2 years ago
parent
commit
267621806a
3 changed files with 57 additions and 23 deletions
  1. 2 2
      app/pnpm-lock.yaml
  2. 54 20
      app/src/protyle/export/index.ts
  3. 1 1
      app/src/util/onGetConfig.ts

+ 2 - 2
app/pnpm-lock.yaml

@@ -1906,10 +1906,10 @@ packages:
     resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
     resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
     engines: {node: '>=14.0.0'}
     engines: {node: '>=14.0.0'}
     dependencies:
     dependencies:
-      7zip-bin: 5.1.1
       '@develar/schema-utils': 2.6.5
       '@develar/schema-utils': 2.6.5
       '@electron/universal': 1.2.1
       '@electron/universal': 1.2.1
       '@malept/flatpak-bundler': 0.4.0
       '@malept/flatpak-bundler': 0.4.0
+      7zip-bin: 5.1.1
       async-exit-hook: 2.0.1
       async-exit-hook: 2.0.1
       bluebird-lst: 1.0.9
       bluebird-lst: 1.0.9
       builder-util: 23.3.3
       builder-util: 23.3.3
@@ -2193,9 +2193,9 @@ packages:
   /builder-util/23.3.3:
   /builder-util/23.3.3:
     resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
     resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
     dependencies:
     dependencies:
-      7zip-bin: 5.1.1
       '@types/debug': 4.1.7
       '@types/debug': 4.1.7
       '@types/fs-extra': 9.0.13
       '@types/fs-extra': 9.0.13
+      7zip-bin: 5.1.1
       app-builder-bin: 4.0.0
       app-builder-bin: 4.0.0
       bluebird-lst: 1.0.9
       bluebird-lst: 1.0.9
       builder-util-runtime: 9.0.3
       builder-util-runtime: 9.0.3

+ 54 - 20
app/src/protyle/export/index.ts

@@ -63,12 +63,11 @@ export const saveExport = (option: { type: string, id: string }) => {
 /// #if !BROWSER
 /// #if !BROWSER
 const renderPDF = (id: string) => {
 const renderPDF = (id: string) => {
     const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({
     const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({
-        printBackground: true,
         landscape: false,
         landscape: false,
         margins: {
         margins: {
-            marginType: "default",
+            marginType: "0",
         },
         },
-        scaleFactor: 100,
+        scale: 1,
         pageSize: "A4",
         pageSize: "A4",
         removeAssets: true,
         removeAssets: true,
         keepFold: false,
         keepFold: false,
@@ -161,17 +160,18 @@ const renderPDF = (id: string) => {
         </div>
         </div>
         <span class="fn__hr"></span>
         <span class="fn__hr"></span>
         <select class="b3-select" id="marginsType">
         <select class="b3-select" id="marginsType">
-            <option ${localData.margins.marginType === "default" ? "selected" : ""} value="default">Default</option>
-            <option ${localData.margins.marginType === "none" ? "selected" : ""} value="none">None</option>
-            <option ${localData.margins.marginType === "printableArea" ? "selected" : ""} value="printableArea">Minimal</option>
+            <option ${localData.margins.marginType === "0" ? "selected" : ""} value="0">Default</option>
+            <option ${localData.margins.marginType === "1" ? "selected" : ""} value="1">None</option>
+            <option ${localData.margins.marginType === "2" ? "selected" : ""} value="2">Minimal</option>
         </select>
         </select>
     </label>
     </label>
     <label class="b3-label">
     <label class="b3-label">
         <div>
         <div>
             ${window.siyuan.languages.exportPDF3}
             ${window.siyuan.languages.exportPDF3}
+            <span id="scaleTip" style="float: right;color: var(--b3-theme-on-background);">${localData.scale}</span>
         </div>
         </div>
         <span class="fn__hr"></span>
         <span class="fn__hr"></span>
-        <input style="width: 192px" value="${localData.scaleFactor}" id="scaleFactor" step="1" class="b3-slider" type="range" min="0" max="100">
+        <input style="width: 192px" value="${localData.scale}" id="scale" step="0.1" class="b3-slider" type="range" min="0.1" max="2">
     </label>
     </label>
     <label class="b3-label">
     <label class="b3-label">
         <div>
         <div>
@@ -208,19 +208,40 @@ const renderPDF = (id: string) => {
 <script src="${servePath}/stage/build/export/protyle-method.js?${Constants.SIYUAN_VERSION}"></script>
 <script src="${servePath}/stage/build/export/protyle-method.js?${Constants.SIYUAN_VERSION}"></script>
 <script src="${servePath}/stage/protyle/js/lute/lute.min.js?${Constants.SIYUAN_VERSION}"></script>    
 <script src="${servePath}/stage/protyle/js/lute/lute.min.js?${Constants.SIYUAN_VERSION}"></script>    
 <script>
 <script>
+    let pdfLeft = 0;
+    let pdfTop = 0;
     const setPadding = () => {
     const setPadding = () => {
-        let pdfMargin = "0.66";
-        if (document.querySelector("#landscape").checked) {
-            pdfMargin = "1.69";
-        }
-        if (document.querySelector("#marginsType").value !== "default") {
-            if (document.querySelector("#landscape").checked) {
-                pdfMargin = "1.69";
-            } else {
-                pdfMargin = "0.3";
-            }
+        const isLandscape = document.querySelector("#landscape").checked;
+        switch (document.querySelector("#marginsType").value) { // none
+            case "0":
+                if (isLandscape) {
+                    pdfLeft = 0.42;
+                    pdfTop = 0.42;
+                } else {
+                    pdfLeft = 0.54;
+                    pdfTop = 1;
+                }
+                break;
+            case "2": // minimal
+                if (isLandscape) {
+                    pdfLeft = 0.07;
+                    pdfTop = 0.07;
+                } else {
+                    pdfLeft = 0.1;
+                    pdfTop = 0.58;
+                }
+                break;
+            case "1": // none
+                if (isLandscape) {
+                    pdfLeft = 0;
+                    pdfTop = 0;
+                } else {
+                    pdfLeft = 0;
+                    pdfTop = 0;
+                }
+                break;
         }
         }
-        document.getElementById('preview').style.padding = "34px " + pdfMargin + "in 16px";
+        document.getElementById('preview').style.padding = pdfTop + "in " + pdfLeft + "in";
     }
     }
     const fetchPost = (url, data, cb) => {
     const fetchPost = (url, data, cb) => {
         fetch("${servePath}" + url, {
         fetch("${servePath}" + url, {
@@ -309,9 +330,15 @@ const renderPDF = (id: string) => {
                 renderPreview(previewElement, response2.data.content);
                 renderPreview(previewElement, response2.data.content);
             })
             })
         })
         })
+        actionElement.querySelector("#scale").addEventListener("input", () => {
+            actionElement.querySelector("#scaleTip").innerText = actionElement.querySelector("#scale").value;
+        })
         actionElement.querySelector("#marginsType").addEventListener('change', () => {
         actionElement.querySelector("#marginsType").addEventListener('change', () => {
             setPadding();
             setPadding();
         });
         });
+        actionElement.querySelector("#landscape").addEventListener('change', () => {
+            setPadding();
+        });
         actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
         actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
             const {ipcRenderer}  = require("electron");
             const {ipcRenderer}  = require("electron");
             ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
             ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
@@ -323,17 +350,24 @@ const renderPDF = (id: string) => {
                 printBackground: true,
                 printBackground: true,
                 landscape: actionElement.querySelector("#landscape").checked,
                 landscape: actionElement.querySelector("#landscape").checked,
                 margins: {
                 margins: {
-                  marginType: actionElement.querySelector("#marginsType").value
+                  marginType: actionElement.querySelector("#marginsType").value,
+                  top: pdfTop * 0.6,
+                  bottom: pdfTop * 0.6,
+                  left: 0,
+                  right: 0,
                 },
                 },
-                scaleFactor: parseInt(actionElement.querySelector("#scaleFactor").value),
+                scale:  parseFloat(actionElement.querySelector("#scale").value),
                 pageSize: actionElement.querySelector("#pageSize").value,
                 pageSize: actionElement.querySelector("#pageSize").value,
               },
               },
+              keepFold: keepFoldElement.checked,
               removeAssets: actionElement.querySelector("#removeAssets").checked,
               removeAssets: actionElement.querySelector("#removeAssets").checked,
               rootId: "${id}",
               rootId: "${id}",
               rootTitle: response.data.name,
               rootTitle: response.data.name,
             })
             })
             actionElement.remove();
             actionElement.remove();
             previewElement.classList.add("exporting");
             previewElement.classList.add("exporting");
+            previewElement.style.paddingTop = "0";
+            previewElement.style.paddingBottom = "0";
         });
         });
         setPadding()
         setPadding()
     });
     });

+ 1 - 1
app/src/util/onGetConfig.ts

@@ -394,7 +394,7 @@ const initWindow = () => {
             }
             }
             const msgId = showMessage(window.siyuan.languages.exporting, -1);
             const msgId = showMessage(window.siyuan.languages.exporting, -1);
             const filePath = result.filePaths[0].endsWith(ipcData.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle));
             const filePath = result.filePaths[0].endsWith(ipcData.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle));
-            localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, {removeAssets: ipcData.removeAssets})));
+            localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, {removeAssets: ipcData.removeAssets, keepFold: ipcData.keepFold})));
             try {
             try {
                 window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {
                 window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {
                     fetchPost("/api/export/exportHTML", {
                     fetchPost("/api/export/exportHTML", {