@syncfusion/ej2-pdf-data-extract 35.1.41 → 35.1.43

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.
@@ -27254,8 +27254,12 @@ class _PdfRedactionProcessor {
27254
27254
  const inkAnnotation = annotation;
27255
27255
  const inkList = inkAnnotation.inkPointsCollection;
27256
27256
  const inkPointsToNumberArray = _convertPointsToNumberArrays(inkList);
27257
- inkBounds = this._getBoundsFromPoints(inkPointsToNumberArray[0], page);
27258
- bounds = inkAnnotation.bounds;
27257
+ let inkStrokePoints = [];
27258
+ for (let stroke = 0; stroke < inkPointsToNumberArray.length; stroke++) {
27259
+ inkStrokePoints = inkStrokePoints.concat(inkPointsToNumberArray[Number.parseInt(stroke.toString(), 10)]);
27260
+ }
27261
+ inkBounds = this._getBoundsFromPoints(inkStrokePoints, page);
27262
+ bounds = inkPointsToNumberArray.length > 0 ? inkBounds.bounds : inkAnnotation.bounds;
27259
27263
  if (!inkAnnotation._isLoaded) {
27260
27264
  inkBounds.isValidAnnotation = true;
27261
27265
  }
@@ -28971,6 +28975,1387 @@ var ScopeType;
28971
28975
  ScopeType[ScopeType["none"] = 3] = "none";
28972
28976
  })(ScopeType || (ScopeType = {}));
28973
28977
 
28978
+ /**
28979
+ * Utilities for converting visually ordered RTL text (as stored inside PDF content
28980
+ * streams) into logical Unicode reading order, and for normalizing Arabic
28981
+ * presentation forms back to their base Unicode code points.
28982
+ *
28983
+ * @private
28984
+ */
28985
+ /**
28986
+ * Checks whether the character is an Arabic presentation form (isolated, final,
28987
+ * initial or medial shape) in the Arabic Presentation Forms A/B blocks.
28988
+ *
28989
+ * @param {string} ch - Character to check.
28990
+ * @returns {boolean} True when the character is an Arabic presentation form.
28991
+ * @private
28992
+ */
28993
+ function _isArabicPresentationForm(ch) {
28994
+ const code = ch.charCodeAt(0);
28995
+ return (code >= 0xFB50 && code <= 0xFDFF) || (code >= 0xFE70 && code <= 0xFEFF);
28996
+ }
28997
+ /**
28998
+ * Checks whether the character belongs to a right-to-left script (Arabic, Hebrew,
28999
+ * Syriac, Thaana and related presentation blocks).
29000
+ *
29001
+ * @param {string} ch - Character to check.
29002
+ * @returns {boolean} True when the character is an RTL character.
29003
+ * @private
29004
+ */
29005
+ function _isRtlCharacter(ch) {
29006
+ const code = ch.charCodeAt(0);
29007
+ if (code < 0x0590 || code > 0x08FF) {
29008
+ if (code < 0xFB1D || code > 0xFEFF) {
29009
+ return false;
29010
+ }
29011
+ }
29012
+ if (code >= 0x0600 && code <= 0x0605) {
29013
+ return false;
29014
+ }
29015
+ if (code >= 0x0660 && code <= 0x0669) {
29016
+ return false;
29017
+ }
29018
+ if (code >= 0x06F0 && code <= 0x06F9) {
29019
+ return false;
29020
+ }
29021
+ if (code >= 0x064B && code <= 0x065F) {
29022
+ return false;
29023
+ }
29024
+ if (code === 0x0640) {
29025
+ return false;
29026
+ }
29027
+ return true;
29028
+ }
29029
+ /**
29030
+ * Checks whether the character is a neutral character (space, punctuation) that
29031
+ * takes its direction from surrounding strong characters.
29032
+ *
29033
+ * @param {string} ch - Character to check.
29034
+ * @returns {boolean} True when the character is directionally neutral.
29035
+ * @private
29036
+ */
29037
+ function _isNeutralCharacter(ch) {
29038
+ const code = ch.charCodeAt(0);
29039
+ if (code < 0x20) {
29040
+ return true;
29041
+ }
29042
+ if (code === 0x20 || code === 0xA0) {
29043
+ return true;
29044
+ }
29045
+ if (code >= 0x2000 && code <= 0x200F) {
29046
+ return true;
29047
+ }
29048
+ if (code >= 0x060C && code <= 0x060C) {
29049
+ return true;
29050
+ }
29051
+ if (code === 0x061B || code === 0x061F || code === 0x06D4) {
29052
+ return true;
29053
+ }
29054
+ if (code >= 0x066A && code <= 0x066D) {
29055
+ return true;
29056
+ }
29057
+ if (code >= 0x21 && code <= 0x2F) {
29058
+ return true;
29059
+ }
29060
+ if (code >= 0x3A && code <= 0x3F) {
29061
+ return true;
29062
+ }
29063
+ if (code >= 0x5B && code <= 0x60) {
29064
+ return true;
29065
+ }
29066
+ if (code >= 0x7B && code <= 0x7E) {
29067
+ return true;
29068
+ }
29069
+ if (code === 0x2013 || code === 0x2014 || code === 0x2026 || code === 0xAB || code === 0xBB) {
29070
+ return true;
29071
+ }
29072
+ return false;
29073
+ }
29074
+ /**
29075
+ * Checks whether the character is a left-to-right character (Latin letters,
29076
+ * digits and other common LTR characters).
29077
+ *
29078
+ * @param {string} ch - Character to check.
29079
+ * @returns {boolean} True when the character is an LTR character.
29080
+ * @private
29081
+ */
29082
+ function _isLtrCharacter(ch) {
29083
+ const code = ch.charCodeAt(0);
29084
+ if (code >= 0x41 && code <= 0x5A) {
29085
+ return true;
29086
+ }
29087
+ if (code >= 0x61 && code <= 0x7A) {
29088
+ return true;
29089
+ }
29090
+ if (code >= 0x30 && code <= 0x39) {
29091
+ return true;
29092
+ }
29093
+ if (code >= 0x0660 && code <= 0x0669) {
29094
+ return true;
29095
+ }
29096
+ if (code >= 0x06F0 && code <= 0x06F9) {
29097
+ return true;
29098
+ }
29099
+ return (code >= 0xC0 && code <= 0x24F) && !((code >= 0x0590 && code <= 0x08FF));
29100
+ }
29101
+ /**
29102
+ * Maps Arabic presentation form characters (U+FB50–U+FDFF, U+FE70–U+FEFF) to their
29103
+ * base Arabic code points (U+0600–U+06FF and supplement ranges). Ligature
29104
+ * presentation forms are mapped to their multi-character logical equivalents.
29105
+ *
29106
+ * @param {string} ch - Character to normalize.
29107
+ * @returns {string} The base (logical) Unicode representation of the character.
29108
+ * @private
29109
+ */
29110
+ function _normalizeArabicCharacter(ch) {
29111
+ const code = ch.charCodeAt(0);
29112
+ const mapped = Object.prototype.hasOwnProperty.call(arabicPresentationForms, code)
29113
+ ? arabicPresentationForms[code] : undefined;
29114
+ if (typeof (mapped) === 'string') {
29115
+ return mapped;
29116
+ }
29117
+ return ch;
29118
+ }
29119
+ /**
29120
+ * Reverses a copy of the given array between the specified bounds (inclusive).
29121
+ *
29122
+ * @param {string[]} items - Array to reverse a portion of.
29123
+ * @param {number} start - Start index.
29124
+ * @param {number} end - End index (inclusive).
29125
+ * @returns {void}
29126
+ * @private
29127
+ */
29128
+ function _reverseRange(items, start, end) {
29129
+ while (start < end) {
29130
+ const temp = items[start];
29131
+ items[start] = items[end];
29132
+ items[end] = temp;
29133
+ start++;
29134
+ end--;
29135
+ }
29136
+ }
29137
+ /**
29138
+ * Converts visually ordered text containing RTL content into logical Unicode order.
29139
+ * LTR runs are left untouched, so mixed RTL/LTR text is preserved. Characters are
29140
+ * handled as UTF-16 code units to match the rest of the extraction pipeline.
29141
+ *
29142
+ * @param {string} text - Text in visual order as extracted from the PDF content stream.
29143
+ * @returns {string} Text in logical reading order.
29144
+ * @private
29145
+ */
29146
+ function _convertVisualToLogicalOrder(text) {
29147
+ if (typeof (text) !== 'string' || text.length === 0) {
29148
+ return text;
29149
+ }
29150
+ if (text.indexOf('\r') !== -1 || text.indexOf('\n') !== -1) {
29151
+ const lines = text.split(/(\r\n|\r|\n)/);
29152
+ let result = '';
29153
+ for (let i = 0; i < lines.length; i++) {
29154
+ const part = lines[Number.parseInt(i.toString(), 10)];
29155
+ if (part === '\r\n' || part === '\r' || part === '\n') {
29156
+ result += part;
29157
+ }
29158
+ else {
29159
+ result += _convertVisualToLogicalOrder(part);
29160
+ }
29161
+ }
29162
+ return result;
29163
+ }
29164
+ const characters = [];
29165
+ for (let i = 0; i < text.length; i++) {
29166
+ characters.push(text[Number.parseInt(i.toString(), 10)]);
29167
+ }
29168
+ if (!_containsRtlCharacter(text)) {
29169
+ return characters.join('');
29170
+ }
29171
+ const length = characters.length;
29172
+ _reverseRange(characters, 0, length - 1);
29173
+ if (_isWholeLineReversalStorage(text)) {
29174
+ return characters.join('');
29175
+ }
29176
+ let index = 0;
29177
+ while (index < length) {
29178
+ const character = characters[Number.parseInt(index.toString(), 10)];
29179
+ if (!_isRtlCharacter(character) && !_isNeutralCharacter(character)) {
29180
+ let runEnd = index;
29181
+ for (let j = index + 1; j < length; j++) {
29182
+ const next = characters[Number.parseInt(j.toString(), 10)];
29183
+ if (_isRtlCharacter(next)) {
29184
+ break;
29185
+ }
29186
+ if (_isNeutralCharacter(next)) {
29187
+ let after = j + 1;
29188
+ while (after < length && _isNeutralCharacter(characters[Number.parseInt(after.toString(), 10)])) {
29189
+ after++;
29190
+ }
29191
+ if (after < length && !_isRtlCharacter(characters[Number.parseInt(after.toString(), 10)])) {
29192
+ runEnd = after - 1;
29193
+ j = after - 1;
29194
+ }
29195
+ else {
29196
+ break;
29197
+ }
29198
+ }
29199
+ else {
29200
+ runEnd = j;
29201
+ }
29202
+ }
29203
+ _reverseRange(characters, index, runEnd);
29204
+ index = runEnd + 1;
29205
+ }
29206
+ else {
29207
+ index++;
29208
+ }
29209
+ }
29210
+ return characters.join('');
29211
+ }
29212
+ /**
29213
+ * Mirrored (swapped) forms of the paired bracket characters. RTL visual
29214
+ * layout stores these glyphs mirrored (Unicode BiDi rule L4), so converting
29215
+ * a visual fragment back to logical order must swap the pair members.
29216
+ *
29217
+ * @private
29218
+ */
29219
+ const mirroredBrackets = {
29220
+ '(': ')', ')': '(',
29221
+ '[': ']', ']': '[',
29222
+ '{': '}', '}': '{',
29223
+ '\u00AB': '\u00BB', '\u00BB': '\u00AB'
29224
+ };
29225
+ /**
29226
+ * Swaps mirrored paired bracket characters (parentheses, square brackets, curly
29227
+ * braces, angle quotes) back to their logical pair member. RTL visual layout
29228
+ * paints these glyphs mirrored (Unicode BiDi rule L4), so a visual-order line
29229
+ * must be un-mirrored to yield the logical text Adobe extracts.
29230
+ *
29231
+ * @param {string} text - Text containing mirrored bracket glyphs.
29232
+ * @returns {string} Text with pair members swapped back.
29233
+ * @private
29234
+ */
29235
+ function _unmirrorPairedBrackets(text) {
29236
+ if (typeof (text) !== 'string' || text.length === 0) {
29237
+ return text;
29238
+ }
29239
+ let result = '';
29240
+ for (let i = 0; i < text.length; i++) {
29241
+ const ch = text[Number.parseInt(i.toString(), 10)];
29242
+ if (Object.prototype.hasOwnProperty.call(mirroredBrackets, ch)) {
29243
+ result += mirroredBrackets[ch]; // eslint-disable-line
29244
+ }
29245
+ else {
29246
+ result += ch;
29247
+ }
29248
+ }
29249
+ return result;
29250
+ }
29251
+ /**
29252
+ * Converts a visual-order fragment that contains no RTL characters (Latin
29253
+ * tokens, digits, neutral punctuation) into logical order for an RTL line.
29254
+ *
29255
+ * @param {string} text - Fragment in visual order.
29256
+ * @returns {string} Fragment in logical order (bracket glyphs unchanged).
29257
+ * @private
29258
+ */
29259
+ function _invertVisualLtrFragment(text) {
29260
+ if (typeof (text) !== 'string' || text.length === 0) {
29261
+ return text;
29262
+ }
29263
+ const characters = text.split('');
29264
+ _reverseRange(characters, 0, characters.length - 1);
29265
+ let index = 0;
29266
+ while (index < characters.length) {
29267
+ if (_isLtrCharacter(characters[Number.parseInt(index.toString(), 10)])) {
29268
+ let runEnd = index;
29269
+ while (runEnd + 1 < characters.length &&
29270
+ _isLtrCharacter(characters[Number.parseInt((runEnd + 1).toString(), 10)])) {
29271
+ runEnd++;
29272
+ }
29273
+ _reverseRange(characters, index, runEnd);
29274
+ index = runEnd + 1;
29275
+ }
29276
+ else {
29277
+ index++;
29278
+ }
29279
+ }
29280
+ return characters.join('');
29281
+ }
29282
+ /**
29283
+ * Checks whether the paired brackets in the given text form a balanced
29284
+ * sequence (every closing bracket is preceded by a matching opener and no
29285
+ * depth underflow). Text without brackets is balanced by definition.
29286
+ *
29287
+ * @param {string} text - Text to inspect.
29288
+ * @returns {boolean} True when the bracket sequence is balanced.
29289
+ * @private
29290
+ */
29291
+ function _isBracketSequenceBalanced(text) {
29292
+ if (typeof (text) !== 'string' || text.length === 0) {
29293
+ return true;
29294
+ }
29295
+ const openers = { '(': ')', '[': ']', '{': '}', '\u00AB': '\u00BB' };
29296
+ const closers = { ')': '(', ']': '[', '}': '{', '\u00BB': '\u00AB' };
29297
+ const stack = [];
29298
+ for (let i = 0; i < text.length; i++) {
29299
+ const ch = text[Number.parseInt(i.toString(), 10)];
29300
+ if (Object.prototype.hasOwnProperty.call(openers, ch)) {
29301
+ stack.push(openers[ch]); // eslint-disable-line
29302
+ }
29303
+ else if (Object.prototype.hasOwnProperty.call(closers, ch)) {
29304
+ const expected = stack.length > 0 ? stack.pop() : undefined;
29305
+ if (expected !== undefined && expected !== ch) {
29306
+ return false;
29307
+ }
29308
+ if (expected === undefined) {
29309
+ return false;
29310
+ }
29311
+ }
29312
+ }
29313
+ return stack.length === 0;
29314
+ }
29315
+ /**
29316
+ * Resolves paired-bracket glyph mirroring for a logical-order RTL line.
29317
+ *
29318
+ * @param {string} text - Line text in logical order.
29319
+ * @returns {string} Text with mirrored bracket glyphs restored when needed.
29320
+ * @private
29321
+ */
29322
+ function _resolveMirroredBrackets(text) {
29323
+ if (typeof (text) !== 'string' || text.length === 0) {
29324
+ return text;
29325
+ }
29326
+ if (_isBracketSequenceBalanced(text)) {
29327
+ return text;
29328
+ }
29329
+ const unmirrored = _unmirrorPairedBrackets(text);
29330
+ return _isBracketSequenceBalanced(unmirrored) ? unmirrored : text;
29331
+ }
29332
+ /**
29333
+ * Detects the naive whole-line-reversal storage convention using digit runs
29334
+ * embedded in RTL text. In canonical visual storage digit runs read
29335
+ * left-to-right in ascending significance order ("2010"); if a stored digit
29336
+ * run instead reads like a plain reversal of an ascending run ("0102"), the
29337
+ * producer wrote the whole logical string reversed (convention B).
29338
+ *
29339
+ * @param {string} text - Text in visual order as extracted from the PDF.
29340
+ * @returns {boolean} True when the text appears whole-line-reversal stored.
29341
+ * @private
29342
+ */
29343
+ function _isWholeLineReversalStorage(text) {
29344
+ const runs = [];
29345
+ let current = '';
29346
+ for (let i = 0; i < text.length; i++) {
29347
+ const code = text.charCodeAt(i);
29348
+ const isDigit = (code >= 0x30 && code <= 0x39) || (code >= 0x0660 && code <= 0x0669);
29349
+ if (isDigit) {
29350
+ current += text[i];
29351
+ }
29352
+ else if (current.length > 0) {
29353
+ runs.push(current);
29354
+ current = '';
29355
+ }
29356
+ }
29357
+ if (current.length > 0) {
29358
+ runs.push(current);
29359
+ }
29360
+ let reversedCount = 0;
29361
+ let total = 0;
29362
+ for (let i = 0; i < runs.length; i++) {
29363
+ const run = runs[Number.parseInt(i.toString(), 10)];
29364
+ if (run.length < 2) {
29365
+ continue;
29366
+ }
29367
+ total++;
29368
+ if (run === run.split('').reverse().join('')) {
29369
+ if (run.length >= 2 && new Set(run).size === 1) {
29370
+ total--;
29371
+ }
29372
+ continue;
29373
+ }
29374
+ if (run[0] === '0' || run[0] === String.fromCharCode(0x0660)) {
29375
+ reversedCount++;
29376
+ }
29377
+ }
29378
+ if (total === 0) {
29379
+ return false;
29380
+ }
29381
+ return reversedCount / total >= 0.5;
29382
+ }
29383
+ /**
29384
+ * Converts visually ordered RTL text into logical order and normalizes Arabic
29385
+ * presentation forms to their base Unicode code points. This produces text
29386
+ * comparable to Adobe text extraction for Arabic, Hebrew, Persian and Urdu.
29387
+ *
29388
+ * @param {string} text - Text in visual order as extracted from the PDF.
29389
+ * @returns {string} Normalized text in logical reading order.
29390
+ * @private
29391
+ */
29392
+ function _normalizeRtlText(text) {
29393
+ if (typeof (text) !== 'string' || text.length === 0) {
29394
+ return text;
29395
+ }
29396
+ const reordered = _convertVisualToLogicalOrder(text);
29397
+ if (!_containsRtlCharacter(reordered)) {
29398
+ return reordered;
29399
+ }
29400
+ let normalized = '';
29401
+ for (let i = 0; i < reordered.length; i++) {
29402
+ normalized += _normalizeArabicCharacter(reordered[Number.parseInt(i.toString(), 10)]);
29403
+ }
29404
+ return normalized;
29405
+ }
29406
+ /**
29407
+ * Checks whether the given string contains any RTL script character.
29408
+ *
29409
+ * @param {string} text - Text to inspect.
29410
+ * @returns {boolean} True when the text contains an RTL character.
29411
+ * @private
29412
+ */
29413
+ function _containsRtlCharacter(text) {
29414
+ if (typeof (text) !== 'string') {
29415
+ return false;
29416
+ }
29417
+ for (let i = 0; i < text.length; i++) {
29418
+ if (_isRtlCharacter(text[Number.parseInt(i.toString(), 10)])) {
29419
+ return true;
29420
+ }
29421
+ }
29422
+ return false;
29423
+ }
29424
+ /**
29425
+ * Checks whether the given text contains at least one Arabic presentation form
29426
+ * character. Producers that store text in visual glyph order typically emit
29427
+ * presentation forms, so this is used as a visual-order signal.
29428
+ *
29429
+ * @param {string} text - Text to inspect.
29430
+ * @returns {boolean} True when a presentation form character is present.
29431
+ * @private
29432
+ */
29433
+ function _containsArabicPresentationForm(text) {
29434
+ if (typeof (text) !== 'string') {
29435
+ return false;
29436
+ }
29437
+ for (let i = 0; i < text.length; i++) {
29438
+ if (_isArabicPresentationForm(text[Number.parseInt(i.toString(), 10)])) {
29439
+ return true;
29440
+ }
29441
+ }
29442
+ return false;
29443
+ }
29444
+ /**
29445
+ * Maps Arabic presentation form characters in the given text to their base
29446
+ * Unicode code points WITHOUT any reordering. Used when the text is already
29447
+ * in logical order and only character normalization is needed.
29448
+ *
29449
+ * @param {string} text - Text to map.
29450
+ * @returns {string} Text with presentation forms replaced by base characters.
29451
+ * @private
29452
+ */
29453
+ function _mapArabicPresentationForms(text) {
29454
+ if (typeof (text) !== 'string' || text.length === 0) {
29455
+ return text;
29456
+ }
29457
+ if (!_containsRtlCharacter(text)) {
29458
+ return text;
29459
+ }
29460
+ let mapped = '';
29461
+ for (let i = 0; i < text.length; i++) {
29462
+ const ch = text[Number.parseInt(i.toString(), 10)];
29463
+ if (_isArabicPresentationForm(ch)) {
29464
+ mapped += _normalizeArabicCharacter(ch);
29465
+ }
29466
+ else {
29467
+ mapped += ch;
29468
+ }
29469
+ }
29470
+ return mapped;
29471
+ }
29472
+ /**
29473
+ * Determines whether the given RTL text is stored in visual (right-to-left
29474
+ * glyph) order rather than logical order, using the horizontal position of
29475
+ * consecutive glyphs/words. When the second fragment is placed to the RIGHT of
29476
+ * the first fragment, the text advances leftward and is visual-ordered RTL.
29477
+ *
29478
+ * @param {{ x: number, width: number }} firstBounds - Bounds of the earlier extracted fragment.
29479
+ * @param {number} firstBounds.x - X-coordinate of the first fragment.
29480
+ * @param {number} firstBounds.width - Width of the first fragment.
29481
+ * @param {{ x: number, width: number }} secondBounds - Bounds of the next extracted fragment.
29482
+ * @param {number} secondBounds.x - X-coordinate of the second fragment.
29483
+ * @param {number} secondBounds.width - Width of the second fragment.
29484
+ * @returns {boolean} True when the fragments indicate visual RTL ordering.
29485
+ * @private
29486
+ */
29487
+ function _isVisualOrderRtl(firstBounds, secondBounds) {
29488
+ if (!firstBounds || !secondBounds) {
29489
+ return false;
29490
+ }
29491
+ return secondBounds.x > firstBounds.x + firstBounds.width * 0.5;
29492
+ }
29493
+ /**
29494
+ * Normalizes a search input string for comparison. Search input is expected in
29495
+ * logical order; Arabic presentation forms are mapped to base code points so a
29496
+ * search value typed in logical Arabic matches extracted logical text.
29497
+ *
29498
+ * @param {string} text - Search text to normalize.
29499
+ * @returns {string} Normalized search text.
29500
+ * @private
29501
+ */
29502
+ function _normalizeSearchText(text) {
29503
+ if (typeof (text) !== 'string' || text.length === 0) {
29504
+ return text;
29505
+ }
29506
+ if (!_containsRtlCharacter(text)) {
29507
+ return text;
29508
+ }
29509
+ let normalized = '';
29510
+ for (let i = 0; i < text.length; i++) {
29511
+ const ch = text[Number.parseInt(i.toString(), 10)];
29512
+ if (_isArabicPresentationForm(ch)) {
29513
+ normalized += _normalizeArabicCharacter(ch);
29514
+ }
29515
+ else {
29516
+ normalized += ch;
29517
+ }
29518
+ }
29519
+ return normalized;
29520
+ }
29521
+ /**
29522
+ * Rebuilds reading order for extracted fragments: groups fragments that share
29523
+ * the same baseline (row) and, for rows containing RTL content, emits the
29524
+ * right-most fragment first (Adobe-style RTL line reconstruction). LTR-only
29525
+ * rows keep the original (left-to-right) order.
29526
+ *
29527
+ * @param {_TextFragment[]} fragments - Fragments in content stream order.
29528
+ * @returns {_TextFragment[]} Fragments in reading order.
29529
+ * @private
29530
+ */
29531
+ function _reorderFragmentsForRtlReading(fragments) {
29532
+ if (!fragments || fragments.length < 2) {
29533
+ return fragments;
29534
+ }
29535
+ let hasRtl = false;
29536
+ for (let i = 0; i < fragments.length; i++) {
29537
+ const fragment = fragments[Number.parseInt(i.toString(), 10)];
29538
+ if (fragment && _containsRtlCharacter(fragment.text)) {
29539
+ hasRtl = true;
29540
+ break;
29541
+ }
29542
+ }
29543
+ if (!hasRtl) {
29544
+ return fragments;
29545
+ }
29546
+ const tolerance = _getRtlRowTolerance(fragments);
29547
+ const rows = [];
29548
+ for (let i = 0; i < fragments.length; i++) {
29549
+ const fragment = fragments[Number.parseInt(i.toString(), 10)];
29550
+ if (!fragment || !fragment.bounds) {
29551
+ continue;
29552
+ }
29553
+ let placed = false;
29554
+ for (let r = 0; r < rows.length; r++) {
29555
+ const row = rows[Number.parseInt(r.toString(), 10)];
29556
+ const reference = row[0];
29557
+ if (_isSameRtlRow(reference.bounds, fragment.bounds, tolerance)) {
29558
+ row.push(fragment);
29559
+ placed = true;
29560
+ break;
29561
+ }
29562
+ }
29563
+ if (!placed) {
29564
+ rows.push([fragment]);
29565
+ }
29566
+ }
29567
+ const ordered = [];
29568
+ rows.sort((a, b) => a[0].bounds.y - b[0].bounds.y);
29569
+ for (let r = 0; r < rows.length; r++) {
29570
+ const row = rows[Number.parseInt(r.toString(), 10)];
29571
+ const rowHasRtl = row.some((fragment) => _containsRtlCharacter(fragment.text));
29572
+ if (rowHasRtl) {
29573
+ row.sort((a, b) => b.bounds.x - a.bounds.x);
29574
+ }
29575
+ else {
29576
+ row.sort((a, b) => a.bounds.x - b.bounds.x);
29577
+ }
29578
+ for (let i = 0; i < row.length; i++) {
29579
+ ordered.push(row[Number.parseInt(i.toString(), 10)]);
29580
+ }
29581
+ }
29582
+ return ordered;
29583
+ }
29584
+ /**
29585
+ * Computes the vertical tolerance used to decide whether two fragments share
29586
+ * the same text row (fraction of the dominant fragment height).
29587
+ *
29588
+ * @param {_TextFragment[]} fragments - Fragments being grouped.
29589
+ * @returns {number} Row-grouping tolerance in page units.
29590
+ * @private
29591
+ */
29592
+ function _getRtlRowTolerance(fragments) {
29593
+ let totalHeight = 0;
29594
+ let count = 0;
29595
+ for (let i = 0; i < fragments.length; i++) {
29596
+ const fragment = fragments[Number.parseInt(i.toString(), 10)];
29597
+ if (fragment && fragment.bounds && fragment.bounds.height > 0) {
29598
+ totalHeight += fragment.bounds.height;
29599
+ count++;
29600
+ }
29601
+ }
29602
+ if (count === 0) {
29603
+ return 2;
29604
+ }
29605
+ return Math.max(2, (totalHeight / count) * 0.5);
29606
+ }
29607
+ /**
29608
+ * Determines whether two fragment bounds belong to the same text row.
29609
+ *
29610
+ * @param {{ y: number, height: number }} first - First fragment bounds.
29611
+ * @param {number} first.y - Y-coordinate of the first fragment.
29612
+ * @param {number} first.height - Height of the first fragment.
29613
+ * @param {{ y: number, height: number }} second - Second fragment bounds.
29614
+ * @param {number} second.y - Y-coordinate of the second fragment.
29615
+ * @param {number} second.height - Height of the second fragment.
29616
+ * @param {number} tolerance - Vertical tolerance for row grouping.
29617
+ * @returns {boolean} True when both fragments are on the same row.
29618
+ * @private
29619
+ */
29620
+ function _isSameRtlRow(first, second, tolerance) {
29621
+ const firstCenter = first.y + first.height / 2;
29622
+ const secondCenter = second.y + second.height / 2;
29623
+ return Math.abs(firstCenter - secondCenter) <= tolerance;
29624
+ }
29625
+ const arabicPresentationForms = {
29626
+ 0xFB50: '\u0671',
29627
+ 0xFB51: '\u0671',
29628
+ 0xFB52: '\u067b',
29629
+ 0xFB53: '\u067b',
29630
+ 0xFB54: '\u067b',
29631
+ 0xFB55: '\u067b',
29632
+ 0xFB56: '\u067e',
29633
+ 0xFB57: '\u067e',
29634
+ 0xFB58: '\u067e',
29635
+ 0xFB59: '\u067e',
29636
+ 0xFB5A: '\u0680',
29637
+ 0xFB5B: '\u0680',
29638
+ 0xFB5C: '\u0680',
29639
+ 0xFB5D: '\u0680',
29640
+ 0xFB5E: '\u067a',
29641
+ 0xFB5F: '\u067a',
29642
+ 0xFB60: '\u067a',
29643
+ 0xFB61: '\u067a',
29644
+ 0xFB62: '\u067f',
29645
+ 0xFB63: '\u067f',
29646
+ 0xFB64: '\u067f',
29647
+ 0xFB65: '\u067f',
29648
+ 0xFB66: '\u0679',
29649
+ 0xFB67: '\u0679',
29650
+ 0xFB68: '\u0679',
29651
+ 0xFB69: '\u0679',
29652
+ 0xFB6A: '\u06a4',
29653
+ 0xFB6B: '\u06a4',
29654
+ 0xFB6C: '\u06a4',
29655
+ 0xFB6D: '\u06a4',
29656
+ 0xFB6E: '\u06a6',
29657
+ 0xFB6F: '\u06a6',
29658
+ 0xFB70: '\u06a6',
29659
+ 0xFB71: '\u06a6',
29660
+ 0xFB72: '\u0684',
29661
+ 0xFB73: '\u0684',
29662
+ 0xFB74: '\u0684',
29663
+ 0xFB75: '\u0684',
29664
+ 0xFB76: '\u0683',
29665
+ 0xFB77: '\u0683',
29666
+ 0xFB78: '\u0683',
29667
+ 0xFB79: '\u0683',
29668
+ 0xFB7A: '\u0686',
29669
+ 0xFB7B: '\u0686',
29670
+ 0xFB7C: '\u0686',
29671
+ 0xFB7D: '\u0686',
29672
+ 0xFB7E: '\u0687',
29673
+ 0xFB7F: '\u0687',
29674
+ 0xFB80: '\u0687',
29675
+ 0xFB81: '\u0687',
29676
+ 0xFB82: '\u068d',
29677
+ 0xFB83: '\u068d',
29678
+ 0xFB84: '\u068c',
29679
+ 0xFB85: '\u068c',
29680
+ 0xFB86: '\u068e',
29681
+ 0xFB87: '\u068e',
29682
+ 0xFB88: '\u0688',
29683
+ 0xFB89: '\u0688',
29684
+ 0xFB8A: '\u0698',
29685
+ 0xFB8B: '\u0698',
29686
+ 0xFB8C: '\u0691',
29687
+ 0xFB8D: '\u0691',
29688
+ 0xFB8E: '\u06a9',
29689
+ 0xFB8F: '\u06a9',
29690
+ 0xFB90: '\u06a9',
29691
+ 0xFB91: '\u06a9',
29692
+ 0xFB92: '\u06af',
29693
+ 0xFB93: '\u06af',
29694
+ 0xFB94: '\u06af',
29695
+ 0xFB95: '\u06af',
29696
+ 0xFB96: '\u06b3',
29697
+ 0xFB97: '\u06b3',
29698
+ 0xFB98: '\u06b3',
29699
+ 0xFB99: '\u06b3',
29700
+ 0xFB9A: '\u06b1',
29701
+ 0xFB9B: '\u06b1',
29702
+ 0xFB9C: '\u06b1',
29703
+ 0xFB9D: '\u06b1',
29704
+ 0xFB9E: '\u06ba',
29705
+ 0xFB9F: '\u06ba',
29706
+ 0xFBA0: '\u06bb',
29707
+ 0xFBA1: '\u06bb',
29708
+ 0xFBA2: '\u06bb',
29709
+ 0xFBA3: '\u06bb',
29710
+ 0xFBA4: '\u06c0',
29711
+ 0xFBA5: '\u06c0',
29712
+ 0xFBA6: '\u06c1',
29713
+ 0xFBA7: '\u06c1',
29714
+ 0xFBA8: '\u06c1',
29715
+ 0xFBA9: '\u06c1',
29716
+ 0xFBAA: '\u06be',
29717
+ 0xFBAB: '\u06be',
29718
+ 0xFBAC: '\u06be',
29719
+ 0xFBAD: '\u06be',
29720
+ 0xFBAE: '\u06d2',
29721
+ 0xFBAF: '\u06d2',
29722
+ 0xFBB0: '\u06d3',
29723
+ 0xFBB1: '\u06d3',
29724
+ 0xFBD3: '\u06ad',
29725
+ 0xFBD4: '\u06ad',
29726
+ 0xFBD5: '\u06ad',
29727
+ 0xFBD6: '\u06ad',
29728
+ 0xFBD7: '\u06c7',
29729
+ 0xFBD8: '\u06c7',
29730
+ 0xFBD9: '\u06c6',
29731
+ 0xFBDA: '\u06c6',
29732
+ 0xFBDB: '\u06c8',
29733
+ 0xFBDC: '\u06c8',
29734
+ 0xFBDD: '\u06c7\u0674',
29735
+ 0xFBDE: '\u06cb',
29736
+ 0xFBDF: '\u06cb',
29737
+ 0xFBE0: '\u06c5',
29738
+ 0xFBE1: '\u06c5',
29739
+ 0xFBE2: '\u06c9',
29740
+ 0xFBE3: '\u06c9',
29741
+ 0xFBE4: '\u06d0',
29742
+ 0xFBE5: '\u06d0',
29743
+ 0xFBE6: '\u06d0',
29744
+ 0xFBE7: '\u06d0',
29745
+ 0xFBE8: '\u0649',
29746
+ 0xFBE9: '\u0649',
29747
+ 0xFBEA: '\u0626\u0627',
29748
+ 0xFBEB: '\u0626\u0627',
29749
+ 0xFBEC: '\u0626\u06d5',
29750
+ 0xFBED: '\u0626\u06d5',
29751
+ 0xFBEE: '\u0626\u0648',
29752
+ 0xFBEF: '\u0626\u0648',
29753
+ 0xFBF0: '\u0626\u06c7',
29754
+ 0xFBF1: '\u0626\u06c7',
29755
+ 0xFBF2: '\u0626\u06c6',
29756
+ 0xFBF3: '\u0626\u06c6',
29757
+ 0xFBF4: '\u0626\u06c8',
29758
+ 0xFBF5: '\u0626\u06c8',
29759
+ 0xFBF6: '\u0626\u06d0',
29760
+ 0xFBF7: '\u0626\u06d0',
29761
+ 0xFBF8: '\u0626\u06d0',
29762
+ 0xFBF9: '\u0626\u0649',
29763
+ 0xFBFA: '\u0626\u0649',
29764
+ 0xFBFB: '\u0626\u0649',
29765
+ 0xFBFC: '\u06cc',
29766
+ 0xFBFD: '\u06cc',
29767
+ 0xFBFE: '\u06cc',
29768
+ 0xFBFF: '\u06cc',
29769
+ 0xFC00: '\u0626\u062c',
29770
+ 0xFC01: '\u0626\u062d',
29771
+ 0xFC02: '\u0626\u0645',
29772
+ 0xFC03: '\u0626\u0649',
29773
+ 0xFC04: '\u0626\u064a',
29774
+ 0xFC05: '\u0628\u062c',
29775
+ 0xFC06: '\u0628\u062d',
29776
+ 0xFC07: '\u0628\u062e',
29777
+ 0xFC08: '\u0628\u0645',
29778
+ 0xFC09: '\u0628\u0649',
29779
+ 0xFC0A: '\u0628\u064a',
29780
+ 0xFC0B: '\u062a\u062c',
29781
+ 0xFC0C: '\u062a\u062d',
29782
+ 0xFC0D: '\u062a\u062e',
29783
+ 0xFC0E: '\u062a\u0645',
29784
+ 0xFC0F: '\u062a\u0649',
29785
+ 0xFC10: '\u062a\u064a',
29786
+ 0xFC11: '\u062b\u062c',
29787
+ 0xFC12: '\u062b\u0645',
29788
+ 0xFC13: '\u062b\u0649',
29789
+ 0xFC14: '\u062b\u064a',
29790
+ 0xFC15: '\u062c\u062d',
29791
+ 0xFC16: '\u062c\u0645',
29792
+ 0xFC17: '\u062d\u062c',
29793
+ 0xFC18: '\u062d\u0645',
29794
+ 0xFC19: '\u062e\u062c',
29795
+ 0xFC1A: '\u062e\u062d',
29796
+ 0xFC1B: '\u062e\u0645',
29797
+ 0xFC1C: '\u0633\u062c',
29798
+ 0xFC1D: '\u0633\u062d',
29799
+ 0xFC1E: '\u0633\u062e',
29800
+ 0xFC1F: '\u0633\u0645',
29801
+ 0xFC20: '\u0635\u062d',
29802
+ 0xFC21: '\u0635\u0645',
29803
+ 0xFC22: '\u0636\u062c',
29804
+ 0xFC23: '\u0636\u062d',
29805
+ 0xFC24: '\u0636\u062e',
29806
+ 0xFC25: '\u0636\u0645',
29807
+ 0xFC26: '\u0637\u062d',
29808
+ 0xFC27: '\u0637\u0645',
29809
+ 0xFC28: '\u0638\u0645',
29810
+ 0xFC29: '\u0639\u062c',
29811
+ 0xFC2A: '\u0639\u0645',
29812
+ 0xFC2B: '\u063a\u062c',
29813
+ 0xFC2C: '\u063a\u0645',
29814
+ 0xFC2D: '\u0641\u062c',
29815
+ 0xFC2E: '\u0641\u062d',
29816
+ 0xFC2F: '\u0641\u062e',
29817
+ 0xFC30: '\u0641\u0645',
29818
+ 0xFC31: '\u0641\u0649',
29819
+ 0xFC32: '\u0641\u064a',
29820
+ 0xFC33: '\u0642\u062d',
29821
+ 0xFC34: '\u0642\u0645',
29822
+ 0xFC35: '\u0642\u0649',
29823
+ 0xFC36: '\u0642\u064a',
29824
+ 0xFC37: '\u0643\u0627',
29825
+ 0xFC38: '\u0643\u062c',
29826
+ 0xFC39: '\u0643\u062d',
29827
+ 0xFC3A: '\u0643\u062e',
29828
+ 0xFC3B: '\u0643\u0644',
29829
+ 0xFC3C: '\u0643\u0645',
29830
+ 0xFC3D: '\u0643\u0649',
29831
+ 0xFC3E: '\u0643\u064a',
29832
+ 0xFC3F: '\u0644\u062c',
29833
+ 0xFC40: '\u0644\u062d',
29834
+ 0xFC41: '\u0644\u062e',
29835
+ 0xFC42: '\u0644\u0645',
29836
+ 0xFC43: '\u0644\u0649',
29837
+ 0xFC44: '\u0644\u064a',
29838
+ 0xFC45: '\u0645\u062c',
29839
+ 0xFC46: '\u0645\u062d',
29840
+ 0xFC47: '\u0645\u062e',
29841
+ 0xFC48: '\u0645\u0645',
29842
+ 0xFC49: '\u0645\u0649',
29843
+ 0xFC4A: '\u0645\u064a',
29844
+ 0xFC4B: '\u0646\u062c',
29845
+ 0xFC4C: '\u0646\u062d',
29846
+ 0xFC4D: '\u0646\u062e',
29847
+ 0xFC4E: '\u0646\u0645',
29848
+ 0xFC4F: '\u0646\u0649',
29849
+ 0xFC50: '\u0646\u064a',
29850
+ 0xFC51: '\u0647\u062c',
29851
+ 0xFC52: '\u0647\u0645',
29852
+ 0xFC53: '\u0647\u0649',
29853
+ 0xFC54: '\u0647\u064a',
29854
+ 0xFC55: '\u064a\u062c',
29855
+ 0xFC56: '\u064a\u062d',
29856
+ 0xFC57: '\u064a\u062e',
29857
+ 0xFC58: '\u064a\u0645',
29858
+ 0xFC59: '\u064a\u0649',
29859
+ 0xFC5A: '\u064a\u064a',
29860
+ 0xFC5B: '\u0630\u0670',
29861
+ 0xFC5C: '\u0631\u0670',
29862
+ 0xFC5D: '\u0649\u0670',
29863
+ 0xFC5E: '\u064c\u0651',
29864
+ 0xFC5F: '\u064d\u0651',
29865
+ 0xFC60: '\u064e\u0651',
29866
+ 0xFC61: '\u064f\u0651',
29867
+ 0xFC62: '\u0650\u0651',
29868
+ 0xFC63: '\u0651\u0670',
29869
+ 0xFC64: '\u0626\u0631',
29870
+ 0xFC65: '\u0626\u0632',
29871
+ 0xFC66: '\u0626\u0645',
29872
+ 0xFC67: '\u0626\u0646',
29873
+ 0xFC68: '\u0626\u0649',
29874
+ 0xFC69: '\u0626\u064a',
29875
+ 0xFC6A: '\u0628\u0631',
29876
+ 0xFC6B: '\u0628\u0632',
29877
+ 0xFC6C: '\u0628\u0645',
29878
+ 0xFC6D: '\u0628\u0646',
29879
+ 0xFC6E: '\u0628\u0649',
29880
+ 0xFC6F: '\u0628\u064a',
29881
+ 0xFC70: '\u062a\u0631',
29882
+ 0xFC71: '\u062a\u0632',
29883
+ 0xFC72: '\u062a\u0645',
29884
+ 0xFC73: '\u062a\u0646',
29885
+ 0xFC74: '\u062a\u0649',
29886
+ 0xFC75: '\u062a\u064a',
29887
+ 0xFC76: '\u062b\u0631',
29888
+ 0xFC77: '\u062b\u0632',
29889
+ 0xFC78: '\u062b\u0645',
29890
+ 0xFC79: '\u062b\u0646',
29891
+ 0xFC7A: '\u062b\u0649',
29892
+ 0xFC7B: '\u062b\u064a',
29893
+ 0xFC7C: '\u0641\u0649',
29894
+ 0xFC7D: '\u0641\u064a',
29895
+ 0xFC7E: '\u0642\u0649',
29896
+ 0xFC7F: '\u0642\u064a',
29897
+ 0xFC80: '\u0643\u0627',
29898
+ 0xFC81: '\u0643\u0644',
29899
+ 0xFC82: '\u0643\u0645',
29900
+ 0xFC83: '\u0643\u0649',
29901
+ 0xFC84: '\u0643\u064a',
29902
+ 0xFC85: '\u0644\u0645',
29903
+ 0xFC86: '\u0644\u0649',
29904
+ 0xFC87: '\u0644\u064a',
29905
+ 0xFC88: '\u0645\u0627',
29906
+ 0xFC89: '\u0645\u0645',
29907
+ 0xFC8A: '\u0646\u0631',
29908
+ 0xFC8B: '\u0646\u0632',
29909
+ 0xFC8C: '\u0646\u0645',
29910
+ 0xFC8D: '\u0646\u0646',
29911
+ 0xFC8E: '\u0646\u0649',
29912
+ 0xFC8F: '\u0646\u064a',
29913
+ 0xFC90: '\u0649\u0670',
29914
+ 0xFC91: '\u064a\u0631',
29915
+ 0xFC92: '\u064a\u0632',
29916
+ 0xFC93: '\u064a\u0645',
29917
+ 0xFC94: '\u064a\u0646',
29918
+ 0xFC95: '\u064a\u0649',
29919
+ 0xFC96: '\u064a\u064a',
29920
+ 0xFC97: '\u0626\u062c',
29921
+ 0xFC98: '\u0626\u062d',
29922
+ 0xFC99: '\u0626\u062e',
29923
+ 0xFC9A: '\u0626\u0645',
29924
+ 0xFC9B: '\u0626\u0647',
29925
+ 0xFC9C: '\u0628\u062c',
29926
+ 0xFC9D: '\u0628\u062d',
29927
+ 0xFC9E: '\u0628\u062e',
29928
+ 0xFC9F: '\u0628\u0645',
29929
+ 0xFCA0: '\u0628\u0647',
29930
+ 0xFCA1: '\u062a\u062c',
29931
+ 0xFCA2: '\u062a\u062d',
29932
+ 0xFCA3: '\u062a\u062e',
29933
+ 0xFCA4: '\u062a\u0645',
29934
+ 0xFCA5: '\u062a\u0647',
29935
+ 0xFCA6: '\u062b\u0645',
29936
+ 0xFCA7: '\u062c\u062d',
29937
+ 0xFCA8: '\u062c\u0645',
29938
+ 0xFCA9: '\u062d\u062c',
29939
+ 0xFCAA: '\u062d\u0645',
29940
+ 0xFCAB: '\u062e\u062c',
29941
+ 0xFCAC: '\u062e\u0645',
29942
+ 0xFCAD: '\u0633\u062c',
29943
+ 0xFCAE: '\u0633\u062d',
29944
+ 0xFCAF: '\u0633\u062e',
29945
+ 0xFCB0: '\u0633\u0645',
29946
+ 0xFCB1: '\u0635\u062d',
29947
+ 0xFCB2: '\u0635\u062e',
29948
+ 0xFCB3: '\u0635\u0645',
29949
+ 0xFCB4: '\u0636\u062c',
29950
+ 0xFCB5: '\u0636\u062d',
29951
+ 0xFCB6: '\u0636\u062e',
29952
+ 0xFCB7: '\u0636\u0645',
29953
+ 0xFCB8: '\u0637\u062d',
29954
+ 0xFCB9: '\u0638\u0645',
29955
+ 0xFCBA: '\u0639\u062c',
29956
+ 0xFCBB: '\u0639\u0645',
29957
+ 0xFCBC: '\u063a\u062c',
29958
+ 0xFCBD: '\u063a\u0645',
29959
+ 0xFCBE: '\u0641\u062c',
29960
+ 0xFCBF: '\u0641\u062d',
29961
+ 0xFCC0: '\u0641\u062e',
29962
+ 0xFCC1: '\u0641\u0645',
29963
+ 0xFCC2: '\u0642\u062d',
29964
+ 0xFCC3: '\u0642\u0645',
29965
+ 0xFCC4: '\u0643\u062c',
29966
+ 0xFCC5: '\u0643\u062d',
29967
+ 0xFCC6: '\u0643\u062e',
29968
+ 0xFCC7: '\u0643\u0644',
29969
+ 0xFCC8: '\u0643\u0645',
29970
+ 0xFCC9: '\u0644\u062c',
29971
+ 0xFCCA: '\u0644\u062d',
29972
+ 0xFCCB: '\u0644\u062e',
29973
+ 0xFCCC: '\u0644\u0645',
29974
+ 0xFCCD: '\u0644\u0647',
29975
+ 0xFCCE: '\u0645\u062c',
29976
+ 0xFCCF: '\u0645\u062d',
29977
+ 0xFCD0: '\u0645\u062e',
29978
+ 0xFCD1: '\u0645\u0645',
29979
+ 0xFCD2: '\u0646\u062c',
29980
+ 0xFCD3: '\u0646\u062d',
29981
+ 0xFCD4: '\u0646\u062e',
29982
+ 0xFCD5: '\u0646\u0645',
29983
+ 0xFCD6: '\u0646\u0647',
29984
+ 0xFCD7: '\u0647\u062c',
29985
+ 0xFCD8: '\u0647\u0645',
29986
+ 0xFCD9: '\u0647\u0670',
29987
+ 0xFCDA: '\u064a\u062c',
29988
+ 0xFCDB: '\u064a\u062d',
29989
+ 0xFCDC: '\u064a\u062e',
29990
+ 0xFCDD: '\u064a\u0645',
29991
+ 0xFCDE: '\u064a\u0647',
29992
+ 0xFCDF: '\u0626\u0645',
29993
+ 0xFCE0: '\u0626\u0647',
29994
+ 0xFCE1: '\u0628\u0645',
29995
+ 0xFCE2: '\u0628\u0647',
29996
+ 0xFCE3: '\u062a\u0645',
29997
+ 0xFCE4: '\u062a\u0647',
29998
+ 0xFCE5: '\u062b\u0645',
29999
+ 0xFCE6: '\u062b\u0647',
30000
+ 0xFCE7: '\u0633\u0645',
30001
+ 0xFCE8: '\u0633\u0647',
30002
+ 0xFCE9: '\u0634\u0645',
30003
+ 0xFCEA: '\u0634\u0647',
30004
+ 0xFCEB: '\u0643\u0644',
30005
+ 0xFCEC: '\u0643\u0645',
30006
+ 0xFCED: '\u0644\u0645',
30007
+ 0xFCEE: '\u0646\u0645',
30008
+ 0xFCEF: '\u0646\u0647',
30009
+ 0xFCF0: '\u064a\u0645',
30010
+ 0xFCF1: '\u064a\u0647',
30011
+ 0xFCF2: '\u0640\u064e\u0651',
30012
+ 0xFCF3: '\u0640\u064f\u0651',
30013
+ 0xFCF4: '\u0640\u0650\u0651',
30014
+ 0xFCF5: '\u0637\u0649',
30015
+ 0xFCF6: '\u0637\u064a',
30016
+ 0xFCF7: '\u0639\u0649',
30017
+ 0xFCF8: '\u0639\u064a',
30018
+ 0xFCF9: '\u063a\u0649',
30019
+ 0xFCFA: '\u063a\u064a',
30020
+ 0xFCFB: '\u0633\u0649',
30021
+ 0xFCFC: '\u0633\u064a',
30022
+ 0xFCFD: '\u0634\u0649',
30023
+ 0xFCFE: '\u0634\u064a',
30024
+ 0xFCFF: '\u062d\u0649',
30025
+ 0xFD00: '\u062d\u064a',
30026
+ 0xFD01: '\u062c\u0649',
30027
+ 0xFD02: '\u062c\u064a',
30028
+ 0xFD03: '\u062e\u0649',
30029
+ 0xFD04: '\u062e\u064a',
30030
+ 0xFD05: '\u0635\u0649',
30031
+ 0xFD06: '\u0635\u064a',
30032
+ 0xFD07: '\u0636\u0649',
30033
+ 0xFD08: '\u0636\u064a',
30034
+ 0xFD09: '\u0634\u062c',
30035
+ 0xFD0A: '\u0634\u062d',
30036
+ 0xFD0B: '\u0634\u062e',
30037
+ 0xFD0C: '\u0634\u0645',
30038
+ 0xFD0D: '\u0634\u0631',
30039
+ 0xFD0E: '\u0633\u0631',
30040
+ 0xFD0F: '\u0635\u0631',
30041
+ 0xFD10: '\u0636\u0631',
30042
+ 0xFD11: '\u0637\u0649',
30043
+ 0xFD12: '\u0637\u064a',
30044
+ 0xFD13: '\u0639\u0649',
30045
+ 0xFD14: '\u0639\u064a',
30046
+ 0xFD15: '\u063a\u0649',
30047
+ 0xFD16: '\u063a\u064a',
30048
+ 0xFD17: '\u0633\u0649',
30049
+ 0xFD18: '\u0633\u064a',
30050
+ 0xFD19: '\u0634\u0649',
30051
+ 0xFD1A: '\u0634\u064a',
30052
+ 0xFD1B: '\u062d\u0649',
30053
+ 0xFD1C: '\u062d\u064a',
30054
+ 0xFD1D: '\u062c\u0649',
30055
+ 0xFD1E: '\u062c\u064a',
30056
+ 0xFD1F: '\u062e\u0649',
30057
+ 0xFD20: '\u062e\u064a',
30058
+ 0xFD21: '\u0635\u0649',
30059
+ 0xFD22: '\u0635\u064a',
30060
+ 0xFD23: '\u0636\u0649',
30061
+ 0xFD24: '\u0636\u064a',
30062
+ 0xFD25: '\u0634\u062c',
30063
+ 0xFD26: '\u0634\u062d',
30064
+ 0xFD27: '\u0634\u062e',
30065
+ 0xFD28: '\u0634\u0645',
30066
+ 0xFD29: '\u0634\u0631',
30067
+ 0xFD2A: '\u0633\u0631',
30068
+ 0xFD2B: '\u0635\u0631',
30069
+ 0xFD2C: '\u0636\u0631',
30070
+ 0xFD2D: '\u0634\u062c',
30071
+ 0xFD2E: '\u0634\u062d',
30072
+ 0xFD2F: '\u0634\u062e',
30073
+ 0xFD30: '\u0634\u0645',
30074
+ 0xFD31: '\u0633\u0647',
30075
+ 0xFD32: '\u0634\u0647',
30076
+ 0xFD33: '\u0637\u0645',
30077
+ 0xFD34: '\u0633\u062c',
30078
+ 0xFD35: '\u0633\u062d',
30079
+ 0xFD36: '\u0633\u062e',
30080
+ 0xFD37: '\u0634\u062c',
30081
+ 0xFD38: '\u0634\u062d',
30082
+ 0xFD39: '\u0634\u062e',
30083
+ 0xFD3A: '\u0637\u0645',
30084
+ 0xFD3B: '\u0638\u0645',
30085
+ 0xFD3C: '\u0627\u064b',
30086
+ 0xFD3D: '\u0627\u064b',
30087
+ 0xFD50: '\u062a\u062c\u0645',
30088
+ 0xFD51: '\u062a\u062d\u062c',
30089
+ 0xFD52: '\u062a\u062d\u062c',
30090
+ 0xFD53: '\u062a\u062d\u0645',
30091
+ 0xFD54: '\u062a\u062e\u0645',
30092
+ 0xFD55: '\u062a\u0645\u062c',
30093
+ 0xFD56: '\u062a\u0645\u062d',
30094
+ 0xFD57: '\u062a\u0645\u062e',
30095
+ 0xFD58: '\u062c\u0645\u062d',
30096
+ 0xFD59: '\u062c\u0645\u062d',
30097
+ 0xFD5A: '\u062d\u0645\u064a',
30098
+ 0xFD5B: '\u062d\u0645\u0649',
30099
+ 0xFD5C: '\u0633\u062d\u062c',
30100
+ 0xFD5D: '\u0633\u062c\u062d',
30101
+ 0xFD5E: '\u0633\u062c\u0649',
30102
+ 0xFD5F: '\u0633\u0645\u062d',
30103
+ 0xFD60: '\u0633\u0645\u062d',
30104
+ 0xFD61: '\u0633\u0645\u062c',
30105
+ 0xFD62: '\u0633\u0645\u0645',
30106
+ 0xFD63: '\u0633\u0645\u0645',
30107
+ 0xFD64: '\u0635\u062d\u062d',
30108
+ 0xFD65: '\u0635\u062d\u062d',
30109
+ 0xFD66: '\u0635\u0645\u0645',
30110
+ 0xFD67: '\u0634\u062d\u0645',
30111
+ 0xFD68: '\u0634\u062d\u0645',
30112
+ 0xFD69: '\u0634\u062c\u064a',
30113
+ 0xFD6A: '\u0634\u0645\u062e',
30114
+ 0xFD6B: '\u0634\u0645\u062e',
30115
+ 0xFD6C: '\u0634\u0645\u0645',
30116
+ 0xFD6D: '\u0634\u0645\u0645',
30117
+ 0xFD6E: '\u0636\u062d\u0649',
30118
+ 0xFD6F: '\u0636\u062e\u0645',
30119
+ 0xFD70: '\u0636\u062e\u0645',
30120
+ 0xFD71: '\u0637\u0645\u062d',
30121
+ 0xFD72: '\u0637\u0645\u062d',
30122
+ 0xFD73: '\u0637\u0645\u0645',
30123
+ 0xFD74: '\u0637\u0645\u064a',
30124
+ 0xFD75: '\u0639\u062c\u0645',
30125
+ 0xFD76: '\u0639\u0645\u0645',
30126
+ 0xFD77: '\u0639\u0645\u0645',
30127
+ 0xFD78: '\u0639\u0645\u0649',
30128
+ 0xFD79: '\u063a\u0645\u0645',
30129
+ 0xFD7A: '\u063a\u0645\u064a',
30130
+ 0xFD7B: '\u063a\u0645\u0649',
30131
+ 0xFD7C: '\u0641\u062e\u0645',
30132
+ 0xFD7D: '\u0641\u062e\u0645',
30133
+ 0xFD7E: '\u0642\u0645\u062d',
30134
+ 0xFD7F: '\u0642\u0645\u0645',
30135
+ 0xFD80: '\u0644\u062d\u0645',
30136
+ 0xFD81: '\u0644\u062d\u064a',
30137
+ 0xFD82: '\u0644\u062d\u0649',
30138
+ 0xFD83: '\u0644\u062c\u062c',
30139
+ 0xFD84: '\u0644\u062c\u062c',
30140
+ 0xFD85: '\u0644\u062e\u0645',
30141
+ 0xFD86: '\u0644\u062e\u0645',
30142
+ 0xFD87: '\u0644\u0645\u062d',
30143
+ 0xFD88: '\u0644\u0645\u062d',
30144
+ 0xFD89: '\u0645\u062d\u062c',
30145
+ 0xFD8A: '\u0645\u062d\u0645',
30146
+ 0xFD8B: '\u0645\u062d\u064a',
30147
+ 0xFD8C: '\u0645\u062c\u062d',
30148
+ 0xFD8D: '\u0645\u062c\u0645',
30149
+ 0xFD8E: '\u0645\u062e\u062c',
30150
+ 0xFD8F: '\u0645\u062e\u0645',
30151
+ 0xFD92: '\u0645\u062c\u062e',
30152
+ 0xFD93: '\u0647\u0645\u062c',
30153
+ 0xFD94: '\u0647\u0645\u0645',
30154
+ 0xFD95: '\u0646\u062d\u0645',
30155
+ 0xFD96: '\u0646\u062d\u0649',
30156
+ 0xFD97: '\u0646\u062c\u0645',
30157
+ 0xFD98: '\u0646\u062c\u0645',
30158
+ 0xFD99: '\u0646\u062c\u0649',
30159
+ 0xFD9A: '\u0646\u0645\u064a',
30160
+ 0xFD9B: '\u0646\u0645\u0649',
30161
+ 0xFD9C: '\u064a\u0645\u0645',
30162
+ 0xFD9D: '\u064a\u0645\u0645',
30163
+ 0xFD9E: '\u0628\u062e\u064a',
30164
+ 0xFD9F: '\u062a\u062c\u064a',
30165
+ 0xFDA0: '\u062a\u062c\u0649',
30166
+ 0xFDA1: '\u062a\u062e\u064a',
30167
+ 0xFDA2: '\u062a\u062e\u0649',
30168
+ 0xFDA3: '\u062a\u0645\u064a',
30169
+ 0xFDA4: '\u062a\u0645\u0649',
30170
+ 0xFDA5: '\u062c\u0645\u064a',
30171
+ 0xFDA6: '\u062c\u062d\u0649',
30172
+ 0xFDA7: '\u062c\u0645\u0649',
30173
+ 0xFDA8: '\u0633\u062e\u0649',
30174
+ 0xFDA9: '\u0635\u062d\u064a',
30175
+ 0xFDAA: '\u0634\u062d\u064a',
30176
+ 0xFDAB: '\u0636\u062d\u064a',
30177
+ 0xFDAC: '\u0644\u062c\u064a',
30178
+ 0xFDAD: '\u0644\u0645\u064a',
30179
+ 0xFDAE: '\u064a\u062d\u064a',
30180
+ 0xFDAF: '\u064a\u062c\u064a',
30181
+ 0xFDB0: '\u064a\u0645\u064a',
30182
+ 0xFDB1: '\u0645\u0645\u064a',
30183
+ 0xFDB2: '\u0642\u0645\u064a',
30184
+ 0xFDB3: '\u0646\u062d\u064a',
30185
+ 0xFDB4: '\u0642\u0645\u062d',
30186
+ 0xFDB5: '\u0644\u062d\u0645',
30187
+ 0xFDB6: '\u0639\u0645\u064a',
30188
+ 0xFDB7: '\u0643\u0645\u064a',
30189
+ 0xFDB8: '\u0646\u062c\u062d',
30190
+ 0xFDB9: '\u0645\u062e\u064a',
30191
+ 0xFDBA: '\u0644\u062c\u0645',
30192
+ 0xFDBB: '\u0643\u0645\u0645',
30193
+ 0xFDBC: '\u0644\u062c\u0645',
30194
+ 0xFDBD: '\u0646\u062c\u062d',
30195
+ 0xFDBE: '\u062c\u062d\u064a',
30196
+ 0xFDBF: '\u062d\u062c\u064a',
30197
+ 0xFDC0: '\u0645\u062c\u064a',
30198
+ 0xFDC1: '\u0641\u0645\u064a',
30199
+ 0xFDC2: '\u0628\u062d\u064a',
30200
+ 0xFDC3: '\u0643\u0645\u0645',
30201
+ 0xFDC4: '\u0639\u062c\u0645',
30202
+ 0xFDC5: '\u0635\u0645\u0645',
30203
+ 0xFDC6: '\u0633\u062e\u064a',
30204
+ 0xFDC7: '\u0646\u062c\u064a',
30205
+ 0xFDF0: '\u0635\u0644\u06d2',
30206
+ 0xFDF1: '\u0642\u0644\u06d2',
30207
+ 0xFDF2: '\u0627\u0644\u0644\u0647',
30208
+ 0xFDF3: '\u0627\u0643\u0628\u0631',
30209
+ 0xFDF4: '\u0645\u062d\u0645\u062f',
30210
+ 0xFDF5: '\u0635\u0644\u0639\u0645',
30211
+ 0xFDF6: '\u0631\u0633\u0648\u0644',
30212
+ 0xFDF7: '\u0639\u0644\u064a\u0647',
30213
+ 0xFDF8: '\u0648\u0633\u0644\u0645',
30214
+ 0xFDF9: '\u0635\u0644\u0649',
30215
+ 0xFDFA: '\u0635\u0644\u0649\u0627\u0644\u0644\u0647\u0639\u0644\u064a\u0647\u0648\u0633\u0644\u0645',
30216
+ 0xFDFB: '\u062c\u0644\u062c\u0644\u0627\u0644\u0647',
30217
+ 0xFDFC: '\u0631\u06cc\u0627\u0644',
30218
+ 0xFE70: '\u064b',
30219
+ 0xFE71: '\u0640\u064b',
30220
+ 0xFE72: '\u064c',
30221
+ 0xFE74: '\u064d',
30222
+ 0xFE76: '\u064e',
30223
+ 0xFE77: '\u0640\u064e',
30224
+ 0xFE78: '\u064f',
30225
+ 0xFE79: '\u0640\u064f',
30226
+ 0xFE7A: '\u0650',
30227
+ 0xFE7B: '\u0640\u0650',
30228
+ 0xFE7C: '\u0651',
30229
+ 0xFE7D: '\u0640\u0651',
30230
+ 0xFE7E: '\u0652',
30231
+ 0xFE7F: '\u0640\u0652',
30232
+ 0xFE80: '\u0621',
30233
+ 0xFE81: '\u0622',
30234
+ 0xFE82: '\u0622',
30235
+ 0xFE83: '\u0623',
30236
+ 0xFE84: '\u0623',
30237
+ 0xFE85: '\u0624',
30238
+ 0xFE86: '\u0624',
30239
+ 0xFE87: '\u0625',
30240
+ 0xFE88: '\u0625',
30241
+ 0xFE89: '\u0626',
30242
+ 0xFE8A: '\u0626',
30243
+ 0xFE8B: '\u0626',
30244
+ 0xFE8C: '\u0626',
30245
+ 0xFE8D: '\u0627',
30246
+ 0xFE8E: '\u0627',
30247
+ 0xFE8F: '\u0628',
30248
+ 0xFE90: '\u0628',
30249
+ 0xFE91: '\u0628',
30250
+ 0xFE92: '\u0628',
30251
+ 0xFE93: '\u0629',
30252
+ 0xFE94: '\u0629',
30253
+ 0xFE95: '\u062a',
30254
+ 0xFE96: '\u062a',
30255
+ 0xFE97: '\u062a',
30256
+ 0xFE98: '\u062a',
30257
+ 0xFE99: '\u062b',
30258
+ 0xFE9A: '\u062b',
30259
+ 0xFE9B: '\u062b',
30260
+ 0xFE9C: '\u062b',
30261
+ 0xFE9D: '\u062c',
30262
+ 0xFE9E: '\u062c',
30263
+ 0xFE9F: '\u062c',
30264
+ 0xFEA0: '\u062c',
30265
+ 0xFEA1: '\u062d',
30266
+ 0xFEA2: '\u062d',
30267
+ 0xFEA3: '\u062d',
30268
+ 0xFEA4: '\u062d',
30269
+ 0xFEA5: '\u062e',
30270
+ 0xFEA6: '\u062e',
30271
+ 0xFEA7: '\u062e',
30272
+ 0xFEA8: '\u062e',
30273
+ 0xFEA9: '\u062f',
30274
+ 0xFEAA: '\u062f',
30275
+ 0xFEAB: '\u0630',
30276
+ 0xFEAC: '\u0630',
30277
+ 0xFEAD: '\u0631',
30278
+ 0xFEAE: '\u0631',
30279
+ 0xFEAF: '\u0632',
30280
+ 0xFEB0: '\u0632',
30281
+ 0xFEB1: '\u0633',
30282
+ 0xFEB2: '\u0633',
30283
+ 0xFEB3: '\u0633',
30284
+ 0xFEB4: '\u0633',
30285
+ 0xFEB5: '\u0634',
30286
+ 0xFEB6: '\u0634',
30287
+ 0xFEB7: '\u0634',
30288
+ 0xFEB8: '\u0634',
30289
+ 0xFEB9: '\u0635',
30290
+ 0xFEBA: '\u0635',
30291
+ 0xFEBB: '\u0635',
30292
+ 0xFEBC: '\u0635',
30293
+ 0xFEBD: '\u0636',
30294
+ 0xFEBE: '\u0636',
30295
+ 0xFEBF: '\u0636',
30296
+ 0xFEC0: '\u0636',
30297
+ 0xFEC1: '\u0637',
30298
+ 0xFEC2: '\u0637',
30299
+ 0xFEC3: '\u0637',
30300
+ 0xFEC4: '\u0637',
30301
+ 0xFEC5: '\u0638',
30302
+ 0xFEC6: '\u0638',
30303
+ 0xFEC7: '\u0638',
30304
+ 0xFEC8: '\u0638',
30305
+ 0xFEC9: '\u0639',
30306
+ 0xFECA: '\u0639',
30307
+ 0xFECB: '\u0639',
30308
+ 0xFECC: '\u0639',
30309
+ 0xFECD: '\u063a',
30310
+ 0xFECE: '\u063a',
30311
+ 0xFECF: '\u063a',
30312
+ 0xFED0: '\u063a',
30313
+ 0xFED1: '\u0641',
30314
+ 0xFED2: '\u0641',
30315
+ 0xFED3: '\u0641',
30316
+ 0xFED4: '\u0641',
30317
+ 0xFED5: '\u0642',
30318
+ 0xFED6: '\u0642',
30319
+ 0xFED7: '\u0642',
30320
+ 0xFED8: '\u0642',
30321
+ 0xFED9: '\u0643',
30322
+ 0xFEDA: '\u0643',
30323
+ 0xFEDB: '\u0643',
30324
+ 0xFEDC: '\u0643',
30325
+ 0xFEDD: '\u0644',
30326
+ 0xFEDE: '\u0644',
30327
+ 0xFEDF: '\u0644',
30328
+ 0xFEE0: '\u0644',
30329
+ 0xFEE1: '\u0645',
30330
+ 0xFEE2: '\u0645',
30331
+ 0xFEE3: '\u0645',
30332
+ 0xFEE4: '\u0645',
30333
+ 0xFEE5: '\u0646',
30334
+ 0xFEE6: '\u0646',
30335
+ 0xFEE7: '\u0646',
30336
+ 0xFEE8: '\u0646',
30337
+ 0xFEE9: '\u0647',
30338
+ 0xFEEA: '\u0647',
30339
+ 0xFEEB: '\u0647',
30340
+ 0xFEEC: '\u0647',
30341
+ 0xFEED: '\u0648',
30342
+ 0xFEEE: '\u0648',
30343
+ 0xFEEF: '\u0649',
30344
+ 0xFEF0: '\u0649',
30345
+ 0xFEF1: '\u064a',
30346
+ 0xFEF2: '\u064a',
30347
+ 0xFEF3: '\u064a',
30348
+ 0xFEF4: '\u064a',
30349
+ 0xFEF5: '\u0644\u0622',
30350
+ 0xFEF6: '\u0644\u0622',
30351
+ 0xFEF7: '\u0644\u0623',
30352
+ 0xFEF8: '\u0644\u0623',
30353
+ 0xFEF9: '\u0644\u0625',
30354
+ 0xFEFA: '\u0644\u0625',
30355
+ 0xFEFB: '\u0644\u0627',
30356
+ 0xFEFC: '\u0644\u0627'
30357
+ };
30358
+
28974
30359
  /**
28975
30360
  * Represents the structure element of the PDF document.
28976
30361
  * ```typescript
@@ -30159,6 +31544,7 @@ class PdfDataExtractor {
30159
31544
  this._processPages(startIndex, endIndex);
30160
31545
  if (this._resultantText.length) {
30161
31546
  this._resultantText = _ignoreEscapeSequence(this._resultantText);
31547
+ this._resultantText = this._buildRtlReadingText(startIndex, endIndex, this._resultantText);
30162
31548
  }
30163
31549
  this._isLayout = false;
30164
31550
  return this._resultantText;
@@ -30184,6 +31570,7 @@ class PdfDataExtractor {
30184
31570
  yield this._processPdfPages(startIndex, endIndex);
30185
31571
  if (this._resultantText.length) {
30186
31572
  this._resultantText = _ignoreEscapeSequence(this._resultantText);
31573
+ this._resultantText = yield this._buildRtlReadingTextAsync(startIndex, endIndex, this._resultantText);
30187
31574
  }
30188
31575
  this._isLayout = false;
30189
31576
  return this._resultantText;
@@ -31541,6 +32928,7 @@ class PdfDataExtractor {
31541
32928
  this._textLine = [];
31542
32929
  this._processPages(startIndex, endIndex);
31543
32930
  this._isExtractTextLines = false;
32931
+ this._normalizeTextLines(this._textLine);
31544
32932
  return this._textLine;
31545
32933
  }
31546
32934
  extractTextLines(options) {
@@ -31559,6 +32947,7 @@ class PdfDataExtractor {
31559
32947
  this._textLine = [];
31560
32948
  yield this._processPdfPages(startIndex, endIndex);
31561
32949
  this._isExtractTextLines = false;
32950
+ this._normalizeTextLines(this._textLine);
31562
32951
  return this._textLine;
31563
32952
  });
31564
32953
  }
@@ -31637,6 +33026,303 @@ class PdfDataExtractor {
31637
33026
  }
31638
33027
  return textSearchResults[0];
31639
33028
  }
33029
+ /**
33030
+ * Rebuilds the plain-text extraction result in logical RTL reading order.
33031
+ * Non-RTL documents keep the existing flat text. RTL documents are rebuilt
33032
+ * from the line pipeline so rows are read top-to-bottom and RTL rows are
33033
+ * emitted right-to-left, matching Adobe extraction order.
33034
+ *
33035
+ * @private
33036
+ * @param {number} startIndex - Start page index of the extraction.
33037
+ * @param {number} endIndex - End page index of the extraction.
33038
+ * @param {string} flatText - Flat extracted text in stream order.
33039
+ * @returns {string} Reading-order text for RTL documents, otherwise flatText.
33040
+ */
33041
+ _buildRtlReadingText(startIndex, endIndex, flatText) {
33042
+ if (!_containsRtlCharacter(flatText)) {
33043
+ return flatText;
33044
+ }
33045
+ const textLines = this.extractTextLinesSync({ startPageIndex: startIndex, endPageIndex: endIndex });
33046
+ if (!textLines || textLines.length === 0) {
33047
+ return _normalizeRtlText(flatText);
33048
+ }
33049
+ let result = '';
33050
+ for (let i = 0; i < textLines.length; i++) {
33051
+ const textLine = textLines[Number.parseInt(i.toString(), 10)];
33052
+ result += textLine._text;
33053
+ if (i < textLines.length - 1) {
33054
+ result += '\r\n';
33055
+ }
33056
+ }
33057
+ return result;
33058
+ }
33059
+ /**
33060
+ * Asynchronous variant of `_buildRtlReadingText`.
33061
+ *
33062
+ * @private
33063
+ * @param {number} startIndex - Start page index of the extraction.
33064
+ * @param {number} endIndex - End page index of the extraction.
33065
+ * @param {string} flatText - Flat extracted text in stream order.
33066
+ * @returns {Promise<string>} Reading-order text for RTL documents, otherwise flatText.
33067
+ */
33068
+ _buildRtlReadingTextAsync(startIndex, endIndex, flatText) {
33069
+ return __awaiter$8(this, void 0, void 0, function* () {
33070
+ if (!_containsRtlCharacter(flatText)) {
33071
+ return flatText;
33072
+ }
33073
+ const textLines = yield this.extractTextLines({ startPageIndex: startIndex, endPageIndex: endIndex });
33074
+ if (!textLines || textLines.length === 0) {
33075
+ return _normalizeRtlText(flatText);
33076
+ }
33077
+ let result = '';
33078
+ for (let i = 0; i < textLines.length; i++) {
33079
+ const textLine = textLines[Number.parseInt(i.toString(), 10)];
33080
+ result += textLine._text;
33081
+ if (i < textLines.length - 1) {
33082
+ result += '\r\n';
33083
+ }
33084
+ }
33085
+ return result;
33086
+ });
33087
+ }
33088
+ _normalizeTextLines(textLines) {
33089
+ if (!textLines || textLines.length === 0) {
33090
+ return;
33091
+ }
33092
+ const fragments = [];
33093
+ for (let i = 0; i < textLines.length; i++) {
33094
+ const textLine = textLines[Number.parseInt(i.toString(), 10)];
33095
+ if (textLine && textLine._text && textLine._bounds) {
33096
+ fragments.push({ text: textLine._text, bounds: textLine._bounds });
33097
+ }
33098
+ }
33099
+ const rowOrder = [];
33100
+ if (fragments.length === textLines.length) {
33101
+ const ordered = _reorderFragmentsForRtlReading(fragments);
33102
+ const consumed = new Array(textLines.length).fill(false);
33103
+ for (let f = 0; f < ordered.length; f++) {
33104
+ const fragment = ordered[Number.parseInt(f.toString(), 10)];
33105
+ for (let i = 0; i < textLines.length; i++) {
33106
+ if (consumed[Number.parseInt(i.toString(), 10)]) {
33107
+ continue;
33108
+ }
33109
+ const textLine = textLines[Number.parseInt(i.toString(), 10)];
33110
+ if (textLine._text === fragment.text && textLine._bounds === fragment.bounds) {
33111
+ rowOrder.push(textLine);
33112
+ consumed[Number.parseInt(i.toString(), 10)] = true;
33113
+ break;
33114
+ }
33115
+ }
33116
+ }
33117
+ }
33118
+ const orderedLines = rowOrder.length === textLines.length ? rowOrder : textLines;
33119
+ for (let i = 0; i < orderedLines.length; i++) {
33120
+ const textLine = orderedLines[Number.parseInt(i.toString(), 10)];
33121
+ this._normalizeRtlTextLine(textLine);
33122
+ }
33123
+ const tolerance = this._getMergeRowTolerance(orderedLines);
33124
+ const mergedLines = [];
33125
+ for (let i = 0; i < orderedLines.length; i++) {
33126
+ const textLine = orderedLines[Number.parseInt(i.toString(), 10)];
33127
+ const previous = mergedLines.length > 0 ?
33128
+ mergedLines[Number.parseInt((mergedLines.length - 1).toString(), 10)] : null;
33129
+ const rowHasRtl = _containsRtlCharacter(previous ? previous._text : '') ||
33130
+ _containsRtlCharacter(textLine._text);
33131
+ if (previous && rowHasRtl && this._isSameRtlRowLine(previous._bounds, textLine._bounds, tolerance) &&
33132
+ this._isAdjacentWordGap(previous._bounds, textLine._bounds, tolerance)) {
33133
+ const needsSpace = previous._text.length > 0 && textLine._text.length > 0 &&
33134
+ previous._text[Number.parseInt((previous._text.length - 1).toString(), 10)] !== ' ' &&
33135
+ textLine._text[0] !== ' ';
33136
+ previous._text += (needsSpace ? ' ' : '') + textLine._text;
33137
+ if (textLine._wordCollection) {
33138
+ for (let j = 0; j < textLine._wordCollection.length; j++) {
33139
+ previous._wordCollection.push(textLine._wordCollection[Number.parseInt(j.toString(), 10)]);
33140
+ }
33141
+ }
33142
+ previous._bounds = this._getMergedBounds(previous._bounds, textLine._bounds);
33143
+ }
33144
+ else {
33145
+ mergedLines.push(textLine);
33146
+ }
33147
+ }
33148
+ if (mergedLines.length !== textLines.length) {
33149
+ for (let i = 0; i < mergedLines.length; i++) {
33150
+ textLines[Number.parseInt(i.toString(), 10)] = mergedLines[Number.parseInt(i.toString(), 10)];
33151
+ }
33152
+ textLines.length = mergedLines.length;
33153
+ }
33154
+ }
33155
+ /**
33156
+ * Computes the vertical tolerance used to decide whether two text lines
33157
+ * share the same baseline (fraction of the dominant line height).
33158
+ *
33159
+ * @private
33160
+ * @param {TextLine[]} textLines - Lines being merged.
33161
+ * @returns {number} Row-grouping tolerance in page units.
33162
+ */
33163
+ _getMergeRowTolerance(textLines) {
33164
+ let totalHeight = 0;
33165
+ let count = 0;
33166
+ for (let i = 0; i < textLines.length; i++) {
33167
+ const textLine = textLines[Number.parseInt(i.toString(), 10)];
33168
+ if (textLine && textLine._bounds && textLine._bounds.height > 0) {
33169
+ totalHeight += textLine._bounds.height;
33170
+ count++;
33171
+ }
33172
+ }
33173
+ if (count === 0) {
33174
+ return 2;
33175
+ }
33176
+ return Math.max(2, (totalHeight / count) * 0.5);
33177
+ }
33178
+ /**
33179
+ * Determines whether two line bounds share the same baseline row.
33180
+ *
33181
+ * @private
33182
+ * @param {Rectangle} first - First line bounds.
33183
+ * @param {Rectangle} second - Second line bounds.
33184
+ * @param {number} tolerance - Vertical tolerance for row grouping.
33185
+ * @returns {boolean} True when both lines are on the same baseline row.
33186
+ */
33187
+ _isSameRtlRowLine(first, second, tolerance) {
33188
+ if (!first || !second) {
33189
+ return false;
33190
+ }
33191
+ const firstCenter = first.y + first.height / 2;
33192
+ const secondCenter = second.y + second.height / 2;
33193
+ return Math.abs(firstCenter - secondCenter) <= tolerance;
33194
+ }
33195
+ /**
33196
+ * Determines whether the horizontal gap between two same-baseline lines is
33197
+ * small enough to treat them as words of the same visual line. Large gaps
33198
+ * (columns, tab-separated figures) are kept as separate lines.
33199
+ *
33200
+ * @private
33201
+ * @param {Rectangle} previous - Bounds of the already merged line.
33202
+ * @param {Rectangle} current - Bounds of the candidate line to merge.
33203
+ * @param {number} tolerance - Row tolerance used as the gap scale.
33204
+ * @returns {boolean} True when the gap indicates words of one visual line.
33205
+ */
33206
+ _isAdjacentWordGap(previous, current, tolerance) {
33207
+ if (!previous || !current) {
33208
+ return false;
33209
+ }
33210
+ const gap = Math.max(previous.x - (current.x + current.width), current.x - (previous.x + previous.width));
33211
+ return gap < Math.max(24, tolerance * 8);
33212
+ }
33213
+ /**
33214
+ * Computes the union of two line bounds.
33215
+ *
33216
+ * @private
33217
+ * @param {Rectangle} first - First line bounds.
33218
+ * @param {Rectangle} second - Second line bounds.
33219
+ * @returns {Rectangle} Union bounds covering both lines.
33220
+ */
33221
+ _getMergedBounds(first, second) {
33222
+ if (!first) {
33223
+ return second;
33224
+ }
33225
+ if (!second) {
33226
+ return first;
33227
+ }
33228
+ const x = Math.min(first.x, second.x);
33229
+ const y = Math.min(first.y, second.y);
33230
+ return {
33231
+ x: x,
33232
+ y: y,
33233
+ width: Math.max(first.x + first.width, second.x + second.width) - x,
33234
+ height: Math.max(first.y + first.height, second.y + second.height) - y
33235
+ };
33236
+ }
33237
+ /**
33238
+ * Normalizes a single text line (and its words) from visual RTL order into
33239
+ * logical reading order, sorting RTL words right-to-left by position when
33240
+ * the line advances leftward.
33241
+ *
33242
+ * @private
33243
+ * @param {TextLine} textLine - Line to normalize.
33244
+ * @returns {void}
33245
+ */
33246
+ _normalizeRtlTextLine(textLine) {
33247
+ const words = textLine._wordCollection;
33248
+ if (!textLine._text || !_containsRtlCharacter(textLine._text)) {
33249
+ return;
33250
+ }
33251
+ const isVisualOrder = _containsArabicPresentationForm(textLine._text) ||
33252
+ this._isLineAdvancingLeftward(words);
33253
+ let changed = false;
33254
+ if (words && words.length > 1 && isVisualOrder) {
33255
+ const orderedWords = words.slice().sort((a, b) => b._bounds.x - a._bounds.x);
33256
+ for (let j = 0; j < orderedWords.length; j++) {
33257
+ if (orderedWords[Number.parseInt(j.toString(), 10)] !== words[Number.parseInt(j.toString(), 10)]) {
33258
+ changed = true;
33259
+ break;
33260
+ }
33261
+ }
33262
+ if (changed) {
33263
+ for (let j = 0; j < orderedWords.length; j++) {
33264
+ words[Number.parseInt(j.toString(), 10)] = orderedWords[Number.parseInt(j.toString(), 10)];
33265
+ }
33266
+ }
33267
+ }
33268
+ for (let j = 0; j < (words ? words.length : 0); j++) {
33269
+ const textWord = words[Number.parseInt(j.toString(), 10)];
33270
+ if (!textWord || !textWord._text) {
33271
+ continue;
33272
+ }
33273
+ if (_containsRtlCharacter(textWord._text)) {
33274
+ textWord._text = _normalizeRtlText(textWord._text);
33275
+ }
33276
+ else if (isVisualOrder) {
33277
+ textWord._text = _invertVisualLtrFragment(textWord._text);
33278
+ }
33279
+ }
33280
+ if (changed) {
33281
+ let rebuilt = '';
33282
+ for (let j = 0; j < words.length; j++) {
33283
+ rebuilt += words[Number.parseInt(j.toString(), 10)]._text;
33284
+ }
33285
+ textLine._text = rebuilt;
33286
+ }
33287
+ else if (isVisualOrder) {
33288
+ textLine._text = _normalizeRtlText(textLine._text);
33289
+ }
33290
+ else {
33291
+ textLine._text = _mapArabicPresentationForms(textLine._text);
33292
+ }
33293
+ if (isVisualOrder) {
33294
+ textLine._text = _resolveMirroredBrackets(textLine._text);
33295
+ }
33296
+ }
33297
+ /**
33298
+ * Determines whether the words of a line advance leftward (visual RTL order)
33299
+ * by comparing the bounds of consecutive words.
33300
+ *
33301
+ * @private
33302
+ * @param {TextWord[]} words - Line words in stream order.
33303
+ * @returns {boolean} True when consecutive words are placed right-to-left.
33304
+ */
33305
+ _isLineAdvancingLeftward(words) {
33306
+ if (!words || words.length < 2) {
33307
+ return false;
33308
+ }
33309
+ let rightward = 0;
33310
+ let leftward = 0;
33311
+ for (let i = 1; i < words.length; i++) {
33312
+ const previous = words[Number.parseInt((i - 1).toString(), 10)];
33313
+ const current = words[Number.parseInt(i.toString(), 10)];
33314
+ if (!previous._bounds || !current._bounds) {
33315
+ continue;
33316
+ }
33317
+ if (_isVisualOrderRtl(previous._bounds, current._bounds)) {
33318
+ rightward++;
33319
+ }
33320
+ else if (current._bounds.x < previous._bounds.x) {
33321
+ leftward++;
33322
+ }
33323
+ }
33324
+ return leftward === 0 && rightward > 0;
33325
+ }
31640
33326
  /**
31641
33327
  * Coordinates document-wide text search and returns the search results for all supplied search strings.
31642
33328
  *
@@ -31704,7 +33390,8 @@ class PdfDataExtractor {
31704
33390
  const page = this._document.getPage(pageIndex);
31705
33391
  for (let i = 0; i < searchTextCollection.length; i++) {
31706
33392
  const searchText = searchTextCollection[Number.parseInt(i.toString(), 10)];
31707
- const searchTextLower = options.caseSensitive ? searchText : searchText.toLowerCase();
33393
+ const normalizedSearchText = _normalizeSearchText(searchText);
33394
+ const searchTextLower = options.caseSensitive ? normalizedSearchText : normalizedSearchText.toLowerCase();
31708
33395
  searchTextLowerCollection.push(searchTextLower);
31709
33396
  boundsCollection.set(i, []);
31710
33397
  }
@@ -31735,6 +33422,7 @@ class PdfDataExtractor {
31735
33422
  }
31736
33423
  else {
31737
33424
  let startIndex = 0;
33425
+ const isRtlWord = _containsRtlCharacter(wordText);
31738
33426
  while (true) { // eslint-disable-line
31739
33427
  const matchIndex = wordText.indexOf(searchTextLower, startIndex);
31740
33428
  if (matchIndex === -1) {
@@ -31750,6 +33438,14 @@ class PdfDataExtractor {
31750
33438
  }
31751
33439
  charIndex++;
31752
33440
  }
33441
+ if (isRtlWord && glyphs.length === wordText.length) {
33442
+ matchGlyphs.length = 0;
33443
+ const glyphStart = glyphs.length - endIndex;
33444
+ const glyphEnd = glyphs.length - matchIndex;
33445
+ for (let i = glyphStart; i < glyphEnd; i++) {
33446
+ matchGlyphs.push(glyphs[Number.parseInt(i.toString(), 10)]);
33447
+ }
33448
+ }
31753
33449
  if (matchGlyphs.length > 0) {
31754
33450
  const pdfPath = new PdfPath();
31755
33451
  for (let i = 0; i < matchGlyphs.length; i++) {
@@ -32440,5 +34136,5 @@ class PdfDataExtractor {
32440
34136
  }
32441
34137
  }
32442
34138
 
32443
- export { ApplicationPlatform, PdfDataExtractor, PdfEmbeddedImage, PdfRedactionRegion, PdfRedactor, PdfStructureElement, PdfTagType, ScopeType, TextGlyph, TextLine, TextWord, _CompositeGlyph, _Contour, _FontHelper, _FontStructure, _Glyph, _GlyphHeader, _GraphicState, _ImageStructure, _MatrixHelper, _PdfAlternateCS, _PdfBaseColorSpace, _PdfBezierSegment, _PdfBinaryCMapStream, _PdfBinaryCharacterMapReader, _PdfCalGrayCS, _PdfCharacterMap, _PdfCharacterMapFactory, _PdfColorPalette, _PdfColorRgbConverter, _PdfColorSpaceUtils, _PdfCompactFont, _PdfCompactFontCharacterSet, _PdfCompactFontCompiler, _PdfCompactFontDictionary, _PdfCompactFontEncoding, _PdfCompactFontHeader, _PdfCompactFontIndex, _PdfCompactFontOffsetTracker, _PdfCompactFontParser, _PdfCompactFontPrivateDictionary, _PdfCompactFontSelect, _PdfCompactFontStrings, _PdfCompactFontTopDictionary, _PdfCompactFormatFont, _PdfContentParserHelper, _PdfDeviceCmykCS, _PdfDeviceGrayCS, _PdfDeviceRgbCS, _PdfDeviceRgbaCS, _PdfGlyph, _PdfGlyphTable, _PdfIccColorSpace, _PdfIdentityCharacterMap, _PdfImage, _PdfImageProcessor, _PdfImageResizer, _PdfIndexedCS, _PdfIntersection, _PdfJpegImage, _PdfJpxImage, _PdfLabCS, _PdfLineSegment, _PdfMetrics, _PdfOpenJpegRunner, _PdfPathFigure, _PdfPathSegment, _PdfPatternCS, _PdfPolygon, _PdfQcmsRunner, _PdfRedactionProcessor, _PdfShapeParser, _PdfTextParser, _PdfVertex, _SimpleGlyph, _TextGlyphMapper, _TextState, _TransformationStack, _addFontResources, _base64ToUint8Array, _convertBlackAndWhiteToRGBA, _convertRGBToRGBA, _convertToRGBA, _decodeEncodedText, _expertEncoding, _fetchXObject, _fontFlags, _fontTables, _getDingbatsGlyphsUnicode, _getEncoding, _getEncodingBase64String, _getFontBasicMetrics, _getFontEncodedString, _getFontGlyphMap, _getFontNameToFileMap, _getGlyphMapForStandardFonts, _getGlyphsUnicode, _getLiteralString, _getNonStdFontMap, _getSerifFonts, _getStdFontMap, _getSupplementalGlyphMapForArialBlack, _getSymbolsFonts, _getUnicodeForGlyph, _getXObject, _getXObjectResources, _glyphAnalysisEnabled, _grayToRGBA, _hexToChar, _ignoreEscapeSequence, _isArrayEqual, _macExpertEncoding, _macRomanEncoding, _parseEncodedText, _parseEscapedText, _recoverGlyphName, _skipEscapeSequence, _standardEncoding, _symbolSetEncoding, _winAnsiEncoding, _zapfDingbatsEncoding, imageKind, maximumCount };
34139
+ export { ApplicationPlatform, PdfDataExtractor, PdfEmbeddedImage, PdfRedactionRegion, PdfRedactor, PdfStructureElement, PdfTagType, ScopeType, TextGlyph, TextLine, TextWord, _CompositeGlyph, _Contour, _FontHelper, _FontStructure, _Glyph, _GlyphHeader, _GraphicState, _ImageStructure, _MatrixHelper, _PdfAlternateCS, _PdfBaseColorSpace, _PdfBezierSegment, _PdfBinaryCMapStream, _PdfBinaryCharacterMapReader, _PdfCalGrayCS, _PdfCharacterMap, _PdfCharacterMapFactory, _PdfColorPalette, _PdfColorRgbConverter, _PdfColorSpaceUtils, _PdfCompactFont, _PdfCompactFontCharacterSet, _PdfCompactFontCompiler, _PdfCompactFontDictionary, _PdfCompactFontEncoding, _PdfCompactFontHeader, _PdfCompactFontIndex, _PdfCompactFontOffsetTracker, _PdfCompactFontParser, _PdfCompactFontPrivateDictionary, _PdfCompactFontSelect, _PdfCompactFontStrings, _PdfCompactFontTopDictionary, _PdfCompactFormatFont, _PdfContentParserHelper, _PdfDeviceCmykCS, _PdfDeviceGrayCS, _PdfDeviceRgbCS, _PdfDeviceRgbaCS, _PdfGlyph, _PdfGlyphTable, _PdfIccColorSpace, _PdfIdentityCharacterMap, _PdfImage, _PdfImageProcessor, _PdfImageResizer, _PdfIndexedCS, _PdfIntersection, _PdfJpegImage, _PdfJpxImage, _PdfLabCS, _PdfLineSegment, _PdfMetrics, _PdfOpenJpegRunner, _PdfPathFigure, _PdfPathSegment, _PdfPatternCS, _PdfPolygon, _PdfQcmsRunner, _PdfRedactionProcessor, _PdfShapeParser, _PdfTextParser, _PdfVertex, _SimpleGlyph, _TextGlyphMapper, _TextState, _TransformationStack, _addFontResources, _base64ToUint8Array, _containsArabicPresentationForm, _containsRtlCharacter, _convertBlackAndWhiteToRGBA, _convertRGBToRGBA, _convertToRGBA, _convertVisualToLogicalOrder, _decodeEncodedText, _expertEncoding, _fetchXObject, _fontFlags, _fontTables, _getDingbatsGlyphsUnicode, _getEncoding, _getEncodingBase64String, _getFontBasicMetrics, _getFontEncodedString, _getFontGlyphMap, _getFontNameToFileMap, _getGlyphMapForStandardFonts, _getGlyphsUnicode, _getLiteralString, _getNonStdFontMap, _getSerifFonts, _getStdFontMap, _getSupplementalGlyphMapForArialBlack, _getSymbolsFonts, _getUnicodeForGlyph, _getXObject, _getXObjectResources, _glyphAnalysisEnabled, _grayToRGBA, _hexToChar, _ignoreEscapeSequence, _invertVisualLtrFragment, _isArabicPresentationForm, _isArrayEqual, _isLtrCharacter, _isNeutralCharacter, _isRtlCharacter, _isVisualOrderRtl, _macExpertEncoding, _macRomanEncoding, _mapArabicPresentationForms, _normalizeArabicCharacter, _normalizeRtlText, _normalizeSearchText, _parseEncodedText, _parseEscapedText, _recoverGlyphName, _reorderFragmentsForRtlReading, _resolveMirroredBrackets, _skipEscapeSequence, _standardEncoding, _symbolSetEncoding, _unmirrorPairedBrackets, _winAnsiEncoding, _zapfDingbatsEncoding, imageKind, maximumCount };
32444
34140
  //# sourceMappingURL=ej2-pdf-data-extract.es2015.js.map