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

Function _getWidgetRect

apps/OpenSign/src/constant/Utils.js:3800–3837  ·  view source on GitHub ↗
(widget, pdfDoc)

Source from the content-addressed store, hash-verified

3798}
3799
3800function _getWidgetRect(widget, pdfDoc) {
3801 try {
3802 const r = widget.getRectangle?.();
3803 if (
3804 r &&
3805 isFinite(r.x) &&
3806 isFinite(r.y) &&
3807 isFinite(r.width) &&
3808 isFinite(r.height)
3809 ) {
3810 return r;
3811 }
3812 } catch {
3813 /* fall through to manual extraction */
3814 }
3815
3816 try {
3817 const rectArr = widget.dict?.lookup?.(PDFName.of("Rect"));
3818 if (!rectArr || typeof rectArr.size !== "function" || rectArr.size() !== 4)
3819 return null;
3820
3821 const x1 = _numberFromPdfObject(rectArr.get(0));
3822 const y1 = _numberFromPdfObject(rectArr.get(1));
3823 const x2 = _numberFromPdfObject(rectArr.get(2));
3824 const y2 = _numberFromPdfObject(rectArr.get(3));
3825
3826 if ([x1, y1, x2, y2].some((v) => !isFinite(v))) return null;
3827
3828 return {
3829 x: Math.min(x1, x2),
3830 y: Math.min(y1, y2),
3831 width: Math.abs(x2 - x1),
3832 height: Math.abs(y2 - y1)
3833 };
3834 } catch {
3835 return null;
3836 }
3837}
3838
3839function _numberFromPdfObject(obj) {
3840 if (!obj) return NaN;

Callers 1

flattenPdfFunction · 0.85

Calls 1

_numberFromPdfObjectFunction · 0.85

Tested by

no test coverage detected