pdfjs-dist 2.4.456 → 2.5.207

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.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (101) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +4447 -4379
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +8549 -8507
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/es5/build/pdf.js +14755 -14540
  9. package/es5/build/pdf.js.map +1 -1
  10. package/es5/build/pdf.worker.js +9830 -9469
  11. package/es5/build/pdf.worker.js.map +1 -1
  12. package/es5/web/pdf_viewer.css +5 -9
  13. package/es5/web/pdf_viewer.js +157 -172
  14. package/es5/web/pdf_viewer.js.map +1 -1
  15. package/image_decoders/pdf.image_decoders.js +107 -93
  16. package/image_decoders/pdf.image_decoders.js.map +1 -1
  17. package/image_decoders/pdf.image_decoders.min.js +1 -1
  18. package/lib/README.md +2 -2
  19. package/lib/core/ccitt.js +7 -7
  20. package/lib/core/cff_parser.js +1 -1
  21. package/lib/core/chunked_stream.js +5 -5
  22. package/lib/core/cmap.js +13 -0
  23. package/lib/core/document.js +22 -18
  24. package/lib/core/evaluator.js +285 -247
  25. package/lib/core/font_renderer.js +7 -7
  26. package/lib/core/fonts.js +163 -147
  27. package/lib/core/function.js +4 -5
  28. package/lib/core/glyphlist.js +4523 -4523
  29. package/lib/core/image.js +19 -44
  30. package/lib/core/image_utils.js +123 -47
  31. package/lib/core/jpeg_stream.js +2 -116
  32. package/lib/core/jpg.js +47 -55
  33. package/lib/core/jpx.js +6 -6
  34. package/lib/core/metrics.js +2916 -2916
  35. package/lib/core/obj.js +18 -7
  36. package/lib/core/operator_list.js +5 -0
  37. package/lib/core/parser.js +1 -1
  38. package/lib/core/pdf_manager.js +2 -2
  39. package/lib/core/primitives.js +4 -0
  40. package/lib/core/standard_fonts.js +103 -103
  41. package/lib/core/type1_parser.js +6 -6
  42. package/lib/core/worker.js +31 -24
  43. package/lib/core/worker_stream.js +1 -1
  44. package/lib/display/annotation_layer.js +3 -0
  45. package/lib/display/api.js +29 -137
  46. package/lib/display/api_compatibility.js +11 -18
  47. package/lib/display/canvas.js +7 -34
  48. package/lib/display/content_disposition.js +4 -4
  49. package/lib/display/display_utils.js +6 -15
  50. package/lib/display/fetch_stream.js +3 -1
  51. package/lib/display/font_loader.js +2 -2
  52. package/lib/display/network.js +1 -1
  53. package/lib/display/node_stream.js +10 -8
  54. package/lib/display/pattern_helper.js +1 -1
  55. package/lib/display/svg.js +61 -31
  56. package/lib/display/text_layer.js +44 -32
  57. package/lib/display/transport_stream.js +3 -3
  58. package/lib/pdf.js +210 -48
  59. package/lib/pdf.worker.js +12 -4
  60. package/lib/shared/compatibility.js +2 -0
  61. package/lib/shared/is_node.js +1 -1
  62. package/lib/shared/message_handler.js +6 -6
  63. package/lib/shared/util.js +15 -9
  64. package/lib/test/unit/api_spec.js +165 -95
  65. package/lib/test/unit/cff_parser_spec.js +12 -12
  66. package/lib/test/unit/clitests_helper.js +1 -1
  67. package/lib/test/unit/display_svg_spec.js +1 -5
  68. package/lib/test/unit/jasmine-boot.js +2 -2
  69. package/lib/test/unit/node_stream_spec.js +5 -3
  70. package/lib/test/unit/parser_spec.js +3 -3
  71. package/lib/test/unit/test_utils.js +1 -1
  72. package/lib/test/unit/testreporter.js +4 -4
  73. package/lib/test/unit/ui_utils_spec.js +1 -55
  74. package/lib/test/unit/unicode_spec.js +1 -1
  75. package/lib/web/app.js +247 -159
  76. package/lib/web/app_options.js +16 -10
  77. package/lib/web/base_viewer.js +14 -6
  78. package/lib/web/download_manager.js +3 -1
  79. package/lib/web/firefox_print_service.js +1 -1
  80. package/lib/web/firefoxcom.js +16 -4
  81. package/lib/web/pdf_attachment_viewer.js +14 -7
  82. package/lib/web/pdf_document_properties.js +11 -16
  83. package/lib/web/pdf_find_bar.js +3 -3
  84. package/lib/web/pdf_find_controller.js +3 -3
  85. package/lib/web/pdf_history.js +7 -5
  86. package/lib/web/pdf_link_service.js +7 -8
  87. package/lib/web/pdf_page_view.js +1 -1
  88. package/lib/web/pdf_presentation_mode.js +6 -2
  89. package/lib/web/pdf_print_service.js +1 -1
  90. package/lib/web/pdf_single_page_viewer.js +2 -2
  91. package/lib/web/pdf_viewer.component.js +2 -2
  92. package/lib/web/pdf_viewer.js +2 -2
  93. package/lib/web/preferences.js +4 -1
  94. package/lib/web/text_layer_builder.js +1 -3
  95. package/lib/web/ui_utils.js +3 -55
  96. package/lib/web/view_history.js +8 -9
  97. package/lib/web/viewer_compatibility.js +14 -1
  98. package/package.json +1 -1
  99. package/web/pdf_viewer.css +5 -9
  100. package/web/pdf_viewer.js +97 -127
  101. package/web/pdf_viewer.js.map +1 -1
package/lib/core/fonts.js CHANGED
@@ -53,6 +53,8 @@ const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
53
53
  var PDF_GLYPH_SPACE_UNITS = 1000;
54
54
  var SEAC_ANALYSIS_ENABLED = true;
55
55
  exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
56
+ const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "fontType", "isMonospace", "isSerifFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "type", "vertical"];
57
+ const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"];
56
58
  var FontFlags = {
57
59
  FixedPitch: 1,
58
60
  Serif: 2,
@@ -410,7 +412,6 @@ var Font = function FontClosure() {
410
412
  this.name = name;
411
413
  this.loadedName = properties.loadedName;
412
414
  this.isType3Font = properties.isType3Font;
413
- this.sizes = [];
414
415
  this.missingFile = false;
415
416
  this.glyphCache = Object.create(null);
416
417
  this.isSerifFont = !!(properties.flags & FontFlags.Serif);
@@ -433,7 +434,6 @@ var Font = function FontClosure() {
433
434
  this.widths = properties.widths;
434
435
  this.defaultWidth = properties.defaultWidth;
435
436
  this.composite = properties.composite;
436
- this.wideChars = properties.wideChars;
437
437
  this.cMap = properties.cMap;
438
438
  this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
439
439
  this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
@@ -454,7 +454,7 @@ var Font = function FontClosure() {
454
454
  }
455
455
 
456
456
  this.cidEncoding = properties.cidEncoding;
457
- this.vertical = properties.vertical;
457
+ this.vertical = !!properties.vertical;
458
458
 
459
459
  if (this.vertical) {
460
460
  this.vmetrics = properties.vmetrics;
@@ -519,7 +519,6 @@ var Font = function FontClosure() {
519
519
  this.widths = properties.widths;
520
520
  this.defaultWidth = properties.defaultWidth;
521
521
  this.toUnicode = properties.toUnicode;
522
- this.encoding = properties.baseEncoding;
523
522
  this.seacMap = properties.seacMap;
524
523
  }
525
524
 
@@ -859,25 +858,25 @@ var Font = function FontClosure() {
859
858
  return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
860
859
  }
861
860
 
862
- function validateOS2Table(os2) {
863
- var stream = new _stream.Stream(os2.data);
864
- var version = stream.getUint16();
865
- stream.getBytes(60);
866
- var selection = stream.getUint16();
861
+ function validateOS2Table(os2, file) {
862
+ file.pos = (file.start || 0) + os2.offset;
863
+ var version = file.getUint16();
864
+ file.skip(60);
865
+ var selection = file.getUint16();
867
866
 
868
867
  if (version < 4 && selection & 0x0300) {
869
868
  return false;
870
869
  }
871
870
 
872
- var firstChar = stream.getUint16();
873
- var lastChar = stream.getUint16();
871
+ var firstChar = file.getUint16();
872
+ var lastChar = file.getUint16();
874
873
 
875
874
  if (firstChar > lastChar) {
876
875
  return false;
877
876
  }
878
877
 
879
- stream.getBytes(6);
880
- var usWinAscent = stream.getUint16();
878
+ file.skip(6);
879
+ var usWinAscent = file.getUint16();
881
880
 
882
881
  if (usWinAscent === 0) {
883
882
  return false;
@@ -1004,7 +1003,6 @@ var Font = function FontClosure() {
1004
1003
  name: null,
1005
1004
  font: null,
1006
1005
  mimetype: null,
1007
- encoding: null,
1008
1006
  disableFontFace: false,
1009
1007
 
1010
1008
  get renderer() {
@@ -1013,20 +1011,24 @@ var Font = function FontClosure() {
1013
1011
  return (0, _util.shadow)(this, "renderer", renderer);
1014
1012
  },
1015
1013
 
1016
- exportData: function Font_exportData() {
1017
- var data = {};
1014
+ exportData(extraProperties = false) {
1015
+ const exportDataProperties = extraProperties ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] : EXPORT_DATA_PROPERTIES;
1016
+ const data = Object.create(null);
1017
+ let property, value;
1018
1018
 
1019
- for (var i in this) {
1020
- if (this.hasOwnProperty(i)) {
1021
- data[i] = this[i];
1019
+ for (property of exportDataProperties) {
1020
+ value = this[property];
1021
+
1022
+ if (value !== undefined) {
1023
+ data[property] = value;
1022
1024
  }
1023
1025
  }
1024
1026
 
1025
1027
  return data;
1026
1028
  },
1029
+
1027
1030
  fallbackToSystemFont: function Font_fallbackToSystemFont() {
1028
1031
  this.missingFile = true;
1029
- var charCode, unicode;
1030
1032
  var name = this.name;
1031
1033
  var type = this.type;
1032
1034
  var subtype = this.subtype;
@@ -1044,20 +1046,20 @@ var Font = function FontClosure() {
1044
1046
  const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
1045
1047
  const map = [];
1046
1048
 
1047
- for (charCode in GlyphMapForStandardFonts) {
1049
+ for (const charCode in GlyphMapForStandardFonts) {
1048
1050
  map[+charCode] = GlyphMapForStandardFonts[charCode];
1049
1051
  }
1050
1052
 
1051
1053
  if (/Arial-?Black/i.test(name)) {
1052
1054
  var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();
1053
1055
 
1054
- for (charCode in SupplementalGlyphMapForArialBlack) {
1056
+ for (const charCode in SupplementalGlyphMapForArialBlack) {
1055
1057
  map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
1056
1058
  }
1057
1059
  } else if (/Calibri/i.test(name)) {
1058
1060
  const SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
1059
1061
 
1060
- for (charCode in SupplementalGlyphMapForCalibri) {
1062
+ for (const charCode in SupplementalGlyphMapForCalibri) {
1061
1063
  map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
1062
1064
  }
1063
1065
  }
@@ -1088,7 +1090,7 @@ var Font = function FontClosure() {
1088
1090
  this.toUnicode.forEach((charCode, unicodeCharCode) => {
1089
1091
  if (!this.composite) {
1090
1092
  var glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
1091
- unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
1093
+ const unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
1092
1094
 
1093
1095
  if (unicode !== -1) {
1094
1096
  unicodeCharCode = unicode;
@@ -1102,7 +1104,7 @@ var Font = function FontClosure() {
1102
1104
  if (/Verdana/i.test(name)) {
1103
1105
  const GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
1104
1106
 
1105
- for (charCode in GlyphMapForStandardFonts) {
1107
+ for (const charCode in GlyphMapForStandardFonts) {
1106
1108
  map[+charCode] = GlyphMapForStandardFonts[charCode];
1107
1109
  }
1108
1110
  }
@@ -1120,16 +1122,16 @@ var Font = function FontClosure() {
1120
1122
  function readTables(file, numTables) {
1121
1123
  const tables = Object.create(null);
1122
1124
  tables["OS/2"] = null;
1123
- tables["cmap"] = null;
1124
- tables["head"] = null;
1125
- tables["hhea"] = null;
1126
- tables["hmtx"] = null;
1127
- tables["maxp"] = null;
1128
- tables["name"] = null;
1129
- tables["post"] = null;
1125
+ tables.cmap = null;
1126
+ tables.head = null;
1127
+ tables.hhea = null;
1128
+ tables.hmtx = null;
1129
+ tables.maxp = null;
1130
+ tables.name = null;
1131
+ tables.post = null;
1130
1132
 
1131
1133
  for (let i = 0; i < numTables; i++) {
1132
- const table = readTableEntry(font);
1134
+ const table = readTableEntry(file);
1133
1135
 
1134
1136
  if (!VALID_TABLES.includes(table.tag)) {
1135
1137
  continue;
@@ -1225,11 +1227,11 @@ var Font = function FontClosure() {
1225
1227
  const potentialHeader = readOpenTypeHeader(ttc);
1226
1228
  const potentialTables = readTables(ttc, potentialHeader.numTables);
1227
1229
 
1228
- if (!potentialTables["name"]) {
1230
+ if (!potentialTables.name) {
1229
1231
  throw new _util.FormatError('TrueType Collection font must contain a "name" table.');
1230
1232
  }
1231
1233
 
1232
- const nameTable = readNameTable(potentialTables["name"]);
1234
+ const nameTable = readNameTable(potentialTables.name);
1233
1235
 
1234
1236
  for (let j = 0, jj = nameTable.length; j < jj; j++) {
1235
1237
  for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
@@ -1248,7 +1250,7 @@ var Font = function FontClosure() {
1248
1250
  throw new _util.FormatError(`TrueType Collection does not contain "${fontName}" font.`);
1249
1251
  }
1250
1252
 
1251
- function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
1253
+ function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
1252
1254
  if (!cmap) {
1253
1255
  (0, _util.warn)("No cmap table available.");
1254
1256
  return {
@@ -1260,17 +1262,17 @@ var Font = function FontClosure() {
1260
1262
  }
1261
1263
 
1262
1264
  var segment;
1263
- var start = (font.start ? font.start : 0) + cmap.offset;
1264
- font.pos = start;
1265
- font.getUint16();
1266
- var numTables = font.getUint16();
1265
+ var start = (file.start ? file.start : 0) + cmap.offset;
1266
+ file.pos = start;
1267
+ file.skip(2);
1268
+ var numTables = file.getUint16();
1267
1269
  var potentialTable;
1268
1270
  var canBreak = false;
1269
1271
 
1270
1272
  for (var i = 0; i < numTables; i++) {
1271
- var platformId = font.getUint16();
1272
- var encodingId = font.getUint16();
1273
- var offset = font.getInt32() >>> 0;
1273
+ var platformId = file.getUint16();
1274
+ var encodingId = file.getUint16();
1275
+ var offset = file.getInt32() >>> 0;
1274
1276
  var useTable = false;
1275
1277
 
1276
1278
  if (potentialTable && potentialTable.platformId === platformId && potentialTable.encodingId === encodingId) {
@@ -1306,10 +1308,10 @@ var Font = function FontClosure() {
1306
1308
  }
1307
1309
 
1308
1310
  if (potentialTable) {
1309
- font.pos = start + potentialTable.offset;
1311
+ file.pos = start + potentialTable.offset;
1310
1312
  }
1311
1313
 
1312
- if (!potentialTable || font.peekByte() === -1) {
1314
+ if (!potentialTable || file.peekByte() === -1) {
1313
1315
  (0, _util.warn)("Could not find a preferred cmap table.");
1314
1316
  return {
1315
1317
  platformId: -1,
@@ -1319,16 +1321,15 @@ var Font = function FontClosure() {
1319
1321
  };
1320
1322
  }
1321
1323
 
1322
- var format = font.getUint16();
1323
- font.getUint16();
1324
- font.getUint16();
1324
+ var format = file.getUint16();
1325
+ file.skip(2 + 2);
1325
1326
  var hasShortCmap = false;
1326
1327
  var mappings = [];
1327
1328
  var j, glyphId;
1328
1329
 
1329
1330
  if (format === 0) {
1330
1331
  for (j = 0; j < 256; j++) {
1331
- var index = font.getByte();
1332
+ var index = file.getByte();
1332
1333
 
1333
1334
  if (!index) {
1334
1335
  continue;
@@ -1342,32 +1343,32 @@ var Font = function FontClosure() {
1342
1343
 
1343
1344
  hasShortCmap = true;
1344
1345
  } else if (format === 4) {
1345
- var segCount = font.getUint16() >> 1;
1346
- font.getBytes(6);
1346
+ var segCount = file.getUint16() >> 1;
1347
+ file.skip(6);
1347
1348
  var segIndex,
1348
1349
  segments = [];
1349
1350
 
1350
1351
  for (segIndex = 0; segIndex < segCount; segIndex++) {
1351
1352
  segments.push({
1352
- end: font.getUint16()
1353
+ end: file.getUint16()
1353
1354
  });
1354
1355
  }
1355
1356
 
1356
- font.getUint16();
1357
+ file.skip(2);
1357
1358
 
1358
1359
  for (segIndex = 0; segIndex < segCount; segIndex++) {
1359
- segments[segIndex].start = font.getUint16();
1360
+ segments[segIndex].start = file.getUint16();
1360
1361
  }
1361
1362
 
1362
1363
  for (segIndex = 0; segIndex < segCount; segIndex++) {
1363
- segments[segIndex].delta = font.getUint16();
1364
+ segments[segIndex].delta = file.getUint16();
1364
1365
  }
1365
1366
 
1366
1367
  var offsetsCount = 0;
1367
1368
 
1368
1369
  for (segIndex = 0; segIndex < segCount; segIndex++) {
1369
1370
  segment = segments[segIndex];
1370
- var rangeOffset = font.getUint16();
1371
+ var rangeOffset = file.getUint16();
1371
1372
 
1372
1373
  if (!rangeOffset) {
1373
1374
  segment.offsetIndex = -1;
@@ -1382,7 +1383,7 @@ var Font = function FontClosure() {
1382
1383
  var offsets = [];
1383
1384
 
1384
1385
  for (j = 0; j < offsetsCount; j++) {
1385
- offsets.push(font.getUint16());
1386
+ offsets.push(file.getUint16());
1386
1387
  }
1387
1388
 
1388
1389
  for (segIndex = 0; segIndex < segCount; segIndex++) {
@@ -1406,11 +1407,11 @@ var Font = function FontClosure() {
1406
1407
  }
1407
1408
  }
1408
1409
  } else if (format === 6) {
1409
- var firstCode = font.getUint16();
1410
- var entryCount = font.getUint16();
1410
+ var firstCode = file.getUint16();
1411
+ var entryCount = file.getUint16();
1411
1412
 
1412
1413
  for (j = 0; j < entryCount; j++) {
1413
- glyphId = font.getUint16();
1414
+ glyphId = file.getUint16();
1414
1415
  var charCode = firstCode + j;
1415
1416
  mappings.push({
1416
1417
  charCode,
@@ -1446,7 +1447,7 @@ var Font = function FontClosure() {
1446
1447
  };
1447
1448
  }
1448
1449
 
1449
- function sanitizeMetrics(font, header, metrics, numGlyphs, dupFirstEntry) {
1450
+ function sanitizeMetrics(file, header, metrics, numGlyphs, dupFirstEntry) {
1450
1451
  if (!header) {
1451
1452
  if (metrics) {
1452
1453
  metrics.data = null;
@@ -1455,21 +1456,21 @@ var Font = function FontClosure() {
1455
1456
  return;
1456
1457
  }
1457
1458
 
1458
- font.pos = (font.start ? font.start : 0) + header.offset;
1459
- font.pos += 4;
1460
- font.pos += 2;
1461
- font.pos += 2;
1462
- font.pos += 2;
1463
- font.pos += 2;
1464
- font.pos += 2;
1465
- font.pos += 2;
1466
- font.pos += 2;
1467
- font.pos += 2;
1468
- font.pos += 2;
1469
- font.pos += 2;
1470
- font.pos += 8;
1471
- font.pos += 2;
1472
- var numOfMetrics = font.getUint16();
1459
+ file.pos = (file.start ? file.start : 0) + header.offset;
1460
+ file.pos += 4;
1461
+ file.pos += 2;
1462
+ file.pos += 2;
1463
+ file.pos += 2;
1464
+ file.pos += 2;
1465
+ file.pos += 2;
1466
+ file.pos += 2;
1467
+ file.pos += 2;
1468
+ file.pos += 2;
1469
+ file.pos += 2;
1470
+ file.pos += 2;
1471
+ file.pos += 8;
1472
+ file.pos += 2;
1473
+ var numOfMetrics = file.getUint16();
1473
1474
 
1474
1475
  if (numOfMetrics > numGlyphs) {
1475
1476
  (0, _util.info)("The numOfMetrics (" + numOfMetrics + ") should not be " + "greater than the numGlyphs (" + numGlyphs + ")");
@@ -1735,13 +1736,13 @@ var Font = function FontClosure() {
1735
1736
  };
1736
1737
  }
1737
1738
 
1738
- function readPostScriptTable(post, properties, maxpNumGlyphs) {
1739
+ function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
1739
1740
  var start = (font.start ? font.start : 0) + post.offset;
1740
1741
  font.pos = start;
1741
1742
  var length = post.length,
1742
1743
  end = start + length;
1743
1744
  var version = font.getInt32();
1744
- font.getBytes(28);
1745
+ font.skip(28);
1745
1746
  var glyphNames;
1746
1747
  var valid = true;
1747
1748
  var i;
@@ -1812,14 +1813,14 @@ var Font = function FontClosure() {
1812
1813
  (0, _util.warn)("Unknown/unsupported post table version " + version);
1813
1814
  valid = false;
1814
1815
 
1815
- if (properties.defaultEncoding) {
1816
- glyphNames = properties.defaultEncoding;
1816
+ if (propertiesObj.defaultEncoding) {
1817
+ glyphNames = propertiesObj.defaultEncoding;
1817
1818
  }
1818
1819
 
1819
1820
  break;
1820
1821
  }
1821
1822
 
1822
- properties.glyphNames = glyphNames;
1823
+ propertiesObj.glyphNames = glyphNames;
1823
1824
  return valid;
1824
1825
  }
1825
1826
 
@@ -2195,27 +2196,27 @@ var Font = function FontClosure() {
2195
2196
  if (!isTrueType) {
2196
2197
  const isComposite = properties.composite && ((properties.cidToGidMap || []).length > 0 || !(properties.cMap instanceof _cmap.IdentityCMap));
2197
2198
 
2198
- if (header.version === "OTTO" && !isComposite || !tables["head"] || !tables["hhea"] || !tables["maxp"] || !tables["post"]) {
2199
+ if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
2199
2200
  cffFile = new _stream.Stream(tables["CFF "].data);
2200
2201
  cff = new CFFFont(cffFile, properties);
2201
2202
  adjustWidths(properties);
2202
2203
  return this.convert(name, cff, properties);
2203
2204
  }
2204
2205
 
2205
- delete tables["glyf"];
2206
- delete tables["loca"];
2207
- delete tables["fpgm"];
2208
- delete tables["prep"];
2206
+ delete tables.glyf;
2207
+ delete tables.loca;
2208
+ delete tables.fpgm;
2209
+ delete tables.prep;
2209
2210
  delete tables["cvt "];
2210
2211
  this.isOpenType = true;
2211
2212
  } else {
2212
- if (!tables["loca"]) {
2213
+ if (!tables.loca) {
2213
2214
  throw new _util.FormatError('Required "loca" table is not found');
2214
2215
  }
2215
2216
 
2216
- if (!tables["glyf"]) {
2217
+ if (!tables.glyf) {
2217
2218
  (0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
2218
- tables["glyf"] = {
2219
+ tables.glyf = {
2219
2220
  tag: "glyf",
2220
2221
  data: new Uint8Array(0)
2221
2222
  };
@@ -2224,11 +2225,11 @@ var Font = function FontClosure() {
2224
2225
  this.isOpenType = false;
2225
2226
  }
2226
2227
 
2227
- if (!tables["maxp"]) {
2228
+ if (!tables.maxp) {
2228
2229
  throw new _util.FormatError('Required "maxp" table is not found');
2229
2230
  }
2230
2231
 
2231
- font.pos = (font.start || 0) + tables["maxp"].offset;
2232
+ font.pos = (font.start || 0) + tables.maxp.offset;
2232
2233
  var version = font.getInt32();
2233
2234
  const numGlyphs = font.getUint16();
2234
2235
  let numGlyphsOut = numGlyphs + 1;
@@ -2243,13 +2244,13 @@ var Font = function FontClosure() {
2243
2244
  var maxFunctionDefs = 0;
2244
2245
  var maxSizeOfInstructions = 0;
2245
2246
 
2246
- if (version >= 0x00010000 && tables["maxp"].length >= 22) {
2247
+ if (version >= 0x00010000 && tables.maxp.length >= 22) {
2247
2248
  font.pos += 8;
2248
2249
  var maxZones = font.getUint16();
2249
2250
 
2250
2251
  if (maxZones > 2) {
2251
- tables["maxp"].data[14] = 0;
2252
- tables["maxp"].data[15] = 2;
2252
+ tables.maxp.data[14] = 0;
2253
+ tables.maxp.data[15] = 2;
2253
2254
  }
2254
2255
 
2255
2256
  font.pos += 4;
@@ -2258,65 +2259,64 @@ var Font = function FontClosure() {
2258
2259
  maxSizeOfInstructions = font.getUint16();
2259
2260
  }
2260
2261
 
2261
- tables["maxp"].data[4] = numGlyphsOut >> 8;
2262
- tables["maxp"].data[5] = numGlyphsOut & 255;
2263
- var hintsValid = sanitizeTTPrograms(tables["fpgm"], tables["prep"], tables["cvt "], maxFunctionDefs);
2262
+ tables.maxp.data[4] = numGlyphsOut >> 8;
2263
+ tables.maxp.data[5] = numGlyphsOut & 255;
2264
+ var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs);
2264
2265
 
2265
2266
  if (!hintsValid) {
2266
- delete tables["fpgm"];
2267
- delete tables["prep"];
2267
+ delete tables.fpgm;
2268
+ delete tables.prep;
2268
2269
  delete tables["cvt "];
2269
2270
  }
2270
2271
 
2271
- sanitizeMetrics(font, tables["hhea"], tables["hmtx"], numGlyphsOut, dupFirstEntry);
2272
+ sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphsOut, dupFirstEntry);
2272
2273
 
2273
- if (!tables["head"]) {
2274
+ if (!tables.head) {
2274
2275
  throw new _util.FormatError('Required "head" table is not found');
2275
2276
  }
2276
2277
 
2277
- sanitizeHead(tables["head"], numGlyphs, isTrueType ? tables["loca"].length : 0);
2278
+ sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
2278
2279
  var missingGlyphs = Object.create(null);
2279
2280
 
2280
2281
  if (isTrueType) {
2281
- var isGlyphLocationsLong = int16(tables["head"].data[50], tables["head"].data[51]);
2282
- var glyphsInfo = sanitizeGlyphLocations(tables["loca"], tables["glyf"], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
2282
+ var isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
2283
+ var glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
2283
2284
  missingGlyphs = glyphsInfo.missingGlyphs;
2284
2285
 
2285
- if (version >= 0x00010000 && tables["maxp"].length >= 22) {
2286
- tables["maxp"].data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
2287
- tables["maxp"].data[27] = glyphsInfo.maxSizeOfInstructions & 255;
2286
+ if (version >= 0x00010000 && tables.maxp.length >= 22) {
2287
+ tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
2288
+ tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
2288
2289
  }
2289
2290
  }
2290
2291
 
2291
- if (!tables["hhea"]) {
2292
+ if (!tables.hhea) {
2292
2293
  throw new _util.FormatError('Required "hhea" table is not found');
2293
2294
  }
2294
2295
 
2295
- if (tables["hhea"].data[10] === 0 && tables["hhea"].data[11] === 0) {
2296
- tables["hhea"].data[10] = 0xff;
2297
- tables["hhea"].data[11] = 0xff;
2296
+ if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
2297
+ tables.hhea.data[10] = 0xff;
2298
+ tables.hhea.data[11] = 0xff;
2298
2299
  }
2299
2300
 
2300
2301
  var metricsOverride = {
2301
- unitsPerEm: int16(tables["head"].data[18], tables["head"].data[19]),
2302
- yMax: int16(tables["head"].data[42], tables["head"].data[43]),
2303
- yMin: signedInt16(tables["head"].data[38], tables["head"].data[39]),
2304
- ascent: int16(tables["hhea"].data[4], tables["hhea"].data[5]),
2305
- descent: signedInt16(tables["hhea"].data[6], tables["hhea"].data[7])
2302
+ unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
2303
+ yMax: int16(tables.head.data[42], tables.head.data[43]),
2304
+ yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
2305
+ ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
2306
+ descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7])
2306
2307
  };
2307
2308
  this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
2308
2309
  this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
2309
2310
 
2310
- if (tables["post"]) {
2311
- readPostScriptTable(tables["post"], properties, numGlyphs);
2311
+ if (tables.post) {
2312
+ readPostScriptTable(tables.post, properties, numGlyphs);
2312
2313
  }
2313
2314
 
2314
- tables["post"] = {
2315
+ tables.post = {
2315
2316
  tag: "post",
2316
2317
  data: createPostTable(properties)
2317
2318
  };
2318
- var charCodeToGlyphId = [],
2319
- charCode;
2319
+ const charCodeToGlyphId = [];
2320
2320
 
2321
2321
  function hasGlyph(glyphId) {
2322
2322
  return !missingGlyphs[glyphId];
@@ -2343,7 +2343,7 @@ var Font = function FontClosure() {
2343
2343
  }
2344
2344
  });
2345
2345
  } else {
2346
- var cmapTable = readCmapTable(tables["cmap"], font, this.isSymbolicFont, properties.hasEncoding);
2346
+ var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding);
2347
2347
  var cmapPlatformId = cmapTable.platformId;
2348
2348
  var cmapEncodingId = cmapTable.encodingId;
2349
2349
  var cmapMappings = cmapTable.mappings;
@@ -2358,7 +2358,7 @@ var Font = function FontClosure() {
2358
2358
 
2359
2359
  var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
2360
2360
 
2361
- for (charCode = 0; charCode < 256; charCode++) {
2361
+ for (let charCode = 0; charCode < 256; charCode++) {
2362
2362
  var glyphName, standardGlyphName;
2363
2363
 
2364
2364
  if (this.differences && charCode in this.differences) {
@@ -2412,7 +2412,7 @@ var Font = function FontClosure() {
2412
2412
  }
2413
2413
  } else {
2414
2414
  for (let i = 0; i < cmapMappingsLength; ++i) {
2415
- charCode = cmapMappings[i].charCode;
2415
+ let charCode = cmapMappings[i].charCode;
2416
2416
 
2417
2417
  if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
2418
2418
  charCode &= 0xff;
@@ -2435,12 +2435,12 @@ var Font = function FontClosure() {
2435
2435
 
2436
2436
  var newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId);
2437
2437
  this.toFontChar = newMapping.toFontChar;
2438
- tables["cmap"] = {
2438
+ tables.cmap = {
2439
2439
  tag: "cmap",
2440
2440
  data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut)
2441
2441
  };
2442
2442
 
2443
- if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"])) {
2443
+ if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
2444
2444
  tables["OS/2"] = {
2445
2445
  tag: "OS/2",
2446
2446
  data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
@@ -2460,14 +2460,14 @@ var Font = function FontClosure() {
2460
2460
  }
2461
2461
  }
2462
2462
 
2463
- if (!tables["name"]) {
2464
- tables["name"] = {
2463
+ if (!tables.name) {
2464
+ tables.name = {
2465
2465
  tag: "name",
2466
2466
  data: createNameTable(this.name)
2467
2467
  };
2468
2468
  } else {
2469
- var namePrototype = readNameTable(tables["name"]);
2470
- tables["name"].data = createNameTable(name, namePrototype);
2469
+ var namePrototype = readNameTable(tables.name);
2470
+ tables.name.data = createNameTable(name, namePrototype);
2471
2471
  }
2472
2472
 
2473
2473
  var builder = new OpenTypeFileBuilder(header.version);
@@ -2552,7 +2552,7 @@ var Font = function FontClosure() {
2552
2552
  continue;
2553
2553
  }
2554
2554
 
2555
- for (var i = 0, ii = charCodes.length; i < ii; i++) {
2555
+ for (let i = 0, ii = charCodes.length; i < ii; i++) {
2556
2556
  var charCode = charCodes[i];
2557
2557
  var charCodeToGlyphId = newMapping.charCodeToGlyphId;
2558
2558
  var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
@@ -2580,7 +2580,7 @@ var Font = function FontClosure() {
2580
2580
  var cffWidths = font.cff ? font.cff.widths : null;
2581
2581
  var hmtx = "\x00\x00\x00\x00";
2582
2582
 
2583
- for (var i = 1, ii = numGlyphs; i < ii; i++) {
2583
+ for (let i = 1, ii = numGlyphs; i < ii; i++) {
2584
2584
  var width = 0;
2585
2585
 
2586
2586
  if (charstrings) {
@@ -2602,10 +2602,6 @@ var Font = function FontClosure() {
2602
2602
  },
2603
2603
 
2604
2604
  get spaceWidth() {
2605
- if ("_shadowWidth" in this) {
2606
- return this._shadowWidth;
2607
- }
2608
-
2609
2605
  var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
2610
2606
  var width;
2611
2607
 
@@ -2621,10 +2617,8 @@ var Font = function FontClosure() {
2621
2617
  var glyphUnicode = glyphsUnicodeMap[glyphName];
2622
2618
  var charcode = 0;
2623
2619
 
2624
- if (this.composite) {
2625
- if (this.cMap.contains(glyphUnicode)) {
2626
- charcode = this.cMap.lookup(glyphUnicode);
2627
- }
2620
+ if (this.composite && this.cMap.contains(glyphUnicode)) {
2621
+ charcode = this.cMap.lookup(glyphUnicode);
2628
2622
  }
2629
2623
 
2630
2624
  if (!charcode && this.toUnicode) {
@@ -2643,8 +2637,7 @@ var Font = function FontClosure() {
2643
2637
  }
2644
2638
 
2645
2639
  width = width || this.defaultWidth;
2646
- this._shadowWidth = width;
2647
- return width;
2640
+ return (0, _util.shadow)(this, "spaceWidth", width);
2648
2641
  },
2649
2642
 
2650
2643
  charToGlyph: function Font_charToGlyph(charcode, isSpace) {
@@ -2664,7 +2657,7 @@ var Font = function FontClosure() {
2664
2657
  unicode = String.fromCharCode(unicode);
2665
2658
  }
2666
2659
 
2667
- var isInFont = charcode in this.toFontChar;
2660
+ var isInFont = (charcode in this.toFontChar);
2668
2661
  fontCharCode = this.toFontChar[charcode] || charcode;
2669
2662
 
2670
2663
  if (this.missingFile) {
@@ -2693,7 +2686,16 @@ var Font = function FontClosure() {
2693
2686
  };
2694
2687
  }
2695
2688
 
2696
- var fontChar = typeof fontCharCode === "number" ? String.fromCodePoint(fontCharCode) : "";
2689
+ let fontChar = "";
2690
+
2691
+ if (typeof fontCharCode === "number") {
2692
+ if (fontCharCode <= 0x10ffff) {
2693
+ fontChar = String.fromCodePoint(fontCharCode);
2694
+ } else {
2695
+ (0, _util.warn)(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
2696
+ }
2697
+ }
2698
+
2697
2699
  var glyph = this.glyphCache[charcode];
2698
2700
 
2699
2701
  if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
@@ -2768,11 +2770,13 @@ var ErrorFont = function ErrorFontClosure() {
2768
2770
  charsToGlyphs: function ErrorFont_charsToGlyphs() {
2769
2771
  return [];
2770
2772
  },
2771
- exportData: function ErrorFont_exportData() {
2773
+
2774
+ exportData(extraProperties = false) {
2772
2775
  return {
2773
2776
  error: this.error
2774
2777
  };
2775
2778
  }
2779
+
2776
2780
  };
2777
2781
  return ErrorFont;
2778
2782
  }();
@@ -2976,8 +2980,8 @@ var Type1Font = function Type1FontClosure() {
2976
2980
  var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
2977
2981
  var data = eexecBlockParser.extractFontProgram(properties);
2978
2982
 
2979
- for (var info in data.properties) {
2980
- properties[info] = data.properties[info];
2983
+ for (const key in data.properties) {
2984
+ properties[key] = data.properties[key];
2981
2985
  }
2982
2986
 
2983
2987
  var charstrings = data.charstrings;
@@ -3005,6 +3009,18 @@ var Type1Font = function Type1FontClosure() {
3005
3009
  },
3006
3010
  getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
3007
3011
  var charstrings = this.charstrings;
3012
+
3013
+ if (properties.composite) {
3014
+ const charCodeToGlyphId = Object.create(null);
3015
+
3016
+ for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) {
3017
+ const charCode = properties.cMap.charCodeOf(glyphId);
3018
+ charCodeToGlyphId[charCode] = glyphId + 1;
3019
+ }
3020
+
3021
+ return charCodeToGlyphId;
3022
+ }
3023
+
3008
3024
  var glyphNames = [".notdef"],
3009
3025
  glyphId;
3010
3026