pdf-codec 1.5.0 → 1.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.
Files changed (118) hide show
  1. package/README.md +36 -3
  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-probe.cjs +133 -0
  35. package/dist/cff-probe.d.cts +10 -0
  36. package/dist/cff-probe.d.ts +10 -0
  37. package/dist/cff-probe.js +132 -0
  38. package/dist/cmap-table.cjs +108 -0
  39. package/dist/cmap-table.d.cts +6 -0
  40. package/dist/cmap-table.d.ts +6 -0
  41. package/dist/cmap-table.js +107 -0
  42. package/dist/content-write.cjs +34 -14
  43. package/dist/content-write.d.cts +9 -2
  44. package/dist/content-write.d.ts +9 -2
  45. package/dist/content-write.js +34 -14
  46. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  47. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  48. package/dist/embedded-font-write.cjs +92 -0
  49. package/dist/embedded-font-write.d.cts +22 -0
  50. package/dist/embedded-font-write.d.ts +22 -0
  51. package/dist/embedded-font-write.js +90 -0
  52. package/dist/embedded-font.cjs +142 -0
  53. package/dist/embedded-font.d.cts +2 -0
  54. package/dist/embedded-font.d.ts +2 -0
  55. package/dist/embedded-font.js +138 -0
  56. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  57. package/dist/font-registry-yby02snZ.d.cts +38 -0
  58. package/dist/font-registry.cjs +152 -0
  59. package/dist/font-registry.d.cts +2 -0
  60. package/dist/font-registry.d.ts +2 -0
  61. package/dist/font-registry.js +150 -0
  62. package/dist/font-substitutes.cjs +13 -0
  63. package/dist/font-substitutes.d.cts +5 -0
  64. package/dist/font-substitutes.d.ts +5 -0
  65. package/dist/font-substitutes.js +12 -0
  66. package/dist/font-tables.cjs +127 -0
  67. package/dist/font-tables.d.cts +43 -0
  68. package/dist/font-tables.d.ts +43 -0
  69. package/dist/font-tables.js +122 -0
  70. package/dist/fonts.cjs +1 -0
  71. package/dist/fonts.d.cts +2 -1
  72. package/dist/fonts.d.ts +2 -1
  73. package/dist/fonts.js +1 -1
  74. package/dist/glyf.cjs +127 -0
  75. package/dist/glyf.d.cts +31 -0
  76. package/dist/glyf.d.ts +31 -0
  77. package/dist/glyf.js +125 -0
  78. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  79. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  80. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  81. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  82. package/dist/index.cjs +5 -0
  83. package/dist/index.d.cts +4 -2
  84. package/dist/index.d.ts +4 -2
  85. package/dist/index.js +3 -2
  86. package/dist/math-font-write.cjs +2 -31
  87. package/dist/math-font-write.js +1 -30
  88. package/dist/math-font.cjs +7 -5
  89. package/dist/math-font.js +5 -3
  90. package/dist/math-table.d.cts +1 -1
  91. package/dist/math-table.d.ts +1 -1
  92. package/dist/measure.cjs +65 -14
  93. package/dist/measure.d.cts +8 -1
  94. package/dist/measure.d.ts +8 -1
  95. package/dist/measure.js +64 -15
  96. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  97. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  98. package/dist/sfnt-subset.cjs +250 -0
  99. package/dist/sfnt-subset.d.cts +11 -0
  100. package/dist/sfnt-subset.d.ts +11 -0
  101. package/dist/sfnt-subset.js +249 -0
  102. package/dist/sfnt.cjs +50 -4
  103. package/dist/sfnt.d.cts +2 -17
  104. package/dist/sfnt.d.ts +2 -17
  105. package/dist/sfnt.js +47 -5
  106. package/dist/tounicode.cjs +34 -0
  107. package/dist/tounicode.d.cts +5 -0
  108. package/dist/tounicode.d.ts +5 -0
  109. package/dist/tounicode.js +33 -0
  110. package/dist/write.cjs +80 -10
  111. package/dist/write.d.cts +6 -0
  112. package/dist/write.d.ts +6 -0
  113. package/dist/write.js +81 -11
  114. package/package.json +1 -1
  115. package/dist/math-cmap.cjs +0 -81
  116. package/dist/math-cmap.d.cts +0 -6
  117. package/dist/math-cmap.d.ts +0 -6
  118. package/dist/math-cmap.js +0 -80
package/dist/glyf.js ADDED
@@ -0,0 +1,125 @@
1
+ import { f2dot14, hasBytes, i16, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
2
+ //#region src/glyf.ts
3
+ const LOCA_SHORT_ENTRY_SIZE = 2;
4
+ const LOCA_LONG_ENTRY_SIZE = 4;
5
+ const LOCA_SHORT_OFFSET_SCALE = 2;
6
+ function parseLoca(font, options) {
7
+ const bytes = sfntTableBytes(font, "loca");
8
+ if (bytes === void 0) return;
9
+ const entryCount = options.numGlyphs + 1;
10
+ const entrySize = options.indexToLocFormat === 0 ? LOCA_SHORT_ENTRY_SIZE : LOCA_LONG_ENTRY_SIZE;
11
+ if (!hasBytes(bytes, 0, entryCount * entrySize)) return;
12
+ const offsets = [];
13
+ for (let i = 0; i < entryCount; i++) offsets.push(options.indexToLocFormat === 0 ? u16(bytes, i * LOCA_SHORT_ENTRY_SIZE) * LOCA_SHORT_OFFSET_SCALE : u32(bytes, i * LOCA_LONG_ENTRY_SIZE));
14
+ return offsets;
15
+ }
16
+ const GLYPH_HEADER_SIZE = 10;
17
+ const ARG_1_AND_2_ARE_WORDS = 1;
18
+ const ARGS_ARE_XY_VALUES = 2;
19
+ const WE_HAVE_A_SCALE = 8;
20
+ const MORE_COMPONENTS = 32;
21
+ const WE_HAVE_AN_X_AND_Y_SCALE = 64;
22
+ const WE_HAVE_A_TWO_BY_TWO = 128;
23
+ const COMPONENT_RECORD_HEADER_SIZE = 4;
24
+ function signedByte(value) {
25
+ return value >= 128 ? value - 256 : value;
26
+ }
27
+ function readComponents(glyph) {
28
+ const components = [];
29
+ let offset = GLYPH_HEADER_SIZE;
30
+ for (;;) {
31
+ if (!hasBytes(glyph, offset, COMPONENT_RECORD_HEADER_SIZE)) return;
32
+ const flags = u16(glyph, offset);
33
+ const glyphIndex = u16(glyph, offset + 2);
34
+ offset += COMPONENT_RECORD_HEADER_SIZE;
35
+ const argsAreWords = (flags & ARG_1_AND_2_ARE_WORDS) !== 0;
36
+ const argsAreXyValues = (flags & ARGS_ARE_XY_VALUES) !== 0;
37
+ const argsSize = argsAreWords ? 4 : 2;
38
+ if (!hasBytes(glyph, offset, argsSize)) return;
39
+ let argument1;
40
+ let argument2;
41
+ if (argsAreWords) {
42
+ argument1 = argsAreXyValues ? i16(glyph, offset) : u16(glyph, offset);
43
+ argument2 = argsAreXyValues ? i16(glyph, offset + 2) : u16(glyph, offset + 2);
44
+ } else {
45
+ argument1 = argsAreXyValues ? signedByte(u8(glyph, offset)) : u8(glyph, offset);
46
+ argument2 = argsAreXyValues ? signedByte(u8(glyph, offset + 1)) : u8(glyph, offset + 1);
47
+ }
48
+ offset += argsSize;
49
+ let transform;
50
+ if ((flags & WE_HAVE_A_SCALE) !== 0) {
51
+ if (!hasBytes(glyph, offset, 2)) return;
52
+ const scale = f2dot14(glyph, offset);
53
+ transform = [
54
+ scale,
55
+ 0,
56
+ 0,
57
+ scale
58
+ ];
59
+ offset += 2;
60
+ } else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
61
+ if (!hasBytes(glyph, offset, 4)) return;
62
+ transform = [
63
+ f2dot14(glyph, offset),
64
+ 0,
65
+ 0,
66
+ f2dot14(glyph, offset + 2)
67
+ ];
68
+ offset += 4;
69
+ } else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
70
+ if (!hasBytes(glyph, offset, 8)) return;
71
+ transform = [
72
+ f2dot14(glyph, offset),
73
+ f2dot14(glyph, offset + 2),
74
+ f2dot14(glyph, offset + 4),
75
+ f2dot14(glyph, offset + 6)
76
+ ];
77
+ offset += 8;
78
+ }
79
+ components.push({
80
+ flags,
81
+ glyphIndex,
82
+ argument1,
83
+ argument2,
84
+ argsAreXyValues,
85
+ transform
86
+ });
87
+ if ((flags & MORE_COMPONENTS) === 0) return components;
88
+ }
89
+ }
90
+ function parseGlyf(font, options) {
91
+ const glyfBytes = sfntTableBytes(font, "glyf");
92
+ const loca = parseLoca(font, options);
93
+ if (glyfBytes === void 0 || loca === void 0) return;
94
+ const glyphBytes = (glyphId) => {
95
+ if (!Number.isInteger(glyphId) || glyphId < 0 || glyphId >= options.numGlyphs) return;
96
+ const start = loca[glyphId];
97
+ const end = loca[glyphId + 1];
98
+ if (end < start || !hasBytes(glyfBytes, start, end - start)) return;
99
+ return glyfBytes.subarray(start, end);
100
+ };
101
+ const glyphHeader = (glyphId) => {
102
+ const glyph = glyphBytes(glyphId);
103
+ if (glyph === void 0 || !hasBytes(glyph, 0, GLYPH_HEADER_SIZE)) return;
104
+ return {
105
+ numberOfContours: i16(glyph, 0),
106
+ xMin: i16(glyph, 2),
107
+ yMin: i16(glyph, 4),
108
+ xMax: i16(glyph, 6),
109
+ yMax: i16(glyph, 8)
110
+ };
111
+ };
112
+ return {
113
+ numGlyphs: options.numGlyphs,
114
+ glyphBytes,
115
+ glyphHeader,
116
+ compositeComponents(glyphId) {
117
+ const header = glyphHeader(glyphId);
118
+ if (header === void 0 || header.numberOfContours >= 0) return;
119
+ const glyph = glyphBytes(glyphId);
120
+ return glyph === void 0 ? void 0 : readComponents(glyph);
121
+ }
122
+ };
123
+ }
124
+ //#endregion
125
+ export { parseGlyf, parseLoca };
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sfnt = require("./sfnt.cjs");
3
- //#region src/math-hmtx.ts
3
+ //#region src/hmtx-table.ts
4
4
  function parseHmtx(font) {
5
5
  const hheaBytes = require_sfnt.sfntTableBytes(font, "hhea");
6
6
  const hmtxBytes = require_sfnt.sfntTableBytes(font, "hmtx");
7
- if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("math font has no hhea/hmtx table");
7
+ if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
8
8
  const numberOfHMetrics = require_sfnt.u16(hheaBytes, 34);
9
- if (numberOfHMetrics === 0) throw new Error("math font hhea numberOfHMetrics is zero");
9
+ if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
10
10
  const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
11
11
  return { advanceWidth(glyphId) {
12
12
  if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * 4);
@@ -1,5 +1,5 @@
1
- import { SfntFont } from "./sfnt.js";
2
- //#region src/math-hmtx.d.ts
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
+ //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
4
  advanceWidth(glyphId: number): number;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { SfntFont } from "./sfnt.cjs";
2
- //#region src/math-hmtx.d.ts
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
+ //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
4
  advanceWidth(glyphId: number): number;
5
5
  }
@@ -1,11 +1,11 @@
1
1
  import { sfntTableBytes, u16 } from "./sfnt.js";
2
- //#region src/math-hmtx.ts
2
+ //#region src/hmtx-table.ts
3
3
  function parseHmtx(font) {
4
4
  const hheaBytes = sfntTableBytes(font, "hhea");
5
5
  const hmtxBytes = sfntTableBytes(font, "hmtx");
6
- if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("math font has no hhea/hmtx table");
6
+ if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
7
7
  const numberOfHMetrics = u16(hheaBytes, 34);
8
- if (numberOfHMetrics === 0) throw new Error("math font hhea numberOfHMetrics is zero");
8
+ if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
9
9
  const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
10
10
  return { advanceWidth(glyphId) {
11
11
  if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * 4);
package/dist/index.cjs CHANGED
@@ -12,6 +12,7 @@ const require_image_png_encode = require("./image/png-encode.cjs");
12
12
  const require_image_jpeg_info = require("./image/jpeg-info.cjs");
13
13
  const require_matrix = require("./matrix.cjs");
14
14
  const require_image_png_decode = require("./image/png-decode.cjs");
15
+ const require_font_registry = require("./font-registry.cjs");
15
16
  const require_math_font = require("./math-font.cjs");
16
17
  const require_measure = require("./measure.cjs");
17
18
  const require_write = require("./write.cjs");
@@ -20,6 +21,7 @@ const require_codec = require("./codec.cjs");
20
21
  const require_text_layout = require("./text-layout.cjs");
21
22
  exports.ByteReader = require_bytes_reader.ByteReader;
22
23
  exports.ByteWriter = require_bytes_writer.ByteWriter;
24
+ exports.DEFAULT_VERTICAL_METRIC_POLICY = require_measure.DEFAULT_VERTICAL_METRIC_POLICY;
23
25
  exports.MAX_INFLATE_OUTPUT_BYTES = require_bytes_flate.MAX_INFLATE_OUTPUT_BYTES;
24
26
  exports.NOOP_DIAGNOSTIC_SINK = require_diagnostics.NOOP_DIAGNOSTIC_SINK;
25
27
  exports.PdfBytesSchema = require_codec.PdfBytesSchema;
@@ -29,6 +31,8 @@ exports.PdfPasswordRequiredError = require_diagnostics.PdfPasswordRequiredError;
29
31
  exports.STANDARD_METRICS = require_afm_widths.STANDARD_METRICS;
30
32
  exports.concatBytes = require_bytes_writer.concatBytes;
31
33
  exports.crc32 = require_bytes_crc32.crc32;
34
+ exports.createFontMeasurer = require_measure.createFontMeasurer;
35
+ exports.createFontRegistry = require_font_registry.createFontRegistry;
32
36
  exports.createStandardFontMeasurer = require_measure.createStandardFontMeasurer;
33
37
  exports.decodeCcittFax = require_image_ccitt.decodeCcittFax;
34
38
  exports.decodePng = require_image_png_decode.decodePng;
@@ -42,6 +46,7 @@ exports.loadMathFont = require_math_font.loadMathFont;
42
46
  exports.pdfCodec = require_codec.pdfCodec;
43
47
  exports.readJpegInfo = require_image_jpeg_info.readJpegInfo;
44
48
  exports.readPdf = require_read.readPdf;
49
+ exports.resolveFaceWithRegistry = require_font_registry.resolveFaceWithRegistry;
45
50
  exports.resolveStandardFont = require_fonts.resolveStandardFont;
46
51
  exports.rotatePointAboutCenter = require_matrix.rotatePointAboutCenter;
47
52
  exports.unfilterScanlines = require_image_png_filter.unfilterScanlines;
package/dist/index.d.cts CHANGED
@@ -5,7 +5,9 @@ import { ByteReader, isAsciiWhitespace } from "./bytes/reader.cjs";
5
5
  import { ByteWriter, concatBytes } from "./bytes/writer.cjs";
6
6
  import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.cjs";
7
7
  import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
8
- import { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer } from "./measure.cjs";
8
+ import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CLedn-mT.cjs";
9
+ 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-yby02snZ.cjs";
10
+ import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.cjs";
9
11
  import { WinAnsiSubstitution } from "./winansi.cjs";
10
12
  import { i as Point, u as rotatePointAboutCenter } from "./matrix-BHzJESll.cjs";
11
13
  import { ResolvedFont, resolveStandardFont } from "./fonts.cjs";
@@ -20,4 +22,4 @@ import { ReadPdfOptions, readPdf } from "./read.cjs";
20
22
  import { WritePdfOptions, writePdf } from "./write.cjs";
21
23
  import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } from "./math-font.cjs";
22
24
  import { StyledFragment, StyledRun, WrapOptions, WrappedLine, wrapRunsToWidth } from "./text-layout.cjs";
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 };
25
+ 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 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 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, concatBytes, crc32, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, pdfCodec, readJpegInfo, readPdf, resolveFaceWithRegistry, resolveStandardFont, rotatePointAboutCenter, unfilterScanlines, wrapRunsToWidth, writePdf };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,9 @@ import { ByteReader, isAsciiWhitespace } from "./bytes/reader.js";
5
5
  import { ByteWriter, concatBytes } from "./bytes/writer.js";
6
6
  import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
7
7
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
8
- import { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer } from "./measure.js";
8
+ import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CbqkKgBl.js";
9
+ 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";
10
+ import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
9
11
  import { WinAnsiSubstitution } from "./winansi.js";
10
12
  import { i as Point, u as rotatePointAboutCenter } from "./matrix-BHzJESll.js";
11
13
  import { ResolvedFont, resolveStandardFont } from "./fonts.js";
@@ -20,4 +22,4 @@ import { ReadPdfOptions, readPdf } from "./read.js";
20
22
  import { WritePdfOptions, writePdf } from "./write.js";
21
23
  import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } from "./math-font.js";
22
24
  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 };
25
+ 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 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 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, concatBytes, crc32, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, pdfCodec, readJpegInfo, readPdf, resolveFaceWithRegistry, resolveStandardFont, rotatePointAboutCenter, unfilterScanlines, wrapRunsToWidth, writePdf };
package/dist/index.js CHANGED
@@ -11,10 +11,11 @@ import { encodePng } from "./image/png-encode.js";
11
11
  import { readJpegInfo } from "./image/jpeg-info.js";
12
12
  import { rotatePointAboutCenter } from "./matrix.js";
13
13
  import { decodePng } from "./image/png-decode.js";
14
+ import { createFontRegistry, resolveFaceWithRegistry } from "./font-registry.js";
14
15
  import { loadMathFont } from "./math-font.js";
15
- import { createStandardFontMeasurer } from "./measure.js";
16
+ import { DEFAULT_VERTICAL_METRIC_POLICY, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
16
17
  import { writePdf } from "./write.js";
17
18
  import { readPdf } from "./read.js";
18
19
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
19
20
  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 };
21
+ export { ByteReader, ByteWriter, DEFAULT_VERTICAL_METRIC_POLICY, MAX_INFLATE_OUTPUT_BYTES, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, concatBytes, crc32, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodePng, deflate, encodePng, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, loadMathFont, pdfCodec, readJpegInfo, readPdf, resolveFaceWithRegistry, resolveStandardFont, rotatePointAboutCenter, unfilterScanlines, wrapRunsToWidth, writePdf };
@@ -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,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ const require_cmap_table = require("./cmap-table.cjs");
2
4
  const require_util_base64 = require("./util/base64.cjs");
5
+ const require_hmtx_table = require("./hmtx-table.cjs");
3
6
  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");
7
7
  const require_math_table = require("./math-table.cjs");
8
8
  //#region src/math-font.ts
9
9
  function toPt(designUnits, unitsPerEm, sizePt) {
@@ -65,6 +65,7 @@ function loadMathFont() {
65
65
  if (cached !== void 0) return cached;
66
66
  const bytes = require_util_base64.base64ToBytes(require_assets_stix_two_math_font.STIX_TWO_MATH_FONT_BASE64);
67
67
  const sfnt = require_sfnt.parseSfnt(bytes);
68
+ if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
68
69
  const headBytes = require_sfnt.sfntTableBytes(sfnt, "head");
69
70
  const hheaBytes = require_sfnt.sfntTableBytes(sfnt, "hhea");
70
71
  const os2Bytes = require_sfnt.sfntTableBytes(sfnt, "OS/2");
@@ -76,8 +77,9 @@ function loadMathFont() {
76
77
  const bboxMin = [require_sfnt.i16(headBytes, 36), require_sfnt.i16(headBytes, 38)];
77
78
  const bboxMax = [require_sfnt.i16(headBytes, 40), require_sfnt.i16(headBytes, 42)];
78
79
  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);
80
+ const cmap = require_cmap_table.buildCmapLookup(sfnt);
81
+ if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
82
+ const hmtx = require_hmtx_table.parseHmtx(sfnt);
81
83
  const math = require_math_table.parseMathTable(sfnt);
82
84
  cached = {
83
85
  font: {
package/dist/math-font.js CHANGED
@@ -1,8 +1,8 @@
1
+ import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
2
+ import { buildCmapLookup } from "./cmap-table.js";
1
3
  import { base64ToBytes } from "./util/base64.js";
4
+ import { parseHmtx } from "./hmtx-table.js";
2
5
  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";
6
6
  import { parseMathTable } from "./math-table.js";
7
7
  //#region src/math-font.ts
8
8
  function toPt(designUnits, unitsPerEm, sizePt) {
@@ -64,6 +64,7 @@ function loadMathFont() {
64
64
  if (cached !== void 0) return cached;
65
65
  const bytes = base64ToBytes(STIX_TWO_MATH_FONT_BASE64);
66
66
  const sfnt = parseSfnt(bytes);
67
+ if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
67
68
  const headBytes = sfntTableBytes(sfnt, "head");
68
69
  const hheaBytes = sfntTableBytes(sfnt, "hhea");
69
70
  const os2Bytes = sfntTableBytes(sfnt, "OS/2");
@@ -76,6 +77,7 @@ function loadMathFont() {
76
77
  const bboxMax = [i16(headBytes, 40), i16(headBytes, 42)];
77
78
  const capHeight = os2Bytes === void 0 ? ascentDesignUnits : i16(os2Bytes, 88);
78
79
  const cmap = buildCmapLookup(sfnt);
80
+ if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
79
81
  const hmtx = parseHmtx(sfnt);
80
82
  const math = parseMathTable(sfnt);
81
83
  cached = {
@@ -1,4 +1,4 @@
1
- import { SfntFont } from "./sfnt.cjs";
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
2
  //#region src/math-table.d.ts
3
3
  interface MathConstants {
4
4
  readonly scriptPercentScaleDown: number;
@@ -1,4 +1,4 @@
1
- import { SfntFont } from "./sfnt.js";
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
2
  //#region src/math-table.d.ts
3
3
  interface MathConstants {
4
4
  readonly scriptPercentScaleDown: number;
package/dist/measure.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
3
- const require_fonts = require("./fonts.cjs");
3
+ const require_embedded_font = require("./embedded-font.cjs");
4
+ const require_font_registry = require("./font-registry.cjs");
4
5
  //#region src/measure.ts
6
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
5
7
  const DEFAULT_WIDTH_CORRECTIONS = {
6
8
  calibri: .92,
7
9
  aptos: .93,
@@ -13,42 +15,91 @@ const DEFAULT_WIDTH_CORRECTIONS = {
13
15
  function normalizeFamilyKey(family) {
14
16
  return family.toLowerCase().replace(/[^a-z0-9]/g, "");
15
17
  }
16
- function createStandardFontMeasurer(options = {}) {
18
+ const EMBEDDED_HORIZONTAL_SCALE = 1;
19
+ const DEFAULT_VERTICAL_METRIC_POLICY = "hhea";
20
+ function verticalMetricsFor(face, policy) {
21
+ const m = face.metrics;
22
+ const hhea = {
23
+ ascentGlyphSpace: m.ascentGlyphSpace,
24
+ descentGlyphSpace: m.descentGlyphSpace,
25
+ lineGapGlyphSpace: m.lineGapGlyphSpace
26
+ };
27
+ if (policy === "os2Typo") {
28
+ if (m.typoAscentGlyphSpace === void 0 || m.typoDescentGlyphSpace === void 0 || m.typoLineGapGlyphSpace === void 0) return hhea;
29
+ return {
30
+ ascentGlyphSpace: m.typoAscentGlyphSpace,
31
+ descentGlyphSpace: m.typoDescentGlyphSpace,
32
+ lineGapGlyphSpace: m.typoLineGapGlyphSpace
33
+ };
34
+ }
35
+ if (policy === "os2Win") {
36
+ if (m.winAscentGlyphSpace === void 0 || m.winDescentGlyphSpace === void 0) return hhea;
37
+ return {
38
+ ascentGlyphSpace: m.winAscentGlyphSpace,
39
+ descentGlyphSpace: m.winDescentGlyphSpace,
40
+ lineGapGlyphSpace: 0
41
+ };
42
+ }
43
+ return hhea;
44
+ }
45
+ function createFontMeasurer(registry, options = {}) {
17
46
  const corrections = {
18
47
  ...DEFAULT_WIDTH_CORRECTIONS,
19
48
  ...options.widthCorrectionByFamily
20
49
  };
21
- function correctionFor(family) {
50
+ const verticalPolicy = options.verticalMetrics ?? "hhea";
51
+ function standardWidthCorrectionFor(family) {
22
52
  return corrections[normalizeFamilyKey(family)] ?? 1;
23
53
  }
24
- function standardNameFor(font) {
25
- return require_fonts.resolveStandardFont(font.family, font.weight === "bold", font.style === "italic").standardName;
54
+ function resolve(font) {
55
+ return require_font_registry.resolveFaceWithRegistry(registry, font);
26
56
  }
27
57
  return {
28
58
  widthOfTextAtSize(text, font, sizePt) {
29
- const { width1000 } = require_afm_widths.encodeForShow(text, standardNameFor(font));
30
- return width1000 / 1e3 * sizePt * correctionFor(font.family);
59
+ const face = resolve(font);
60
+ if (face.kind === "embedded") return require_embedded_font.encodeForShowEmbedded(text, face.face).width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt;
61
+ const { width1000 } = require_afm_widths.encodeForShow(text, face.standardName);
62
+ return width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt * standardWidthCorrectionFor(font.family);
31
63
  },
32
64
  lineHeightAtSize(font, sizePt) {
33
- return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].lineHeightEm * sizePt;
65
+ const face = resolve(font);
66
+ if (face.kind === "embedded") {
67
+ const vertical = verticalMetricsFor(face.face, verticalPolicy);
68
+ return (vertical.ascentGlyphSpace - vertical.descentGlyphSpace + vertical.lineGapGlyphSpace) / GLYPH_SPACE_UNITS_PER_EM * sizePt;
69
+ }
70
+ return require_afm_widths.STANDARD_METRICS[face.standardName].lineHeightEm * sizePt;
34
71
  },
35
72
  ascenderAtSize(font, sizePt) {
36
- return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].ascender / 1e3 * sizePt;
73
+ const face = resolve(font);
74
+ if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).ascentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
75
+ return require_afm_widths.STANDARD_METRICS[face.standardName].ascender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
37
76
  },
38
77
  descenderAtSize(font, sizePt) {
39
- return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].descender / 1e3 * sizePt;
78
+ const face = resolve(font);
79
+ if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).descentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
80
+ return require_afm_widths.STANDARD_METRICS[face.standardName].descender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
40
81
  },
41
82
  underlineAtSize(font, sizePt) {
42
- const metrics = require_afm_widths.STANDARD_METRICS[standardNameFor(font)];
83
+ const face = resolve(font);
84
+ if (face.kind === "embedded") return {
85
+ offsetPt: face.face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt,
86
+ thicknessPt: face.face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt
87
+ };
88
+ const metrics = require_afm_widths.STANDARD_METRICS[face.standardName];
43
89
  return {
44
- offsetPt: metrics.underlinePosition / 1e3 * sizePt,
45
- thicknessPt: metrics.underlineThickness / 1e3 * sizePt
90
+ offsetPt: metrics.underlinePosition / GLYPH_SPACE_UNITS_PER_EM * sizePt,
91
+ thicknessPt: metrics.underlineThickness / GLYPH_SPACE_UNITS_PER_EM * sizePt
46
92
  };
47
93
  },
48
94
  horizontalScaleFor(font) {
49
- return correctionFor(font.family);
95
+ return resolve(font).kind === "embedded" ? EMBEDDED_HORIZONTAL_SCALE : standardWidthCorrectionFor(font.family);
50
96
  }
51
97
  };
52
98
  }
99
+ function createStandardFontMeasurer(options = {}) {
100
+ return createFontMeasurer(void 0, options);
101
+ }
53
102
  //#endregion
103
+ exports.DEFAULT_VERTICAL_METRIC_POLICY = DEFAULT_VERTICAL_METRIC_POLICY;
104
+ exports.createFontMeasurer = createFontMeasurer;
54
105
  exports.createStandardFontMeasurer = createStandardFontMeasurer;
@@ -1,3 +1,4 @@
1
+ import { t as FontRegistry } from "./font-registry-yby02snZ.cjs";
1
2
  import { LayoutFont } from "document-schema.js";
2
3
  //#region src/measure.d.ts
3
4
  interface UnderlineMetrics {
@@ -12,9 +13,15 @@ interface TextMeasurer {
12
13
  underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
13
14
  horizontalScaleFor(font: LayoutFont): number;
14
15
  }
16
+ type VerticalMetricPolicy = 'hhea' | 'os2Typo' | 'os2Win';
17
+ declare const DEFAULT_VERTICAL_METRIC_POLICY: VerticalMetricPolicy;
15
18
  interface StandardFontMeasurerOptions {
16
19
  readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
17
20
  }
21
+ interface FontMeasurerOptions extends StandardFontMeasurerOptions {
22
+ readonly verticalMetrics?: VerticalMetricPolicy;
23
+ }
24
+ declare function createFontMeasurer(registry?: FontRegistry, options?: FontMeasurerOptions): TextMeasurer;
18
25
  declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
19
26
  //#endregion
20
- export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
27
+ export { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer };
package/dist/measure.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as FontRegistry } from "./font-registry-Cn7P9lAh.js";
1
2
  import { LayoutFont } from "document-schema.js";
2
3
  //#region src/measure.d.ts
3
4
  interface UnderlineMetrics {
@@ -12,9 +13,15 @@ interface TextMeasurer {
12
13
  underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
13
14
  horizontalScaleFor(font: LayoutFont): number;
14
15
  }
16
+ type VerticalMetricPolicy = 'hhea' | 'os2Typo' | 'os2Win';
17
+ declare const DEFAULT_VERTICAL_METRIC_POLICY: VerticalMetricPolicy;
15
18
  interface StandardFontMeasurerOptions {
16
19
  readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
17
20
  }
21
+ interface FontMeasurerOptions extends StandardFontMeasurerOptions {
22
+ readonly verticalMetrics?: VerticalMetricPolicy;
23
+ }
24
+ declare function createFontMeasurer(registry?: FontRegistry, options?: FontMeasurerOptions): TextMeasurer;
18
25
  declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
19
26
  //#endregion
20
- export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
27
+ export { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer };