| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 | 1×
1×
1×
1×
10×
10×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "./../../primitives/pdf-string", "./rtl/rtl-text-shape", "./../enum", "./rtl/rtl-bidirectional"], function (require, exports, pdf_string_1, rtl_text_shape_1, enum_1, rtl_bidirectional_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var RtlRenderer = (function () {
function RtlRenderer() {
this.openBracket = '(';
this.closeBracket = ')';
}
RtlRenderer.prototype.layout = function (line, font, rtl, wordSpace, format) {
if (line == null) {
throw new Error('ArgumentNullException : line');
}
if (font == null) {
throw new Error('ArgumentNullException : font');
}
var result = [];
if (font.Unicode) {
result = this.customLayout(line, rtl, format, font, wordSpace);
}
else {
result = [];
result[0] = line;
}
return result;
};
RtlRenderer.prototype.splitLayout = function (line, font, rtl, wordSpace, format) {
if (line == null) {
throw new Error('ArgumentNullException : line');
}
if (font == null) {
throw new Error('ArgumentNullException : font');
}
var words = [];
var system = false;
if (!system || words == null) {
words = this.customSplitLayout(line, font, rtl, wordSpace, format);
}
return words;
};
RtlRenderer.prototype.getGlyphIndex = function (line, font, rtl, glyphs, custom) {
var success = true;
var fail = false;
if (line == null) {
throw new Error('ArgumentNullException : line');
}
if (font == null) {
throw new Error('ArgumentNullException : font');
}
glyphs = null;
if (line.length === 0) {
return { success: fail, glyphs: glyphs };
}
var renderer = new rtl_text_shape_1.ArabicShapeRenderer();
var text = renderer.shape(line, 0);
var internalFont = font.fontInternal;
var ttfReader = internalFont.ttfReader;
glyphs = new Uint16Array(text.length);
var i = 0;
for (var k = 0, len = text.length; k < len; k++) {
var ch = text[k];
var glyphInfo = ttfReader.getGlyph(ch);
if (glyphInfo !== null && typeof glyphInfo !== 'undefined') {
glyphs[i++] = (glyphInfo).index;
}
}
return { success: success, glyphs: glyphs };
};
RtlRenderer.prototype.customLayout = function (line, rtl, format, font, wordSpace) {
if (wordSpace === null || typeof wordSpace === 'undefined') {
if (line == null) {
throw new Error('ArgumentNullException : line');
}
var result = null;
if (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_1.PdfTextDirection.None) {
var bidi = new rtl_bidirectional_1.Bidi();
result = bidi.getLogicalToVisualString(line, rtl);
}
return result;
}
else {
if (line == null) {
throw new Error('ArgumentNullException : line');
}
if (font == null) {
throw new Error('ArgumentNullException : font');
}
var layouted = null;
if (format !== null && typeof format !== 'undefined' && format.textDirection !== enum_1.PdfTextDirection.None) {
var renderer = new rtl_text_shape_1.ArabicShapeRenderer();
var txt = renderer.shape(line, 0);
layouted = this.customLayout(txt, rtl, format);
}
var result = [];
if (wordSpace) {
var words = layouted.split('');
var count = words.length;
for (var i = 0; i < count; i++) {
words[i] = this.addChars(font, words[i]);
}
result = words;
}
else {
result = [];
result[0] = this.addChars(font, layouted);
}
return result;
}
};
RtlRenderer.prototype.addChars = function (font, glyphs) {
var line = glyphs;
if (font == null) {
throw new Error('ArgumentNullException : font');
}
if (line == null) {
throw new Error('ArgumentNullException : line');
}
var text = line;
var internalFont = font.fontInternal;
var ttfReader = internalFont.ttfReader;
font.setSymbols(text);
text = ttfReader.convertString(text);
var bytes = pdf_string_1.PdfString.toUnicodeArray(text, false);
text = pdf_string_1.PdfString.byteToString(bytes);
return text;
};
RtlRenderer.prototype.customSplitLayout = function (line, font, rtl, wordSpace, format) {
if (line == null) {
throw new Error('ArgumentNullException : line');
}
if (font == null) {
throw new Error('ArgumentNullException : font');
}
var reversedLine = this.customLayout(line, rtl, format);
var words = reversedLine.split('');
return words;
};
return RtlRenderer;
}());
exports.RtlRenderer = RtlRenderer;
});
|