| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "./element-layouter", "./../../../drawing/pdf-drawing", "./../../figures/enum", "./../../../structured-elements/grid/layout/grid-layouter"], function (require, exports, element_layouter_1, pdf_drawing_1, enum_1, grid_layouter_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ShapeLayouter = (function (_super) { __extends(ShapeLayouter, _super); function ShapeLayouter(element) { var _this = _super.call(this, element) || this; _this.olderPdfForm = 0; _this.shapeBounds = new pdf_drawing_1.RectangleF(); _this.totalPageSize = 0; return _this; } Object.defineProperty(ShapeLayouter.prototype, "element", { get: function () { return this.elements; }, enumerable: true, configurable: true }); ShapeLayouter.prototype.layoutInternal = function (param) { var currentPage = param.page; var currentBounds = param.bounds; var shapeLayoutBounds = this.element.getBounds(); shapeLayoutBounds.x = 0; shapeLayoutBounds.y = 0; var isEmpty = (this.shapeBounds.x === this.shapeBounds.y && this.shapeBounds.y === this.shapeBounds.width && this.shapeBounds.width === this.shapeBounds.height && this.shapeBounds.height === 0) ? true : false; if ((this.isPdfGrid) && (!(isEmpty))) { shapeLayoutBounds = this.shapeBounds; } var result = null; var pageResult = new ShapeLayoutResult(); pageResult.page = currentPage; while (true) { var result1 = this.raiseBeforePageLayout(currentPage, currentBounds); currentBounds = result1.currentBounds; var endArgs = null; if (!result1.cancel) { pageResult = this.layoutOnPage(currentPage, currentBounds, shapeLayoutBounds, param); endArgs = this.raiseEndPageLayout(pageResult); result1.cancel = (endArgs === null) ? false : endArgs.cancel; } if (!pageResult.end && !result1.cancel) { currentBounds = this.getPaginateBounds(param); shapeLayoutBounds = this.getNextShapeBounds(shapeLayoutBounds, pageResult); currentPage = (endArgs === null || endArgs.nextPage === null) ? this.getNextPage(currentPage) : endArgs.nextPage; if (this.isPdfGrid) { result = this.getLayoutResult(pageResult); break; } } else { result = this.getLayoutResult(pageResult); break; } } return result; }; ShapeLayouter.prototype.raiseBeforePageLayout = function (currentPage, currentBounds) { var cancel = false; if (this.element.raiseBeginPageLayout) { var args = new grid_layouter_1.BeginPageLayoutEventArgs(currentBounds, currentPage); this.element.onBeginPageLayout(args); cancel = args.cancel; currentBounds = args.bounds; } return { currentBounds: currentBounds, cancel: cancel }; }; ShapeLayouter.prototype.raiseEndPageLayout = function (pageResult) { var args = null; if (this.element.raiseEndPageLayout) { var res = this.getLayoutResult(pageResult); args = new grid_layouter_1.EndPageLayoutEventArgs(res); this.element.onEndPageLayout(args); } return args; }; ShapeLayouter.prototype.getLayoutResult = function (pageResult) { var result = new element_layouter_1.PdfLayoutResult(pageResult.page, pageResult.bounds); return result; }; ShapeLayouter.prototype.getNextShapeBounds = function (shapeLayoutBounds, pageResult) { var layoutedBounds = pageResult.bounds; shapeLayoutBounds.y = (shapeLayoutBounds.y + layoutedBounds.height); shapeLayoutBounds.height = (shapeLayoutBounds.height - layoutedBounds.height); return shapeLayoutBounds; }; ShapeLayouter.prototype.layoutOnPage = function (currentPage, curBounds, sBounds, param) { var result = new ShapeLayoutResult(); curBounds = this.checkCorrectCurrentBounds(currentPage, curBounds, param); var fitToPage = this.fitsToBounds(curBounds, sBounds); var canDraw = !((param.format.break === enum_1.PdfLayoutBreakType.FitElement) && (!fitToPage && (currentPage === param.page))); var shapeFinished = false; if (canDraw) { var drawRectangle = this.getDrawBounds(curBounds, sBounds); this.drawShape(currentPage.graphics, curBounds, drawRectangle); result.bounds = this.getPageResultBounds(curBounds, sBounds); shapeFinished = ((curBounds.height) >= (sBounds.height)); } result.end = (shapeFinished || (param.format.layout === enum_1.PdfLayoutType.OnePage)); result.page = currentPage; return result; }; ShapeLayouter.prototype.getDrawBounds = function (currentBounds, shapeLayoutBounds) { var result = currentBounds; result.y = (result.y - shapeLayoutBounds.y); result.height = (result.height + shapeLayoutBounds.y); return result; }; ShapeLayouter.prototype.drawShape = function (g, currentBounds, drawRectangle) { var gState = g.save(); try { g.setClip(currentBounds); this.element.drawGraphicsHelper(g, new pdf_drawing_1.PointF(drawRectangle.x, drawRectangle.y)); } finally { g.restore(gState); } }; ShapeLayouter.prototype.checkCorrectCurrentBounds = function (currentPage, curBounds, param) { var pageSize = currentPage.graphics.clientSize; curBounds.width = (curBounds.width > 0) ? curBounds.width : (pageSize.width - curBounds.x); curBounds.height = (curBounds.height > 0) ? curBounds.height : (pageSize.height - curBounds.y); if (this.isPdfGrid) { curBounds.height = (curBounds.height - this.bottomCellPadding); } return curBounds; }; ShapeLayouter.prototype.getPageResultBounds = function (currentBounds, shapeLayoutBounds) { var result = currentBounds; result.height = Math.min(result.height, shapeLayoutBounds.height); return result; }; ShapeLayouter.prototype.fitsToBounds = function (currentBounds, shapeLayoutBounds) { var fits = (shapeLayoutBounds.height <= currentBounds.height); return fits; }; ShapeLayouter.index = 0; ShapeLayouter.splitDiff = 0; ShapeLayouter.last = false; ShapeLayouter.borderWidth = 0; return ShapeLayouter; }(element_layouter_1.ElementLayouter)); exports.ShapeLayouter = ShapeLayouter; var ShapeLayoutResult = (function () { function ShapeLayoutResult() { } return ShapeLayoutResult; }()); }); |