diff --git a/src/core/obj.js b/src/core/obj.js index 22b6a2a77..823a8d138 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -16,7 +16,7 @@ import { bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError, info, InvalidPDFException, isBool, isString, MissingDataException, shadow, - stringToPDFString, stringToUTF8String, unreachable, Util, warn, + stringToPDFString, stringToUTF8String, toRomanNumerals, unreachable, warn, XRefParseException } from '../shared/util'; import { @@ -310,7 +310,7 @@ var Catalog = (function CatalogClosure() { break; case 'R': case 'r': - currentLabel = Util.toRoman(currentIndex, style === 'r'); + currentLabel = toRomanNumerals(currentIndex, style === 'r'); break; case 'A': case 'a': diff --git a/src/shared/util.js b/src/shared/util.js index 7f6fc931d..642bacf9e 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -839,45 +839,46 @@ var Util = (function UtilClosure() { return result; }; - var ROMAN_NUMBER_MAP = [ - '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', - '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', - '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' - ]; - /** - * Converts positive integers to (upper case) Roman numerals. - * @param {integer} number - The number that should be converted. - * @param {boolean} lowerCase - Indicates if the result should be converted - * to lower case letters. The default is false. - * @return {string} The resulting Roman number. - */ - Util.toRoman = function Util_toRoman(number, lowerCase) { - assert(Number.isInteger(number) && number > 0, - 'The number should be a positive integer.'); - var pos, romanBuf = []; - // Thousands - while (number >= 1000) { - number -= 1000; - romanBuf.push('M'); - } - // Hundreds - pos = (number / 100) | 0; - number %= 100; - romanBuf.push(ROMAN_NUMBER_MAP[pos]); - // Tens - pos = (number / 10) | 0; - number %= 10; - romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); - // Ones - romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); - - var romanStr = romanBuf.join(''); - return (lowerCase ? romanStr.toLowerCase() : romanStr); - }; - return Util; })(); +const ROMAN_NUMBER_MAP = [ + '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', + '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', + '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' +]; + +/** + * Converts positive integers to (upper case) Roman numerals. + * @param {integer} number - The number that should be converted. + * @param {boolean} lowerCase - Indicates if the result should be converted + * to lower case letters. The default value is `false`. + * @return {string} The resulting Roman number. + */ +function toRomanNumerals(number, lowerCase = false) { + assert(Number.isInteger(number) && number > 0, + 'The number should be a positive integer.'); + let pos, romanBuf = []; + // Thousands + while (number >= 1000) { + number -= 1000; + romanBuf.push('M'); + } + // Hundreds + pos = (number / 100) | 0; + number %= 100; + romanBuf.push(ROMAN_NUMBER_MAP[pos]); + // Tens + pos = (number / 10) | 0; + number %= 10; + romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); + // Ones + romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); + + const romanStr = romanBuf.join(''); + return (lowerCase ? romanStr.toLowerCase() : romanStr); +} + var PDFStringTranslateTable = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, @@ -1025,6 +1026,7 @@ export { UnexpectedResponseException, UnknownErrorException, Util, + toRomanNumerals, XRefParseException, FormatError, arrayByteLength,