| 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 | 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", "./../text-element", "./../../../drawing/pdf-drawing", "./../../fonts/string-layouter", "./../../figures/enum", "./../../pdf-color", "./../../../annotations/pdf-text-web-link", "../../enum"], function (require, exports, element_layouter_1, text_element_1, pdf_drawing_1, string_layouter_1, enum_1, pdf_color_1, pdf_text_web_link_1, enum_2) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var TextLayouter = (function (_super) { __extends(TextLayouter, _super); function TextLayouter(element) { return _super.call(this, element) || this; } Object.defineProperty(TextLayouter.prototype, "element", { get: function () { return _super.prototype.getElement.call(this); }, enumerable: true, configurable: true }); TextLayouter.prototype.layoutInternal = function (param) { this.format = (this.element.stringFormat !== null && typeof this.element.stringFormat !== 'undefined') ? this.element.stringFormat : null; var currentPage = param.page; var currentBounds = param.bounds; var text = this.element.value; var result = null; var pageResult = new TextPageLayoutResult(); pageResult.page = currentPage; pageResult.remainder = text; for (;;) { pageResult = this.layoutOnPage(text, currentPage, currentBounds, param); result = this.getLayoutResult(pageResult); break; } return result; }; TextLayouter.prototype.getLayoutResult = function (pageResult) { var result = new PdfTextLayoutResult(pageResult.page, pageResult.bounds, pageResult.remainder, pageResult.lastLineBounds); return result; }; TextLayouter.prototype.layoutOnPage = function (text, currentPage, currentBounds, param) { var result = new TextPageLayoutResult(); result.remainder = text; result.page = currentPage; currentBounds = this.checkCorrectBounds(currentPage, currentBounds); var layouter = new string_layouter_1.PdfStringLayouter(); var stringResult = layouter.layout(text, this.element.font, this.format, currentBounds, currentPage.getClientSize().height, false, new pdf_drawing_1.SizeF(0, 0)); var textFinished = (stringResult.remainder == null); var doesntFit = (param.format.break === enum_1.PdfLayoutBreakType.FitElement); var canDraw = !(doesntFit || stringResult.empty); var graphics = currentPage.graphics; var brush = this.element.getBrush(); if (this.element instanceof pdf_text_web_link_1.PdfTextWebLink) { brush.color = new pdf_color_1.PdfColor(0, 0, 255); if (!this.element._isLastElement && this.element.stringFormat && this.element.stringFormat.alignment === enum_2.PdfTextAlignment.Justify) { stringResult.layoutLines[0].type = string_layouter_1.LineType.LayoutBreak | string_layouter_1.LineType.FirstParagraphLine; } } if (this.element && this.element instanceof text_element_1.PdfTextElement && !this.element._isLastElement && this.element.stringFormat && this.element.stringFormat.alignment === enum_2.PdfTextAlignment.Justify) { stringResult.layoutLines[0].type = string_layouter_1.LineType.LayoutBreak | string_layouter_1.LineType.FirstParagraphLine; } graphics.drawStringLayoutResult(stringResult, this.element.font, this.element.pen, brush, currentBounds, this.format); var lineInfo = stringResult.lines[stringResult.lineCount - 1]; result.lastLineBounds = graphics.getLineBounds(stringResult.lineCount - 1, stringResult, this.element.font, currentBounds, this.format); result.bounds = this.getTextPageBounds(currentPage, currentBounds, stringResult); result.remainder = stringResult.remainder; result.end = (textFinished); return result; }; TextLayouter.prototype.checkCorrectBounds = function (currentPage, currentBounds) { var pageSize = currentPage.graphics.clientSize; currentBounds.height = (currentBounds.height > 0) ? currentBounds.height : pageSize.height - currentBounds.y; return currentBounds; }; TextLayouter.prototype.getTextPageBounds = function (currentPage, currentBounds, stringResult) { var textSize = stringResult.actualSize; var x = currentBounds.x; var y = currentBounds.y; var width = (currentBounds.width > 0) ? currentBounds.width : textSize.width; var height = textSize.height; var shiftedRect = currentPage.graphics.checkCorrectLayoutRectangle(textSize, currentBounds.x, currentBounds.y, this.format); x = shiftedRect.x; var verticalShift = currentPage.graphics.getTextVerticalAlignShift(textSize.height, currentBounds.height, this.format); y += verticalShift; var bounds = new pdf_drawing_1.RectangleF(x, y, width, height); return bounds; }; return TextLayouter; }(element_layouter_1.ElementLayouter)); exports.TextLayouter = TextLayouter; var TextPageLayoutResult = (function () { function TextPageLayoutResult() { } return TextPageLayoutResult; }()); exports.TextPageLayoutResult = TextPageLayoutResult; var PdfTextLayoutResult = (function (_super) { __extends(PdfTextLayoutResult, _super); function PdfTextLayoutResult(page, bounds, remainder, lastLineBounds) { var _this = _super.call(this, page, bounds) || this; _this.remainderText = remainder; _this.lastLineTextBounds = lastLineBounds; return _this; } Object.defineProperty(PdfTextLayoutResult.prototype, "remainder", { get: function () { return this.remainderText; }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextLayoutResult.prototype, "lastLineBounds", { get: function () { return this.lastLineTextBounds; }, enumerable: true, configurable: true }); return PdfTextLayoutResult; }(element_layouter_1.PdfLayoutResult)); exports.PdfTextLayoutResult = PdfTextLayoutResult; }); |