@embedpdf/models 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/geometry.d.ts +73 -0
- package/dist/helpers/font.d.ts +13 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -11
- package/dist/index.js.map +1 -1
- package/dist/pdf.d.ts +19 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -242,6 +242,66 @@ function boundingRect(rects) {
|
|
|
242
242
|
function boundingRectOrEmpty(rects) {
|
|
243
243
|
return boundingRect(rects) ?? EMPTY_RECT;
|
|
244
244
|
}
|
|
245
|
+
function normalizeAngle(degrees) {
|
|
246
|
+
const normalized = degrees % 360;
|
|
247
|
+
return normalized < 0 ? normalized + 360 : normalized;
|
|
248
|
+
}
|
|
249
|
+
function getRectCenter(rect) {
|
|
250
|
+
return {
|
|
251
|
+
x: rect.origin.x + rect.size.width / 2,
|
|
252
|
+
y: rect.origin.y + rect.size.height / 2
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function rotatePointAround(point, center, angleDegrees) {
|
|
256
|
+
const angleRad = angleDegrees * Math.PI / 180;
|
|
257
|
+
const cos = Math.cos(angleRad);
|
|
258
|
+
const sin = Math.sin(angleRad);
|
|
259
|
+
const dx = point.x - center.x;
|
|
260
|
+
const dy = point.y - center.y;
|
|
261
|
+
return {
|
|
262
|
+
x: center.x + dx * cos - dy * sin,
|
|
263
|
+
y: center.y + dx * sin + dy * cos
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function rotateVertices(points, center, angleDegrees) {
|
|
267
|
+
return points.map((v) => rotatePointAround(v, center, angleDegrees));
|
|
268
|
+
}
|
|
269
|
+
function calculateRotatedRectAABBAroundPoint(rect, angleDegrees, center) {
|
|
270
|
+
const corners = [
|
|
271
|
+
{ x: rect.origin.x, y: rect.origin.y },
|
|
272
|
+
{ x: rect.origin.x + rect.size.width, y: rect.origin.y },
|
|
273
|
+
{ x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height },
|
|
274
|
+
{ x: rect.origin.x, y: rect.origin.y + rect.size.height }
|
|
275
|
+
];
|
|
276
|
+
const rotated = rotateVertices(corners, center, angleDegrees);
|
|
277
|
+
return rectFromPoints(rotated);
|
|
278
|
+
}
|
|
279
|
+
function calculateRotatedRectAABB(unrotatedRect, angleDegrees) {
|
|
280
|
+
return calculateRotatedRectAABBAroundPoint(
|
|
281
|
+
unrotatedRect,
|
|
282
|
+
angleDegrees,
|
|
283
|
+
getRectCenter(unrotatedRect)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
function inferRotationCenterFromRects(unrotatedRect, rotatedAabb, angleDegrees) {
|
|
287
|
+
const angleRad = angleDegrees * Math.PI / 180;
|
|
288
|
+
const cos = Math.cos(angleRad);
|
|
289
|
+
const sin = Math.sin(angleRad);
|
|
290
|
+
const m00 = 1 - cos;
|
|
291
|
+
const m01 = sin;
|
|
292
|
+
const m10 = -sin;
|
|
293
|
+
const m11 = 1 - cos;
|
|
294
|
+
const det = m00 * m11 - m01 * m10;
|
|
295
|
+
const unrotatedCenter = getRectCenter(unrotatedRect);
|
|
296
|
+
if (Math.abs(det) < 1e-10) return unrotatedCenter;
|
|
297
|
+
const rotatedCenter = getRectCenter(rotatedAabb);
|
|
298
|
+
const rhsX = rotatedCenter.x - (cos * unrotatedCenter.x - sin * unrotatedCenter.y);
|
|
299
|
+
const rhsY = rotatedCenter.y - (sin * unrotatedCenter.x + cos * unrotatedCenter.y);
|
|
300
|
+
return {
|
|
301
|
+
x: (m11 * rhsX - m01 * rhsY) / det,
|
|
302
|
+
y: (-m10 * rhsX + m00 * rhsY) / det
|
|
303
|
+
};
|
|
304
|
+
}
|
|
245
305
|
function buildUserToDeviceMatrix(rect, rotation, outW, outH) {
|
|
246
306
|
const L = rect.origin.x;
|
|
247
307
|
const B = rect.origin.y;
|
|
@@ -1538,7 +1598,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1538
1598
|
bold: true,
|
|
1539
1599
|
italic: false,
|
|
1540
1600
|
label: "Courier Bold",
|
|
1541
|
-
css:
|
|
1601
|
+
css: "Courier, monospace"
|
|
1542
1602
|
},
|
|
1543
1603
|
{
|
|
1544
1604
|
id: PdfStandardFont.Courier_BoldOblique,
|
|
@@ -1546,7 +1606,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1546
1606
|
bold: true,
|
|
1547
1607
|
italic: true,
|
|
1548
1608
|
label: "Courier Bold Oblique",
|
|
1549
|
-
css:
|
|
1609
|
+
css: "Courier, monospace"
|
|
1550
1610
|
},
|
|
1551
1611
|
{
|
|
1552
1612
|
id: PdfStandardFont.Courier_Oblique,
|
|
@@ -1554,7 +1614,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1554
1614
|
bold: false,
|
|
1555
1615
|
italic: true,
|
|
1556
1616
|
label: "Courier Oblique",
|
|
1557
|
-
css:
|
|
1617
|
+
css: "Courier, monospace"
|
|
1558
1618
|
},
|
|
1559
1619
|
HELVETICA_DESC,
|
|
1560
1620
|
{
|
|
@@ -1563,7 +1623,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1563
1623
|
bold: true,
|
|
1564
1624
|
italic: false,
|
|
1565
1625
|
label: "Helvetica Bold",
|
|
1566
|
-
css:
|
|
1626
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1567
1627
|
},
|
|
1568
1628
|
{
|
|
1569
1629
|
id: PdfStandardFont.Helvetica_BoldOblique,
|
|
@@ -1571,7 +1631,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1571
1631
|
bold: true,
|
|
1572
1632
|
italic: true,
|
|
1573
1633
|
label: "Helvetica Bold Oblique",
|
|
1574
|
-
css:
|
|
1634
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1575
1635
|
},
|
|
1576
1636
|
{
|
|
1577
1637
|
id: PdfStandardFont.Helvetica_Oblique,
|
|
@@ -1579,7 +1639,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1579
1639
|
bold: false,
|
|
1580
1640
|
italic: true,
|
|
1581
1641
|
label: "Helvetica Oblique",
|
|
1582
|
-
css:
|
|
1642
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1583
1643
|
},
|
|
1584
1644
|
{
|
|
1585
1645
|
id: PdfStandardFont.Times_Roman,
|
|
@@ -1595,7 +1655,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1595
1655
|
bold: true,
|
|
1596
1656
|
italic: false,
|
|
1597
1657
|
label: "Times Bold",
|
|
1598
|
-
css: '"Times New Roman
|
|
1658
|
+
css: '"Times New Roman", Times, serif'
|
|
1599
1659
|
},
|
|
1600
1660
|
{
|
|
1601
1661
|
id: PdfStandardFont.Times_BoldItalic,
|
|
@@ -1603,7 +1663,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1603
1663
|
bold: true,
|
|
1604
1664
|
italic: true,
|
|
1605
1665
|
label: "Times Bold Italic",
|
|
1606
|
-
css: '"Times New Roman
|
|
1666
|
+
css: '"Times New Roman", Times, serif'
|
|
1607
1667
|
},
|
|
1608
1668
|
{
|
|
1609
1669
|
id: PdfStandardFont.Times_Italic,
|
|
@@ -1611,7 +1671,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1611
1671
|
bold: false,
|
|
1612
1672
|
italic: true,
|
|
1613
1673
|
label: "Times Italic",
|
|
1614
|
-
css: '"Times New Roman
|
|
1674
|
+
css: '"Times New Roman", Times, serif'
|
|
1615
1675
|
},
|
|
1616
1676
|
{
|
|
1617
1677
|
id: PdfStandardFont.Symbol,
|
|
@@ -1619,7 +1679,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1619
1679
|
bold: false,
|
|
1620
1680
|
italic: false,
|
|
1621
1681
|
label: "Symbol",
|
|
1622
|
-
css: "Symbol"
|
|
1682
|
+
css: "Symbol, serif"
|
|
1623
1683
|
},
|
|
1624
1684
|
{
|
|
1625
1685
|
id: PdfStandardFont.ZapfDingbats,
|
|
@@ -1627,7 +1687,7 @@ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
|
1627
1687
|
bold: false,
|
|
1628
1688
|
italic: false,
|
|
1629
1689
|
label: "Zapf Dingbats",
|
|
1630
|
-
css: "ZapfDingbats"
|
|
1690
|
+
css: "ZapfDingbats, serif"
|
|
1631
1691
|
}
|
|
1632
1692
|
]);
|
|
1633
1693
|
const idToDescriptor = STANDARD_FONT_DESCRIPTORS.reduce((m, d) => (m[d.id] = d, m), {});
|
|
@@ -1659,6 +1719,14 @@ function standardFontLabel(font) {
|
|
|
1659
1719
|
function standardFontCss(font) {
|
|
1660
1720
|
return getStandardFontDescriptor(font).css;
|
|
1661
1721
|
}
|
|
1722
|
+
function standardFontCssProperties(font) {
|
|
1723
|
+
const desc = getStandardFontDescriptor(font);
|
|
1724
|
+
return {
|
|
1725
|
+
fontFamily: desc.css,
|
|
1726
|
+
fontWeight: desc.bold ? "bold" : "normal",
|
|
1727
|
+
fontStyle: desc.italic ? "italic" : "normal"
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1662
1730
|
const standardFontFamilySelectOptions = Object.values(PdfStandardFontFamily).filter(
|
|
1663
1731
|
(f) => f !== "Unknown"
|
|
1664
1732
|
/* Unknown */
|
|
@@ -2088,6 +2156,8 @@ export {
|
|
|
2088
2156
|
buildUserToDeviceMatrix,
|
|
2089
2157
|
calculateAngle,
|
|
2090
2158
|
calculateDegree,
|
|
2159
|
+
calculateRotatedRectAABB,
|
|
2160
|
+
calculateRotatedRectAABBAroundPoint,
|
|
2091
2161
|
combinePdfColorWithAlpha,
|
|
2092
2162
|
combineWebColorWithOpacity,
|
|
2093
2163
|
compareSearchTarget,
|
|
@@ -2100,12 +2170,15 @@ export {
|
|
|
2100
2170
|
extractWebOpacity,
|
|
2101
2171
|
flagsToNames,
|
|
2102
2172
|
getBlendModeInfo,
|
|
2173
|
+
getRectCenter,
|
|
2103
2174
|
getStandardFontDescriptor,
|
|
2104
2175
|
getTextAlignmentInfo,
|
|
2105
2176
|
ignore,
|
|
2177
|
+
inferRotationCenterFromRects,
|
|
2106
2178
|
isUuidV4,
|
|
2107
2179
|
makeStandardFont,
|
|
2108
2180
|
namesToFlags,
|
|
2181
|
+
normalizeAngle,
|
|
2109
2182
|
pdfAlphaColorToWebAlphaColor,
|
|
2110
2183
|
pdfAlphaToWebOpacity,
|
|
2111
2184
|
pdfColorToWebColor,
|
|
@@ -2121,12 +2194,15 @@ export {
|
|
|
2121
2194
|
restorePosition,
|
|
2122
2195
|
restoreRect,
|
|
2123
2196
|
rotateAndTranslatePoint,
|
|
2197
|
+
rotatePointAround,
|
|
2124
2198
|
rotatePosition,
|
|
2125
2199
|
rotateRect,
|
|
2200
|
+
rotateVertices,
|
|
2126
2201
|
scalePosition,
|
|
2127
2202
|
scaleRect,
|
|
2128
2203
|
serializeLogger,
|
|
2129
2204
|
standardFontCss,
|
|
2205
|
+
standardFontCssProperties,
|
|
2130
2206
|
standardFontFamily,
|
|
2131
2207
|
standardFontFamilyLabel,
|
|
2132
2208
|
standardFontFamilySelectOptions,
|