Move the toRoman helper function out of the Util scope
				
					
				
			Compared to all the other (static) methods in `Util`, the `toRoman` one looks slightly out of place. Even more so considering that `Util` is being exposed through `pdfjsLib`, where access to a Roman numerals conversion method doesn't make much sense.
This commit is contained in:
		
							parent
							
								
									c1c49badff
								
							
						
					
					
						commit
						8e76d26e5b
					
				@ -16,7 +16,7 @@
 | 
				
			|||||||
import {
 | 
					import {
 | 
				
			||||||
  bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
 | 
					  bytesToString, createPromiseCapability, createValidAbsoluteUrl, FormatError,
 | 
				
			||||||
  info, InvalidPDFException, isBool, isString, MissingDataException, shadow,
 | 
					  info, InvalidPDFException, isBool, isString, MissingDataException, shadow,
 | 
				
			||||||
  stringToPDFString, stringToUTF8String, unreachable, Util, warn,
 | 
					  stringToPDFString, stringToUTF8String, toRomanNumerals, unreachable, warn,
 | 
				
			||||||
  XRefParseException
 | 
					  XRefParseException
 | 
				
			||||||
} from '../shared/util';
 | 
					} from '../shared/util';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
@ -310,7 +310,7 @@ var Catalog = (function CatalogClosure() {
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
          case 'R':
 | 
					          case 'R':
 | 
				
			||||||
          case 'r':
 | 
					          case 'r':
 | 
				
			||||||
            currentLabel = Util.toRoman(currentIndex, style === 'r');
 | 
					            currentLabel = toRomanNumerals(currentIndex, style === 'r');
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
          case 'A':
 | 
					          case 'A':
 | 
				
			||||||
          case 'a':
 | 
					          case 'a':
 | 
				
			||||||
 | 
				
			|||||||
@ -839,45 +839,46 @@ var Util = (function UtilClosure() {
 | 
				
			|||||||
    return result;
 | 
					    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;
 | 
					  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 = [
 | 
					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,
 | 
					  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,
 | 
					  0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
 | 
				
			||||||
@ -1025,6 +1026,7 @@ export {
 | 
				
			|||||||
  UnexpectedResponseException,
 | 
					  UnexpectedResponseException,
 | 
				
			||||||
  UnknownErrorException,
 | 
					  UnknownErrorException,
 | 
				
			||||||
  Util,
 | 
					  Util,
 | 
				
			||||||
 | 
					  toRomanNumerals,
 | 
				
			||||||
  XRefParseException,
 | 
					  XRefParseException,
 | 
				
			||||||
  FormatError,
 | 
					  FormatError,
 | 
				
			||||||
  arrayByteLength,
 | 
					  arrayByteLength,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user