emf-converter 4.26.0 → 4.27.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/browser.js CHANGED
@@ -36984,7 +36984,35 @@ function parseTrueTypeFace(view, base = 0) {
36984
36984
  }
36985
36985
  const locaAt = (g) => longLoca ? view.getUint32(loca.offset + g * 4) : view.getUint16(loca.offset + g * 2) * 2;
36986
36986
  const glyphCache = /* @__PURE__ */ new Map();
36987
+ const kernT = tables.get("kern");
36988
+ let kernPairs = null;
36989
+ const kerning = (left, right) => {
36990
+ if (!kernT) return 0;
36991
+ if (!kernPairs) {
36992
+ kernPairs = /* @__PURE__ */ new Map();
36993
+ const end = kernT.offset + kernT.length;
36994
+ if (kernT.offset + 4 <= end && view.getUint16(kernT.offset) === 0) {
36995
+ const n = view.getUint16(kernT.offset + 2);
36996
+ let o = kernT.offset + 4;
36997
+ for (let t = 0; t < n && o + 6 <= end; t++) {
36998
+ const length = view.getUint16(o + 2);
36999
+ const coverage = view.getUint16(o + 4);
37000
+ if (coverage >> 8 === 0 && (coverage & 7) === 1 && o + 14 <= end) {
37001
+ const pairs = view.getUint16(o + 6);
37002
+ for (let i = 0; i < pairs && o + 14 + i * 6 + 6 <= end; i++) {
37003
+ const p = o + 14 + i * 6;
37004
+ kernPairs.set(view.getUint16(p) * 65536 + view.getUint16(p + 2), view.getInt16(p + 4));
37005
+ }
37006
+ }
37007
+ if (length < 6) break;
37008
+ o += length;
37009
+ }
37010
+ }
37011
+ }
37012
+ return kernPairs.get(left * 65536 + right) ?? 0;
37013
+ };
36987
37014
  return {
37015
+ kerning,
36988
37016
  family: names2.get(1) ?? "",
36989
37017
  subfamily: names2.get(2) ?? "",
36990
37018
  fullName: names2.get(4) ?? "",
@@ -54959,14 +54987,14 @@ function realizePlusEngineFont(rCtx, font, paint, brushSampler2) {
54959
54987
  plusBars: hint === 4 ? "fractional" : "snapped"
54960
54988
  };
54961
54989
  }
54962
- function paintPlusEngineRun(rCtx, ef, run) {
54990
+ function paintPlusEngineRun(rCtx, ef, run, clip) {
54963
54991
  const base = {
54964
54992
  ...run,
54965
54993
  textAlign: 24,
54966
54994
  bkColor: "#ffffff",
54967
54995
  bkMode: 1,
54968
- options: 0,
54969
- rect: null,
54996
+ options: clip ? ETO_CLIPPED : 0,
54997
+ rect: clip ?? null,
54970
54998
  matrix: null
54971
54999
  };
54972
55000
  if ((!ef.color || ef.solidViaCoverage) && ef.sampler) {
@@ -54974,6 +55002,19 @@ function paintPlusEngineRun(rCtx, ef, run) {
54974
55002
  if (!cov) {
54975
55003
  return true;
54976
55004
  }
55005
+ if (clip) {
55006
+ for (let yy = 0; yy < cov.height; yy++) {
55007
+ const py = cov.y + yy;
55008
+ for (let xx = 0; xx < cov.width; xx++) {
55009
+ const px = cov.x + xx;
55010
+ if (px < clip.left || px >= clip.right || py < clip.top || py >= clip.bottom) {
55011
+ const i = yy * cov.width + xx;
55012
+ cov.data.fill(0, i * cov.channels, (i + 1) * cov.channels);
55013
+ if (cov.bars) cov.bars[i] = 0;
55014
+ }
55015
+ }
55016
+ }
55017
+ }
54977
55018
  const gamma = textGamma(rCtx.ext?.textContrast);
54978
55019
  if (cov.channels === 1) {
54979
55020
  applyTextContrast(cov.data, gamma);
@@ -55037,8 +55078,126 @@ function drawPlusStringWithEngine(rCtx, font, text, layoutX, layoutY, layoutW, l
55037
55078
  const tracking = format?.tracking ?? PLUS_DEFAULT_TRACKING;
55038
55079
  const ctGrid = !unhinted && realized.mode === "cleartype" && !!realized.ctGridAdvance && !realized.syntheticItalic && tracking > 1;
55039
55080
  const designUnits = !!realized.designAdvance && m[0] === 1 && m[3] === 1;
55040
- const dx = unhinted ? codes.map((c) => designUnits ? realized.designAdvance(realized.glyphIndex(c), tracking) : realized.advance(realized.glyphIndex(c)) * tracking) : ctGrid ? codes.map((c) => realized.ctGridAdvance(realized.glyphIndex(c))) : null;
55041
- return paintPlusEngineRun(rCtx, ef, { codes, glyphIndices: false, x, y, dx, dy: null });
55081
+ const advanceOf = (c) => {
55082
+ const gi = realized.glyphIndex(c);
55083
+ return unhinted ? designUnits ? realized.designAdvance(gi, tracking) : realized.advance(gi) * tracking : ctGrid ? realized.ctGridAdvance(gi) : realized.advance(gi);
55084
+ };
55085
+ const dx = unhinted || ctGrid ? codes.map(advanceOf) : null;
55086
+ const flags = format?.flags ?? 0;
55087
+ const left = m[0] * layoutX + m[4];
55088
+ const top = m[3] * layoutY + m[5];
55089
+ const width = m[0] * layoutW;
55090
+ const height = m[3] * layoutH;
55091
+ const rect = width > 0 && height > 0 && !(flags & STRING_FORMAT_NO_CLIP) ? { left: Math.round(left), top: Math.round(top), right: Math.round(left + width), bottom: Math.round(top + height) } : void 0;
55092
+ let clip = void 0;
55093
+ const available = width > 0 && !(flags & STRING_FORMAT_NO_WRAP) ? width - emPx * ((format?.leadingMargin ?? PLUS_LEADING_EM) + (format?.trailingMargin ?? PLUS_LEADING_EM)) : Infinity;
55094
+ const fit = (realized.designAdvance ? codes.map((c) => realized.designAdvance(realized.glyphIndex(c), tracking)) : codes.map(advanceOf)).map((w, i) => i + 1 < codes.length && ttf.kerning ? w + ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : w);
55095
+ let lines = layoutPlusLines(codes, fit, available);
55096
+ const paragraph = lines.length > 1;
55097
+ if (paragraph) clip = rect;
55098
+ const descentUnits = ttf.winDescent ?? 0;
55099
+ const lineUnits = ttf.hheaAscender !== void 0 && ttf.hheaDescender !== void 0 ? ttf.hheaAscender - ttf.hheaDescender + (ttf.hheaLineGap ?? 0) : ttf.winAscent + descentUnits;
55100
+ const lineSpacing = lineUnits * emPx / ttf.unitsPerEm;
55101
+ if (rect) {
55102
+ const visible = flags & STRING_FORMAT_LINE_LIMIT ? Math.floor((height - (ttf.winAscent + descentUnits) * emPx / ttf.unitsPerEm) / lineSpacing) + 1 : Math.floor(height / lineSpacing - 0.25) + 1;
55103
+ if (lines.length > visible) {
55104
+ clip = rect;
55105
+ const kept = lines.slice(0, Math.max(0, visible));
55106
+ if (kept.length > 0 && (format?.trimming ?? 1) === 1) {
55107
+ const last = kept[kept.length - 1];
55108
+ let end = last.start;
55109
+ while (end < codes.length && codes[end] !== 10 && codes[end] !== 13) {
55110
+ let w = 0;
55111
+ for (let i = last.start; i <= end; i++) w += fit[i];
55112
+ if (w > available && end > last.start) break;
55113
+ end++;
55114
+ }
55115
+ while (end > last.start && codes[end - 1] === 32) end--;
55116
+ kept[kept.length - 1] = { start: last.start, end };
55117
+ }
55118
+ lines = kept;
55119
+ }
55120
+ }
55121
+ if (lines.length === 0) {
55122
+ return true;
55123
+ }
55124
+ if (!paragraph) {
55125
+ return paintPlusEngineRun(rCtx, ef, {
55126
+ codes: codes.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end),
55127
+ glyphIndices: false,
55128
+ x,
55129
+ y,
55130
+ dx: dx ? dx.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end) : null,
55131
+ dy: null
55132
+ }, clip);
55133
+ }
55134
+ for (const [n, line] of lines.entries()) {
55135
+ const exact = top + (ttf.winAscent + n * lineUnits) * emPx / ttf.unitsPerEm;
55136
+ const lineCodes = codes.slice(line.start, line.end);
55137
+ if (lineCodes.length === 0) {
55138
+ continue;
55139
+ }
55140
+ const kern = (i) => {
55141
+ const k = i + 1 < line.end && ttf.kerning ? ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : 0;
55142
+ return unhinted ? k : Math.round(k);
55143
+ };
55144
+ const lineDx = Array.from({ length: line.end - line.start }, (_, k) => advanceOf(codes[line.start + k]) + kern(line.start + k));
55145
+ paintPlusEngineRun(rCtx, ef, {
55146
+ codes: lineCodes,
55147
+ glyphIndices: false,
55148
+ x,
55149
+ y: unhinted ? top + Math.round(exactAscent) + n * lineSpacing : Math.round(exact),
55150
+ dx: lineDx.some((v, k) => v !== advanceOf(codes[line.start + k])) || dx ? lineDx : null,
55151
+ dy: null
55152
+ }, clip);
55153
+ }
55154
+ return true;
55155
+ }
55156
+ function trimmedLength(codes) {
55157
+ let n = codes.length;
55158
+ while (n > 0 && codes[n - 1] === 32) n--;
55159
+ return n;
55160
+ }
55161
+ var STRING_FORMAT_NO_WRAP = 4096;
55162
+ var STRING_FORMAT_LINE_LIMIT = 8192;
55163
+ var STRING_FORMAT_NO_CLIP = 16384;
55164
+ function layoutPlusLines(codes, advances, available) {
55165
+ const lines = [];
55166
+ const trimEnd = (start, end) => {
55167
+ while (end > start && codes[end - 1] === 32) end--;
55168
+ return end;
55169
+ };
55170
+ const width = (start, end) => {
55171
+ let w = 0;
55172
+ for (let i = start; i < end; i++) w += advances[i];
55173
+ return w;
55174
+ };
55175
+ let p = 0;
55176
+ while (p <= codes.length) {
55177
+ let e = p;
55178
+ while (e < codes.length && codes[e] !== 10 && codes[e] !== 13) e++;
55179
+ let pos = p;
55180
+ do {
55181
+ let end = trimEnd(pos, e);
55182
+ if (Number.isFinite(available) && width(pos, end) > available) {
55183
+ let best = -1;
55184
+ for (let i = pos + 1; i < e; i++) {
55185
+ if (codes[i - 1] === 32 && codes[i] !== 32 && width(pos, trimEnd(pos, i)) <= available) best = i;
55186
+ }
55187
+ if (best > pos) {
55188
+ end = best;
55189
+ } else {
55190
+ end = pos + 1;
55191
+ while (end < e && codes[end] !== 32 && width(pos, end + 1) <= available) end++;
55192
+ }
55193
+ }
55194
+ lines.push({ start: pos, end: trimEnd(pos, end) });
55195
+ pos = end;
55196
+ while (pos < e && codes[pos] === 32 && pos > p) pos++;
55197
+ } while (pos < e);
55198
+ p = e + (codes[e] === 13 && codes[e + 1] === 10 ? 2 : 1);
55199
+ }
55200
+ return lines;
55042
55201
  }
55043
55202
  var DRIVER_STRING_CMAP_LOOKUP = 1;
55044
55203
  var DRIVER_STRING_VERTICAL = 2;
@@ -55849,7 +56008,8 @@ function handleEmfPlusObjectRecord(rCtx, recFlags, dataOff, recDataSize, cacheKe
55849
56008
  lineAlignment: lineAlignment ?? 0,
55850
56009
  leadingMargin: hasSpacing ? view.getFloat32(dataOff + 36, true) : void 0,
55851
56010
  trailingMargin: hasSpacing ? view.getFloat32(dataOff + 40, true) : void 0,
55852
- tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0
56011
+ tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0,
56012
+ trimming: recDataSize >= 52 ? view.getUint32(dataOff + 48, true) : void 0
55853
56013
  });
55854
56014
  }
55855
56015
  break;
package/dist/browser.mjs CHANGED
@@ -36982,7 +36982,35 @@ function parseTrueTypeFace(view, base = 0) {
36982
36982
  }
36983
36983
  const locaAt = (g) => longLoca ? view.getUint32(loca.offset + g * 4) : view.getUint16(loca.offset + g * 2) * 2;
36984
36984
  const glyphCache = /* @__PURE__ */ new Map();
36985
+ const kernT = tables.get("kern");
36986
+ let kernPairs = null;
36987
+ const kerning = (left, right) => {
36988
+ if (!kernT) return 0;
36989
+ if (!kernPairs) {
36990
+ kernPairs = /* @__PURE__ */ new Map();
36991
+ const end = kernT.offset + kernT.length;
36992
+ if (kernT.offset + 4 <= end && view.getUint16(kernT.offset) === 0) {
36993
+ const n = view.getUint16(kernT.offset + 2);
36994
+ let o = kernT.offset + 4;
36995
+ for (let t = 0; t < n && o + 6 <= end; t++) {
36996
+ const length = view.getUint16(o + 2);
36997
+ const coverage = view.getUint16(o + 4);
36998
+ if (coverage >> 8 === 0 && (coverage & 7) === 1 && o + 14 <= end) {
36999
+ const pairs = view.getUint16(o + 6);
37000
+ for (let i = 0; i < pairs && o + 14 + i * 6 + 6 <= end; i++) {
37001
+ const p = o + 14 + i * 6;
37002
+ kernPairs.set(view.getUint16(p) * 65536 + view.getUint16(p + 2), view.getInt16(p + 4));
37003
+ }
37004
+ }
37005
+ if (length < 6) break;
37006
+ o += length;
37007
+ }
37008
+ }
37009
+ }
37010
+ return kernPairs.get(left * 65536 + right) ?? 0;
37011
+ };
36985
37012
  return {
37013
+ kerning,
36986
37014
  family: names2.get(1) ?? "",
36987
37015
  subfamily: names2.get(2) ?? "",
36988
37016
  fullName: names2.get(4) ?? "",
@@ -54957,14 +54985,14 @@ function realizePlusEngineFont(rCtx, font, paint, brushSampler2) {
54957
54985
  plusBars: hint === 4 ? "fractional" : "snapped"
54958
54986
  };
54959
54987
  }
54960
- function paintPlusEngineRun(rCtx, ef, run) {
54988
+ function paintPlusEngineRun(rCtx, ef, run, clip) {
54961
54989
  const base = {
54962
54990
  ...run,
54963
54991
  textAlign: 24,
54964
54992
  bkColor: "#ffffff",
54965
54993
  bkMode: 1,
54966
- options: 0,
54967
- rect: null,
54994
+ options: clip ? ETO_CLIPPED : 0,
54995
+ rect: clip ?? null,
54968
54996
  matrix: null
54969
54997
  };
54970
54998
  if ((!ef.color || ef.solidViaCoverage) && ef.sampler) {
@@ -54972,6 +55000,19 @@ function paintPlusEngineRun(rCtx, ef, run) {
54972
55000
  if (!cov) {
54973
55001
  return true;
54974
55002
  }
55003
+ if (clip) {
55004
+ for (let yy = 0; yy < cov.height; yy++) {
55005
+ const py = cov.y + yy;
55006
+ for (let xx = 0; xx < cov.width; xx++) {
55007
+ const px = cov.x + xx;
55008
+ if (px < clip.left || px >= clip.right || py < clip.top || py >= clip.bottom) {
55009
+ const i = yy * cov.width + xx;
55010
+ cov.data.fill(0, i * cov.channels, (i + 1) * cov.channels);
55011
+ if (cov.bars) cov.bars[i] = 0;
55012
+ }
55013
+ }
55014
+ }
55015
+ }
54975
55016
  const gamma = textGamma(rCtx.ext?.textContrast);
54976
55017
  if (cov.channels === 1) {
54977
55018
  applyTextContrast(cov.data, gamma);
@@ -55035,8 +55076,126 @@ function drawPlusStringWithEngine(rCtx, font, text, layoutX, layoutY, layoutW, l
55035
55076
  const tracking = format?.tracking ?? PLUS_DEFAULT_TRACKING;
55036
55077
  const ctGrid = !unhinted && realized.mode === "cleartype" && !!realized.ctGridAdvance && !realized.syntheticItalic && tracking > 1;
55037
55078
  const designUnits = !!realized.designAdvance && m[0] === 1 && m[3] === 1;
55038
- const dx = unhinted ? codes.map((c) => designUnits ? realized.designAdvance(realized.glyphIndex(c), tracking) : realized.advance(realized.glyphIndex(c)) * tracking) : ctGrid ? codes.map((c) => realized.ctGridAdvance(realized.glyphIndex(c))) : null;
55039
- return paintPlusEngineRun(rCtx, ef, { codes, glyphIndices: false, x, y, dx, dy: null });
55079
+ const advanceOf = (c) => {
55080
+ const gi = realized.glyphIndex(c);
55081
+ return unhinted ? designUnits ? realized.designAdvance(gi, tracking) : realized.advance(gi) * tracking : ctGrid ? realized.ctGridAdvance(gi) : realized.advance(gi);
55082
+ };
55083
+ const dx = unhinted || ctGrid ? codes.map(advanceOf) : null;
55084
+ const flags = format?.flags ?? 0;
55085
+ const left = m[0] * layoutX + m[4];
55086
+ const top = m[3] * layoutY + m[5];
55087
+ const width = m[0] * layoutW;
55088
+ const height = m[3] * layoutH;
55089
+ const rect = width > 0 && height > 0 && !(flags & STRING_FORMAT_NO_CLIP) ? { left: Math.round(left), top: Math.round(top), right: Math.round(left + width), bottom: Math.round(top + height) } : void 0;
55090
+ let clip = void 0;
55091
+ const available = width > 0 && !(flags & STRING_FORMAT_NO_WRAP) ? width - emPx * ((format?.leadingMargin ?? PLUS_LEADING_EM) + (format?.trailingMargin ?? PLUS_LEADING_EM)) : Infinity;
55092
+ const fit = (realized.designAdvance ? codes.map((c) => realized.designAdvance(realized.glyphIndex(c), tracking)) : codes.map(advanceOf)).map((w, i) => i + 1 < codes.length && ttf.kerning ? w + ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : w);
55093
+ let lines = layoutPlusLines(codes, fit, available);
55094
+ const paragraph = lines.length > 1;
55095
+ if (paragraph) clip = rect;
55096
+ const descentUnits = ttf.winDescent ?? 0;
55097
+ const lineUnits = ttf.hheaAscender !== void 0 && ttf.hheaDescender !== void 0 ? ttf.hheaAscender - ttf.hheaDescender + (ttf.hheaLineGap ?? 0) : ttf.winAscent + descentUnits;
55098
+ const lineSpacing = lineUnits * emPx / ttf.unitsPerEm;
55099
+ if (rect) {
55100
+ const visible = flags & STRING_FORMAT_LINE_LIMIT ? Math.floor((height - (ttf.winAscent + descentUnits) * emPx / ttf.unitsPerEm) / lineSpacing) + 1 : Math.floor(height / lineSpacing - 0.25) + 1;
55101
+ if (lines.length > visible) {
55102
+ clip = rect;
55103
+ const kept = lines.slice(0, Math.max(0, visible));
55104
+ if (kept.length > 0 && (format?.trimming ?? 1) === 1) {
55105
+ const last = kept[kept.length - 1];
55106
+ let end = last.start;
55107
+ while (end < codes.length && codes[end] !== 10 && codes[end] !== 13) {
55108
+ let w = 0;
55109
+ for (let i = last.start; i <= end; i++) w += fit[i];
55110
+ if (w > available && end > last.start) break;
55111
+ end++;
55112
+ }
55113
+ while (end > last.start && codes[end - 1] === 32) end--;
55114
+ kept[kept.length - 1] = { start: last.start, end };
55115
+ }
55116
+ lines = kept;
55117
+ }
55118
+ }
55119
+ if (lines.length === 0) {
55120
+ return true;
55121
+ }
55122
+ if (!paragraph) {
55123
+ return paintPlusEngineRun(rCtx, ef, {
55124
+ codes: codes.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end),
55125
+ glyphIndices: false,
55126
+ x,
55127
+ y,
55128
+ dx: dx ? dx.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end) : null,
55129
+ dy: null
55130
+ }, clip);
55131
+ }
55132
+ for (const [n, line] of lines.entries()) {
55133
+ const exact = top + (ttf.winAscent + n * lineUnits) * emPx / ttf.unitsPerEm;
55134
+ const lineCodes = codes.slice(line.start, line.end);
55135
+ if (lineCodes.length === 0) {
55136
+ continue;
55137
+ }
55138
+ const kern = (i) => {
55139
+ const k = i + 1 < line.end && ttf.kerning ? ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : 0;
55140
+ return unhinted ? k : Math.round(k);
55141
+ };
55142
+ const lineDx = Array.from({ length: line.end - line.start }, (_, k) => advanceOf(codes[line.start + k]) + kern(line.start + k));
55143
+ paintPlusEngineRun(rCtx, ef, {
55144
+ codes: lineCodes,
55145
+ glyphIndices: false,
55146
+ x,
55147
+ y: unhinted ? top + Math.round(exactAscent) + n * lineSpacing : Math.round(exact),
55148
+ dx: lineDx.some((v, k) => v !== advanceOf(codes[line.start + k])) || dx ? lineDx : null,
55149
+ dy: null
55150
+ }, clip);
55151
+ }
55152
+ return true;
55153
+ }
55154
+ function trimmedLength(codes) {
55155
+ let n = codes.length;
55156
+ while (n > 0 && codes[n - 1] === 32) n--;
55157
+ return n;
55158
+ }
55159
+ var STRING_FORMAT_NO_WRAP = 4096;
55160
+ var STRING_FORMAT_LINE_LIMIT = 8192;
55161
+ var STRING_FORMAT_NO_CLIP = 16384;
55162
+ function layoutPlusLines(codes, advances, available) {
55163
+ const lines = [];
55164
+ const trimEnd = (start, end) => {
55165
+ while (end > start && codes[end - 1] === 32) end--;
55166
+ return end;
55167
+ };
55168
+ const width = (start, end) => {
55169
+ let w = 0;
55170
+ for (let i = start; i < end; i++) w += advances[i];
55171
+ return w;
55172
+ };
55173
+ let p = 0;
55174
+ while (p <= codes.length) {
55175
+ let e = p;
55176
+ while (e < codes.length && codes[e] !== 10 && codes[e] !== 13) e++;
55177
+ let pos = p;
55178
+ do {
55179
+ let end = trimEnd(pos, e);
55180
+ if (Number.isFinite(available) && width(pos, end) > available) {
55181
+ let best = -1;
55182
+ for (let i = pos + 1; i < e; i++) {
55183
+ if (codes[i - 1] === 32 && codes[i] !== 32 && width(pos, trimEnd(pos, i)) <= available) best = i;
55184
+ }
55185
+ if (best > pos) {
55186
+ end = best;
55187
+ } else {
55188
+ end = pos + 1;
55189
+ while (end < e && codes[end] !== 32 && width(pos, end + 1) <= available) end++;
55190
+ }
55191
+ }
55192
+ lines.push({ start: pos, end: trimEnd(pos, end) });
55193
+ pos = end;
55194
+ while (pos < e && codes[pos] === 32 && pos > p) pos++;
55195
+ } while (pos < e);
55196
+ p = e + (codes[e] === 13 && codes[e + 1] === 10 ? 2 : 1);
55197
+ }
55198
+ return lines;
55040
55199
  }
55041
55200
  var DRIVER_STRING_CMAP_LOOKUP = 1;
55042
55201
  var DRIVER_STRING_VERTICAL = 2;
@@ -55847,7 +56006,8 @@ function handleEmfPlusObjectRecord(rCtx, recFlags, dataOff, recDataSize, cacheKe
55847
56006
  lineAlignment: lineAlignment ?? 0,
55848
56007
  leadingMargin: hasSpacing ? view.getFloat32(dataOff + 36, true) : void 0,
55849
56008
  trailingMargin: hasSpacing ? view.getFloat32(dataOff + 40, true) : void 0,
55850
- tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0
56009
+ tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0,
56010
+ trimming: recDataSize >= 52 ? view.getUint32(dataOff + 48, true) : void 0
55851
56011
  });
55852
56012
  }
55853
56013
  break;
package/dist/index.js CHANGED
@@ -36985,7 +36985,35 @@ function parseTrueTypeFace(view, base = 0) {
36985
36985
  }
36986
36986
  const locaAt = (g) => longLoca ? view.getUint32(loca.offset + g * 4) : view.getUint16(loca.offset + g * 2) * 2;
36987
36987
  const glyphCache = /* @__PURE__ */ new Map();
36988
+ const kernT = tables.get("kern");
36989
+ let kernPairs = null;
36990
+ const kerning = (left, right) => {
36991
+ if (!kernT) return 0;
36992
+ if (!kernPairs) {
36993
+ kernPairs = /* @__PURE__ */ new Map();
36994
+ const end = kernT.offset + kernT.length;
36995
+ if (kernT.offset + 4 <= end && view.getUint16(kernT.offset) === 0) {
36996
+ const n = view.getUint16(kernT.offset + 2);
36997
+ let o = kernT.offset + 4;
36998
+ for (let t = 0; t < n && o + 6 <= end; t++) {
36999
+ const length = view.getUint16(o + 2);
37000
+ const coverage = view.getUint16(o + 4);
37001
+ if (coverage >> 8 === 0 && (coverage & 7) === 1 && o + 14 <= end) {
37002
+ const pairs = view.getUint16(o + 6);
37003
+ for (let i = 0; i < pairs && o + 14 + i * 6 + 6 <= end; i++) {
37004
+ const p = o + 14 + i * 6;
37005
+ kernPairs.set(view.getUint16(p) * 65536 + view.getUint16(p + 2), view.getInt16(p + 4));
37006
+ }
37007
+ }
37008
+ if (length < 6) break;
37009
+ o += length;
37010
+ }
37011
+ }
37012
+ }
37013
+ return kernPairs.get(left * 65536 + right) ?? 0;
37014
+ };
36988
37015
  return {
37016
+ kerning,
36989
37017
  family: names2.get(1) ?? "",
36990
37018
  subfamily: names2.get(2) ?? "",
36991
37019
  fullName: names2.get(4) ?? "",
@@ -54960,14 +54988,14 @@ function realizePlusEngineFont(rCtx, font, paint, brushSampler2) {
54960
54988
  plusBars: hint === 4 ? "fractional" : "snapped"
54961
54989
  };
54962
54990
  }
54963
- function paintPlusEngineRun(rCtx, ef, run) {
54991
+ function paintPlusEngineRun(rCtx, ef, run, clip) {
54964
54992
  const base = {
54965
54993
  ...run,
54966
54994
  textAlign: 24,
54967
54995
  bkColor: "#ffffff",
54968
54996
  bkMode: 1,
54969
- options: 0,
54970
- rect: null,
54997
+ options: clip ? ETO_CLIPPED : 0,
54998
+ rect: clip ?? null,
54971
54999
  matrix: null
54972
55000
  };
54973
55001
  if ((!ef.color || ef.solidViaCoverage) && ef.sampler) {
@@ -54975,6 +55003,19 @@ function paintPlusEngineRun(rCtx, ef, run) {
54975
55003
  if (!cov) {
54976
55004
  return true;
54977
55005
  }
55006
+ if (clip) {
55007
+ for (let yy = 0; yy < cov.height; yy++) {
55008
+ const py = cov.y + yy;
55009
+ for (let xx = 0; xx < cov.width; xx++) {
55010
+ const px = cov.x + xx;
55011
+ if (px < clip.left || px >= clip.right || py < clip.top || py >= clip.bottom) {
55012
+ const i = yy * cov.width + xx;
55013
+ cov.data.fill(0, i * cov.channels, (i + 1) * cov.channels);
55014
+ if (cov.bars) cov.bars[i] = 0;
55015
+ }
55016
+ }
55017
+ }
55018
+ }
54978
55019
  const gamma = textGamma(rCtx.ext?.textContrast);
54979
55020
  if (cov.channels === 1) {
54980
55021
  applyTextContrast(cov.data, gamma);
@@ -55038,8 +55079,126 @@ function drawPlusStringWithEngine(rCtx, font, text, layoutX, layoutY, layoutW, l
55038
55079
  const tracking = format?.tracking ?? PLUS_DEFAULT_TRACKING;
55039
55080
  const ctGrid = !unhinted && realized.mode === "cleartype" && !!realized.ctGridAdvance && !realized.syntheticItalic && tracking > 1;
55040
55081
  const designUnits = !!realized.designAdvance && m[0] === 1 && m[3] === 1;
55041
- const dx = unhinted ? codes.map((c) => designUnits ? realized.designAdvance(realized.glyphIndex(c), tracking) : realized.advance(realized.glyphIndex(c)) * tracking) : ctGrid ? codes.map((c) => realized.ctGridAdvance(realized.glyphIndex(c))) : null;
55042
- return paintPlusEngineRun(rCtx, ef, { codes, glyphIndices: false, x, y, dx, dy: null });
55082
+ const advanceOf = (c) => {
55083
+ const gi = realized.glyphIndex(c);
55084
+ return unhinted ? designUnits ? realized.designAdvance(gi, tracking) : realized.advance(gi) * tracking : ctGrid ? realized.ctGridAdvance(gi) : realized.advance(gi);
55085
+ };
55086
+ const dx = unhinted || ctGrid ? codes.map(advanceOf) : null;
55087
+ const flags = format?.flags ?? 0;
55088
+ const left = m[0] * layoutX + m[4];
55089
+ const top = m[3] * layoutY + m[5];
55090
+ const width = m[0] * layoutW;
55091
+ const height = m[3] * layoutH;
55092
+ const rect = width > 0 && height > 0 && !(flags & STRING_FORMAT_NO_CLIP) ? { left: Math.round(left), top: Math.round(top), right: Math.round(left + width), bottom: Math.round(top + height) } : void 0;
55093
+ let clip = void 0;
55094
+ const available = width > 0 && !(flags & STRING_FORMAT_NO_WRAP) ? width - emPx * ((format?.leadingMargin ?? PLUS_LEADING_EM) + (format?.trailingMargin ?? PLUS_LEADING_EM)) : Infinity;
55095
+ const fit = (realized.designAdvance ? codes.map((c) => realized.designAdvance(realized.glyphIndex(c), tracking)) : codes.map(advanceOf)).map((w, i) => i + 1 < codes.length && ttf.kerning ? w + ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : w);
55096
+ let lines = layoutPlusLines(codes, fit, available);
55097
+ const paragraph = lines.length > 1;
55098
+ if (paragraph) clip = rect;
55099
+ const descentUnits = ttf.winDescent ?? 0;
55100
+ const lineUnits = ttf.hheaAscender !== void 0 && ttf.hheaDescender !== void 0 ? ttf.hheaAscender - ttf.hheaDescender + (ttf.hheaLineGap ?? 0) : ttf.winAscent + descentUnits;
55101
+ const lineSpacing = lineUnits * emPx / ttf.unitsPerEm;
55102
+ if (rect) {
55103
+ const visible = flags & STRING_FORMAT_LINE_LIMIT ? Math.floor((height - (ttf.winAscent + descentUnits) * emPx / ttf.unitsPerEm) / lineSpacing) + 1 : Math.floor(height / lineSpacing - 0.25) + 1;
55104
+ if (lines.length > visible) {
55105
+ clip = rect;
55106
+ const kept = lines.slice(0, Math.max(0, visible));
55107
+ if (kept.length > 0 && (format?.trimming ?? 1) === 1) {
55108
+ const last = kept[kept.length - 1];
55109
+ let end = last.start;
55110
+ while (end < codes.length && codes[end] !== 10 && codes[end] !== 13) {
55111
+ let w = 0;
55112
+ for (let i = last.start; i <= end; i++) w += fit[i];
55113
+ if (w > available && end > last.start) break;
55114
+ end++;
55115
+ }
55116
+ while (end > last.start && codes[end - 1] === 32) end--;
55117
+ kept[kept.length - 1] = { start: last.start, end };
55118
+ }
55119
+ lines = kept;
55120
+ }
55121
+ }
55122
+ if (lines.length === 0) {
55123
+ return true;
55124
+ }
55125
+ if (!paragraph) {
55126
+ return paintPlusEngineRun(rCtx, ef, {
55127
+ codes: codes.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end),
55128
+ glyphIndices: false,
55129
+ x,
55130
+ y,
55131
+ dx: dx ? dx.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end) : null,
55132
+ dy: null
55133
+ }, clip);
55134
+ }
55135
+ for (const [n, line] of lines.entries()) {
55136
+ const exact = top + (ttf.winAscent + n * lineUnits) * emPx / ttf.unitsPerEm;
55137
+ const lineCodes = codes.slice(line.start, line.end);
55138
+ if (lineCodes.length === 0) {
55139
+ continue;
55140
+ }
55141
+ const kern = (i) => {
55142
+ const k = i + 1 < line.end && ttf.kerning ? ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : 0;
55143
+ return unhinted ? k : Math.round(k);
55144
+ };
55145
+ const lineDx = Array.from({ length: line.end - line.start }, (_, k) => advanceOf(codes[line.start + k]) + kern(line.start + k));
55146
+ paintPlusEngineRun(rCtx, ef, {
55147
+ codes: lineCodes,
55148
+ glyphIndices: false,
55149
+ x,
55150
+ y: unhinted ? top + Math.round(exactAscent) + n * lineSpacing : Math.round(exact),
55151
+ dx: lineDx.some((v, k) => v !== advanceOf(codes[line.start + k])) || dx ? lineDx : null,
55152
+ dy: null
55153
+ }, clip);
55154
+ }
55155
+ return true;
55156
+ }
55157
+ function trimmedLength(codes) {
55158
+ let n = codes.length;
55159
+ while (n > 0 && codes[n - 1] === 32) n--;
55160
+ return n;
55161
+ }
55162
+ var STRING_FORMAT_NO_WRAP = 4096;
55163
+ var STRING_FORMAT_LINE_LIMIT = 8192;
55164
+ var STRING_FORMAT_NO_CLIP = 16384;
55165
+ function layoutPlusLines(codes, advances, available) {
55166
+ const lines = [];
55167
+ const trimEnd = (start, end) => {
55168
+ while (end > start && codes[end - 1] === 32) end--;
55169
+ return end;
55170
+ };
55171
+ const width = (start, end) => {
55172
+ let w = 0;
55173
+ for (let i = start; i < end; i++) w += advances[i];
55174
+ return w;
55175
+ };
55176
+ let p = 0;
55177
+ while (p <= codes.length) {
55178
+ let e = p;
55179
+ while (e < codes.length && codes[e] !== 10 && codes[e] !== 13) e++;
55180
+ let pos = p;
55181
+ do {
55182
+ let end = trimEnd(pos, e);
55183
+ if (Number.isFinite(available) && width(pos, end) > available) {
55184
+ let best = -1;
55185
+ for (let i = pos + 1; i < e; i++) {
55186
+ if (codes[i - 1] === 32 && codes[i] !== 32 && width(pos, trimEnd(pos, i)) <= available) best = i;
55187
+ }
55188
+ if (best > pos) {
55189
+ end = best;
55190
+ } else {
55191
+ end = pos + 1;
55192
+ while (end < e && codes[end] !== 32 && width(pos, end + 1) <= available) end++;
55193
+ }
55194
+ }
55195
+ lines.push({ start: pos, end: trimEnd(pos, end) });
55196
+ pos = end;
55197
+ while (pos < e && codes[pos] === 32 && pos > p) pos++;
55198
+ } while (pos < e);
55199
+ p = e + (codes[e] === 13 && codes[e + 1] === 10 ? 2 : 1);
55200
+ }
55201
+ return lines;
55043
55202
  }
55044
55203
  var DRIVER_STRING_CMAP_LOOKUP = 1;
55045
55204
  var DRIVER_STRING_VERTICAL = 2;
@@ -55850,7 +56009,8 @@ function handleEmfPlusObjectRecord(rCtx, recFlags, dataOff, recDataSize, cacheKe
55850
56009
  lineAlignment: lineAlignment ?? 0,
55851
56010
  leadingMargin: hasSpacing ? view.getFloat32(dataOff + 36, true) : void 0,
55852
56011
  trailingMargin: hasSpacing ? view.getFloat32(dataOff + 40, true) : void 0,
55853
- tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0
56012
+ tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0,
56013
+ trimming: recDataSize >= 52 ? view.getUint32(dataOff + 48, true) : void 0
55854
56014
  });
55855
56015
  }
55856
56016
  break;
package/dist/index.mjs CHANGED
@@ -36983,7 +36983,35 @@ function parseTrueTypeFace(view, base = 0) {
36983
36983
  }
36984
36984
  const locaAt = (g) => longLoca ? view.getUint32(loca.offset + g * 4) : view.getUint16(loca.offset + g * 2) * 2;
36985
36985
  const glyphCache = /* @__PURE__ */ new Map();
36986
+ const kernT = tables.get("kern");
36987
+ let kernPairs = null;
36988
+ const kerning = (left, right) => {
36989
+ if (!kernT) return 0;
36990
+ if (!kernPairs) {
36991
+ kernPairs = /* @__PURE__ */ new Map();
36992
+ const end = kernT.offset + kernT.length;
36993
+ if (kernT.offset + 4 <= end && view.getUint16(kernT.offset) === 0) {
36994
+ const n = view.getUint16(kernT.offset + 2);
36995
+ let o = kernT.offset + 4;
36996
+ for (let t = 0; t < n && o + 6 <= end; t++) {
36997
+ const length = view.getUint16(o + 2);
36998
+ const coverage = view.getUint16(o + 4);
36999
+ if (coverage >> 8 === 0 && (coverage & 7) === 1 && o + 14 <= end) {
37000
+ const pairs = view.getUint16(o + 6);
37001
+ for (let i = 0; i < pairs && o + 14 + i * 6 + 6 <= end; i++) {
37002
+ const p = o + 14 + i * 6;
37003
+ kernPairs.set(view.getUint16(p) * 65536 + view.getUint16(p + 2), view.getInt16(p + 4));
37004
+ }
37005
+ }
37006
+ if (length < 6) break;
37007
+ o += length;
37008
+ }
37009
+ }
37010
+ }
37011
+ return kernPairs.get(left * 65536 + right) ?? 0;
37012
+ };
36986
37013
  return {
37014
+ kerning,
36987
37015
  family: names2.get(1) ?? "",
36988
37016
  subfamily: names2.get(2) ?? "",
36989
37017
  fullName: names2.get(4) ?? "",
@@ -54958,14 +54986,14 @@ function realizePlusEngineFont(rCtx, font, paint, brushSampler2) {
54958
54986
  plusBars: hint === 4 ? "fractional" : "snapped"
54959
54987
  };
54960
54988
  }
54961
- function paintPlusEngineRun(rCtx, ef, run) {
54989
+ function paintPlusEngineRun(rCtx, ef, run, clip) {
54962
54990
  const base = {
54963
54991
  ...run,
54964
54992
  textAlign: 24,
54965
54993
  bkColor: "#ffffff",
54966
54994
  bkMode: 1,
54967
- options: 0,
54968
- rect: null,
54995
+ options: clip ? ETO_CLIPPED : 0,
54996
+ rect: clip ?? null,
54969
54997
  matrix: null
54970
54998
  };
54971
54999
  if ((!ef.color || ef.solidViaCoverage) && ef.sampler) {
@@ -54973,6 +55001,19 @@ function paintPlusEngineRun(rCtx, ef, run) {
54973
55001
  if (!cov) {
54974
55002
  return true;
54975
55003
  }
55004
+ if (clip) {
55005
+ for (let yy = 0; yy < cov.height; yy++) {
55006
+ const py = cov.y + yy;
55007
+ for (let xx = 0; xx < cov.width; xx++) {
55008
+ const px = cov.x + xx;
55009
+ if (px < clip.left || px >= clip.right || py < clip.top || py >= clip.bottom) {
55010
+ const i = yy * cov.width + xx;
55011
+ cov.data.fill(0, i * cov.channels, (i + 1) * cov.channels);
55012
+ if (cov.bars) cov.bars[i] = 0;
55013
+ }
55014
+ }
55015
+ }
55016
+ }
54976
55017
  const gamma = textGamma(rCtx.ext?.textContrast);
54977
55018
  if (cov.channels === 1) {
54978
55019
  applyTextContrast(cov.data, gamma);
@@ -55036,8 +55077,126 @@ function drawPlusStringWithEngine(rCtx, font, text, layoutX, layoutY, layoutW, l
55036
55077
  const tracking = format?.tracking ?? PLUS_DEFAULT_TRACKING;
55037
55078
  const ctGrid = !unhinted && realized.mode === "cleartype" && !!realized.ctGridAdvance && !realized.syntheticItalic && tracking > 1;
55038
55079
  const designUnits = !!realized.designAdvance && m[0] === 1 && m[3] === 1;
55039
- const dx = unhinted ? codes.map((c) => designUnits ? realized.designAdvance(realized.glyphIndex(c), tracking) : realized.advance(realized.glyphIndex(c)) * tracking) : ctGrid ? codes.map((c) => realized.ctGridAdvance(realized.glyphIndex(c))) : null;
55040
- return paintPlusEngineRun(rCtx, ef, { codes, glyphIndices: false, x, y, dx, dy: null });
55080
+ const advanceOf = (c) => {
55081
+ const gi = realized.glyphIndex(c);
55082
+ return unhinted ? designUnits ? realized.designAdvance(gi, tracking) : realized.advance(gi) * tracking : ctGrid ? realized.ctGridAdvance(gi) : realized.advance(gi);
55083
+ };
55084
+ const dx = unhinted || ctGrid ? codes.map(advanceOf) : null;
55085
+ const flags = format?.flags ?? 0;
55086
+ const left = m[0] * layoutX + m[4];
55087
+ const top = m[3] * layoutY + m[5];
55088
+ const width = m[0] * layoutW;
55089
+ const height = m[3] * layoutH;
55090
+ const rect = width > 0 && height > 0 && !(flags & STRING_FORMAT_NO_CLIP) ? { left: Math.round(left), top: Math.round(top), right: Math.round(left + width), bottom: Math.round(top + height) } : void 0;
55091
+ let clip = void 0;
55092
+ const available = width > 0 && !(flags & STRING_FORMAT_NO_WRAP) ? width - emPx * ((format?.leadingMargin ?? PLUS_LEADING_EM) + (format?.trailingMargin ?? PLUS_LEADING_EM)) : Infinity;
55093
+ const fit = (realized.designAdvance ? codes.map((c) => realized.designAdvance(realized.glyphIndex(c), tracking)) : codes.map(advanceOf)).map((w, i) => i + 1 < codes.length && ttf.kerning ? w + ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : w);
55094
+ let lines = layoutPlusLines(codes, fit, available);
55095
+ const paragraph = lines.length > 1;
55096
+ if (paragraph) clip = rect;
55097
+ const descentUnits = ttf.winDescent ?? 0;
55098
+ const lineUnits = ttf.hheaAscender !== void 0 && ttf.hheaDescender !== void 0 ? ttf.hheaAscender - ttf.hheaDescender + (ttf.hheaLineGap ?? 0) : ttf.winAscent + descentUnits;
55099
+ const lineSpacing = lineUnits * emPx / ttf.unitsPerEm;
55100
+ if (rect) {
55101
+ const visible = flags & STRING_FORMAT_LINE_LIMIT ? Math.floor((height - (ttf.winAscent + descentUnits) * emPx / ttf.unitsPerEm) / lineSpacing) + 1 : Math.floor(height / lineSpacing - 0.25) + 1;
55102
+ if (lines.length > visible) {
55103
+ clip = rect;
55104
+ const kept = lines.slice(0, Math.max(0, visible));
55105
+ if (kept.length > 0 && (format?.trimming ?? 1) === 1) {
55106
+ const last = kept[kept.length - 1];
55107
+ let end = last.start;
55108
+ while (end < codes.length && codes[end] !== 10 && codes[end] !== 13) {
55109
+ let w = 0;
55110
+ for (let i = last.start; i <= end; i++) w += fit[i];
55111
+ if (w > available && end > last.start) break;
55112
+ end++;
55113
+ }
55114
+ while (end > last.start && codes[end - 1] === 32) end--;
55115
+ kept[kept.length - 1] = { start: last.start, end };
55116
+ }
55117
+ lines = kept;
55118
+ }
55119
+ }
55120
+ if (lines.length === 0) {
55121
+ return true;
55122
+ }
55123
+ if (!paragraph) {
55124
+ return paintPlusEngineRun(rCtx, ef, {
55125
+ codes: codes.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end),
55126
+ glyphIndices: false,
55127
+ x,
55128
+ y,
55129
+ dx: dx ? dx.slice(0, lines[0].end === trimmedLength(codes) ? codes.length : lines[0].end) : null,
55130
+ dy: null
55131
+ }, clip);
55132
+ }
55133
+ for (const [n, line] of lines.entries()) {
55134
+ const exact = top + (ttf.winAscent + n * lineUnits) * emPx / ttf.unitsPerEm;
55135
+ const lineCodes = codes.slice(line.start, line.end);
55136
+ if (lineCodes.length === 0) {
55137
+ continue;
55138
+ }
55139
+ const kern = (i) => {
55140
+ const k = i + 1 < line.end && ttf.kerning ? ttf.kerning(realized.glyphIndex(codes[i]), realized.glyphIndex(codes[i + 1])) * emPx / ttf.unitsPerEm : 0;
55141
+ return unhinted ? k : Math.round(k);
55142
+ };
55143
+ const lineDx = Array.from({ length: line.end - line.start }, (_, k) => advanceOf(codes[line.start + k]) + kern(line.start + k));
55144
+ paintPlusEngineRun(rCtx, ef, {
55145
+ codes: lineCodes,
55146
+ glyphIndices: false,
55147
+ x,
55148
+ y: unhinted ? top + Math.round(exactAscent) + n * lineSpacing : Math.round(exact),
55149
+ dx: lineDx.some((v, k) => v !== advanceOf(codes[line.start + k])) || dx ? lineDx : null,
55150
+ dy: null
55151
+ }, clip);
55152
+ }
55153
+ return true;
55154
+ }
55155
+ function trimmedLength(codes) {
55156
+ let n = codes.length;
55157
+ while (n > 0 && codes[n - 1] === 32) n--;
55158
+ return n;
55159
+ }
55160
+ var STRING_FORMAT_NO_WRAP = 4096;
55161
+ var STRING_FORMAT_LINE_LIMIT = 8192;
55162
+ var STRING_FORMAT_NO_CLIP = 16384;
55163
+ function layoutPlusLines(codes, advances, available) {
55164
+ const lines = [];
55165
+ const trimEnd = (start, end) => {
55166
+ while (end > start && codes[end - 1] === 32) end--;
55167
+ return end;
55168
+ };
55169
+ const width = (start, end) => {
55170
+ let w = 0;
55171
+ for (let i = start; i < end; i++) w += advances[i];
55172
+ return w;
55173
+ };
55174
+ let p = 0;
55175
+ while (p <= codes.length) {
55176
+ let e = p;
55177
+ while (e < codes.length && codes[e] !== 10 && codes[e] !== 13) e++;
55178
+ let pos = p;
55179
+ do {
55180
+ let end = trimEnd(pos, e);
55181
+ if (Number.isFinite(available) && width(pos, end) > available) {
55182
+ let best = -1;
55183
+ for (let i = pos + 1; i < e; i++) {
55184
+ if (codes[i - 1] === 32 && codes[i] !== 32 && width(pos, trimEnd(pos, i)) <= available) best = i;
55185
+ }
55186
+ if (best > pos) {
55187
+ end = best;
55188
+ } else {
55189
+ end = pos + 1;
55190
+ while (end < e && codes[end] !== 32 && width(pos, end + 1) <= available) end++;
55191
+ }
55192
+ }
55193
+ lines.push({ start: pos, end: trimEnd(pos, end) });
55194
+ pos = end;
55195
+ while (pos < e && codes[pos] === 32 && pos > p) pos++;
55196
+ } while (pos < e);
55197
+ p = e + (codes[e] === 13 && codes[e + 1] === 10 ? 2 : 1);
55198
+ }
55199
+ return lines;
55041
55200
  }
55042
55201
  var DRIVER_STRING_CMAP_LOOKUP = 1;
55043
55202
  var DRIVER_STRING_VERTICAL = 2;
@@ -55848,7 +56007,8 @@ function handleEmfPlusObjectRecord(rCtx, recFlags, dataOff, recDataSize, cacheKe
55848
56007
  lineAlignment: lineAlignment ?? 0,
55849
56008
  leadingMargin: hasSpacing ? view.getFloat32(dataOff + 36, true) : void 0,
55850
56009
  trailingMargin: hasSpacing ? view.getFloat32(dataOff + 40, true) : void 0,
55851
- tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0
56010
+ tracking: hasSpacing ? view.getFloat32(dataOff + 44, true) : void 0,
56011
+ trimming: recDataSize >= 52 ? view.getUint32(dataOff + 48, true) : void 0
55852
56012
  });
55853
56013
  }
55854
56014
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.26.0",
3
+ "version": "4.27.0",
4
4
  "description": "Convert EMF/WMF metafile binaries to PNG, JPEG or WebP data URLs, SVG (markup, data URL, React/JSX) or PDF",
5
5
  "keywords": [
6
6
  "canvas",