Skip to content

Commit

Permalink
fix(pdf): add font for burmese rendering (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
correcthorsebatterystaple authored Nov 11, 2024
1 parent 69222b5 commit 1e33c5e
Show file tree
Hide file tree
Showing 5 changed files with 5,819 additions and 5,805 deletions.
Binary file not shown.
6 changes: 6 additions & 0 deletions app/src/services/reportFile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const PDFDocument = require("pdfkit");
const ConvertService = require("./convert.service");
//const GeostoreService = require("./geostore.service");
import logger from "../logger";
import { isBurmese } from "../utils/isBurmese";

const allowedFields = [
"reportName",
Expand Down Expand Up @@ -497,6 +498,7 @@ class ReportFileService {

doc.registerFont("Regular", "./app/src/services/font/NotoSansCJKjp-Regular.otf");
doc.registerFont("Bold", "./app/src/services/font/NotoSansCJKjp-Bold.otf");
doc.registerFont("Burmese", "./app/src/services/font/NotoSansMyanmar-Regular.otf");

doc.fontSize(14).text("Monitoring Report", 50, 80);
doc.font("Bold").fontSize(14).text(record.attributes.reportName.toUpperCase(), 50, 105);
Expand Down Expand Up @@ -537,8 +539,12 @@ class ReportFileService {
textToPrint = `POINT (${value[0]?.toString().substring(0, 9)} ${value[1]?.toString().substring(0, 9)})`;
}
} else textToPrint = value;

doc.font(isBurmese(textToPrint) ? "Burmese" : "Regular");
doc.fontSize(13).text(textToPrint, 80 + 250 * (i % 2), 170 + ((i - (i % 2)) / 2) * 50);
doc.font("Regular");
});

doc.moveDown(1);
doc.moveTo(50, doc.y).lineTo(500, doc.y).stroke();
doc.moveDown(1);
Expand Down
8 changes: 8 additions & 0 deletions app/src/utils/isBurmese.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Check if the text contains only Burmese characters
* @param {String} text The text to check
* @returns {Boolean} True if the text contains only Burmese characters, false otherwise
*/
export function isBurmese(text) {
return /^[\u1000-\u109F]$/.test(text);
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e33c5e

Please sign in to comment.