@chialab/pdfjs-lib 1.0.0-alpha.38 → 1.0.0-alpha.39

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.
@@ -42322,7 +42322,7 @@ var loadTextLayerFontsMap = /* @__PURE__ */ (() => {
42322
42322
  return promise;
42323
42323
  };
42324
42324
  })();
42325
- var HYPHEN_REGEX2 = /-\n+$/;
42325
+ var HYPHEN_REGEX2 = /-\n*$/;
42326
42326
  var isNameObject = (obj) => {
42327
42327
  return obj !== null && typeof obj === "object" && "name" in obj;
42328
42328
  };
@@ -42405,16 +42405,18 @@ async function createTextLayerV2(page, {
42405
42405
  angle
42406
42406
  } = currentTextItem;
42407
42407
  const textFont = fonts[font.bold || font.black ? font.italic ? 3 : 2 : font.italic ? 1 : 0];
42408
+ const computedText = glyphsList.map((g) => g[0].unicode).join("");
42409
+ const isHyphen = HYPHEN_REGEX2.test(computedText);
42408
42410
  const glyphsBlocks = glyphsList.reduce(
42409
42411
  (acc, glyph) => {
42410
42412
  if (!glyph[0]) {
42411
42413
  return acc;
42412
42414
  }
42413
- if (glyph[0].unicode.trim()) {
42414
- acc[acc.length - 1].push(glyph);
42415
- } else {
42415
+ if (!glyph[0].unicode.trim() || glyph[0].unicode === "-") {
42416
42416
  acc.push([glyph]);
42417
42417
  acc.push([]);
42418
+ } else {
42419
+ acc[acc.length - 1].push(glyph);
42418
42420
  }
42419
42421
  return acc;
42420
42422
  },
@@ -42422,14 +42424,12 @@ async function createTextLayerV2(page, {
42422
42424
  );
42423
42425
  const chunks = [];
42424
42426
  let currentLeft = 0;
42425
- let computedText = "";
42426
42427
  for (let i = 0; i < glyphsBlocks.length; i++) {
42427
42428
  const glyphs = glyphsBlocks[i];
42428
42429
  if (glyphs.length === 0) {
42429
42430
  continue;
42430
42431
  }
42431
42432
  const text = glyphs.map((g) => g[0].unicode).join("");
42432
- computedText += text;
42433
42433
  const textWidth = textFont.getAdvanceWidth(text, fontSize);
42434
42434
  if (!textWidth) {
42435
42435
  continue;
@@ -42475,7 +42475,7 @@ async function createTextLayerV2(page, {
42475
42475
  text: dir === "ltr" ? chunks : chunks.reverse(),
42476
42476
  fontFamily: font.loadedName,
42477
42477
  fontFallback: "sans-serif",
42478
- hyphen: HYPHEN_REGEX2.test(computedText),
42478
+ hyphen: isHyphen,
42479
42479
  top,
42480
42480
  left,
42481
42481
  fontSize: finalFontSize,
@@ -40962,7 +40962,7 @@ var loadTextLayerFontsMap = /* @__PURE__ */ (() => {
40962
40962
  return promise;
40963
40963
  };
40964
40964
  })();
40965
- var HYPHEN_REGEX2 = /-\n+$/;
40965
+ var HYPHEN_REGEX2 = /-\n*$/;
40966
40966
  var isNameObject = (obj) => {
40967
40967
  return obj !== null && typeof obj === "object" && "name" in obj;
40968
40968
  };
@@ -41045,16 +41045,18 @@ async function createTextLayerV2(page, {
41045
41045
  angle
41046
41046
  } = currentTextItem;
41047
41047
  const textFont = fonts[font.bold || font.black ? font.italic ? 3 : 2 : font.italic ? 1 : 0];
41048
+ const computedText = glyphsList.map((g) => g[0].unicode).join("");
41049
+ const isHyphen = HYPHEN_REGEX2.test(computedText);
41048
41050
  const glyphsBlocks = glyphsList.reduce(
41049
41051
  (acc, glyph) => {
41050
41052
  if (!glyph[0]) {
41051
41053
  return acc;
41052
41054
  }
41053
- if (glyph[0].unicode.trim()) {
41054
- acc[acc.length - 1].push(glyph);
41055
- } else {
41055
+ if (!glyph[0].unicode.trim() || glyph[0].unicode === "-") {
41056
41056
  acc.push([glyph]);
41057
41057
  acc.push([]);
41058
+ } else {
41059
+ acc[acc.length - 1].push(glyph);
41058
41060
  }
41059
41061
  return acc;
41060
41062
  },
@@ -41062,14 +41064,12 @@ async function createTextLayerV2(page, {
41062
41064
  );
41063
41065
  const chunks = [];
41064
41066
  let currentLeft = 0;
41065
- let computedText = "";
41066
41067
  for (let i = 0; i < glyphsBlocks.length; i++) {
41067
41068
  const glyphs = glyphsBlocks[i];
41068
41069
  if (glyphs.length === 0) {
41069
41070
  continue;
41070
41071
  }
41071
41072
  const text = glyphs.map((g) => g[0].unicode).join("");
41072
- computedText += text;
41073
41073
  const textWidth = textFont.getAdvanceWidth(text, fontSize);
41074
41074
  if (!textWidth) {
41075
41075
  continue;
@@ -41115,7 +41115,7 @@ async function createTextLayerV2(page, {
41115
41115
  text: dir === "ltr" ? chunks : chunks.reverse(),
41116
41116
  fontFamily: font.loadedName,
41117
41117
  fontFallback: "sans-serif",
41118
- hyphen: HYPHEN_REGEX2.test(computedText),
41118
+ hyphen: isHyphen,
41119
41119
  top,
41120
41120
  left,
41121
41121
  fontSize: finalFontSize,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chialab/pdfjs-lib",
3
3
  "description": "A custom Mozilla's PDF.js build with better Node support and extras.",
4
- "version": "1.0.0-alpha.38",
4
+ "version": "1.0.0-alpha.39",
5
5
  "type": "module",
6
6
  "author": "Chialab <dev@chialab.it>",
7
7
  "license": "MIT",