pdf-codec 1.5.0 → 1.7.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.
Files changed (214) hide show
  1. package/README.md +100 -9
  2. package/dist/assets/caladea-bold.cjs +5 -0
  3. package/dist/assets/caladea-bold.d.cts +4 -0
  4. package/dist/assets/caladea-bold.d.ts +4 -0
  5. package/dist/assets/caladea-bold.js +4 -0
  6. package/dist/assets/caladea-bolditalic.cjs +5 -0
  7. package/dist/assets/caladea-bolditalic.d.cts +4 -0
  8. package/dist/assets/caladea-bolditalic.d.ts +4 -0
  9. package/dist/assets/caladea-bolditalic.js +4 -0
  10. package/dist/assets/caladea-italic.cjs +5 -0
  11. package/dist/assets/caladea-italic.d.cts +4 -0
  12. package/dist/assets/caladea-italic.d.ts +4 -0
  13. package/dist/assets/caladea-italic.js +4 -0
  14. package/dist/assets/caladea-regular.cjs +5 -0
  15. package/dist/assets/caladea-regular.d.cts +4 -0
  16. package/dist/assets/caladea-regular.d.ts +4 -0
  17. package/dist/assets/caladea-regular.js +4 -0
  18. package/dist/assets/carlito-bold.cjs +5 -0
  19. package/dist/assets/carlito-bold.d.cts +4 -0
  20. package/dist/assets/carlito-bold.d.ts +4 -0
  21. package/dist/assets/carlito-bold.js +4 -0
  22. package/dist/assets/carlito-bolditalic.cjs +5 -0
  23. package/dist/assets/carlito-bolditalic.d.cts +4 -0
  24. package/dist/assets/carlito-bolditalic.d.ts +4 -0
  25. package/dist/assets/carlito-bolditalic.js +4 -0
  26. package/dist/assets/carlito-italic.cjs +5 -0
  27. package/dist/assets/carlito-italic.d.cts +4 -0
  28. package/dist/assets/carlito-italic.d.ts +4 -0
  29. package/dist/assets/carlito-italic.js +4 -0
  30. package/dist/assets/carlito-regular.cjs +5 -0
  31. package/dist/assets/carlito-regular.d.cts +4 -0
  32. package/dist/assets/carlito-regular.d.ts +4 -0
  33. package/dist/assets/carlito-regular.js +4 -0
  34. package/dist/cff-bounds.cjs +432 -0
  35. package/dist/cff-bounds.d.cts +9 -0
  36. package/dist/cff-bounds.d.ts +9 -0
  37. package/dist/cff-bounds.js +431 -0
  38. package/dist/cff-probe.cjs +35 -0
  39. package/dist/cff-probe.d.cts +10 -0
  40. package/dist/cff-probe.d.ts +10 -0
  41. package/dist/cff-probe.js +34 -0
  42. package/dist/cff.cjs +158 -0
  43. package/dist/cff.d.cts +17 -0
  44. package/dist/cff.d.ts +17 -0
  45. package/dist/cff.js +150 -0
  46. package/dist/cmap-table.cjs +108 -0
  47. package/dist/cmap-table.d.cts +6 -0
  48. package/dist/cmap-table.d.ts +6 -0
  49. package/dist/cmap-table.js +107 -0
  50. package/dist/content-write.cjs +34 -14
  51. package/dist/content-write.d.cts +9 -2
  52. package/dist/content-write.d.ts +9 -2
  53. package/dist/content-write.js +34 -14
  54. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  55. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  56. package/dist/embedded-font-write.cjs +92 -0
  57. package/dist/embedded-font-write.d.cts +22 -0
  58. package/dist/embedded-font-write.d.ts +22 -0
  59. package/dist/embedded-font-write.js +90 -0
  60. package/dist/embedded-font.cjs +142 -0
  61. package/dist/embedded-font.d.cts +2 -0
  62. package/dist/embedded-font.d.ts +2 -0
  63. package/dist/embedded-font.js +138 -0
  64. package/dist/filters.cjs +45 -2
  65. package/dist/filters.d.cts +4 -3
  66. package/dist/filters.d.ts +4 -3
  67. package/dist/filters.js +45 -2
  68. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  69. package/dist/font-registry-yby02snZ.d.cts +38 -0
  70. package/dist/font-registry.cjs +152 -0
  71. package/dist/font-registry.d.cts +2 -0
  72. package/dist/font-registry.d.ts +2 -0
  73. package/dist/font-registry.js +150 -0
  74. package/dist/font-substitutes.cjs +13 -0
  75. package/dist/font-substitutes.d.cts +5 -0
  76. package/dist/font-substitutes.d.ts +5 -0
  77. package/dist/font-substitutes.js +12 -0
  78. package/dist/font-tables.cjs +127 -0
  79. package/dist/font-tables.d.cts +43 -0
  80. package/dist/font-tables.d.ts +43 -0
  81. package/dist/font-tables.js +122 -0
  82. package/dist/fonts.cjs +1 -0
  83. package/dist/fonts.d.cts +2 -1
  84. package/dist/fonts.d.ts +2 -1
  85. package/dist/fonts.js +1 -1
  86. package/dist/formula.d.cts +1 -1
  87. package/dist/formula.d.ts +1 -1
  88. package/dist/glyf.cjs +183 -0
  89. package/dist/glyf.d.cts +33 -0
  90. package/dist/glyf.d.ts +33 -0
  91. package/dist/glyf.js +181 -0
  92. package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
  93. package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
  94. package/dist/glyph-bounds.cjs +12 -0
  95. package/dist/glyph-bounds.d.cts +2 -0
  96. package/dist/glyph-bounds.d.ts +2 -0
  97. package/dist/glyph-bounds.js +11 -0
  98. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  99. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  100. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  101. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  102. package/dist/image/jbig2-arith.cjs +432 -0
  103. package/dist/image/jbig2-arith.d.cts +23 -0
  104. package/dist/image/jbig2-arith.d.ts +23 -0
  105. package/dist/image/jbig2-arith.js +426 -0
  106. package/dist/image/jbig2-bitmap.cjs +80 -0
  107. package/dist/image/jbig2-bitmap.d.cts +20 -0
  108. package/dist/image/jbig2-bitmap.d.ts +20 -0
  109. package/dist/image/jbig2-bitmap.js +72 -0
  110. package/dist/image/jbig2-errors.cjs +17 -0
  111. package/dist/image/jbig2-errors.d.cts +2 -0
  112. package/dist/image/jbig2-errors.d.ts +2 -0
  113. package/dist/image/jbig2-errors.js +15 -0
  114. package/dist/image/jbig2-generic.cjs +242 -0
  115. package/dist/image/jbig2-generic.d.cts +27 -0
  116. package/dist/image/jbig2-generic.d.ts +27 -0
  117. package/dist/image/jbig2-generic.js +237 -0
  118. package/dist/image/jbig2-text.cjs +175 -0
  119. package/dist/image/jbig2-text.d.cts +58 -0
  120. package/dist/image/jbig2-text.d.ts +58 -0
  121. package/dist/image/jbig2-text.js +170 -0
  122. package/dist/image/jbig2.cjs +333 -0
  123. package/dist/image/jbig2.d.cts +15 -0
  124. package/dist/image/jbig2.d.ts +15 -0
  125. package/dist/image/jbig2.js +332 -0
  126. package/dist/image/jp2-boxes.cjs +148 -0
  127. package/dist/image/jp2-boxes.d.cts +26 -0
  128. package/dist/image/jp2-boxes.d.ts +26 -0
  129. package/dist/image/jp2-boxes.js +146 -0
  130. package/dist/image/jpeg2000-codestream.cjs +309 -0
  131. package/dist/image/jpeg2000-codestream.d.cts +78 -0
  132. package/dist/image/jpeg2000-codestream.d.ts +78 -0
  133. package/dist/image/jpeg2000-codestream.js +308 -0
  134. package/dist/image/jpeg2000-dwt.cjs +148 -0
  135. package/dist/image/jpeg2000-dwt.d.cts +34 -0
  136. package/dist/image/jpeg2000-dwt.d.ts +34 -0
  137. package/dist/image/jpeg2000-dwt.js +145 -0
  138. package/dist/image/jpeg2000-errors.cjs +17 -0
  139. package/dist/image/jpeg2000-errors.d.cts +9 -0
  140. package/dist/image/jpeg2000-errors.d.ts +9 -0
  141. package/dist/image/jpeg2000-errors.js +15 -0
  142. package/dist/image/jpeg2000-t1.cjs +254 -0
  143. package/dist/image/jpeg2000-t1.d.cts +18 -0
  144. package/dist/image/jpeg2000-t1.d.ts +18 -0
  145. package/dist/image/jpeg2000-t1.js +253 -0
  146. package/dist/image/jpeg2000-t2.cjs +316 -0
  147. package/dist/image/jpeg2000-t2.d.cts +79 -0
  148. package/dist/image/jpeg2000-t2.d.ts +79 -0
  149. package/dist/image/jpeg2000-t2.js +311 -0
  150. package/dist/image/jpeg2000-tagtree.cjs +105 -0
  151. package/dist/image/jpeg2000-tagtree.d.cts +29 -0
  152. package/dist/image/jpeg2000-tagtree.d.ts +29 -0
  153. package/dist/image/jpeg2000-tagtree.js +103 -0
  154. package/dist/image/jpeg2000.cjs +322 -0
  155. package/dist/image/jpeg2000.d.cts +54 -0
  156. package/dist/image/jpeg2000.d.ts +54 -0
  157. package/dist/image/jpeg2000.js +320 -0
  158. package/dist/images-read.cjs +78 -1
  159. package/dist/images-read.js +78 -1
  160. package/dist/index.cjs +22 -0
  161. package/dist/index.d.cts +14 -3
  162. package/dist/index.d.ts +14 -3
  163. package/dist/index.js +9 -2
  164. package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
  165. package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
  166. package/dist/math-font-write.cjs +2 -31
  167. package/dist/math-font-write.js +1 -30
  168. package/dist/math-font.cjs +50 -23
  169. package/dist/math-font.d.cts +8 -1
  170. package/dist/math-font.d.ts +8 -1
  171. package/dist/math-font.js +48 -21
  172. package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
  173. package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
  174. package/dist/math-stretch.cjs +96 -0
  175. package/dist/math-stretch.d.cts +2 -0
  176. package/dist/math-stretch.d.ts +2 -0
  177. package/dist/math-stretch.js +94 -0
  178. package/dist/math-table-DhPrNoPa.d.ts +70 -0
  179. package/dist/math-table-gFNB8DmQ.d.cts +70 -0
  180. package/dist/math-table.cjs +69 -1
  181. package/dist/math-table.d.cts +2 -45
  182. package/dist/math-table.d.ts +2 -45
  183. package/dist/math-table.js +69 -1
  184. package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
  185. package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
  186. package/dist/math-types.d.cts +1 -1
  187. package/dist/math-types.d.ts +1 -1
  188. package/dist/measure.cjs +65 -14
  189. package/dist/measure.d.cts +8 -1
  190. package/dist/measure.d.ts +8 -1
  191. package/dist/measure.js +64 -15
  192. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  193. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  194. package/dist/sfnt-subset.cjs +250 -0
  195. package/dist/sfnt-subset.d.cts +11 -0
  196. package/dist/sfnt-subset.d.ts +11 -0
  197. package/dist/sfnt-subset.js +249 -0
  198. package/dist/sfnt.cjs +50 -4
  199. package/dist/sfnt.d.cts +2 -17
  200. package/dist/sfnt.d.ts +2 -17
  201. package/dist/sfnt.js +47 -5
  202. package/dist/tounicode.cjs +34 -0
  203. package/dist/tounicode.d.cts +5 -0
  204. package/dist/tounicode.d.ts +5 -0
  205. package/dist/tounicode.js +33 -0
  206. package/dist/write.cjs +80 -10
  207. package/dist/write.d.cts +6 -0
  208. package/dist/write.d.ts +6 -0
  209. package/dist/write.js +81 -11
  210. package/package.json +1 -1
  211. package/dist/math-cmap.cjs +0 -81
  212. package/dist/math-cmap.d.cts +0 -6
  213. package/dist/math-cmap.d.ts +0 -6
  214. package/dist/math-cmap.js +0 -80
package/dist/index.d.ts CHANGED
@@ -3,21 +3,32 @@ import { crc32 } from "./bytes/crc32.js";
3
3
  import { DeflateLevel, InflateResult, MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant } from "./bytes/flate.js";
4
4
  import { ByteReader, isAsciiWhitespace } from "./bytes/reader.js";
5
5
  import { ByteWriter, concatBytes } from "./bytes/writer.js";
6
+ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
6
7
  import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
7
8
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
8
- import { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer } from "./measure.js";
9
+ import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CbqkKgBl.js";
10
+ import { a as ResolvedFace, i as ProvidedFont, n as FontRegistryOptions, o as createFontRegistry, r as FontSubstitution, s as resolveFaceWithRegistry, t as FontRegistry } from "./font-registry-Cn7P9lAh.js";
11
+ import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
9
12
  import { WinAnsiSubstitution } from "./winansi.js";
10
13
  import { i as Point, u as rotatePointAboutCenter } from "./matrix-BHzJESll.js";
11
14
  import { ResolvedFont, resolveStandardFont } from "./fonts.js";
12
- import { a as MathGlyphRun, c as MathStroke, i as MathGlyphMetrics, n as MathColor, o as MathLayoutItem, r as MathFontMetrics, s as MathRule, t as MathBox } from "./math-types-Ba8qAf1p.js";
15
+ import { a as MathGlyphRun, c as MathStroke, i as MathGlyphMetrics, n as MathColor, o as MathLayoutItem, r as MathFontMetrics, s as MathRule, t as MathBox } from "./math-types-YSQUTviw.js";
13
16
  import { PositionedFormula } from "./formula.js";
14
17
  import { CcittFaxImage, CcittFaxOptions, decodeCcittFax } from "./image/ccitt.js";
18
+ import { n as Jbig2UnsupportedError, t as Jbig2ParseError } from "./jbig2-errors-Bj6MPxrx.js";
19
+ import { Jbig2DecodeOptions, Jbig2Image, decodeJbig2Embedded } from "./image/jbig2.js";
20
+ import { Jp2ChannelDefinition, Jp2ColourSpace, Jp2Container, Jp2ImageHeader, looksLikeBareCodestream, parseJp2Container } from "./image/jp2-boxes.js";
15
21
  import { JpegInfo, readJpegInfo } from "./image/jpeg-info.js";
22
+ import { Jpeg2000ProgressionOrder, Jpeg2000QuantizationStyle, Jpeg2000Transform } from "./image/jpeg2000-codestream.js";
23
+ import { Jpeg2000ParseError, Jpeg2000UnsupportedError } from "./image/jpeg2000-errors.js";
24
+ import { Jpeg2000ComponentMetadata, Jpeg2000DecodeOptions, Jpeg2000Image, Jpeg2000Metadata, decodeJpeg2000, readJpeg2000Metadata } from "./image/jpeg2000.js";
16
25
  import { PngDecodeOptions, RawImage, decodePng } from "./image/png-decode.js";
17
26
  import { PngEncodeOptions, encodePng } from "./image/png-encode.js";
18
27
  import { PngFilterType, filterScanlines, unfilterScanlines } from "./image/png-filter.js";
19
28
  import { ReadPdfOptions, readPdf } from "./read.js";
20
29
  import { WritePdfOptions, writePdf } from "./write.js";
30
+ import { a as MathGlyphPart, c as MathVariants, n as MathGlyphAssembly, o as MathGlyphVariant, r as MathGlyphConstruction } from "./math-table-DhPrNoPa.js";
31
+ import { a as assembleStretchyGlyph, i as MathStretchPlacement, n as MathStretchConstruction, o as scaleMathStretchConstruction, r as MathStretchOptions, t as MathStretchAxis } from "./math-stretch-Bwk_bxh1.js";
21
32
  import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } from "./math-font.js";
22
33
  import { StyledFragment, StyledRun, WrapOptions, WrappedLine, wrapRunsToWidth } from "./text-layout.js";
23
- export { ByteReader, ByteWriter, type CcittFaxImage, type CcittFaxOptions, type DeflateLevel, type FontMetrics, type InflateResult, type JpegInfo, type LoadedMathFont, MAX_INFLATE_OUTPUT_BYTES, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphMetrics, type MathGlyphRun, type MathLayoutItem, type MathRule, type MathStroke, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type PngDecodeOptions, type PngEncodeOptions, type PngFilterType, type Point, type PositionedFormula, type RawImage, type ReadPdfOptions, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, concatBytes, crc32, createStandardFontMeasurer, decodeCcittFax, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, pdfCodec, readJpegInfo, readPdf, resolveStandardFont, rotatePointAboutCenter, unfilterScanlines, wrapRunsToWidth, writePdf };
34
+ export { ByteReader, ByteWriter, type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type DeflateLevel, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type InflateResult, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, type JpegInfo, type LoadedMathFont, MAX_INFLATE_OUTPUT_BYTES, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchOptions, type MathStretchPlacement, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type PngDecodeOptions, type PngEncodeOptions, type PngFilterType, type Point, type PositionedFormula, type ProvidedFont, type RawImage, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, concatBytes, crc32, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readJpeg2000Metadata, readJpegInfo, readPdf, resolveFaceWithRegistry, resolveStandardFont, rotatePointAboutCenter, scaleMathStretchConstruction, unfilterScanlines, wrapRunsToWidth, writePdf };
package/dist/index.js CHANGED
@@ -5,16 +5,23 @@ import { ByteWriter, concatBytes } from "./bytes/writer.js";
5
5
  import { NOOP_DIAGNOSTIC_SINK, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
6
6
  import { MAX_INFLATE_OUTPUT_BYTES, deflate, inflate, inflateTolerant } from "./bytes/flate.js";
7
7
  import { decodeCcittFax } from "./image/ccitt.js";
8
+ import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
9
+ import { decodeJbig2Embedded } from "./image/jbig2.js";
8
10
  import { filterScanlines, unfilterScanlines } from "./image/png-filter.js";
9
11
  import { resolveStandardFont } from "./fonts.js";
10
12
  import { encodePng } from "./image/png-encode.js";
11
13
  import { readJpegInfo } from "./image/jpeg-info.js";
14
+ import { Jpeg2000ParseError, Jpeg2000UnsupportedError } from "./image/jpeg2000-errors.js";
15
+ import { looksLikeBareCodestream, parseJp2Container } from "./image/jp2-boxes.js";
16
+ import { decodeJpeg2000, readJpeg2000Metadata } from "./image/jpeg2000.js";
12
17
  import { rotatePointAboutCenter } from "./matrix.js";
13
18
  import { decodePng } from "./image/png-decode.js";
19
+ import { createFontRegistry, resolveFaceWithRegistry } from "./font-registry.js";
20
+ import { assembleStretchyGlyph, scaleMathStretchConstruction } from "./math-stretch.js";
14
21
  import { loadMathFont } from "./math-font.js";
15
- import { createStandardFontMeasurer } from "./measure.js";
22
+ import { DEFAULT_VERTICAL_METRIC_POLICY, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
16
23
  import { writePdf } from "./write.js";
17
24
  import { readPdf } from "./read.js";
18
25
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
19
26
  import { wrapRunsToWidth } from "./text-layout.js";
20
- export { ByteReader, ByteWriter, MAX_INFLATE_OUTPUT_BYTES, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, concatBytes, crc32, createStandardFontMeasurer, decodeCcittFax, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, pdfCodec, readJpegInfo, readPdf, resolveStandardFont, rotatePointAboutCenter, unfilterScanlines, wrapRunsToWidth, writePdf };
27
+ export { ByteReader, ByteWriter, DEFAULT_VERTICAL_METRIC_POLICY, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, MAX_INFLATE_OUTPUT_BYTES, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, concatBytes, crc32, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readJpeg2000Metadata, readJpegInfo, readPdf, resolveFaceWithRegistry, resolveStandardFont, rotatePointAboutCenter, scaleMathStretchConstruction, unfilterScanlines, wrapRunsToWidth, writePdf };
@@ -0,0 +1,9 @@
1
+ //#region src/image/jbig2-errors.d.ts
2
+ declare class Jbig2ParseError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ declare class Jbig2UnsupportedError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ //#endregion
9
+ export { Jbig2UnsupportedError as n, Jbig2ParseError as t };
@@ -0,0 +1,9 @@
1
+ //#region src/image/jbig2-errors.d.ts
2
+ declare class Jbig2ParseError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ declare class Jbig2UnsupportedError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ //#endregion
9
+ export { Jbig2UnsupportedError as n, Jbig2ParseError as t };
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_objects = require("./objects.cjs");
3
3
  const require_bytes_flate = require("./bytes/flate.cjs");
4
+ const require_tounicode = require("./tounicode.cjs");
4
5
  //#region src/math-font-write.ts
5
6
  const FLAG_SYMBOLIC = 4;
6
7
  const NOMINAL_STEM_V = 80;
@@ -37,36 +38,6 @@ function buildFontFileStream(font, compress) {
37
38
  } : { Subtype: require_objects.pdfName("CIDFontType0C") });
38
39
  return require_objects.pdfStream(dict, compress ? require_bytes_flate.deflate(font.cffBytes) : font.cffBytes);
39
40
  }
40
- function codePointToUtf16BEHex(codePoint) {
41
- const text = String.fromCodePoint(codePoint);
42
- let hex = "";
43
- for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
44
- return hex;
45
- }
46
- function buildToUnicodeCMap(usedGlyphs) {
47
- const sortedGids = [...usedGlyphs.keys()].sort((a, b) => a - b);
48
- const lines = [
49
- "/CIDInit /ProcSet findresource begin",
50
- "12 dict begin",
51
- "begincmap",
52
- "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
53
- "/CMapName /Adobe-Identity-UCS def",
54
- "/CMapType 2 def",
55
- "1 begincodespacerange",
56
- "<0000> <FFFF>",
57
- "endcodespacerange",
58
- `${sortedGids.length} beginbfchar`
59
- ];
60
- for (const gid of sortedGids) {
61
- const codePoint = usedGlyphs.get(gid);
62
- if (codePoint === void 0) continue;
63
- lines.push(`<${gid.toString(16).padStart(4, "0")}> <${codePointToUtf16BEHex(codePoint)}>`);
64
- }
65
- lines.push("endbfchar", "endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
66
- const text = `${lines.join("\n")}\n`;
67
- const bytes = new TextEncoder().encode(text);
68
- return require_objects.pdfStream(require_objects.pdfDict({}), bytes);
69
- }
70
41
  function buildMathFontObjects(font, usedGlyphs, refs, compress) {
71
42
  const cidFont = require_objects.pdfDict({
72
43
  Type: require_objects.pdfName("Font"),
@@ -93,7 +64,7 @@ function buildMathFontObjects(font, usedGlyphs, refs, compress) {
93
64
  cidFont,
94
65
  descriptor: buildFontDescriptor(font, refs.fontFileRef),
95
66
  fontFile: buildFontFileStream(font, compress),
96
- toUnicode: buildToUnicodeCMap(usedGlyphs)
67
+ toUnicode: require_tounicode.buildToUnicodeCMap(usedGlyphs)
97
68
  };
98
69
  }
99
70
  //#endregion
@@ -1,5 +1,6 @@
1
1
  import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNum, pdfStream } from "./objects.js";
2
2
  import { deflate } from "./bytes/flate.js";
3
+ import { buildToUnicodeCMap } from "./tounicode.js";
3
4
  //#region src/math-font-write.ts
4
5
  const FLAG_SYMBOLIC = 4;
5
6
  const NOMINAL_STEM_V = 80;
@@ -36,36 +37,6 @@ function buildFontFileStream(font, compress) {
36
37
  } : { Subtype: pdfName("CIDFontType0C") });
37
38
  return pdfStream(dict, compress ? deflate(font.cffBytes) : font.cffBytes);
38
39
  }
39
- function codePointToUtf16BEHex(codePoint) {
40
- const text = String.fromCodePoint(codePoint);
41
- let hex = "";
42
- for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
43
- return hex;
44
- }
45
- function buildToUnicodeCMap(usedGlyphs) {
46
- const sortedGids = [...usedGlyphs.keys()].sort((a, b) => a - b);
47
- const lines = [
48
- "/CIDInit /ProcSet findresource begin",
49
- "12 dict begin",
50
- "begincmap",
51
- "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
52
- "/CMapName /Adobe-Identity-UCS def",
53
- "/CMapType 2 def",
54
- "1 begincodespacerange",
55
- "<0000> <FFFF>",
56
- "endcodespacerange",
57
- `${sortedGids.length} beginbfchar`
58
- ];
59
- for (const gid of sortedGids) {
60
- const codePoint = usedGlyphs.get(gid);
61
- if (codePoint === void 0) continue;
62
- lines.push(`<${gid.toString(16).padStart(4, "0")}> <${codePointToUtf16BEHex(codePoint)}>`);
63
- }
64
- lines.push("endbfchar", "endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
65
- const text = `${lines.join("\n")}\n`;
66
- const bytes = new TextEncoder().encode(text);
67
- return pdfStream(pdfDict({}), bytes);
68
- }
69
40
  function buildMathFontObjects(font, usedGlyphs, refs, compress) {
70
41
  const cidFont = pdfDict({
71
42
  Type: pdfName("Font"),
@@ -1,15 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ const require_cff_bounds = require("./cff-bounds.cjs");
4
+ const require_cmap_table = require("./cmap-table.cjs");
2
5
  const require_util_base64 = require("./util/base64.cjs");
6
+ const require_hmtx_table = require("./hmtx-table.cjs");
3
7
  const require_assets_stix_two_math_font = require("./assets/stix-two-math-font.cjs");
4
- const require_sfnt = require("./sfnt.cjs");
5
- const require_math_cmap = require("./math-cmap.cjs");
6
- const require_math_hmtx = require("./math-hmtx.cjs");
8
+ const require_math_stretch = require("./math-stretch.cjs");
7
9
  const require_math_table = require("./math-table.cjs");
8
10
  //#region src/math-font.ts
9
11
  function toPt(designUnits, unitsPerEm, sizePt) {
10
12
  return designUnits / unitsPerEm * sizePt;
11
13
  }
12
- function metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt) {
14
+ function metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt) {
13
15
  const c = math.constants;
14
16
  const pt = (designUnits) => toPt(designUnits, unitsPerEm, sizePt);
15
17
  return {
@@ -52,10 +54,13 @@ function metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentD
52
54
  const advanceWidthPt = toPt(hmtx.advanceWidth(glyphId), unitsPerEm, glyphSizePt);
53
55
  const italicCorrectionDesignUnits = math.glyphInfo.italicsCorrection.get(glyphId) ?? 0;
54
56
  const topAccentDesignUnits = math.glyphInfo.topAccentAttachment.get(glyphId);
57
+ const ink = inkBounds?.bounds(glyphId);
55
58
  return {
56
59
  advanceWidthPt,
57
60
  italicCorrectionPt: toPt(italicCorrectionDesignUnits, unitsPerEm, glyphSizePt),
58
- topAccentXPt: topAccentDesignUnits === void 0 ? void 0 : toPt(topAccentDesignUnits, unitsPerEm, glyphSizePt)
61
+ topAccentXPt: topAccentDesignUnits === void 0 ? void 0 : toPt(topAccentDesignUnits, unitsPerEm, glyphSizePt),
62
+ inkAscentPt: ink === void 0 ? void 0 : toPt(ink.yMax, unitsPerEm, glyphSizePt),
63
+ inkDescentPt: ink === void 0 ? void 0 : toPt(-ink.yMin, unitsPerEm, glyphSizePt)
59
64
  };
60
65
  }
61
66
  };
@@ -65,6 +70,7 @@ function loadMathFont() {
65
70
  if (cached !== void 0) return cached;
66
71
  const bytes = require_util_base64.base64ToBytes(require_assets_stix_two_math_font.STIX_TWO_MATH_FONT_BASE64);
67
72
  const sfnt = require_sfnt.parseSfnt(bytes);
73
+ if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
68
74
  const headBytes = require_sfnt.sfntTableBytes(sfnt, "head");
69
75
  const hheaBytes = require_sfnt.sfntTableBytes(sfnt, "hhea");
70
76
  const os2Bytes = require_sfnt.sfntTableBytes(sfnt, "OS/2");
@@ -76,26 +82,47 @@ function loadMathFont() {
76
82
  const bboxMin = [require_sfnt.i16(headBytes, 36), require_sfnt.i16(headBytes, 38)];
77
83
  const bboxMax = [require_sfnt.i16(headBytes, 40), require_sfnt.i16(headBytes, 42)];
78
84
  const capHeight = os2Bytes === void 0 ? ascentDesignUnits : require_sfnt.i16(os2Bytes, 88);
79
- const cmap = require_math_cmap.buildCmapLookup(sfnt);
80
- const hmtx = require_math_hmtx.parseHmtx(sfnt);
85
+ const cmap = require_cmap_table.buildCmapLookup(sfnt);
86
+ if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
87
+ const hmtx = require_hmtx_table.parseHmtx(sfnt);
81
88
  const math = require_math_table.parseMathTable(sfnt);
82
- cached = {
83
- font: {
84
- metrics: metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, unitsPerEm),
85
- cffBytes,
86
- descriptor: {
87
- unitsPerEm,
88
- ascent: ascentDesignUnits,
89
- descent: descentDesignUnits,
90
- capHeight,
91
- bboxMin,
92
- bboxMax,
93
- italicAngle: 0
94
- },
95
- glyphId: (codePoint) => cmap(codePoint),
96
- glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm
89
+ const inkBounds = require_cff_bounds.parseCffGlyphBounds(cffBytes);
90
+ const font = {
91
+ metrics: metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, unitsPerEm),
92
+ cffBytes,
93
+ descriptor: {
94
+ unitsPerEm,
95
+ ascent: ascentDesignUnits,
96
+ descent: descentDesignUnits,
97
+ capHeight,
98
+ bboxMin,
99
+ bboxMax,
100
+ italicAngle: 0
97
101
  },
98
- metricsAt: (sizePt) => metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt)
102
+ glyphId: (codePoint) => cmap(codePoint),
103
+ glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm,
104
+ glyphInkBounds: (glyphId) => inkBounds?.bounds(glyphId),
105
+ minConnectorOverlap: math.variants.minConnectorOverlap,
106
+ stretchyConstruction: (codePoint, axis) => {
107
+ const glyphId = cmap(codePoint);
108
+ if (glyphId === void 0) return;
109
+ return (axis === "vertical" ? math.variants.vertical : math.variants.horizontal).get(glyphId);
110
+ }
111
+ };
112
+ cached = {
113
+ font,
114
+ metricsAt: (sizePt) => metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt),
115
+ stretchGlyph: (codePoint, axis, targetSizePt, sizePt) => {
116
+ const construction = font.stretchyConstruction(codePoint, axis);
117
+ if (construction === void 0) return;
118
+ const designUnitsPerPt = unitsPerEm / sizePt;
119
+ const assembled = require_math_stretch.assembleStretchyGlyph(construction, {
120
+ axis,
121
+ targetSize: targetSizePt * designUnitsPerPt,
122
+ minConnectorOverlap: math.variants.minConnectorOverlap
123
+ });
124
+ return assembled === void 0 ? void 0 : require_math_stretch.scaleMathStretchConstruction(assembled, 1 / designUnitsPerPt);
125
+ }
99
126
  };
100
127
  return cached;
101
128
  }
@@ -1,4 +1,7 @@
1
- import { r as MathFontMetrics } from "./math-types-Ba8qAf1p.cjs";
1
+ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
2
+ import { r as MathFontMetrics } from "./math-types-YSQUTviw.cjs";
3
+ import { r as MathGlyphConstruction } from "./math-table-gFNB8DmQ.cjs";
4
+ import { n as MathStretchConstruction, t as MathStretchAxis } from "./math-stretch-DXWjs8gL.cjs";
2
5
  //#region src/math-font.d.ts
3
6
  interface MathFontDescriptorMetrics {
4
7
  readonly unitsPerEm: number;
@@ -15,10 +18,14 @@ interface MathFont {
15
18
  readonly descriptor: MathFontDescriptorMetrics;
16
19
  glyphId(codePoint: number): number | undefined;
17
20
  glyphSpaceWidth(glyphId: number): number;
21
+ glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
22
+ readonly minConnectorOverlap: number;
23
+ stretchyConstruction(codePoint: number, axis: MathStretchAxis): MathGlyphConstruction | undefined;
18
24
  }
19
25
  interface LoadedMathFont {
20
26
  readonly font: MathFont;
21
27
  readonly metricsAt: (sizePt: number) => MathFontMetrics;
28
+ readonly stretchGlyph: (codePoint: number, axis: MathStretchAxis, targetSizePt: number, sizePt: number) => MathStretchConstruction | undefined;
22
29
  }
23
30
  declare function loadMathFont(): LoadedMathFont;
24
31
  //#endregion
@@ -1,4 +1,7 @@
1
- import { r as MathFontMetrics } from "./math-types-Ba8qAf1p.js";
1
+ import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
2
+ import { r as MathFontMetrics } from "./math-types-YSQUTviw.js";
3
+ import { r as MathGlyphConstruction } from "./math-table-DhPrNoPa.js";
4
+ import { n as MathStretchConstruction, t as MathStretchAxis } from "./math-stretch-Bwk_bxh1.js";
2
5
  //#region src/math-font.d.ts
3
6
  interface MathFontDescriptorMetrics {
4
7
  readonly unitsPerEm: number;
@@ -15,10 +18,14 @@ interface MathFont {
15
18
  readonly descriptor: MathFontDescriptorMetrics;
16
19
  glyphId(codePoint: number): number | undefined;
17
20
  glyphSpaceWidth(glyphId: number): number;
21
+ glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
22
+ readonly minConnectorOverlap: number;
23
+ stretchyConstruction(codePoint: number, axis: MathStretchAxis): MathGlyphConstruction | undefined;
18
24
  }
19
25
  interface LoadedMathFont {
20
26
  readonly font: MathFont;
21
27
  readonly metricsAt: (sizePt: number) => MathFontMetrics;
28
+ readonly stretchGlyph: (codePoint: number, axis: MathStretchAxis, targetSizePt: number, sizePt: number) => MathStretchConstruction | undefined;
22
29
  }
23
30
  declare function loadMathFont(): LoadedMathFont;
24
31
  //#endregion
package/dist/math-font.js CHANGED
@@ -1,14 +1,16 @@
1
+ import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
2
+ import { parseCffGlyphBounds } from "./cff-bounds.js";
3
+ import { buildCmapLookup } from "./cmap-table.js";
1
4
  import { base64ToBytes } from "./util/base64.js";
5
+ import { parseHmtx } from "./hmtx-table.js";
2
6
  import { STIX_TWO_MATH_FONT_BASE64 } from "./assets/stix-two-math-font.js";
3
- import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
4
- import { buildCmapLookup } from "./math-cmap.js";
5
- import { parseHmtx } from "./math-hmtx.js";
7
+ import { assembleStretchyGlyph, scaleMathStretchConstruction } from "./math-stretch.js";
6
8
  import { parseMathTable } from "./math-table.js";
7
9
  //#region src/math-font.ts
8
10
  function toPt(designUnits, unitsPerEm, sizePt) {
9
11
  return designUnits / unitsPerEm * sizePt;
10
12
  }
11
- function metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt) {
13
+ function metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt) {
12
14
  const c = math.constants;
13
15
  const pt = (designUnits) => toPt(designUnits, unitsPerEm, sizePt);
14
16
  return {
@@ -51,10 +53,13 @@ function metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentD
51
53
  const advanceWidthPt = toPt(hmtx.advanceWidth(glyphId), unitsPerEm, glyphSizePt);
52
54
  const italicCorrectionDesignUnits = math.glyphInfo.italicsCorrection.get(glyphId) ?? 0;
53
55
  const topAccentDesignUnits = math.glyphInfo.topAccentAttachment.get(glyphId);
56
+ const ink = inkBounds?.bounds(glyphId);
54
57
  return {
55
58
  advanceWidthPt,
56
59
  italicCorrectionPt: toPt(italicCorrectionDesignUnits, unitsPerEm, glyphSizePt),
57
- topAccentXPt: topAccentDesignUnits === void 0 ? void 0 : toPt(topAccentDesignUnits, unitsPerEm, glyphSizePt)
60
+ topAccentXPt: topAccentDesignUnits === void 0 ? void 0 : toPt(topAccentDesignUnits, unitsPerEm, glyphSizePt),
61
+ inkAscentPt: ink === void 0 ? void 0 : toPt(ink.yMax, unitsPerEm, glyphSizePt),
62
+ inkDescentPt: ink === void 0 ? void 0 : toPt(-ink.yMin, unitsPerEm, glyphSizePt)
58
63
  };
59
64
  }
60
65
  };
@@ -64,6 +69,7 @@ function loadMathFont() {
64
69
  if (cached !== void 0) return cached;
65
70
  const bytes = base64ToBytes(STIX_TWO_MATH_FONT_BASE64);
66
71
  const sfnt = parseSfnt(bytes);
72
+ if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
67
73
  const headBytes = sfntTableBytes(sfnt, "head");
68
74
  const hheaBytes = sfntTableBytes(sfnt, "hhea");
69
75
  const os2Bytes = sfntTableBytes(sfnt, "OS/2");
@@ -76,25 +82,46 @@ function loadMathFont() {
76
82
  const bboxMax = [i16(headBytes, 40), i16(headBytes, 42)];
77
83
  const capHeight = os2Bytes === void 0 ? ascentDesignUnits : i16(os2Bytes, 88);
78
84
  const cmap = buildCmapLookup(sfnt);
85
+ if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
79
86
  const hmtx = parseHmtx(sfnt);
80
87
  const math = parseMathTable(sfnt);
81
- cached = {
82
- font: {
83
- metrics: metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, unitsPerEm),
84
- cffBytes,
85
- descriptor: {
86
- unitsPerEm,
87
- ascent: ascentDesignUnits,
88
- descent: descentDesignUnits,
89
- capHeight,
90
- bboxMin,
91
- bboxMax,
92
- italicAngle: 0
93
- },
94
- glyphId: (codePoint) => cmap(codePoint),
95
- glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm
88
+ const inkBounds = parseCffGlyphBounds(cffBytes);
89
+ const font = {
90
+ metrics: metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, unitsPerEm),
91
+ cffBytes,
92
+ descriptor: {
93
+ unitsPerEm,
94
+ ascent: ascentDesignUnits,
95
+ descent: descentDesignUnits,
96
+ capHeight,
97
+ bboxMin,
98
+ bboxMax,
99
+ italicAngle: 0
96
100
  },
97
- metricsAt: (sizePt) => metricsAtSize(cmap, hmtx, math, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt)
101
+ glyphId: (codePoint) => cmap(codePoint),
102
+ glyphSpaceWidth: (glyphId) => hmtx.advanceWidth(glyphId) * 1e3 / unitsPerEm,
103
+ glyphInkBounds: (glyphId) => inkBounds?.bounds(glyphId),
104
+ minConnectorOverlap: math.variants.minConnectorOverlap,
105
+ stretchyConstruction: (codePoint, axis) => {
106
+ const glyphId = cmap(codePoint);
107
+ if (glyphId === void 0) return;
108
+ return (axis === "vertical" ? math.variants.vertical : math.variants.horizontal).get(glyphId);
109
+ }
110
+ };
111
+ cached = {
112
+ font,
113
+ metricsAt: (sizePt) => metricsAtSize(cmap, hmtx, math, inkBounds, unitsPerEm, ascentDesignUnits, descentDesignUnits, sizePt),
114
+ stretchGlyph: (codePoint, axis, targetSizePt, sizePt) => {
115
+ const construction = font.stretchyConstruction(codePoint, axis);
116
+ if (construction === void 0) return;
117
+ const designUnitsPerPt = unitsPerEm / sizePt;
118
+ const assembled = assembleStretchyGlyph(construction, {
119
+ axis,
120
+ targetSize: targetSizePt * designUnitsPerPt,
121
+ minConnectorOverlap: math.variants.minConnectorOverlap
122
+ });
123
+ return assembled === void 0 ? void 0 : scaleMathStretchConstruction(assembled, 1 / designUnitsPerPt);
124
+ }
98
125
  };
99
126
  return cached;
100
127
  }
@@ -0,0 +1,24 @@
1
+ import { r as MathGlyphConstruction } from "./math-table-DhPrNoPa.js";
2
+ //#region src/math-stretch.d.ts
3
+ type MathStretchAxis = 'vertical' | 'horizontal';
4
+ interface MathStretchPlacement {
5
+ readonly glyphId: number;
6
+ readonly offset: number;
7
+ readonly advance: number;
8
+ }
9
+ interface MathStretchConstruction {
10
+ readonly kind: 'base' | 'variant' | 'assembly';
11
+ readonly axis: MathStretchAxis;
12
+ readonly size: number;
13
+ readonly italicsCorrection: number;
14
+ readonly placements: readonly MathStretchPlacement[];
15
+ }
16
+ interface MathStretchOptions {
17
+ readonly axis: MathStretchAxis;
18
+ readonly targetSize: number;
19
+ readonly minConnectorOverlap: number;
20
+ }
21
+ declare function assembleStretchyGlyph(construction: MathGlyphConstruction, options: MathStretchOptions): MathStretchConstruction | undefined;
22
+ declare function scaleMathStretchConstruction(construction: MathStretchConstruction, factor: number): MathStretchConstruction;
23
+ //#endregion
24
+ export { assembleStretchyGlyph as a, MathStretchPlacement as i, MathStretchConstruction as n, scaleMathStretchConstruction as o, MathStretchOptions as r, MathStretchAxis as t };
@@ -0,0 +1,24 @@
1
+ import { r as MathGlyphConstruction } from "./math-table-gFNB8DmQ.cjs";
2
+ //#region src/math-stretch.d.ts
3
+ type MathStretchAxis = 'vertical' | 'horizontal';
4
+ interface MathStretchPlacement {
5
+ readonly glyphId: number;
6
+ readonly offset: number;
7
+ readonly advance: number;
8
+ }
9
+ interface MathStretchConstruction {
10
+ readonly kind: 'base' | 'variant' | 'assembly';
11
+ readonly axis: MathStretchAxis;
12
+ readonly size: number;
13
+ readonly italicsCorrection: number;
14
+ readonly placements: readonly MathStretchPlacement[];
15
+ }
16
+ interface MathStretchOptions {
17
+ readonly axis: MathStretchAxis;
18
+ readonly targetSize: number;
19
+ readonly minConnectorOverlap: number;
20
+ }
21
+ declare function assembleStretchyGlyph(construction: MathGlyphConstruction, options: MathStretchOptions): MathStretchConstruction | undefined;
22
+ declare function scaleMathStretchConstruction(construction: MathStretchConstruction, factor: number): MathStretchConstruction;
23
+ //#endregion
24
+ export { assembleStretchyGlyph as a, MathStretchPlacement as i, MathStretchConstruction as n, scaleMathStretchConstruction as o, MathStretchOptions as r, MathStretchAxis as t };
@@ -0,0 +1,96 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/math-stretch.ts
3
+ function sumBy(items, value) {
4
+ return items.reduce((total, item) => total + value(item), 0);
5
+ }
6
+ function requiredRepeatCount(fixed, extenders, targetSize, minConnectorOverlap) {
7
+ const minimumRepeat = fixed.length === 0 ? 1 : 0;
8
+ if (extenders.length === 0) return minimumRepeat;
9
+ const growthPerRepeat = sumBy(extenders, (part) => part.fullAdvance) - extenders.length * minConnectorOverlap;
10
+ if (growthPerRepeat <= 0) return minimumRepeat;
11
+ const shortfall = targetSize - sumBy(fixed, (part) => part.fullAdvance) + (fixed.length - 1) * minConnectorOverlap;
12
+ return Math.max(minimumRepeat, Math.ceil(shortfall / growthPerRepeat));
13
+ }
14
+ function expandParts(parts, repeatCount) {
15
+ const expanded = [];
16
+ for (const part of parts) for (let i = 0; i < (part.isExtender ? repeatCount : 1); i++) expanded.push(part);
17
+ return expanded;
18
+ }
19
+ function maximumOverlap(expanded) {
20
+ let overlap = Number.POSITIVE_INFINITY;
21
+ for (let i = 0; i + 1 < expanded.length; i++) overlap = Math.min(overlap, expanded[i].endConnectorLength, expanded[i + 1].startConnectorLength);
22
+ for (let i = 0; i < expanded.length; i++) {
23
+ const joins = (i === 0 ? 0 : 1) + (i === expanded.length - 1 ? 0 : 1);
24
+ if (joins > 0) overlap = Math.min(overlap, expanded[i].fullAdvance / joins);
25
+ }
26
+ return overlap;
27
+ }
28
+ function assembleFromParts(assembly, options) {
29
+ const fixed = assembly.parts.filter((part) => !part.isExtender);
30
+ const extenders = assembly.parts.filter((part) => part.isExtender);
31
+ const expanded = expandParts(assembly.parts, requiredRepeatCount(fixed, extenders, options.targetSize, options.minConnectorOverlap));
32
+ if (expanded.length === 0) return;
33
+ const joins = expanded.length - 1;
34
+ const maxOverlap = maximumOverlap(expanded);
35
+ const minOverlap = Math.min(options.minConnectorOverlap, maxOverlap);
36
+ const totalAdvance = sumBy(expanded, (part) => part.fullAdvance);
37
+ const exactOverlap = joins === 0 ? minOverlap : (totalAdvance - options.targetSize) / joins;
38
+ const overlap = Math.min(Math.max(exactOverlap, minOverlap), maxOverlap);
39
+ const placements = [];
40
+ let offset = 0;
41
+ for (const part of expanded) {
42
+ placements.push({
43
+ glyphId: part.glyphId,
44
+ offset,
45
+ advance: part.fullAdvance
46
+ });
47
+ offset += part.fullAdvance - overlap;
48
+ }
49
+ return {
50
+ kind: "assembly",
51
+ axis: options.axis,
52
+ size: totalAdvance - joins * overlap,
53
+ italicsCorrection: assembly.italicsCorrection,
54
+ placements
55
+ };
56
+ }
57
+ function fromVariant(variant, isBaseGlyph, axis) {
58
+ return {
59
+ kind: isBaseGlyph ? "base" : "variant",
60
+ axis,
61
+ size: variant.advanceMeasurement,
62
+ italicsCorrection: 0,
63
+ placements: [{
64
+ glyphId: variant.glyphId,
65
+ offset: 0,
66
+ advance: variant.advanceMeasurement
67
+ }]
68
+ };
69
+ }
70
+ function assembleStretchyGlyph(construction, options) {
71
+ const variants = construction.variants;
72
+ const reaching = variants.findIndex((variant) => variant.advanceMeasurement >= options.targetSize);
73
+ if (reaching !== -1) return fromVariant(variants[reaching], reaching === 0, options.axis);
74
+ if (construction.assembly !== void 0) {
75
+ const assembled = assembleFromParts(construction.assembly, options);
76
+ if (assembled !== void 0) return assembled;
77
+ }
78
+ const largest = variants[variants.length - 1];
79
+ return largest === void 0 ? void 0 : fromVariant(largest, variants.length === 1, options.axis);
80
+ }
81
+ function scaleMathStretchConstruction(construction, factor) {
82
+ return {
83
+ kind: construction.kind,
84
+ axis: construction.axis,
85
+ size: construction.size * factor,
86
+ italicsCorrection: construction.italicsCorrection * factor,
87
+ placements: construction.placements.map((placement) => ({
88
+ glyphId: placement.glyphId,
89
+ offset: placement.offset * factor,
90
+ advance: placement.advance * factor
91
+ }))
92
+ };
93
+ }
94
+ //#endregion
95
+ exports.assembleStretchyGlyph = assembleStretchyGlyph;
96
+ exports.scaleMathStretchConstruction = scaleMathStretchConstruction;
@@ -0,0 +1,2 @@
1
+ import { a as assembleStretchyGlyph, i as MathStretchPlacement, n as MathStretchConstruction, o as scaleMathStretchConstruction, r as MathStretchOptions, t as MathStretchAxis } from "./math-stretch-DXWjs8gL.cjs";
2
+ export { MathStretchAxis, MathStretchConstruction, MathStretchOptions, MathStretchPlacement, assembleStretchyGlyph, scaleMathStretchConstruction };
@@ -0,0 +1,2 @@
1
+ import { a as assembleStretchyGlyph, i as MathStretchPlacement, n as MathStretchConstruction, o as scaleMathStretchConstruction, r as MathStretchOptions, t as MathStretchAxis } from "./math-stretch-Bwk_bxh1.js";
2
+ export { MathStretchAxis, MathStretchConstruction, MathStretchOptions, MathStretchPlacement, assembleStretchyGlyph, scaleMathStretchConstruction };