Commit 700d62f8 authored by Alexander.Trofimov's avatar Alexander.Trofimov

Пернес fitToWidth и fitToHeight в PagePrintOptions

parent 1906aba4
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
"use strict";
var editor;
......@@ -856,9 +856,9 @@ var editor;
oAdditionalData["userid"] = this.documentUserId;
oAdditionalData["vkey"] = this.documentVKey;
oAdditionalData["outputformat"] = sFormat;
oAdditionalData["title"] = changeFileExtention(this.documentTitle, getExtentionByFormat(sFormat));
if (DownloadType.Print === options.downloadType) {
oAdditionalData["inline"] = 1;
oAdditionalData["title"] = changeFileExtention(this.documentTitle, getExtentionByFormat(sFormat));
if (DownloadType.Print === options.downloadType) {
oAdditionalData["inline"] = 1;
}
if (c_oAscFileType.PDF === sFormat) {
var printPagesData = this.wb.calcPagesPrint(this.adjustPrint);
......@@ -3184,11 +3184,14 @@ var editor;
var _adjustPrint = window.AscDesktopEditor_PrintData ? window.AscDesktopEditor_PrintData : new asc_CAdjustPrint();
window.AscDesktopEditor_PrintData = undefined;
if (1 == _param)
{
_adjustPrint.asc_setPrintType(c_oAscPrintType.EntireWorkbook);
_adjustPrint.asc_setFitToWidth(true);
_adjustPrint.asc_setFitToHeight(true);
if (1 == _param) {
var countWorksheets = _adjustPrint.asc_setPrintType(c_oAscPrintType.EntireWorkbook), printOptions;
this.wbModel.getWorksheetCount();
for (var j = 0; j < countWorksheets; ++j) {
printOptions = this.wbModel.getWorksheet(j).PagePrintOptions;
printOptions.asc_setFitToWidth(true);
printOptions.asc_setFitToHeight(true);
}
}
var _printPagesData = this.wb.calcPagesPrint(_adjustPrint);
......
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
"use strict";
// Используем [] вместо new Array() для ускорения (http://jsperf.com/creation-array)
......@@ -251,11 +251,6 @@ var c_oAscPrintType = {
EntireWorkbook: 1, // Всю книгу
Selection: 2 // Выделенный фрагмент
};
// Тип печати
var c_oAscLayoutPageType = {
FitToWidth: 0, // На всю ширину
ActualSize: 1 // По реальным размерам
};
/** @enum */
var c_oAscCustomAutoFilter = {
......
......@@ -2352,7 +2352,8 @@ function asc_ReadAdjustPrint(s, p) {
}
case 1:
{
adjustPrint.asc_setLayoutPageType(s[p.pos++]);
// ToDo что-то тут нужно поправить...Теперь нет asc_setLayoutPageType
//adjustPrint.asc_setLayoutPageType(s[p.pos++]);
break;
}
case 255:
......
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7  3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7  3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
"use strict";
/* Utils.js
......@@ -1079,33 +1079,26 @@
asc_CPageMargins.prototype.asc_setTop = function (val) { this.top = val; };
asc_CPageMargins.prototype.asc_setBottom = function (val) { this.bottom = val; };
/** @constructor */
function asc_CPageSetup (obj) {
if ( !(this instanceof asc_CPageSetup) ) {
return new asc_CPageSetup(obj);
}
function asc_CPageSetup () {
this.orientation = c_oAscPrintDefaultSettings.PageOrientation;
this.width = c_oAscPrintDefaultSettings.PageWidth;
this.height = c_oAscPrintDefaultSettings.PageHeight;
if (obj) {
this.orientation = obj.orientation;
this.width = obj.width;
this.height = obj.height;
}
this.fitToWidth = false; //ToDo can be a number
this.fitToHeight = false; //ToDo can be a number
return this;
}
asc_CPageSetup.prototype.init = function () {
if (null == this.orientation)
this.orientation = c_oAscPrintDefaultSettings.PageOrientation;
if (null == this.width)
this.width = c_oAscPrintDefaultSettings.PageWidth;
if (null == this.height)
this.height = c_oAscPrintDefaultSettings.PageHeight;
};
asc_CPageSetup.prototype.asc_getOrientation = function () { return this.orientation; };
asc_CPageSetup.prototype.asc_getWidth = function () { return this.width; };
asc_CPageSetup.prototype.asc_getHeight = function () { return this.height; };
asc_CPageSetup.prototype.asc_setOrientation = function (val) { this.orientation = val; };
asc_CPageSetup.prototype.asc_setWidth = function (val) { this.width = val; };
asc_CPageSetup.prototype.asc_setHeight = function (val) { this.height = val; };
asc_CPageSetup.prototype.getFitToWidth = function () { return this.fitToWidth; };
asc_CPageSetup.prototype.getFitToHeight = function () { return this.fitToHeight; };
asc_CPageSetup.prototype.asc_setFitToWidth = function (val) { this.fitToWidth = val; };
asc_CPageSetup.prototype.asc_setFitToHeight = function (val) { this.fitToHeight = val; };
/** @constructor */
function asc_CPageOptions (obj) {
......@@ -1186,30 +1179,14 @@
}
/** @constructor */
function asc_CAdjustPrint () {
if ( !(this instanceof asc_CAdjustPrint) ) {
return new asc_CAdjustPrint();
}
// Вид печати
this.printType = c_oAscPrintType.ActiveSheets;
// Вид печати
this.layoutPageType = c_oAscLayoutPageType.ActualSize;
// По ширине
this.fitToWidth = false;
// По высоте
this.fitToHeight = false;
// ToDo сюда же start и end page index
return this;
}
asc_CAdjustPrint.prototype.asc_getPrintType = function () { return this.printType; };
asc_CAdjustPrint.prototype.asc_getLayoutPageType = function () { return this.layoutPageType; };
asc_CAdjustPrint.prototype.asc_setPrintType = function (val) { this.printType = val; };
asc_CAdjustPrint.prototype.asc_setLayoutPageType = function (val) { this.layoutPageType = val; };
asc_CAdjustPrint.prototype.getFitToWidth = function () { return this.fitToWidth; };
asc_CAdjustPrint.prototype.getFitToHeight = function () { return this.fitToHeight; };
asc_CAdjustPrint.prototype.asc_setFitToWidth = function (val) { this.fitToWidth = val; };
asc_CAdjustPrint.prototype.asc_setFitToHeight = function (val) { this.fitToHeight = val; };
/** @constructor */
function asc_CLockInfo () {
......@@ -1688,6 +1665,8 @@
prot["asc_setOrientation"] = prot.asc_setOrientation;
prot["asc_setWidth"] = prot.asc_setWidth;
prot["asc_setHeight"] = prot.asc_setHeight;
prot["asc_setFitToWidth"] = prot.asc_setFitToWidth;
prot["asc_setFitToHeight"] = prot.asc_setFitToHeight;
window["Asc"]["asc_CPageOptions"] = window["Asc"].asc_CPageOptions = asc_CPageOptions;
prot = asc_CPageOptions.prototype;
......@@ -1706,11 +1685,7 @@
window["Asc"]["asc_CAdjustPrint"] = window["Asc"].asc_CAdjustPrint = asc_CAdjustPrint;
prot = asc_CAdjustPrint.prototype;
prot["asc_getPrintType"] = prot.asc_getPrintType;
prot["asc_getLayoutPageType"] = prot.asc_getLayoutPageType;
prot["asc_setPrintType"] = prot.asc_setPrintType;
prot["asc_setLayoutPageType"] = prot.asc_setLayoutPageType;
prot["asc_setFitToWidth"] = prot.asc_setFitToWidth;
prot["asc_setFitToHeight"] = prot.asc_setFitToHeight;
window["Asc"].asc_CLockInfo = asc_CLockInfo;
......
......@@ -2387,19 +2387,19 @@
var activeWs;
var printPagesData = new asc_CPrintPagesData();
var printType = adjustPrint.asc_getPrintType();
// var layoutPageType = adjustPrint.asc_getLayoutPageType();
var bFitToWidth = adjustPrint.getFitToWidth();
var bFitToHeight = adjustPrint.getFitToHeight();
if (printType == c_oAscPrintType.ActiveSheets) {
if (printType === c_oAscPrintType.ActiveSheets) {
activeWs = wb.getActive();
ws = this.getWorksheet();
printPagesData.arrPages = ws.calcPagesPrint(wb.getWorksheet(activeWs).PagePrintOptions, /*printOnlySelection*/false, /*indexWorksheet*/activeWs, bFitToWidth, bFitToHeight);
} else if (printType == c_oAscPrintType.EntireWorkbook) {
printPagesData.arrPages =
ws.calcPagesPrint(wb.getWorksheet(activeWs).PagePrintOptions, /*printOnlySelection*/false, /*indexWorksheet*/
activeWs);
} else if (printType === c_oAscPrintType.EntireWorkbook) {
// Колличество листов
var countWorksheets = this.model.getWorksheetCount();
for (var i = 0; i < countWorksheets; ++i) {
ws = this.getWorksheet(i);
var arrPages = ws.calcPagesPrint(wb.getWorksheet(i).PagePrintOptions, /*printOnlySelection*/false, /*indexWorksheet*/i, bFitToWidth, bFitToHeight);
var arrPages = ws.calcPagesPrint(wb.getWorksheet(i).PagePrintOptions, /*printOnlySelection*/false,
/*indexWorksheet*/i);
if (null !== arrPages) {
if (null === printPagesData.arrPages) {
printPagesData.arrPages = [];
......@@ -2407,10 +2407,12 @@
printPagesData.arrPages = printPagesData.arrPages.concat(arrPages);
}
}
} else if (printType == c_oAscPrintType.Selection) {
} else if (printType === c_oAscPrintType.Selection) {
activeWs = wb.getActive();
ws = this.getWorksheet();
printPagesData.arrPages = ws.calcPagesPrint(wb.getWorksheet(activeWs).PagePrintOptions, /*printOnlySelection*/true, /*indexWorksheet*/activeWs, bFitToWidth, bFitToHeight);
printPagesData.arrPages =
ws.calcPagesPrint(wb.getWorksheet(activeWs).PagePrintOptions, /*printOnlySelection*/true, /*indexWorksheet*/
activeWs);
}
return printPagesData;
......
......@@ -1631,29 +1631,31 @@
};
// ----- Drawing for print -----
WorksheetView.prototype.calcPagesPrint = function(pageOptions, printOnlySelection, indexWorksheet, bFitToWidth, bFitToHeight) {
WorksheetView.prototype.calcPagesPrint = function(pageOptions, printOnlySelection, indexWorksheet) {
var range;
var maxCols = this.model.getColsCount();
var maxRows = this.model.getRowsCount();
var lastC = -1, lastR = -1;
var activeRange = printOnlySelection ? this.activeRange : null;
if ( null === activeRange ) {
range = new asc_Range( 0, 0, maxCols, maxRows );
this._prepareCellTextMetricsCache( range );
for ( var c = 0; c < maxCols; ++c ) {
for ( var r = 0; r < maxRows; ++r ) {
if ( !this._isCellEmptyOrMergedOrBackgroundColorOrBorders( c, r ) ) {
var bFitToWidth = pageOptions.getFitToWidth();
var bFitToHeight = pageOptions.getFitToHeight();
if (null === activeRange) {
range = new asc_Range(0, 0, maxCols, maxRows);
this._prepareCellTextMetricsCache(range);
for (var c = 0; c < maxCols; ++c) {
for (var r = 0; r < maxRows; ++r) {
if (!this._isCellEmptyOrMergedOrBackgroundColorOrBorders(c, r)) {
var rightSide = 0;
var ct = this._getCellTextCache( c, r );
if ( ct !== undefined ) {
if ( !ct.flags.isMerged() && !ct.flags.wrapText ) {
var ct = this._getCellTextCache(c, r);
if (ct !== undefined) {
if (!ct.flags.isMerged() && !ct.flags.wrapText) {
rightSide = ct.sideR;
}
}
lastC = Math.max( lastC, c + rightSide );
lastR = Math.max( lastR, r );
lastC = Math.max(lastC, c + rightSide);
lastR = Math.max(lastR, r);
}
}
}
......@@ -1662,20 +1664,19 @@
// Получаем максимальную колонку/строку для изображений/чатов
var maxObjectsCoord = this.objectRender.getDrawingAreaMetrics();
if ( maxObjectsCoord ) {
maxCols = Math.max( maxCols, maxObjectsCoord.maxCol );
maxRows = Math.max( maxRows, maxObjectsCoord.maxRow );
if (maxObjectsCoord) {
maxCols = Math.max(maxCols, maxObjectsCoord.maxCol);
maxRows = Math.max(maxRows, maxObjectsCoord.maxRow);
}
}
else {
} else {
maxCols = activeRange.c2 + 1;
maxRows = activeRange.r2 + 1;
range = new asc_Range( 0, 0, maxCols, maxRows );
this._prepareCellTextMetricsCache( range );
range = new asc_Range(0, 0, maxCols, maxRows);
this._prepareCellTextMetricsCache(range);
}
var pageMargins, pageSetup, pageGridLines, pageHeadings;
if ( pageOptions instanceof asc_CPageOptions ) {
if (pageOptions instanceof asc_CPageOptions) {
pageMargins = pageOptions.asc_getPageMargins();
pageSetup = pageOptions.asc_getPageSetup();
pageGridLines = pageOptions.asc_getGridLines();
......@@ -1683,218 +1684,216 @@
}
var pageWidth, pageHeight, pageOrientation;
if ( pageSetup instanceof asc_CPageSetup ) {
if (pageSetup instanceof asc_CPageSetup) {
pageWidth = pageSetup.asc_getWidth();
pageHeight = pageSetup.asc_getHeight();
pageOrientation = pageSetup.asc_getOrientation();
}
var pageLeftField, pageRightField, pageTopField, pageBottomField;
if ( pageMargins instanceof asc_CPageMargins ) {
pageLeftField = pageMargins.asc_getLeft();
pageRightField = pageMargins.asc_getRight();
pageTopField = pageMargins.asc_getTop();
pageBottomField = pageMargins.asc_getBottom();
}
if ( null == pageGridLines ) {
pageGridLines = c_oAscPrintDefaultSettings.PageGridLines;
}
if ( null == pageHeadings ) {
pageHeadings = c_oAscPrintDefaultSettings.PageHeadings;
}
if ( null == pageWidth ) {
pageWidth = c_oAscPrintDefaultSettings.PageWidth;
}
if ( null == pageHeight ) {
pageHeight = c_oAscPrintDefaultSettings.PageHeight;
}
if ( null == pageOrientation ) {
pageOrientation = c_oAscPrintDefaultSettings.PageOrientation;
}
if ( null == pageLeftField ) {
pageLeftField = c_oAscPrintDefaultSettings.PageLeftField;
}
if ( null == pageRightField ) {
pageRightField = c_oAscPrintDefaultSettings.PageRightField;
}
if ( null == pageTopField ) {
pageTopField = c_oAscPrintDefaultSettings.PageTopField;
}
if ( null == pageBottomField ) {
pageBottomField = c_oAscPrintDefaultSettings.PageBottomField;
}
if ( c_oAscPageOrientation.PageLandscape === pageOrientation ) {
var tmp = pageWidth;
pageWidth = pageHeight;
pageHeight = tmp;
}
var arrResult = [];
if ( 0 === maxCols || 0 === maxRows ) {
// Ничего нет, возвращаем пустой массив
return null;
}
else {
var pageWidthWithFields = pageWidth - pageLeftField - pageRightField;
var pageHeightWithFields = pageHeight - pageTopField - pageBottomField;
var leftFieldInPt = pageLeftField / vector_koef;
var topFieldInPt = pageTopField / vector_koef;
var rightFieldInPt = pageRightField / vector_koef;
var bottomFieldInPt = pageBottomField / vector_koef;
if ( pageHeadings ) {
// Рисуем заголовки, нужно чуть сдвинуться
leftFieldInPt += this.cellsLeft;
topFieldInPt += this.cellsTop;
}
var pageWidthWithFieldsHeadings = (pageWidth - pageRightField) / vector_koef - leftFieldInPt;
var pageHeightWithFieldsHeadings = (pageHeight - pageBottomField) / vector_koef - topFieldInPt;
var currentColIndex = (null !== activeRange) ? activeRange.c1 : 0;
var currentWidth = 0;
var currentRowIndex = (null !== activeRange) ? activeRange.r1 : 0;
var currentHeight = 0;
var isCalcColumnsWidth = true;
var bIsAddOffset = false;
var nCountOffset = 0;
while ( true ) {
if ( currentColIndex === maxCols && currentRowIndex === maxRows ) {
break;
}
var newPagePrint = new asc_CPagePrint();
var colIndex = currentColIndex, rowIndex = currentRowIndex;
newPagePrint.indexWorksheet = indexWorksheet;
newPagePrint.pageWidth = pageWidth;
newPagePrint.pageHeight = pageHeight;
newPagePrint.pageClipRectLeft = pageLeftField / vector_koef;
newPagePrint.pageClipRectTop = pageTopField / vector_koef;
newPagePrint.pageClipRectWidth = pageWidthWithFields / vector_koef;
newPagePrint.pageClipRectHeight = pageHeightWithFields / vector_koef;
newPagePrint.leftFieldInPt = leftFieldInPt;
newPagePrint.topFieldInPt = topFieldInPt;
newPagePrint.rightFieldInPt = rightFieldInPt;
newPagePrint.bottomFieldInPt = bottomFieldInPt;
for ( rowIndex = currentRowIndex; rowIndex < maxRows; ++rowIndex ) {
var currentRowHeight = this.rows[rowIndex].height;
if (!bFitToHeight && currentHeight + currentRowHeight > pageHeightWithFieldsHeadings) {
// Закончили рисовать страницу
break;
}
if ( isCalcColumnsWidth ) {
for ( colIndex = currentColIndex; colIndex < maxCols; ++colIndex ) {
var currentColWidth = this.cols[colIndex].width;
if ( bIsAddOffset ) {
newPagePrint.startOffset = ++nCountOffset;
newPagePrint.startOffsetPt = (pageWidthWithFieldsHeadings * newPagePrint.startOffset);
currentColWidth -= newPagePrint.startOffsetPt;
}
if (!bFitToWidth && currentWidth + currentColWidth > pageWidthWithFieldsHeadings && colIndex !== currentColIndex) {
break;
}
currentWidth += currentColWidth;
if (!bFitToWidth && currentWidth > pageWidthWithFieldsHeadings && colIndex === currentColIndex) {
// Смещаем в селедующий раз ячейку
bIsAddOffset = true;
++colIndex;
break;
}
else {
bIsAddOffset = false;
}
}
isCalcColumnsWidth = false;
if ( pageHeadings ) {
currentWidth += this.cellsLeft;
}
if (bFitToWidth) {
newPagePrint.pageClipRectWidth = Math.max( currentWidth, newPagePrint.pageClipRectWidth );
newPagePrint.pageWidth = newPagePrint.pageClipRectWidth * vector_koef + (pageLeftField + pageRightField);
}
else {
newPagePrint.pageClipRectWidth = Math.min( currentWidth, newPagePrint.pageClipRectWidth );
}
}
currentHeight += currentRowHeight;
currentWidth = 0;
}
if (bFitToHeight) {
newPagePrint.pageClipRectHeight = Math.max(currentHeight, newPagePrint.pageClipRectHeight);
newPagePrint.pageHeight = newPagePrint.pageClipRectHeight * vector_koef + (pageTopField + pageBottomField);
}
// Нужно будет пересчитывать колонки
isCalcColumnsWidth = true;
// Рисуем сетку
if ( pageGridLines ) {
newPagePrint.pageGridLines = true;
}
if ( pageHeadings ) {
// Нужно отрисовать заголовки
newPagePrint.pageHeadings = true;
}
newPagePrint.pageRange = new asc_Range( currentColIndex, currentRowIndex, colIndex - 1, rowIndex - 1 );
if ( bIsAddOffset ) {
// Мы еще не дорисовали колонку
colIndex -= 1;
}
else {
nCountOffset = 0;
}
if ( colIndex < maxCols ) {
// Мы еще не все колонки отрисовали
currentColIndex = colIndex;
currentHeight = 0;
}
else {
// Мы дорисовали все колонки, нужна новая строка и стартовая колонка
currentColIndex = (null !== activeRange) ? activeRange.c1 : 0;
currentRowIndex = rowIndex;
currentHeight = 0;
}
if ( rowIndex === maxRows ) {
// Мы вышли, т.к. дошли до конца отрисовки по строкам
if ( colIndex < maxCols ) {
currentColIndex = colIndex;
currentHeight = 0;
}
else {
// Мы дошли до конца отрисовки
currentColIndex = colIndex;
currentRowIndex = rowIndex;
}
}
arrResult.push( newPagePrint );
}
}
return arrResult;
};
pageOrientation = pageSetup.asc_getOrientation();
}
var pageLeftField, pageRightField, pageTopField, pageBottomField;
if (pageMargins instanceof asc_CPageMargins) {
pageLeftField = pageMargins.asc_getLeft();
pageRightField = pageMargins.asc_getRight();
pageTopField = pageMargins.asc_getTop();
pageBottomField = pageMargins.asc_getBottom();
}
if (null == pageGridLines) {
pageGridLines = c_oAscPrintDefaultSettings.PageGridLines;
}
if (null == pageHeadings) {
pageHeadings = c_oAscPrintDefaultSettings.PageHeadings;
}
if (null == pageWidth) {
pageWidth = c_oAscPrintDefaultSettings.PageWidth;
}
if (null == pageHeight) {
pageHeight = c_oAscPrintDefaultSettings.PageHeight;
}
if (null == pageOrientation) {
pageOrientation = c_oAscPrintDefaultSettings.PageOrientation;
}
if (null == pageLeftField) {
pageLeftField = c_oAscPrintDefaultSettings.PageLeftField;
}
if (null == pageRightField) {
pageRightField = c_oAscPrintDefaultSettings.PageRightField;
}
if (null == pageTopField) {
pageTopField = c_oAscPrintDefaultSettings.PageTopField;
}
if (null == pageBottomField) {
pageBottomField = c_oAscPrintDefaultSettings.PageBottomField;
}
if (c_oAscPageOrientation.PageLandscape === pageOrientation) {
var tmp = pageWidth;
pageWidth = pageHeight;
pageHeight = tmp;
}
var arrResult = [];
if (0 === maxCols || 0 === maxRows) {
// Ничего нет, возвращаем пустой массив
return null;
} else {
var pageWidthWithFields = pageWidth - pageLeftField - pageRightField;
var pageHeightWithFields = pageHeight - pageTopField - pageBottomField;
var leftFieldInPt = pageLeftField / vector_koef;
var topFieldInPt = pageTopField / vector_koef;
var rightFieldInPt = pageRightField / vector_koef;
var bottomFieldInPt = pageBottomField / vector_koef;
if (pageHeadings) {
// Рисуем заголовки, нужно чуть сдвинуться
leftFieldInPt += this.cellsLeft;
topFieldInPt += this.cellsTop;
}
var pageWidthWithFieldsHeadings = (pageWidth - pageRightField) / vector_koef - leftFieldInPt;
var pageHeightWithFieldsHeadings = (pageHeight - pageBottomField) / vector_koef - topFieldInPt;
var currentColIndex = (null !== activeRange) ? activeRange.c1 : 0;
var currentWidth = 0;
var currentRowIndex = (null !== activeRange) ? activeRange.r1 : 0;
var currentHeight = 0;
var isCalcColumnsWidth = true;
var bIsAddOffset = false;
var nCountOffset = 0;
while (true) {
if (currentColIndex === maxCols && currentRowIndex === maxRows) {
break;
}
var newPagePrint = new asc_CPagePrint();
var colIndex = currentColIndex, rowIndex = currentRowIndex;
newPagePrint.indexWorksheet = indexWorksheet;
newPagePrint.pageWidth = pageWidth;
newPagePrint.pageHeight = pageHeight;
newPagePrint.pageClipRectLeft = pageLeftField / vector_koef;
newPagePrint.pageClipRectTop = pageTopField / vector_koef;
newPagePrint.pageClipRectWidth = pageWidthWithFields / vector_koef;
newPagePrint.pageClipRectHeight = pageHeightWithFields / vector_koef;
newPagePrint.leftFieldInPt = leftFieldInPt;
newPagePrint.topFieldInPt = topFieldInPt;
newPagePrint.rightFieldInPt = rightFieldInPt;
newPagePrint.bottomFieldInPt = bottomFieldInPt;
for (rowIndex = currentRowIndex; rowIndex < maxRows; ++rowIndex) {
var currentRowHeight = this.rows[rowIndex].height;
if (!bFitToHeight && currentHeight + currentRowHeight > pageHeightWithFieldsHeadings) {
// Закончили рисовать страницу
break;
}
if (isCalcColumnsWidth) {
for (colIndex = currentColIndex; colIndex < maxCols; ++colIndex) {
var currentColWidth = this.cols[colIndex].width;
if (bIsAddOffset) {
newPagePrint.startOffset = ++nCountOffset;
newPagePrint.startOffsetPt = (pageWidthWithFieldsHeadings * newPagePrint.startOffset);
currentColWidth -= newPagePrint.startOffsetPt;
}
if (!bFitToWidth && currentWidth + currentColWidth > pageWidthWithFieldsHeadings &&
colIndex !== currentColIndex) {
break;
}
currentWidth += currentColWidth;
if (!bFitToWidth && currentWidth > pageWidthWithFieldsHeadings &&
colIndex === currentColIndex) {
// Смещаем в селедующий раз ячейку
bIsAddOffset = true;
++colIndex;
break;
} else {
bIsAddOffset = false;
}
}
isCalcColumnsWidth = false;
if (pageHeadings) {
currentWidth += this.cellsLeft;
}
if (bFitToWidth) {
newPagePrint.pageClipRectWidth = Math.max(currentWidth, newPagePrint.pageClipRectWidth);
newPagePrint.pageWidth =
newPagePrint.pageClipRectWidth * vector_koef + (pageLeftField + pageRightField);
} else {
newPagePrint.pageClipRectWidth = Math.min(currentWidth, newPagePrint.pageClipRectWidth);
}
}
currentHeight += currentRowHeight;
currentWidth = 0;
}
if (bFitToHeight) {
newPagePrint.pageClipRectHeight = Math.max(currentHeight, newPagePrint.pageClipRectHeight);
newPagePrint.pageHeight =
newPagePrint.pageClipRectHeight * vector_koef + (pageTopField + pageBottomField);
}
// Нужно будет пересчитывать колонки
isCalcColumnsWidth = true;
// Рисуем сетку
if (pageGridLines) {
newPagePrint.pageGridLines = true;
}
if (pageHeadings) {
// Нужно отрисовать заголовки
newPagePrint.pageHeadings = true;
}
newPagePrint.pageRange = new asc_Range(currentColIndex, currentRowIndex, colIndex - 1, rowIndex - 1);
if (bIsAddOffset) {
// Мы еще не дорисовали колонку
colIndex -= 1;
} else {
nCountOffset = 0;
}
if (colIndex < maxCols) {
// Мы еще не все колонки отрисовали
currentColIndex = colIndex;
currentHeight = 0;
} else {
// Мы дорисовали все колонки, нужна новая строка и стартовая колонка
currentColIndex = (null !== activeRange) ? activeRange.c1 : 0;
currentRowIndex = rowIndex;
currentHeight = 0;
}
if (rowIndex === maxRows) {
// Мы вышли, т.к. дошли до конца отрисовки по строкам
if (colIndex < maxCols) {
currentColIndex = colIndex;
currentHeight = 0;
} else {
// Мы дошли до конца отрисовки
currentColIndex = colIndex;
currentRowIndex = rowIndex;
}
}
arrResult.push(newPagePrint);
}
}
return arrResult;
};
WorksheetView.prototype.drawForPrint = function ( drawingCtx, printPagesData ) {
var isAppBridge = (undefined != window['appBridge']);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment