@syncfusion/ej2-pdf-export 30.1.37 → 30.1.38
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/.eslintrc.json +2 -0
- 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 +54 -8
- package/dist/es6/ej2-pdf-export.es2015.js.map +1 -1
- package/dist/es6/ej2-pdf-export.es5.js +54 -8
- 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/package.json +8 -44
- package/src/implementation/graphics/fonts/ttf-reader.d.ts +2 -0
- package/src/implementation/graphics/fonts/ttf-reader.js +14 -1
- package/src/implementation/graphics/fonts/unicode-true-type-font.js +25 -7
- package/src/implementation/input-output/pdf-dictionary-properties.d.ts +15 -0
- package/src/implementation/input-output/pdf-dictionary-properties.js +15 -0
- package/dist/ts/implementation/actions/action.d.ts +0 -50
- package/dist/ts/implementation/actions/action.ts +0 -76
- package/dist/ts/implementation/actions/index.d.ts +0 -6
- package/dist/ts/implementation/actions/index.ts +0 -6
- package/dist/ts/implementation/actions/uri-action.d.ts +0 -33
- package/dist/ts/implementation/actions/uri-action.ts +0 -52
- package/dist/ts/implementation/annotations/action-link-annotation.d.ts +0 -30
- package/dist/ts/implementation/annotations/action-link-annotation.ts +0 -43
- package/dist/ts/implementation/annotations/annotation-collection.d.ts +0 -77
- package/dist/ts/implementation/annotations/annotation-collection.ts +0 -159
- package/dist/ts/implementation/annotations/annotation.d.ts +0 -152
- package/dist/ts/implementation/annotations/annotation.ts +0 -241
- package/dist/ts/implementation/annotations/document-link-annotation.d.ts +0 -89
- package/dist/ts/implementation/annotations/document-link-annotation.ts +0 -118
- package/dist/ts/implementation/annotations/index.d.ts +0 -11
- package/dist/ts/implementation/annotations/index.ts +0 -11
- package/dist/ts/implementation/annotations/link-annotation.d.ts +0 -23
- package/dist/ts/implementation/annotations/link-annotation.ts +0 -32
- package/dist/ts/implementation/annotations/pdf-text-web-link.d.ts +0 -118
- package/dist/ts/implementation/annotations/pdf-text-web-link.ts +0 -268
- package/dist/ts/implementation/annotations/uri-annotation.d.ts +0 -48
- package/dist/ts/implementation/annotations/uri-annotation.ts +0 -86
- package/dist/ts/implementation/collections/dictionary.d.ts +0 -76
- package/dist/ts/implementation/collections/dictionary.ts +0 -150
- package/dist/ts/implementation/collections/index.d.ts +0 -7
- package/dist/ts/implementation/collections/index.ts +0 -7
- package/dist/ts/implementation/collections/object-object-pair/dictionary.d.ts +0 -62
- package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +0 -125
- package/dist/ts/implementation/collections/object-object-pair/index.d.ts +0 -5
- package/dist/ts/implementation/collections/object-object-pair/index.ts +0 -5
- package/dist/ts/implementation/collections/utils.d.ts +0 -27
- package/dist/ts/implementation/collections/utils.ts +0 -38
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.d.ts +0 -31
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +0 -39
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info.d.ts +0 -67
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +0 -108
- package/dist/ts/implementation/document/automatic-fields/automatic-field.d.ts +0 -41
- package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +0 -127
- package/dist/ts/implementation/document/automatic-fields/composite-field.d.ts +0 -46
- package/dist/ts/implementation/document/automatic-fields/composite-field.ts +0 -76
- package/dist/ts/implementation/document/automatic-fields/index.d.ts +0 -11
- package/dist/ts/implementation/document/automatic-fields/index.ts +0 -11
- package/dist/ts/implementation/document/automatic-fields/multiple-value-field.d.ts +0 -18
- package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +0 -37
- package/dist/ts/implementation/document/automatic-fields/page-count-field.d.ts +0 -44
- package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +0 -75
- package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.d.ts +0 -53
- package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +0 -157
- package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.d.ts +0 -51
- package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +0 -82
- package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.d.ts +0 -38
- package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +0 -60
- package/dist/ts/implementation/document/automatic-fields/single-value-field.d.ts +0 -15
- package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +0 -48
- package/dist/ts/implementation/document/index.d.ts +0 -16
- package/dist/ts/implementation/document/index.ts +0 -16
- package/dist/ts/implementation/document/pdf-catalog.d.ts +0 -39
- package/dist/ts/implementation/document/pdf-catalog.ts +0 -65
- package/dist/ts/implementation/document/pdf-document-base.d.ts +0 -137
- package/dist/ts/implementation/document/pdf-document-base.ts +0 -187
- package/dist/ts/implementation/document/pdf-document-template.d.ts +0 -166
- package/dist/ts/implementation/document/pdf-document-template.ts +0 -310
- package/dist/ts/implementation/document/pdf-document.d.ts +0 -227
- package/dist/ts/implementation/document/pdf-document.ts +0 -361
- package/dist/ts/implementation/document/pdf-viewer-preferences.d.ts +0 -467
- package/dist/ts/implementation/document/pdf-viewer-preferences.ts +0 -578
- package/dist/ts/implementation/drawing/index.d.ts +0 -5
- package/dist/ts/implementation/drawing/index.ts +0 -5
- package/dist/ts/implementation/drawing/pdf-drawing.d.ts +0 -141
- package/dist/ts/implementation/drawing/pdf-drawing.ts +0 -218
- package/dist/ts/implementation/general/enum.d.ts +0 -21
- package/dist/ts/implementation/general/enum.ts +0 -21
- package/dist/ts/implementation/general/functions/index.d.ts +0 -6
- package/dist/ts/implementation/general/functions/index.ts +0 -6
- package/dist/ts/implementation/general/functions/pdf-function.d.ts +0 -44
- package/dist/ts/implementation/general/functions/pdf-function.ts +0 -66
- package/dist/ts/implementation/general/functions/pdf-sampled-function.d.ts +0 -25
- package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +0 -63
- package/dist/ts/implementation/general/index.d.ts +0 -9
- package/dist/ts/implementation/general/index.ts +0 -9
- package/dist/ts/implementation/general/pdf-cache-collection.d.ts +0 -42
- package/dist/ts/implementation/general/pdf-cache-collection.ts +0 -97
- package/dist/ts/implementation/general/pdf-collection.d.ts +0 -26
- package/dist/ts/implementation/general/pdf-collection.ts +0 -41
- package/dist/ts/implementation/general/pdf-destination.d.ts +0 -103
- package/dist/ts/implementation/general/pdf-destination.ts +0 -170
- package/dist/ts/implementation/graphics/brushes/enum.d.ts +0 -236
- package/dist/ts/implementation/graphics/brushes/enum.ts +0 -237
- package/dist/ts/implementation/graphics/brushes/index.d.ts +0 -13
- package/dist/ts/implementation/graphics/brushes/index.ts +0 -13
- package/dist/ts/implementation/graphics/brushes/pdf-blend.d.ts +0 -105
- package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +0 -294
- package/dist/ts/implementation/graphics/brushes/pdf-brush.d.ts +0 -51
- package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +0 -63
- package/dist/ts/implementation/graphics/brushes/pdf-brushes.d.ts +0 -726
- package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +0 -2438
- package/dist/ts/implementation/graphics/brushes/pdf-color-blend.d.ts +0 -113
- package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +0 -295
- package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.d.ts +0 -155
- package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +0 -311
- package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.d.ts +0 -147
- package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +0 -406
- package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.d.ts +0 -122
- package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +0 -290
- package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.d.ts +0 -77
- package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +0 -107
- package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.d.ts +0 -161
- package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +0 -304
- package/dist/ts/implementation/graphics/constants.d.ts +0 -31
- package/dist/ts/implementation/graphics/constants.ts +0 -31
- package/dist/ts/implementation/graphics/enum.d.ts +0 -413
- package/dist/ts/implementation/graphics/enum.ts +0 -413
- package/dist/ts/implementation/graphics/figures/arc.d.ts +0 -87
- package/dist/ts/implementation/graphics/figures/arc.ts +0 -133
- package/dist/ts/implementation/graphics/figures/base/draw-element.d.ts +0 -30
- package/dist/ts/implementation/graphics/figures/base/draw-element.ts +0 -59
- package/dist/ts/implementation/graphics/figures/base/element-layouter.d.ts +0 -161
- package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +0 -260
- package/dist/ts/implementation/graphics/figures/base/fill-element.d.ts +0 -46
- package/dist/ts/implementation/graphics/figures/base/fill-element.ts +0 -72
- package/dist/ts/implementation/graphics/figures/base/graphics-element.d.ts +0 -16
- package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +0 -34
- package/dist/ts/implementation/graphics/figures/base/index.d.ts +0 -9
- package/dist/ts/implementation/graphics/figures/base/index.ts +0 -9
- package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.d.ts +0 -40
- package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +0 -69
- package/dist/ts/implementation/graphics/figures/base/shape-layouter.d.ts +0 -131
- package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +0 -276
- package/dist/ts/implementation/graphics/figures/base/text-layouter.d.ts +0 -107
- package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +0 -212
- package/dist/ts/implementation/graphics/figures/ellipse-part.d.ts +0 -48
- package/dist/ts/implementation/graphics/figures/ellipse-part.ts +0 -76
- package/dist/ts/implementation/graphics/figures/enum.d.ts +0 -79
- package/dist/ts/implementation/graphics/figures/enum.ts +0 -80
- package/dist/ts/implementation/graphics/figures/index.d.ts +0 -13
- package/dist/ts/implementation/graphics/figures/index.ts +0 -13
- package/dist/ts/implementation/graphics/figures/layout-element.d.ts +0 -73
- package/dist/ts/implementation/graphics/figures/layout-element.ts +0 -132
- package/dist/ts/implementation/graphics/figures/path.d.ts +0 -319
- package/dist/ts/implementation/graphics/figures/path.ts +0 -646
- package/dist/ts/implementation/graphics/figures/pdf-template.d.ts +0 -113
- package/dist/ts/implementation/graphics/figures/pdf-template.ts +0 -205
- package/dist/ts/implementation/graphics/figures/rectangle-area.d.ts +0 -64
- package/dist/ts/implementation/graphics/figures/rectangle-area.ts +0 -108
- package/dist/ts/implementation/graphics/figures/text-element.d.ts +0 -214
- package/dist/ts/implementation/graphics/figures/text-element.ts +0 -449
- package/dist/ts/implementation/graphics/fonts/enum.d.ts +0 -385
- package/dist/ts/implementation/graphics/fonts/enum.ts +0 -385
- package/dist/ts/implementation/graphics/fonts/index.d.ts +0 -16
- package/dist/ts/implementation/graphics/fonts/index.ts +0 -16
- package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.d.ts +0 -164
- package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +0 -248
- package/dist/ts/implementation/graphics/fonts/pdf-font.d.ts +0 -187
- package/dist/ts/implementation/graphics/fonts/pdf-font.ts +0 -316
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.d.ts +0 -301
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +0 -606
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font.d.ts +0 -143
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +0 -243
- package/dist/ts/implementation/graphics/fonts/pdf-string-format.d.ts +0 -321
- package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +0 -474
- package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.d.ts +0 -49
- package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +0 -165
- package/dist/ts/implementation/graphics/fonts/rtl/index.d.ts +0 -6
- package/dist/ts/implementation/graphics/fonts/rtl/index.ts +0 -6
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.d.ts +0 -62
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +0 -958
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.d.ts +0 -68
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +0 -374
- package/dist/ts/implementation/graphics/fonts/rtl-renderer.d.ts +0 -23
- package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +0 -255
- package/dist/ts/implementation/graphics/fonts/string-layouter.d.ts +0 -254
- package/dist/ts/implementation/graphics/fonts/string-layouter.ts +0 -617
- package/dist/ts/implementation/graphics/fonts/string-tokenizer.d.ts +0 -109
- package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +0 -275
- package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.d.ts +0 -204
- package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +0 -206
- package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.d.ts +0 -17
- package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +0 -18
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.d.ts +0 -17
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +0 -18
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.d.ts +0 -13
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +0 -14
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.d.ts +0 -25
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +0 -26
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.d.ts +0 -25
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +0 -35
- package/dist/ts/implementation/graphics/fonts/ttf-head-table.d.ts +0 -94
- package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +0 -94
- package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.d.ts +0 -55
- package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +0 -56
- package/dist/ts/implementation/graphics/fonts/ttf-loca-table.d.ts +0 -9
- package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +0 -10
- package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.d.ts +0 -13
- package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +0 -14
- package/dist/ts/implementation/graphics/fonts/ttf-metrics.d.ts +0 -101
- package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +0 -106
- package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.d.ts +0 -57
- package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +0 -58
- package/dist/ts/implementation/graphics/fonts/ttf-name-record.d.ts +0 -33
- package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +0 -33
- package/dist/ts/implementation/graphics/fonts/ttf-name-table.d.ts +0 -22
- package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +0 -22
- package/dist/ts/implementation/graphics/fonts/ttf-post-table.d.ts +0 -41
- package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +0 -42
- package/dist/ts/implementation/graphics/fonts/ttf-reader.d.ts +0 -225
- package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +0 -1254
- package/dist/ts/implementation/graphics/fonts/ttf-table-info.d.ts +0 -22
- package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +0 -26
- package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.d.ts +0 -25
- package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +0 -26
- package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.d.ts +0 -213
- package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +0 -577
- package/dist/ts/implementation/graphics/images/byte-array.d.ts +0 -74
- package/dist/ts/implementation/graphics/images/byte-array.ts +0 -137
- package/dist/ts/implementation/graphics/images/image-decoder.d.ts +0 -274
- package/dist/ts/implementation/graphics/images/image-decoder.ts +0 -439
- package/dist/ts/implementation/graphics/images/index.d.ts +0 -8
- package/dist/ts/implementation/graphics/images/index.ts +0 -8
- package/dist/ts/implementation/graphics/images/pdf-bitmap.d.ts +0 -90
- package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +0 -110
- package/dist/ts/implementation/graphics/images/pdf-image.d.ts +0 -88
- package/dist/ts/implementation/graphics/images/pdf-image.ts +0 -132
- package/dist/ts/implementation/graphics/index.d.ts +0 -35
- package/dist/ts/implementation/graphics/index.ts +0 -46
- package/dist/ts/implementation/graphics/pdf-color.d.ts +0 -206
- package/dist/ts/implementation/graphics/pdf-color.ts +0 -484
- package/dist/ts/implementation/graphics/pdf-graphics.d.ts +0 -1210
- package/dist/ts/implementation/graphics/pdf-graphics.ts +0 -2556
- package/dist/ts/implementation/graphics/pdf-margins.d.ts +0 -82
- package/dist/ts/implementation/graphics/pdf-margins.ts +0 -124
- package/dist/ts/implementation/graphics/pdf-pen.d.ts +0 -237
- package/dist/ts/implementation/graphics/pdf-pen.ts +0 -370
- package/dist/ts/implementation/graphics/pdf-resources.d.ts +0 -122
- package/dist/ts/implementation/graphics/pdf-resources.ts +0 -300
- package/dist/ts/implementation/graphics/pdf-transformation-matrix.d.ts +0 -143
- package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +0 -246
- package/dist/ts/implementation/graphics/pdf-transparency.d.ts +0 -34
- package/dist/ts/implementation/graphics/pdf-transparency.ts +0 -93
- package/dist/ts/implementation/graphics/unit-convertor.d.ts +0 -72
- package/dist/ts/implementation/graphics/unit-convertor.ts +0 -96
- package/dist/ts/implementation/index.d.ts +0 -103
- package/dist/ts/implementation/index.ts +0 -103
- package/dist/ts/implementation/input-output/big-endian-writer.d.ts +0 -59
- package/dist/ts/implementation/input-output/big-endian-writer.ts +0 -121
- package/dist/ts/implementation/input-output/cross-table.d.ts +0 -21
- package/dist/ts/implementation/input-output/cross-table.ts +0 -21
- package/dist/ts/implementation/input-output/enum.d.ts +0 -16
- package/dist/ts/implementation/input-output/enum.ts +0 -16
- package/dist/ts/implementation/input-output/index.d.ts +0 -12
- package/dist/ts/implementation/input-output/index.ts +0 -12
- package/dist/ts/implementation/input-output/pdf-cross-table.d.ts +0 -259
- package/dist/ts/implementation/input-output/pdf-cross-table.ts +0 -536
- package/dist/ts/implementation/input-output/pdf-dictionary-properties.d.ts +0 -568
- package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +0 -571
- package/dist/ts/implementation/input-output/pdf-main-object-collection.d.ts +0 -120
- package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +0 -194
- package/dist/ts/implementation/input-output/pdf-operators.d.ts +0 -361
- package/dist/ts/implementation/input-output/pdf-operators.ts +0 -363
- package/dist/ts/implementation/input-output/pdf-stream-writer.d.ts +0 -311
- package/dist/ts/implementation/input-output/pdf-stream-writer.ts +0 -681
- package/dist/ts/implementation/input-output/pdf-writer.d.ts +0 -122
- package/dist/ts/implementation/input-output/pdf-writer.ts +0 -164
- package/dist/ts/implementation/pages/enum.d.ts +0 -201
- package/dist/ts/implementation/pages/enum.ts +0 -201
- package/dist/ts/implementation/pages/index.d.ts +0 -17
- package/dist/ts/implementation/pages/index.ts +0 -17
- package/dist/ts/implementation/pages/page-added-event-arguments.d.ts +0 -30
- package/dist/ts/implementation/pages/page-added-event-arguments.ts +0 -39
- package/dist/ts/implementation/pages/pdf-document-page-collection.d.ts +0 -86
- package/dist/ts/implementation/pages/pdf-document-page-collection.ts +0 -180
- package/dist/ts/implementation/pages/pdf-page-base.d.ts +0 -121
- package/dist/ts/implementation/pages/pdf-page-base.ts +0 -181
- package/dist/ts/implementation/pages/pdf-page-layer-collection.d.ts +0 -99
- package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +0 -348
- package/dist/ts/implementation/pages/pdf-page-layer.d.ts +0 -160
- package/dist/ts/implementation/pages/pdf-page-layer.ts +0 -271
- package/dist/ts/implementation/pages/pdf-page-settings.d.ts +0 -111
- package/dist/ts/implementation/pages/pdf-page-settings.ts +0 -192
- package/dist/ts/implementation/pages/pdf-page-size.d.ts +0 -159
- package/dist/ts/implementation/pages/pdf-page-size.ts +0 -162
- package/dist/ts/implementation/pages/pdf-page-template-element.d.ts +0 -240
- package/dist/ts/implementation/pages/pdf-page-template-element.ts +0 -663
- package/dist/ts/implementation/pages/pdf-page.d.ts +0 -153
- package/dist/ts/implementation/pages/pdf-page.ts +0 -235
- package/dist/ts/implementation/pages/pdf-section-collection.d.ts +0 -109
- package/dist/ts/implementation/pages/pdf-section-collection.ts +0 -187
- package/dist/ts/implementation/pages/pdf-section-page-collection.d.ts +0 -41
- package/dist/ts/implementation/pages/pdf-section-page-collection.ts +0 -61
- package/dist/ts/implementation/pages/pdf-section-templates.d.ts +0 -64
- package/dist/ts/implementation/pages/pdf-section-templates.ts +0 -96
- package/dist/ts/implementation/pages/pdf-section.d.ts +0 -327
- package/dist/ts/implementation/pages/pdf-section.ts +0 -644
- package/dist/ts/implementation/primitives/index.d.ts +0 -12
- package/dist/ts/implementation/primitives/index.ts +0 -12
- package/dist/ts/implementation/primitives/pdf-array.d.ts +0 -192
- package/dist/ts/implementation/primitives/pdf-array.ts +0 -386
- package/dist/ts/implementation/primitives/pdf-boolean.d.ts +0 -84
- package/dist/ts/implementation/primitives/pdf-boolean.ts +0 -119
- package/dist/ts/implementation/primitives/pdf-dictionary.d.ts +0 -362
- package/dist/ts/implementation/primitives/pdf-dictionary.ts +0 -513
- package/dist/ts/implementation/primitives/pdf-name.d.ts +0 -121
- package/dist/ts/implementation/primitives/pdf-name.ts +0 -218
- package/dist/ts/implementation/primitives/pdf-number.d.ts +0 -104
- package/dist/ts/implementation/primitives/pdf-number.ts +0 -165
- package/dist/ts/implementation/primitives/pdf-reference.d.ts +0 -223
- package/dist/ts/implementation/primitives/pdf-reference.ts +0 -430
- package/dist/ts/implementation/primitives/pdf-stream.d.ts +0 -161
- package/dist/ts/implementation/primitives/pdf-stream.ts +0 -306
- package/dist/ts/implementation/primitives/pdf-string.d.ts +0 -235
- package/dist/ts/implementation/primitives/pdf-string.ts +0 -397
- package/dist/ts/implementation/structured-elements/grid/index.d.ts +0 -4
- package/dist/ts/implementation/structured-elements/grid/index.ts +0 -10
- package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.d.ts +0 -597
- package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +0 -2127
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.d.ts +0 -288
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +0 -1225
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.d.ts +0 -108
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +0 -206
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.d.ts +0 -261
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +0 -470
- package/dist/ts/implementation/structured-elements/grid/pdf-grid.d.ts +0 -292
- package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +0 -853
- package/dist/ts/implementation/structured-elements/grid/styles/index.d.ts +0 -5
- package/dist/ts/implementation/structured-elements/grid/styles/index.ts +0 -5
- package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.d.ts +0 -146
- package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +0 -238
- package/dist/ts/implementation/structured-elements/grid/styles/style.d.ts +0 -272
- package/dist/ts/implementation/structured-elements/grid/styles/style.ts +0 -423
- package/dist/ts/implementation/structured-elements/index.d.ts +0 -4
- package/dist/ts/implementation/structured-elements/index.ts +0 -10
- package/dist/ts/implementation/structured-elements/tables/light-tables/enum.d.ts +0 -16
- package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +0 -16
- package/dist/ts/index.d.ts +0 -116
- package/dist/ts/index.ts +0 -116
- package/dist/ts/interfaces/i-pdf-cache.d.ts +0 -23
- package/dist/ts/interfaces/i-pdf-cache.ts +0 -23
- package/dist/ts/interfaces/i-pdf-changable.d.ts +0 -17
- package/dist/ts/interfaces/i-pdf-changable.ts +0 -17
- package/dist/ts/interfaces/i-pdf-clonable.d.ts +0 -12
- package/dist/ts/interfaces/i-pdf-clonable.ts +0 -12
- package/dist/ts/interfaces/i-pdf-primitives.d.ts +0 -45
- package/dist/ts/interfaces/i-pdf-primitives.ts +0 -45
- package/dist/ts/interfaces/i-pdf-true-type-font.d.ts +0 -18
- package/dist/ts/interfaces/i-pdf-true-type-font.ts +0 -48
- package/dist/ts/interfaces/i-pdf-wrapper.d.ts +0 -13
- package/dist/ts/interfaces/i-pdf-wrapper.ts +0 -13
- package/dist/ts/interfaces/i-pdf-writer.d.ts +0 -29
- package/dist/ts/interfaces/i-pdf-writer.ts +0 -29
- package/dist/ts/interfaces/index.d.ts +0 -10
- package/dist/ts/interfaces/index.ts +0 -10
|
@@ -1,1254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TtfReader.ts class for EJ2-PDF
|
|
3
|
-
*/
|
|
4
|
-
import { TtfTableInfo } from './ttf-table-info';
|
|
5
|
-
import { Dictionary } from './../../collections/dictionary';
|
|
6
|
-
import { TtfNameTable } from './ttf-name-table';
|
|
7
|
-
import { TtfNameRecord } from './ttf-name-record';
|
|
8
|
-
import { TtfHeadTable } from './ttf-head-table';
|
|
9
|
-
import { TtfMetrics } from './ttf-metrics';
|
|
10
|
-
import { TtfHorizontalHeaderTable } from './ttf-horizontal-header-table';
|
|
11
|
-
import { TtfOS2Table } from './ttf-OS2-Table';
|
|
12
|
-
import { TtfPostTable } from './ttf-post-table';
|
|
13
|
-
import { TtfLongHorMetric } from './ttf-long-hor-metric';
|
|
14
|
-
import { TtfCmapSubTable } from './ttf-cmap-sub-table';
|
|
15
|
-
import { TtfCmapTable } from './ttf-cmap-table';
|
|
16
|
-
import { TtfGlyphInfo } from './ttf-glyph-info';
|
|
17
|
-
import { TtfLocaTable } from './ttf-loca-table';
|
|
18
|
-
import { TtfAppleCmapSubTable } from './ttf-apple-cmap-sub-table';
|
|
19
|
-
import { TtfMicrosoftCmapSubTable } from './ttf-microsoft-cmap-sub-table';
|
|
20
|
-
import { TtfTrimmedCmapSubTable } from './ttf-trimmed-cmap-sub-table';
|
|
21
|
-
import { TtfGlyphHeader } from './ttf-glyph-header';
|
|
22
|
-
import { Rectangle } from './../../drawing/pdf-drawing';
|
|
23
|
-
import { StringTokenizer } from './string-tokenizer';
|
|
24
|
-
import { TtfCmapFormat, TtfCmapEncoding, TtfPlatformID } from './enum';
|
|
25
|
-
import { TtfMicrosoftEncodingID, TtfMacintoshEncodingID, TtfCompositeGlyphFlags } from './enum';
|
|
26
|
-
import { BigEndianWriter } from './../../input-output/big-endian-writer';
|
|
27
|
-
export class TtfReader {
|
|
28
|
-
//Fields
|
|
29
|
-
private fontData : Uint8Array;
|
|
30
|
-
private readonly int32Size : number = 4;
|
|
31
|
-
private offset : number;
|
|
32
|
-
public tableDirectory : Dictionary<string, TtfTableInfo>;
|
|
33
|
-
private isTtcFont : boolean = false;
|
|
34
|
-
private isMacTtf : boolean = false;
|
|
35
|
-
private lowestPosition : number;
|
|
36
|
-
private metricsName : string = '';
|
|
37
|
-
public metrics : TtfMetrics;
|
|
38
|
-
private maxMacIndex : number;
|
|
39
|
-
private isFontPresent : boolean;
|
|
40
|
-
private isMacTTF : boolean = false;
|
|
41
|
-
private missedGlyphs : number = 0;
|
|
42
|
-
private tableNames : string[] = ['cvt ', 'fpgm', 'glyf', 'head', 'hhea', 'hmtx', 'loca', 'maxp', 'prep'];
|
|
43
|
-
private entrySelectors : number[] = [0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4];
|
|
44
|
-
/**
|
|
45
|
-
* Width table.
|
|
46
|
-
*/
|
|
47
|
-
private width : number[];
|
|
48
|
-
/**
|
|
49
|
-
* Indicates whether loca table is short.
|
|
50
|
-
*/
|
|
51
|
-
public bIsLocaShort : boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Glyphs for Macintosh or Symbol fonts.
|
|
54
|
-
*/
|
|
55
|
-
private macintoshDictionary : Dictionary<number, TtfGlyphInfo>;
|
|
56
|
-
/**
|
|
57
|
-
* Glyphs for Microsoft or Symbol fonts.
|
|
58
|
-
*/
|
|
59
|
-
private microsoftDictionary : Dictionary<number, TtfGlyphInfo>;
|
|
60
|
-
/**
|
|
61
|
-
* Glyphs for Macintosh or Symbol fonts (glyph index - key, glyph - value).
|
|
62
|
-
*/
|
|
63
|
-
private internalMacintoshGlyphs : Dictionary<number, TtfGlyphInfo>;
|
|
64
|
-
/**
|
|
65
|
-
* Glyphs for Microsoft or Symbol fonts (glyph index - key, glyph - value).
|
|
66
|
-
*/
|
|
67
|
-
private internalMicrosoftGlyphs : Dictionary<number, TtfGlyphInfo>;
|
|
68
|
-
//Properties
|
|
69
|
-
/**
|
|
70
|
-
* Gets glyphs for Macintosh or Symbol fonts (char - key, glyph - value).
|
|
71
|
-
*/
|
|
72
|
-
private get macintosh() : Dictionary<number, TtfGlyphInfo> {
|
|
73
|
-
if (this.macintoshDictionary === null || this.macintoshDictionary === undefined) {
|
|
74
|
-
this.macintoshDictionary = new Dictionary<number, TtfGlyphInfo>();
|
|
75
|
-
}
|
|
76
|
-
return this.macintoshDictionary;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Gets glyphs for Microsoft or Symbol fonts (char - key, glyph - value).
|
|
80
|
-
*/
|
|
81
|
-
private get microsoft() : Dictionary<number, TtfGlyphInfo> {
|
|
82
|
-
if (this.microsoftDictionary === null || this.microsoftDictionary === undefined) {
|
|
83
|
-
this.microsoftDictionary = new Dictionary<number, TtfGlyphInfo>();
|
|
84
|
-
}
|
|
85
|
-
return this.microsoftDictionary;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Gets glyphs for Macintosh or Symbol fonts (glyph index - key, glyph - value).
|
|
89
|
-
*/
|
|
90
|
-
private get macintoshGlyphs() : Dictionary<number, TtfGlyphInfo> {
|
|
91
|
-
if (this.internalMacintoshGlyphs === null || this.internalMacintoshGlyphs === undefined) {
|
|
92
|
-
this.internalMacintoshGlyphs = new Dictionary<number, TtfGlyphInfo>();
|
|
93
|
-
}
|
|
94
|
-
return this.internalMacintoshGlyphs;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets glyphs for Microsoft Unicode fonts (glyph index - key, glyph - value).
|
|
98
|
-
*/
|
|
99
|
-
private get microsoftGlyphs() : Dictionary<number, TtfGlyphInfo> {
|
|
100
|
-
if (this.internalMicrosoftGlyphs === null || this.internalMicrosoftGlyphs === undefined) {
|
|
101
|
-
this.internalMicrosoftGlyphs = new Dictionary<number, TtfGlyphInfo>();
|
|
102
|
-
}
|
|
103
|
-
return this.internalMicrosoftGlyphs;
|
|
104
|
-
}
|
|
105
|
-
//Constructors
|
|
106
|
-
public constructor(fontData : Uint8Array) {
|
|
107
|
-
this.fontData = fontData;
|
|
108
|
-
this.initialize();
|
|
109
|
-
}
|
|
110
|
-
//Implementation
|
|
111
|
-
private initialize() : void {
|
|
112
|
-
if (this.metrics === undefined) {
|
|
113
|
-
this.metrics = new TtfMetrics();
|
|
114
|
-
}
|
|
115
|
-
this.readFontDictionary();
|
|
116
|
-
let nameTable : TtfNameTable = this.readNameTable();
|
|
117
|
-
let headTable : TtfHeadTable = this.readHeadTable();
|
|
118
|
-
this.initializeFontName(nameTable);
|
|
119
|
-
this.metrics.macStyle = headTable.macStyle;
|
|
120
|
-
}
|
|
121
|
-
private readFontDictionary() : void {
|
|
122
|
-
this.offset = 0;
|
|
123
|
-
let version : number = this.checkPreambula();
|
|
124
|
-
//this.offset += 4;
|
|
125
|
-
let numTables : number = this.readInt16(this.offset);
|
|
126
|
-
let searchRange : number = this.readInt16(this.offset);
|
|
127
|
-
let entrySelector : number = this.readInt16(this.offset);
|
|
128
|
-
let rangeShift : number = this.readInt16(this.offset);
|
|
129
|
-
if (this.tableDirectory === undefined) {
|
|
130
|
-
this.tableDirectory = new Dictionary<string, TtfTableInfo>();
|
|
131
|
-
}
|
|
132
|
-
for (let i : number = 0; i < numTables; ++i) {
|
|
133
|
-
let table : TtfTableInfo = new TtfTableInfo();
|
|
134
|
-
let tableKey : string = this.readString(this.int32Size);
|
|
135
|
-
table.checksum = this.readInt32(this.offset);
|
|
136
|
-
table.offset = this.readInt32(this.offset);
|
|
137
|
-
table.length = this.readInt32(this.offset);
|
|
138
|
-
this.tableDirectory.setValue(tableKey, table);
|
|
139
|
-
}
|
|
140
|
-
this.lowestPosition = this.offset;
|
|
141
|
-
if (!this.isTtcFont) {
|
|
142
|
-
this.fixOffsets();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
private fixOffsets() : void {
|
|
146
|
-
let minOffset : number = Number.MAX_VALUE;
|
|
147
|
-
// Search for a smallest offset and compare it with the lowest position found.
|
|
148
|
-
let tableKeys : string[] = this.tableDirectory.keys();
|
|
149
|
-
for (let i : number = 0; i < tableKeys.length; i++) {
|
|
150
|
-
let value : TtfTableInfo = this.tableDirectory.getValue(tableKeys[i]);
|
|
151
|
-
let offset : number = value.offset;
|
|
152
|
-
if (minOffset > offset) {
|
|
153
|
-
minOffset = offset;
|
|
154
|
-
if (minOffset <= this.lowestPosition) {
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
let shift : number = minOffset - this.lowestPosition;
|
|
160
|
-
if (shift !== 0) {
|
|
161
|
-
let table : Dictionary<string, TtfTableInfo> = new Dictionary<string, TtfTableInfo>();
|
|
162
|
-
for (let i : number = 0; i < tableKeys.length; i++) {
|
|
163
|
-
let value : TtfTableInfo = this.tableDirectory.getValue(tableKeys[i]);
|
|
164
|
-
value.offset -= shift;
|
|
165
|
-
table.setValue(tableKeys[i], value);
|
|
166
|
-
}
|
|
167
|
-
this.tableDirectory = table;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
private checkPreambula() : number {
|
|
171
|
-
let version : number = this.readInt32(this.offset);
|
|
172
|
-
this.isMacTtf = (version === 0x74727565) ? true : false;
|
|
173
|
-
if (version !== 0x10000 && version !== 0x74727565 && version !== 0x4f54544f) {
|
|
174
|
-
this.isTtcFont = true;
|
|
175
|
-
this.offset = 0;
|
|
176
|
-
let fontTag : string = this.readString(4);
|
|
177
|
-
if (fontTag !== 'ttcf') {
|
|
178
|
-
throw new Error('Can not read TTF font data');
|
|
179
|
-
}
|
|
180
|
-
//skip 4
|
|
181
|
-
this.offset += 4;
|
|
182
|
-
let ttcIdentificationNumber : number = this.readInt32(this.offset);
|
|
183
|
-
if (ttcIdentificationNumber < 0) {
|
|
184
|
-
throw new Error('Can not read TTF font data');
|
|
185
|
-
}
|
|
186
|
-
this.offset = this.readInt32(this.offset);
|
|
187
|
-
version = this.readInt32(this.offset);
|
|
188
|
-
}
|
|
189
|
-
return version;
|
|
190
|
-
}
|
|
191
|
-
private readNameTable() : TtfNameTable {
|
|
192
|
-
let tableInfo : TtfTableInfo = this.getTable('name');
|
|
193
|
-
this.offset = tableInfo.offset;
|
|
194
|
-
let table : TtfNameTable = new TtfNameTable();
|
|
195
|
-
table.formatSelector = this.readUInt16(this.offset);
|
|
196
|
-
table.recordsCount = this.readUInt16(this.offset);
|
|
197
|
-
table.offset = this.readUInt16(this.offset);
|
|
198
|
-
table.nameRecords = [];
|
|
199
|
-
let recordSize : number = 12;
|
|
200
|
-
let position : number = this.offset;
|
|
201
|
-
for (let i : number = 0; i < table.recordsCount; i++) {
|
|
202
|
-
this.offset = position;
|
|
203
|
-
let record : TtfNameRecord = new TtfNameRecord();
|
|
204
|
-
record.platformID = this.readUInt16(this.offset);
|
|
205
|
-
record.encodingID = this.readUInt16(this.offset);
|
|
206
|
-
record.languageID = this.readUInt16(this.offset);
|
|
207
|
-
record.nameID = this.readUInt16(this.offset);
|
|
208
|
-
record.length = this.readUInt16(this.offset);
|
|
209
|
-
record.offset = this.readUInt16(this.offset);
|
|
210
|
-
this.offset = tableInfo.offset + table.offset + record.offset;
|
|
211
|
-
let unicode : boolean = (record.platformID === 0 || record.platformID === 3);
|
|
212
|
-
record.name = this.readString(record.length, unicode);
|
|
213
|
-
table.nameRecords[i] = record;
|
|
214
|
-
position += recordSize;
|
|
215
|
-
}
|
|
216
|
-
return table;
|
|
217
|
-
}
|
|
218
|
-
private readHeadTable() : TtfHeadTable {
|
|
219
|
-
let tableInfo : TtfTableInfo = this.getTable('head');
|
|
220
|
-
this.offset = tableInfo.offset;
|
|
221
|
-
let table : TtfHeadTable = new TtfHeadTable();
|
|
222
|
-
table.version = this.readFixed(this.offset);
|
|
223
|
-
table.fontRevision = this.readFixed(this.offset);
|
|
224
|
-
table.checkSumAdjustment = this.readUInt32(this.offset);
|
|
225
|
-
table.magicNumber = this.readUInt32(this.offset);
|
|
226
|
-
table.flags = this.readUInt16(this.offset);
|
|
227
|
-
table.unitsPerEm = this.readUInt16(this.offset);
|
|
228
|
-
table.created = this.readInt64(this.offset);
|
|
229
|
-
table.modified = this.readInt64(this.offset);
|
|
230
|
-
table.xMin = this.readInt16(this.offset);
|
|
231
|
-
table.yMin = this.readInt16(this.offset);
|
|
232
|
-
table.xMax = this.readInt16(this.offset);
|
|
233
|
-
table.yMax = this.readInt16(this.offset);
|
|
234
|
-
table.macStyle = this.readUInt16(this.offset);
|
|
235
|
-
table.lowestReadableSize = this.readUInt16(this.offset);
|
|
236
|
-
table.fontDirectionHint = this.readInt16(this.offset);
|
|
237
|
-
table.indexToLocalFormat = this.readInt16(this.offset);
|
|
238
|
-
table.glyphDataFormat = this.readInt16(this.offset);
|
|
239
|
-
return table;
|
|
240
|
-
}
|
|
241
|
-
private readHorizontalHeaderTable() : TtfHorizontalHeaderTable {
|
|
242
|
-
let tableInfo : TtfTableInfo = this.getTable('hhea');
|
|
243
|
-
this.offset = tableInfo.offset;
|
|
244
|
-
let table : TtfHorizontalHeaderTable = new TtfHorizontalHeaderTable();
|
|
245
|
-
table.version = this.readFixed(this.offset);
|
|
246
|
-
table.ascender = this.readInt16(this.offset);
|
|
247
|
-
table.descender = this.readInt16(this.offset);
|
|
248
|
-
table.lineGap = this.readInt16(this.offset);
|
|
249
|
-
table.advanceWidthMax = this.readUInt16(this.offset);
|
|
250
|
-
table.minLeftSideBearing = this.readInt16(this.offset);
|
|
251
|
-
table.minRightSideBearing = this.readInt16(this.offset);
|
|
252
|
-
table.xMaxExtent = this.readInt16(this.offset);
|
|
253
|
-
table.caretSlopeRise = this.readInt16(this.offset);
|
|
254
|
-
table.caretSlopeRun = this.readInt16(this.offset);
|
|
255
|
-
//skip 2 * 5
|
|
256
|
-
this.offset += 10;
|
|
257
|
-
table.metricDataFormat = this.readInt16(this.offset);
|
|
258
|
-
table.numberOfHMetrics = this.readUInt16(this.offset);
|
|
259
|
-
return table;
|
|
260
|
-
}
|
|
261
|
-
private readOS2Table() : TtfOS2Table {
|
|
262
|
-
let tableInfo : TtfTableInfo = this.getTable('OS/2');
|
|
263
|
-
this.offset = tableInfo.offset;
|
|
264
|
-
let table : TtfOS2Table = new TtfOS2Table();
|
|
265
|
-
table.version = this.readUInt16(this.offset);
|
|
266
|
-
table.xAvgCharWidth = this.readInt16(this.offset);
|
|
267
|
-
table.usWeightClass = this.readUInt16(this.offset);
|
|
268
|
-
table.usWidthClass = this.readUInt16(this.offset);
|
|
269
|
-
table.fsType = this.readInt16(this.offset);
|
|
270
|
-
table.ySubscriptXSize = this.readInt16(this.offset);
|
|
271
|
-
table.ySubscriptYSize = this.readInt16(this.offset);
|
|
272
|
-
table.ySubscriptXOffset = this.readInt16(this.offset);
|
|
273
|
-
table.ySubscriptYOffset = this.readInt16(this.offset);
|
|
274
|
-
table.ySuperscriptXSize = this.readInt16(this.offset);
|
|
275
|
-
table.ySuperscriptYSize = this.readInt16(this.offset);
|
|
276
|
-
table.ySuperscriptXOffset = this.readInt16(this.offset);
|
|
277
|
-
table.ySuperscriptYOffset = this.readInt16(this.offset);
|
|
278
|
-
table.yStrikeoutSize = this.readInt16(this.offset);
|
|
279
|
-
table.yStrikeoutPosition = this.readInt16(this.offset);
|
|
280
|
-
table.sFamilyClass = this.readInt16(this.offset);
|
|
281
|
-
table.panose = this.readBytes(10);
|
|
282
|
-
table.ulUnicodeRange1 = this.readUInt32(this.offset);
|
|
283
|
-
table.ulUnicodeRange2 = this.readUInt32(this.offset);
|
|
284
|
-
table.ulUnicodeRange3 = this.readUInt32(this.offset);
|
|
285
|
-
table.ulUnicodeRange4 = this.readUInt32(this.offset);
|
|
286
|
-
table.vendorIdentifier = this.readBytes(4);
|
|
287
|
-
table.fsSelection = this.readUInt16(this.offset);
|
|
288
|
-
table.usFirstCharIndex = this.readUInt16(this.offset);
|
|
289
|
-
table.usLastCharIndex = this.readUInt16(this.offset);
|
|
290
|
-
table.sTypoAscender = this.readInt16(this.offset);
|
|
291
|
-
table.sTypoDescender = this.readInt16(this.offset);
|
|
292
|
-
table.sTypoLineGap = this.readInt16(this.offset);
|
|
293
|
-
table.usWinAscent = this.readUInt16(this.offset);
|
|
294
|
-
table.usWinDescent = this.readUInt16(this.offset);
|
|
295
|
-
table.ulCodePageRange1 = this.readUInt32(this.offset);
|
|
296
|
-
table.ulCodePageRange2 = this.readUInt32(this.offset);
|
|
297
|
-
if (table.version > 1) {
|
|
298
|
-
table.sxHeight = this.readInt16(this.offset);
|
|
299
|
-
table.sCapHeight = this.readInt16(this.offset);
|
|
300
|
-
table.usDefaultChar = this.readUInt16(this.offset);
|
|
301
|
-
table.usBreakChar = this.readUInt16(this.offset);
|
|
302
|
-
table.usMaxContext = this.readUInt16(this.offset);
|
|
303
|
-
} else {
|
|
304
|
-
table.sxHeight = 0;
|
|
305
|
-
table.sCapHeight = 0;
|
|
306
|
-
table.usDefaultChar = 0;
|
|
307
|
-
table.usBreakChar = 0;
|
|
308
|
-
table.usMaxContext = 0;
|
|
309
|
-
}
|
|
310
|
-
return table;
|
|
311
|
-
}
|
|
312
|
-
private readPostTable() : TtfPostTable {
|
|
313
|
-
let tableInfo : TtfTableInfo = this.getTable('post');
|
|
314
|
-
this.offset = tableInfo.offset;
|
|
315
|
-
let table : TtfPostTable = new TtfPostTable();
|
|
316
|
-
table.formatType = this.readFixed(this.offset);
|
|
317
|
-
table.italicAngle = this.readFixed(this.offset);
|
|
318
|
-
table.underlinePosition = this.readInt16(this.offset);
|
|
319
|
-
table.underlineThickness = this.readInt16(this.offset);
|
|
320
|
-
table.isFixedPitch = this.readUInt32(this.offset);
|
|
321
|
-
table.minType42 = this.readUInt32(this.offset);
|
|
322
|
-
table.maxType42 = this.readUInt32(this.offset);
|
|
323
|
-
table.minType1 = this.readUInt32(this.offset);
|
|
324
|
-
table.maxType1 = this.readUInt32(this.offset);
|
|
325
|
-
return table;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Reads Width of the glyphs.
|
|
329
|
-
*/
|
|
330
|
-
private readWidthTable(glyphCount : number, unitsPerEm : number) : number[] {
|
|
331
|
-
let tableInfo : TtfTableInfo = this.getTable('hmtx');
|
|
332
|
-
this.offset = tableInfo.offset;
|
|
333
|
-
let width : number[] = [];
|
|
334
|
-
for (let i : number = 0; i < glyphCount; i++) {
|
|
335
|
-
let glyph : TtfLongHorMetric = new TtfLongHorMetric();
|
|
336
|
-
glyph.advanceWidth = this.readUInt16(this.offset);
|
|
337
|
-
glyph.lsb = this.readInt16(this.offset);
|
|
338
|
-
let glyphWidth : number = glyph.advanceWidth * 1000 / unitsPerEm;
|
|
339
|
-
width.push(Math.floor(glyphWidth));
|
|
340
|
-
}
|
|
341
|
-
return width;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Reads the cmap table.
|
|
345
|
-
*/
|
|
346
|
-
private readCmapTable() : TtfCmapSubTable[] {
|
|
347
|
-
let tableInfo : TtfTableInfo = this.getTable('cmap');
|
|
348
|
-
this.offset = tableInfo.offset;
|
|
349
|
-
let table : TtfCmapTable = new TtfCmapTable();
|
|
350
|
-
table.version = this.readUInt16(this.offset);
|
|
351
|
-
table.tablesCount = this.readUInt16(this.offset);
|
|
352
|
-
let position : number = this.offset;
|
|
353
|
-
let subTables : TtfCmapSubTable[] = [];
|
|
354
|
-
for (let i : number = 0; i < table.tablesCount; i++) {
|
|
355
|
-
this.offset = position;
|
|
356
|
-
let subTable : TtfCmapSubTable = new TtfCmapSubTable();
|
|
357
|
-
subTable.platformID = this.readUInt16(this.offset);
|
|
358
|
-
subTable.encodingID = this.readUInt16(this.offset);
|
|
359
|
-
subTable.offset = this.readUInt32(this.offset);
|
|
360
|
-
position = this.offset;
|
|
361
|
-
this.readCmapSubTable(subTable);
|
|
362
|
-
subTables[i] = subTable;
|
|
363
|
-
}
|
|
364
|
-
return subTables;
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Reads the cmap sub table.
|
|
368
|
-
*/
|
|
369
|
-
private readCmapSubTable(subTable : TtfCmapSubTable) : void {
|
|
370
|
-
let tableInfo : TtfTableInfo = this.getTable('cmap');
|
|
371
|
-
this.offset = tableInfo.offset + subTable.offset;
|
|
372
|
-
let format : TtfCmapFormat = this.readUInt16(this.offset) as TtfCmapFormat;
|
|
373
|
-
let encoding : TtfCmapEncoding = this.getCmapEncoding(subTable.platformID, subTable.encodingID);
|
|
374
|
-
let platform : TtfPlatformID = (encoding === TtfCmapEncoding.Macintosh) ? TtfPlatformID.Macintosh : TtfPlatformID.Microsoft;
|
|
375
|
-
if (encoding !== TtfCmapEncoding.Unknown) {
|
|
376
|
-
switch (format) {
|
|
377
|
-
case TtfCmapFormat.Apple:
|
|
378
|
-
this.readAppleCmapTable(subTable, encoding);
|
|
379
|
-
break;
|
|
380
|
-
case TtfCmapFormat.Microsoft:
|
|
381
|
-
this.readMicrosoftCmapTable(subTable, encoding);
|
|
382
|
-
break;
|
|
383
|
-
case TtfCmapFormat.Trimmed:
|
|
384
|
-
this.readTrimmedCmapTable(subTable, encoding);
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Reads Symbol cmap table.
|
|
391
|
-
*/
|
|
392
|
-
private readAppleCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
|
|
393
|
-
let tableInfo : TtfTableInfo = this.getTable('cmap');
|
|
394
|
-
this.offset = tableInfo.offset + subTable.offset;
|
|
395
|
-
let table : TtfAppleCmapSubTable = new TtfAppleCmapSubTable();
|
|
396
|
-
table.format = this.readUInt16(this.offset);
|
|
397
|
-
table.length = this.readUInt16(this.offset);
|
|
398
|
-
table.version = this.readUInt16(this.offset);
|
|
399
|
-
if (this.maxMacIndex === null || this.maxMacIndex === undefined) {
|
|
400
|
-
this.maxMacIndex = 0;
|
|
401
|
-
}
|
|
402
|
-
for (let i : number = 0; i < 256; ++i) {
|
|
403
|
-
let glyphInfo : TtfGlyphInfo = new TtfGlyphInfo();
|
|
404
|
-
glyphInfo.index = this.readByte(this.offset) as number;
|
|
405
|
-
glyphInfo.width = this.getWidth(glyphInfo.index);
|
|
406
|
-
glyphInfo.charCode = i;
|
|
407
|
-
this.macintosh.setValue(i, glyphInfo);
|
|
408
|
-
this.addGlyph(glyphInfo, encoding);
|
|
409
|
-
// NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
|
|
410
|
-
this.maxMacIndex = Math.max(i, this.maxMacIndex);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Reads Symbol cmap table.
|
|
415
|
-
*/
|
|
416
|
-
private readMicrosoftCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
|
|
417
|
-
let tableInfo : TtfTableInfo = this.getTable('cmap');
|
|
418
|
-
this.offset = tableInfo.offset + subTable.offset;
|
|
419
|
-
let collection : Dictionary<number, TtfGlyphInfo> = (encoding === TtfCmapEncoding.Unicode) ? this.microsoft : this.macintosh;
|
|
420
|
-
let table : TtfMicrosoftCmapSubTable = new TtfMicrosoftCmapSubTable();
|
|
421
|
-
table.format = this.readUInt16(this.offset);
|
|
422
|
-
table.length = this.readUInt16(this.offset);
|
|
423
|
-
table.version = this.readUInt16(this.offset);
|
|
424
|
-
table.segCountX2 = this.readUInt16(this.offset);
|
|
425
|
-
table.searchRange = this.readUInt16(this.offset);
|
|
426
|
-
table.entrySelector = this.readUInt16(this.offset);
|
|
427
|
-
table.rangeShift = this.readUInt16(this.offset);
|
|
428
|
-
let segCount : number = table.segCountX2 / 2;
|
|
429
|
-
table.endCount = this.readUshortArray(segCount);
|
|
430
|
-
table.reservedPad = this.readUInt16(this.offset);
|
|
431
|
-
table.startCount = this.readUshortArray(segCount);
|
|
432
|
-
table.idDelta = this.readUshortArray(segCount);
|
|
433
|
-
table.idRangeOffset = this.readUshortArray(segCount);
|
|
434
|
-
let length : number = (table.length / 2 - 8) - (segCount * 4);
|
|
435
|
-
table.glyphID = this.readUshortArray(length);
|
|
436
|
-
// Process glyphIdArray array.
|
|
437
|
-
let codeOffset : number = 0;
|
|
438
|
-
let index : number = 0;
|
|
439
|
-
for (let j : number = 0; j < segCount; j++) {
|
|
440
|
-
for (let k : number = table.startCount[j]; k <= table.endCount[j] && k !== 65535; k++) {
|
|
441
|
-
if (table.idRangeOffset[j] === 0) {
|
|
442
|
-
codeOffset = (k + table.idDelta[j]) & 65535;
|
|
443
|
-
} else {
|
|
444
|
-
index = j + table.idRangeOffset[j] / 2 - segCount + k - table.startCount[j];
|
|
445
|
-
if (index >= table.glyphID.length) {
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
codeOffset = (table.glyphID[index] + table.idDelta[j]) & 65535;
|
|
449
|
-
}
|
|
450
|
-
let glyph : TtfGlyphInfo = new TtfGlyphInfo();
|
|
451
|
-
glyph.index = codeOffset;
|
|
452
|
-
glyph.width = this.getWidth(glyph.index);
|
|
453
|
-
let id : number = (encoding === TtfCmapEncoding.Symbol) ? ((k & 0xff00) === 0xf000 ? k & 0xff : k) : k;
|
|
454
|
-
glyph.charCode = id;
|
|
455
|
-
collection.setValue(id, glyph);
|
|
456
|
-
this.addGlyph(glyph, encoding);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Reads Trimed cmap table.
|
|
462
|
-
*/
|
|
463
|
-
private readTrimmedCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
|
|
464
|
-
let tableInfo : TtfTableInfo = this.getTable('cmap');
|
|
465
|
-
this.offset = tableInfo.offset + subTable.offset;
|
|
466
|
-
let table : TtfTrimmedCmapSubTable = new TtfTrimmedCmapSubTable();
|
|
467
|
-
table.format = this.readUInt16(this.offset);
|
|
468
|
-
table.length = this.readUInt16(this.offset);
|
|
469
|
-
table.version = this.readUInt16(this.offset);
|
|
470
|
-
table.firstCode = this.readUInt16(this.offset);
|
|
471
|
-
table.entryCount = this.readUInt16(this.offset);
|
|
472
|
-
for (let i : number = 0; i < table.entryCount; ++i) {
|
|
473
|
-
let glyphInfo : TtfGlyphInfo = new TtfGlyphInfo();
|
|
474
|
-
glyphInfo.index = this.readUInt16(this.offset);
|
|
475
|
-
glyphInfo.width = this.getWidth(glyphInfo.index);
|
|
476
|
-
glyphInfo.charCode = i + table.firstCode;
|
|
477
|
-
this.macintosh.setValue(i, glyphInfo);
|
|
478
|
-
this.addGlyph(glyphInfo, encoding);
|
|
479
|
-
// NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
|
|
480
|
-
this.maxMacIndex = Math.max(i, this.maxMacIndex);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
private initializeFontName(nameTable : TtfNameTable) : void {
|
|
484
|
-
for (let i : number = 0; i < nameTable.recordsCount; i++) {
|
|
485
|
-
let record : TtfNameRecord = nameTable.nameRecords[i];
|
|
486
|
-
if (record.nameID === 1) {
|
|
487
|
-
//font family
|
|
488
|
-
this.metrics.fontFamily = record.name;
|
|
489
|
-
} else if (record.nameID === 6) {
|
|
490
|
-
//post script name
|
|
491
|
-
this.metrics.postScriptName = record.name;
|
|
492
|
-
}
|
|
493
|
-
/* tslint:disable */
|
|
494
|
-
if (this.metrics.fontFamily !== null && this.metrics.fontFamily !== undefined && this.metrics.postScriptName !== null && this.metrics.postScriptName !== undefined) {
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
/* tslint:disable */
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
private getTable(name : string) : TtfTableInfo {
|
|
501
|
-
// if (name === null) {
|
|
502
|
-
// throw new Error('Argument Null Exception : name');
|
|
503
|
-
// }
|
|
504
|
-
let table : TtfTableInfo = new TtfTableInfo();
|
|
505
|
-
let obj : TtfTableInfo;
|
|
506
|
-
if (this.tableDirectory.containsKey(name)) {
|
|
507
|
-
obj = this.tableDirectory.getValue(name);
|
|
508
|
-
}
|
|
509
|
-
if (obj !== null && obj !== undefined) {
|
|
510
|
-
table = obj as TtfTableInfo;
|
|
511
|
-
}
|
|
512
|
-
return table;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Returns width of the glyph.
|
|
516
|
-
*/
|
|
517
|
-
private getWidth(glyphCode : number) : number {
|
|
518
|
-
glyphCode = (glyphCode < this.width.length) ? glyphCode : this.width.length - 1;
|
|
519
|
-
return this.width[glyphCode];
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Gets CMAP encoding based on platform ID and encoding ID.
|
|
523
|
-
*/
|
|
524
|
-
/* tslint:disable */
|
|
525
|
-
private getCmapEncoding(platformID : number, encodingID : number) : TtfCmapEncoding {
|
|
526
|
-
let format : TtfCmapEncoding = TtfCmapEncoding.Unknown;
|
|
527
|
-
if (platformID == (TtfPlatformID.Microsoft as number) && encodingID == (TtfMicrosoftEncodingID.Undefined as number)) {
|
|
528
|
-
// When building a symbol font for Windows,
|
|
529
|
-
// the platform ID should be 3 and the encoding ID should be 0.
|
|
530
|
-
format = TtfCmapEncoding.Symbol;
|
|
531
|
-
} else if (platformID == (TtfPlatformID.Microsoft as number) && encodingID == (TtfMicrosoftEncodingID.Unicode as number)) {
|
|
532
|
-
// When building a Unicode font for Windows,
|
|
533
|
-
// the platform ID should be 3 and the encoding ID should be 1.
|
|
534
|
-
format = TtfCmapEncoding.Unicode;
|
|
535
|
-
} else if (platformID == (TtfPlatformID.Macintosh as number) && encodingID == (TtfMacintoshEncodingID.Roman as number)) {
|
|
536
|
-
// When building a font that will be used on the Macintosh,
|
|
537
|
-
// the platform ID should be 1 and the encoding ID should be 0.
|
|
538
|
-
format = TtfCmapEncoding.Macintosh;
|
|
539
|
-
}
|
|
540
|
-
return format;
|
|
541
|
-
}
|
|
542
|
-
/* tslint:enable */
|
|
543
|
-
/**
|
|
544
|
-
* Adds glyph to the collection.
|
|
545
|
-
*/
|
|
546
|
-
private addGlyph(glyph : TtfGlyphInfo, encoding : TtfCmapEncoding) : void {
|
|
547
|
-
let collection : Dictionary<number, TtfGlyphInfo> = null;
|
|
548
|
-
switch (encoding) {
|
|
549
|
-
case TtfCmapEncoding.Unicode:
|
|
550
|
-
collection = this.microsoftGlyphs;
|
|
551
|
-
break;
|
|
552
|
-
case TtfCmapEncoding.Macintosh:
|
|
553
|
-
case TtfCmapEncoding.Symbol:
|
|
554
|
-
collection = this.macintoshGlyphs;
|
|
555
|
-
break;
|
|
556
|
-
}
|
|
557
|
-
collection.setValue(glyph.index, glyph);
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Initializes metrics.
|
|
561
|
-
*/
|
|
562
|
-
/* tslint:disable */
|
|
563
|
-
private initializeMetrics(nameTable : TtfNameTable, headTable : TtfHeadTable, horizontalHeadTable : TtfHorizontalHeaderTable, os2Table : TtfOS2Table, postTable : TtfPostTable, cmapTables : TtfCmapSubTable[]) : void {
|
|
564
|
-
/* tslint:enable */
|
|
565
|
-
// if (cmapTables === null) {
|
|
566
|
-
// throw new Error('ArgumentNullException : cmapTables');
|
|
567
|
-
// }
|
|
568
|
-
this.initializeFontName(nameTable);
|
|
569
|
-
// Get font encoding.
|
|
570
|
-
let bSymbol : boolean = false;
|
|
571
|
-
for (let i : number = 0; i < cmapTables.length; i++) {
|
|
572
|
-
let subTable : TtfCmapSubTable = cmapTables[i];
|
|
573
|
-
let encoding : TtfCmapEncoding = this.getCmapEncoding(subTable.platformID, subTable.encodingID);
|
|
574
|
-
if (encoding === TtfCmapEncoding.Symbol) {
|
|
575
|
-
bSymbol = true;
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
this.metrics.isSymbol = bSymbol;
|
|
580
|
-
this.metrics.macStyle = headTable.macStyle;
|
|
581
|
-
this.metrics.isFixedPitch = (postTable.isFixedPitch !== 0);
|
|
582
|
-
this.metrics.italicAngle = postTable.italicAngle;
|
|
583
|
-
let factor : number = 1000 / headTable.unitsPerEm;
|
|
584
|
-
this.metrics.winAscent = os2Table.sTypoAscender * factor;
|
|
585
|
-
this.metrics.macAscent = horizontalHeadTable.ascender * factor;
|
|
586
|
-
//m_metrics.MacAscent = os2Table.UsWinAscent * factor;
|
|
587
|
-
// NOTE: This is stange workaround. The value is good if os2Table.SCapHeight != 0, otherwise it should be properly computed.
|
|
588
|
-
this.metrics.capHeight = (os2Table.sCapHeight !== 0) ? os2Table.sCapHeight : 0.7 * headTable.unitsPerEm * factor;
|
|
589
|
-
this.metrics.winDescent = os2Table.sTypoDescender * factor;
|
|
590
|
-
this.metrics.macDescent = horizontalHeadTable.descender * factor;
|
|
591
|
-
//m_metrics.MacDescent = -os2Table.UsWinDescent * factor;
|
|
592
|
-
this.metrics.leading = (os2Table.sTypoAscender - os2Table.sTypoDescender + os2Table.sTypoLineGap) * factor;
|
|
593
|
-
this.metrics.lineGap = Math.ceil(horizontalHeadTable.lineGap * factor);
|
|
594
|
-
let left : number = headTable.xMin * factor;
|
|
595
|
-
let top : number = Math.ceil(this.metrics.macAscent + this.metrics.lineGap);
|
|
596
|
-
let right : number = headTable.xMax * factor;
|
|
597
|
-
let bottom : number = this.metrics.macDescent;
|
|
598
|
-
this.metrics.fontBox = new Rectangle(left, top, right, bottom);
|
|
599
|
-
// NOTE: Strange!
|
|
600
|
-
this.metrics.stemV = 80;
|
|
601
|
-
this.metrics.widthTable = this.updateWidth();
|
|
602
|
-
this.metrics.contains = this.tableDirectory.containsKey('CFF');
|
|
603
|
-
this.metrics.subScriptSizeFactor = headTable.unitsPerEm / os2Table.ySubscriptYSize;
|
|
604
|
-
this.metrics.superscriptSizeFactor = headTable.unitsPerEm / os2Table.ySuperscriptYSize;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Updates chars structure which is used in the case of ansi encoding (256 bytes).
|
|
608
|
-
*/
|
|
609
|
-
private updateWidth() : number[] {
|
|
610
|
-
let count : number = 256;
|
|
611
|
-
let bytes : number[] = [];
|
|
612
|
-
if (this.metrics.isSymbol) {
|
|
613
|
-
for (let i : number = 0; i < count; i++) {
|
|
614
|
-
let glyphInfo : TtfGlyphInfo = this.getGlyph(String.fromCharCode(i));
|
|
615
|
-
bytes[i] = (glyphInfo.empty) ? 0 : glyphInfo.width;
|
|
616
|
-
}
|
|
617
|
-
} else {
|
|
618
|
-
let byteToProcess : number[] = [];
|
|
619
|
-
let unknown : string = '?';
|
|
620
|
-
let space : string = String.fromCharCode(32);
|
|
621
|
-
for (let i : number = 0; i < count; i++) {
|
|
622
|
-
byteToProcess[0] = i;
|
|
623
|
-
let text : string = this.getString(byteToProcess, 0, byteToProcess.length);
|
|
624
|
-
let ch : string = (text.length > 0) ? text[0] : unknown;
|
|
625
|
-
let glyphInfo : TtfGlyphInfo = this.getGlyph(ch);
|
|
626
|
-
if (!glyphInfo.empty) {
|
|
627
|
-
bytes[i] = glyphInfo.width;
|
|
628
|
-
} else {
|
|
629
|
-
glyphInfo = this.getGlyph(space);
|
|
630
|
-
bytes[i] = (glyphInfo.empty) ? 0 : glyphInfo.width;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
return bytes;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Returns default glyph.
|
|
638
|
-
*/
|
|
639
|
-
private getDefaultGlyph() : TtfGlyphInfo {
|
|
640
|
-
let glyph : TtfGlyphInfo = this.getGlyph(StringTokenizer.whiteSpace);
|
|
641
|
-
return glyph;
|
|
642
|
-
}
|
|
643
|
-
/**
|
|
644
|
-
* Reads unicode string from byte array.
|
|
645
|
-
*/
|
|
646
|
-
private getString(byteToProcess : number[], start : number, length : number) : string {
|
|
647
|
-
let result : string = '';
|
|
648
|
-
for (let index : number = 0; index < length; index++) {
|
|
649
|
-
result += String.fromCharCode(byteToProcess[index + start]);
|
|
650
|
-
}
|
|
651
|
-
return result;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Reads loca table.
|
|
655
|
-
*/
|
|
656
|
-
private readLocaTable(bShort : boolean) : TtfLocaTable {
|
|
657
|
-
let tableInfo : TtfTableInfo = this.getTable('loca');
|
|
658
|
-
this.offset = tableInfo.offset;
|
|
659
|
-
let table : TtfLocaTable = new TtfLocaTable();
|
|
660
|
-
let buffer : number[] = null;
|
|
661
|
-
if (bShort) {
|
|
662
|
-
let len : number = tableInfo.length / 2;
|
|
663
|
-
buffer = [];
|
|
664
|
-
for (let i : number = 0; i < len; i++) {
|
|
665
|
-
buffer[i] = this.readUInt16(this.offset) * 2;
|
|
666
|
-
}
|
|
667
|
-
} else {
|
|
668
|
-
let len : number = tableInfo.length / 4;
|
|
669
|
-
buffer = [];
|
|
670
|
-
for (let i : number = 0; i < len; i++) {
|
|
671
|
-
buffer[i] = this.readUInt32(this.offset);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
table.offsets = buffer;
|
|
675
|
-
return table;
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Updates hash table of used glyphs.
|
|
679
|
-
*/
|
|
680
|
-
private updateGlyphChars(glyphChars : Dictionary<number, number>, locaTable : TtfLocaTable) : void {
|
|
681
|
-
// if (glyphChars === null) {
|
|
682
|
-
// throw new Error('Argument Null Exception : glyphChars');
|
|
683
|
-
// }
|
|
684
|
-
// Add zero key.
|
|
685
|
-
if (!glyphChars.containsKey(0)) {
|
|
686
|
-
glyphChars.setValue(0, 0);
|
|
687
|
-
}
|
|
688
|
-
let clone : Dictionary<number, number> = new Dictionary<number, number>();
|
|
689
|
-
let glyphCharKeys : number[] = glyphChars.keys();
|
|
690
|
-
for (let i : number = 0; i < glyphCharKeys.length; i++) {
|
|
691
|
-
clone.setValue(glyphCharKeys[i], glyphChars.getValue(glyphCharKeys[i]));
|
|
692
|
-
}
|
|
693
|
-
for (let i : number = 0; i < glyphCharKeys.length; i++) {
|
|
694
|
-
let nextKey : number = glyphCharKeys[i];
|
|
695
|
-
this.processCompositeGlyph(glyphChars, nextKey, locaTable);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
/**
|
|
699
|
-
* Checks if glyph is composite or not.
|
|
700
|
-
*/
|
|
701
|
-
private processCompositeGlyph(glyphChars : Dictionary<number, number>, glyph : number, locaTable : TtfLocaTable) : void {
|
|
702
|
-
// if (glyphChars === null) {
|
|
703
|
-
// throw new Error('Argument Null Exception : glyphChars');
|
|
704
|
-
// }
|
|
705
|
-
// Is in range.
|
|
706
|
-
if (glyph < locaTable.offsets.length - 1) {
|
|
707
|
-
let glyphOffset : number = locaTable.offsets[glyph];
|
|
708
|
-
if (glyphOffset !== locaTable.offsets[glyph + 1]) {
|
|
709
|
-
let tableInfo : TtfTableInfo = this.getTable('glyf');
|
|
710
|
-
this.offset = tableInfo.offset + glyphOffset;
|
|
711
|
-
let glyphHeader : TtfGlyphHeader = new TtfGlyphHeader();
|
|
712
|
-
glyphHeader.numberOfContours = this.readInt16(this.offset);
|
|
713
|
-
glyphHeader.xMin = this.readInt16(this.offset);
|
|
714
|
-
glyphHeader.yMin = this.readInt16(this.offset);
|
|
715
|
-
glyphHeader.xMax = this.readInt16(this.offset);
|
|
716
|
-
glyphHeader.yMax = this.readInt16(this.offset);
|
|
717
|
-
// Glyph is composite.
|
|
718
|
-
if (glyphHeader.numberOfContours < 0) {
|
|
719
|
-
let skipBytes : number = 0;
|
|
720
|
-
let entry : boolean = true;
|
|
721
|
-
while (entry) {
|
|
722
|
-
let flags : number = this.readUInt16(this.offset);
|
|
723
|
-
let glyphIndex : number = this.readUInt16(this.offset);
|
|
724
|
-
if (!glyphChars.containsKey(glyphIndex)) {
|
|
725
|
-
glyphChars.setValue(glyphIndex, 0);
|
|
726
|
-
}
|
|
727
|
-
if ((flags & TtfCompositeGlyphFlags.MoreComponents) === 0) {
|
|
728
|
-
break;
|
|
729
|
-
}
|
|
730
|
-
skipBytes = ((flags & TtfCompositeGlyphFlags.Arg1And2AreWords) !== 0) ? 4 : 2;
|
|
731
|
-
if ((flags & TtfCompositeGlyphFlags.WeHaveScale) !== 0) {
|
|
732
|
-
skipBytes += 2;
|
|
733
|
-
} else if ((flags & TtfCompositeGlyphFlags.WeHaveAnXyScale) !== 0) {
|
|
734
|
-
skipBytes += 4;
|
|
735
|
-
} else if ((flags & TtfCompositeGlyphFlags.WeHaveTwoByTwo) !== 0) {
|
|
736
|
-
skipBytes += 2 * 4;
|
|
737
|
-
}
|
|
738
|
-
this.offset += skipBytes;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Creates new glyph tables based on chars that are used for output.
|
|
746
|
-
*/
|
|
747
|
-
/* tslint:disable */
|
|
748
|
-
private generateGlyphTable(glyphChars : Dictionary<number, number>, locaTable : TtfLocaTable, newLocaTable : number[], newGlyphTable : number[]) : { glyphTableSize : number, newLocaTable : number[], newGlyphTable : number[] } {
|
|
749
|
-
/* tslint:enable */
|
|
750
|
-
// if (glyphChars === null) {
|
|
751
|
-
// throw new Error('Argument Null Exception : glyphChars');
|
|
752
|
-
// }
|
|
753
|
-
newLocaTable = [];
|
|
754
|
-
// Sorting used glyphs keys.
|
|
755
|
-
let activeGlyphs : number[] = glyphChars.keys();
|
|
756
|
-
activeGlyphs.sort((a : number, b : number) => a - b);
|
|
757
|
-
let glyphSize : number = 0;
|
|
758
|
-
for (let i : number = 0; i < activeGlyphs.length; i++) {
|
|
759
|
-
let glyphIndex : number = activeGlyphs[i];
|
|
760
|
-
if (locaTable.offsets.length > 0) {
|
|
761
|
-
glyphSize += locaTable.offsets[glyphIndex + 1] - locaTable.offsets[glyphIndex];
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
let glyphSizeAligned : number = this.align(glyphSize);
|
|
765
|
-
newGlyphTable = [];
|
|
766
|
-
for (let i : number = 0; i < glyphSizeAligned; i++) {
|
|
767
|
-
newGlyphTable.push(0);
|
|
768
|
-
}
|
|
769
|
-
let nextGlyphOffset : number = 0;
|
|
770
|
-
let nextGlyphIndex : number = 0;
|
|
771
|
-
let table : TtfTableInfo = this.getTable('glyf');
|
|
772
|
-
// Creating NewLocaTable - that would hold offsets for filtered glyphs.
|
|
773
|
-
for (let i : number = 0; i < locaTable.offsets.length; i++) {
|
|
774
|
-
newLocaTable.push(nextGlyphOffset);
|
|
775
|
-
if (nextGlyphIndex < activeGlyphs.length && activeGlyphs[nextGlyphIndex] === i) {
|
|
776
|
-
++nextGlyphIndex;
|
|
777
|
-
newLocaTable[i] = nextGlyphOffset;
|
|
778
|
-
let oldGlyphOffset : number = locaTable.offsets[i];
|
|
779
|
-
let oldNextGlyphOffset : number = locaTable.offsets[i + 1] - oldGlyphOffset;
|
|
780
|
-
if (oldNextGlyphOffset > 0) {
|
|
781
|
-
this.offset = table.offset + oldGlyphOffset;
|
|
782
|
-
let result : { buffer : number[], written : number } = this.read(newGlyphTable, nextGlyphOffset, oldNextGlyphOffset);
|
|
783
|
-
newGlyphTable = result.buffer;
|
|
784
|
-
nextGlyphOffset += oldNextGlyphOffset;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
return { glyphTableSize : glyphSize, newLocaTable : newLocaTable, newGlyphTable : newGlyphTable };
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* Updates new Loca table.
|
|
792
|
-
*/
|
|
793
|
-
/* tslint:disable */
|
|
794
|
-
private updateLocaTable(newLocaTable : number[], bLocaIsShort : boolean, newLocaTableOut : number[]) : { newLocaUpdated : number[], newLocaSize : number } {
|
|
795
|
-
/* tslint:enable */
|
|
796
|
-
if (newLocaTable === null) {
|
|
797
|
-
throw new Error('Argument Null Exception : newLocaTable');
|
|
798
|
-
}
|
|
799
|
-
let size : number = (bLocaIsShort) ? newLocaTable.length * 2 : newLocaTable.length * 4;
|
|
800
|
-
let count : number = this.align(size);
|
|
801
|
-
//BigEndianWiter
|
|
802
|
-
let writer : BigEndianWriter = new BigEndianWriter(count);
|
|
803
|
-
for (let i : number = 0; i < newLocaTable.length; i++) {
|
|
804
|
-
let value : number = newLocaTable[i];
|
|
805
|
-
if (bLocaIsShort) {
|
|
806
|
-
value /= 2;
|
|
807
|
-
writer.writeShort(value);
|
|
808
|
-
} else {
|
|
809
|
-
writer.writeInt(value);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
return { newLocaUpdated : writer.data, newLocaSize : size };
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Aligns number to be divisible on 4.
|
|
816
|
-
*/
|
|
817
|
-
private align(value : number) : number {
|
|
818
|
-
return (value + 3) & (~3);
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Returns font program data.
|
|
822
|
-
*/
|
|
823
|
-
/* tslint:disable */
|
|
824
|
-
private getFontProgram(newLocaTableOut : number[], newGlyphTable : number[], glyphTableSize : number, locaTableSize : number) : number[] {
|
|
825
|
-
/* tslint:enable */
|
|
826
|
-
if (newLocaTableOut === null) {
|
|
827
|
-
throw new Error('Argument Null Exception : newLocaTableOut');
|
|
828
|
-
}
|
|
829
|
-
if (newGlyphTable === null) {
|
|
830
|
-
throw new Error('Argument Null Exception : newGlyphTable');
|
|
831
|
-
}
|
|
832
|
-
let tableNames : string[] = this.tableNames;
|
|
833
|
-
let result : {fontProgramLength : number, numTables : number} = this.getFontProgramLength(newLocaTableOut, newGlyphTable, 0);
|
|
834
|
-
let fontProgramLength : number = result.fontProgramLength;
|
|
835
|
-
let numTables : number = result.numTables;
|
|
836
|
-
let writer : BigEndianWriter = new BigEndianWriter(fontProgramLength);
|
|
837
|
-
writer.writeInt(0x10000);
|
|
838
|
-
writer.writeShort(numTables);
|
|
839
|
-
let entrySelector : number = this.entrySelectors[numTables];
|
|
840
|
-
writer.writeShort((1 << (entrySelector & 31)) * 16);
|
|
841
|
-
writer.writeShort(entrySelector);
|
|
842
|
-
writer.writeShort((numTables - (1 << (entrySelector & 31))) * 16);
|
|
843
|
-
// Writing to destination buffer - checksums && sizes of used tables.
|
|
844
|
-
this.writeCheckSums(writer, numTables, newLocaTableOut, newGlyphTable, glyphTableSize, locaTableSize);
|
|
845
|
-
// // Writing to destination buffer - used glyphs.
|
|
846
|
-
this.writeGlyphs(writer, newLocaTableOut, newGlyphTable);
|
|
847
|
-
return writer.data;
|
|
848
|
-
}
|
|
849
|
-
/* tslint:disable */
|
|
850
|
-
private getFontProgramLength(newLocaTableOut : number[], newGlyphTable : number[], numTables : number) : {fontProgramLength : number, numTables : number} {
|
|
851
|
-
/* tslint:enable */
|
|
852
|
-
if (newLocaTableOut === null) {
|
|
853
|
-
throw new Error('Argument Null Exception : newLocaTableOut');
|
|
854
|
-
}
|
|
855
|
-
if (newGlyphTable === null) {
|
|
856
|
-
throw new Error('Argument Null Exception : newGlyphTable');
|
|
857
|
-
}
|
|
858
|
-
// glyf and loca are used by default;
|
|
859
|
-
numTables = 2;
|
|
860
|
-
let tableNames : string[] = this.tableNames;
|
|
861
|
-
let fontProgramLength : number = 0;
|
|
862
|
-
for (let i : number = 0; i < tableNames.length; i++) {
|
|
863
|
-
let tableName : string = tableNames[i];
|
|
864
|
-
if (tableName !== 'glyf' && tableName !== 'loca') {
|
|
865
|
-
let table : TtfTableInfo = this.getTable(tableName);
|
|
866
|
-
if (!table.empty) {
|
|
867
|
-
++numTables;
|
|
868
|
-
fontProgramLength += this.align(table.length);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
fontProgramLength += newLocaTableOut.length;
|
|
873
|
-
fontProgramLength += newGlyphTable.length;
|
|
874
|
-
let usedTablesSize : number = numTables * 16 + (3 * 4);
|
|
875
|
-
fontProgramLength += usedTablesSize;
|
|
876
|
-
return { fontProgramLength : fontProgramLength, numTables : numTables};
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* Writing to destination buffer - checksums and sizes of used tables.
|
|
880
|
-
*/
|
|
881
|
-
/* tslint:disable */
|
|
882
|
-
private writeCheckSums(writer : BigEndianWriter, numTables : number, newLocaTableOut : number[], newGlyphTable : number[], glyphTableSize : number, locaTableSize : number) : void {
|
|
883
|
-
/* tslint:enable */
|
|
884
|
-
if (writer === null) {
|
|
885
|
-
throw new Error('Argument Null Exception : writer');
|
|
886
|
-
}
|
|
887
|
-
if (newLocaTableOut === null) {
|
|
888
|
-
throw new Error('Argument Null Exception : newLocaTableOut');
|
|
889
|
-
}
|
|
890
|
-
if (newGlyphTable === null) {
|
|
891
|
-
throw new Error('Argument Null Exception : newGlyphTable');
|
|
892
|
-
}
|
|
893
|
-
let tableNames : string[] = this.tableNames;
|
|
894
|
-
let usedTablesSize : number = numTables * 16 + (3 * 4);
|
|
895
|
-
let nextTableSize : number = 0;
|
|
896
|
-
for (let i : number = 0; i < tableNames.length; i++) {
|
|
897
|
-
let tableName : string = tableNames[i];
|
|
898
|
-
let tableInfo : TtfTableInfo = this.getTable(tableName);
|
|
899
|
-
if (tableInfo.empty) {
|
|
900
|
-
continue;
|
|
901
|
-
}
|
|
902
|
-
writer.writeString(tableName);
|
|
903
|
-
if (tableName === 'glyf') {
|
|
904
|
-
let checksum : number = this.calculateCheckSum(newGlyphTable);
|
|
905
|
-
writer.writeInt(checksum);
|
|
906
|
-
nextTableSize = glyphTableSize;
|
|
907
|
-
} else if (tableName === 'loca') {
|
|
908
|
-
let checksum : number = this.calculateCheckSum(newLocaTableOut);
|
|
909
|
-
writer.writeInt(checksum);
|
|
910
|
-
nextTableSize = locaTableSize;
|
|
911
|
-
} else {
|
|
912
|
-
writer.writeInt(tableInfo.checksum);
|
|
913
|
-
nextTableSize = tableInfo.length;
|
|
914
|
-
}
|
|
915
|
-
writer.writeUInt(usedTablesSize);
|
|
916
|
-
writer.writeUInt(nextTableSize);
|
|
917
|
-
usedTablesSize += this.align(nextTableSize);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Gets checksum from source buffer.
|
|
922
|
-
*/
|
|
923
|
-
private calculateCheckSum(bytes : number[]) : number {
|
|
924
|
-
if (bytes === null) {
|
|
925
|
-
throw new Error('Argument Null Exception : bytes');
|
|
926
|
-
}
|
|
927
|
-
let pos : number = 0;
|
|
928
|
-
let byte1 : number = 0;
|
|
929
|
-
let byte2 : number = 0;
|
|
930
|
-
let byte3 : number = 0;
|
|
931
|
-
let byte4 : number = 0;
|
|
932
|
-
|
|
933
|
-
for (let i : number = 0; i < (bytes.length + 1) / 4; i++) {
|
|
934
|
-
byte4 += (bytes[pos++] & 255);
|
|
935
|
-
byte3 += (bytes[pos++] & 255);
|
|
936
|
-
byte2 += (bytes[pos++] & 255);
|
|
937
|
-
byte1 += (bytes[pos++] & 255);
|
|
938
|
-
}
|
|
939
|
-
let result : number = byte1;
|
|
940
|
-
result += (byte2 << 8);
|
|
941
|
-
result += (byte3 << 16);
|
|
942
|
-
result += (byte4 << 24);
|
|
943
|
-
return result;
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
|
-
* Writing to destination buffer - used glyphs.
|
|
947
|
-
*/
|
|
948
|
-
private writeGlyphs(writer : BigEndianWriter, newLocaTable : number[], newGlyphTable : number[]) : void {
|
|
949
|
-
if (writer === null) {
|
|
950
|
-
throw new Error('Argument Null Exception : writer');
|
|
951
|
-
}
|
|
952
|
-
if (newLocaTable === null) {
|
|
953
|
-
throw new Error('Argument Null Exception : newLocaTableOut');
|
|
954
|
-
}
|
|
955
|
-
if (newGlyphTable === null) {
|
|
956
|
-
throw new Error('Argument Null Exception : newGlyphTable');
|
|
957
|
-
}
|
|
958
|
-
let tableNames : string[] = this.tableNames;
|
|
959
|
-
for (let i : number = 0; i < tableNames.length; i++) {
|
|
960
|
-
let tableName : string = tableNames[i];
|
|
961
|
-
let tableInfo : TtfTableInfo = this.getTable(tableName);
|
|
962
|
-
if (tableInfo.empty) {
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
if (tableName === 'glyf') {
|
|
966
|
-
writer.writeBytes(newGlyphTable);
|
|
967
|
-
} else if (tableName === 'loca') {
|
|
968
|
-
writer.writeBytes(newLocaTable);
|
|
969
|
-
} else {
|
|
970
|
-
let count : number = this.align(tableInfo.length);
|
|
971
|
-
let buff : number[] = [];
|
|
972
|
-
for (let i : number = 0; i < count; i++) {
|
|
973
|
-
buff.push(0);
|
|
974
|
-
}
|
|
975
|
-
this.offset = tableInfo.offset;
|
|
976
|
-
let result : {buffer : number[], written : number} = this.read(buff, 0, tableInfo.length);
|
|
977
|
-
writer.writeBytes(result.buffer);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
//public methods
|
|
982
|
-
/**
|
|
983
|
-
* Sets position value of font data.
|
|
984
|
-
*/
|
|
985
|
-
public setOffset(offset : number) : void {
|
|
986
|
-
this.offset = offset;
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Creates font Internals
|
|
990
|
-
* @private
|
|
991
|
-
*/
|
|
992
|
-
public createInternals() : void {
|
|
993
|
-
this.metrics = new TtfMetrics();
|
|
994
|
-
let nameTable : TtfNameTable = this.readNameTable();
|
|
995
|
-
let headTable : TtfHeadTable = this.readHeadTable();
|
|
996
|
-
this.bIsLocaShort = (headTable.indexToLocalFormat === 0);
|
|
997
|
-
let horizontalHeadTable : TtfHorizontalHeaderTable = this.readHorizontalHeaderTable();
|
|
998
|
-
let os2Table : TtfOS2Table = this.readOS2Table();
|
|
999
|
-
let postTable : TtfPostTable = this.readPostTable();
|
|
1000
|
-
this.width = this.readWidthTable(horizontalHeadTable.numberOfHMetrics, headTable.unitsPerEm);
|
|
1001
|
-
let subTables : TtfCmapSubTable[] = this.readCmapTable();
|
|
1002
|
-
this.initializeMetrics(nameTable, headTable, horizontalHeadTable, os2Table, postTable, subTables);
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Gets glyph's info by char code.
|
|
1006
|
-
*/
|
|
1007
|
-
public getGlyph(charCode : string ) : TtfGlyphInfo
|
|
1008
|
-
public getGlyph(charCode : number ) : TtfGlyphInfo
|
|
1009
|
-
public getGlyph(charCode ?: string | number) : TtfGlyphInfo {
|
|
1010
|
-
if (typeof charCode === 'number') {
|
|
1011
|
-
let obj1 : object = null;
|
|
1012
|
-
if (!this.metrics.isSymbol && this.microsoftGlyphs != null) {
|
|
1013
|
-
if (this.microsoftGlyphs.containsKey(charCode)) {
|
|
1014
|
-
obj1 = this.microsoftGlyphs.getValue(charCode);
|
|
1015
|
-
}
|
|
1016
|
-
} else if (this.metrics.isSymbol && this.macintoshGlyphs != null) {
|
|
1017
|
-
if (this.macintoshGlyphs.containsKey(charCode)) {
|
|
1018
|
-
obj1 = this.macintoshGlyphs.getValue(charCode);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
let glyph : TtfGlyphInfo = (obj1 != null) ? obj1 as TtfGlyphInfo : this.getDefaultGlyph();
|
|
1022
|
-
return glyph;
|
|
1023
|
-
} else {
|
|
1024
|
-
let obj : object = null;
|
|
1025
|
-
let code : number = charCode.charCodeAt(0);
|
|
1026
|
-
if (!this.metrics.isSymbol && this.microsoft !== null) {
|
|
1027
|
-
if (this.microsoft.containsKey(code)) {
|
|
1028
|
-
obj = this.microsoft.getValue(code);
|
|
1029
|
-
if (code !== StringTokenizer.whiteSpace.charCodeAt(0)) {
|
|
1030
|
-
this.isFontPresent = true;
|
|
1031
|
-
}
|
|
1032
|
-
} else if (code !== StringTokenizer.whiteSpace.charCodeAt(0)) {
|
|
1033
|
-
this.isFontPresent = false;
|
|
1034
|
-
}
|
|
1035
|
-
} else if (this.metrics.isSymbol && this.macintosh !== null || this.isMacTTF) {
|
|
1036
|
-
// NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
|
|
1037
|
-
if (this.maxMacIndex !== 0) {
|
|
1038
|
-
code %= this.maxMacIndex + 1;
|
|
1039
|
-
} else {
|
|
1040
|
-
code = ((code & 0xff00) === 0xf000 ? code & 0xff : code);
|
|
1041
|
-
}
|
|
1042
|
-
if (this.macintosh.containsKey(code)) {
|
|
1043
|
-
obj = this.macintosh.getValue(code);
|
|
1044
|
-
this.isFontPresent = true;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
// Fix for StackOverFlow exception in XPS to PDF converter
|
|
1048
|
-
if (charCode === StringTokenizer.whiteSpace && obj === null) {
|
|
1049
|
-
obj = new TtfGlyphInfo();
|
|
1050
|
-
}
|
|
1051
|
-
let glyph : TtfGlyphInfo = (obj !== null) ? obj as TtfGlyphInfo : this.getDefaultGlyph();
|
|
1052
|
-
return glyph;
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Gets hash table with chars indexed by glyph index.
|
|
1057
|
-
*/
|
|
1058
|
-
public getGlyphChars(chars : Dictionary<string, string>) : Dictionary<number, number> {
|
|
1059
|
-
if (chars === null || chars === undefined) {
|
|
1060
|
-
throw new Error('Argument Null Exception : chars');
|
|
1061
|
-
}
|
|
1062
|
-
let dictionary : Dictionary<number, number> = new Dictionary<number, number>();
|
|
1063
|
-
let charKeys : string[] = chars.keys();
|
|
1064
|
-
for (let i : number = 0; i < charKeys.length; i++) {
|
|
1065
|
-
let ch : string = charKeys[i];
|
|
1066
|
-
let glyph : TtfGlyphInfo = this.getGlyph(ch);
|
|
1067
|
-
if (!glyph.empty) {
|
|
1068
|
-
dictionary.setValue(glyph.index, ch.charCodeAt(0));
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
return dictionary;
|
|
1072
|
-
}
|
|
1073
|
-
/**
|
|
1074
|
-
* Gets all glyphs.
|
|
1075
|
-
*/
|
|
1076
|
-
public getAllGlyphs() : TtfGlyphInfo[] {
|
|
1077
|
-
let allGlyphInfo : TtfGlyphInfo[] = [];
|
|
1078
|
-
let info : TtfGlyphInfo = new TtfGlyphInfo();
|
|
1079
|
-
let index : number = 0;
|
|
1080
|
-
for (let i : number = 0; i < this.width.length; i++) {
|
|
1081
|
-
let width : number = this.width[i];
|
|
1082
|
-
info.index = index;
|
|
1083
|
-
info.width = width;
|
|
1084
|
-
allGlyphInfo.push(info);
|
|
1085
|
-
index++;
|
|
1086
|
-
}
|
|
1087
|
-
return allGlyphInfo;
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Reads a font's program.
|
|
1091
|
-
* @private
|
|
1092
|
-
*/
|
|
1093
|
-
public readFontProgram(chars : Dictionary<string, string>) : number[] {
|
|
1094
|
-
let glyphChars : Dictionary<number, number> = this.getGlyphChars(chars);
|
|
1095
|
-
let locaTable : TtfLocaTable = this.readLocaTable(this.bIsLocaShort);
|
|
1096
|
-
if (glyphChars.size() < chars.size()) {
|
|
1097
|
-
this.missedGlyphs = chars.size() - glyphChars.size();
|
|
1098
|
-
}
|
|
1099
|
-
this.updateGlyphChars(glyphChars, locaTable);
|
|
1100
|
-
/* tslint:disable */
|
|
1101
|
-
let result1 : { glyphTableSize : number, newLocaTable : number[], newGlyphTable : number[] } = this.generateGlyphTable(glyphChars, locaTable, null, null);
|
|
1102
|
-
/* tslint:enable */
|
|
1103
|
-
let glyphTableSize : number = result1.glyphTableSize;
|
|
1104
|
-
let newLocaTable : number[] = result1.newLocaTable;
|
|
1105
|
-
let newGlyphTable : number[] = result1.newGlyphTable;
|
|
1106
|
-
let result2 : { newLocaUpdated : number[], newLocaSize : number } = this.updateLocaTable(newLocaTable, this.bIsLocaShort, null);
|
|
1107
|
-
let newLocaSize : number = result2.newLocaSize;
|
|
1108
|
-
let newLocaUpdated : number[] = result2.newLocaUpdated;
|
|
1109
|
-
let fontProgram : number[] = this.getFontProgram(newLocaUpdated, newGlyphTable, glyphTableSize, newLocaSize);
|
|
1110
|
-
return fontProgram;
|
|
1111
|
-
}
|
|
1112
|
-
/**
|
|
1113
|
-
* Reconverts string to be in proper format saved into PDF file.
|
|
1114
|
-
*/
|
|
1115
|
-
public convertString(text : string) : string {
|
|
1116
|
-
if (text === null) {
|
|
1117
|
-
throw new Error('Argument Null Exception : text');
|
|
1118
|
-
}
|
|
1119
|
-
let glyph : string = '';
|
|
1120
|
-
let i : number = 0;
|
|
1121
|
-
for (let k : number = 0; k < text.length; k++) {
|
|
1122
|
-
let ch : string = text[k];
|
|
1123
|
-
let glyphInfo : TtfGlyphInfo = this.getGlyph(ch);
|
|
1124
|
-
if (!glyphInfo.empty) {
|
|
1125
|
-
glyph += String.fromCharCode(glyphInfo.index);
|
|
1126
|
-
i++;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
return glyph;
|
|
1130
|
-
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Gets char width.
|
|
1133
|
-
*/
|
|
1134
|
-
public getCharWidth(code : string) : number {
|
|
1135
|
-
let glyphInfo : TtfGlyphInfo = this.getGlyph(code);
|
|
1136
|
-
glyphInfo = (!glyphInfo.empty) ? glyphInfo : this.getDefaultGlyph();
|
|
1137
|
-
let codeWidth : number = (!glyphInfo.empty) ? glyphInfo.width : 0;
|
|
1138
|
-
return codeWidth;
|
|
1139
|
-
}
|
|
1140
|
-
//Stream reader
|
|
1141
|
-
private readString(length : number) : string
|
|
1142
|
-
private readString(length : number, isUnicode : boolean) : string
|
|
1143
|
-
private readString(length : number, isUnicode ?: boolean) : string {
|
|
1144
|
-
if (isUnicode === undefined) {
|
|
1145
|
-
return this.readString(length, false);
|
|
1146
|
-
} else {
|
|
1147
|
-
//let buffer : number[] = this.readBytes(length);
|
|
1148
|
-
let result : string = '';
|
|
1149
|
-
if (isUnicode) {
|
|
1150
|
-
for (let i : number = 0; i < length; i++) {
|
|
1151
|
-
if (i % 2 !== 0) {
|
|
1152
|
-
result += String.fromCharCode(this.fontData[this.offset]);
|
|
1153
|
-
}
|
|
1154
|
-
this.offset += 1;
|
|
1155
|
-
}
|
|
1156
|
-
} else {
|
|
1157
|
-
for (let i : number = 0; i < length; i++) {
|
|
1158
|
-
result += String.fromCharCode(this.fontData[this.offset]);
|
|
1159
|
-
this.offset += 1;
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
return result;
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
private readFixed(offset : number) : number {
|
|
1166
|
-
let integer : number = this.readInt16(offset);
|
|
1167
|
-
let sFraction : number = this.readInt16(offset + 2);
|
|
1168
|
-
let fraction : number = sFraction / 16384;
|
|
1169
|
-
return integer + fraction;
|
|
1170
|
-
}
|
|
1171
|
-
private readInt32(offset : number) : number {
|
|
1172
|
-
let i1 : number = this.fontData[offset + 3];
|
|
1173
|
-
let i2 : number = this.fontData[offset + 2];
|
|
1174
|
-
let i3 : number = this.fontData[offset + 1];
|
|
1175
|
-
let i4 : number = this.fontData[offset];
|
|
1176
|
-
this.offset += 4;
|
|
1177
|
-
return i1 + (i2 << 8) + (i3 << 16) + (i4 << 24);
|
|
1178
|
-
}
|
|
1179
|
-
private readUInt32(offset : number) : number {
|
|
1180
|
-
let i1 : number = this.fontData[offset + 3];
|
|
1181
|
-
let i2 : number = this.fontData[offset + 2];
|
|
1182
|
-
let i3 : number = this.fontData[offset + 1];
|
|
1183
|
-
let i4 : number = this.fontData[offset];
|
|
1184
|
-
this.offset += 4;
|
|
1185
|
-
return (i1 | i2 << 8 | i3 << 16 | i4 << 24);
|
|
1186
|
-
}
|
|
1187
|
-
// private readInt16(offset : number) : number {
|
|
1188
|
-
// let result : number = (this.fontData[offset] << 8) + this.fontData[offset + 1];
|
|
1189
|
-
// this.offset += 2;
|
|
1190
|
-
// return result;
|
|
1191
|
-
// }
|
|
1192
|
-
private readInt16(offset : number) : number {
|
|
1193
|
-
let result : number = (this.fontData[offset] << 8) + this.fontData[offset + 1];
|
|
1194
|
-
result = result & (1 << 15) ? result - 0x10000 : result;
|
|
1195
|
-
this.offset += 2;
|
|
1196
|
-
return result;
|
|
1197
|
-
}
|
|
1198
|
-
private readInt64(offset : number) : number {
|
|
1199
|
-
let low : number = this.readInt32(offset + 4);
|
|
1200
|
-
let n : number = this.readInt32(offset) * 4294967296.0 + low;
|
|
1201
|
-
if (low < 0) {
|
|
1202
|
-
n += 4294967296;
|
|
1203
|
-
}
|
|
1204
|
-
return n;
|
|
1205
|
-
}
|
|
1206
|
-
private readUInt16(offset : number) : number {
|
|
1207
|
-
let result : number = (this.fontData[offset] << 8) | this.fontData[offset + 1];
|
|
1208
|
-
this.offset += 2;
|
|
1209
|
-
return result;
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Reads ushort array.
|
|
1213
|
-
*/
|
|
1214
|
-
private readUshortArray(length : number) : number[] {
|
|
1215
|
-
let buffer : number[] = [];
|
|
1216
|
-
for (let i : number = 0; i < length; i++) {
|
|
1217
|
-
buffer[i] = this.readUInt16(this.offset);
|
|
1218
|
-
}
|
|
1219
|
-
return buffer;
|
|
1220
|
-
}
|
|
1221
|
-
private readBytes(length : number) : number[] {
|
|
1222
|
-
let result : number[] = [];
|
|
1223
|
-
for (let i : number = 0; i < length; i++) {
|
|
1224
|
-
result.push(this.fontData[this.offset]);
|
|
1225
|
-
this.offset += 1;
|
|
1226
|
-
}
|
|
1227
|
-
return result;
|
|
1228
|
-
}
|
|
1229
|
-
private readByte(offset : number) : number {
|
|
1230
|
-
let result : number = this.fontData[offset];
|
|
1231
|
-
this.offset += 1;
|
|
1232
|
-
return result;
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Reads bytes to array in BigEndian order.
|
|
1236
|
-
* @private
|
|
1237
|
-
*/
|
|
1238
|
-
public read(buffer : number[], index : number, count : number) : { buffer : number[], written : number } {
|
|
1239
|
-
if (buffer === null) {
|
|
1240
|
-
throw new Error('Argument Null Exception : buffer');
|
|
1241
|
-
}
|
|
1242
|
-
let written : number = 0;
|
|
1243
|
-
let read : number = 0;
|
|
1244
|
-
do {
|
|
1245
|
-
for (let i : number = 0; (i < count - written) && (this.offset + i < this.fontData.length); i++) {
|
|
1246
|
-
buffer[index + i] = this.fontData[this.offset + i];
|
|
1247
|
-
}
|
|
1248
|
-
read = count - written;
|
|
1249
|
-
this.offset += read;
|
|
1250
|
-
written += read;
|
|
1251
|
-
} while (written < count);
|
|
1252
|
-
return { buffer : buffer, written : written };
|
|
1253
|
-
}
|
|
1254
|
-
}
|