Skip to content

Commit

Permalink
Implement RTL language support
Browse files Browse the repository at this point in the history
  • Loading branch information
soimy committed Jan 7, 2018
1 parent a1e4f10 commit f4bc573
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
33 changes: 33 additions & 0 deletions assets/charset/charset.persian.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ببب ب
تتت ت
ضضض ض
صصص ص
ثثث ث
ققق ق
ففف ف
غغغ غ
ععع ع
ههه ه
خخخ خ
ححح ح
ججج ج
چچچ چ
ششش ش
سسس س
ییی ئ ی ي
ببب ب
للل ل
اآ
ننن ن
ممم م
ککک ک
گگگ گ
ظظظ ظ
ططط ط
زرژ
و
ذد
پپپ پ
َُِّ
":><؟{}|+_()&*!@#$%×÷÷`|;'[].,/\،-=
12345567890
Binary file added assets/fonts/Iransans.ttf
Binary file not shown.
2 changes: 2 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ args
.option(' --smart-size', 'shrink atlas to the smallest possible square (Default: false)', false)
.option(' --pot', 'atlas size shall be power of 2 (Default: false)', false)
.option(' --square', 'atlas size shall be square (Default: false)', false)
.option(' --rtl', 'use RTL charators fix (Default: false)', false)
.action(function(file){
fontFile = fileExistValidate(file);
}).parse(process.argv);
Expand Down Expand Up @@ -57,6 +58,7 @@ opt.reuse = utils.valueQueue([opt.reuse, false]);
opt.smartSize = utils.valueQueue([opt.smartSize, false]);
opt.pot = utils.valueQueue([opt.pot, false]);
opt.square = utils.valueQueue([opt.square, false]);
opt.rtl = utils.valueQueue([opt.rtl, false]);

//
// Display options
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const utils = require('./lib/utils');
const reshaper = require('arabic-persian-reshaper');
const opentype = require('opentype.js');
const exec = require('child_process').exec;
const mapLimit = require('map-limit');
Expand Down Expand Up @@ -36,6 +37,7 @@ module.exports = generateBMFont;
* smartSize : shrink atlas to the smallest possible square (Default: false)
* pot : atlas size shall be power of 2 (Default: false)
* square : atlas size shall be square (Default: false)
* rtl : use RTL charators fix (Default: false)
* @param {function(string, Array.<Object>, Object)} callback - Callback funtion(err, textures, font)
*
*/
Expand Down Expand Up @@ -79,7 +81,6 @@ function generateBMFont (fontPath, opt, callback) {
reuse = cfg.opt;
}
} else reuse = {};
let charset = opt.charset = (typeof opt.charset === 'string' ? opt.charset.split('') : opt.charset) || reuse.charset || defaultCharset;
const outputType = opt.outputType = utils.valueQueue([opt.outputType, reuse.outputType, "xml"]);
let filename = utils.valueQueue([opt.filename, reuse.filename]);
const fontSize = opt.fontSize = utils.valueQueue([opt.fontSize, reuse.fontSize, 42]);
Expand All @@ -96,7 +97,9 @@ function generateBMFont (fontPath, opt, callback) {
const square = opt.square = utils.valueQueue([opt.square, reuse.square, false]);
const debug = opt.vector || false;
const tolerance = opt.tolerance = utils.valueQueue([opt.tolerance, reuse.tolerance, 0]);
// const cfg = typeof opt.reuse === 'boolean' ? opt.reuse : false;
const isRTL = opt.rtl = utils.valueQueue([opt.rtl, reuse.rtl, false]);
if (isRTL) opt.charset = require('arabic-persian-reshaper').convertArabic(opt.charset);
let charset = opt.charset = (typeof opt.charset === 'string' ? Array.from(opt.charset) : opt.charset) || reuse.charset || defaultCharset;

// TODO: Validate options
if (fieldType !== 'msdf' && fieldType !== 'sdf' && fieldType !== 'psdf') {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"license": "MIT",
"dependencies": {
"arabic-persian-reshaper": "^1.0.0",
"canvas-prebuilt": "^1.6.5-prerelease.1",
"cli-progress": "^1.7.0",
"commander": "^2.12.2",
Expand Down

0 comments on commit f4bc573

Please sign in to comment.