mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
[api-minor] Add support for PageLabels in the API
This commit is contained in:
parent
8ad18959d7
commit
85cf90643f
7 changed files with 177 additions and 0 deletions
|
@ -808,6 +808,42 @@ var Util = PDFJS.Util = (function UtilClosure() {
|
|||
return num < 0 ? -1 : 1;
|
||||
};
|
||||
|
||||
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(isInt(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);
|
||||
};
|
||||
|
||||
Util.appendToArray = function Util_appendToArray(arr1, arr2) {
|
||||
Array.prototype.push.apply(arr1, arr2);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue