YARA-994 and fixed metal plate bug

This commit is contained in:
SepehrYahyaee
2026-07-15 10:33:50 +03:30
parent 385757c3a0
commit da7a4f8890
3 changed files with 48 additions and 9 deletions

View File

@@ -8,18 +8,31 @@ export function normalizePersianPdfText(text: string): string {
.trim();
}
/**
* pdfkit renders glyphs strictly left-to-right.
* fontkit already reshapes each word's glyphs into visual (LTR) order,
* but it does NOT reorder words — so a multi-word RTL string like
* "نام صاحب خودرو" has its words placed LTR on the page and reads
* backwards. Reversing the word sequence here makes pdfkit emit the
* words in the correct visual order for a right-to-left PDF reader.
*/
function reverseRtlWords(text: string): string {
if (!/[\u0600-\u06FF]/.test(text)) return text;
return text.split(" ").reverse().join(" ");
}
export function pdfKitRtlKeyValue(
label: string,
value: string,
): { label: string; value: string } {
return {
label: normalizePersianPdfText(label),
value: normalizePersianPdfText(value),
label: reverseRtlWords(normalizePersianPdfText(label)),
value: reverseRtlWords(normalizePersianPdfText(value)),
};
}
export function pdfKitRtlParagraph(text: string): string {
return normalizePersianPdfText(text);
return reverseRtlWords(normalizePersianPdfText(text));
}
export function isMostlyAscii(text: string): boolean {