officegen-dbb
Version:
Modification of Ziv Barber's officegen, to provide a reasonable way to have line breaks in table cells.
92 lines (79 loc) • 2.98 kB
JavaScript
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// 'Software'), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
/**
* This function creating the wide screen plugin object.
* @param {object} pluginsman Access to the plugins manager for pptx documents.
* @constructor
* @name MakeWidescreenPlugin
*/
function MakeWidescreenPlugin ( pluginsman ) {
var funcThis = this;
if ( pluginsman.docType !== 'pptx' && pluginsman.docType !== 'ppsx' ) {
throw "[pptx-widescreen] This plugin supporting only PowerPoint based documents.";
} // Endif.
this.pluginsman = pluginsman;
this.pptxData = pluginsman.getDataStorage ();
// We want to extend the main API of the pptx document object:
pluginsman.registerCallback ( 'makeDocApi', function ( docObj ) { funcThis.extendPptxApi ( docObj ); } );
return this;
}
/**
* This function extending the main document object with new API methods.
* @param {object} docObj Document object.
*/
MakeWidescreenPlugin.prototype.extendPptxApi = function ( docObj ) {
var funcThis = this;
docObj.setSlideSize = function ( cx, cy, sizeType ) {
if ( cx && typeof cx === 'number' ) {
funcThis.pptxData.pptWidth = cx * funcThis.pptxData.EMUS_PER_PT;
} // Endif.
if ( cy && typeof cy === 'number' ) {
funcThis.pptxData.pptHeight = cy * funcThis.pptxData.EMUS_PER_PT;
} // Endif.
/*
Supported types:
'35mm'
'A3'
'A4'
'B4ISO'
'B4JIS'
'B5ISO'
'B5JIS'
'banner'
'custom'
'hagakiCard'
'ledger'
'letter'
'overhead'
'screen16x10'
'screen16x9'
'screen4x3'
*/
if ( sizeType && typeof sizeType === 'string' ) {
funcThis.pptxData.pptType = sizeType;
} // Endif.
};
docObj.setWidescreen = function ( wide ) {
funcThis.pptxData.pptWidth = wide ? (960 * funcThis.pptxData.EMUS_PER_PT) : funcThis.pptxData.pptWidth;
funcThis.pptxData.pptType = wide ? 'screen16x9' : 'screen4x3';
};
};
module.exports = MakeWidescreenPlugin;