| 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | 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", "./../figures/layout-element", "./../brushes/pdf-brush", "./../fonts/pdf-font", "./../fonts/pdf-standard-font", "./../pdf-pen", "./../figures/base/element-layouter", "./base/text-layouter", "./../brushes/pdf-solid-brush", "./../pdf-color", "./../../drawing/pdf-drawing", "./base/element-layouter", "./../fonts/string-layouter", "./../enum"], function (require, exports, layout_element_1, pdf_brush_1, pdf_font_1, pdf_standard_font_1, pdf_pen_1, element_layouter_1, text_layouter_1, pdf_solid_brush_1, pdf_color_1, pdf_drawing_1, element_layouter_2, string_layouter_1, enum_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var PdfTextElement = (function (_super) { __extends(PdfTextElement, _super); function PdfTextElement(arg1, arg2, arg3, arg4, arg5) { var _this = _super.call(this) || this; _this.content = ''; _this.elementValue = ''; _this.hasPointOverload = false; _this._isLastElement = false; _this.isPdfTextElement = false; if (typeof arg1 === 'undefined') { } else if (typeof arg1 === 'string' && typeof arg2 === 'undefined') { _this.content = arg1; _this.elementValue = arg1; } else if (typeof arg1 === 'string' && arg2 instanceof pdf_font_1.PdfFont && typeof arg3 === 'undefined') { _this.content = arg1; _this.elementValue = arg1; _this.pdfFont = arg2; } else if (typeof arg1 === 'string' && arg2 instanceof pdf_font_1.PdfFont && arg3 instanceof pdf_pen_1.PdfPen && typeof arg4 === 'undefined') { _this.content = arg1; _this.elementValue = arg1; _this.pdfFont = arg2; _this.pdfPen = arg3; } else if (typeof arg1 === 'string' && arg2 instanceof pdf_font_1.PdfFont && arg3 instanceof pdf_brush_1.PdfBrush && typeof arg4 === 'undefined') { _this.content = arg1; _this.elementValue = arg1; _this.pdfFont = arg2; _this.pdfBrush = arg3; } else { _this.content = arg1; _this.elementValue = arg1; _this.pdfFont = arg2; _this.pdfPen = arg3; _this.pdfBrush = arg4; _this.format = arg5; } return _this; } Object.defineProperty(PdfTextElement.prototype, "text", { get: function () { return this.content; }, set: function (value) { this.elementValue = value; this.content = value; }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextElement.prototype, "value", { get: function () { return this.elementValue; }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextElement.prototype, "pen", { get: function () { return this.pdfPen; }, set: function (value) { this.pdfPen = value; }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextElement.prototype, "brush", { get: function () { return this.pdfBrush; }, set: function (value) { this.pdfBrush = value; }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextElement.prototype, "font", { get: function () { return this.pdfFont; }, set: function (value) { this.pdfFont = value; if (this.pdfFont instanceof pdf_standard_font_1.PdfStandardFont && this.content != null) { this.elementValue = pdf_standard_font_1.PdfStandardFont.convert(this.content); } else { this.elementValue = this.content; } }, enumerable: true, configurable: true }); Object.defineProperty(PdfTextElement.prototype, "stringFormat", { get: function () { return this.format; }, set: function (value) { this.format = value; }, enumerable: true, configurable: true }); PdfTextElement.prototype.getBrush = function () { return (this.pdfBrush == null || typeof this.pdfBrush === 'undefined') ? new pdf_solid_brush_1.PdfSolidBrush(new pdf_color_1.PdfColor(0, 0, 0)) : this.pdfBrush; }; PdfTextElement.prototype.layout = function (param) { var layouter = new text_layouter_1.TextLayouter(this); var result = layouter.layout(param); return result; }; PdfTextElement.prototype.drawText = function (arg2, arg3, arg4, arg5) { if (arg3 instanceof pdf_drawing_1.PointF && typeof arg3.width === 'undefined' && typeof arg4 === 'undefined') { this.hasPointOverload = true; return this.drawText(arg2, arg3.x, arg3.y); } else if (typeof arg3 === 'number' && typeof arg4 === 'number' && typeof arg5 === 'undefined') { this.hasPointOverload = true; return this.drawText(arg2, arg3, arg4, null); } else if (arg3 instanceof pdf_drawing_1.RectangleF && typeof arg3.width !== 'undefined' && typeof arg4 === 'undefined') { return this.drawText(arg2, arg3, null); } else if (arg3 instanceof pdf_drawing_1.PointF && typeof arg3.width === 'undefined' && arg4 instanceof element_layouter_2.PdfLayoutFormat) { this.hasPointOverload = true; return this.drawText(arg2, arg3.x, arg3.y, arg4); } else if (typeof arg3 === 'number' && typeof arg4 === 'number' && (arg5 instanceof element_layouter_2.PdfLayoutFormat || arg5 == null)) { this.hasPointOverload = true; var width = (arg2.graphics.clientSize.width - arg3); var layoutRectangle = new pdf_drawing_1.RectangleF(arg3, arg4, width, 0); return this.drawText(arg2, layoutRectangle, arg5); } else if (arg3 instanceof pdf_drawing_1.RectangleF && typeof arg3.width !== 'undefined' && typeof arg4 === 'boolean') { return this.drawText(arg2, arg3, null); } else { var layout = new string_layouter_1.PdfStringLayouter(); if (this.hasPointOverload) { var stringLayoutResult = layout.layout(this.value, this.font, this.stringFormat, new pdf_drawing_1.SizeF((arg2.graphics.clientSize.width - arg3.x), 0), true, arg2.graphics.clientSize); var layoutResult = void 0; var param = new element_layouter_1.PdfLayoutParams(); var temparg3 = arg3; var temparg4 = arg4; param.page = arg2; var previousPage = arg2; param.bounds = temparg3; param.format = (temparg4 != null) ? temparg4 : new element_layouter_2.PdfLayoutFormat(); if (stringLayoutResult.lines.length > 1) { this.text = stringLayoutResult.layoutLines[0].text; if (param.bounds.y <= param.page.graphics.clientSize.height) { var previousPosition = new pdf_drawing_1.PointF(param.bounds.x, param.bounds.y); layoutResult = this.layout(param); var bounds = new pdf_drawing_1.RectangleF(0, layoutResult.bounds.y + stringLayoutResult.lineHeight, arg2.graphics.clientSize.width, stringLayoutResult.lineHeight); var isPaginate = false; for (var i = 1; i < stringLayoutResult.lines.length; i++) { param.page = layoutResult.page; param.bounds = new pdf_drawing_1.RectangleF(new pdf_drawing_1.PointF(bounds.x, bounds.y), new pdf_drawing_1.SizeF(bounds.width, bounds.height)); this.text = stringLayoutResult.layoutLines[i].text; if (bounds.y + stringLayoutResult.lineHeight > layoutResult.page.graphics.clientSize.height) { isPaginate = true; param.page = param.page.graphics.getNextPage(); if (previousPosition.y > (layoutResult.page.graphics.clientSize.height - layoutResult.bounds.height)) { bounds = new pdf_drawing_1.RectangleF(0, layoutResult.bounds.height, layoutResult.page.graphics.clientSize.width, stringLayoutResult.lineHeight); } else { bounds = new pdf_drawing_1.RectangleF(0, 0, layoutResult.page.graphics.clientSize.width, stringLayoutResult.lineHeight); } param.bounds = bounds; } if (i === stringLayoutResult.lines.length - 1) { this._isLastElement = true; } layoutResult = this.layout(param); if (i !== (stringLayoutResult.lines.length - 1)) { bounds = new pdf_drawing_1.RectangleF(0, layoutResult.bounds.y + stringLayoutResult.lineHeight, layoutResult.page.graphics.clientSize.width, stringLayoutResult.lineHeight); } else { var lineWidth = this.font.measureString(this.text, this.format).width; layoutResult = this.calculateResultBounds(layoutResult, lineWidth, layoutResult.page.graphics.clientSize.width, 0); } } } return layoutResult; } else { var lineSize = this.font.measureString(this.text, this.format); if (param.bounds.y <= param.page.graphics.clientSize.height) { layoutResult = this.layout(param); layoutResult = this.calculateResultBounds(layoutResult, lineSize.width, layoutResult.page.graphics.clientSize.width, 0); } return layoutResult; } } else { var layoutResult = layout.layout(this.value, this.font, this.stringFormat, new pdf_drawing_1.SizeF(arg3.width, 0), false, arg2.graphics.clientSize); var result = void 0; var param = new element_layouter_1.PdfLayoutParams(); var temparg3 = arg3; var temparg4 = arg4; param.page = arg2; param.bounds = temparg3; param.format = (temparg4 != null) ? temparg4 : new element_layouter_2.PdfLayoutFormat(); if (layoutResult.lines.length > 1) { this.text = layoutResult.layoutLines[0].text; if (param.bounds.y <= param.page.graphics.clientSize.height) { var previousPosition = new pdf_drawing_1.PointF(param.bounds.x, param.bounds.y); result = this.layout(param); var bounds = new pdf_drawing_1.RectangleF(temparg3.x, result.bounds.y + layoutResult.lineHeight, temparg3.width, layoutResult.lineHeight); var isPaginate = false; for (var i = 1; i < layoutResult.lines.length; i++) { param.page = result.page; param.bounds = new pdf_drawing_1.RectangleF(bounds.x, bounds.y, bounds.width, bounds.height); this.text = layoutResult.layoutLines[i].text; if (bounds.y + layoutResult.lineHeight > result.page.graphics.clientSize.height) { isPaginate = true; param.page = param.page.graphics.getNextPage(); if (previousPosition.y > (result.page.graphics.clientSize.height - result.bounds.height)) { bounds = new pdf_drawing_1.RectangleF(temparg3.x, layoutResult.lineHeight, temparg3.width, layoutResult.lineHeight); } else { bounds = new pdf_drawing_1.RectangleF(temparg3.x, 0, temparg3.width, layoutResult.lineHeight); } param.bounds = bounds; } result = this.layout(param); if (i !== (layoutResult.lines.length - 1)) { bounds = new pdf_drawing_1.RectangleF(temparg3.x, result.bounds.y + layoutResult.lineHeight, temparg3.width, layoutResult.lineHeight); } else { var lineWidth = this.font.measureString(this.text, this.format).width; result = this.calculateResultBounds(result, lineWidth, temparg3.width, temparg3.x); } } } return result; } else { var lineSize = this.font.measureString(this.text, this.format); if (param.bounds.y <= param.page.graphics.clientSize.height) { result = this.layout(param); result = this.calculateResultBounds(result, lineSize.width, temparg3.width, temparg3.x); } return result; } } } }; PdfTextElement.prototype.calculateResultBounds = function (result, lineWidth, maximumWidth, startPosition) { var shift = 0; if (this.stringFormat != null && typeof this.stringFormat !== 'undefined' && this.stringFormat.alignment === enum_1.PdfTextAlignment.Center) { result.bounds.x = startPosition + (maximumWidth - lineWidth) / 2; result.bounds.width = lineWidth; } else if (this.stringFormat != null && typeof this.stringFormat !== 'undefined' && this.stringFormat.alignment === enum_1.PdfTextAlignment.Right) { result.bounds.x = startPosition + (maximumWidth - lineWidth); result.bounds.width = lineWidth; } else if (this.stringFormat != null && typeof this.stringFormat !== 'undefined' && this.stringFormat.alignment === enum_1.PdfTextAlignment.Justify) { result.bounds.x = startPosition; result.bounds.width = maximumWidth; } else { result.bounds.width = startPosition; result.bounds.width = lineWidth; } return result; }; return PdfTextElement; }(layout_element_1.PdfLayoutElement)); exports.PdfTextElement = PdfTextElement; }); |