Skip to content

Commit

Permalink
Support IVS Font
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyxuan committed Jun 2, 2021
1 parent 310bc8f commit bb48ecf
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 jeffreyxuan
Copyright (c) 2021 jeffreyxuan, https://toneoz.com/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 20 additions & 0 deletions LICENSE-jQuery-MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2006 John Resig, http://jquery.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file added screenshot/toneozdic_20210601-14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/tzdic/tzdata/1.js

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

2 changes: 1 addition & 1 deletion web/tzdic/tzdata/tzdicidx.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
window.tzdicidx = {"":1,"":1,"th":1,"vo":1,"of":1,"jo":1,"":1,"":1,"":1};
window.tzdicidx = {"jo":1,"of":1,"th":1,"vo":1,"":1,"":1,"":1,"":1,"":1};
17 changes: 13 additions & 4 deletions web/tzdic/tzdicui.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if(!window.tzdicidx){
}

function TZDicUI(){
let thisObj = this;
// ToneOZDic Parameters
let tzparam = {
objInput : null
Expand All @@ -34,6 +35,8 @@ function TZDicUI(){
// Custeom lookup table to specify the IVS fonts (Ideographic Variation Sequences) displayed in the dictionary entry iframe
, strCssIframe : tzstrCssIframe
// Custom css object to decorate the objIframe outter position
, intMaxPhrase : 16
// Max phrases per query
, strVer : ""
// Version control string
};
Expand Down Expand Up @@ -73,10 +76,13 @@ function TZDicUI(){

// events init
tzparam.objInput.on('input selectionchange propertychange keydown click focus', function(event) {
tzUpdateEvent({event:event});
thisObj.tzUpdateEvent({event:event});
});
tzparam.objInput.on('DOMSubtreeModified', function(event) {
thisObj.tzUpdateEvent({event:event});
});
$(document).on('mouseup', function(event) {
tzUpdateEvent({event:event});
thisObj.tzUpdateEvent({event:event});
});

return tzparam;
Expand All @@ -99,7 +105,7 @@ function TZDicUI(){
}

let tmrUpdateEvent = null;
window.tzUpdateEvent = function(dicParam){
this.tzUpdateEvent = function(dicParam){
if(tmrUpdateEvent){
clearTimeout(tmrUpdateEvent);
tmrUpdateEvent = null;
Expand Down Expand Up @@ -154,9 +160,12 @@ function TZDicUI(){
// get query parameters for ToneOZDic
for(let idxPhrase in phrases){
let phrase = phrases[idxPhrase];
if(qArray.length >= tzparam.intMaxPhrase){
break;
}
qArray.push(GetQuery({
phrase : phrase
}));
}));
}

let dicURLParam = JSON.stringify(qArray);
Expand Down
40 changes: 32 additions & 8 deletions web/tzdic/tzlib/tzdicentry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// BEGIN CONFIG /////////
// Folder path of the dictionary files
const defaultDataFolder = "./tzdata/";
// Max phrases per query
const intMaxPhrase = 16;
// END CONFIG /////////
const vsbase = 0xe01e0;
let tzQuery, tzQueryArray, tzCss, tzIvsPosDic;
let tzQuery, tzQueryArray, tzCss, tzIvsPosDic, tzVer;
let winSearch = window.location.search;
if(!window.tzdic){
window.tzdic = {};
Expand All @@ -12,19 +15,23 @@ if(winSearch){
tzQuery = urlParams.get("q");
tzCss = urlParams.get("css");
tzIvsPosDic = urlParams.get("ivs");
tzVer = urlParams.get("v");
tzVer = (tzVer?"?v="+tzVer:"");
tzQueryArray = JSON.parse(tzQuery);
if(tzCss){
document.write('<link rel="stylesheet" href="'+tzCss+'" />');
document.write('<link rel="stylesheet" href="'+tzCss + tzVer +'" />');
}
if(tzIvsPosDic){
document.write('<script type="text/javascript" src="' +tzIvsPosDic+'">\x3C/script>');
document.write('<script type="text/javascript" src="' +tzIvsPosDic
+ tzVer + '">\x3C/script>');
}
if(tzQueryArray){
for(let qIdx in tzQueryArray){
if(tzQueryArray[qIdx].id){
document.write('<script type="text/javascript" src="'
+ defaultDataFolder
+ (""+tzQueryArray[qIdx].id)+'.js">\x3C/script>');
+ (""+tzQueryArray[qIdx].id)+'.js'
+ tzVer + '">\x3C/script>');
}
}
}
Expand All @@ -38,14 +45,14 @@ $(document).ready(function () {
window.ivsdic = null;
}
if(tzdic){
for(let qIdx in tzQueryArray){
let isPrevIVSCtl = false;
for(let qIdx=0; qIdx<tzQueryArray.length; qIdx++){
let item = tzQueryArray[qIdx];
let dicSlot = null;
if(item.id){
dicSlot = ""+item.id;
}
if(item.q){
let unsortPoyinArray = [];
for(let pi = 0; pi < poyinMaxCount; pi++){
// lookup each poyin option
let posfix = "";
Expand All @@ -57,11 +64,21 @@ $(document).ready(function () {
let qarray = null;
let yinarray = null;
let noivs = removeIVS(item.q);
if(item.q && !noivs){
isPrevIVSCtl = true;
break;;
}
if(isPrevIVSCtl){
isPrevIVSCtl = false;
if(HasIvsPair(item.q)){
break;
}
}
// check is the dictionary data tzdata loaded
if(tzdic[dicSlot]){
// dictionary lookup
result = tzdic[dicSlot][noivs+posfix];
if(ivsdic){
if(result && ivsdic){
qarray = noivs.split("");
if(result && result.z){
yinarray = result.z.split(new RegExp(separators.join('|'), 'g'));
Expand Down Expand Up @@ -95,7 +112,10 @@ $(document).ready(function () {
.append(dDom);
}
}
}
}
}
if(qIdx >= intMaxPhrase-1){
break;
}
}
}
Expand Down Expand Up @@ -125,6 +145,10 @@ function removeIVS(q){
return noivs;
}

function HasIvsPair(q){
return q.match(/([\ud800-\udfff])/g);
}

function chr(uni) {
if (String.fromCodePoint) return String.fromCodePoint(uni); // ES6
if (uni <= 0xffff) return String.fromCharCode(uni);
Expand Down

0 comments on commit bb48ecf

Please sign in to comment.