@ -37,6 +37,20 @@ var _pdf = require('../pdf');
@@ -37,6 +37,20 @@ var _pdf = require('../pdf');
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
var DEFAULT _FIELD _CONTENT = '-' ;
var NON _METRIC _LOCALES = [ 'en-us' , 'en-lr' , 'my' ] ;
var US _PAGE _NAMES = {
'8.5x11' : 'Letter' ,
'8.5x14' : 'Legal'
} ;
var METRIC _PAGE _NAMES = {
'297x420' : 'A3' ,
'210x297' : 'A4'
} ;
function getPageName ( size , isPortrait , pageNames ) {
var width = isPortrait ? size . width : size . height ;
var height = isPortrait ? size . height : size . width ;
return pageNames [ width + 'x' + height ] ;
}
var PDFDocumentProperties = function ( ) {
function PDFDocumentProperties ( _ref , overlayManager , eventBus ) {
@ -65,7 +79,14 @@ var PDFDocumentProperties = function () {
@@ -65,7 +79,14 @@ var PDFDocumentProperties = function () {
eventBus . on ( 'pagechanging' , function ( evt ) {
_this . _currentPageNumber = evt . pageNumber ;
} ) ;
eventBus . on ( 'rotationchanging' , function ( evt ) {
_this . _pagesRotation = evt . pagesRotation ;
} ) ;
}
this . _isNonMetricLocale = true ;
l10n . getLanguage ( ) . then ( function ( locale ) {
_this . _isNonMetricLocale = NON _METRIC _LOCALES . includes ( locale ) ;
} ) ;
}
_createClass ( PDFDocumentProperties , [ {
@ -83,7 +104,8 @@ var PDFDocumentProperties = function () {
@@ -83,7 +104,8 @@ var PDFDocumentProperties = function () {
} ;
Promise . all ( [ this . overlayManager . open ( this . overlayName ) , this . _dataAvailableCapability . promise ] ) . then ( function ( ) {
var currentPageNumber = _this2 . _currentPageNumber ;
if ( _this2 . fieldData && currentPageNumber === _this2 . fieldData [ '_currentPageNumber' ] ) {
var pagesRotation = _this2 . _pagesRotation ;
if ( _this2 . fieldData && currentPageNumber === _this2 . fieldData [ '_currentPageNumber' ] && pagesRotation === _this2 . fieldData [ '_pagesRotation' ] ) {
_this2 . _updateUI ( ) ;
return ;
}
@ -93,7 +115,7 @@ var PDFDocumentProperties = function () {
@@ -93,7 +115,7 @@ var PDFDocumentProperties = function () {
contentDispositionFilename = _ref2 . contentDispositionFilename ;
return Promise . all ( [ info , metadata , contentDispositionFilename || ( 0 , _ui _utils . getPDFFileNameFromURL ) ( _this2 . url ) , _this2 . _parseFileSize ( _this2 . maybeFileSize ) , _this2 . _parseDate ( info . CreationDate ) , _this2 . _parseDate ( info . ModDate ) , _this2 . pdfDocument . getPage ( currentPageNumber ) . then ( function ( pdfPage ) {
return _this2 . _parsePageSize ( ( 0 , _ui _utils . getPageSizeInches ) ( pdfPage ) ) ;
return _this2 . _parsePageSize ( ( 0 , _ui _utils . getPageSizeInches ) ( pdfPage ) , pagesRotation ) ;
} ) ] ) ;
} ) . then ( function ( _ref3 ) {
var _ref4 = _slicedToArray ( _ref3 , 7 ) ,
@ -103,7 +125,7 @@ var PDFDocumentProperties = function () {
@@ -103,7 +125,7 @@ var PDFDocumentProperties = function () {
fileSize = _ref4 [ 3 ] ,
creationDate = _ref4 [ 4 ] ,
modDate = _ref4 [ 5 ] ,
pageSizes = _ref4 [ 6 ] ;
pageSize = _ref4 [ 6 ] ;
freezeFieldData ( {
'fileName' : fileName ,
@ -118,9 +140,9 @@ var PDFDocumentProperties = function () {
@@ -118,9 +140,9 @@ var PDFDocumentProperties = function () {
'producer' : info . Producer ,
'version' : info . PDFFormatVersion ,
'pageCount' : _this2 . pdfDocument . numPages ,
'pageSizeInch ' : pageSizes . inch ,
'pageSizeMM' : pageSizes . mm ,
'_currentPageNumber' : currentPageNumber
'pageSize' : pageSize ,
'_currentPageNumber' : currentPageNumber ,
'_pagesRotation' : pagesRotation
} ) ;
_this2 . _updateUI ( ) ;
return _this2 . pdfDocument . getDownloadInfo ( ) ;
@ -175,6 +197,7 @@ var PDFDocumentProperties = function () {
@@ -175,6 +197,7 @@ var PDFDocumentProperties = function () {
delete this . fieldData ;
this . _dataAvailableCapability = ( 0 , _pdf . createPromiseCapability ) ( ) ;
this . _currentPageNumber = 1 ;
this . _pagesRotation = 0 ;
}
} , {
key : '_updateUI' ,
@ -216,27 +239,68 @@ var PDFDocumentProperties = function () {
@@ -216,27 +239,68 @@ var PDFDocumentProperties = function () {
}
} , {
key : '_parsePageSize' ,
value : function _parsePageSize ( pageSizeInches ) {
value : function _parsePageSize ( pageSizeInches , pagesRotation ) {
var _this3 = this ;
if ( ! pageSizeInches ) {
return Promise . resolve ( {
inch : undefined ,
mm : undefined
} ) ;
return Promise . resolve ( undefined ) ;
}
var width = pageSizeInches . width ,
height = pageSizeInches . height ;
return Promise . all ( [ this . l10n . get ( 'document_properties_page_size_in_2' , {
width : ( Math . round ( width * 100 ) / 100 ) . toLocaleString ( ) ,
height : ( Math . round ( height * 100 ) / 100 ) . toLocaleString ( )
} , '{{width}} × {{height}} in' ) , this . l10n . get ( 'document_properties_page_size_mm_2' , {
width : ( Math . round ( width * 25.4 * 10 ) / 10 ) . toLocaleString ( ) ,
height : ( Math . round ( height * 25.4 * 10 ) / 10 ) . toLocaleString ( )
} , '{{width}} × {{height}} mm' ) ] ) . then ( function ( sizes ) {
return {
inch : sizes [ 0 ] ,
mm : sizes [ 1 ]
if ( pagesRotation % 180 !== 0 ) {
pageSizeInches = {
width : pageSizeInches . height ,
height : pageSizeInches . width
} ;
}
var isPortrait = ( 0 , _ui _utils . isPortraitOrientation ) ( pageSizeInches ) ;
var sizeInches = {
width : Math . round ( pageSizeInches . width * 100 ) / 100 ,
height : Math . round ( pageSizeInches . height * 100 ) / 100
} ;
var sizeMillimeters = {
width : Math . round ( pageSizeInches . width * 25.4 * 10 ) / 10 ,
height : Math . round ( pageSizeInches . height * 25.4 * 10 ) / 10
} ;
var pageName = null ;
var name = getPageName ( sizeInches , isPortrait , US _PAGE _NAMES ) || getPageName ( sizeMillimeters , isPortrait , METRIC _PAGE _NAMES ) ;
if ( ! name && ! ( Number . isInteger ( sizeMillimeters . width ) && Number . isInteger ( sizeMillimeters . height ) ) ) {
var exactMillimeters = {
width : pageSizeInches . width * 25.4 ,
height : pageSizeInches . height * 25.4
} ;
var intMillimeters = {
width : Math . round ( sizeMillimeters . width ) ,
height : Math . round ( sizeMillimeters . height )
} ;
if ( Math . abs ( exactMillimeters . width - intMillimeters . width ) < 0.1 && Math . abs ( exactMillimeters . height - intMillimeters . height ) < 0.1 ) {
name = getPageName ( intMillimeters , isPortrait , METRIC _PAGE _NAMES ) ;
if ( name ) {
sizeInches = {
width : Math . round ( intMillimeters . width / 25.4 * 100 ) / 100 ,
height : Math . round ( intMillimeters . height / 25.4 * 100 ) / 100
} ;
sizeMillimeters = intMillimeters ;
}
}
}
if ( name ) {
pageName = this . l10n . get ( 'document_properties_page_size_name_' + name . toLowerCase ( ) , null , name ) ;
}
return Promise . all ( [ this . _isNonMetricLocale ? sizeInches : sizeMillimeters , this . l10n . get ( 'document_properties_page_size_unit_' + ( this . _isNonMetricLocale ? 'inches' : 'millimeters' ) , null , this . _isNonMetricLocale ? 'in' : 'mm' ) , pageName , this . l10n . get ( 'document_properties_page_size_orientation_' + ( isPortrait ? 'portrait' : 'landscape' ) , null , isPortrait ? 'portrait' : 'landscape' ) ] ) . then ( function ( _ref6 ) {
var _ref7 = _slicedToArray ( _ref6 , 4 ) ,
_ref7$ = _ref7 [ 0 ] ,
width = _ref7$ . width ,
height = _ref7$ . height ,
unit = _ref7 [ 1 ] ,
name = _ref7 [ 2 ] ,
orientation = _ref7 [ 3 ] ;
return _this3 . l10n . get ( 'document_properties_page_size_dimension_' + ( name ? 'name_' : '' ) + 'string' , {
width : width . toLocaleString ( ) ,
height : height . toLocaleString ( ) ,
unit : unit ,
name : name ,
orientation : orientation
} , '{{width}} × {{height}} {{unit}} (' + ( name ? '{{name}}, ' : '' ) + '{{orientation}})' ) ;
} ) ;
}
} , {