@syncfusion/ej2-pdf-export 23.2.6 → 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.
Files changed (161) hide show
  1. package/CHANGELOG.md +0 -26
  2. package/dist/ej2-pdf-export.min.js +2 -2
  3. package/dist/ej2-pdf-export.umd.min.js +1 -1
  4. package/dist/ej2-pdf-export.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-pdf-export.es2015.js.map +1 -1
  6. package/dist/es6/ej2-pdf-export.es5.js.map +1 -1
  7. package/dist/global/ej2-pdf-export.min.js +1 -1
  8. package/dist/global/ej2-pdf-export.min.js.map +1 -1
  9. package/dist/global/index.d.ts +1 -1
  10. package/dist/ts/implementation/actions/action.ts +76 -0
  11. package/dist/ts/implementation/actions/uri-action.ts +52 -0
  12. package/dist/ts/implementation/annotations/action-link-annotation.ts +43 -0
  13. package/dist/ts/implementation/annotations/annotation-collection.ts +159 -0
  14. package/dist/ts/implementation/annotations/annotation.ts +241 -0
  15. package/dist/ts/implementation/annotations/document-link-annotation.ts +118 -0
  16. package/dist/ts/implementation/annotations/link-annotation.ts +32 -0
  17. package/dist/ts/implementation/annotations/pdf-text-web-link.ts +265 -0
  18. package/dist/ts/implementation/annotations/uri-annotation.ts +86 -0
  19. package/dist/ts/implementation/collections/dictionary.ts +150 -0
  20. package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +125 -0
  21. package/dist/ts/implementation/collections/utils.ts +38 -0
  22. package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +39 -0
  23. package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +108 -0
  24. package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +127 -0
  25. package/dist/ts/implementation/document/automatic-fields/composite-field.ts +76 -0
  26. package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +37 -0
  27. package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +75 -0
  28. package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +157 -0
  29. package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +82 -0
  30. package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +60 -0
  31. package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +48 -0
  32. package/dist/ts/implementation/document/pdf-catalog.ts +65 -0
  33. package/dist/ts/implementation/document/pdf-document-base.ts +180 -0
  34. package/dist/ts/implementation/document/pdf-document-template.ts +310 -0
  35. package/dist/ts/implementation/document/pdf-document.ts +342 -0
  36. package/dist/ts/implementation/document/pdf-viewer-preferences.ts +578 -0
  37. package/dist/ts/implementation/drawing/pdf-drawing.ts +218 -0
  38. package/dist/ts/implementation/general/enum.ts +21 -0
  39. package/dist/ts/implementation/general/functions/pdf-function.ts +66 -0
  40. package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +63 -0
  41. package/dist/ts/implementation/general/pdf-cache-collection.ts +97 -0
  42. package/dist/ts/implementation/general/pdf-collection.ts +41 -0
  43. package/dist/ts/implementation/general/pdf-destination.ts +170 -0
  44. package/dist/ts/implementation/graphics/brushes/enum.ts +237 -0
  45. package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +294 -0
  46. package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +68 -0
  47. package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +2438 -0
  48. package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +295 -0
  49. package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +311 -0
  50. package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +406 -0
  51. package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +290 -0
  52. package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +107 -0
  53. package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +304 -0
  54. package/dist/ts/implementation/graphics/constants.ts +31 -0
  55. package/dist/ts/implementation/graphics/enum.ts +413 -0
  56. package/dist/ts/implementation/graphics/figures/arc.ts +133 -0
  57. package/dist/ts/implementation/graphics/figures/base/draw-element.ts +59 -0
  58. package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +260 -0
  59. package/dist/ts/implementation/graphics/figures/base/fill-element.ts +72 -0
  60. package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +34 -0
  61. package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +69 -0
  62. package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +276 -0
  63. package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +205 -0
  64. package/dist/ts/implementation/graphics/figures/ellipse-part.ts +76 -0
  65. package/dist/ts/implementation/graphics/figures/enum.ts +80 -0
  66. package/dist/ts/implementation/graphics/figures/layout-element.ts +132 -0
  67. package/dist/ts/implementation/graphics/figures/path.ts +646 -0
  68. package/dist/ts/implementation/graphics/figures/pdf-template.ts +205 -0
  69. package/dist/ts/implementation/graphics/figures/rectangle-area.ts +108 -0
  70. package/dist/ts/implementation/graphics/figures/text-element.ts +445 -0
  71. package/dist/ts/implementation/graphics/fonts/enum.ts +385 -0
  72. package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +248 -0
  73. package/dist/ts/implementation/graphics/fonts/pdf-font.ts +316 -0
  74. package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +606 -0
  75. package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +243 -0
  76. package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +474 -0
  77. package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +165 -0
  78. package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +958 -0
  79. package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +374 -0
  80. package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +255 -0
  81. package/dist/ts/implementation/graphics/fonts/string-layouter.ts +617 -0
  82. package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +275 -0
  83. package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +206 -0
  84. package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +18 -0
  85. package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +18 -0
  86. package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +14 -0
  87. package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +26 -0
  88. package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +35 -0
  89. package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +94 -0
  90. package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +56 -0
  91. package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +10 -0
  92. package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +14 -0
  93. package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +106 -0
  94. package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +58 -0
  95. package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +33 -0
  96. package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +22 -0
  97. package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +42 -0
  98. package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +1254 -0
  99. package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +26 -0
  100. package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +26 -0
  101. package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +577 -0
  102. package/dist/ts/implementation/graphics/images/byte-array.ts +137 -0
  103. package/dist/ts/implementation/graphics/images/image-decoder.ts +439 -0
  104. package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +110 -0
  105. package/dist/ts/implementation/graphics/images/pdf-image.ts +132 -0
  106. package/dist/ts/implementation/graphics/pdf-color.ts +478 -0
  107. package/dist/ts/implementation/graphics/pdf-graphics.ts +2429 -0
  108. package/dist/ts/implementation/graphics/pdf-margins.ts +124 -0
  109. package/dist/ts/implementation/graphics/pdf-pen.ts +370 -0
  110. package/dist/ts/implementation/graphics/pdf-resources.ts +300 -0
  111. package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +246 -0
  112. package/dist/ts/implementation/graphics/pdf-transparency.ts +93 -0
  113. package/dist/ts/implementation/graphics/unit-convertor.ts +96 -0
  114. package/dist/ts/implementation/input-output/big-endian-writer.ts +121 -0
  115. package/dist/ts/implementation/input-output/cross-table.ts +21 -0
  116. package/dist/ts/implementation/input-output/enum.ts +16 -0
  117. package/dist/ts/implementation/input-output/pdf-cross-table.ts +524 -0
  118. package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +571 -0
  119. package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +194 -0
  120. package/dist/ts/implementation/input-output/pdf-operators.ts +363 -0
  121. package/dist/ts/implementation/input-output/pdf-stream-writer.ts +681 -0
  122. package/dist/ts/implementation/input-output/pdf-writer.ts +88 -0
  123. package/dist/ts/implementation/pages/enum.ts +201 -0
  124. package/dist/ts/implementation/pages/page-added-event-arguments.ts +39 -0
  125. package/dist/ts/implementation/pages/pdf-document-page-collection.ts +180 -0
  126. package/dist/ts/implementation/pages/pdf-page-base.ts +181 -0
  127. package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +348 -0
  128. package/dist/ts/implementation/pages/pdf-page-layer.ts +271 -0
  129. package/dist/ts/implementation/pages/pdf-page-settings.ts +192 -0
  130. package/dist/ts/implementation/pages/pdf-page-size.ts +162 -0
  131. package/dist/ts/implementation/pages/pdf-page-template-element.ts +663 -0
  132. package/dist/ts/implementation/pages/pdf-page.ts +235 -0
  133. package/dist/ts/implementation/pages/pdf-section-collection.ts +187 -0
  134. package/dist/ts/implementation/pages/pdf-section-page-collection.ts +61 -0
  135. package/dist/ts/implementation/pages/pdf-section-templates.ts +96 -0
  136. package/dist/ts/implementation/pages/pdf-section.ts +644 -0
  137. package/dist/ts/implementation/primitives/pdf-array.ts +386 -0
  138. package/dist/ts/implementation/primitives/pdf-boolean.ts +119 -0
  139. package/dist/ts/implementation/primitives/pdf-dictionary.ts +513 -0
  140. package/dist/ts/implementation/primitives/pdf-name.ts +218 -0
  141. package/dist/ts/implementation/primitives/pdf-number.ts +165 -0
  142. package/dist/ts/implementation/primitives/pdf-reference.ts +430 -0
  143. package/dist/ts/implementation/primitives/pdf-stream.ts +306 -0
  144. package/dist/ts/implementation/primitives/pdf-string.ts +397 -0
  145. package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +2027 -0
  146. package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +1193 -0
  147. package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +206 -0
  148. package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +470 -0
  149. package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +853 -0
  150. package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +240 -0
  151. package/dist/ts/implementation/structured-elements/grid/styles/style.ts +424 -0
  152. package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +16 -0
  153. package/dist/ts/interfaces/i-pdf-cache.ts +23 -0
  154. package/dist/ts/interfaces/i-pdf-changable.ts +17 -0
  155. package/dist/ts/interfaces/i-pdf-clonable.ts +12 -0
  156. package/dist/ts/interfaces/i-pdf-primitives.ts +45 -0
  157. package/dist/ts/interfaces/i-pdf-true-type-font.ts +48 -0
  158. package/dist/ts/interfaces/i-pdf-wrapper.ts +13 -0
  159. package/dist/ts/interfaces/i-pdf-writer.ts +29 -0
  160. package/package.json +7 -7
  161. package/src/implementation/document/pdf-document-base.js +1 -2
@@ -0,0 +1,132 @@
1
+ /**
2
+ * PdfImage.ts class for EJ2-PDF
3
+ */
4
+ import { IPdfWrapper } from './../../../interfaces/i-pdf-wrapper';
5
+ import { IPdfPrimitive } from './../../../interfaces/i-pdf-primitives';
6
+ import { PdfStream } from './../../primitives/pdf-stream';
7
+ import { SizeF } from './../../drawing/pdf-drawing';
8
+ import { PdfGraphicsUnit } from './../enum';
9
+ import { PdfUnitConverter } from './../unit-convertor';
10
+ import { PdfBitmap } from './pdf-bitmap';
11
+ /**
12
+ * `PdfImage` class represents the base class for images and provides functionality for the 'PdfBitmap' class.
13
+ * @private
14
+ */
15
+ export abstract class PdfImage implements IPdfWrapper {
16
+ /**
17
+ * `Width` of an image.
18
+ * @private
19
+ */
20
+ private imageWidth : number;
21
+ /**
22
+ * `Height` of an image.
23
+ * @private
24
+ */
25
+ private imageHeight : number;
26
+ /**
27
+ * `Bits per component` of an image.
28
+ * @hidden
29
+ * @private
30
+ */
31
+ public bitsPerComponent : number;
32
+ /**
33
+ * `horizontal resolution` of an image.
34
+ * @hidden
35
+ * @private
36
+ */
37
+ public horizontalResolution : number;
38
+ /**
39
+ * `Vertical resolution` of an image.
40
+ * @hidden
41
+ * @private
42
+ */
43
+ public verticalResolution : number;
44
+ /**
45
+ * `physical dimension` of an image.
46
+ * @hidden
47
+ * @private
48
+ */
49
+ private imagePhysicalDimension : SizeF;
50
+ /**
51
+ * Gets and Sets the `width` of an image.
52
+ * @private
53
+ */
54
+ public get width() : number {
55
+ return this.imageWidth;
56
+ }
57
+ public set width(value : number) {
58
+ this.imageWidth = value;
59
+ }
60
+ /**
61
+ * Gets and Sets the `height` of an image.
62
+ * @private
63
+ */
64
+ public get height() : number {
65
+ return this.imageHeight;
66
+ }
67
+ public set height(value : number) {
68
+ this.imageHeight = value;
69
+ }
70
+ /**
71
+ * Gets or sets the size of the image.
72
+ * @private
73
+ */
74
+ public set size(value : SizeF) {
75
+ this.width = value.width;
76
+ this.height = value.height;
77
+ }
78
+ /**
79
+ * Gets the `physical dimension` of an image.
80
+ * @private
81
+ */
82
+ public get physicalDimension() : SizeF {
83
+ this.imagePhysicalDimension = this.getPointSize(this.width, this.height, this.horizontalResolution, this.verticalResolution);
84
+ return new SizeF(this.width, this.height);
85
+ }
86
+ /**
87
+ * return the stored `stream of an image`.
88
+ * @private
89
+ */
90
+ public imageStream : PdfStream;
91
+ // /**
92
+ // * Gets the `image stream as string`.
93
+ // * @private
94
+ // */
95
+ // public static fromString(string : string) : PdfImage {
96
+ // let image : PdfImage = new PdfBitmap(string);
97
+ // return image;
98
+ // }
99
+ /**
100
+ * Gets the `element` image stream.
101
+ * @private
102
+ */
103
+ public get element() : IPdfPrimitive {
104
+ return this.imageStream;
105
+ }
106
+ /**
107
+ * `Save` the image stream.
108
+ * @private
109
+ */
110
+ public abstract save() : void;
111
+ /**
112
+ * Return the value of `width and height of an image` in points.
113
+ * @private
114
+ */
115
+ public getPointSize(width : number, height : number) : SizeF
116
+ public getPointSize(width : number, height : number, horizontalResolution : number, verticalResolution : number) : SizeF
117
+ public getPointSize(width : number, height : number, horizontalResolution ?: number, verticalResolution ?: number) : SizeF {
118
+ if (typeof horizontalResolution === 'undefined') {
119
+ let dpiX : number = PdfUnitConverter.horizontalResolution;
120
+ let dpiY : number = PdfUnitConverter.verticalResolution;
121
+ let size : SizeF = this.getPointSize(width, height, dpiX, dpiY);
122
+ return size;
123
+ } else {
124
+ let ucX : PdfUnitConverter = new PdfUnitConverter(horizontalResolution);
125
+ let ucY : PdfUnitConverter = new PdfUnitConverter(verticalResolution);
126
+ let ptWidth : number = ucX.convertUnits(width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
127
+ let ptHeight : number = ucY.convertUnits(height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
128
+ let size : SizeF = new SizeF(ptWidth, ptHeight);
129
+ return size;
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,478 @@
1
+ import { PdfColorSpace } from './enum';
2
+ import { Operators } from './../input-output/pdf-operators';
3
+ import { Dictionary } from './../collections/dictionary';
4
+ import { PdfNumber } from './../primitives/pdf-number';
5
+ import { PdfArray } from './../primitives/pdf-array';
6
+ /**
7
+ * Implements structures and routines working with `color`.
8
+ * ```typescript
9
+ * // create a new PDF document
10
+ * let document : PdfDocument = new PdfDocument();
11
+ * // add a new page to the document
12
+ * let page1 : PdfPage = document.pages.add();
13
+ * // set the font
14
+ * let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
15
+ * //
16
+ * // set color
17
+ * let brushColor : PdfColor = new PdfColor(0, 0, 0);
18
+ * //
19
+ * // create black brush
20
+ * let blackBrush : PdfSolidBrush = new PdfSolidBrush(brushColor);
21
+ * // draw the text
22
+ * page1.graphics.drawString('Hello World', font, blackBrush, new PointF(0, 0));
23
+ * // save the document
24
+ * document.save('output.pdf');
25
+ * // destroy the document
26
+ * document.destroy();
27
+ * ```
28
+ * @default black color
29
+ */
30
+ export class PdfColor {
31
+ //Fields
32
+ /**
33
+ * Holds `RGB colors` converted into strings.
34
+ * @private
35
+ */
36
+ private static rgbStrings : Dictionary<number, Object> = new Dictionary<number, Object>();
37
+ /**
38
+ * Holds Gray scale colors converted into strings for `stroking`.
39
+ * @private
40
+ */
41
+ private static grayStringsSroke : Dictionary<number, Object> = new Dictionary<number, Object>();
42
+ /**
43
+ * Holds Gray scale colors converted into strings for `filling`.
44
+ * @private
45
+ */
46
+ private static grayStringsFill : Dictionary<number, Object> = new Dictionary<number, Object>();
47
+ /**
48
+ * Value of `Red` channel.
49
+ * @private
50
+ */
51
+ private redColor : number;
52
+ /**
53
+ * Value of `Cyan` channel.
54
+ * @private
55
+ */
56
+ private cyanColor : number;
57
+ /**
58
+ * Value of `Green` channel.
59
+ * @private
60
+ */
61
+ private greenColor : number;
62
+ /**
63
+ * Value of `Magenta` channel.
64
+ * @private
65
+ */
66
+ private magentaColor : number;
67
+ /**
68
+ * Value of `Blue` channel.
69
+ * @private
70
+ */
71
+ private blueColor : number;
72
+ /**
73
+ * Value of `Yellow` channel.
74
+ * @private
75
+ */
76
+ private yellowColor : number;
77
+ /**
78
+ * Value of `Black` channel.
79
+ * @private
80
+ */
81
+ private blackColor : number;
82
+ /**
83
+ * Value of `Gray` channel.
84
+ * @private
85
+ */
86
+ private grayColor : number;
87
+ /**
88
+ * `Alpha` channel.
89
+ * @private
90
+ */
91
+ private alpha : number;
92
+ /**
93
+ * Shows if the color `is empty`.
94
+ * @private
95
+ */
96
+ private filled : boolean;
97
+ /**
98
+ * `Max value` of color channel.
99
+ * @private
100
+ */
101
+ public static readonly maxColourChannelValue : number = 255.0;
102
+
103
+ //constructor
104
+ /**
105
+ * Initialize a new instance for `PdfColor` class.
106
+ */
107
+ public constructor()
108
+ public constructor(color1 : PdfColor)
109
+ public constructor(color1 : number)
110
+ public constructor(color1 : number, color2 : number, color3 : number)
111
+ public constructor(color1 : number, color2 : number, color3 : number, color4 : number)
112
+ public constructor(color1 ?: number|PdfColor, color2 ?: number, color3 ?: number, color4 ?: number) {
113
+ if (typeof color1 === 'undefined') {
114
+ if (typeof color2 !== 'undefined' && typeof color3 !== 'undefined' && typeof color4 !== 'undefined') {
115
+ this.assignRGB(color2, color3, color4);
116
+ } else {
117
+ this.filled = false;
118
+ }
119
+ } else if (color1 instanceof PdfColor) {
120
+ this.redColor = color1.r;
121
+ this.greenColor = color1.g;
122
+ this.blueColor = color1.b;
123
+ this.grayColor = color1.gray;
124
+ this.alpha = color1.alpha;
125
+ this.filled = (this.alpha !== 0);
126
+ /* tslint:disable-next-line:max-line-length */
127
+ } else if (typeof color1 === 'number' && typeof color2 === 'undefined' && typeof color3 === 'undefined' && typeof color4 === 'undefined') {
128
+ if (color1 < 0) {
129
+ color1 = 0;
130
+ }
131
+ if (color1 > 1) {
132
+ color1 = 1;
133
+ }
134
+ this.redColor = color1 * PdfColor.maxColourChannelValue;
135
+ this.greenColor = color1 * PdfColor.maxColourChannelValue;
136
+ this.blueColor = color1 * PdfColor.maxColourChannelValue;
137
+ this.cyanColor = color1;
138
+ this.magentaColor = color1;
139
+ this.yellowColor = color1;
140
+ this.blackColor = color1;
141
+ this.grayColor = color1;
142
+ this.alpha = PdfColor.maxColourChannelValue;
143
+ this.filled = true;
144
+ } else if (typeof color4 === 'undefined') {
145
+ this.assignRGB(color1, color2, color3);
146
+ } else {
147
+ this.assignRGB(color2, color3, color4, color1);
148
+ }
149
+ }
150
+ /**
151
+ * `Assign` red, green, blue colors with alpha value..
152
+ * @private
153
+ */
154
+ private assignRGB(r : number, g : number, b : number, a ?: number) : void {
155
+ if (typeof r === 'undefined' || typeof g === 'undefined' || typeof b === 'undefined') {
156
+ this.filled = false;
157
+ } else {
158
+ this.cyanColor = 0;
159
+ this.magentaColor = 0;
160
+ this.yellowColor = 0;
161
+ this.blackColor = 0;
162
+ this.grayColor = 0;
163
+ this.redColor = r;
164
+ this.greenColor = g;
165
+ this.blueColor = b;
166
+ if ( typeof a === 'undefined') {
167
+ this.alpha = PdfColor.maxColourChannelValue;
168
+ } else {
169
+ this.alpha = a;
170
+ }
171
+ this.filled = true;
172
+ this.assignCMYK(r, g, b);
173
+ }
174
+ }
175
+ /**
176
+ * `Calculate and assign` cyan, megenta, yellow colors from rgb values..
177
+ * @private
178
+ */
179
+ private assignCMYK(r : number, g : number, b : number) : void {
180
+ let red : number = r / PdfColor.maxColourChannelValue;
181
+ let green : number = g / PdfColor.maxColourChannelValue;
182
+ let blue : number = b / PdfColor.maxColourChannelValue;
183
+ let black : number = PdfNumber.min(1 - red, 1 - green, 1 - blue);
184
+ let cyan : number = (black === 1.0) ? 0 : (1 - red - black) / (1 - black);
185
+ let magenta : number = (black === 1.0) ? 0 : (1 - green - black) / (1 - black);
186
+ let yellow : number = (black === 1.0) ? 0 : (1 - blue - black) / (1 - black);
187
+ this.blackColor = black;
188
+ this.cyanColor = cyan;
189
+ this.magentaColor = magenta;
190
+ this.yellowColor = yellow;
191
+ }
192
+
193
+ //Properties
194
+ // public static get Empty():PdfColor
195
+ // {
196
+ // return this.s_emptyColor
197
+ // }
198
+ /**
199
+ * Gets or sets `Red` channel value.
200
+ * @private
201
+ */
202
+ public get r() : number {
203
+ return this.redColor;
204
+ }
205
+ public set r(value : number) {
206
+ this.redColor = value;
207
+ this.assignCMYK(this.redColor, this.greenColor, this.blueColor);
208
+ this.filled = true;
209
+ }
210
+ /**
211
+ * Gets the `Red` color
212
+ * @private
213
+ */
214
+ public get red() : number {
215
+ return (this.r / PdfColor.maxColourChannelValue);
216
+ }
217
+ /**
218
+ * Gets or sets `Blue` channel value.
219
+ * @private
220
+ */
221
+ public get b() : number {
222
+ return this.blueColor;
223
+ }
224
+ public set b(value : number) {
225
+ this.blueColor = value;
226
+ this.assignCMYK(this.redColor, this.greenColor, this.blueColor);
227
+ this.filled = true;
228
+ }
229
+ /**
230
+ * Gets the `blue` color.
231
+ * @private
232
+ */
233
+ public get blue() : number {
234
+ return (this.b / PdfColor.maxColourChannelValue);
235
+ }
236
+ /**
237
+ * Gets or sets `Cyan` channel value.
238
+ * @private
239
+ */
240
+ public get c() : number {
241
+ return this.cyanColor;
242
+ }
243
+ public set c(value : number) {
244
+ if (value < 0) {
245
+ this.cyanColor = 0;
246
+ } else if (value > 1) {
247
+ this.cyanColor = 1;
248
+ } else {
249
+ this.cyanColor = value;
250
+ }
251
+ this.assignRGB(this.cyanColor, this.magentaColor, this.yellowColor, this.blackColor);
252
+ this.filled = true;
253
+ }
254
+ /**
255
+ * Gets or sets `Black` channel value.
256
+ * @private
257
+ */
258
+ public get k(): number {
259
+ return this.blackColor;
260
+ }
261
+ public set k(value: number) {
262
+ if ((value < 0)) {
263
+ this.blackColor = 0;
264
+ } else if ((value > 1)) {
265
+ this.blackColor = 1;
266
+ } else {
267
+ this.blackColor = value;
268
+ }
269
+ this.assignRGB(this.cyanColor, this.magentaColor, this.yellowColor, this.blackColor);
270
+ this.filled = true;
271
+ }
272
+ /**
273
+ * Gets or sets `Magenta` channel value.
274
+ * @private
275
+ */
276
+ public get m(): number {
277
+ return this.magentaColor;
278
+ }
279
+ public set m(value: number) {
280
+ if ((value < 0)) {
281
+ this.magentaColor = 0;
282
+ } else if ((value > 1)) {
283
+ this.magentaColor = 1;
284
+ } else {
285
+ this.magentaColor = value;
286
+ }
287
+ this.assignRGB(this.cyanColor, this.magentaColor, this.yellowColor, this.blackColor);
288
+ this.filled = true;
289
+ }
290
+ /**
291
+ * Gets or sets `Yellow` channel value.
292
+ * @private
293
+ */
294
+ public get y(): number {
295
+ return this.yellowColor;
296
+ }
297
+ public set y(value: number) {
298
+ if ((value < 0)) {
299
+ this.yellowColor = 0;
300
+ } else if ((value > 1)) {
301
+ this.yellowColor = 1;
302
+ } else {
303
+ this.yellowColor = value;
304
+ }
305
+ this.assignRGB(this.cyanColor, this.magentaColor, this.yellowColor, this.blackColor);
306
+ this.filled = true;
307
+ }
308
+ /**
309
+ * Gets or sets `Green` channel value.
310
+ * @private
311
+ */
312
+ public get g() : number {
313
+ return this.greenColor;
314
+ }
315
+ public set g(value : number) {
316
+ this.greenColor = value;
317
+ this.assignCMYK(this.redColor, this.greenColor, this.blueColor);
318
+ this.filled = true;
319
+ }
320
+ /**
321
+ * Gets the `Green` color.
322
+ * @private
323
+ */
324
+ public get green() : number {
325
+ return (this.g / PdfColor.maxColourChannelValue);
326
+ }
327
+ /**
328
+ * Gets or sets `Gray` channel value.
329
+ * @private
330
+ */
331
+ public get gray() : number
332
+ {
333
+ return ((((this.redColor + this.greenColor) + this.blueColor)) / (PdfColor.maxColourChannelValue * 3));
334
+ }
335
+ public set gray(value : number) {
336
+ if (value < 0) {
337
+ this.grayColor = 0;
338
+ } else if (value > 1) {
339
+ this.grayColor = 1;
340
+ } else {
341
+ this.grayColor = value;
342
+ }
343
+ this.r = (this.grayColor * PdfColor.maxColourChannelValue);
344
+ this.g = (this.grayColor * PdfColor.maxColourChannelValue);
345
+ this.b = (this.grayColor * PdfColor.maxColourChannelValue);
346
+ this.assignCMYK(this.redColor, this.greenColor, this.blueColor);
347
+ this.filled = true;
348
+ }
349
+ /**
350
+ * Gets whether the PDFColor `is Empty` or not.
351
+ * @private
352
+ */
353
+ public get isEmpty() : boolean
354
+ {
355
+ return !this.filled;
356
+ }
357
+ /**
358
+ * Gets or sets `Alpha` channel value.
359
+ * @private
360
+ */
361
+ public get a() : number
362
+ {
363
+ return this.alpha;
364
+ }
365
+ public set a(value : number) {
366
+ if (value < 0) {
367
+ this.alpha = 0;
368
+ } else {
369
+ // if (this.alpha !== value) {
370
+ this.alpha = value;
371
+ // }
372
+ }
373
+ this.filled = true;
374
+ }
375
+ //Public methods
376
+ /**
377
+ * Converts `PDFColor to PDF string` representation.
378
+ * @private
379
+ */
380
+ public toString(colorSpace : PdfColorSpace, stroke : boolean) : string {
381
+ if (this.isEmpty) {
382
+ return '';
383
+ }
384
+ let str : string = '';
385
+ switch (colorSpace) {
386
+ case PdfColorSpace.Rgb:
387
+ str = this.rgbToString(stroke);
388
+ break;
389
+ case PdfColorSpace.GrayScale:
390
+ str = this.grayScaleToString(stroke);
391
+ break;
392
+ case PdfColorSpace.Cmyk:
393
+ str = this.cmykToString(stroke);
394
+ break;
395
+ }
396
+ return str;
397
+ }
398
+ /**
399
+ * Sets `GrayScale` color.
400
+ * @private
401
+ */
402
+ private grayScaleToString(ifStroking : boolean) : string {
403
+ let gray : number = this.gray;
404
+ let colour : string = '';
405
+ let obj : Object = null;
406
+ /* tslint:disable-next-line:max-line-length */
407
+ obj = (ifStroking) ? PdfColor.grayStringsSroke.containsKey(gray) ? PdfColor.grayStringsSroke.getValue(gray) : null : PdfColor.grayStringsFill.containsKey(gray) ? PdfColor.grayStringsFill.getValue(gray) : null;
408
+ if (obj == null) {
409
+ if (ifStroking) {
410
+ colour = gray.toString() + ' G';
411
+ PdfColor.grayStringsSroke.setValue(gray, colour);
412
+ }
413
+ } else {
414
+ colour = obj.toString();
415
+ }
416
+ return colour + Operators.newLine;
417
+ }
418
+ /**
419
+ * Sets `RGB` color.
420
+ * @private
421
+ */
422
+ private rgbToString(ifStroking : boolean) : string {
423
+ let r : number = this.r;
424
+ let g : number = this.g;
425
+ let b : number = this.b;
426
+ let key : number = (r << 16) + (g << 8) + b;
427
+ if (ifStroking) {
428
+ key += 1 << 24;
429
+ }
430
+ let colour : string = '';
431
+ let obj : Object = null;
432
+ if (PdfColor.rgbStrings.containsKey(key)) {
433
+ obj = PdfColor.rgbStrings.getValue(key);
434
+ }
435
+ if (obj == null) {
436
+ let red : number = r / PdfColor.maxColourChannelValue;
437
+ let green : number = g / PdfColor.maxColourChannelValue;
438
+ let blue : number = b / PdfColor.maxColourChannelValue;
439
+ if (ifStroking) {
440
+ colour = red.toString() + ' ' + green.toString() + ' ' + blue.toString() + ' RG';
441
+ } else {
442
+ colour = red.toString() + ' ' + green.toString() + ' ' + blue.toString() + ' rg';
443
+ }
444
+ PdfColor.rgbStrings.setValue(key, colour);
445
+ } else {
446
+ colour = obj.toString();
447
+ }
448
+ return colour + Operators.newLine;
449
+ }
450
+ /***
451
+ * Sets `CMYK` color.
452
+ * @private
453
+ */
454
+ private cmykToString(ifStroking : boolean) : string {
455
+ let cyan : number = this.c;
456
+ let magenta : number = this.m;
457
+ let yellow : number = this.y;
458
+ let black : number = this.b;
459
+ let colour : string = '';
460
+ colour = cyan.toString() + ' ' + magenta.toString() + ' ' + yellow.toString() + ' ' + black.toString() + ' K';
461
+ return colour + Operators.newLine;
462
+ }
463
+ /**
464
+ * Converts `colour to a PDF array`.
465
+ * @private
466
+ */
467
+ public toArray(colorSpace : PdfColorSpace) : PdfArray {
468
+ let array : PdfArray = new PdfArray();
469
+ switch (colorSpace) {
470
+ case PdfColorSpace.Rgb:
471
+ array.add(new PdfNumber(this.red));
472
+ array.add(new PdfNumber(this.green));
473
+ array.add(new PdfNumber(this.blue));
474
+ break;
475
+ }
476
+ return array;
477
+ }
478
+ }