diff --git a/src/assets/iconfont/Anton-Regular.ttf b/src/assets/iconfont/Anton-Regular.ttf new file mode 100644 index 0000000..5a582b1 Binary files /dev/null and b/src/assets/iconfont/Anton-Regular.ttf differ diff --git a/src/assets/iconfont/HanaleiFill-Regular.ttf b/src/assets/iconfont/HanaleiFill-Regular.ttf new file mode 100644 index 0000000..b7e94ff Binary files /dev/null and b/src/assets/iconfont/HanaleiFill-Regular.ttf differ diff --git a/src/assets/iconfont/Pacifico-Regular.ttf b/src/assets/iconfont/Pacifico-Regular.ttf new file mode 100644 index 0000000..f85aee0 Binary files /dev/null and b/src/assets/iconfont/Pacifico-Regular.ttf differ diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js index 27f6992..e8c3359 100644 --- a/src/controllers/menuButton.js +++ b/src/controllers/menuButton.js @@ -47,6 +47,16 @@ const menuButton = { "rightclickmenu": null, "submenuhide": null, focus: function($obj, value){ + if($obj.attr("id")=="luckysheet-icon-font-family-menuButton"){ + if (isdatatypemulti(value)["num"]) { + let _locale = locale(); + const locale_fontarray = _locale.fontarray; + value = locale_fontarray[parseInt(value)]; + if(value==null){ + value = this.defualtFont[itemvalue]; + } + } + } $obj.find(".luckysheet-cols-menuitem").find("span.icon").html(""); if(value == null){ $obj.find(".luckysheet-cols-menuitem").eq(0).find("span.icon").html(''); @@ -468,19 +478,19 @@ const menuButton = { let menuButtonId = $(this).attr("id")+"-menuButton"; let $menuButton = $("#"+menuButtonId); if($menuButton.length == 0){ - const locale_fontarray = locale().fontarray; - let itemdata = []; - - for(let a=0;a"+fItem+""; - ret.example = ""; - itemdata.push(ret); - } + // const locale_fontarray = locale().fontarray; + // let itemdata = []; - let itemset = _this.createButtonMenu(itemdata); + // for(let a=0;a"+fItem+""; + // ret.example = ""; + // itemdata.push(ret); + // } + + let itemset = _this.createButtonMenu(_this.fontSelectList); let menu = replaceHtml(_this.menu, {"id": "font-family", "item": itemset, "subclass": "", "sub": ""}); @@ -488,7 +498,7 @@ const menuButton = { $menuButton = $("#"+menuButtonId).width(200); _this.focus($menuButton); - $menuButton.find(".luckysheet-cols-menuitem").click(function(){ + $menuButton.on("click", ".luckysheet-cols-menuitem", function(){ $menuButton.hide(); luckysheetContainerFocus(); @@ -3317,10 +3327,20 @@ const menuButton = { if(isdatatypemulti(foucsStatus)["num"]){ itemvalue = parseInt(foucsStatus); itemname = locale_fontarray[itemvalue]; + + if(itemname==null){ + itemvalue = _this.defualtFont[itemvalue]; + itemname = itemvalue; + if(itemvalue!=null){ + _this.addFontTolist(itemvalue); + } + } } else{ - itemvalue = locale_fontjson[foucsStatus]; - itemname = locale_fontarray[itemvalue]; + itemvalue = foucsStatus; + itemname = foucsStatus; + + _this.addFontTolist(itemvalue); } } @@ -4320,6 +4340,75 @@ const menuButton = { } return style; + }, + fontSelectList:[], + defualtFont:["Times New Roman","Arial","Tahoma","Verdana","微软雅黑","宋体","黑体","楷体","仿宋","新宋体","华文新魏","华文行楷","华文隶书"], + addFontTolist:function(fontName) { + let isNone = true; + for(let a=0;a"+fontName+""; + ret.example = ""; + this.fontSelectList.push(ret); + + let $menuButton = $("#luckysheet-icon-font-family-menuButton"); + let itemset = this.createButtonMenu(this.fontSelectList); + $menuButton.html(itemset); + } + }, + fontInitial:function(fontList) { + let itemdata = []; + const locale_fontarray = locale().fontarray; + for(let a=0;a"+fItem+""; + ret.example = ""; + itemdata.push(ret); + } + + if(fontList!=null){ + for(let a=0;a"+fItem.fontName+""; + ret.example = ""; + itemdata.push(ret); + + if(!document.fonts.check("12px "+fItem.fontName)){ + if(fItem.url){ + const fontface = new FontFace(fItem.fontName, `url(${fItem.url})`); + document.fonts.add(fontface); + fontface.load(); + } + } + } + + document.fonts.ready.then(function() { + // Any operation that needs to be done only after all the fonts + // have finished loading can go here. + console.log("font ready"); + }); + } + + this.fontSelectList = itemdata; } } diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index c5b7994..00d6671 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -27,6 +27,7 @@ import locale from '../locale/locale'; import { renderChartShow } from '../expendPlugins/chart/plugin'; import {changeSheetContainerSize} from './resize'; import {zoomNumberDomBind} from './zoom'; +import menuButton from './menuButton'; const sheetmanage = { generateRandomSheetIndex: function(prefix) { @@ -676,6 +677,8 @@ const sheetmanage = { } } + menuButton.fontInitial(Store.fontList);//initial font + file.data = data; let rowheight = data.length; diff --git a/src/core.js b/src/core.js index 0c2ad85..24a8044 100644 --- a/src/core.js +++ b/src/core.js @@ -38,7 +38,11 @@ let luckysheet = {}; // mount api // luckysheet.api = api; -Object.assign(luckysheet, api); +// Object.assign(luckysheet, api); + +luckysheet = common_extend(api,luckysheet); + + //创建luckysheet表格 luckysheet.create = function (setting) { @@ -56,6 +60,7 @@ luckysheet.create = function (setting) { Store.fullscreenmode = extendsetting.fullscreenmode; Store.lang = extendsetting.lang; //language Store.allowEdit = extendsetting.allowEdit; + Store.fontList = extendsetting.fontList; server.gridKey = extendsetting.gridKey; server.loadUrl = extendsetting.loadUrl; server.updateUrl = extendsetting.updateUrl; diff --git a/src/global/api.js b/src/global/api.js index 965cff0..44a2986 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -152,6 +152,7 @@ export function setCellValue(row, column, value, options = {}) { if(value.m!=null){ curv.m = value.m; } + formula.delFunctionGroup(row, column); setcellvalue(row, column, data, curv);//update text value } for(let attr in value){ @@ -166,6 +167,7 @@ export function setCellValue(row, column, value, options = {}) { data = luckysheetformula.updatecell(row, column, value, false).data;//update formula value or convert inline string html to object } else{ + formula.delFunctionGroup(row, column); setcellvalue(row, column, data, value); } diff --git a/src/global/formula.js b/src/global/formula.js index 5b9c1c9..1ae42be 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -681,8 +681,8 @@ const luckysheetformula = { return; } - if(txt in this.addToCellIndexList){ - return this.addToCellIndexList[txt]; + if(txt in this.cellTextToIndexList){ + return this.cellTextToIndexList[txt]; } let val = txt.split("!"); diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index e2e1bfc..44d60d0 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -198,13 +198,15 @@ function getMeasureText(value, ctx, fontset){ let measureText = ctx.measureText(value), cache = {}; var regu = "^[ ]+$"; var re = new RegExp(regu); - if(measureText.actualBoundingBoxRight==null || re.test(value)){ - cache.width = measureText.width; - } - else{ - //measureText.actualBoundingBoxLeft + - cache.width = measureText.actualBoundingBoxRight; - } + // if(measureText.actualBoundingBoxRight==null || re.test(value)){ + // cache.width = measureText.width; + // } + // else{ + // //measureText.actualBoundingBoxLeft + + // cache.width = measureText.actualBoundingBoxRight; + // } + + cache.width = measureText.width; if(fontset!=null){ ctx.font = fontset; @@ -237,7 +239,7 @@ function getMeasureText(value, ctx, fontset){ cache.actualBoundingBoxDescent *= Store.zoomRatio; cache.actualBoundingBoxAscent *= Store.zoomRatio; Store.measureTextCache[value + "_" + Store.zoomRatio + "_" + ctx.font] = cache; - + // console.log(measureText, value); return cache; } } diff --git a/src/index.html b/src/index.html index 0399b7c..fe0eb44 100644 --- a/src/index.html +++ b/src/index.html @@ -39,6 +39,20 @@ allowEdit:true, forceCalculation:false, plugins: ['chart'], + fontList:[ + { + "fontName":"HanaleiFill", + "url":"http://localhost:3002/assets/iconfont/HanaleiFill-Regular.ttf" + }, + { + "fontName":"Anton", + "url":"http://localhost:3002/assets/iconfont/Anton-Regular.ttf" + }, + { + "fontName":"Pacifico", + "url":"http://localhost:3002/assets/iconfont/Pacifico-Regular.ttf" + } + ], data: [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification] // [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[ diff --git a/src/store/index.js b/src/store/index.js index a4cf1b2..8414665 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -131,6 +131,8 @@ const Store = { inlineStringEditCache:null, inlineStringEditRange:null, + fontList:[], + } export default Store; \ No newline at end of file diff --git a/src/utils/util.js b/src/utils/util.js index e1f8310..48b3bed 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -375,7 +375,12 @@ function luckysheetfontformat(format) { } else { - fontfamily = fontarray[fontjson[format.ff]]; + // fontfamily = fontarray[fontjson[format.ff]]; + fontfamily = format.ff; + + if(fontfamily!=null && !document.fonts.check("12px "+fontfamily)){ + menuButton.addFontTolist(fontfamily); + } } if (fontfamily == null) { @@ -663,7 +668,6 @@ function loadLinks(urls) { } - export { isJsonString, common_extend,