@syncfusion/ej2-pdf-export 19.4.52 → 20.2.36

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 (154) hide show
  1. package/dist/ej2-pdf-export.umd.min.js +1 -1
  2. package/dist/global/ej2-pdf-export.min.js +1 -1
  3. package/dist/global/index.d.ts +1 -1
  4. package/dist/ts/implementation/actions/action.ts +76 -0
  5. package/dist/ts/implementation/actions/uri-action.ts +52 -0
  6. package/dist/ts/implementation/annotations/action-link-annotation.ts +43 -0
  7. package/dist/ts/implementation/annotations/annotation-collection.ts +159 -0
  8. package/dist/ts/implementation/annotations/annotation.ts +241 -0
  9. package/dist/ts/implementation/annotations/document-link-annotation.ts +118 -0
  10. package/dist/ts/implementation/annotations/link-annotation.ts +32 -0
  11. package/dist/ts/implementation/annotations/pdf-text-web-link.ts +265 -0
  12. package/dist/ts/implementation/annotations/uri-annotation.ts +86 -0
  13. package/dist/ts/implementation/collections/dictionary.ts +150 -0
  14. package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +125 -0
  15. package/dist/ts/implementation/collections/utils.ts +38 -0
  16. package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +39 -0
  17. package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +108 -0
  18. package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +127 -0
  19. package/dist/ts/implementation/document/automatic-fields/composite-field.ts +76 -0
  20. package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +37 -0
  21. package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +75 -0
  22. package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +157 -0
  23. package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +82 -0
  24. package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +60 -0
  25. package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +48 -0
  26. package/dist/ts/implementation/document/pdf-catalog.ts +52 -0
  27. package/dist/ts/implementation/document/pdf-document-base.ts +166 -0
  28. package/dist/ts/implementation/document/pdf-document-template.ts +310 -0
  29. package/dist/ts/implementation/document/pdf-document.ts +342 -0
  30. package/dist/ts/implementation/drawing/pdf-drawing.ts +218 -0
  31. package/dist/ts/implementation/general/enum.ts +21 -0
  32. package/dist/ts/implementation/general/functions/pdf-function.ts +66 -0
  33. package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +62 -0
  34. package/dist/ts/implementation/general/pdf-cache-collection.ts +97 -0
  35. package/dist/ts/implementation/general/pdf-collection.ts +41 -0
  36. package/dist/ts/implementation/general/pdf-destination.ts +170 -0
  37. package/dist/ts/implementation/graphics/brushes/enum.ts +237 -0
  38. package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +294 -0
  39. package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +68 -0
  40. package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +2438 -0
  41. package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +295 -0
  42. package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +311 -0
  43. package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +406 -0
  44. package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +290 -0
  45. package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +107 -0
  46. package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +304 -0
  47. package/dist/ts/implementation/graphics/constants.ts +31 -0
  48. package/dist/ts/implementation/graphics/enum.ts +413 -0
  49. package/dist/ts/implementation/graphics/figures/arc.ts +133 -0
  50. package/dist/ts/implementation/graphics/figures/base/draw-element.ts +59 -0
  51. package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +260 -0
  52. package/dist/ts/implementation/graphics/figures/base/fill-element.ts +72 -0
  53. package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +34 -0
  54. package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +69 -0
  55. package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +276 -0
  56. package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +205 -0
  57. package/dist/ts/implementation/graphics/figures/ellipse-part.ts +76 -0
  58. package/dist/ts/implementation/graphics/figures/enum.ts +80 -0
  59. package/dist/ts/implementation/graphics/figures/layout-element.ts +132 -0
  60. package/dist/ts/implementation/graphics/figures/path.ts +646 -0
  61. package/dist/ts/implementation/graphics/figures/pdf-template.ts +205 -0
  62. package/dist/ts/implementation/graphics/figures/rectangle-area.ts +108 -0
  63. package/dist/ts/implementation/graphics/figures/text-element.ts +445 -0
  64. package/dist/ts/implementation/graphics/fonts/enum.ts +385 -0
  65. package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +248 -0
  66. package/dist/ts/implementation/graphics/fonts/pdf-font.ts +316 -0
  67. package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +606 -0
  68. package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +243 -0
  69. package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +474 -0
  70. package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +165 -0
  71. package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +958 -0
  72. package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +374 -0
  73. package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +255 -0
  74. package/dist/ts/implementation/graphics/fonts/string-layouter.ts +617 -0
  75. package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +275 -0
  76. package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +206 -0
  77. package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +18 -0
  78. package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +18 -0
  79. package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +14 -0
  80. package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +26 -0
  81. package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +35 -0
  82. package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +94 -0
  83. package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +56 -0
  84. package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +10 -0
  85. package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +14 -0
  86. package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +106 -0
  87. package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +58 -0
  88. package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +33 -0
  89. package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +22 -0
  90. package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +42 -0
  91. package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +1254 -0
  92. package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +26 -0
  93. package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +26 -0
  94. package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +577 -0
  95. package/dist/ts/implementation/graphics/images/byte-array.ts +137 -0
  96. package/dist/ts/implementation/graphics/images/image-decoder.ts +437 -0
  97. package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +110 -0
  98. package/dist/ts/implementation/graphics/images/pdf-image.ts +132 -0
  99. package/dist/ts/implementation/graphics/pdf-color.ts +478 -0
  100. package/dist/ts/implementation/graphics/pdf-graphics.ts +2424 -0
  101. package/dist/ts/implementation/graphics/pdf-margins.ts +124 -0
  102. package/dist/ts/implementation/graphics/pdf-pen.ts +370 -0
  103. package/dist/ts/implementation/graphics/pdf-resources.ts +300 -0
  104. package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +246 -0
  105. package/dist/ts/implementation/graphics/pdf-transparency.ts +93 -0
  106. package/dist/ts/implementation/graphics/unit-convertor.ts +96 -0
  107. package/dist/ts/implementation/input-output/big-endian-writer.ts +121 -0
  108. package/dist/ts/implementation/input-output/cross-table.ts +21 -0
  109. package/dist/ts/implementation/input-output/enum.ts +16 -0
  110. package/dist/ts/implementation/input-output/pdf-cross-table.ts +524 -0
  111. package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +515 -0
  112. package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +194 -0
  113. package/dist/ts/implementation/input-output/pdf-operators.ts +363 -0
  114. package/dist/ts/implementation/input-output/pdf-stream-writer.ts +681 -0
  115. package/dist/ts/implementation/input-output/pdf-writer.ts +88 -0
  116. package/dist/ts/implementation/pages/enum.ts +201 -0
  117. package/dist/ts/implementation/pages/page-added-event-arguments.ts +39 -0
  118. package/dist/ts/implementation/pages/pdf-document-page-collection.ts +180 -0
  119. package/dist/ts/implementation/pages/pdf-page-base.ts +181 -0
  120. package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +348 -0
  121. package/dist/ts/implementation/pages/pdf-page-layer.ts +271 -0
  122. package/dist/ts/implementation/pages/pdf-page-settings.ts +192 -0
  123. package/dist/ts/implementation/pages/pdf-page-size.ts +162 -0
  124. package/dist/ts/implementation/pages/pdf-page-template-element.ts +659 -0
  125. package/dist/ts/implementation/pages/pdf-page.ts +235 -0
  126. package/dist/ts/implementation/pages/pdf-section-collection.ts +187 -0
  127. package/dist/ts/implementation/pages/pdf-section-page-collection.ts +61 -0
  128. package/dist/ts/implementation/pages/pdf-section-templates.ts +96 -0
  129. package/dist/ts/implementation/pages/pdf-section.ts +644 -0
  130. package/dist/ts/implementation/primitives/pdf-array.ts +386 -0
  131. package/dist/ts/implementation/primitives/pdf-boolean.ts +119 -0
  132. package/dist/ts/implementation/primitives/pdf-dictionary.ts +513 -0
  133. package/dist/ts/implementation/primitives/pdf-name.ts +218 -0
  134. package/dist/ts/implementation/primitives/pdf-number.ts +165 -0
  135. package/dist/ts/implementation/primitives/pdf-reference.ts +430 -0
  136. package/dist/ts/implementation/primitives/pdf-stream.ts +336 -0
  137. package/dist/ts/implementation/primitives/pdf-string.ts +397 -0
  138. package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +2027 -0
  139. package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +1189 -0
  140. package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +206 -0
  141. package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +470 -0
  142. package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +853 -0
  143. package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +240 -0
  144. package/dist/ts/implementation/structured-elements/grid/styles/style.ts +424 -0
  145. package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +16 -0
  146. package/dist/ts/interfaces/i-pdf-cache.ts +23 -0
  147. package/dist/ts/interfaces/i-pdf-changable.ts +17 -0
  148. package/dist/ts/interfaces/i-pdf-clonable.ts +12 -0
  149. package/dist/ts/interfaces/i-pdf-primitives.ts +45 -0
  150. package/dist/ts/interfaces/i-pdf-true-type-font.ts +48 -0
  151. package/dist/ts/interfaces/i-pdf-wrapper.ts +13 -0
  152. package/dist/ts/interfaces/i-pdf-writer.ts +29 -0
  153. package/package.json +6 -6
  154. package/CHANGELOG.md +0 -81
@@ -0,0 +1,26 @@
1
+ /**
2
+ * TtfTableInfo.ts class for EJ2-PDF
3
+ */
4
+ export class TtfTableInfo {
5
+ /**
6
+ * offset from beginning of true type font file.
7
+ */
8
+ public offset : number;
9
+ /**
10
+ * length of the table.
11
+ */
12
+ public length : number;
13
+ /**
14
+ * table checksum;
15
+ */
16
+ public checksum : number;
17
+ //Properties
18
+ /**
19
+ * Gets a value indicating whether this table is empty.
20
+ * @private
21
+ */
22
+ public get empty() : boolean {
23
+ let empty : boolean = (this.offset === this.length && this.length === this.checksum && this.checksum === 0);
24
+ return empty;
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * TtfTrimmedCmapSubTable.ts class for EJ2-PDF
3
+ */
4
+ export class TtfTrimmedCmapSubTable {
5
+ //Fields
6
+ /**
7
+ * Structure field.
8
+ */
9
+ public format : number;
10
+ /**
11
+ * Structure field.
12
+ */
13
+ public length : number;
14
+ /**
15
+ * Structure field.
16
+ */
17
+ public version : number;
18
+ /**
19
+ * Structure field.
20
+ */
21
+ public firstCode : number;
22
+ /**
23
+ * Structure field.
24
+ */
25
+ public entryCount : number;
26
+ }
@@ -0,0 +1,577 @@
1
+ /**
2
+ * TrueTypeFont.ts class for EJ2-PDF
3
+ */
4
+ import { ByteArray } from './../../graphics/images/index';
5
+ import { TtfReader } from './ttf-reader';
6
+ import { TtfMetrics } from './ttf-metrics';
7
+ import { PdfDictionary, SaveDescendantFontEventHandler, SaveFontDictionaryEventHandler } from './../../primitives/pdf-dictionary';
8
+ import { SaveFontProgramEventHandler, SaveCmapEventHandler } from './../../primitives/pdf-stream';
9
+ import { PdfStream } from './../../primitives/pdf-stream';
10
+ import { PdfArray } from './../../primitives/pdf-array';
11
+ import { PdfName } from './../../primitives/pdf-name';
12
+ import { PdfNumber } from './../../primitives/pdf-number';
13
+ import { PdfString } from './../../primitives/pdf-string';
14
+ import { PdfReferenceHolder } from './../../primitives/pdf-reference';
15
+ import { PdfFontMetrics } from './pdf-font-metrics';
16
+ import { IPdfPrimitive } from './../../../interfaces/i-pdf-primitives';
17
+ import { StandardWidthTable } from './pdf-font-metrics';
18
+ import { DictionaryProperties } from './../../input-output/pdf-dictionary-properties';
19
+ import { Dictionary } from './../../collections/dictionary';
20
+ import { FontDescriptorFlags } from './enum';
21
+ import { RectangleF, Rectangle } from './../../drawing/pdf-drawing';
22
+ import { TtfGlyphInfo } from './ttf-glyph-info';
23
+ import { Operators } from './../../input-output/pdf-operators';
24
+ export class UnicodeTrueTypeFont {
25
+ // Fields
26
+ private readonly nameString : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
27
+ /**
28
+ * Name of the font subset.
29
+ */
30
+ private subsetName : string;
31
+ /**
32
+ * `Size` of the true type font.
33
+ * @private
34
+ */
35
+ private fontSize : number;
36
+ /**
37
+ * `Base64 string` of the true type font.
38
+ * @private
39
+ */
40
+ private fontString : string;
41
+ /**
42
+ * `font data` of the true type font.
43
+ * @private
44
+ */
45
+ private fontData : Uint8Array;
46
+ /**
47
+ * `true type font` reader object.
48
+ * @private
49
+ */
50
+ public ttfReader : TtfReader;
51
+ /**
52
+ * metrics of true type font.
53
+ * @private
54
+ */
55
+ public ttfMetrics : TtfMetrics;
56
+ /**
57
+ * Indicates whether the font is embedded or not.
58
+ * @private
59
+ */
60
+ public isEmbed : boolean;
61
+ /**
62
+ * Pdf primitive describing the font.
63
+ */
64
+ private fontDictionary : PdfDictionary;
65
+ /**
66
+ * Descendant font.
67
+ */
68
+ private descendantFont : PdfDictionary;
69
+ /**
70
+ * font descripter.
71
+ */
72
+ private fontDescriptor : PdfDictionary;
73
+ /**
74
+ * Font program.
75
+ */
76
+ private fontProgram : PdfStream;
77
+ /**
78
+ * Cmap stream.
79
+ */
80
+ private cmap : PdfStream;
81
+ /**
82
+ * C i d stream.
83
+ */
84
+ private cidStream : PdfStream;
85
+ /**
86
+ * Font metrics.
87
+ */
88
+ public metrics : PdfFontMetrics;
89
+ /**
90
+ * Specifies the Internal variable to store fields of `PdfDictionaryProperties`.
91
+ * @private
92
+ */
93
+ private dictionaryProperties : DictionaryProperties = new DictionaryProperties();
94
+ /**
95
+ * Array of used chars.
96
+ * @private
97
+ */
98
+ private usedChars : Dictionary<string, string>;
99
+ /**
100
+ * Indicates whether the font program is compressed or not.
101
+ * @private
102
+ */
103
+ private isCompress : boolean = false;
104
+ /**
105
+ * Indicates whether the font is embedded or not.
106
+ */
107
+ private isEmbedFont : boolean = false;
108
+ /**
109
+ * Cmap table's start prefix.
110
+ */
111
+ /* tslint:disable */
112
+ private readonly cmapPrefix : string = '/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap' + Operators.newLine + '/CIDSystemInfo << /Registry (Adobe)/Ordering (UCS)/Supplement 0>> def\n/CMapName ' + '/Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange' + Operators.newLine;
113
+ /* tslint:enable */
114
+ /**
115
+ * Cmap table's start suffix.
116
+ */
117
+ private readonly cmapEndCodespaceRange : string = 'endcodespacerange' + Operators.newLine;
118
+ /**
119
+ * Cmap's begin range marker.
120
+ */
121
+ private readonly cmapBeginRange : string = 'beginbfrange' + Operators.newLine;
122
+ /**
123
+ * Cmap's end range marker.
124
+ */
125
+ private readonly cmapEndRange : string = 'endbfrange' + Operators.newLine;
126
+ /**
127
+ * Cmap table's end
128
+ */
129
+ /* tslint:disable */
130
+ private readonly cmapSuffix : string = 'endbfrange\nendcmap\nCMapName currentdict ' + '/CMap defineresource pop\nend end' + Operators.newLine;
131
+ /* tslint:enable */
132
+ //Constructors
133
+ /**
134
+ * Initializes a new instance of the `PdfTrueTypeFont` class.
135
+ * @private
136
+ */
137
+ public constructor(base64String : string, size : number) {
138
+ if (base64String === null || base64String === undefined) {
139
+ throw new Error('ArgumentNullException:base64String');
140
+ }
141
+ this.fontSize = size;
142
+ this.fontString = base64String;
143
+ this.Initialize();
144
+ }
145
+ //Implementation
146
+ /**
147
+ * Returns width of the char symbol.
148
+ */
149
+ public getCharWidth(charCode : string) : number {
150
+ let codeWidth : number = this.ttfReader.getCharWidth(charCode);
151
+ return codeWidth;
152
+ }
153
+ /**
154
+ * Returns width of the text line.
155
+ */
156
+ public getLineWidth( line : string) : number {
157
+ // if (line == null) {
158
+ // throw new Error('ArgumentNullException : line');
159
+ // }
160
+ let width : number = 0;
161
+ for (let i : number = 0, len : number = line.length; i < len; i++) {
162
+ let ch : string = line[i];
163
+ let charWidth : number = this.getCharWidth(ch);
164
+ width += charWidth;
165
+ }
166
+ return width;
167
+ }
168
+ /**
169
+ * Initializes a new instance of the `PdfTrueTypeFont` class.
170
+ * @private
171
+ */
172
+ private Initialize() : void {
173
+ let byteArray : ByteArray = new ByteArray(this.fontString.length);
174
+ byteArray.writeFromBase64String(this.fontString);
175
+ this.fontData = byteArray.internalBuffer;
176
+ this.ttfReader = new TtfReader(this.fontData);
177
+ this.ttfMetrics = this.ttfReader.metrics;
178
+ }
179
+ public createInternals() : void {
180
+ this.fontDictionary = new PdfDictionary();
181
+ this.fontProgram = new PdfStream();
182
+ this.cmap = new PdfStream();
183
+ this.descendantFont = new PdfDictionary();
184
+ this.metrics = new PdfFontMetrics();
185
+ this.ttfReader.createInternals();
186
+ this.ttfMetrics = this.ttfReader.metrics;
187
+ this.initializeMetrics();
188
+ // Create all the dictionaries of the font.
189
+ this.subsetName = this.getFontName();
190
+ this.createDescendantFont();
191
+ this.createCmap();
192
+ this.createFontDictionary();
193
+ this.createFontProgram();
194
+ }
195
+ public getInternals() : IPdfPrimitive {
196
+ return this.fontDictionary;
197
+ }
198
+ /**
199
+ * Initializes metrics.
200
+ */
201
+ private initializeMetrics() : void {
202
+ let ttfMetrics : TtfMetrics = this.ttfReader.metrics;
203
+ this.metrics.ascent = ttfMetrics.macAscent;
204
+ this.metrics.descent = ttfMetrics.macDescent;
205
+ this.metrics.height = ttfMetrics.macAscent - ttfMetrics.macDescent + ttfMetrics.lineGap;
206
+ this.metrics.name = ttfMetrics.fontFamily;
207
+ this.metrics.postScriptName = ttfMetrics.postScriptName;
208
+ this.metrics.size = this.fontSize;
209
+ this.metrics.widthTable = new StandardWidthTable(ttfMetrics.widthTable);
210
+ this.metrics.lineGap = ttfMetrics.lineGap;
211
+ this.metrics.subScriptSizeFactor = ttfMetrics.subScriptSizeFactor;
212
+ this.metrics.superscriptSizeFactor = ttfMetrics.superscriptSizeFactor;
213
+ this.metrics.isBold = ttfMetrics.isBold;
214
+ }
215
+ /**
216
+ * Gets random string.
217
+ */
218
+ private getFontName() : string {
219
+ let builder : string = '';
220
+ let name : string;
221
+ // if (this.isEmbed === false) {
222
+ for (let i : number = 0; i < 6; i++) {
223
+ let index : number = Math.floor(Math.random() * (25 - 0 + 1)) + 0;
224
+ builder += this.nameString[index];
225
+ }
226
+ builder += '+';
227
+ // }
228
+ builder += this.ttfReader.metrics.postScriptName;
229
+ name = builder.toString();
230
+ // if (name === '') {
231
+ // name = this.ttfReader.metrics.fontFamily;
232
+ // }
233
+ name = this.formatName(name);
234
+ return name;
235
+ }
236
+ /**
237
+ * Generates name of the font.
238
+ */
239
+ private formatName(fontName : string) : string {
240
+ // if (fontName === null) {
241
+ // throw new Error('ArgumentNullException : fontName');
242
+ // }
243
+ // if (fontName === '') {
244
+ // throw new Error('ArgumentOutOfRangeException : fontName, Parameter can not be empty');
245
+ // }
246
+ let ret : string = fontName.replace('(', '#28');
247
+ ret = ret.replace(')', '#29');
248
+ ret = ret.replace('[', '#5B');
249
+ ret = ret.replace(']', '#5D');
250
+ ret = ret.replace('<', '#3C');
251
+ ret = ret.replace('>', '#3E');
252
+ ret = ret.replace('{', '#7B');
253
+ ret = ret.replace('}', '#7D');
254
+ ret = ret.replace('/', '#2F');
255
+ ret = ret.replace('%', '#25');
256
+ return ret.replace(' ', '#20');
257
+ }
258
+ /**
259
+ * Creates descendant font.
260
+ */
261
+ private createDescendantFont() : void {
262
+ // Set property used to clone Font every time
263
+ this.descendantFont.isFont = true;
264
+ this.descendantFont.descendantFontBeginSave = new SaveDescendantFontEventHandler(this);
265
+ this.descendantFont.items.setValue(this.dictionaryProperties.type, new PdfName(this.dictionaryProperties.font));
266
+ this.descendantFont.items.setValue(this.dictionaryProperties.subtype, new PdfName(this.dictionaryProperties.cIDFontType2));
267
+ this.descendantFont.items.setValue(this.dictionaryProperties.baseFont, new PdfName(this.subsetName));
268
+ this.descendantFont.items.setValue(this.dictionaryProperties.cIDToGIDMap, new PdfName(this.dictionaryProperties.identity));
269
+ this.descendantFont.items.setValue(this.dictionaryProperties.dw, new PdfNumber(1000));
270
+ this.fontDescriptor = this.createFontDescriptor();
271
+ this.descendantFont.items.setValue(this.dictionaryProperties.fontDescriptor, new PdfReferenceHolder(this.fontDescriptor));
272
+ let systemInfo : IPdfPrimitive = this.createSystemInfo();
273
+ this.descendantFont.items.setValue(this.dictionaryProperties.cIDSystemInfo, systemInfo);
274
+ }
275
+ /**
276
+ * Creates font descriptor.
277
+ */
278
+ private createFontDescriptor() : PdfDictionary {
279
+ let descriptor : PdfDictionary = new PdfDictionary();
280
+ let metrics : TtfMetrics = this.ttfReader.metrics;
281
+ // Set property used to clone Font every time
282
+ descriptor.isFont = true;
283
+ descriptor.items.setValue(this.dictionaryProperties.type, new PdfName(this.dictionaryProperties.fontDescriptor));
284
+ descriptor.items.setValue(this.dictionaryProperties.fontName, new PdfName(this.subsetName));
285
+ descriptor.items.setValue(this.dictionaryProperties.flags, new PdfNumber(this.getDescriptorFlags()));
286
+ descriptor.items.setValue(this.dictionaryProperties.fontBBox, PdfArray.fromRectangle(this.getBoundBox()));
287
+ descriptor.items.setValue(this.dictionaryProperties.missingWidth, new PdfNumber(metrics.widthTable[32]));
288
+ descriptor.items.setValue(this.dictionaryProperties.stemV, new PdfNumber(metrics.stemV));
289
+ descriptor.items.setValue(this.dictionaryProperties.italicAngle, new PdfNumber(metrics.italicAngle));
290
+ descriptor.items.setValue(this.dictionaryProperties.capHeight, new PdfNumber(metrics.capHeight));
291
+ descriptor.items.setValue(this.dictionaryProperties.ascent, new PdfNumber(metrics.winAscent));
292
+ descriptor.items.setValue(this.dictionaryProperties.descent, new PdfNumber(metrics.winDescent));
293
+ descriptor.items.setValue(this.dictionaryProperties.leading, new PdfNumber(metrics.leading));
294
+ descriptor.items.setValue(this.dictionaryProperties.avgWidth, new PdfNumber(metrics.widthTable[32]));
295
+ descriptor.items.setValue(this.dictionaryProperties.fontFile2, new PdfReferenceHolder(this.fontProgram));
296
+ descriptor.items.setValue(this.dictionaryProperties.maxWidth, new PdfNumber(metrics.widthTable[32]));
297
+ descriptor.items.setValue(this.dictionaryProperties.xHeight, new PdfNumber(0));
298
+ descriptor.items.setValue(this.dictionaryProperties.stemH, new PdfNumber(0));
299
+ return descriptor;
300
+ }
301
+ /**
302
+ * Generates cmap.
303
+ * @private
304
+ */
305
+ private createCmap() : void {
306
+ this.cmap.cmapBeginSave = new SaveCmapEventHandler(this);
307
+ }
308
+ /**
309
+ * Generates font dictionary.
310
+ */
311
+ private createFontDictionary() : void {
312
+ // Set property used to clone Font every time
313
+ this.fontDictionary.isFont = true;
314
+ this.fontDictionary.fontDictionaryBeginSave = new SaveFontDictionaryEventHandler(this);
315
+ this.fontDictionary.items.setValue(this.dictionaryProperties.type, new PdfName(this.dictionaryProperties.font));
316
+ this.fontDictionary.items.setValue(this.dictionaryProperties.baseFont, new PdfName(this.subsetName));
317
+ this.fontDictionary.items.setValue(this.dictionaryProperties.subtype, new PdfName(this.dictionaryProperties.type0));
318
+ this.fontDictionary.items.setValue(this.dictionaryProperties.encoding, new PdfName(this.dictionaryProperties.identityH));
319
+ let descFonts : PdfArray = new PdfArray();
320
+ let reference : PdfReferenceHolder = new PdfReferenceHolder(this.descendantFont);
321
+ // Set property used to clone Font every time
322
+ descFonts.isFont = true;
323
+ descFonts.add(reference);
324
+ this.fontDictionary.items.setValue(this.dictionaryProperties.descendantFonts, descFonts);
325
+ }
326
+ /**
327
+ * Creates font program.
328
+ */
329
+ private createFontProgram() : void {
330
+ this.fontProgram.fontProgramBeginSave = new SaveFontProgramEventHandler(this);
331
+ }
332
+ /**
333
+ * Creates system info dictionary for CID font.
334
+ * @private
335
+ */
336
+ private createSystemInfo() : IPdfPrimitive {
337
+ let systemInfo : PdfDictionary = new PdfDictionary();
338
+ systemInfo.items.setValue(this.dictionaryProperties.registry, new PdfString('Adobe'));
339
+ systemInfo.items.setValue(this.dictionaryProperties.ordering, new PdfString(this.dictionaryProperties.identity));
340
+ systemInfo.items.setValue(this.dictionaryProperties.supplement, new PdfNumber(0));
341
+ return systemInfo;
342
+ }
343
+ /**
344
+ * Runs before font Dictionary will be saved.
345
+ */
346
+ public descendantFontBeginSave() : void {
347
+ if (this.usedChars !== null && this.usedChars !== undefined && this.usedChars.size() > 0) {
348
+ let width : PdfArray = this.getDescendantWidth();
349
+ if (width !== null) {
350
+ this.descendantFont.items.setValue(this.dictionaryProperties.w, width);
351
+ }
352
+ }
353
+ }
354
+ /**
355
+ * Runs before font Dictionary will be saved.
356
+ */
357
+ public cmapBeginSave() : void {
358
+ this.generateCmap();
359
+ }
360
+ /**
361
+ * Runs before font Dictionary will be saved.
362
+ */
363
+ /* tslint:disable */
364
+ public fontDictionaryBeginSave() : void {
365
+ if (this.usedChars !== null && this.usedChars !== undefined && this.usedChars.size() > 0 && !this.fontDictionary.containsKey(this.dictionaryProperties.toUnicode)) {
366
+ this.fontDictionary.items.setValue(this.dictionaryProperties.toUnicode, new PdfReferenceHolder(this.cmap));
367
+ }
368
+ }
369
+ /* tslint:enable */
370
+ /**
371
+ * Runs before font program stream save.
372
+ */
373
+ public fontProgramBeginSave() : void {
374
+ this.isCompress = true;
375
+ this.generateFontProgram();
376
+ }
377
+ /**
378
+ * Gets width description pad array for c i d font.
379
+ */
380
+ public getDescendantWidth() : PdfArray {
381
+ let array : PdfArray = new PdfArray();
382
+ if (this.usedChars !== null && this.usedChars !== undefined && this.usedChars.size() > 0) {
383
+ let glyphInfo : TtfGlyphInfo[] = [];
384
+ // if (!this.isEmbedFont) {
385
+ let keys : string[] = this.usedChars.keys();
386
+ for (let i : number = 0; i < keys.length; i++) {
387
+ let chLen : string = keys[i];
388
+ let glyph : TtfGlyphInfo = this.ttfReader.getGlyph(chLen);
389
+ if (glyph.empty) {
390
+ continue;
391
+ }
392
+ glyphInfo.push(glyph);
393
+ }
394
+ // } else {
395
+ // glyphInfo = this.ttfReader.getAllGlyphs();
396
+ // }
397
+ glyphInfo.sort((a : TtfGlyphInfo, b : TtfGlyphInfo) => a.index - b.index);
398
+ let firstGlyphIndex : number = 0;
399
+ let lastGlyphIndex : number = 0;
400
+ let firstGlyphIndexWasSet : boolean = false;
401
+ let widthDetails : PdfArray = new PdfArray();
402
+ // if (!this.isEmbedFont) {
403
+ for (let i : number = 0; i < glyphInfo.length; i++) {
404
+ let glyph : TtfGlyphInfo = glyphInfo[i];
405
+ if (!firstGlyphIndexWasSet) {
406
+ firstGlyphIndexWasSet = true;
407
+ firstGlyphIndex = glyph.index;
408
+ lastGlyphIndex = glyph.index - 1;
409
+ }
410
+ if ((lastGlyphIndex + 1 !== glyph.index || (i + 1 === glyphInfo.length)) && glyphInfo.length > 1) {
411
+ // Add glyph index / width.
412
+ array.add(new PdfNumber(firstGlyphIndex));
413
+ if (i !== 0) {
414
+ array.add(widthDetails);
415
+ }
416
+ firstGlyphIndex = glyph.index;
417
+ widthDetails = new PdfArray();
418
+ }
419
+ widthDetails.add(new PdfNumber(glyph.width));
420
+ if (i + 1 === glyphInfo.length) {
421
+ array.add(new PdfNumber(firstGlyphIndex));
422
+ array.add(widthDetails);
423
+ }
424
+ lastGlyphIndex = glyph.index;
425
+ }
426
+ // } else {
427
+ // for (let i : number = 0; i < glyphInfo.length; i++) {
428
+ // let glyph : TtfGlyphInfo = glyphInfo[i];
429
+ // if (!firstGlyphIndexWasSet) {
430
+ // firstGlyphIndexWasSet = true;
431
+ // lastGlyphIndex = glyph.index - 1;
432
+ // }
433
+ // firstGlyphIndex = glyph.index;
434
+ // if ((lastGlyphIndex + 1 === glyph.index || (i + 1 === glyphInfo.length)) && glyphInfo.length > 1) {
435
+ // // Add glyph index / width.
436
+ // widthDetails.add(new PdfNumber(glyph.width));
437
+ // array.add(new PdfNumber(firstGlyphIndex));
438
+ // array.add(widthDetails);
439
+ // widthDetails = new PdfArray();
440
+ // }
441
+ // lastGlyphIndex = glyph.index;
442
+ // }
443
+ // }
444
+ }
445
+ return array;
446
+ }
447
+ /**
448
+ * Creates cmap.
449
+ */
450
+ private generateCmap() : void {
451
+ if (this.usedChars !== null && this.usedChars !== undefined && this.usedChars.size() > 0) {
452
+ let glyphChars : Dictionary<number, number> = this.ttfReader.getGlyphChars(this.usedChars);
453
+ if (glyphChars.size() > 0) {
454
+ let keys : number[] = glyphChars.keys().sort();
455
+ // add first and last glyph indexes
456
+ let first : number = keys[0];
457
+ let last : number = keys[keys.length - 1];
458
+ let middlePart : string = this.toHexString(first, false) + this.toHexString(last, false) + Operators.newLine;
459
+ let builder : string = '';
460
+ builder += this.cmapPrefix;
461
+ builder += middlePart;
462
+ builder += this.cmapEndCodespaceRange;
463
+ let nextRange : number = 0;
464
+ for (let i : number = 0; i < keys.length; i++) {
465
+ if (nextRange === 0) {
466
+ if (i !== 0) {
467
+ builder += this.cmapEndRange;
468
+ }
469
+ nextRange = Math.min(100, keys.length - i);
470
+ builder += nextRange;
471
+ builder += Operators.whiteSpace;
472
+ builder += this.cmapBeginRange;
473
+ }
474
+ nextRange -= 1;
475
+ let key : number = keys[i];
476
+ /* tslint:disable */
477
+ builder += this.toHexString(key, true) + this.toHexString(key, true) + this.toHexString(glyphChars.getValue(key), true) + '\n';
478
+ /* tslint:enable */
479
+ }
480
+ builder += this.cmapSuffix;
481
+ this.cmap.clearStream();
482
+ this.cmap.isFont = true;
483
+ this.cmap.write(builder);
484
+ }
485
+ }
486
+ }
487
+ /**
488
+ * Generates font program.
489
+ */
490
+ private generateFontProgram() : void {
491
+ let fontProgram : number[] = null;
492
+ this.usedChars = (this.usedChars === null || this.usedChars === undefined) ? new Dictionary<string, string>() : this.usedChars;
493
+ this.ttfReader.setOffset(0);
494
+ fontProgram = this.ttfReader.readFontProgram(this.usedChars);
495
+ this.fontProgram.clearStream();
496
+ this.fontProgram.isFont = true;
497
+ this.fontProgram.writeBytes(fontProgram);
498
+ }
499
+ /**
500
+ * Calculates flags for the font descriptor.
501
+ * @private
502
+ */
503
+ public getDescriptorFlags() : number {
504
+ let flags : number = 0;
505
+ let metrics : TtfMetrics = this.ttfReader.metrics;
506
+ if (metrics.isFixedPitch) {
507
+ flags |= FontDescriptorFlags.FixedPitch;
508
+ }
509
+ if (metrics.isSymbol) {
510
+ flags |= FontDescriptorFlags.Symbolic;
511
+ } else {
512
+ flags |= FontDescriptorFlags.Nonsymbolic;
513
+ }
514
+ if (metrics.isItalic) {
515
+ flags |= FontDescriptorFlags.Italic;
516
+ }
517
+ if (metrics.isBold) {
518
+ flags |= FontDescriptorFlags.ForceBold;
519
+ }
520
+ return flags;
521
+ }
522
+ /**
523
+ * Calculates BoundBox of the descriptor.
524
+ * @private
525
+ */
526
+ private getBoundBox() : RectangleF {
527
+ let rect : Rectangle = this.ttfReader.metrics.fontBox;
528
+ let width : number = Math.abs(rect.right - rect.left);
529
+ let height : number = Math.abs(rect.top - rect.bottom);
530
+ let rectangle : RectangleF = new RectangleF(rect.left, rect.bottom, width, height);
531
+ return rectangle;
532
+ }
533
+ /**
534
+ * Converts integer of decimal system to hex integer.
535
+ */
536
+ private toHexString(n : number, isCaseChange : boolean) : string {
537
+ let s : string = n.toString(16);
538
+ if (isCaseChange) {
539
+ s = s.toUpperCase();
540
+ }
541
+ return '<0000'.substring(0, 5 - s.length) + s + '>';
542
+ }
543
+ /**
544
+ * Stores used symbols.
545
+ */
546
+ public setSymbols(text : string) : void {
547
+ if (text === null) {
548
+ throw new Error('Argument Null Exception : text');
549
+ }
550
+ if (this.usedChars === null || this.usedChars === undefined) {
551
+ this.usedChars = new Dictionary<string, string>();
552
+ }
553
+ for (let i : number = 0; i < text.length; i++) {
554
+ let ch : string = text[i];
555
+ this.usedChars.setValue(ch, String.fromCharCode(0));
556
+ }
557
+ // else {
558
+ // if (text === null) {
559
+ // throw new Error('Argument Null Exception : glyphs');
560
+ // }
561
+ // if (this.usedChars === null || this.usedChars === undefined) {
562
+ // this.usedChars = new Dictionary<string, string>();
563
+ // }
564
+ // for (let i : number = 0; i < text.length; i++) {
565
+ // let glyphIndex : number = text[i];
566
+ // let glyph : TtfGlyphInfo = this.ttfReader.getGlyph(glyphIndex);
567
+ // if (!glyph == null) {
568
+ // let c : string = glyph.charCode.toLocaleString();
569
+ // this.usedChars.setValue(c, String.fromCharCode(0));
570
+ // }
571
+ // }
572
+ // }
573
+ if (this.isEmbedFont === false) {
574
+ this.getDescendantWidth();
575
+ }
576
+ }
577
+ }