feat: add option to truncate long course descriptions to single line (default on, matches official PDF)
This commit is contained in:
+14
-1
@@ -5,7 +5,7 @@ const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
global.PDFLib = require('pdf-lib');
|
||||
const { buildStudyLoadPdf, compactProgram, deriveDateRange, formatSchedule, formatFullName } = require('../pdf.js');
|
||||
const { buildStudyLoadPdf, compactProgram, deriveDateRange, formatSchedule, formatFullName, truncateToWidth } = require('../pdf.js');
|
||||
|
||||
const sampleData = {
|
||||
header: {
|
||||
@@ -88,3 +88,16 @@ test('deriveDateRange maps semesters', () => {
|
||||
assert.strictEqual(deriveDateRange('Summer 2026'), 'JUNE - JULY');
|
||||
assert.strictEqual(deriveDateRange(''), '');
|
||||
});
|
||||
|
||||
test('truncateToWidth hard-cuts text to fit within maxWidth', async () => {
|
||||
const doc = await global.PDFLib.PDFDocument.create();
|
||||
const font = doc.embedStandardFont(global.PDFLib.StandardFonts.Helvetica);
|
||||
const longText = 'APPLICATION DEVELOPMENT AND EMERGING TECHNOLOGIES';
|
||||
const tr = truncateToWidth(longText, font, 8, 100);
|
||||
assert.ok(tr.length < longText.length, 'long text should be cut down');
|
||||
assert.ok(longText.startsWith(tr), 'result must be a prefix of the input');
|
||||
assert.ok(font.widthOfTextAtSize(tr, 8) <= 100, 'truncated line must fit maxWidth');
|
||||
const short = 'DATA STRUCTURES';
|
||||
assert.strictEqual(truncateToWidth(short, font, 8, 200), short);
|
||||
assert.strictEqual(truncateToWidth('', font, 8, 200), '');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user