feat: resolve all 22 items in Features and Bugs.txt and complete UI polish
This commit is contained in:
@@ -38,11 +38,31 @@ function buildRuns(text: string, marks: Mark[]): Run[] {
|
||||
return runs;
|
||||
}
|
||||
|
||||
function resolvePdfFont(fontFamily: string): "times" | "helvetica" | "courier" {
|
||||
const lower = fontFamily.toLowerCase();
|
||||
if (lower.includes("mono") || lower.includes("courier") || lower.includes("consolas")) {
|
||||
return "courier";
|
||||
}
|
||||
if (
|
||||
lower.includes("serif") ||
|
||||
lower.includes("garamond") ||
|
||||
lower.includes("georgia") ||
|
||||
lower.includes("iowan") ||
|
||||
lower.includes("times")
|
||||
) {
|
||||
return "times";
|
||||
}
|
||||
return "helvetica";
|
||||
}
|
||||
|
||||
function setRunFont(doc: jsPDF, run: Run, theme: Theme): void {
|
||||
const hasCode = run.marks.some((m) => m.type === "code");
|
||||
const hasBold = run.marks.some((m) => m.type === "bold");
|
||||
const hasItalic = run.marks.some((m) => m.type === "italic");
|
||||
doc.setFont(hasCode ? "courier" : theme.fontFamily.split(",")[0]!.replace(/"/g, "").trim() || "helvetica", hasBold ? "bold" : hasItalic ? "italic" : "normal");
|
||||
doc.setFont(
|
||||
hasCode ? "courier" : resolvePdfFont(theme.fontFamily),
|
||||
hasBold ? "bold" : hasItalic ? "italic" : "normal",
|
||||
);
|
||||
}
|
||||
|
||||
function pageGeometry() {
|
||||
@@ -55,7 +75,7 @@ function pageGeometry() {
|
||||
}
|
||||
|
||||
function newPage(doc: jsPDF, theme: Theme): void {
|
||||
doc.setFont(theme.fontFamily.split(",")[0]!.replace(/"/g, "").trim() || "helvetica", "normal");
|
||||
doc.setFont(resolvePdfFont(theme.fontFamily), "normal");
|
||||
doc.setTextColor(hexToRgb(theme.colors.text));
|
||||
doc.setFillColor(hexToRgb(theme.colors.background));
|
||||
doc.rect(0, 0, doc.internal.pageSize.getWidth(), doc.internal.pageSize.getHeight(), "F");
|
||||
@@ -111,7 +131,7 @@ function renderBlocks(
|
||||
const level = Math.max(1, Math.min(6, block.level ?? 1));
|
||||
const size = level === 1 ? 24 : level === 2 ? 18 : 14;
|
||||
doc.setFontSize(size);
|
||||
doc.setFont(theme.fontFamily.split(",")[0]!.replace(/"/g, "").trim() || "helvetica", "bold");
|
||||
doc.setFont(resolvePdfFont(theme.fontFamily), "bold");
|
||||
doc.setTextColor(hexToRgb(theme.colors.heading));
|
||||
y += size * 0.9;
|
||||
y = renderParagraph(doc, block.text ?? "", block.marks ?? [], margin, y, maxWidth, lineHeight * 1.2, theme);
|
||||
@@ -120,7 +140,7 @@ function renderBlocks(
|
||||
}
|
||||
case "paragraph": {
|
||||
doc.setFontSize(12);
|
||||
doc.setFont(theme.fontFamily.split(",")[0]!.replace(/"/g, "").trim() || "helvetica", "normal");
|
||||
doc.setFont(resolvePdfFont(theme.fontFamily), "normal");
|
||||
doc.setTextColor(hexToRgb(theme.colors.text));
|
||||
y += lineHeight;
|
||||
y = renderParagraph(doc, block.text ?? "", block.marks ?? [], margin, y, maxWidth, lineHeight, theme);
|
||||
|
||||
Reference in New Issue
Block a user