@syncfusion/ej2-pdf-export 23.2.4 → 24.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -18
- package/dist/ej2-pdf-export.min.js +2 -2
- package/dist/ej2-pdf-export.umd.min.js +2 -2
- package/dist/ej2-pdf-export.umd.min.js.map +1 -1
- package/dist/es6/ej2-pdf-export.es2015.js +6 -1
- package/dist/es6/ej2-pdf-export.es2015.js.map +1 -1
- package/dist/es6/ej2-pdf-export.es5.js +6 -1
- package/dist/es6/ej2-pdf-export.es5.js.map +1 -1
- package/dist/global/ej2-pdf-export.min.js +2 -2
- package/dist/global/ej2-pdf-export.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/dist/ts/implementation/actions/action.ts +76 -0
- package/dist/ts/implementation/actions/uri-action.ts +52 -0
- package/dist/ts/implementation/annotations/action-link-annotation.ts +43 -0
- package/dist/ts/implementation/annotations/annotation-collection.ts +159 -0
- package/dist/ts/implementation/annotations/annotation.ts +241 -0
- package/dist/ts/implementation/annotations/document-link-annotation.ts +118 -0
- package/dist/ts/implementation/annotations/link-annotation.ts +32 -0
- package/dist/ts/implementation/annotations/pdf-text-web-link.ts +265 -0
- package/dist/ts/implementation/annotations/uri-annotation.ts +86 -0
- package/dist/ts/implementation/collections/dictionary.ts +150 -0
- package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +125 -0
- package/dist/ts/implementation/collections/utils.ts +38 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +39 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +108 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +127 -0
- package/dist/ts/implementation/document/automatic-fields/composite-field.ts +76 -0
- package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +37 -0
- package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +75 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +157 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +82 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +60 -0
- package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +48 -0
- package/dist/ts/implementation/document/pdf-catalog.ts +65 -0
- package/dist/ts/implementation/document/pdf-document-base.ts +180 -0
- package/dist/ts/implementation/document/pdf-document-template.ts +310 -0
- package/dist/ts/implementation/document/pdf-document.ts +342 -0
- package/dist/ts/implementation/document/pdf-viewer-preferences.ts +578 -0
- package/dist/ts/implementation/drawing/pdf-drawing.ts +218 -0
- package/dist/ts/implementation/general/enum.ts +21 -0
- package/dist/ts/implementation/general/functions/pdf-function.ts +66 -0
- package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +63 -0
- package/dist/ts/implementation/general/pdf-cache-collection.ts +97 -0
- package/dist/ts/implementation/general/pdf-collection.ts +41 -0
- package/dist/ts/implementation/general/pdf-destination.ts +170 -0
- package/dist/ts/implementation/graphics/brushes/enum.ts +237 -0
- package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +294 -0
- package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +68 -0
- package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +2438 -0
- package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +295 -0
- package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +311 -0
- package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +406 -0
- package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +290 -0
- package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +107 -0
- package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +304 -0
- package/dist/ts/implementation/graphics/constants.ts +31 -0
- package/dist/ts/implementation/graphics/enum.ts +413 -0
- package/dist/ts/implementation/graphics/figures/arc.ts +133 -0
- package/dist/ts/implementation/graphics/figures/base/draw-element.ts +59 -0
- package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +260 -0
- package/dist/ts/implementation/graphics/figures/base/fill-element.ts +72 -0
- package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +34 -0
- package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +69 -0
- package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +276 -0
- package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +205 -0
- package/dist/ts/implementation/graphics/figures/ellipse-part.ts +76 -0
- package/dist/ts/implementation/graphics/figures/enum.ts +80 -0
- package/dist/ts/implementation/graphics/figures/layout-element.ts +132 -0
- package/dist/ts/implementation/graphics/figures/path.ts +646 -0
- package/dist/ts/implementation/graphics/figures/pdf-template.ts +205 -0
- package/dist/ts/implementation/graphics/figures/rectangle-area.ts +108 -0
- package/dist/ts/implementation/graphics/figures/text-element.ts +445 -0
- package/dist/ts/implementation/graphics/fonts/enum.ts +385 -0
- package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +248 -0
- package/dist/ts/implementation/graphics/fonts/pdf-font.ts +316 -0
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +606 -0
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +243 -0
- package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +474 -0
- package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +165 -0
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +958 -0
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +374 -0
- package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +255 -0
- package/dist/ts/implementation/graphics/fonts/string-layouter.ts +617 -0
- package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +275 -0
- package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +206 -0
- package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +18 -0
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +18 -0
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +14 -0
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +35 -0
- package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +94 -0
- package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +56 -0
- package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +10 -0
- package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +14 -0
- package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +106 -0
- package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +58 -0
- package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +33 -0
- package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +22 -0
- package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +42 -0
- package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +1254 -0
- package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +577 -0
- package/dist/ts/implementation/graphics/images/byte-array.ts +137 -0
- package/dist/ts/implementation/graphics/images/image-decoder.ts +439 -0
- package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +110 -0
- package/dist/ts/implementation/graphics/images/pdf-image.ts +132 -0
- package/dist/ts/implementation/graphics/pdf-color.ts +478 -0
- package/dist/ts/implementation/graphics/pdf-graphics.ts +2429 -0
- package/dist/ts/implementation/graphics/pdf-margins.ts +124 -0
- package/dist/ts/implementation/graphics/pdf-pen.ts +370 -0
- package/dist/ts/implementation/graphics/pdf-resources.ts +300 -0
- package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +246 -0
- package/dist/ts/implementation/graphics/pdf-transparency.ts +93 -0
- package/dist/ts/implementation/graphics/unit-convertor.ts +96 -0
- package/dist/ts/implementation/input-output/big-endian-writer.ts +121 -0
- package/dist/ts/implementation/input-output/cross-table.ts +21 -0
- package/dist/ts/implementation/input-output/enum.ts +16 -0
- package/dist/ts/implementation/input-output/pdf-cross-table.ts +524 -0
- package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +571 -0
- package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +194 -0
- package/dist/ts/implementation/input-output/pdf-operators.ts +363 -0
- package/dist/ts/implementation/input-output/pdf-stream-writer.ts +681 -0
- package/dist/ts/implementation/input-output/pdf-writer.ts +88 -0
- package/dist/ts/implementation/pages/enum.ts +201 -0
- package/dist/ts/implementation/pages/page-added-event-arguments.ts +39 -0
- package/dist/ts/implementation/pages/pdf-document-page-collection.ts +180 -0
- package/dist/ts/implementation/pages/pdf-page-base.ts +181 -0
- package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +348 -0
- package/dist/ts/implementation/pages/pdf-page-layer.ts +271 -0
- package/dist/ts/implementation/pages/pdf-page-settings.ts +192 -0
- package/dist/ts/implementation/pages/pdf-page-size.ts +162 -0
- package/dist/ts/implementation/pages/pdf-page-template-element.ts +663 -0
- package/dist/ts/implementation/pages/pdf-page.ts +235 -0
- package/dist/ts/implementation/pages/pdf-section-collection.ts +187 -0
- package/dist/ts/implementation/pages/pdf-section-page-collection.ts +61 -0
- package/dist/ts/implementation/pages/pdf-section-templates.ts +96 -0
- package/dist/ts/implementation/pages/pdf-section.ts +644 -0
- package/dist/ts/implementation/primitives/pdf-array.ts +386 -0
- package/dist/ts/implementation/primitives/pdf-boolean.ts +119 -0
- package/dist/ts/implementation/primitives/pdf-dictionary.ts +513 -0
- package/dist/ts/implementation/primitives/pdf-name.ts +218 -0
- package/dist/ts/implementation/primitives/pdf-number.ts +165 -0
- package/dist/ts/implementation/primitives/pdf-reference.ts +430 -0
- package/dist/ts/implementation/primitives/pdf-stream.ts +306 -0
- package/dist/ts/implementation/primitives/pdf-string.ts +397 -0
- package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +2027 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +1193 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +206 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +470 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +853 -0
- package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +240 -0
- package/dist/ts/implementation/structured-elements/grid/styles/style.ts +424 -0
- package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +16 -0
- package/dist/ts/interfaces/i-pdf-cache.ts +23 -0
- package/dist/ts/interfaces/i-pdf-changable.ts +17 -0
- package/dist/ts/interfaces/i-pdf-clonable.ts +12 -0
- package/dist/ts/interfaces/i-pdf-primitives.ts +45 -0
- package/dist/ts/interfaces/i-pdf-true-type-font.ts +48 -0
- package/dist/ts/interfaces/i-pdf-wrapper.ts +13 -0
- package/dist/ts/interfaces/i-pdf-writer.ts +29 -0
- package/package.json +7 -7
- package/src/implementation/document/pdf-document-base.js +1 -2
- package/src/implementation/graphics/pdf-graphics.js +7 -2
- package/src/implementation/graphics/pdf-transformation-matrix.d.ts +1 -1
|
@@ -0,0 +1,2429 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PdfGraphics.ts class for EJ2-PDF
|
|
3
|
+
*/
|
|
4
|
+
import { PdfColorSpace, TextRenderingMode, PdfFillMode, PdfTextAlignment } from './enum';
|
|
5
|
+
import { PdfVerticalAlignment, PdfBlendMode } from './enum';
|
|
6
|
+
import { PdfSubSuperScript } from './fonts/enum';
|
|
7
|
+
import { PdfStreamWriter } from './../input-output/pdf-stream-writer';
|
|
8
|
+
import { PdfPen } from './pdf-pen';
|
|
9
|
+
import { PdfBrush } from './brushes/pdf-brush';
|
|
10
|
+
import { PdfSolidBrush } from './brushes/pdf-solid-brush';
|
|
11
|
+
import { PdfFont } from './fonts/pdf-font';
|
|
12
|
+
import { PdfStandardFont } from './fonts/pdf-standard-font';
|
|
13
|
+
import { PdfTransformationMatrix, Matrix } from './pdf-transformation-matrix';
|
|
14
|
+
import { PointF, SizeF, RectangleF } from './../drawing/pdf-drawing';
|
|
15
|
+
import { ProcedureSets } from './constants';
|
|
16
|
+
import { PdfStream } from './../primitives/pdf-stream';
|
|
17
|
+
import { PdfString } from './../primitives/pdf-string';
|
|
18
|
+
import { PdfName } from './../primitives/pdf-name';
|
|
19
|
+
import { PdfArray } from './../primitives/pdf-array';
|
|
20
|
+
import { PdfStringFormat } from './fonts/pdf-string-format';
|
|
21
|
+
import { TemporaryDictionary } from './../collections/object-object-pair/dictionary';
|
|
22
|
+
import { PdfTransparency } from './pdf-transparency';
|
|
23
|
+
import { PdfStringLayouter, PdfStringLayoutResult, LineType } from './fonts/string-layouter';
|
|
24
|
+
import { PdfPageLayer } from './../pages/pdf-page-layer';
|
|
25
|
+
import { PdfPageBase } from './../pages/pdf-page-base';
|
|
26
|
+
import { PdfPage } from './../pages/pdf-page';
|
|
27
|
+
import { DictionaryProperties } from './../input-output/pdf-dictionary-properties';
|
|
28
|
+
import { StringTokenizer } from './fonts/string-tokenizer';
|
|
29
|
+
import { PdfResources } from './pdf-resources';
|
|
30
|
+
import { LineInfo } from './fonts/string-layouter';
|
|
31
|
+
import { PdfImage } from './images/pdf-image';
|
|
32
|
+
import { PdfAutomaticFieldInfoCollection } from './../document/automatic-fields/automatic-field-info-collection';
|
|
33
|
+
import { PdfAutomaticFieldInfo } from './../document/automatic-fields/automatic-field-info';
|
|
34
|
+
import { PdfTemplate } from './figures/pdf-template';
|
|
35
|
+
import { PdfCrossTable } from './../input-output/pdf-cross-table';
|
|
36
|
+
import { PdfSection } from './../pages/pdf-section';
|
|
37
|
+
import { Operators } from './../input-output/pdf-operators';
|
|
38
|
+
import { PdfTrueTypeFont } from './fonts/pdf-true-type-font';
|
|
39
|
+
import { UnicodeTrueTypeFont } from './fonts/unicode-true-type-font';
|
|
40
|
+
import { TtfReader } from './fonts/ttf-reader';
|
|
41
|
+
import { InternalEnum } from './../primitives/pdf-string';
|
|
42
|
+
import { RtlRenderer } from './fonts/rtl-renderer';
|
|
43
|
+
import { PdfTextDirection } from './enum';
|
|
44
|
+
import { PathPointType } from './figures/enum';
|
|
45
|
+
import { PdfPath } from './figures/path';
|
|
46
|
+
import { PdfGradientBrush } from './../../implementation/graphics/brushes/pdf-gradient-brush';
|
|
47
|
+
import { PdfTilingBrush } from './brushes/pdf-tiling-brush';
|
|
48
|
+
/**
|
|
49
|
+
* `PdfGraphics` class represents a graphics context of the objects.
|
|
50
|
+
* It's used for performing all the graphics operations.
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // create a new PDF document
|
|
53
|
+
* let document : PdfDocument = new PdfDocument();
|
|
54
|
+
* // add a new page to the document
|
|
55
|
+
* let page1 : PdfPage = document.pages.add();
|
|
56
|
+
* // set the font
|
|
57
|
+
* let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
|
|
58
|
+
* // create black brush
|
|
59
|
+
* let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
|
|
60
|
+
* //
|
|
61
|
+
* //graphics of the page
|
|
62
|
+
* let page1Graphics : PdfGraphics = page1.graphics;
|
|
63
|
+
* // draw the text on the page1 graphics
|
|
64
|
+
* page1Graphics.drawString('Hello World', font, blackBrush, new PointF(0, 0));
|
|
65
|
+
* //
|
|
66
|
+
* // save the document
|
|
67
|
+
* document.save('output.pdf');
|
|
68
|
+
* // destroy the document
|
|
69
|
+
* document.destroy();
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export class PdfGraphics {
|
|
73
|
+
// Constants
|
|
74
|
+
/**
|
|
75
|
+
* Specifies the mask of `path type values`.
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
private static readonly pathTypesValuesMask : number = 0xf;
|
|
79
|
+
// Fields
|
|
80
|
+
/**
|
|
81
|
+
* Represents the `Stream writer` object.
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private pdfStreamWriter : PdfStreamWriter;
|
|
85
|
+
/**
|
|
86
|
+
* Represents the state, whether it `is saved or not`.
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
private bStateSaved : boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Represents the `Current pen`.
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
private currentPen : PdfPen;
|
|
95
|
+
/**
|
|
96
|
+
* Represents the `Current brush`.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
private currentBrush : PdfBrush;
|
|
100
|
+
/**
|
|
101
|
+
* Represents the `Current font`.
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
private currentFont : PdfFont;
|
|
105
|
+
/**
|
|
106
|
+
* Represents the `Current font`.
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
public currentPage : PdfPage;
|
|
110
|
+
/**
|
|
111
|
+
* Represents the `Current color space`.
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
private currentColorSpace : PdfColorSpace = PdfColorSpace.Rgb;
|
|
115
|
+
/**
|
|
116
|
+
* The `transformation matrix` monitoring all changes with CTM.
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private transformationMatrix : PdfTransformationMatrix;
|
|
120
|
+
/**
|
|
121
|
+
* Stores `previous rendering mode`.
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
private previousTextRenderingMode : TextRenderingMode = TextRenderingMode.Fill;
|
|
125
|
+
/**
|
|
126
|
+
* Previous `character spacing` value or 0.
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
private previousCharacterSpacing : number = 0.0;
|
|
130
|
+
/**
|
|
131
|
+
* Previous `word spacing` value or 0.
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
private previousWordSpacing : number = 0.0;
|
|
135
|
+
/**
|
|
136
|
+
* The `previously used text scaling` value.
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
private previousTextScaling : number = 100.0;
|
|
140
|
+
/**
|
|
141
|
+
* Event handler object to store instance of `PdfResources` class.
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
private getResources : GetResourceEventHandler;
|
|
145
|
+
/**
|
|
146
|
+
* Indicates whether `color space was initialized`.
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
private bCSInitialized : boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Represents the `Size of the canvas`.
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
private canvasSize : SizeF;
|
|
155
|
+
/**
|
|
156
|
+
* Represents the size of the canvas reduced by `margins and templates`.
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
public clipBounds : RectangleF;
|
|
160
|
+
// private trasparencies : Dictionary<TransparencyData, PdfTransparency>;
|
|
161
|
+
/**
|
|
162
|
+
* Current `string format`.
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
private currentStringFormat : PdfStringFormat;
|
|
166
|
+
/**
|
|
167
|
+
* Instance of `ProcedureSets` class.
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
private procedureSets : ProcedureSets = new ProcedureSets();
|
|
171
|
+
/**
|
|
172
|
+
* To check wihether it is a `direct text rendering`.
|
|
173
|
+
* @default true
|
|
174
|
+
* @private
|
|
175
|
+
*/
|
|
176
|
+
private isNormalRender : boolean = true;
|
|
177
|
+
/**
|
|
178
|
+
* check whether to `use font size` to calculate the shift.
|
|
179
|
+
* @default false
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
private isUseFontSize : boolean = false;
|
|
183
|
+
/**
|
|
184
|
+
* check whether the font is in `italic type`.
|
|
185
|
+
* @default false
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
private isItalic : boolean = false;
|
|
189
|
+
/**
|
|
190
|
+
* Check whether it is an `emf Text Matrix`.
|
|
191
|
+
* @default false
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
public isEmfTextScaled : boolean = false;
|
|
195
|
+
/**
|
|
196
|
+
* Check whether it is an `emf` call.
|
|
197
|
+
* @default false
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
public isEmf : boolean = false;
|
|
201
|
+
/**
|
|
202
|
+
* Check whether it is an `emf plus` call.
|
|
203
|
+
* @default false
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
public isEmfPlus : boolean = false;
|
|
207
|
+
/**
|
|
208
|
+
* Check whether it is in `base line format`.
|
|
209
|
+
* @default true
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
public isBaselineFormat : boolean = true;
|
|
213
|
+
/**
|
|
214
|
+
* Emf Text `Scaling Factor`.
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
public emfScalingFactor : SizeF = new SizeF(0, 0);
|
|
218
|
+
/**
|
|
219
|
+
* Internal variable to store `layout result` after drawing string.
|
|
220
|
+
* @private
|
|
221
|
+
*/
|
|
222
|
+
private pdfStringLayoutResult : PdfStringLayoutResult;
|
|
223
|
+
/**
|
|
224
|
+
* Internal variable to store `layer` on which this graphics lays.
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
private pageLayer : PdfPageLayer;
|
|
228
|
+
/**
|
|
229
|
+
* To check whether the `last color space` of document and garphics is saved.
|
|
230
|
+
* @private
|
|
231
|
+
*/
|
|
232
|
+
private colorSpaceChanged : boolean = false;
|
|
233
|
+
/**
|
|
234
|
+
* Media box upper right `bound`.
|
|
235
|
+
* @hidden
|
|
236
|
+
* @private
|
|
237
|
+
*/
|
|
238
|
+
private internalMediaBoxUpperRightBound : number;
|
|
239
|
+
/**
|
|
240
|
+
* Holds instance of PdfArray as `cropBox`.
|
|
241
|
+
* @private
|
|
242
|
+
*/
|
|
243
|
+
public cropBox : PdfArray;
|
|
244
|
+
/**
|
|
245
|
+
* Checks whether the object is `transparencyObject`.
|
|
246
|
+
* @hidden
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
private static transparencyObject : boolean = false;
|
|
250
|
+
/**
|
|
251
|
+
* Stores an instance of `DictionaryProperties`.
|
|
252
|
+
* @private
|
|
253
|
+
*/
|
|
254
|
+
private dictionaryProperties : DictionaryProperties = new DictionaryProperties();
|
|
255
|
+
/**
|
|
256
|
+
* `last document colorspace`.
|
|
257
|
+
* @hidden
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
private lastDocumentCS : PdfColorSpace;
|
|
261
|
+
/**
|
|
262
|
+
* `last graphics's colorspace`.
|
|
263
|
+
* @hidden
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
private lastGraphicsCS : PdfColorSpace;
|
|
267
|
+
/**
|
|
268
|
+
* Checks whether the x co-ordinate is need to set as client size or not.
|
|
269
|
+
* @hidden
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
private isOverloadWithPosition : boolean = false;
|
|
273
|
+
/**
|
|
274
|
+
* Checks whether the x co-ordinate is need to set as client size or not.
|
|
275
|
+
* @hidden
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
private isPointOverload : boolean = false;
|
|
279
|
+
/**
|
|
280
|
+
* Current colorspaces.
|
|
281
|
+
* @hidden
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
private currentColorSpaces : string[] = ['RGB', 'CMYK', 'GrayScale', 'Indexed'];
|
|
285
|
+
/**
|
|
286
|
+
* Checks the current image `is optimized` or not.
|
|
287
|
+
* @default false.
|
|
288
|
+
* @private
|
|
289
|
+
*/
|
|
290
|
+
public isImageOptimized : boolean = false;
|
|
291
|
+
/**
|
|
292
|
+
* Returns the `current graphics state`.
|
|
293
|
+
* @private
|
|
294
|
+
*/
|
|
295
|
+
private gState : PdfGraphicsState;
|
|
296
|
+
/**
|
|
297
|
+
* Stores the `graphics states`.
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
private graphicsState : PdfGraphicsState[] = [];
|
|
301
|
+
/**
|
|
302
|
+
* Stores the `trasparencies`.
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
private trasparencies : TemporaryDictionary<TransparencyData, PdfTransparency>;
|
|
306
|
+
/**
|
|
307
|
+
* Indicates whether the object `had trasparency`.
|
|
308
|
+
* @default false
|
|
309
|
+
* @private
|
|
310
|
+
*/
|
|
311
|
+
private istransparencySet : boolean = false;
|
|
312
|
+
/**
|
|
313
|
+
* Stores the instance of `PdfAutomaticFieldInfoCollection` class .
|
|
314
|
+
* @default null
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
private internalAutomaticFields : PdfAutomaticFieldInfoCollection = null;
|
|
318
|
+
/**
|
|
319
|
+
* Stores shift value for draw string with `PointF` overload.
|
|
320
|
+
* @private
|
|
321
|
+
* @hidden
|
|
322
|
+
*/
|
|
323
|
+
private shift : number;
|
|
324
|
+
/**
|
|
325
|
+
* Stores the index of the start line that should draw with in the next page.
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
328
|
+
private startCutIndex : number = -1;
|
|
329
|
+
// Properties
|
|
330
|
+
/**
|
|
331
|
+
* Returns the `result` after drawing string.
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
public get stringLayoutResult() : PdfStringLayoutResult {
|
|
335
|
+
return this.pdfStringLayoutResult;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Gets the `size` of the canvas.
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
public get size() : SizeF {
|
|
342
|
+
return this.canvasSize;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Gets and Sets the value of `MediaBox upper right bound`.
|
|
346
|
+
* @private
|
|
347
|
+
*/
|
|
348
|
+
public get mediaBoxUpperRightBound() : number {
|
|
349
|
+
if (typeof this.internalMediaBoxUpperRightBound === 'undefined') {
|
|
350
|
+
this.internalMediaBoxUpperRightBound = 0;
|
|
351
|
+
}
|
|
352
|
+
return this.internalMediaBoxUpperRightBound;
|
|
353
|
+
}
|
|
354
|
+
public set mediaBoxUpperRightBound(value : number) {
|
|
355
|
+
this.internalMediaBoxUpperRightBound = value;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Gets the `size` of the canvas reduced by margins and page templates.
|
|
359
|
+
* @private
|
|
360
|
+
*/
|
|
361
|
+
public get clientSize() : SizeF {
|
|
362
|
+
return new SizeF(this.clipBounds.width, this.clipBounds.height);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Gets or sets the current `color space` of the document
|
|
366
|
+
* @private
|
|
367
|
+
*/
|
|
368
|
+
public get colorSpace() : PdfColorSpace {
|
|
369
|
+
return this.currentColorSpace;
|
|
370
|
+
}
|
|
371
|
+
public set colorSpace(value : PdfColorSpace) {
|
|
372
|
+
this.currentColorSpace = value;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Gets the `stream writer`.
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
public get streamWriter() : PdfStreamWriter {
|
|
379
|
+
return this.pdfStreamWriter;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Gets the `transformation matrix` reflecting current transformation.
|
|
383
|
+
* @private
|
|
384
|
+
*/
|
|
385
|
+
public get matrix() : PdfTransformationMatrix {
|
|
386
|
+
if (this.transformationMatrix == null) {
|
|
387
|
+
this.transformationMatrix = new PdfTransformationMatrix();
|
|
388
|
+
}
|
|
389
|
+
return this.transformationMatrix;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Gets the `layer` for the graphics, if exists.
|
|
393
|
+
* @private
|
|
394
|
+
*/
|
|
395
|
+
public get layer() : PdfPageLayer {
|
|
396
|
+
return this.pageLayer;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Gets the `page` for this graphics, if exists.
|
|
400
|
+
* @private
|
|
401
|
+
*/
|
|
402
|
+
public get page() : PdfPageBase {
|
|
403
|
+
return this.pageLayer.page;
|
|
404
|
+
}
|
|
405
|
+
public get automaticFields() : PdfAutomaticFieldInfoCollection {
|
|
406
|
+
if (this.internalAutomaticFields == null || typeof this.internalAutomaticFields === 'undefined') {
|
|
407
|
+
this.internalAutomaticFields = new PdfAutomaticFieldInfoCollection();
|
|
408
|
+
}
|
|
409
|
+
return this.internalAutomaticFields;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Initializes a new instance of the `PdfGraphics` class.
|
|
413
|
+
* @private
|
|
414
|
+
*/
|
|
415
|
+
public constructor(size : SizeF, resources : GetResourceEventHandler, writer : PdfStreamWriter)
|
|
416
|
+
/**
|
|
417
|
+
* Initializes a new instance of the `PdfGraphics` class.
|
|
418
|
+
* @private
|
|
419
|
+
*/
|
|
420
|
+
public constructor(size : SizeF, resources : GetResourceEventHandler, stream : PdfStream)
|
|
421
|
+
public constructor(arg1 : SizeF, arg2 : GetResourceEventHandler, arg3 : PdfStream | PdfStreamWriter) {
|
|
422
|
+
this.getResources = arg2 as GetResourceEventHandler;
|
|
423
|
+
this.canvasSize = arg1;
|
|
424
|
+
if (arg3 instanceof PdfStreamWriter) {
|
|
425
|
+
this.pdfStreamWriter = arg3;
|
|
426
|
+
} else {
|
|
427
|
+
this.pdfStreamWriter = new PdfStreamWriter(arg3);
|
|
428
|
+
}
|
|
429
|
+
this.initialize();
|
|
430
|
+
}
|
|
431
|
+
//Implementation
|
|
432
|
+
/**
|
|
433
|
+
* `Initializes` this instance.
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
public initialize() : void {
|
|
437
|
+
this.bStateSaved = false;
|
|
438
|
+
this.currentPen = null;
|
|
439
|
+
this.currentBrush = null;
|
|
440
|
+
this.currentFont = null;
|
|
441
|
+
this.currentColorSpace = PdfColorSpace.Rgb;
|
|
442
|
+
this.bCSInitialized = false;
|
|
443
|
+
this.transformationMatrix = null;
|
|
444
|
+
this.previousTextRenderingMode = <TextRenderingMode>(-1); //.Fill;
|
|
445
|
+
this.previousCharacterSpacing = -1.0;
|
|
446
|
+
this.previousWordSpacing = -1.0;
|
|
447
|
+
this.previousTextScaling = -100.0;
|
|
448
|
+
// this.m_trasparencies = null;
|
|
449
|
+
this.currentStringFormat = null;
|
|
450
|
+
this.clipBounds = new RectangleF(new PointF(0, 0), this.size);
|
|
451
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.pdf);
|
|
452
|
+
}
|
|
453
|
+
// Public methods
|
|
454
|
+
/* tslint:disable */
|
|
455
|
+
/**
|
|
456
|
+
* `Draw the template`.
|
|
457
|
+
* @private
|
|
458
|
+
*/
|
|
459
|
+
public drawPdfTemplate(template : PdfTemplate, location : PointF) : void
|
|
460
|
+
public drawPdfTemplate(template : PdfTemplate, location : PointF, size : SizeF) : void
|
|
461
|
+
public drawPdfTemplate(template : PdfTemplate, location : PointF, size ?: SizeF) : void {
|
|
462
|
+
if (typeof size === 'undefined') {
|
|
463
|
+
if (template == null) {
|
|
464
|
+
throw Error('ArgumentNullException-template');
|
|
465
|
+
}
|
|
466
|
+
this.drawPdfTemplate(template, location, template.size);
|
|
467
|
+
} else {
|
|
468
|
+
// let crossTable : PdfCrossTable = null;
|
|
469
|
+
// if (this.pageLayer != null) {
|
|
470
|
+
// crossTable = (this.page as PdfPage).section.parentDocument.crossTable;
|
|
471
|
+
// }
|
|
472
|
+
if (template == null) {
|
|
473
|
+
throw Error('ArgumentNullException-template');
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
let scaleX : number = (template.width > 0) ? size.width / template.width : 1;
|
|
477
|
+
let scaleY : number = (template.height > 0) ? size.height / template.height : 1;
|
|
478
|
+
let bNeedScale : boolean = !(scaleX === 1 && scaleY === 1);
|
|
479
|
+
// Save state.
|
|
480
|
+
let state : PdfGraphicsState = this.save();
|
|
481
|
+
// Take into consideration that rect location is bottom/left.
|
|
482
|
+
let matrix : PdfTransformationMatrix = new PdfTransformationMatrix();
|
|
483
|
+
if (this.pageLayer != null) {
|
|
484
|
+
this.getTranslateTransform(location.x, location.y + size.height, matrix);
|
|
485
|
+
}
|
|
486
|
+
if (bNeedScale) {
|
|
487
|
+
this.getScaleTransform(scaleX, scaleY, matrix);
|
|
488
|
+
}
|
|
489
|
+
this.pdfStreamWriter.modifyCtm(matrix);
|
|
490
|
+
// Output template.
|
|
491
|
+
let resources : PdfResources = this.getResources.getResources();
|
|
492
|
+
let name : PdfName = resources.getName(template);
|
|
493
|
+
this.pdfStreamWriter.executeObject(name);
|
|
494
|
+
// Restore state.
|
|
495
|
+
this.restore(state);
|
|
496
|
+
//Transfer automatic fields from template.
|
|
497
|
+
let g : PdfGraphics = template.graphics;
|
|
498
|
+
if (g != null) {
|
|
499
|
+
for (let index : number = 0; index < g.automaticFields.automaticFields.length; index++) {
|
|
500
|
+
let fieldInfo : PdfAutomaticFieldInfo = g.automaticFields.automaticFields[index] as PdfAutomaticFieldInfo;
|
|
501
|
+
let newLocation : PointF = new PointF(fieldInfo.location.x + location.x, fieldInfo.location.y + location.y);
|
|
502
|
+
let scalingX : number = template.size.width == 0 ? 0 : size.width / template.size.width;
|
|
503
|
+
let scalingY : number = template.size.height == 0 ? 0 : size.height / template.size.height;
|
|
504
|
+
this.automaticFields.add(new PdfAutomaticFieldInfo(fieldInfo.field, newLocation, scalingX, scalingY));
|
|
505
|
+
this.page.dictionary.modify();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageB);
|
|
509
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageC);
|
|
510
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.imageI);
|
|
511
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// DrawString overloads
|
|
515
|
+
/**
|
|
516
|
+
* `Draws the specified text` at the specified location and size with string format.
|
|
517
|
+
* ```typescript
|
|
518
|
+
* // create a new PDF document
|
|
519
|
+
* let document : PdfDocument = new PdfDocument();
|
|
520
|
+
* // add a pages to the document
|
|
521
|
+
* let page1 : PdfPage = document.pages.add();
|
|
522
|
+
* // set font
|
|
523
|
+
* let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
|
|
524
|
+
* // set pen
|
|
525
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(255, 0, 0));
|
|
526
|
+
* // set brush
|
|
527
|
+
* let brush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
|
|
528
|
+
* // set rectangle bounds
|
|
529
|
+
* let rectangle : RectangleF = new RectangleF({x : 10, y : 10}, {width : 200, height : 200});
|
|
530
|
+
* // set the format for string
|
|
531
|
+
* let stringFormat : PdfStringFormat = new PdfStringFormat();
|
|
532
|
+
* // set the text alignment
|
|
533
|
+
* stringFormat.alignment = PdfTextAlignment.Center;
|
|
534
|
+
* // set the vertical alignment
|
|
535
|
+
* stringFormat.lineAlignment = PdfVerticalAlignment.Middle;
|
|
536
|
+
* //
|
|
537
|
+
* // draw the text
|
|
538
|
+
* page1.graphics.drawString('Hello World', font, pen, brush, rectangle, stringFormat);
|
|
539
|
+
* //
|
|
540
|
+
* // save the document
|
|
541
|
+
* document.save('output.pdf');
|
|
542
|
+
* // destroy the document
|
|
543
|
+
* document.destroy();
|
|
544
|
+
* ```
|
|
545
|
+
* @param s Input text.
|
|
546
|
+
* @param font Font of the text.
|
|
547
|
+
* @param pen Color of the text.
|
|
548
|
+
* @param brush Color of the text.
|
|
549
|
+
* @param layoutRectangle RectangleF structure that specifies the bounds of the drawn text.
|
|
550
|
+
* @param format String formatting information.
|
|
551
|
+
*/
|
|
552
|
+
public drawString(s : string, font : PdfFont, pen : PdfPen, brush : PdfBrush, x : number, y : number, format : PdfStringFormat) : void
|
|
553
|
+
public drawString(s : string, font : PdfFont, pen : PdfPen, brush : PdfBrush, x : number, y : number, width : number, height : number, format : PdfStringFormat) : void
|
|
554
|
+
/* tslint:disable */
|
|
555
|
+
/**
|
|
556
|
+
* @public
|
|
557
|
+
*/
|
|
558
|
+
public drawString(arg1 : string, arg2 : PdfFont, arg3 : PdfPen, arg4 : PdfBrush, arg5 : number, arg6 : number, arg7 : number|PdfStringFormat, arg8 ?: number, arg9 ?: PdfStringFormat) : void {
|
|
559
|
+
if (typeof arg1 === 'string' && arg2 instanceof PdfFont && (arg3 instanceof PdfPen || arg3 === null) && (arg4 instanceof PdfBrush || arg4 === null) && typeof arg5 === 'number' && typeof arg6 === 'number' && (arg7 instanceof PdfStringFormat || arg7 === null) && typeof arg8 === 'undefined') {
|
|
560
|
+
this.isOverloadWithPosition = true;
|
|
561
|
+
this.drawString(arg1, arg2, arg3, arg4, arg5, arg6, (this.clientSize.width - arg5), 0, arg7 as PdfStringFormat);
|
|
562
|
+
} else {
|
|
563
|
+
let temparg3 : PdfPen = arg3 as PdfPen;
|
|
564
|
+
let temparg4 : PdfBrush = arg4 as PdfBrush;
|
|
565
|
+
let temparg5 : number = arg5 as number;
|
|
566
|
+
let temparg6 : number = arg6 as number;
|
|
567
|
+
let temparg7 : number = arg7 as number;
|
|
568
|
+
let temparg8 : number = arg8 as number;
|
|
569
|
+
let temparg9 : PdfStringFormat = arg9 as PdfStringFormat;
|
|
570
|
+
let layouter : PdfStringLayouter = new PdfStringLayouter();
|
|
571
|
+
let result : PdfStringLayoutResult = layouter.layout(arg1, arg2, temparg9, new SizeF(temparg7, temparg8), this.isOverloadWithPosition, this.clientSize);
|
|
572
|
+
if (!result.empty) {
|
|
573
|
+
let rect : RectangleF = this.checkCorrectLayoutRectangle(result.actualSize, temparg5, temparg6, temparg9);
|
|
574
|
+
if (temparg7 <= 0) {
|
|
575
|
+
temparg5 = rect.x;
|
|
576
|
+
temparg7 = rect.width;
|
|
577
|
+
}
|
|
578
|
+
if (temparg8 <= 0) {
|
|
579
|
+
temparg6 = rect.y;
|
|
580
|
+
temparg8 = rect.height;
|
|
581
|
+
}
|
|
582
|
+
this.drawStringLayoutResult(result, arg2, temparg3, temparg4, new RectangleF(temparg5, temparg6, temparg7, temparg8), temparg9);
|
|
583
|
+
this.isEmfTextScaled = false;
|
|
584
|
+
this.emfScalingFactor = new SizeF(0, 0);
|
|
585
|
+
}
|
|
586
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
|
|
587
|
+
this.isNormalRender = true;
|
|
588
|
+
this.pdfStringLayoutResult = result;
|
|
589
|
+
this.isUseFontSize = false;
|
|
590
|
+
}
|
|
591
|
+
}/* tslint:enable */
|
|
592
|
+
//DrawLine overloads
|
|
593
|
+
/**
|
|
594
|
+
* `Draws a line` connecting the two points specified by the coordinate pairs.
|
|
595
|
+
* ```typescript
|
|
596
|
+
* // create a new PDF document
|
|
597
|
+
* let document : PdfDocument = new PdfDocument();
|
|
598
|
+
* // create a new page
|
|
599
|
+
* let page1 : PdfPage = document.pages.add();
|
|
600
|
+
* //
|
|
601
|
+
* // draw the line
|
|
602
|
+
* page1.graphics.drawLine(new PdfPen(new PdfColor(0, 0, 255)), new PointF(10, 20), new PointF(100, 200));
|
|
603
|
+
* //
|
|
604
|
+
* // save the document.
|
|
605
|
+
* document.save('output.pdf');
|
|
606
|
+
* // destroy the document
|
|
607
|
+
* document.destroy();
|
|
608
|
+
* ```
|
|
609
|
+
* @param pen Color of the line.
|
|
610
|
+
* @param point1 PointF structure that represents the first point to connect.
|
|
611
|
+
* @param point2 PointF structure that represents the second point to connect.
|
|
612
|
+
*/
|
|
613
|
+
public drawLine(pen : PdfPen, point1 : PointF, point2 : PointF) : void
|
|
614
|
+
/**
|
|
615
|
+
* `Draws a line` connecting the two points specified by the coordinate pairs.
|
|
616
|
+
* ```typescript
|
|
617
|
+
* // create a new PDF document
|
|
618
|
+
* let document : PdfDocument = new PdfDocument();
|
|
619
|
+
* // create a new page
|
|
620
|
+
* let page1 : PdfPage = document.pages.add();
|
|
621
|
+
* //
|
|
622
|
+
* // draw the line
|
|
623
|
+
* page1.graphics.drawLine(new PdfPen(new PdfColor(0, 0, 255)), 10, 20, 100, 200);
|
|
624
|
+
* //
|
|
625
|
+
* // save the document.
|
|
626
|
+
* document.save('output.pdf');
|
|
627
|
+
* // destroy the document
|
|
628
|
+
* document.destroy();
|
|
629
|
+
* ```
|
|
630
|
+
* @param pen Color of the line.
|
|
631
|
+
* @param x1 The x-coordinate of the first point.
|
|
632
|
+
* @param y1 The y-coordinate of the first point.
|
|
633
|
+
* @param x2 The x-coordinate of the second point.
|
|
634
|
+
* @param y2 The y-coordinate of the second point.
|
|
635
|
+
*/
|
|
636
|
+
public drawLine(pen : PdfPen, x1 : number, y1 : number, x2 : number, y2 : number) : void
|
|
637
|
+
public drawLine(arg1 : PdfPen, arg2 : number | PointF, arg3 : number | PointF, arg4 ?: number, arg5 ?: number) : void {
|
|
638
|
+
if (arg2 instanceof PointF) {
|
|
639
|
+
let temparg2 : PointF = arg2 as PointF;
|
|
640
|
+
let temparg3 : PointF = arg3 as PointF;
|
|
641
|
+
this.drawLine(arg1, temparg2.x, temparg2.y, temparg3.x, temparg3.y);
|
|
642
|
+
} else {
|
|
643
|
+
let temparg2 : number = arg2 as number;
|
|
644
|
+
let temparg3 : number = arg3 as number;
|
|
645
|
+
let temparg4 : number = arg4 as number;
|
|
646
|
+
let temparg5 : number = arg5 as number;
|
|
647
|
+
this.stateControl(arg1, null, null);
|
|
648
|
+
let sw : PdfStreamWriter = this.streamWriter;
|
|
649
|
+
sw.beginPath(temparg2, temparg3);
|
|
650
|
+
sw.appendLineSegment(temparg4, temparg5);
|
|
651
|
+
sw.strokePath();
|
|
652
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.pdf);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// DrawRectangle overloads
|
|
657
|
+
/**
|
|
658
|
+
* `Draws a rectangle` specified by a pen, a coordinate pair, a width, and a height.
|
|
659
|
+
* ```typescript
|
|
660
|
+
* // create a new PDF document.
|
|
661
|
+
* let document : PdfDocument = new PdfDocument();
|
|
662
|
+
* // create a new page
|
|
663
|
+
* let page1 : PdfPage = document.pages.add();
|
|
664
|
+
* // create pen for draw rectangle
|
|
665
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(238, 130, 238));
|
|
666
|
+
* //
|
|
667
|
+
* // draw rectangle
|
|
668
|
+
* page1.graphics.drawRectangle(pen, 10, 10, 50, 100);
|
|
669
|
+
* //
|
|
670
|
+
* // save the document
|
|
671
|
+
* document.save('output.pdf');
|
|
672
|
+
* // destroy the document
|
|
673
|
+
* document.destroy();
|
|
674
|
+
* ```
|
|
675
|
+
* @param pen Color of the rectangle.
|
|
676
|
+
* @param x The x-coordinate of the upper-left corner of the rectangle to draw.
|
|
677
|
+
* @param y The y-coordinate of the upper-left corner of the rectangle to draw.
|
|
678
|
+
* @param width Width of the rectangle to draw.
|
|
679
|
+
* @param height Height of the rectangle to draw.
|
|
680
|
+
*/
|
|
681
|
+
public drawRectangle(pen : PdfPen, x : number, y : number, width : number, height : number) : void
|
|
682
|
+
/**
|
|
683
|
+
* `Draws a rectangle` specified by a brush, coordinate pair, a width, and a height.
|
|
684
|
+
* ```typescript
|
|
685
|
+
* // create a new PDF document.
|
|
686
|
+
* let document : PdfDocument = new PdfDocument();
|
|
687
|
+
* // create a new page
|
|
688
|
+
* let page1 : PdfPage = document.pages.add();
|
|
689
|
+
* // create brush for draw rectangle
|
|
690
|
+
* let brush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(238, 130, 238));
|
|
691
|
+
* //
|
|
692
|
+
* // draw rectangle
|
|
693
|
+
* page1.graphics.drawRectangle(brush, 10, 10, 50, 100);
|
|
694
|
+
* //
|
|
695
|
+
* // save the document
|
|
696
|
+
* document.save('output.pdf');
|
|
697
|
+
* // destroy the document
|
|
698
|
+
* document.destroy();
|
|
699
|
+
* ```
|
|
700
|
+
* @param brush Color of the rectangle.
|
|
701
|
+
* @param x The x-coordinate of the upper-left corner of the rectangle to draw.
|
|
702
|
+
* @param y The y-coordinate of the upper-left corner of the rectangle to draw.
|
|
703
|
+
* @param width Width of the rectangle to draw.
|
|
704
|
+
* @param height Height of the rectangle to draw.
|
|
705
|
+
*/
|
|
706
|
+
public drawRectangle(brush : PdfBrush, x : number, y : number, width : number, height : number) : void
|
|
707
|
+
/**
|
|
708
|
+
* `Draws a rectangle` specified by a pen, a coordinate pair, a width, and a height.
|
|
709
|
+
* ```typescript
|
|
710
|
+
* // create a new PDF document.
|
|
711
|
+
* let document : PdfDocument = new PdfDocument();
|
|
712
|
+
* // create a new page
|
|
713
|
+
* let page1 : PdfPage = document.pages.add();
|
|
714
|
+
* // create brush for draw rectangle
|
|
715
|
+
* let brush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(238, 130, 238));
|
|
716
|
+
* // set pen
|
|
717
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
718
|
+
* //
|
|
719
|
+
* // draw rectangle
|
|
720
|
+
* page1.graphics.drawRectangle(pen, brush, 10, 10, 50, 100);
|
|
721
|
+
* //
|
|
722
|
+
* // save the document
|
|
723
|
+
* document.save('output.pdf');
|
|
724
|
+
* // destroy the document
|
|
725
|
+
* document.destroy();
|
|
726
|
+
* ```
|
|
727
|
+
* @param pen A Pen that determines the color, width, and style of the rectangle.
|
|
728
|
+
* @param brush Color of the rectangle.
|
|
729
|
+
* @param x The x-coordinate of the upper-left corner of the rectangle to draw.
|
|
730
|
+
* @param y The y-coordinate of the upper-left corner of the rectangle to draw.
|
|
731
|
+
* @param width Width of the rectangle to draw.
|
|
732
|
+
* @param height Height of the rectangle to draw.
|
|
733
|
+
*/
|
|
734
|
+
public drawRectangle(pen : PdfPen, brush : PdfBrush, x : number, y : number, width : number, height : number) : void
|
|
735
|
+
/* tslint:disable */
|
|
736
|
+
public drawRectangle(arg1 : PdfPen|PdfBrush, arg2 : PdfBrush|number, arg3 : number, arg4 : number, arg5 : number, arg6 ?: number) : void {
|
|
737
|
+
if ( arg1 instanceof PdfPen && typeof arg2 === 'number' ) {
|
|
738
|
+
let temparg3 : number = arg3 as number;
|
|
739
|
+
this.drawRectangle(arg1, null, arg2, temparg3, arg4, arg5);
|
|
740
|
+
} else if ( arg1 instanceof PdfBrush && typeof arg2 === 'number' ) {
|
|
741
|
+
let temparg3 : number = arg3 as number;
|
|
742
|
+
this.drawRectangle(null, arg1, arg2, temparg3, arg4, arg5);
|
|
743
|
+
} else {
|
|
744
|
+
let temparg3 : number = arg3 as number;
|
|
745
|
+
let temparg4 : number = arg4 as number;
|
|
746
|
+
let temparg5 : number = arg5 as number;
|
|
747
|
+
let temparg6 : number = arg6 as number;
|
|
748
|
+
if ((arg2 instanceof PdfTilingBrush)) {
|
|
749
|
+
this.bCSInitialized = false;
|
|
750
|
+
let xOffset: number = (this.matrix.matrix.offsetX + temparg3);
|
|
751
|
+
let yOffset: number;
|
|
752
|
+
if (((this.layer != null) && (this.layer.page != null))) {
|
|
753
|
+
yOffset = ((this.layer.page.size.height - this.matrix.matrix.offsetY) + temparg4);
|
|
754
|
+
} else {
|
|
755
|
+
yOffset = ((this.clientSize.height - this.matrix.matrix.offsetY) + temparg4);
|
|
756
|
+
}
|
|
757
|
+
(<PdfTilingBrush>(arg2)).location = new PointF(xOffset, yOffset);
|
|
758
|
+
(<PdfTilingBrush>(arg2)).graphics.colorSpace = this.colorSpace;
|
|
759
|
+
} else if ((arg2 instanceof PdfGradientBrush)) {
|
|
760
|
+
(arg2 as PdfGradientBrush).colorSpace = this.colorSpace;
|
|
761
|
+
}
|
|
762
|
+
if (arg2 instanceof PdfSolidBrush && (<PdfSolidBrush>arg2).color.isEmpty) {
|
|
763
|
+
arg2 = null;
|
|
764
|
+
}
|
|
765
|
+
let temparg1 : PdfPen = <PdfPen>arg1;
|
|
766
|
+
let temparg2 : PdfBrush = <PdfBrush>arg2;
|
|
767
|
+
this.stateControl(temparg1, temparg2, null);
|
|
768
|
+
this.streamWriter.appendRectangle(temparg3, temparg4, temparg5, temparg6);
|
|
769
|
+
this.drawPathHelper(temparg1, temparg2, false);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* `Draws the path`.
|
|
775
|
+
* @private
|
|
776
|
+
*/
|
|
777
|
+
private drawPathHelper(pen : PdfPen, brush : PdfBrush, needClosing : boolean) : void
|
|
778
|
+
/**
|
|
779
|
+
* `Draws the path`.
|
|
780
|
+
* @private
|
|
781
|
+
*/
|
|
782
|
+
private drawPathHelper(pen : PdfPen, brush : PdfBrush, fillMode : PdfFillMode, needClosing : boolean) : void
|
|
783
|
+
private drawPathHelper(arg1 : PdfPen, arg2 : PdfBrush, arg3 : PdfFillMode|boolean, arg4 ?: boolean) : void {
|
|
784
|
+
if (typeof arg3 === 'boolean') {
|
|
785
|
+
let temparg3 : boolean = arg3 as boolean;
|
|
786
|
+
this.drawPathHelper(arg1, arg2, PdfFillMode.Winding, temparg3);
|
|
787
|
+
} else {
|
|
788
|
+
let temparg3 : PdfFillMode = arg3 as PdfFillMode;
|
|
789
|
+
let temparg4 : boolean = arg4 as boolean;
|
|
790
|
+
let isPen : boolean = arg1 != null;
|
|
791
|
+
let isBrush : boolean = arg2 != null;
|
|
792
|
+
let isEvenOdd : boolean = (temparg3 === PdfFillMode.Alternate);
|
|
793
|
+
if (isPen && isBrush) {
|
|
794
|
+
this.streamWriter.fillStrokePath(isEvenOdd);
|
|
795
|
+
} else if (!isPen && !isBrush) {
|
|
796
|
+
this.streamWriter.endPath();
|
|
797
|
+
} else if (isPen) {
|
|
798
|
+
this.streamWriter.strokePath();
|
|
799
|
+
} else {
|
|
800
|
+
this.streamWriter.fillPath(isEvenOdd);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
/* tslint:disable */
|
|
805
|
+
//DrawImage overloads
|
|
806
|
+
/**
|
|
807
|
+
* `Draws the specified image`, using its original physical size, at the location specified by a coordinate pair.
|
|
808
|
+
* ```typescript
|
|
809
|
+
* // create a new PDF document.
|
|
810
|
+
* let document : PdfDocument = new PdfDocument();
|
|
811
|
+
* // add a page to the document.
|
|
812
|
+
* let page1 : PdfPage = document.pages.add();
|
|
813
|
+
* // base64 string of an image
|
|
814
|
+
* let imageString : string = '/9j/3+2w7em7HzY/KiijFw … 1OEYRUYrQ45yc5OUtz/9k=';
|
|
815
|
+
* // load the image from the base64 string of original image.
|
|
816
|
+
* let image : PdfBitmap = new PdfBitmap(imageString);
|
|
817
|
+
* //
|
|
818
|
+
* // draw the image
|
|
819
|
+
* page1.graphics.drawImage(image, 10, 10);
|
|
820
|
+
* //
|
|
821
|
+
* // save the document.
|
|
822
|
+
* document.save('output.pdf');
|
|
823
|
+
* // destroy the document
|
|
824
|
+
* document.destroy();
|
|
825
|
+
* ```
|
|
826
|
+
* @param image PdfImage to draw.
|
|
827
|
+
* @param x The x-coordinate of the upper-left corner of the drawn image.
|
|
828
|
+
* @param y The y-coordinate of the upper-left corner of the drawn image.
|
|
829
|
+
*/
|
|
830
|
+
public drawImage(image : PdfImage, x : number, y : number) : void
|
|
831
|
+
/**
|
|
832
|
+
* `Draws the specified image`, using its original physical size, at the location specified by a coordinate pair.
|
|
833
|
+
* ```typescript
|
|
834
|
+
* // create a new PDF document.
|
|
835
|
+
* let document : PdfDocument = new PdfDocument();
|
|
836
|
+
* // add a page to the document.
|
|
837
|
+
* let page1 : PdfPage = document.pages.add();
|
|
838
|
+
* // base64 string of an image
|
|
839
|
+
* let imageString : string = '/9j/3+2w7em7HzY/KiijFw … 1OEYRUYrQ45yc5OUtz/9k=';
|
|
840
|
+
* // load the image from the base64 string of original image.
|
|
841
|
+
* let image : PdfBitmap = new PdfBitmap(imageString);
|
|
842
|
+
* //
|
|
843
|
+
* // draw the image
|
|
844
|
+
* page1.graphics.drawImage(image, 0, 0, 100, 100);
|
|
845
|
+
* //
|
|
846
|
+
* // save the document.
|
|
847
|
+
* document.save('output.pdf');
|
|
848
|
+
* // destroy the document
|
|
849
|
+
* document.destroy();
|
|
850
|
+
* ```
|
|
851
|
+
* @param image PdfImage to draw.
|
|
852
|
+
* @param x The x-coordinate of the upper-left corner of the drawn image.
|
|
853
|
+
* @param y The y-coordinate of the upper-left corner of the drawn image.
|
|
854
|
+
* @param width Width of the drawn image.
|
|
855
|
+
* @param height Height of the drawn image.
|
|
856
|
+
*/
|
|
857
|
+
public drawImage(image : PdfImage, x : number, y : number, width : number, height : number) : void
|
|
858
|
+
/* tslint:disable */
|
|
859
|
+
public drawImage(arg1 : PdfImage, arg2 : number, arg3 : number, arg4 ?: number, arg5 ?: number) : void {/* tslint:enable */
|
|
860
|
+
if (typeof arg2 === 'number' && typeof arg3 === 'number' && typeof arg4 === 'undefined') {
|
|
861
|
+
let size : SizeF = arg1.physicalDimension;
|
|
862
|
+
this.drawImage(arg1, arg2, arg3, size.width, size.height);
|
|
863
|
+
} else {
|
|
864
|
+
let temparg2 : number = arg2 as number;
|
|
865
|
+
let temparg3 : number = arg3 as number;
|
|
866
|
+
let temparg4 : number = arg4 as number;
|
|
867
|
+
let temparg5 : number = arg5 as number;
|
|
868
|
+
arg1.save();
|
|
869
|
+
let matrix : PdfTransformationMatrix = new PdfTransformationMatrix();
|
|
870
|
+
this.getTranslateTransform(temparg2, (temparg3 + temparg5), matrix);
|
|
871
|
+
this.getScaleTransform(arg4, arg5, matrix);
|
|
872
|
+
this.pdfStreamWriter.write('q');
|
|
873
|
+
this.pdfStreamWriter.modifyCtm(matrix);
|
|
874
|
+
// Output template.
|
|
875
|
+
let resources : PdfResources = this.getResources.getResources();
|
|
876
|
+
if (typeof this.pageLayer !== 'undefined' && (this.page as PdfPage) != null) {
|
|
877
|
+
resources.document = (this.page as PdfPage).document;
|
|
878
|
+
}
|
|
879
|
+
let name : PdfName = resources.getName(arg1);
|
|
880
|
+
if (typeof this.pageLayer !== 'undefined') {
|
|
881
|
+
this.page.setResources(resources);
|
|
882
|
+
}
|
|
883
|
+
this.pdfStreamWriter.executeObject(name);
|
|
884
|
+
this.pdfStreamWriter.write(Operators.restoreState);
|
|
885
|
+
this.pdfStreamWriter.write(Operators.newLine);
|
|
886
|
+
let resource : PdfResources = this.getResources.getResources();
|
|
887
|
+
resource.requireProcedureSet(this.procedureSets.imageB);
|
|
888
|
+
resource.requireProcedureSet(this.procedureSets.imageC);
|
|
889
|
+
resource.requireProcedureSet(this.procedureSets.imageI);
|
|
890
|
+
resource.requireProcedureSet(this.procedureSets.text);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
//Implementation
|
|
894
|
+
/* tslint:disable */
|
|
895
|
+
/**
|
|
896
|
+
* Returns `bounds` of the line info.
|
|
897
|
+
* @private
|
|
898
|
+
*/
|
|
899
|
+
public getLineBounds(lineIndex : number, result : PdfStringLayoutResult, font : PdfFont, layoutRectangle : RectangleF, format : PdfStringFormat) : RectangleF {/* tslint:enable */
|
|
900
|
+
let bounds : RectangleF;
|
|
901
|
+
if (!result.empty && lineIndex < result.lineCount && lineIndex >= 0) {
|
|
902
|
+
let line : LineInfo = result.lines[lineIndex];
|
|
903
|
+
let vShift : number = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
|
|
904
|
+
let y : number = vShift + layoutRectangle.y + (result.lineHeight * lineIndex);
|
|
905
|
+
let lineWidth : number = line.width;
|
|
906
|
+
let hShift : number = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
|
|
907
|
+
let lineIndent : number = this.getLineIndent(line, format, layoutRectangle, (lineIndex === 0));
|
|
908
|
+
hShift += (!this.rightToLeft(format)) ? lineIndent : 0;
|
|
909
|
+
let x : number = layoutRectangle.x + hShift;
|
|
910
|
+
/* tslint:disable */
|
|
911
|
+
let width : number = (!this.shouldJustify(line, layoutRectangle.width, format)) ? lineWidth - lineIndent : layoutRectangle.width - lineIndent;/* tslint:enable */
|
|
912
|
+
let height : number = result.lineHeight;
|
|
913
|
+
bounds = new RectangleF(x, y, width, height);
|
|
914
|
+
} else {
|
|
915
|
+
bounds = new RectangleF(0, 0, 0, 0);
|
|
916
|
+
}
|
|
917
|
+
return bounds;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Creates `lay outed rectangle` depending on the text settings.
|
|
921
|
+
* @private
|
|
922
|
+
*/
|
|
923
|
+
public checkCorrectLayoutRectangle(textSize : SizeF, x : number, y : number, format : PdfStringFormat) : RectangleF {
|
|
924
|
+
let layoutedRectangle : RectangleF = new RectangleF(x, y, textSize.width, textSize.width);
|
|
925
|
+
if (format != null) {
|
|
926
|
+
switch (format.alignment) {
|
|
927
|
+
case PdfTextAlignment.Center:
|
|
928
|
+
layoutedRectangle.x -= layoutedRectangle.width / 2;
|
|
929
|
+
break;
|
|
930
|
+
case PdfTextAlignment.Right:
|
|
931
|
+
layoutedRectangle.x -= layoutedRectangle.width;
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
934
|
+
switch (format.lineAlignment) {
|
|
935
|
+
case PdfVerticalAlignment.Middle:
|
|
936
|
+
layoutedRectangle.y -= layoutedRectangle.height / 2;
|
|
937
|
+
break;
|
|
938
|
+
case PdfVerticalAlignment.Bottom:
|
|
939
|
+
layoutedRectangle.y -= layoutedRectangle.height;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return layoutedRectangle;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Sets the `layer` for the graphics.
|
|
947
|
+
* @private
|
|
948
|
+
*/
|
|
949
|
+
public setLayer(layer : PdfPageLayer) : void {
|
|
950
|
+
this.pageLayer = layer;
|
|
951
|
+
let page : PdfPage = layer.page as PdfPage;
|
|
952
|
+
if (page != null && typeof page !== 'undefined') {
|
|
953
|
+
page.beginSave = this.pageSave;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Adding page number field before page saving.
|
|
958
|
+
* @private
|
|
959
|
+
*/
|
|
960
|
+
/* tslint:disable */
|
|
961
|
+
public pageSave(page : PdfPage) : void {
|
|
962
|
+
if (page.graphics.automaticFields != null) {
|
|
963
|
+
for (let i : number = 0; i < page.graphics.automaticFields.automaticFields.length; i++) {
|
|
964
|
+
let fieldInfo : PdfAutomaticFieldInfo = page.graphics.automaticFields.automaticFields[i] as PdfAutomaticFieldInfo;
|
|
965
|
+
fieldInfo.field.performDraw(page.graphics, fieldInfo.location, fieldInfo.scalingX, fieldInfo.scalingY);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* `Draws a layout result`.
|
|
971
|
+
* @private
|
|
972
|
+
*/
|
|
973
|
+
public drawStringLayoutResult(result : PdfStringLayoutResult, font : PdfFont, pen : PdfPen, brush : PdfBrush, layoutRectangle : RectangleF, format : PdfStringFormat) : void {
|
|
974
|
+
if (!result.empty) {
|
|
975
|
+
this.applyStringSettings(font, pen, brush, format, layoutRectangle);
|
|
976
|
+
// Set text scaling
|
|
977
|
+
let textScaling : number = (format != null) ? format.horizontalScalingFactor : 100.0;
|
|
978
|
+
if (textScaling !== this.previousTextScaling && !this.isEmfTextScaled) {
|
|
979
|
+
this.pdfStreamWriter.setTextScaling(textScaling);
|
|
980
|
+
this.previousTextScaling = textScaling;
|
|
981
|
+
}
|
|
982
|
+
let height : number = (format == null || format.lineSpacing === 0) ? font.height : format.lineSpacing + font.height;
|
|
983
|
+
let subScript : boolean = (format != null && format.subSuperScript === PdfSubSuperScript.SubScript);
|
|
984
|
+
let shift : number = 0;
|
|
985
|
+
shift = (subScript) ? height - (font.height + font.metrics.getDescent(format)) : (height - font.metrics.getAscent(format));
|
|
986
|
+
this.shift = shift;
|
|
987
|
+
this.pdfStreamWriter.startNextLine(layoutRectangle.x, layoutRectangle.y - shift);
|
|
988
|
+
this.pdfStreamWriter.setLeading(+height);
|
|
989
|
+
let resultHeight : number = 0;
|
|
990
|
+
let remainingString : string = '';
|
|
991
|
+
for (let i : number = 0; i < result.lines.length; i++) {
|
|
992
|
+
resultHeight += result.lineHeight;
|
|
993
|
+
if ((layoutRectangle.y + resultHeight) > this.clientSize.height) {
|
|
994
|
+
this.startCutIndex = i;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
for (let j : number = this.startCutIndex; (j < result.lines.length && j >= 0); j++) {
|
|
999
|
+
remainingString += result.lines[j].text;
|
|
1000
|
+
}
|
|
1001
|
+
let bounds : RectangleF = new RectangleF(layoutRectangle.x, layoutRectangle.y, layoutRectangle.width, layoutRectangle.height);
|
|
1002
|
+
this.drawLayoutResult(result, font, format, layoutRectangle);
|
|
1003
|
+
this.underlineStrikeoutText(pen, brush, result, font, bounds, format);
|
|
1004
|
+
this.isEmfPlus = false;
|
|
1005
|
+
this.isUseFontSize = false;
|
|
1006
|
+
if (this.startCutIndex !== -1) {
|
|
1007
|
+
let page : PdfPage = this.getNextPage();
|
|
1008
|
+
page.graphics.drawString(remainingString, font, pen, brush, layoutRectangle.x, 0, layoutRectangle.width, 0, format);
|
|
1009
|
+
}
|
|
1010
|
+
} else {
|
|
1011
|
+
throw new Error('ArgumentNullException:result');
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Gets the `next page`.
|
|
1016
|
+
* @private
|
|
1017
|
+
*/
|
|
1018
|
+
public getNextPage() : PdfPage {
|
|
1019
|
+
let section : PdfSection = this.currentPage.section;
|
|
1020
|
+
let nextPage : PdfPage = null;
|
|
1021
|
+
let index : number = section.indexOf(this.currentPage);
|
|
1022
|
+
if (index === section.count - 1) {
|
|
1023
|
+
nextPage = (section.add() as PdfPage);
|
|
1024
|
+
} else {
|
|
1025
|
+
nextPage = (section.getPages()[index + 1] as PdfPage);
|
|
1026
|
+
}
|
|
1027
|
+
return nextPage;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* `Sets the clipping` region of this Graphics to the rectangle specified by a RectangleF structure.
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* // create a new PDF document
|
|
1033
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1034
|
+
* // create a new page
|
|
1035
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1036
|
+
* // create PDF graphics for the page
|
|
1037
|
+
* let graphics : PdfGraphics = page1.graphics;
|
|
1038
|
+
* // set the font
|
|
1039
|
+
* let font : PdfFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
|
|
1040
|
+
* // create black brush
|
|
1041
|
+
* let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
|
|
1042
|
+
* //
|
|
1043
|
+
* // set clipping with rectangle bounds
|
|
1044
|
+
* graphics.setClip(new RectangleF({x : 10, y : 80}, {width : 150 , height : 15}));
|
|
1045
|
+
* //
|
|
1046
|
+
* // draw the text after clipping
|
|
1047
|
+
* graphics.drawString('Text after clipping', font, blackBrush, new PointF(10, 80));
|
|
1048
|
+
* // save the document.
|
|
1049
|
+
* document.save('output.pdf');
|
|
1050
|
+
* // destroy the document
|
|
1051
|
+
* document.destroy();
|
|
1052
|
+
* ```
|
|
1053
|
+
* @param rectangle RectangleF structure that represents the new clip region.
|
|
1054
|
+
*/
|
|
1055
|
+
public setClip(rectangle : RectangleF) : void
|
|
1056
|
+
/**
|
|
1057
|
+
* `Sets the clipping` region of this Graphics to the result of the specified operation combining the current clip region and the rectangle specified by a RectangleF structure.
|
|
1058
|
+
* @private
|
|
1059
|
+
*/
|
|
1060
|
+
public setClip(rectangle : RectangleF, mode : PdfFillMode) : void
|
|
1061
|
+
public setClip(rectangle : RectangleF, mode ?: PdfFillMode) : void {
|
|
1062
|
+
if (typeof mode === 'undefined') {
|
|
1063
|
+
this.setClip(rectangle, PdfFillMode.Winding);
|
|
1064
|
+
} else {
|
|
1065
|
+
this.pdfStreamWriter.appendRectangle(rectangle);
|
|
1066
|
+
this.pdfStreamWriter.clipPath((mode === PdfFillMode.Alternate));
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Applies all the `text settings`.
|
|
1071
|
+
* @private
|
|
1072
|
+
*/
|
|
1073
|
+
private applyStringSettings(font : PdfFont, pen : PdfPen, brush : PdfBrush, format : PdfStringFormat, bounds : RectangleF) : void {
|
|
1074
|
+
if ( brush instanceof PdfTilingBrush) {
|
|
1075
|
+
this.bCSInitialized = false;
|
|
1076
|
+
(<PdfTilingBrush>brush).graphics.colorSpace = this.colorSpace;
|
|
1077
|
+
} else if ((brush instanceof PdfGradientBrush)) {
|
|
1078
|
+
this.bCSInitialized = false;
|
|
1079
|
+
(<PdfGradientBrush>brush).colorSpace = this.colorSpace;
|
|
1080
|
+
}
|
|
1081
|
+
let setLineWidth : boolean = false;
|
|
1082
|
+
let tm : TextRenderingMode = this.getTextRenderingMode(pen, brush, format);
|
|
1083
|
+
this.stateControl(pen, brush, font, format);
|
|
1084
|
+
this.pdfStreamWriter.beginText();
|
|
1085
|
+
if ((tm) !== this.previousTextRenderingMode) {
|
|
1086
|
+
this.pdfStreamWriter.setTextRenderingMode(tm);
|
|
1087
|
+
this.previousTextRenderingMode = tm;
|
|
1088
|
+
}
|
|
1089
|
+
// Set character spacing.
|
|
1090
|
+
let cs : number = (format != null) ? format.characterSpacing : 0;
|
|
1091
|
+
if (cs !== this.previousCharacterSpacing && !this.isEmfTextScaled) {
|
|
1092
|
+
this.pdfStreamWriter.setCharacterSpacing(cs);
|
|
1093
|
+
this.previousCharacterSpacing = cs;
|
|
1094
|
+
}
|
|
1095
|
+
// Set word spacing.
|
|
1096
|
+
// NOTE: it works only if the space code is equal to 32 (0x20).
|
|
1097
|
+
let ws : number = (format != null) ? format.wordSpacing : 0;
|
|
1098
|
+
if (ws !== this.previousWordSpacing) {
|
|
1099
|
+
this.pdfStreamWriter.setWordSpacing(ws);
|
|
1100
|
+
this.previousWordSpacing = ws;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Calculates `shift value` if the text is vertically aligned.
|
|
1105
|
+
* @private
|
|
1106
|
+
*/
|
|
1107
|
+
public getTextVerticalAlignShift(textHeight : number, boundsHeight : number, format : PdfStringFormat) : number {
|
|
1108
|
+
let shift : number = 0;
|
|
1109
|
+
if (boundsHeight >= 0 && format != null && format.lineAlignment !== PdfVerticalAlignment.Top) {
|
|
1110
|
+
switch (format.lineAlignment) {
|
|
1111
|
+
case PdfVerticalAlignment.Middle:
|
|
1112
|
+
shift = (boundsHeight - textHeight) / 2;
|
|
1113
|
+
break;
|
|
1114
|
+
case PdfVerticalAlignment.Bottom:
|
|
1115
|
+
shift = boundsHeight - textHeight;
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
return shift;
|
|
1120
|
+
}
|
|
1121
|
+
/* tslint:disable */
|
|
1122
|
+
/**
|
|
1123
|
+
* `Draws layout result`.
|
|
1124
|
+
* @private
|
|
1125
|
+
*/
|
|
1126
|
+
private drawLayoutResult(result : PdfStringLayoutResult, font : PdfFont, format : PdfStringFormat, layoutRectangle : RectangleF) : void {/* tslint:enable */
|
|
1127
|
+
let vAlignShift : number = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
|
|
1128
|
+
if (vAlignShift !== 0) {
|
|
1129
|
+
this.pdfStreamWriter.startNextLine(0, vAlignShift);
|
|
1130
|
+
}
|
|
1131
|
+
let ttfFont : PdfTrueTypeFont = font as PdfTrueTypeFont;
|
|
1132
|
+
let unicode : boolean = (ttfFont != null && ttfFont.isUnicode);
|
|
1133
|
+
let embed : boolean = (ttfFont != null && ttfFont.isEmbedFont);
|
|
1134
|
+
let lines : LineInfo[] = result.lines;
|
|
1135
|
+
for (let i : number = 0, len : number = lines.length; (i < len && i !== this.startCutIndex); i++) {
|
|
1136
|
+
let lineInfo : LineInfo = lines[i];
|
|
1137
|
+
let line : string = lineInfo.text;
|
|
1138
|
+
let lineWidth : number = lineInfo.width;
|
|
1139
|
+
let hAlignShift : number = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
|
|
1140
|
+
let lineIndent : number = this.getLineIndent(lineInfo, format, layoutRectangle, (i === 0));
|
|
1141
|
+
hAlignShift += (!this.rightToLeft(format)) ? lineIndent : 0;
|
|
1142
|
+
if (hAlignShift !== 0 && !this.isEmfTextScaled) {
|
|
1143
|
+
this.pdfStreamWriter.startNextLine(hAlignShift, 0);
|
|
1144
|
+
}
|
|
1145
|
+
if (unicode) {
|
|
1146
|
+
this.drawUnicodeLine(lineInfo, layoutRectangle, font, format);
|
|
1147
|
+
} else {
|
|
1148
|
+
this.drawAsciiLine(lineInfo, layoutRectangle, font, format);
|
|
1149
|
+
}
|
|
1150
|
+
if (hAlignShift !== 0 && !this.isEmfTextScaled) {
|
|
1151
|
+
this.pdfStreamWriter.startNextLine(-hAlignShift, 0);
|
|
1152
|
+
}
|
|
1153
|
+
if (this.isOverloadWithPosition && lines.length > 1) {
|
|
1154
|
+
this.pdfStreamWriter.startNextLine(-(layoutRectangle.x), 0);
|
|
1155
|
+
layoutRectangle.x = 0;
|
|
1156
|
+
layoutRectangle.width = this.clientSize.width;
|
|
1157
|
+
this.isOverloadWithPosition = false;
|
|
1158
|
+
this.isPointOverload = true;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
this.getResources.getResources().requireProcedureSet(this.procedureSets.text);
|
|
1162
|
+
if (vAlignShift !== 0) {
|
|
1163
|
+
this.pdfStreamWriter.startNextLine(0, -(vAlignShift - result.lineHeight));
|
|
1164
|
+
}
|
|
1165
|
+
this.pdfStreamWriter.endText();
|
|
1166
|
+
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* `Draws Ascii line`.
|
|
1170
|
+
* @private
|
|
1171
|
+
*/
|
|
1172
|
+
private drawAsciiLine(lineInfo : LineInfo, layoutRectangle : RectangleF, font : PdfFont, format : PdfStringFormat) : void {
|
|
1173
|
+
this.justifyLine(lineInfo, layoutRectangle.width, format);
|
|
1174
|
+
let value : string = '';
|
|
1175
|
+
if (lineInfo.text.indexOf('(') !== -1 || lineInfo.text.indexOf(')') !== -1) {
|
|
1176
|
+
for (let i : number = 0; i < lineInfo.text.length; i ++) {
|
|
1177
|
+
if (lineInfo.text[i] === '(') {
|
|
1178
|
+
value += '\\\(';
|
|
1179
|
+
} else if (lineInfo.text[i] === ')') {
|
|
1180
|
+
value += '\\\)';
|
|
1181
|
+
} else {
|
|
1182
|
+
value += lineInfo.text[i];
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (value === '') {
|
|
1187
|
+
value = lineInfo.text;
|
|
1188
|
+
}
|
|
1189
|
+
let line : string = '(' + value + ')';
|
|
1190
|
+
this.pdfStreamWriter.showNextLineText(new PdfString(line));
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Draws unicode line.
|
|
1194
|
+
* @private
|
|
1195
|
+
*/
|
|
1196
|
+
private drawUnicodeLine(lineInfo : LineInfo, layoutRectangle : RectangleF, font : PdfFont, format : PdfStringFormat) : void {
|
|
1197
|
+
let line : string = lineInfo.text;
|
|
1198
|
+
let lineWidth : number = lineInfo.width;
|
|
1199
|
+
let rtl : boolean = (format !== null && typeof format !== 'undefined' && format.rightToLeft);
|
|
1200
|
+
let useWordSpace : boolean = (format !== null && typeof format !== 'undefined' && (format.wordSpacing !== 0 || format.alignment === PdfTextAlignment.Justify));
|
|
1201
|
+
let ttfFont : PdfTrueTypeFont = font as PdfTrueTypeFont;
|
|
1202
|
+
let wordSpacing : number = this.justifyLine(lineInfo, layoutRectangle.width, format);
|
|
1203
|
+
let rtlRender : RtlRenderer = new RtlRenderer();
|
|
1204
|
+
if (rtl || (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.None)) {
|
|
1205
|
+
let blocks : string[] = null;
|
|
1206
|
+
let rightAlign : boolean = (format !== null && typeof format !== 'undefined' && format.alignment === PdfTextAlignment.Right);
|
|
1207
|
+
if (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.None) {
|
|
1208
|
+
/* tslint:disable-next-line:max-line-length */
|
|
1209
|
+
blocks = rtlRender.layout(line, ttfFont, (format.textDirection === PdfTextDirection.RightToLeft) ? true : false, useWordSpace, format);
|
|
1210
|
+
} else {
|
|
1211
|
+
blocks = rtlRender.layout(line, ttfFont, rightAlign, useWordSpace, format);
|
|
1212
|
+
}
|
|
1213
|
+
let words : string[] = null;
|
|
1214
|
+
if (blocks.length > 1) {
|
|
1215
|
+
if (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.None) {
|
|
1216
|
+
/* tslint:disable-next-line:max-line-length */
|
|
1217
|
+
words = rtlRender.splitLayout(line, ttfFont, (format.textDirection === PdfTextDirection.RightToLeft) ? true : false, useWordSpace, format);
|
|
1218
|
+
} else {
|
|
1219
|
+
words = rtlRender.splitLayout(line, ttfFont, rightAlign, useWordSpace, format);
|
|
1220
|
+
}
|
|
1221
|
+
} else {
|
|
1222
|
+
words = [line] ;
|
|
1223
|
+
}
|
|
1224
|
+
this.drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
|
|
1225
|
+
} else {
|
|
1226
|
+
if (useWordSpace) {
|
|
1227
|
+
let result : { tokens : string[], words : string[] } = this.breakUnicodeLine(line, ttfFont, null);
|
|
1228
|
+
let blocks : string[] = result.tokens;
|
|
1229
|
+
let words : string[] = result.words;
|
|
1230
|
+
this.drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
|
|
1231
|
+
} else {
|
|
1232
|
+
let token : string = this.convertToUnicode(line, ttfFont);
|
|
1233
|
+
let value : PdfString = this.getUnicodeString(token);
|
|
1234
|
+
this.streamWriter.showNextLineText(value);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Draws array of unicode tokens.
|
|
1240
|
+
*/
|
|
1241
|
+
/* tslint:disable */
|
|
1242
|
+
private drawUnicodeBlocks(blocks : string[], words : string[], font : PdfTrueTypeFont, format : PdfStringFormat, wordSpacing : number) : void {
|
|
1243
|
+
/* tslint:enable */
|
|
1244
|
+
if (blocks == null) {
|
|
1245
|
+
throw new Error('Argument Null Exception : blocks');
|
|
1246
|
+
}
|
|
1247
|
+
if (words == null) {
|
|
1248
|
+
throw new Error('Argument Null Exception : words');
|
|
1249
|
+
}
|
|
1250
|
+
if (font == null) {
|
|
1251
|
+
throw new Error('Argument Null Exception : font');
|
|
1252
|
+
}
|
|
1253
|
+
this.streamWriter.startNextLine();
|
|
1254
|
+
let x : number = 0;
|
|
1255
|
+
let xShift : number = 0;
|
|
1256
|
+
let firstLineIndent : number = 0;
|
|
1257
|
+
let paragraphIndent : number = 0;
|
|
1258
|
+
try {
|
|
1259
|
+
if (format !== null && typeof format !== 'undefined') {
|
|
1260
|
+
firstLineIndent = format.firstLineIndent;
|
|
1261
|
+
paragraphIndent = format.paragraphIndent;
|
|
1262
|
+
format.firstLineIndent = 0;
|
|
1263
|
+
format.paragraphIndent = 0;
|
|
1264
|
+
}
|
|
1265
|
+
let spaceWidth : number = font.getCharWidth(StringTokenizer.whiteSpace, format) + wordSpacing;
|
|
1266
|
+
let characterSpacing : number = (format != null) ? format.characterSpacing : 0;
|
|
1267
|
+
let wordSpace : number = (format !== null && typeof format !== 'undefined' && wordSpacing === 0) ? format.wordSpacing : 0;
|
|
1268
|
+
spaceWidth += characterSpacing + wordSpace;
|
|
1269
|
+
for (let i : number = 0; i < blocks.length; i++) {
|
|
1270
|
+
let token : string = blocks[i];
|
|
1271
|
+
let word : string = words[i];
|
|
1272
|
+
let tokenWidth : number = 0;
|
|
1273
|
+
if (x !== 0) {
|
|
1274
|
+
this.streamWriter.startNextLine(x, 0);
|
|
1275
|
+
}
|
|
1276
|
+
if (word.length > 0) {
|
|
1277
|
+
tokenWidth += /*Utils.Round(*/ font.measureString(word, format).width /*)*/;
|
|
1278
|
+
tokenWidth += characterSpacing;
|
|
1279
|
+
let val : PdfString = this.getUnicodeString(token);
|
|
1280
|
+
this.streamWriter.showText(val);
|
|
1281
|
+
}
|
|
1282
|
+
if (i !== blocks.length - 1) {
|
|
1283
|
+
x = tokenWidth + spaceWidth;
|
|
1284
|
+
xShift += x;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
// Rolback current line position.
|
|
1288
|
+
if (xShift > 0) {
|
|
1289
|
+
this.streamWriter.startNextLine(-xShift, 0);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
finally {
|
|
1293
|
+
if (format !== null && typeof format !== 'undefined') {
|
|
1294
|
+
format.firstLineIndent = firstLineIndent;
|
|
1295
|
+
format.paragraphIndent = paragraphIndent;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Breakes the unicode line to the words and converts symbols to glyphs.
|
|
1301
|
+
*/
|
|
1302
|
+
private breakUnicodeLine(line : string, ttfFont : PdfTrueTypeFont, words : string[]) : {tokens : string[], words : string[]} {
|
|
1303
|
+
if (line === null) {
|
|
1304
|
+
throw new Error('Argument Null Exception : line');
|
|
1305
|
+
}
|
|
1306
|
+
words = line.split(null);
|
|
1307
|
+
let tokens : string[] = [];
|
|
1308
|
+
for (let i : number = 0; i < words.length; i++) {
|
|
1309
|
+
// Reconvert string according to unicode standard.
|
|
1310
|
+
let word : string = words[i];
|
|
1311
|
+
let token : string = this.convertToUnicode(word, ttfFont);
|
|
1312
|
+
tokens[i] = token;
|
|
1313
|
+
}
|
|
1314
|
+
return { tokens : tokens, words : words };
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Creates PdfString from the unicode text.
|
|
1318
|
+
*/
|
|
1319
|
+
private getUnicodeString(token : string) : PdfString {
|
|
1320
|
+
if (token === null) {
|
|
1321
|
+
throw new Error('Argument Null Exception : token');
|
|
1322
|
+
}
|
|
1323
|
+
let val : PdfString = new PdfString(token);
|
|
1324
|
+
val.converted = true;
|
|
1325
|
+
val.encode = InternalEnum.ForceEncoding.Ascii;
|
|
1326
|
+
return val;
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Converts to unicode format.
|
|
1330
|
+
*/
|
|
1331
|
+
private convertToUnicode(text : string, ttfFont : PdfTrueTypeFont) : string {
|
|
1332
|
+
let token : string = null;
|
|
1333
|
+
if (text == null) {
|
|
1334
|
+
throw new Error('Argument Null Exception : text');
|
|
1335
|
+
}
|
|
1336
|
+
if (ttfFont == null) {
|
|
1337
|
+
throw new Error('Argument Null Exception : ttfFont');
|
|
1338
|
+
}
|
|
1339
|
+
if (ttfFont.fontInternal instanceof UnicodeTrueTypeFont) {
|
|
1340
|
+
let ttfReader : TtfReader = (ttfFont.fontInternal as UnicodeTrueTypeFont).ttfReader;
|
|
1341
|
+
ttfFont.setSymbols(text);
|
|
1342
|
+
token = ttfReader.convertString(text);
|
|
1343
|
+
let bytes : number[] = PdfString.toUnicodeArray(token, false);
|
|
1344
|
+
token = PdfString.byteToString(bytes);
|
|
1345
|
+
}
|
|
1346
|
+
return token;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* `Justifies` the line if needed.
|
|
1350
|
+
* @private
|
|
1351
|
+
*/
|
|
1352
|
+
private justifyLine(lineInfo : LineInfo, boundsWidth : number, format : PdfStringFormat) : number {
|
|
1353
|
+
let line : string = lineInfo.text;
|
|
1354
|
+
let lineWidth : number = lineInfo.width;
|
|
1355
|
+
let shouldJustify : boolean = this.shouldJustify(lineInfo, boundsWidth, format);
|
|
1356
|
+
let hasWordSpacing : boolean = (format != null && format.wordSpacing !== 0);
|
|
1357
|
+
let symbols : string[] = StringTokenizer.spaces;
|
|
1358
|
+
let whitespacesCount : number = StringTokenizer.getCharsCount(line, symbols);
|
|
1359
|
+
let wordSpace : number = 0;
|
|
1360
|
+
if (shouldJustify) {
|
|
1361
|
+
// Correct line width.
|
|
1362
|
+
if (hasWordSpacing) {
|
|
1363
|
+
lineWidth -= (whitespacesCount * format.wordSpacing);
|
|
1364
|
+
}
|
|
1365
|
+
let difference : number = boundsWidth - lineWidth;
|
|
1366
|
+
wordSpace = difference / whitespacesCount;
|
|
1367
|
+
this.pdfStreamWriter.setWordSpacing(wordSpace);
|
|
1368
|
+
} else {
|
|
1369
|
+
// If there is justifying, but the line shouldn't be justified, restore default word spacing.
|
|
1370
|
+
if (hasWordSpacing) {
|
|
1371
|
+
this.pdfStreamWriter.setWordSpacing(format.wordSpacing);
|
|
1372
|
+
} else {
|
|
1373
|
+
this.pdfStreamWriter.setWordSpacing(0);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return wordSpace;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* `Reset` or reinitialize the current graphic value.
|
|
1380
|
+
* @private
|
|
1381
|
+
*/
|
|
1382
|
+
public reset(size : SizeF) : void {
|
|
1383
|
+
this.canvasSize = size;
|
|
1384
|
+
this.streamWriter.clear();
|
|
1385
|
+
this.initialize();
|
|
1386
|
+
this.initializeCoordinates();
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Checks whether the line should be `justified`.
|
|
1390
|
+
* @private
|
|
1391
|
+
*/
|
|
1392
|
+
private shouldJustify(lineInfo : LineInfo, boundsWidth : number, format : PdfStringFormat) : boolean {
|
|
1393
|
+
let line : string = lineInfo.text;
|
|
1394
|
+
let lineWidth : number = lineInfo.width;
|
|
1395
|
+
let justifyStyle : boolean = (format != null && format.alignment === PdfTextAlignment.Justify);
|
|
1396
|
+
let goodWidth : boolean = (boundsWidth >= 0 && lineWidth < boundsWidth);
|
|
1397
|
+
let symbols : string[] = StringTokenizer.spaces;
|
|
1398
|
+
let whitespacesCount : number = StringTokenizer.getCharsCount(line, symbols);
|
|
1399
|
+
let hasSpaces : boolean = (whitespacesCount > 0 && line[0] !== StringTokenizer.whiteSpace);
|
|
1400
|
+
let goodLineBreakStyle : boolean = ((lineInfo.lineType & LineType.LayoutBreak) > 0);
|
|
1401
|
+
/* tslint:disable */
|
|
1402
|
+
let shouldJustify : boolean = (justifyStyle && goodWidth && hasSpaces && (goodLineBreakStyle || format.alignment === PdfTextAlignment.Justify));/* tslint:enable */
|
|
1403
|
+
return shouldJustify;
|
|
1404
|
+
}
|
|
1405
|
+
/* tslint:disable */
|
|
1406
|
+
/**
|
|
1407
|
+
* Emulates `Underline, Strikeout` of the text if needed.
|
|
1408
|
+
* @private
|
|
1409
|
+
*/
|
|
1410
|
+
private underlineStrikeoutText(pen : PdfPen, brush : PdfBrush, result : PdfStringLayoutResult, font : PdfFont, layoutRectangle : RectangleF, format : PdfStringFormat) : void {/* tslint:enable */
|
|
1411
|
+
if (font.underline || font.strikeout) {
|
|
1412
|
+
// Calculate line width.
|
|
1413
|
+
let linePen : PdfPen = this.createUnderlineStikeoutPen(pen, brush, font, format);
|
|
1414
|
+
if (linePen != null) {
|
|
1415
|
+
// Approximate line positions.
|
|
1416
|
+
let vShift : number = this.getTextVerticalAlignShift(result.actualSize.height, layoutRectangle.height, format);
|
|
1417
|
+
let underlineYOffset : number = 0;
|
|
1418
|
+
underlineYOffset = layoutRectangle.y + vShift + font.metrics.getAscent(format) + 1.5 * linePen.width;
|
|
1419
|
+
let strikeoutYOffset : number = layoutRectangle.y + vShift + font.metrics.getHeight(format) / 2 + 1.5 * linePen.width;
|
|
1420
|
+
let lines : LineInfo[] = result.lines;
|
|
1421
|
+
// Run through the text and draw lines.
|
|
1422
|
+
for (let i : number = 0, len : number = result.lineCount; i < len; i++) {
|
|
1423
|
+
let lineInfo : LineInfo = lines[i];
|
|
1424
|
+
let line : string = lineInfo.text;
|
|
1425
|
+
let lineWidth : number = lineInfo.width;
|
|
1426
|
+
let hShift : number = this.getHorizontalAlignShift(lineWidth, layoutRectangle.width, format);
|
|
1427
|
+
let lineIndent : number = this.getLineIndent(lineInfo, format, layoutRectangle, (i === 0));
|
|
1428
|
+
hShift += (!this.rightToLeft(format)) ? lineIndent : 0;
|
|
1429
|
+
let x1 : number = layoutRectangle.x + hShift;
|
|
1430
|
+
/* tslint:disable */
|
|
1431
|
+
let x2 : number = (!this.shouldJustify(lineInfo, layoutRectangle.width, format)) ? x1 + lineWidth - lineIndent : x1 + layoutRectangle.width - lineIndent;
|
|
1432
|
+
/* tslint:enable */
|
|
1433
|
+
if (font.underline) {
|
|
1434
|
+
let y : number = underlineYOffset;
|
|
1435
|
+
this.drawLine(linePen, x1, y, x2, y);
|
|
1436
|
+
underlineYOffset += result.lineHeight;
|
|
1437
|
+
}
|
|
1438
|
+
if (font.strikeout) {
|
|
1439
|
+
let y : number = strikeoutYOffset;
|
|
1440
|
+
this.drawLine(linePen, x1, y, x2, y);
|
|
1441
|
+
strikeoutYOffset += result.lineHeight;
|
|
1442
|
+
}
|
|
1443
|
+
if (this.isPointOverload && lines.length > 1) {
|
|
1444
|
+
layoutRectangle.x = 0;
|
|
1445
|
+
layoutRectangle.width = this.clientSize.width;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
this.isPointOverload = false;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* `Creates a pen` for drawing lines in the text.
|
|
1454
|
+
* @private
|
|
1455
|
+
*/
|
|
1456
|
+
private createUnderlineStikeoutPen(pen : PdfPen, brush : PdfBrush, font : PdfFont, format : PdfStringFormat) : PdfPen {
|
|
1457
|
+
// Calculate line width.
|
|
1458
|
+
let lineWidth : number = font.metrics.getSize(format) / 20;
|
|
1459
|
+
let linePen : PdfPen = null;
|
|
1460
|
+
// Create a pen fo the lines.
|
|
1461
|
+
if (pen != null) {
|
|
1462
|
+
linePen = new PdfPen(pen.color, lineWidth);
|
|
1463
|
+
} else if (brush != null) {
|
|
1464
|
+
linePen = new PdfPen(brush, lineWidth);
|
|
1465
|
+
}
|
|
1466
|
+
return linePen;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Return `text rendering mode`.
|
|
1470
|
+
* @private
|
|
1471
|
+
*/
|
|
1472
|
+
private getTextRenderingMode(pen : PdfPen, brush : PdfBrush, format : PdfStringFormat) : TextRenderingMode {
|
|
1473
|
+
let tm : TextRenderingMode = TextRenderingMode.None;
|
|
1474
|
+
if (pen != null && brush != null) {
|
|
1475
|
+
tm = TextRenderingMode.FillStroke;
|
|
1476
|
+
} else if (pen != null) {
|
|
1477
|
+
tm = TextRenderingMode.Stroke;
|
|
1478
|
+
} else {
|
|
1479
|
+
tm = TextRenderingMode.Fill;
|
|
1480
|
+
}
|
|
1481
|
+
if (format != null && format.clipPath) {
|
|
1482
|
+
tm |= TextRenderingMode.ClipFlag;
|
|
1483
|
+
}
|
|
1484
|
+
return tm;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Returns `line indent` for the line.
|
|
1488
|
+
* @private
|
|
1489
|
+
*/
|
|
1490
|
+
private getLineIndent(lineInfo : LineInfo, format : PdfStringFormat, layoutBounds : RectangleF, firstLine : boolean) : number {
|
|
1491
|
+
let lineIndent : number = 0;
|
|
1492
|
+
let firstParagraphLine : boolean = ((lineInfo.lineType & LineType.FirstParagraphLine) > 0);
|
|
1493
|
+
if (format != null && firstParagraphLine) {
|
|
1494
|
+
lineIndent = (firstLine) ? format.firstLineIndent : format.paragraphIndent;
|
|
1495
|
+
lineIndent = (layoutBounds.width > 0) ? Math.min(layoutBounds.width, lineIndent) : lineIndent;
|
|
1496
|
+
}
|
|
1497
|
+
return lineIndent;
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Calculates shift value if the line is `horizontaly aligned`.
|
|
1501
|
+
* @private
|
|
1502
|
+
*/
|
|
1503
|
+
private getHorizontalAlignShift(lineWidth : number, boundsWidth : number, format : PdfStringFormat) : number {
|
|
1504
|
+
let shift : number = 0;
|
|
1505
|
+
if (boundsWidth >= 0 && format != null && format.alignment !== PdfTextAlignment.Left) {
|
|
1506
|
+
switch (format.alignment) {
|
|
1507
|
+
case PdfTextAlignment.Center:
|
|
1508
|
+
shift = (boundsWidth - lineWidth) / 2;
|
|
1509
|
+
break;
|
|
1510
|
+
case PdfTextAlignment.Right:
|
|
1511
|
+
shift = boundsWidth - lineWidth;
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
return shift;
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Gets or sets the value that indicates `text direction` mode.
|
|
1519
|
+
* @private
|
|
1520
|
+
*/
|
|
1521
|
+
private rightToLeft(format : PdfStringFormat) : boolean {
|
|
1522
|
+
let rtl : boolean = (format !== null && typeof format !== 'undefined' && format.rightToLeft);
|
|
1523
|
+
if (format !== null && typeof format !== 'undefined') {
|
|
1524
|
+
if (format.textDirection !== PdfTextDirection.None && typeof format.textDirection !== 'undefined') {
|
|
1525
|
+
rtl = true;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return rtl;
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Controls all `state modifications` and react repectively.
|
|
1532
|
+
* @private
|
|
1533
|
+
*/
|
|
1534
|
+
private stateControl(pen : PdfPen, brush : PdfBrush, font : PdfFont) : void
|
|
1535
|
+
/**
|
|
1536
|
+
* Controls all `state modifications` and react respectively.
|
|
1537
|
+
* @private
|
|
1538
|
+
*/
|
|
1539
|
+
private stateControl(pen : PdfPen, brush : PdfBrush, font : PdfFont, format : PdfStringFormat) : void
|
|
1540
|
+
private stateControl(pen : PdfPen, brush : PdfBrush, font : PdfFont, format ?: PdfStringFormat) : void {
|
|
1541
|
+
if (typeof format === 'undefined') {
|
|
1542
|
+
this.stateControl(pen, brush, font, null);
|
|
1543
|
+
} else {
|
|
1544
|
+
if (brush instanceof PdfGradientBrush) {
|
|
1545
|
+
this.bCSInitialized = false;
|
|
1546
|
+
(<PdfGradientBrush>brush).colorSpace = this.colorSpace;
|
|
1547
|
+
}
|
|
1548
|
+
if (brush instanceof PdfTilingBrush) {
|
|
1549
|
+
this.bCSInitialized = false;
|
|
1550
|
+
(<PdfTilingBrush>brush).graphics.colorSpace = this.colorSpace;
|
|
1551
|
+
}
|
|
1552
|
+
let saveState : boolean = false;
|
|
1553
|
+
if (brush !== null) {
|
|
1554
|
+
let solidBrush : PdfSolidBrush = <PdfSolidBrush>brush;
|
|
1555
|
+
if (typeof this.pageLayer !== 'undefined' && this.pageLayer != null) {
|
|
1556
|
+
if (this.colorSpaceChanged === false) {
|
|
1557
|
+
this.lastDocumentCS = (this.pageLayer.page as PdfPage).document.colorSpace;
|
|
1558
|
+
this.lastGraphicsCS = (this.pageLayer.page as PdfPage).graphics.colorSpace;
|
|
1559
|
+
this.colorSpace = (this.pageLayer.page as PdfPage).document.colorSpace;
|
|
1560
|
+
this.currentColorSpace = (this.pageLayer.page as PdfPage).document.colorSpace;
|
|
1561
|
+
this.colorSpaceChanged = true;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
this.initCurrentColorSpace(this.currentColorSpace);
|
|
1565
|
+
} else if (pen != null) {
|
|
1566
|
+
let pdfPen : PdfPen = pen as PdfPen;
|
|
1567
|
+
if (typeof this.pageLayer !== 'undefined' && this.pageLayer != null) {
|
|
1568
|
+
/* tslint:disable */
|
|
1569
|
+
this.colorSpace = (this.pageLayer.page as PdfPage).document.colorSpace;
|
|
1570
|
+
this.currentColorSpace = (this.pageLayer.page as PdfPage).document.colorSpace;
|
|
1571
|
+
}
|
|
1572
|
+
this.initCurrentColorSpace(this.currentColorSpace);
|
|
1573
|
+
}
|
|
1574
|
+
this.penControl(pen, saveState);
|
|
1575
|
+
this.brushControl(brush, saveState);
|
|
1576
|
+
this.fontControl(font, format, saveState);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Initializes the `current color space`.
|
|
1581
|
+
* @private
|
|
1582
|
+
*/
|
|
1583
|
+
private initCurrentColorSpace(colorspace : PdfColorSpace) : void {
|
|
1584
|
+
let re : PdfResources = this.getResources.getResources() as PdfResources;
|
|
1585
|
+
if (!this.bCSInitialized) {
|
|
1586
|
+
if (this.currentColorSpace != PdfColorSpace.GrayScale) {
|
|
1587
|
+
this.pdfStreamWriter.setColorSpace('Device' + this.currentColorSpaces[this.currentColorSpace], true);
|
|
1588
|
+
this.pdfStreamWriter.setColorSpace('Device' + this.currentColorSpaces[this.currentColorSpace], false);
|
|
1589
|
+
this.bCSInitialized = true;
|
|
1590
|
+
} else {
|
|
1591
|
+
this.pdfStreamWriter.setColorSpace('DeviceGray' , true);
|
|
1592
|
+
this.pdfStreamWriter.setColorSpace('DeviceGray' , false);
|
|
1593
|
+
this.bCSInitialized = true;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Controls the `pen state`.
|
|
1600
|
+
* @private
|
|
1601
|
+
*/
|
|
1602
|
+
private penControl(pen : PdfPen, saveState : boolean) : void {
|
|
1603
|
+
if (pen != null) {
|
|
1604
|
+
this.currentPen = pen;
|
|
1605
|
+
/* tslint:disable */
|
|
1606
|
+
pen.monitorChanges(this.currentPen, this.pdfStreamWriter, this.getResources, saveState, this.colorSpace, this.matrix.clone());
|
|
1607
|
+
/* tslint:enable */
|
|
1608
|
+
this.currentPen = pen.clone();
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Controls the `brush state`.
|
|
1613
|
+
* @private
|
|
1614
|
+
*/
|
|
1615
|
+
private brushControl(brush : PdfBrush, saveState : boolean) : void {
|
|
1616
|
+
if (brush != null && typeof brush !== 'undefined') {
|
|
1617
|
+
let b : PdfBrush = brush.clone();
|
|
1618
|
+
let lgb : PdfGradientBrush = <PdfGradientBrush>b;
|
|
1619
|
+
if (lgb !== null && typeof lgb !== 'undefined' && !(brush instanceof PdfSolidBrush) && !(brush instanceof PdfTilingBrush)) {
|
|
1620
|
+
let m: PdfTransformationMatrix = lgb.matrix;
|
|
1621
|
+
let matrix: PdfTransformationMatrix = this.matrix.clone();
|
|
1622
|
+
if ((m != null)) {
|
|
1623
|
+
m.multiply(matrix);
|
|
1624
|
+
matrix = m;
|
|
1625
|
+
}
|
|
1626
|
+
lgb.matrix = matrix;
|
|
1627
|
+
}
|
|
1628
|
+
this.currentBrush = lgb;
|
|
1629
|
+
let br: PdfSolidBrush = (<PdfSolidBrush>(brush));
|
|
1630
|
+
/* tslint:disable */
|
|
1631
|
+
b.monitorChanges(this.currentBrush, this.pdfStreamWriter, this.getResources, saveState, this.colorSpace);
|
|
1632
|
+
/* tslint:enable */
|
|
1633
|
+
this.currentBrush = brush;
|
|
1634
|
+
brush = null;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Saves the font and other `font settings`.
|
|
1639
|
+
* @private
|
|
1640
|
+
*/
|
|
1641
|
+
private fontControl(font : PdfFont, format : PdfStringFormat, saveState : boolean) : void {
|
|
1642
|
+
if (font != null) {
|
|
1643
|
+
let curSubSuper : PdfSubSuperScript = (format != null) ? format.subSuperScript : PdfSubSuperScript.None;
|
|
1644
|
+
/* tslint:disable */
|
|
1645
|
+
let prevSubSuper : PdfSubSuperScript = (this.currentStringFormat != null) ? this.currentStringFormat.subSuperScript : PdfSubSuperScript.None; /* tslint:enable */
|
|
1646
|
+
if (saveState || font !== this.currentFont || curSubSuper !== prevSubSuper) {
|
|
1647
|
+
let resources : PdfResources = this.getResources.getResources();
|
|
1648
|
+
this.currentFont = font;
|
|
1649
|
+
this.currentStringFormat = format;
|
|
1650
|
+
let size : number = font.metrics.getSize(format);
|
|
1651
|
+
/* tslint:disable */
|
|
1652
|
+
this.isEmfTextScaled = false;
|
|
1653
|
+
let fontName : PdfName = resources.getName(font);
|
|
1654
|
+
this.pdfStreamWriter.setFont(font, fontName, size);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* `Sets the transparency` of this Graphics with the specified value for pen.
|
|
1660
|
+
* ```typescript
|
|
1661
|
+
* // create a new PDF document
|
|
1662
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1663
|
+
* // create a new page
|
|
1664
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1665
|
+
* // create pen
|
|
1666
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1667
|
+
* //
|
|
1668
|
+
* // set transparency
|
|
1669
|
+
* page1.graphics.setTransparency(0.5);
|
|
1670
|
+
* //
|
|
1671
|
+
* // draw the rectangle after applying transparency
|
|
1672
|
+
* page1.graphics.drawRectangle(pen, new RectangleF({x : 0, y : 0}, {width : 100, height : 50}));
|
|
1673
|
+
* // save the document.
|
|
1674
|
+
* document.save('output.pdf');
|
|
1675
|
+
* // destroy the document
|
|
1676
|
+
* document.destroy();
|
|
1677
|
+
* ```
|
|
1678
|
+
* @param alpha The alpha value for both pen and brush.
|
|
1679
|
+
*/
|
|
1680
|
+
public setTransparency(alpha : number) : void
|
|
1681
|
+
/**
|
|
1682
|
+
* `Sets the transparency` of this Graphics with the specified value for pen and brush.
|
|
1683
|
+
* ```typescript
|
|
1684
|
+
* // create a new PDF document
|
|
1685
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1686
|
+
* // create a new page
|
|
1687
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1688
|
+
* // create pen
|
|
1689
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1690
|
+
* // set brush
|
|
1691
|
+
* let brush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
|
|
1692
|
+
* //
|
|
1693
|
+
* // set transparency
|
|
1694
|
+
* page1.graphics.setTransparency(0.8, 0.2);
|
|
1695
|
+
* //
|
|
1696
|
+
* // draw the rectangle after applying transparency
|
|
1697
|
+
* page1.graphics.drawRectangle(pen, brush, new RectangleF({x : 0, y : 0}, {width : 100, height : 50}));
|
|
1698
|
+
* // save the document.
|
|
1699
|
+
* document.save('output.pdf');
|
|
1700
|
+
* // destroy the document
|
|
1701
|
+
* document.destroy();
|
|
1702
|
+
* ```
|
|
1703
|
+
* @param alphaPen The alpha value for pen.
|
|
1704
|
+
* @param alphaBrush The alpha value for brush.
|
|
1705
|
+
*/
|
|
1706
|
+
public setTransparency(alphaPen : number, alphaBrush : number) : void
|
|
1707
|
+
/**
|
|
1708
|
+
* `Sets the transparency` of this Graphics with the specified PdfBlendMode.
|
|
1709
|
+
* @private
|
|
1710
|
+
*/
|
|
1711
|
+
public setTransparency(alphaPen : number, alphaBrush : number, blendMode : PdfBlendMode) : void
|
|
1712
|
+
public setTransparency(arg1 : number, arg2 ?: number, arg3 ?: PdfBlendMode) : void {
|
|
1713
|
+
if (typeof arg2 === 'undefined') {
|
|
1714
|
+
this.istransparencySet = true;
|
|
1715
|
+
this.setTransparency(arg1, arg1, PdfBlendMode.Normal);
|
|
1716
|
+
} else if (typeof arg2 === 'number' && typeof arg3 === 'undefined') {
|
|
1717
|
+
this.setTransparency(arg1, arg2, PdfBlendMode.Normal);
|
|
1718
|
+
} else {
|
|
1719
|
+
if (this.trasparencies == null) {
|
|
1720
|
+
this.trasparencies = new TemporaryDictionary<TransparencyData, PdfTransparency>();
|
|
1721
|
+
}
|
|
1722
|
+
let transp : PdfTransparency = null;
|
|
1723
|
+
let td : TransparencyData = new TransparencyData(arg1, arg2, arg3);
|
|
1724
|
+
if (this.trasparencies.containsKey(td)) {
|
|
1725
|
+
transp = this.trasparencies.getValue(td) as PdfTransparency;
|
|
1726
|
+
}
|
|
1727
|
+
if (transp == null) {
|
|
1728
|
+
transp = new PdfTransparency(arg1, arg2, arg3);
|
|
1729
|
+
this.trasparencies.setValue(td, transp);
|
|
1730
|
+
}
|
|
1731
|
+
let resources : PdfResources = this.getResources.getResources();
|
|
1732
|
+
let name : PdfName = resources.getName(transp);
|
|
1733
|
+
let sw : PdfStreamWriter = this.streamWriter;
|
|
1734
|
+
sw.setGraphicsState(name);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Sets the `drawing area and translates origin`.
|
|
1739
|
+
* @private
|
|
1740
|
+
*/
|
|
1741
|
+
public clipTranslateMargins(clipBounds : RectangleF) : void
|
|
1742
|
+
public clipTranslateMargins(x : number, y : number, left : number, top : number, right : number, bottom : number) : void
|
|
1743
|
+
public clipTranslateMargins(x : number | RectangleF, y ?: number, left ?: number, top ?: number, right ?: number, bottom ?: number) : void {
|
|
1744
|
+
if (x instanceof RectangleF && typeof y === 'undefined') {
|
|
1745
|
+
this.clipBounds = x as RectangleF;
|
|
1746
|
+
this.pdfStreamWriter.writeComment('Clip margins.');
|
|
1747
|
+
this.pdfStreamWriter.appendRectangle(x as RectangleF);
|
|
1748
|
+
this.pdfStreamWriter.closePath();
|
|
1749
|
+
this.pdfStreamWriter.clipPath(false);
|
|
1750
|
+
this.pdfStreamWriter.writeComment('Translate co-ordinate system.');
|
|
1751
|
+
this.translateTransform((x as RectangleF).x, (x as RectangleF).y);
|
|
1752
|
+
} else if (typeof x === 'number') {
|
|
1753
|
+
let clipArea : RectangleF = new RectangleF(left, top, this.size.width-left-right, this.size.height-top-bottom);
|
|
1754
|
+
this.clipBounds = clipArea;
|
|
1755
|
+
this.pdfStreamWriter.writeComment("Clip margins.");
|
|
1756
|
+
this.pdfStreamWriter.appendRectangle(clipArea);
|
|
1757
|
+
this.pdfStreamWriter.closePath();
|
|
1758
|
+
this.pdfStreamWriter.clipPath(false);
|
|
1759
|
+
this.pdfStreamWriter.writeComment("Translate co-ordinate system.");
|
|
1760
|
+
this.translateTransform(x, y);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* `Updates y` co-ordinate.
|
|
1765
|
+
* @private
|
|
1766
|
+
*/
|
|
1767
|
+
public updateY(y : number) : number {
|
|
1768
|
+
return -y;
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Used to `translate the transformation`.
|
|
1772
|
+
* ```typescript
|
|
1773
|
+
* // create a new PDF document
|
|
1774
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1775
|
+
* // create a new page
|
|
1776
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1777
|
+
* // set pen
|
|
1778
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1779
|
+
* //
|
|
1780
|
+
* // set translate transform
|
|
1781
|
+
* page1.graphics.translateTransform(100, 100);
|
|
1782
|
+
* //
|
|
1783
|
+
* // draw the rectangle after applying translate transform
|
|
1784
|
+
* page1.graphics.drawRectangle(pen, new RectangleF({x : 0, y : 0}, {width : 100, height : 50}));
|
|
1785
|
+
* // save the document.
|
|
1786
|
+
* document.save('output.pdf');
|
|
1787
|
+
* // destroy the document
|
|
1788
|
+
* document.destroy();
|
|
1789
|
+
* ```
|
|
1790
|
+
* @param offsetX The x-coordinate of the translation.
|
|
1791
|
+
* @param offsetY The y-coordinate of the translation.
|
|
1792
|
+
*/
|
|
1793
|
+
public translateTransform(offsetX : number, offsetY : number) : void {
|
|
1794
|
+
let matrix : PdfTransformationMatrix = new PdfTransformationMatrix();
|
|
1795
|
+
this.getTranslateTransform(offsetX, offsetY, matrix);
|
|
1796
|
+
this.pdfStreamWriter.modifyCtm(matrix);
|
|
1797
|
+
this.matrix.multiply(matrix);
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* `Translates` coordinates of the input matrix.
|
|
1801
|
+
* @private
|
|
1802
|
+
*/
|
|
1803
|
+
private getTranslateTransform(x : number, y : number, input : PdfTransformationMatrix) : PdfTransformationMatrix {
|
|
1804
|
+
input.translate(x, this.updateY(y));
|
|
1805
|
+
return input;
|
|
1806
|
+
}
|
|
1807
|
+
/* tslint:disable */
|
|
1808
|
+
/**
|
|
1809
|
+
* Applies the specified `scaling operation` to the transformation matrix of this Graphics by prepending it to the object's transformation matrix.
|
|
1810
|
+
* ```typescript
|
|
1811
|
+
* // create a new PDF document
|
|
1812
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1813
|
+
* // create a new page
|
|
1814
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1815
|
+
* // create pen
|
|
1816
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1817
|
+
* //
|
|
1818
|
+
* // apply scaling trasformation
|
|
1819
|
+
* page1.graphics.scaleTransform(1.5, 2);
|
|
1820
|
+
* //
|
|
1821
|
+
* // draw the rectangle after applying scaling transform
|
|
1822
|
+
* page1.graphics.drawRectangle(pen, new RectangleF({x : 100, y : 100}, {width : 100, height : 50}));
|
|
1823
|
+
* // save the document.
|
|
1824
|
+
* document.save('output.pdf');
|
|
1825
|
+
* // destroy the document
|
|
1826
|
+
* document.destroy();
|
|
1827
|
+
* ```
|
|
1828
|
+
* @param scaleX Scale factor in the x direction.
|
|
1829
|
+
* @param scaleY Scale factor in the y direction.
|
|
1830
|
+
*/
|
|
1831
|
+
/* tslint:enable */
|
|
1832
|
+
public scaleTransform(scaleX : number, scaleY : number) : void {
|
|
1833
|
+
let matrix : PdfTransformationMatrix = new PdfTransformationMatrix();
|
|
1834
|
+
this.getScaleTransform(scaleX, scaleY, matrix);
|
|
1835
|
+
this.pdfStreamWriter.modifyCtm(matrix);
|
|
1836
|
+
this.matrix.multiply(matrix);
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* `Scales` coordinates of the input matrix.
|
|
1840
|
+
* @private
|
|
1841
|
+
*/
|
|
1842
|
+
private getScaleTransform(x : number, y : number, input : PdfTransformationMatrix) : PdfTransformationMatrix {
|
|
1843
|
+
if (input == null) {
|
|
1844
|
+
input = new PdfTransformationMatrix();
|
|
1845
|
+
}
|
|
1846
|
+
input.scale(x, y);
|
|
1847
|
+
return input;
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Applies the specified `rotation` to the transformation matrix of this Graphics.
|
|
1851
|
+
* ```typescript
|
|
1852
|
+
* // create a new PDF document
|
|
1853
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1854
|
+
* // create a new page
|
|
1855
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1856
|
+
* // create pen
|
|
1857
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1858
|
+
* //
|
|
1859
|
+
* // set RotateTransform with 25 degree of angle
|
|
1860
|
+
* page1.graphics.rotateTransform(25);
|
|
1861
|
+
* //
|
|
1862
|
+
* // draw the rectangle after RotateTransformation
|
|
1863
|
+
* page1.graphics.drawRectangle(pen, new RectangleF({x : 100, y : 100}, {width : 100, height : 50}));
|
|
1864
|
+
* // save the document.
|
|
1865
|
+
* document.save('output.pdf');
|
|
1866
|
+
* // destroy the document
|
|
1867
|
+
* document.destroy();
|
|
1868
|
+
* ```
|
|
1869
|
+
* @param angle Angle of rotation in degrees.
|
|
1870
|
+
*/
|
|
1871
|
+
public rotateTransform(angle : number) : void {
|
|
1872
|
+
let matrix : PdfTransformationMatrix = new PdfTransformationMatrix();
|
|
1873
|
+
this.getRotateTransform(angle, matrix);
|
|
1874
|
+
this.pdfStreamWriter.modifyCtm(matrix);
|
|
1875
|
+
this.matrix.multiply(matrix);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* `Initializes coordinate system`.
|
|
1879
|
+
* @private
|
|
1880
|
+
*/
|
|
1881
|
+
public initializeCoordinates() : void {
|
|
1882
|
+
// Matrix equation: TM(T-1)=M', where T=[1 0 0 -1 0 h]
|
|
1883
|
+
this.pdfStreamWriter.writeComment('Change co-ordinate system to left/top.');
|
|
1884
|
+
// Translate co-ordinates only, don't flip.
|
|
1885
|
+
if (this.mediaBoxUpperRightBound !== -(this.size.height)) {
|
|
1886
|
+
if (this.cropBox == null) {
|
|
1887
|
+
if (this.mediaBoxUpperRightBound === this.size.height || this.mediaBoxUpperRightBound === 0) {
|
|
1888
|
+
this.translateTransform(0, this.updateY(this.size.height));
|
|
1889
|
+
} else {
|
|
1890
|
+
this.translateTransform(0, this.updateY(this.mediaBoxUpperRightBound));
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* `Rotates` coordinates of the input matrix.
|
|
1897
|
+
* @private
|
|
1898
|
+
*/
|
|
1899
|
+
private getRotateTransform(angle : number, input : PdfTransformationMatrix) : PdfTransformationMatrix {
|
|
1900
|
+
if (input == null || typeof input === 'undefined') {
|
|
1901
|
+
input = new PdfTransformationMatrix();
|
|
1902
|
+
}
|
|
1903
|
+
input.rotate(this.updateY(angle));
|
|
1904
|
+
return input;
|
|
1905
|
+
}
|
|
1906
|
+
/**
|
|
1907
|
+
* `Saves` the current state of this Graphics and identifies the saved state with a GraphicsState.
|
|
1908
|
+
* ```typescript
|
|
1909
|
+
* // create a new PDF document
|
|
1910
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1911
|
+
* // create a new page
|
|
1912
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1913
|
+
* // create pen
|
|
1914
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(0, 0, 0));
|
|
1915
|
+
* //
|
|
1916
|
+
* // save the graphics state
|
|
1917
|
+
* let state1 : PdfGraphicsState = page1.graphics.save();
|
|
1918
|
+
* //
|
|
1919
|
+
* page1.graphics.scaleTransform(1.5, 2);
|
|
1920
|
+
* // draw the rectangle
|
|
1921
|
+
* page1.graphics.drawRectangle(pen, new RectangleF({x : 100, y : 100}, {width : 100, height : 50}));
|
|
1922
|
+
* // restore the graphics state
|
|
1923
|
+
* page1.graphics.restore(state1);
|
|
1924
|
+
* // save the document.
|
|
1925
|
+
* document.save('output.pdf');
|
|
1926
|
+
* // destroy the document
|
|
1927
|
+
* document.destroy();
|
|
1928
|
+
* ```
|
|
1929
|
+
*/
|
|
1930
|
+
public save() : PdfGraphicsState {
|
|
1931
|
+
let state : PdfGraphicsState = new PdfGraphicsState(this, this.matrix.clone());
|
|
1932
|
+
state.brush = this.currentBrush;
|
|
1933
|
+
state.pen = this.currentPen;
|
|
1934
|
+
state.font = this.currentFont;
|
|
1935
|
+
state.colorSpace = this.currentColorSpace;
|
|
1936
|
+
state.characterSpacing = this.previousCharacterSpacing;
|
|
1937
|
+
state.wordSpacing = this.previousWordSpacing;
|
|
1938
|
+
state.textScaling = this.previousTextScaling;
|
|
1939
|
+
state.textRenderingMode = this.previousTextRenderingMode;
|
|
1940
|
+
this.graphicsState.push(state);
|
|
1941
|
+
this.pdfStreamWriter.saveGraphicsState();
|
|
1942
|
+
return state;
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* `Restores the state` of this Graphics to the state represented by a GraphicsState.
|
|
1946
|
+
* @private
|
|
1947
|
+
*/
|
|
1948
|
+
public restore() : void
|
|
1949
|
+
/**
|
|
1950
|
+
* `Restores the state` of this Graphics to the state represented by a GraphicsState.
|
|
1951
|
+
* @private
|
|
1952
|
+
*/
|
|
1953
|
+
public restore(state : PdfGraphicsState) : void
|
|
1954
|
+
public restore(state ?: PdfGraphicsState) : void {
|
|
1955
|
+
if (typeof state === 'undefined') {
|
|
1956
|
+
if (this.graphicsState.length > 0) {
|
|
1957
|
+
this.doRestoreState();
|
|
1958
|
+
}
|
|
1959
|
+
} else {
|
|
1960
|
+
if (this.graphicsState.indexOf(state) !== -1) {
|
|
1961
|
+
for ( ; ; ) {
|
|
1962
|
+
if (this.graphicsState.length === 0) {
|
|
1963
|
+
break;
|
|
1964
|
+
}
|
|
1965
|
+
let popState : PdfGraphicsState = this.doRestoreState();
|
|
1966
|
+
if (popState === state) {
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* `Restores graphics state`.
|
|
1975
|
+
* @private
|
|
1976
|
+
*/
|
|
1977
|
+
private doRestoreState() : PdfGraphicsState {
|
|
1978
|
+
let state : PdfGraphicsState = this.graphicsState.pop();
|
|
1979
|
+
this.transformationMatrix = state.matrix;
|
|
1980
|
+
this.currentBrush = state.brush;
|
|
1981
|
+
this.currentPen = state.pen;
|
|
1982
|
+
this.currentFont = state.font;
|
|
1983
|
+
this.currentColorSpace = state.colorSpace;
|
|
1984
|
+
this.previousCharacterSpacing = state.characterSpacing;
|
|
1985
|
+
this.previousWordSpacing = state.wordSpacing;
|
|
1986
|
+
this.previousTextScaling = state.textScaling;
|
|
1987
|
+
this.previousTextRenderingMode = state.textRenderingMode;
|
|
1988
|
+
this.pdfStreamWriter.restoreGraphicsState();
|
|
1989
|
+
return state;
|
|
1990
|
+
}
|
|
1991
|
+
/* tslint:enable */
|
|
1992
|
+
/**
|
|
1993
|
+
* `Draws the specified path`, using its original physical size, at the location specified by a coordinate pair.
|
|
1994
|
+
* ```typescript
|
|
1995
|
+
* // create a new PDF document.
|
|
1996
|
+
* let document : PdfDocument = new PdfDocument();
|
|
1997
|
+
* // add a page to the document.
|
|
1998
|
+
* let page1 : PdfPage = document.pages.add();
|
|
1999
|
+
* //Create new PDF path.
|
|
2000
|
+
* let path : PdfPath = new PdfPath();
|
|
2001
|
+
* //Add line path points.
|
|
2002
|
+
* path.addLine(new PointF(10, 100), new PointF(10, 200));
|
|
2003
|
+
* path.addLine(new PointF(100, 100), new PointF(100, 200));
|
|
2004
|
+
* path.addLine(new PointF(100, 200), new PointF(55, 150));
|
|
2005
|
+
* // set pen
|
|
2006
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(255, 0, 0));
|
|
2007
|
+
* // set brush
|
|
2008
|
+
* let brush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
|
|
2009
|
+
* // draw the path
|
|
2010
|
+
* page1.graphics.drawPath(pen, brush, path);
|
|
2011
|
+
* //
|
|
2012
|
+
* // save the document.
|
|
2013
|
+
* document.save('output.pdf');
|
|
2014
|
+
* // destroy the document
|
|
2015
|
+
* document.destroy();
|
|
2016
|
+
* ```
|
|
2017
|
+
* @param pen Color of the text.
|
|
2018
|
+
* @param brush Color of the text.
|
|
2019
|
+
* @param path Draw path.
|
|
2020
|
+
*/
|
|
2021
|
+
public drawPath(pen: PdfPen, brush: PdfBrush, path: PdfPath) : void {
|
|
2022
|
+
if (brush instanceof PdfTilingBrush) {
|
|
2023
|
+
this.bCSInitialized = false;
|
|
2024
|
+
(<PdfTilingBrush>brush).graphics.colorSpace = this.colorSpace;
|
|
2025
|
+
} else if (brush instanceof PdfGradientBrush) {
|
|
2026
|
+
this.bCSInitialized = false;
|
|
2027
|
+
(<PdfGradientBrush>brush).colorSpace = this.colorSpace;
|
|
2028
|
+
}
|
|
2029
|
+
this.stateControl(pen, brush, null);
|
|
2030
|
+
this.buildUpPath(path.pathPoints, path.pathTypes);
|
|
2031
|
+
this.drawPathHelper(pen, brush, path.fillMode, false);
|
|
2032
|
+
}
|
|
2033
|
+
/* tslint:enable */
|
|
2034
|
+
//drawArc overloads
|
|
2035
|
+
/**
|
|
2036
|
+
* `Draws the specified arc`, using its original physical size, at the location specified by a coordinate pair.
|
|
2037
|
+
* ```typescript
|
|
2038
|
+
* // create a new PDF document.
|
|
2039
|
+
* let document : PdfDocument = new PdfDocument();
|
|
2040
|
+
* // add a page to the document.
|
|
2041
|
+
* let page1 : PdfPage = document.pages.add();
|
|
2042
|
+
* let pen : PdfPen = new PdfPen(new PdfColor(255, 0, 0));
|
|
2043
|
+
* // draw the path
|
|
2044
|
+
* page1.graphics.drawArc(pen, 10, 10, 100, 200, 90, 270);
|
|
2045
|
+
* // save the document.
|
|
2046
|
+
* document.save('output.pdf');
|
|
2047
|
+
* // destroy the document
|
|
2048
|
+
* document.destroy();
|
|
2049
|
+
* ```
|
|
2050
|
+
* @param name Pen that determines the color, width, and style of the arc.
|
|
2051
|
+
* @param rectangle RectangleF structure that defines the boundaries of the ellipse.
|
|
2052
|
+
* @param startAngle Angle in degrees measured clockwise from the x-axis to the starting point of the arc.
|
|
2053
|
+
* @param sweepAngle Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
|
|
2054
|
+
*/
|
|
2055
|
+
public drawArc(pen: PdfPen, rectangle: RectangleF, startAngle: number, sweepAngle: number) : void
|
|
2056
|
+
public drawArc(pen: PdfPen, x: number, y: number, width: number, height: number, startAngle: number, sweepAngle: number) : void
|
|
2057
|
+
/* tslint:disable-next-line:max-line-length */
|
|
2058
|
+
public drawArc(arg1 : PdfPen, arg2 : number|RectangleF, arg3 ?: number, arg4 ?: number, arg5 ?: number, arg6 ?: number, arg7 ?: number) : void {
|
|
2059
|
+
if (arg2 instanceof RectangleF) {
|
|
2060
|
+
this.drawArc(arg1, arg2.x, arg2.y, arg2.width, arg2.height, arg3, arg4);
|
|
2061
|
+
} else {
|
|
2062
|
+
if ((arg7 !== 0)) {
|
|
2063
|
+
this.stateControl(arg1, null, null);
|
|
2064
|
+
this.constructArcPath(arg2, arg3, (arg2 + arg4), (arg3 + arg5), arg6, arg7);
|
|
2065
|
+
this.drawPathHelper(arg1, null, false);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* Builds up the path.
|
|
2071
|
+
* @private
|
|
2072
|
+
*/
|
|
2073
|
+
private buildUpPath(arg1 : PointF[], arg2 : number[]) : void {
|
|
2074
|
+
let cnt : number = arg1.length;
|
|
2075
|
+
for (let i : number = 0 ; i < cnt; ++i) {
|
|
2076
|
+
let typeValue: number = 0;
|
|
2077
|
+
let point: PointF = arg1[i];
|
|
2078
|
+
switch ((<PathPointType>((arg2[i] & (<number>(PdfGraphics.pathTypesValuesMask)))))) {
|
|
2079
|
+
case PathPointType.Start:
|
|
2080
|
+
this.pdfStreamWriter.beginPath(point.x, point.y);
|
|
2081
|
+
break;
|
|
2082
|
+
case PathPointType.Bezier3:
|
|
2083
|
+
let p2 : PointF = new PointF(0, 0);
|
|
2084
|
+
let p3 : PointF = new PointF(0, 0);
|
|
2085
|
+
let result1 : { i: number, p2 : PointF, p3 : PointF } = this.getBezierPoints(arg1, arg2, i, p2, p3);
|
|
2086
|
+
this.pdfStreamWriter.appendBezierSegment(point, result1.p2, result1.p3);
|
|
2087
|
+
i = result1.i;
|
|
2088
|
+
break;
|
|
2089
|
+
case PathPointType.Line:
|
|
2090
|
+
this.pdfStreamWriter.appendLineSegment(point);
|
|
2091
|
+
break;
|
|
2092
|
+
default:
|
|
2093
|
+
throw new Error('ArithmeticException - Incorrect path formation.');
|
|
2094
|
+
}
|
|
2095
|
+
typeValue = arg2[i];
|
|
2096
|
+
this.checkFlags(typeValue);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
/**
|
|
2100
|
+
* Gets the bezier points from respective arrays.
|
|
2101
|
+
* @private
|
|
2102
|
+
*/
|
|
2103
|
+
/* tslint:disable-next-line:max-line-length */
|
|
2104
|
+
private getBezierPoints(points: PointF[], types: number[], i: number, p2: PointF, p3: PointF) : { i : number, p2 : PointF, p3 : PointF } {
|
|
2105
|
+
let errorMsg: string = 'Malforming path.';
|
|
2106
|
+
++i;
|
|
2107
|
+
if (((<PathPointType>((types[i] & PdfGraphics.pathTypesValuesMask))) === PathPointType.Bezier3)) {
|
|
2108
|
+
p2 = points[i];
|
|
2109
|
+
++i;
|
|
2110
|
+
if (((<PathPointType>((types[i] & PdfGraphics.pathTypesValuesMask))) === PathPointType.Bezier3)) {
|
|
2111
|
+
p3 = points[i];
|
|
2112
|
+
} else {
|
|
2113
|
+
throw new Error ('ArgumentException : errorMsg');
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
throw new Error ('ArgumentException : errorMsg');
|
|
2117
|
+
}
|
|
2118
|
+
return { i : i, p2 : p2, p3 : p3 };
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
/**
|
|
2122
|
+
* Checks path point type flags.
|
|
2123
|
+
* @private
|
|
2124
|
+
*/
|
|
2125
|
+
private checkFlags(type : number) : void {
|
|
2126
|
+
if (((<PathPointType>((type & (<number>(PathPointType.CloseSubpath))))) === PathPointType.CloseSubpath)) {
|
|
2127
|
+
this.pdfStreamWriter.closePath();
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Constructs the arc path using Bezier curves.
|
|
2132
|
+
* @private
|
|
2133
|
+
*/
|
|
2134
|
+
private constructArcPath(x1: number, y1: number, x2: number, y2: number, startAng: number, sweepAngle: number) : void {
|
|
2135
|
+
let points: number[] = this.getBezierArc(x1, y1, x2, y2, startAng, sweepAngle);
|
|
2136
|
+
if ((points.length === 0)) {
|
|
2137
|
+
return;
|
|
2138
|
+
}
|
|
2139
|
+
let pt: number[] = [points[0], points[1], points[2], points[3], points[4], points[5], points[6], points[7]];
|
|
2140
|
+
this.pdfStreamWriter.beginPath(pt[0], pt[1]);
|
|
2141
|
+
let i: number = 0;
|
|
2142
|
+
for (i = 0 ; i < points.length; i = i + 8) {
|
|
2143
|
+
pt = [ points[i], points[i + 1], points[i + 2], points[i + 3], points[i + 4], points[i + 5], points[i + 6], points[i + 7]];
|
|
2144
|
+
this.pdfStreamWriter.appendBezierSegment(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Gets the bezier points for arc constructing.
|
|
2149
|
+
* @private
|
|
2150
|
+
*/
|
|
2151
|
+
private getBezierArc(numX1: number, numY1: number, numX2: number, numY2: number, s1: number, e1: number): number[] {
|
|
2152
|
+
if ((numX1 > numX2)) {
|
|
2153
|
+
let tmp: number;
|
|
2154
|
+
tmp = numX1;
|
|
2155
|
+
numX1 = numX2;
|
|
2156
|
+
numX2 = tmp;
|
|
2157
|
+
}
|
|
2158
|
+
if ((numY2 > numY1)) {
|
|
2159
|
+
let tmp: number;
|
|
2160
|
+
tmp = numY1;
|
|
2161
|
+
numY1 = numY2;
|
|
2162
|
+
numY2 = tmp;
|
|
2163
|
+
}
|
|
2164
|
+
let fragAngle1: number;
|
|
2165
|
+
let numFragments: number;
|
|
2166
|
+
if ((Math.abs(e1) <= 90)) {
|
|
2167
|
+
fragAngle1 = e1;
|
|
2168
|
+
numFragments = 1;
|
|
2169
|
+
} else {
|
|
2170
|
+
numFragments = (<number>(Math.ceil((Math.abs(e1) / 90))));
|
|
2171
|
+
fragAngle1 = (e1 / numFragments);
|
|
2172
|
+
}
|
|
2173
|
+
let xcen: number = ((numX1 + numX2) / 2);
|
|
2174
|
+
let ycen: number = ((numY1 + numY2) / 2);
|
|
2175
|
+
let rx: number = ((numX2 - numX1) / 2);
|
|
2176
|
+
let ry: number = ((numY2 - numY1) / 2);
|
|
2177
|
+
let halfAng: number = (<number>((fragAngle1 * (Math.PI / 360))));
|
|
2178
|
+
let kappa: number = (<number>(Math.abs(4.0 / 3.0 * (1.0 - Math.cos(halfAng)) / Math.sin(halfAng))));
|
|
2179
|
+
let pointsList: number[] = [];
|
|
2180
|
+
for (let i: number = 0; (i < numFragments); i++) {
|
|
2181
|
+
let thetaValue0: number = (<number>(((s1 + (i * fragAngle1)) * (Math.PI / 180))));
|
|
2182
|
+
let thetaValue1: number = (<number>(((s1 + ((i + 1) * fragAngle1)) * (Math.PI / 180))));
|
|
2183
|
+
let cos0: number = (<number>(Math.cos(thetaValue0)));
|
|
2184
|
+
let cos1: number = (<number>(Math.cos(thetaValue1)));
|
|
2185
|
+
let sin0: number = (<number>(Math.sin(thetaValue0)));
|
|
2186
|
+
let sin1: number = (<number>(Math.sin(thetaValue1)));
|
|
2187
|
+
if ((fragAngle1 > 0)) {
|
|
2188
|
+
/* tslint:disable-next-line:max-line-length */
|
|
2189
|
+
pointsList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 - (kappa * sin0)))), (ycen - (ry * (sin0 + (kappa * cos0)))), (xcen + (rx * (cos1 + (kappa * sin1)))), (ycen - (ry * (sin1 - (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
|
|
2190
|
+
} else {
|
|
2191
|
+
/* tslint:disable-next-line:max-line-length */
|
|
2192
|
+
pointsList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 + (kappa * sin0)))), (ycen - (ry * (sin0 - (kappa * cos0)))), (xcen + (rx * (cos1 - (kappa * sin1)))), (ycen - (ry * (sin1 + (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1)));
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return pointsList;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* `GetResourceEventHandler` class is alternate for event handlers and delegates.
|
|
2200
|
+
* @private
|
|
2201
|
+
* @hidden
|
|
2202
|
+
*/
|
|
2203
|
+
export class GetResourceEventHandler {
|
|
2204
|
+
/**
|
|
2205
|
+
* Return the instance of `PdfResources` class.
|
|
2206
|
+
* @private
|
|
2207
|
+
*/
|
|
2208
|
+
public getResources() : PdfResources {
|
|
2209
|
+
return this.sender.getResources();
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Variable to store instance of `PdfPageBase as sender`.
|
|
2213
|
+
* @hidden
|
|
2214
|
+
* @private
|
|
2215
|
+
*/
|
|
2216
|
+
public sender : PdfPageBase|PdfTemplate|PdfTilingBrush;
|
|
2217
|
+
/**
|
|
2218
|
+
* Initialize instance of `GetResourceEventHandler` class.
|
|
2219
|
+
* Alternate for event handlers and delegates.
|
|
2220
|
+
* @private
|
|
2221
|
+
*/
|
|
2222
|
+
public constructor(sender : PdfPageBase|PdfTemplate|PdfTilingBrush) {
|
|
2223
|
+
this.sender = sender;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
export class PdfGraphicsState {
|
|
2227
|
+
// Fields
|
|
2228
|
+
/**
|
|
2229
|
+
* `Parent graphics` object.
|
|
2230
|
+
* @private
|
|
2231
|
+
*/
|
|
2232
|
+
private pdfGraphics : PdfGraphics;
|
|
2233
|
+
/**
|
|
2234
|
+
* The current `transformation matrix`.
|
|
2235
|
+
* @private
|
|
2236
|
+
*/
|
|
2237
|
+
private transformationMatrix : PdfTransformationMatrix;
|
|
2238
|
+
/**
|
|
2239
|
+
* Stores `previous rendering mode`.
|
|
2240
|
+
* @default TextRenderingMode.Fill
|
|
2241
|
+
* @private
|
|
2242
|
+
*/
|
|
2243
|
+
private internalTextRenderingMode : TextRenderingMode = TextRenderingMode.Fill;
|
|
2244
|
+
/**
|
|
2245
|
+
* `Previous character spacing` value or 0.
|
|
2246
|
+
* @default 0.0
|
|
2247
|
+
* @private
|
|
2248
|
+
*/
|
|
2249
|
+
private internalCharacterSpacing : number = 0.0;
|
|
2250
|
+
/**
|
|
2251
|
+
* `Previous word spacing` value or 0.
|
|
2252
|
+
* @default 0.0
|
|
2253
|
+
* @private
|
|
2254
|
+
*/
|
|
2255
|
+
private internalWordSpacing : number = 0.0;
|
|
2256
|
+
/**
|
|
2257
|
+
* The previously used `text scaling value`.
|
|
2258
|
+
* @default 100.0
|
|
2259
|
+
* @private
|
|
2260
|
+
*/
|
|
2261
|
+
private internalTextScaling : number = 100.0;
|
|
2262
|
+
/**
|
|
2263
|
+
* `Current pen`.
|
|
2264
|
+
* @private
|
|
2265
|
+
*/
|
|
2266
|
+
private pdfPen : PdfPen;
|
|
2267
|
+
/**
|
|
2268
|
+
* `Current brush`.
|
|
2269
|
+
* @private
|
|
2270
|
+
*/
|
|
2271
|
+
private pdfBrush : PdfBrush;
|
|
2272
|
+
/**
|
|
2273
|
+
* `Current font`.
|
|
2274
|
+
* @private
|
|
2275
|
+
*/
|
|
2276
|
+
private pdfFont : PdfFont;
|
|
2277
|
+
/**
|
|
2278
|
+
* `Current color space`.
|
|
2279
|
+
* @default PdfColorSpace.Rgb
|
|
2280
|
+
* @private
|
|
2281
|
+
*/
|
|
2282
|
+
private pdfColorSpace : PdfColorSpace = PdfColorSpace.Rgb;
|
|
2283
|
+
// Properties
|
|
2284
|
+
/**
|
|
2285
|
+
* Gets the parent `graphics object`.
|
|
2286
|
+
* @private
|
|
2287
|
+
*/
|
|
2288
|
+
public get graphics() : PdfGraphics {
|
|
2289
|
+
return this.pdfGraphics;
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Gets the `current matrix`.
|
|
2293
|
+
* @private
|
|
2294
|
+
*/
|
|
2295
|
+
public get matrix() : PdfTransformationMatrix {
|
|
2296
|
+
return this.transformationMatrix;
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Gets or sets the `current character spacing`.
|
|
2300
|
+
* @private
|
|
2301
|
+
*/
|
|
2302
|
+
public get characterSpacing() : number {
|
|
2303
|
+
return this.internalCharacterSpacing;
|
|
2304
|
+
}
|
|
2305
|
+
public set characterSpacing(value : number) {
|
|
2306
|
+
this.internalCharacterSpacing = value;
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Gets or sets the `word spacing` value.
|
|
2310
|
+
* @private
|
|
2311
|
+
*/
|
|
2312
|
+
public get wordSpacing() : number {
|
|
2313
|
+
return this.internalWordSpacing;
|
|
2314
|
+
}
|
|
2315
|
+
public set wordSpacing(value : number) {
|
|
2316
|
+
this.internalWordSpacing = value;
|
|
2317
|
+
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Gets or sets the `text scaling` value.
|
|
2320
|
+
* @private
|
|
2321
|
+
*/
|
|
2322
|
+
public get textScaling() : number {
|
|
2323
|
+
return this.internalTextScaling;
|
|
2324
|
+
}
|
|
2325
|
+
public set textScaling(value : number) {
|
|
2326
|
+
this.internalTextScaling = value;
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Gets or sets the `current pen` object.
|
|
2330
|
+
* @private
|
|
2331
|
+
*/
|
|
2332
|
+
public get pen() : PdfPen {
|
|
2333
|
+
return this.pdfPen;
|
|
2334
|
+
}
|
|
2335
|
+
public set pen(value : PdfPen) {
|
|
2336
|
+
this.pdfPen = value;
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Gets or sets the `brush`.
|
|
2340
|
+
* @private
|
|
2341
|
+
*/
|
|
2342
|
+
public get brush() : PdfBrush {
|
|
2343
|
+
return this.pdfBrush;
|
|
2344
|
+
}
|
|
2345
|
+
public set brush(value : PdfBrush) {
|
|
2346
|
+
this.pdfBrush = value;
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* Gets or sets the `current font` object.
|
|
2350
|
+
* @private
|
|
2351
|
+
*/
|
|
2352
|
+
public get font() : PdfFont {
|
|
2353
|
+
return this.pdfFont;
|
|
2354
|
+
}
|
|
2355
|
+
public set font(value : PdfFont) {
|
|
2356
|
+
this.pdfFont = value;
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Gets or sets the `current color space` value.
|
|
2360
|
+
* @private
|
|
2361
|
+
*/
|
|
2362
|
+
public get colorSpace() : PdfColorSpace {
|
|
2363
|
+
return this.pdfColorSpace;
|
|
2364
|
+
}
|
|
2365
|
+
public set colorSpace(value : PdfColorSpace) {
|
|
2366
|
+
this.pdfColorSpace = value;
|
|
2367
|
+
}
|
|
2368
|
+
/**
|
|
2369
|
+
* Gets or sets the `text rendering mode`.
|
|
2370
|
+
* @private
|
|
2371
|
+
*/
|
|
2372
|
+
public get textRenderingMode() : TextRenderingMode {
|
|
2373
|
+
return this.internalTextRenderingMode;
|
|
2374
|
+
}
|
|
2375
|
+
public set textRenderingMode(value : TextRenderingMode) {
|
|
2376
|
+
this.internalTextRenderingMode = value;
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
// Constructors
|
|
2380
|
+
/**
|
|
2381
|
+
* `default constructor`.
|
|
2382
|
+
* @private
|
|
2383
|
+
*/
|
|
2384
|
+
public constructor()
|
|
2385
|
+
/**
|
|
2386
|
+
* Creates new object for `PdfGraphicsState`.
|
|
2387
|
+
* @private
|
|
2388
|
+
*/
|
|
2389
|
+
public constructor(graphics : PdfGraphics, matrix : PdfTransformationMatrix)
|
|
2390
|
+
public constructor(graphics ?: PdfGraphics, matrix ?: PdfTransformationMatrix) {
|
|
2391
|
+
if (typeof graphics !== 'undefined') {
|
|
2392
|
+
this.pdfGraphics = graphics;
|
|
2393
|
+
const elements: number[] = [];
|
|
2394
|
+
graphics.matrix.matrix.elements.forEach((element: number) => {
|
|
2395
|
+
elements.push(element);
|
|
2396
|
+
});
|
|
2397
|
+
this.transformationMatrix = new PdfTransformationMatrix();
|
|
2398
|
+
this.transformationMatrix.matrix = new Matrix(elements);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
class TransparencyData {
|
|
2403
|
+
// Fields
|
|
2404
|
+
/**
|
|
2405
|
+
* Specifies the `Alpha pen`.
|
|
2406
|
+
* @private
|
|
2407
|
+
*/
|
|
2408
|
+
public alphaPen : number;
|
|
2409
|
+
/**
|
|
2410
|
+
* Specifies the `Alpha brush`.
|
|
2411
|
+
* @private
|
|
2412
|
+
*/
|
|
2413
|
+
public alphaBrush : number;
|
|
2414
|
+
/**
|
|
2415
|
+
* Specifies the `blend mode`.
|
|
2416
|
+
* @private
|
|
2417
|
+
*/
|
|
2418
|
+
public blendMode : PdfBlendMode;
|
|
2419
|
+
// Constructors
|
|
2420
|
+
/**
|
|
2421
|
+
* Initializes a new instance of the `TransparencyData` class.
|
|
2422
|
+
* @private
|
|
2423
|
+
*/
|
|
2424
|
+
public constructor(alphaPen : number, alphaBrush : number, blendMode : PdfBlendMode) {
|
|
2425
|
+
this.alphaPen = alphaPen;
|
|
2426
|
+
this.alphaBrush = alphaBrush;
|
|
2427
|
+
this.blendMode = blendMode;
|
|
2428
|
+
}
|
|
2429
|
+
}
|