Skip to content

Commit

Permalink
fix(util.breakText): take in account international characters (#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKanera authored Nov 6, 2023
1 parent 8d3a09f commit c314a3d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ export const breakText = function(text, size, styles = {}, opt = {}) {
// If separator is a RegExp, we use the space character to join words together again (not ideal)
const separatorChar = (typeof separator === 'string') ? separator : space;
var eol = opt.eol || '\n';
var hyphen = opt.hyphen ? new RegExp(opt.hyphen) : /[^\w\d]/;
var hyphen = opt.hyphen ? new RegExp(opt.hyphen) : /[^\w\d\u00C0-\u1FFF\u2800-\uFFFD]/;
var maxLineCount = opt.maxLineCount;
if (!isNumber(maxLineCount)) maxLineCount = Infinity;

Expand Down
73 changes: 73 additions & 0 deletions test/jointjs/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,79 @@ QUnit.module('util', function(hooks) {

assert.notOk(r.includes(NO_SPACE));
});

QUnit.test('takes in account international characters', function(assert) {
const size = { width: 100 };

const tests = [
'אבגדהוזחטיכ-למנסעפצ-קרשת',
'აბგდ-ევზთიკ-ლმნოპჟრსტუფქ-ღყშჩცძწ-ჭხჯჰ',
'ԱԲԳ-ԴԵԶԷԸԹԺԻԼ-ԽԾԿՀՁՂՃՄՅՆՇՈՉ-ՊՋՌՍՎՏՐՑ-ՒՓՔՕՖ',
'АБВГ-ДЕЁЖЗИЙКЛМ-НОПР-СТУФХЦ-ЧШЩЪЫ-ЬЭЮЯ',
'กขฃคฅ-ฆงจฉชซฌญฎ-ฏฐฑฒณดตถทธนบปผฝ-พฟภมยรลว-ศษสหฬอฮ',
'अआइई-उऊऋऌऍऎएऐऑऒओऔक-खगघङचछ-जझञटठडढणतथदधन-पफबभमयरलवशषसह',
'ሀሁሂ-ሃሄህሆለሉሊላሌልሎሏ-ሐሑሒሓሔሕሖሗመ-ሙሚማሜምሞሟ-ሠሡሢሣሤሥሦሧ',
'ا ب- ت -ث ج ح خ د ذ ر ز س ش- ص ض ط ظ ع غ ف- ق ك ل م -ن ه و ي',
'ĀāĂă-ĄąĆćĈĉĊċ-ČčĎďĐđĒēĔĕĖėĘę',
'ĚěĜĝ-ĞğĠġĢ-ģĤĥĦħĨĩĪīĬĭĮįİ',
'ıIJijĴ-ĵĶķĸĹĺ-ĻļĽľĿŀŁł',
'ŃńŅņ-ŇňʼnŊŋŌōŎŏŐőŒœŔ',
'ŕŖŗŘ-řŚśŜŝŞ-şŠšŢţŤťŦŧ',
'ŨũŪū-ŬŭŮůŰű-ŲųŴŵŶŷŸŹźŻż',
'Žžſƀ-ƁƂƃƄ-ƅƆƇƈƉƊ-ƋƌƍƎƏ',
'ƐƑƒƓ-ƔƕƖƗƘƙ-ƚƛƜƝƞƟ',
'ƠơƢƣ-ƤƥƦƧƨƩ-ƪƫƬƭƮƯ',
'ưƱƲƳ-ƴƵƶƷƸ-ƹƺƻƼƽƾƿ',
'ǀǁǂǃ-DŽDždžLJLjljNJNjnjǍǎǏ',
'ǐǑǒǓ-ǔǕǖǗǘǙǚǛ-ǜǝǞǟ',
'ǠǡǢǣ-ǤǥǦǧǨǩǪǫ-ǬǭǮǯ',
'ǰDZDzdz-ǴǵǶǷǸǹǺǻǼǽǾǿ',
'ȀȁȂȃ-ȄȅȆȇȈ-ȉȊȋȌȍȎȏ',
'ȐȑȒȓ-ȔȕȖȗȘ-șȚțȜȝȞȟ',
'ΑΒΓΔ-ΕΖΗΘΙΚ-ΛΜΝΞΟΠΡΣΤ-ΥΦΧΨΩ',
'あい-うえおかきくけ-こさしすせそたちつてと-なにぬねのはひふへほまみむめもやゆよらりるれろわをんぁ-ぃぅぇぉっゃゅょゎ',
'アイ-ウエオカキクケコサ-シスセソタチツテトナニヌネノハ-ヒフヘホマミムメモヤユヨラ-リルレロワヰヱヲンヴァィ-ゥェォッャュョー',
'ㄱㄴㄷ-ㄹㅁㅂㅅㅇㅈㅊㅋ-ㅌㅍㅎㅏㅑㅓㅕㅗㅛㅜㅠㅡㅣ',
'円山川-川口町村市区京大学乳水牛車自転車電車飛行機船航空宇宙駅道路-橋横断歩道交差点信号標-識地図国県市町村庁銀行郵便-局病院公園図書館博-物館美術館劇場映画館遊び場商店店舗-商品買物料理食事料理料理人調理食器鍋皿箸包丁'
];

const results = [
'אבגדהוזחטיכ-\nלמנסעפצ-קרשת',
'აბგდ-\nევზთიკ-\nლმნოპჟრსტუფქ-\nღყშჩცძწ-ჭხჯჰ',
'ԱԲԳ-\nԴԵԶԷԸԹԺԻԼ-\nԽԾԿՀՁՂՃՄՅՆՇՈ\nՉ-\nՊՋՌՍՎՏՐՑ-\nՒՓՔՕՖ',
'АБВГ-\nДЕЁЖЗИЙКЛМ-\nНОПР-\nСТУФХЦ-\nЧШЩЪЫ-ЬЭЮЯ',
'กขฃคฅ-\nฆงจฉชซฌญฎ-\nฏฐฑฒณดตถทธนบปผ\nฝ-\nพฟภมยรลว-\nศษสหฬอฮ',
'अआइई-\nउऊऋऌऍऎएऐऑऒओ\nऔक-\nखगघङचछ-\nजझञटठडढणतथदधन\n-पफबभमयरलवशषस\nह',
'ሀሁሂ-\nሃሄህሆለሉሊላሌል\nሎሏ-\nሐሑሒሓሔሕሖ\nሗመ-\nሙሚማሜምሞሟ\n-ሠሡሢሣሤሥሦ\nሧ',
'ا ب- ت -ث ج ح\nخ د ذ ر ز س\nش- ص ض ط ظ ع\nغ ف- ق ك ل م\n-ن ه و ي',
'ĀāĂă-\nĄąĆćĈĉĊċ-\nČčĎďĐđĒēĔĕĖėĘ\nę',
'ĚěĜĝ-\nĞğĠġĢ-\nģĤĥĦħĨĩĪīĬĭĮį\nİ',
'ıIJijĴ-\nĵĶķĸĹĺ-\nĻļĽľĿŀŁł',
'ŃńŅņ-\nŇňʼnŊŋŌōŎŏŐőŒœ\nŔ',
'ŕŖŗŘ-\nřŚśŜŝŞ-\nşŠšŢţŤťŦŧ',
'ŨũŪū-\nŬŭŮůŰű-\nŲųŴŵŶŷŸŹźŻż',
'Žžſƀ-\nƁƂƃƄ-ƅƆƇƈƉƊ-ƋƌƍƎƏ',
'ƐƑƒƓ-\nƔƕƖƗƘƙ-ƚƛƜƝƞƟ',
'ƠơƢƣ-\nƤƥƦƧƨƩ-ƪƫƬƭƮƯ',
'ưƱƲƳ-\nƴƵƶƷƸ-ƹƺƻƼƽƾƿ',
'ǀǁǂǃ-\nDŽDždžLJLjljNJNjnjǍǎǏ',
'ǐǑǒǓ-\nǔǕǖǗǘǙǚǛ-ǜǝǞǟ',
'ǠǡǢǣ-\nǤǥǦǧǨǩǪǫ-ǬǭǮǯ',
'ǰDZDzdz-\nǴǵǶǷǸǹǺǻǼǽǾǿ',
'ȀȁȂȃ-\nȄȅȆȇȈ-ȉȊȋȌȍȎȏ',
'ȐȑȒȓ-\nȔȕȖȗȘ-șȚțȜȝȞȟ',
'ΑΒΓΔ-\nΕΖΗΘΙΚ-\nΛΜΝΞΟΠΡΣΤ-\nΥΦΧΨΩ',
'あい-\nうえおかきくけ-\nこさしすせそたち\nつてと-\nなにぬねのはひふ\nへほまみむめもや\nゆよらりるれろわ\nをんぁ-\nぃぅぇぉっゃゅょ\nゎ',
'アイ-\nウエオカキクケコ\nサ-\nシスセソタチツテ\nトナニヌネノハ-\nヒフヘホマミムメ\nモヤユヨラ-\nリルレロワヰヱヲ\nンヴァィ-\nゥェォッャュョー',
'ㄱㄴㄷ-\nㄹㅁㅂㅅㅇㅈㅊㅋ-\nㅌㅍㅎㅏㅑㅓㅕㅗㅛ\nㅜㅠㅡㅣ',
'円山川-\n川口町村市区京大\n学乳水牛車自転車\n電車飛行機船航空\n宇宙駅道路-\n橋横断歩道交差点\n信号標-\n識地図国県市町村\n庁銀行郵便-\n局病院公園図書館\n博-\n物館美術館劇場映\n画館遊び場商店店\n舗-\n商品買物料理食事\n料理料理人調理食\n器鍋皿箸包丁'
];

tests.forEach((test) => {
const r = joint.util.breakText(test, size, styles);
assert.equal(r, results.shift());
});
});
});

QUnit.test('util.parseCssNumeric', function(assert) {
Expand Down

0 comments on commit c314a3d

Please sign in to comment.