Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/letter-centre.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"facturas": patch
"@facturas/pdf": patch
---

`@facturas/pdf` centra la letra del comprobante en su recuadro con cualquier fuente del tema. Con una altura de l铆nea fija, una fuente de ascendente alto como Geist la bajaba 3,6 puntos.
4 changes: 3 additions & 1 deletion packages/pdf/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export function createStyles(theme: ResolvedTheme) {
alignItems: "center",
justifyContent: "center",
},
letter: { ...bold, fontSize: 24, lineHeight: 1, color: theme.accentColor },
// No lineHeight: the font's own line box centres the capital in the box.
// A fixed one sinks it by the font's ascent, 3.6 pt with Geist.
letter: { ...bold, fontSize: 24, color: theme.accentColor },
code: { fontSize: 7.5, color: theme.textColor },
letterLegend: { ...bold, fontSize: 6.5, textAlign: "center" },
issuerName: {
Expand Down
20 changes: 20 additions & 0 deletions packages/pdf/src/voucher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ describe("<Voucher>", () => {
expect(hasText(page, "R茅gimen de Transparencia Fiscal")).toBe(false);
});

it("centres the letter in its box whatever the bold font", async () => {
// The box starts below the page and column padding and its 0.6 pt outline.
const boxCentre = 32 + 14 + 0.6 + 20;
// Cap heights of the standard fonts, in thousandths of the size.
for (const [boldFontFamily, capHeight] of [
["Helvetica-Bold", 718],
["Times-Bold", 676],
] as const) {
const [page] = await readPdf(
await renderVoucherPdf(classBDocument(), { theme: { boldFontFamily } })
);
if (page === undefined) {
throw new Error("no page");
}
const letter = findExact(page, "B");
const capCentre = letter.top - (letter.fontSize * capHeight) / 2000;
expect(Math.abs(capCentre - boxCentre)).toBeLessThan(0.5);
}
});

it("drops the line rate column on class A when every line has the same rate", async () => {
const doc = classADocument();
const single = {
Expand Down
Loading