footprint: fit each pad label to its pad

With real geometry in, a fixed label size turns multi-character names on fine-pitch
pads into overlapping mush — USB-C's A1/B12 row was unreadable. Scale per pad instead,
bounded by both the pad width (divided across the label) and its height.
This commit is contained in:
gator 2026-08-16 15:32:32 +00:00
parent 85ddf36a63
commit 529aa947e1

View file

@ -22,7 +22,13 @@ function footprintSVG(p) {
// EasyEDA names a round pad ELLIPSE; OVAL/ROUND are the KiCad-side spellings. // EasyEDA names a round pad ELLIPSE; OVAL/ROUND are the KiCad-side spellings.
const round = /OVAL|ROUND|ELLIPSE|CIRCLE/.test((d.shape || '').toUpperCase()); const round = /OVAL|ROUND|ELLIPSE|CIRCLE/.test((d.shape || '').toUpperCase());
s += `<rect x="${d.x - d.w / 2}" y="${d.y - d.h / 2}" width="${d.w}" height="${d.h}" rx="${round ? Math.min(d.w, d.h) / 2 : fs * 0.06}" fill="#c47a3d" stroke="#8a531f" stroke-width="${fs * 0.05}"/>`; s += `<rect x="${d.x - d.w / 2}" y="${d.y - d.h / 2}" width="${d.w}" height="${d.h}" rx="${round ? Math.min(d.w, d.h) / 2 : fs * 0.06}" fill="#c47a3d" stroke="#8a531f" stroke-width="${fs * 0.05}"/>`;
if (d.n != null) s += `<text x="${d.x}" y="${d.y + fs * 0.35}" font-size="${fs}" fill="#2a1a0c" text-anchor="middle" font-weight="600">${esc(d.n)}</text>`; // Fit the label to its pad. A fixed size turns multi-character names on fine-pitch
// pads (USB-C's A1/B12) into overlapping mush, so narrow pads get smaller text.
if (d.n != null) {
const lab = String(d.n);
const pf = Math.min(fs, (d.w * 1.7) / Math.max(lab.length, 1), d.h * 0.95);
s += `<text x="${d.x}" y="${d.y + pf * 0.35}" font-size="${pf}" fill="#2a1a0c" text-anchor="middle" font-weight="600">${esc(lab)}</text>`;
}
} }
if (p.class === 'connector') { // board-edge marker on the mating side if (p.class === 'connector') { // board-edge marker on the mating side
s += `<line x1="${minx + m * 0.4}" y1="${maxy - m * 0.5}" x2="${maxx - m * 0.4}" y2="${maxy - m * 0.5}" stroke="#2f8f2f" stroke-width="${fs * 0.18}"/>`; s += `<line x1="${minx + m * 0.4}" y1="${maxy - m * 0.5}" x2="${maxx - m * 0.4}" y2="${maxy - m * 0.5}" stroke="#2f8f2f" stroke-width="${fs * 0.18}"/>`;