-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_ArabicSimplify.js
210 lines (186 loc) · 6.8 KB
/
RS_ArabicSimplify.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//================================================================
// RS_ArabicSimplify.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2019 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @target MV
* @plugindesc This plugin is possible to show up Arabic text simplify. <RS_ArabicSimplify>
* @author biud436
*
* @param Message Mode
* @type select
* @desc this parameter sets up the text direction.
* default : arabic
* @default arabic
* @option Arabic Mode
* @value arabic
* @option Normal Mode
* @value normal
*
* @param Arabic Font
* @desc Choose your font that can indicate Arabic text from your system font folder.
* @default Simplified Arabic, Times New Roman, Segoe UI
*
* @help
* ============================================================================
* Introduction
* ============================================================================
* There is no a flip layer because is compatibility issue.
*
* ============================================================================
* Plugin Commands
* ============================================================================
*
* This plugin command changes with the mode for Arabic.
*
* ArabicMessageMode
*
* This plugin command changes with normal mode.
*
* NormalMessageMode
*
* ============================================================================
* Version Log
* ============================================================================
* 2019.06.03 (v1.0.0) - First Release.
*/
(() => {
let parameters = $plugins.filter(i => {
return i.description.contains('<RS_ArabicSimplify>');
});
const RS = window.RS || {};
RS.ArabicSimplify = RS.ArabicSimplify || {};
parameters = parameters.length > 0 && parameters[0].parameters;
RS.ArabicSimplify.Params = {};
RS.ArabicSimplify.Params.messageMode = String(
parameters['Message Mode'] || 'arabic'
);
RS.ArabicSimplify.Params.arabicFont = String(
parameters['Arabic Font'] ||
'Simplified Arabic, Times New Roman, Segoe UI'
);
//============================================================================
// ArabicUtils
//============================================================================
function ArabicUtils() {
throw new Error('This is a static class');
}
ArabicUtils.LEFT_TO_RIGHT_EMBEDDING = '\u202A';
ArabicUtils.RIGHT_TO_LEFT_EMBEDDING = '\u202B';
ArabicUtils.POP_DIRECTIONAL_FORMATTING = '\u202C';
ArabicUtils.LEFT_TO_RIGHT_OVERRIDE = '\u202D';
ArabicUtils.RIGHT_TO_LEFT_OVERRIDE = '\u202E';
ArabicUtils.LEFT_TO_RIGHT_ISOLATE = '\u2066';
ArabicUtils.RIGHT_TO_LEFT_ISOLATE = '\u2067';
ArabicUtils.FIRST_STRONG_ISOLATE = '\u2068';
ArabicUtils.POP_DIRECTIONAL_ISOLATE = '\u2069';
ArabicUtils.isArabic = function (text) {
const pattern =
/[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFD\uFE70-\uFEFF\u10E600-\u10E7E\u1EE00-\u1EEFF]/;
return pattern.test(text);
};
ArabicUtils.makeText = function (text) {
return String(ArabicUtils.RIGHT_TO_LEFT_EMBEDDING + text);
};
//============================================================================
// Window_Base
//============================================================================
const alias_Bitmap_drawText = Bitmap.prototype.drawText;
Bitmap.prototype.drawText = function (
text,
x,
y,
maxWidth,
lineHeight,
align
) {
if (
RS.ArabicSimplify.Params.messageMode === 'arabic' &&
ArabicUtils.isArabic(text)
) {
text = ArabicUtils.makeText(text);
}
alias_Bitmap_drawText.call(
this,
text,
x,
y,
maxWidth,
lineHeight,
align
);
};
//============================================================================
// Window_Base
//============================================================================
const alias_Window_Base_standardFontFace =
Window_Base.prototype.standardFontFace;
Window_Base.prototype.standardFontFace = function () {
if (
RS.ArabicSimplify.Params.messageMode === 'arabic' ||
navigator.language.match(/^ar/)
) {
return RS.ArabicSimplify.Params.arabicFont;
}
return alias_Window_Base_standardFontFace.call(this);
};
const alias_Window_Base_processNormalCharacter =
Window_Base.prototype.processNormalCharacter;
Window_Base.prototype.processNormalCharacter = function (textState) {
if (RS.ArabicSimplify.Params.messageMode !== 'arabic') {
return alias_Window_Base_processNormalCharacter.call(
this,
textState
);
}
const allLines = textState.text
.slice(textState.index++)
.split(/[\r\n]+/);
const currentLine = allLines[0] || '';
const [currentText] = currentLine.split('\x1b');
textState.index += currentText.length - 1;
const c = currentText;
const w = this.textWidth(c);
this.contents.drawText(
c,
textState.x,
textState.y,
w * 2,
textState.height
);
textState.x += w;
return c;
};
//============================================================================
// Window_Message
//============================================================================
const alias_Window_Message_standardFontFace =
Window_Message.prototype.standardFontFace;
Window_Message.prototype.standardFontFace = function () {
if (
RS.ArabicSimplify.Params.messageMode === 'arabic' ||
navigator.language.match(/^ar/)
) {
return RS.ArabicSimplify.Params.arabicFont;
}
return alias_Window_Message_standardFontFace.call(this);
};
//============================================================================
// Game_Interpreter
//============================================================================
const alias_Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'ArabicMessageMode') {
RS.ArabicSimplify.Params.messageMode = true;
}
if (command === 'NormalMessageMode') {
RS.ArabicSimplify.Params.messageMode = false;
}
};
})();