MCPcopy Create free account
hub / github.com/OpenSignLabs/OpenSign / _drawCombText

Function _drawCombText

apps/OpenSign/src/constant/Utils.js:3977–4012  ·  view source on GitHub ↗
(page, text, rect, font)

Source from the content-addressed store, hash-verified

3975}
3976
3977function _drawCombText(page, text, rect, font) {
3978 const chars = String(text).split("");
3979 const count = Math.max(chars.length, 1);
3980 const cellWidth = rect.width / count;
3981 const fontSize = Math.max(8, Math.min(12, rect.height - 4));
3982
3983 chars.forEach((ch, i) => {
3984 const textWidth = font.widthOfTextAtSize(ch, fontSize);
3985 const x = rect.x + i * cellWidth + (cellWidth - textWidth) / 2;
3986 const y = rect.y + Math.max(2, (rect.height - fontSize) / 2);
3987
3988 page.drawText(ch, {
3989 x,
3990 y,
3991 size: fontSize,
3992 font,
3993 color: rgb(0, 0, 0)
3994 });
3995
3996 if (i < count - 1) {
3997 try {
3998 page.drawLine({
3999 start: { x: rect.x + (i + 1) * cellWidth, y: rect.y },
4000 end: {
4001 x: rect.x + (i + 1) * cellWidth,
4002 y: rect.y + rect.height
4003 },
4004 thickness: 0.4,
4005 color: rgb(0.75, 0.75, 0.75)
4006 });
4007 } catch {
4008 /* best effort */
4009 }
4010 }
4011 });
4012}
4013
4014function _fitSingleLineFontSize(text, rect, font) {
4015 let size = Math.min(12, rect.height - 4);

Callers 1

_drawTextFieldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected