@chialab/pdfjs-lib 1.0.0-alpha.35 → 1.0.0-alpha.36
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/index.js +41 -3
- package/dist/lib/AnnotationData.d.ts +4 -0
- package/dist/node/index.js +41 -3
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -42318,6 +42318,24 @@ var loadTextLayerFontsMap = /* @__PURE__ */ (() => {
|
|
|
42318
42318
|
return promise;
|
|
42319
42319
|
};
|
|
42320
42320
|
})();
|
|
42321
|
+
var getTextDirection = (text) => {
|
|
42322
|
+
const rtlChars = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/;
|
|
42323
|
+
const ltrChars = /[A-Za-z]/;
|
|
42324
|
+
let rtlCount = 0;
|
|
42325
|
+
let ltrCount = 0;
|
|
42326
|
+
for (const char of text) {
|
|
42327
|
+
if (rtlChars.test(char)) {
|
|
42328
|
+
rtlCount++;
|
|
42329
|
+
}
|
|
42330
|
+
if (ltrChars.test(char)) {
|
|
42331
|
+
ltrCount++;
|
|
42332
|
+
}
|
|
42333
|
+
}
|
|
42334
|
+
return rtlCount > ltrCount ? "rtl" : "ltr";
|
|
42335
|
+
};
|
|
42336
|
+
var isNameObject = (obj) => {
|
|
42337
|
+
return obj !== null && typeof obj === "object" && "name" in obj;
|
|
42338
|
+
};
|
|
42321
42339
|
async function createTextLayerV2(page, {
|
|
42322
42340
|
graphics,
|
|
42323
42341
|
annotations: _annotations
|
|
@@ -42341,6 +42359,7 @@ async function createTextLayerV2(page, {
|
|
|
42341
42359
|
const markedContentStack = [rootContainer];
|
|
42342
42360
|
let markedContent = rootContainer;
|
|
42343
42361
|
let currentTextItem = null;
|
|
42362
|
+
let transformMatrix = [1, 0, 0, 1, 0, 0];
|
|
42344
42363
|
let textMatrix = [1, 0, 0, 1, 0, 0];
|
|
42345
42364
|
let lineMatrix = [1, 0, 0, 1, 0, 0];
|
|
42346
42365
|
let fontSize = 0;
|
|
@@ -42367,7 +42386,10 @@ async function createTextLayerV2(page, {
|
|
|
42367
42386
|
const { font, glyphs: glyphsList } = currentTextItem;
|
|
42368
42387
|
const textFont = fonts[font.bold || font.black ? font.italic ? 3 : 2 : font.italic ? 1 : 0];
|
|
42369
42388
|
const riseMatrix = [1, 0, 0, 1, 0, textRise];
|
|
42370
|
-
const finalMatrix = Util.transform(
|
|
42389
|
+
const finalMatrix = Util.transform(
|
|
42390
|
+
transformMatrix,
|
|
42391
|
+
Util.transform(textMatrix, riseMatrix)
|
|
42392
|
+
);
|
|
42371
42393
|
const [, , , , x, y] = Util.transform(transform, finalMatrix);
|
|
42372
42394
|
const finalFontSize = fontSize * Math.sqrt(finalMatrix[2] ** 2 + finalMatrix[3] ** 2);
|
|
42373
42395
|
const angle = -Math.atan2(finalMatrix[1], finalMatrix[0]);
|
|
@@ -42391,12 +42413,14 @@ async function createTextLayerV2(page, {
|
|
|
42391
42413
|
);
|
|
42392
42414
|
const chunks = [];
|
|
42393
42415
|
let currentLeft = 0;
|
|
42416
|
+
let computedText = "";
|
|
42394
42417
|
for (let i = 0; i < glyphsBlocks.length; i++) {
|
|
42395
42418
|
const glyphs = glyphsBlocks[i];
|
|
42396
42419
|
if (glyphs.length === 0) {
|
|
42397
42420
|
continue;
|
|
42398
42421
|
}
|
|
42399
42422
|
const text = glyphs.map((g) => g[0].unicode).join("");
|
|
42423
|
+
computedText += text;
|
|
42400
42424
|
const textWidth = textFont.getAdvanceWidth(text, fontSize);
|
|
42401
42425
|
if (!textWidth) {
|
|
42402
42426
|
continue;
|
|
@@ -42447,7 +42471,7 @@ async function createTextLayerV2(page, {
|
|
|
42447
42471
|
fontSize: finalFontSize,
|
|
42448
42472
|
fontWeight: font?.black ? 900 : font?.bold ? 700 : 400,
|
|
42449
42473
|
fontStyle: font?.italic ? "italic" : "normal",
|
|
42450
|
-
dir:
|
|
42474
|
+
dir: getTextDirection(computedText),
|
|
42451
42475
|
scale: 1,
|
|
42452
42476
|
angle: angle * (180 / Math.PI)
|
|
42453
42477
|
});
|
|
@@ -42600,9 +42624,15 @@ async function createTextLayerV2(page, {
|
|
|
42600
42624
|
case OPS.beginMarkedContentProps: {
|
|
42601
42625
|
const [role, idRef, props] = args;
|
|
42602
42626
|
const id2 = normalizeMarkedContentId(idRef);
|
|
42627
|
+
let normalizedRole = isNameObject(role) ? role.name.toLowerCase() : role?.toString().toLowerCase();
|
|
42628
|
+
switch (normalizedRole) {
|
|
42629
|
+
case "placedgraphic":
|
|
42630
|
+
normalizedRole = "figure";
|
|
42631
|
+
break;
|
|
42632
|
+
}
|
|
42603
42633
|
markedContent.children.push({
|
|
42604
42634
|
id: id2,
|
|
42605
|
-
role:
|
|
42635
|
+
role: normalizedRole || "span",
|
|
42606
42636
|
attrs: props ?? void 0,
|
|
42607
42637
|
children: []
|
|
42608
42638
|
});
|
|
@@ -42620,9 +42650,16 @@ async function createTextLayerV2(page, {
|
|
|
42620
42650
|
}
|
|
42621
42651
|
break;
|
|
42622
42652
|
}
|
|
42653
|
+
case OPS.transform: {
|
|
42654
|
+
closeTextItem();
|
|
42655
|
+
const [a, b, c, d, e, f] = args;
|
|
42656
|
+
transformMatrix = Util.transform(transformMatrix, [a, b, c, d, e, f]);
|
|
42657
|
+
break;
|
|
42658
|
+
}
|
|
42623
42659
|
case OPS.restore: {
|
|
42624
42660
|
const state = stateStack.pop();
|
|
42625
42661
|
if (state) {
|
|
42662
|
+
transformMatrix = state.transformMatrix;
|
|
42626
42663
|
textMatrix = state.textMatrix;
|
|
42627
42664
|
lineMatrix = state.lineMatrix;
|
|
42628
42665
|
fontSize = state.fontSize;
|
|
@@ -42637,6 +42674,7 @@ async function createTextLayerV2(page, {
|
|
|
42637
42674
|
}
|
|
42638
42675
|
case OPS.save: {
|
|
42639
42676
|
stateStack.push({
|
|
42677
|
+
transformMatrix: [...transformMatrix],
|
|
42640
42678
|
textMatrix: [...textMatrix],
|
|
42641
42679
|
lineMatrix: [...lineMatrix],
|
|
42642
42680
|
fontSize,
|
package/dist/node/index.js
CHANGED
|
@@ -40960,6 +40960,24 @@ var loadTextLayerFontsMap = /* @__PURE__ */ (() => {
|
|
|
40960
40960
|
return promise;
|
|
40961
40961
|
};
|
|
40962
40962
|
})();
|
|
40963
|
+
var getTextDirection = (text) => {
|
|
40964
|
+
const rtlChars = /[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/;
|
|
40965
|
+
const ltrChars = /[A-Za-z]/;
|
|
40966
|
+
let rtlCount = 0;
|
|
40967
|
+
let ltrCount = 0;
|
|
40968
|
+
for (const char of text) {
|
|
40969
|
+
if (rtlChars.test(char)) {
|
|
40970
|
+
rtlCount++;
|
|
40971
|
+
}
|
|
40972
|
+
if (ltrChars.test(char)) {
|
|
40973
|
+
ltrCount++;
|
|
40974
|
+
}
|
|
40975
|
+
}
|
|
40976
|
+
return rtlCount > ltrCount ? "rtl" : "ltr";
|
|
40977
|
+
};
|
|
40978
|
+
var isNameObject = (obj) => {
|
|
40979
|
+
return obj !== null && typeof obj === "object" && "name" in obj;
|
|
40980
|
+
};
|
|
40963
40981
|
async function createTextLayerV2(page, {
|
|
40964
40982
|
graphics,
|
|
40965
40983
|
annotations: _annotations
|
|
@@ -40983,6 +41001,7 @@ async function createTextLayerV2(page, {
|
|
|
40983
41001
|
const markedContentStack = [rootContainer];
|
|
40984
41002
|
let markedContent = rootContainer;
|
|
40985
41003
|
let currentTextItem = null;
|
|
41004
|
+
let transformMatrix = [1, 0, 0, 1, 0, 0];
|
|
40986
41005
|
let textMatrix = [1, 0, 0, 1, 0, 0];
|
|
40987
41006
|
let lineMatrix = [1, 0, 0, 1, 0, 0];
|
|
40988
41007
|
let fontSize = 0;
|
|
@@ -41009,7 +41028,10 @@ async function createTextLayerV2(page, {
|
|
|
41009
41028
|
const { font, glyphs: glyphsList } = currentTextItem;
|
|
41010
41029
|
const textFont = fonts[font.bold || font.black ? font.italic ? 3 : 2 : font.italic ? 1 : 0];
|
|
41011
41030
|
const riseMatrix = [1, 0, 0, 1, 0, textRise];
|
|
41012
|
-
const finalMatrix = Util.transform(
|
|
41031
|
+
const finalMatrix = Util.transform(
|
|
41032
|
+
transformMatrix,
|
|
41033
|
+
Util.transform(textMatrix, riseMatrix)
|
|
41034
|
+
);
|
|
41013
41035
|
const [, , , , x, y] = Util.transform(transform, finalMatrix);
|
|
41014
41036
|
const finalFontSize = fontSize * Math.sqrt(finalMatrix[2] ** 2 + finalMatrix[3] ** 2);
|
|
41015
41037
|
const angle = -Math.atan2(finalMatrix[1], finalMatrix[0]);
|
|
@@ -41033,12 +41055,14 @@ async function createTextLayerV2(page, {
|
|
|
41033
41055
|
);
|
|
41034
41056
|
const chunks = [];
|
|
41035
41057
|
let currentLeft = 0;
|
|
41058
|
+
let computedText = "";
|
|
41036
41059
|
for (let i = 0; i < glyphsBlocks.length; i++) {
|
|
41037
41060
|
const glyphs = glyphsBlocks[i];
|
|
41038
41061
|
if (glyphs.length === 0) {
|
|
41039
41062
|
continue;
|
|
41040
41063
|
}
|
|
41041
41064
|
const text = glyphs.map((g) => g[0].unicode).join("");
|
|
41065
|
+
computedText += text;
|
|
41042
41066
|
const textWidth = textFont.getAdvanceWidth(text, fontSize);
|
|
41043
41067
|
if (!textWidth) {
|
|
41044
41068
|
continue;
|
|
@@ -41089,7 +41113,7 @@ async function createTextLayerV2(page, {
|
|
|
41089
41113
|
fontSize: finalFontSize,
|
|
41090
41114
|
fontWeight: font?.black ? 900 : font?.bold ? 700 : 400,
|
|
41091
41115
|
fontStyle: font?.italic ? "italic" : "normal",
|
|
41092
|
-
dir:
|
|
41116
|
+
dir: getTextDirection(computedText),
|
|
41093
41117
|
scale: 1,
|
|
41094
41118
|
angle: angle * (180 / Math.PI)
|
|
41095
41119
|
});
|
|
@@ -41242,9 +41266,15 @@ async function createTextLayerV2(page, {
|
|
|
41242
41266
|
case OPS.beginMarkedContentProps: {
|
|
41243
41267
|
const [role, idRef, props] = args;
|
|
41244
41268
|
const id2 = normalizeMarkedContentId(idRef);
|
|
41269
|
+
let normalizedRole = isNameObject(role) ? role.name.toLowerCase() : role?.toString().toLowerCase();
|
|
41270
|
+
switch (normalizedRole) {
|
|
41271
|
+
case "placedgraphic":
|
|
41272
|
+
normalizedRole = "figure";
|
|
41273
|
+
break;
|
|
41274
|
+
}
|
|
41245
41275
|
markedContent.children.push({
|
|
41246
41276
|
id: id2,
|
|
41247
|
-
role:
|
|
41277
|
+
role: normalizedRole || "span",
|
|
41248
41278
|
attrs: props ?? void 0,
|
|
41249
41279
|
children: []
|
|
41250
41280
|
});
|
|
@@ -41262,9 +41292,16 @@ async function createTextLayerV2(page, {
|
|
|
41262
41292
|
}
|
|
41263
41293
|
break;
|
|
41264
41294
|
}
|
|
41295
|
+
case OPS.transform: {
|
|
41296
|
+
closeTextItem();
|
|
41297
|
+
const [a, b, c, d, e, f] = args;
|
|
41298
|
+
transformMatrix = Util.transform(transformMatrix, [a, b, c, d, e, f]);
|
|
41299
|
+
break;
|
|
41300
|
+
}
|
|
41265
41301
|
case OPS.restore: {
|
|
41266
41302
|
const state = stateStack.pop();
|
|
41267
41303
|
if (state) {
|
|
41304
|
+
transformMatrix = state.transformMatrix;
|
|
41268
41305
|
textMatrix = state.textMatrix;
|
|
41269
41306
|
lineMatrix = state.lineMatrix;
|
|
41270
41307
|
fontSize = state.fontSize;
|
|
@@ -41279,6 +41316,7 @@ async function createTextLayerV2(page, {
|
|
|
41279
41316
|
}
|
|
41280
41317
|
case OPS.save: {
|
|
41281
41318
|
stateStack.push({
|
|
41319
|
+
transformMatrix: [...transformMatrix],
|
|
41282
41320
|
textMatrix: [...textMatrix],
|
|
41283
41321
|
lineMatrix: [...lineMatrix],
|
|
41284
41322
|
fontSize,
|
package/package.json
CHANGED