Browse Source

fix(inline string finished): fix some bus

master
liuyang 5 years ago
parent
commit
57e75188ff
  1. 61
      src/controllers/inlineString.js
  2. 12
      src/controllers/menuButton.js
  3. 4
      src/global/draw.js
  4. 59
      src/global/getRowlen.js
  5. 12
      src/global/getdata.js
  6. 80
      src/index.html

61
src/controllers/inlineString.js

@ -3,6 +3,8 @@ import {selectTextContent,selectTextContentCross,selectTextContentCollapse} from
import locale from '../locale/locale';
import Store from '../store';
export const inlineStyleAffectAttribute = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1};
export function isInlineStringCell(cell){
let isIs = cell && cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
return isIs;
@ -257,6 +259,14 @@ export function enterKeyControll(){
}
}
export function updateInlineStringFormatOutside(cell, key, value){
let s = cell.ct.s;
for(let i=0;i<s.length;i++){
let item = s[i];
item[key] = value;
}
}
export function convertSpanToShareString($dom){
let styles = [], preStyleList, preStyleListString=null;
for(let i=0;i<$dom.length;i++){
@ -341,17 +351,11 @@ export function convertCssToStyleList(cssText){
}
if(key=="text-decoration"){
if(value=="line-through"){
styleList["cl"] = 1;
}
else{
if(value=="underline"){
styleList["un"] = 1;
}
else{
styleList["cl"] = 0;
}
}
}
if(key=="border-bottom"){
styleList["un"] = 1;
}
if(key=="lucky-strike"){
@ -374,7 +378,27 @@ const luckyToCssName = {
"fs":"font-size",
"fc":"color",
"cl":"text-decoration",
"un":"text-decoration",
"un":"border-bottom",
}
function getClassWithcss(cssText, ukey){
let cssTextArray = cssText.split(";");
if(ukey==null || ukey.length==0){
return cssText;
}
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(key==ukey){
return value;
}
}
}
return "";
}
function upsetClassWithCss(cssText, ukey, uvalue){
@ -439,6 +463,19 @@ function removeClassWidthCss(cssText, ukey){
function getCssText(cssText, attr, value){
let styleObj = {};
styleObj[attr] = value;
if(attr=="un"){
let fontColor = getClassWithcss(cssText,"color");
if(fontColor==""){
fontColor = "#000000";
}
let fs = getClassWithcss(cssText,"font-size");
if(fs==""){
fs = 11;
}
fs = parseInt(fs);
styleObj["_fontSize"] = fs;
styleObj["_color"] = fontColor;
}
let s = getFontStyleByCell(styleObj, undefined, undefined, false);
let ukey = textTrim(s.substr(0, s.indexOf(':')));
let uvalue = textTrim(s.substr(s.indexOf(':')+1));
@ -453,3 +490,5 @@ function getCssText(cssText, attr, value){

12
src/controllers/menuButton.js

@ -31,7 +31,7 @@ import { countfunc } from '../global/count';
import { hideMenuByCancel } from '../global/cursorPos';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
import { setluckysheetfile } from '../methods/set';
import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList} from './inlineString';
import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList,inlineStyleAffectAttribute,updateInlineStringFormatOutside} from './inlineString';
import { replaceHtml, getObjType, rgbTohex, mouseclickposition, luckysheetfontformat,luckysheetContainerFocus } from '../utils/util';
import Store from '../store';
import locale from '../locale/locale';
@ -2846,7 +2846,7 @@ const menuButton = {
let canvasElement = document.createElement('canvas');
let canvas = canvasElement.getContext("2d");
if(attr in {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1} ){
if(attr in inlineStyleAffectAttribute ){
if (parseInt($("#luckysheet-input-box").css("top")) > 0 ) {
let value = $("#luckysheet-input-box").text();
if(value.substr(0,1)!="="){
@ -2979,7 +2979,13 @@ const menuButton = {
let value = d[r][c];
if (getObjType(value) == "object") {
d[r][c][attr] = foucsStatus;
if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
updateInlineStringFormatOutside(value, attr, foucsStatus);
}
else{
d[r][c][attr] = foucsStatus;
}
}
else{
d[r][c] = { v: value };

4
src/global/draw.js

@ -2169,7 +2169,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +c.endX)/Store.zoomRatio)+0.5 ,
Math.floor((pos_y+c.endY)/Store.zoomRatio)+0.5 ,
);
ctx.lineWidth = 1;
ctx.lineWidth = Math.floor(c.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
@ -2188,7 +2188,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +item.endX)/Store.zoomRatio)+0.5,
Math.floor((pos_y+ item.endY)/Store.zoomRatio)+0.5
);
ctx.lineWidth = 1;
ctx.lineWidth = Math.floor(item.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();

59
src/global/getRowlen.js

@ -326,13 +326,13 @@ function getCellTextInfo(cell , ctx, option){
let textContent = {};
textContent.values = [];
let fontset, cancelLine="0", underLine="0", isInline=false, value, inlineStringArr=[];
let fontset, cancelLine="0", underLine="0", fontSize=11, isInline=false, value, inlineStringArr=[];
if(isInlineStringCell(cell)){
let sharedStrings = cell.ct.s, similarIndex = 0;
for(let i=0;i<sharedStrings.length;i++){
let shareCell = sharedStrings[i];
let scfontset = luckysheetfontformat(shareCell);
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v;
let fc = shareCell.fc, cl=shareCell.cl,un = shareCell.un, v = shareCell.v, fs=shareCell.fs;
v = v.replace(/\r\n/g, "_x000D_").replace(/&#13;&#10;/g, "_x000D_").replace(/\r/g, "_x000D_").replace(/\n/g, "_x000D_");
let splitArr = v.split("_x000D_"), preNewValue=null;
for(let x=0;x<splitArr.length;x++){
@ -344,7 +344,8 @@ function getCellTextInfo(cell , ctx, option){
fc:fc==null?"#000":fc,
cl:cl==null?0:cl,
un:un==null?0:un,
wrap:true
wrap:true,
fs:fs==null?11:fs,
});
similarIndex++;
}
@ -359,7 +360,8 @@ function getCellTextInfo(cell , ctx, option){
cl:cl==null?0:cl,
un:un==null?0:un,
v: nv,
si:similarIndex
si:similarIndex,
fs:fs==null?11:fs,
});
}
@ -370,7 +372,8 @@ function getCellTextInfo(cell , ctx, option){
fc:fc==null?"#000":fc,
cl:cl==null?0:cl,
un:un==null?0:un,
wrap:true
wrap:true,
fs:fs==null?11:fs,
});
similarIndex++;
}
@ -391,6 +394,7 @@ function getCellTextInfo(cell , ctx, option){
cancelLine = checkstatusByCell(cell ,"cl");//cancelLine
underLine = checkstatusByCell(cell ,"un");//underLine
fontSize = checkstatusByCell(cell ,"fs");
if(cell instanceof Object){
value = cell.m;
@ -609,7 +613,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top+word.height-space_height,
asc:word.height,
desc:0
desc:0,
fs:fontSize
});
textContent.values.push(word);
@ -662,6 +667,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
}
// if(rt!=0){//rotate
@ -691,6 +697,7 @@ function getCellTextInfo(cell , ctx, option){
desc:measureText.actualBoundingBoxDescent,
inline:true,
wrap:true,
fs:sc.fs
});
}
@ -738,6 +745,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -761,6 +769,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
break;
@ -790,6 +799,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -813,6 +823,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
@ -857,7 +868,8 @@ function getCellTextInfo(cell , ctx, option){
height:preTextHeight,
width:preTextWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
@ -876,7 +888,8 @@ function getCellTextInfo(cell , ctx, option){
height:textHeight,
width:textWidth,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
}
@ -901,7 +914,8 @@ function getCellTextInfo(cell , ctx, option){
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
splitIndex +=1;
@ -919,7 +933,8 @@ function getCellTextInfo(cell , ctx, option){
top:0,
splitIndex:splitIndex,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
break;
@ -1095,7 +1110,8 @@ function getCellTextInfo(cell , ctx, option){
left:left-wordGroup.width,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
textContent.values.push(wordGroup);
@ -1178,7 +1194,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
}
@ -1208,7 +1225,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:size.asc,
desc:size.desc
desc:size.desc,
fs:wordGroup.fs
});
}
@ -1356,7 +1374,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:measureText.actualBoundingBoxAscent,
desc:measureText.actualBoundingBoxDescent
desc:measureText.actualBoundingBoxDescent,
fs:fontSize,
});
textContent.values.push(wordGroup);
@ -1376,7 +1395,7 @@ function getCellTextInfo(cell , ctx, option){
function drawLineInfo(wordGroup, cancelLine,underLine,option){
let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc;
let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc,fs = option.fs;
if(wordGroup.wrap===true){
return;
@ -1395,6 +1414,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
wordGroup.cancelLine.endX = left + width;
wordGroup.cancelLine.endY = top-asc/2+1;
wordGroup.cancelLine.fs = fs;
}
if(underLine!="0"){
@ -1407,6 +1428,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1418,6 +1441,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1429,6 +1454,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
item.fs = fs;
wordGroup.underLine.push(item);
}
@ -1440,6 +1467,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc+2;
item.fs = fs;
wordGroup.underLine.push(item);
}
}

12
src/global/getdata.js

@ -369,7 +369,15 @@ export function getFontStyleByCell(cell,checksAF,checksCF, isCheck=true){
}
if(key == "un" && (value == "1" || value == "3")){
style += "text-decoration: underline;";
let color = cell["_color"];
if(color==null){
color = cell["fc"];
}
let fs = cell["_fontSize"];
if(fs==null){
fs = cell["fs"];
}
style += "border-bottom: "+ Math.floor(fs/9) +"px solid "+ color +";";
}
}
@ -380,7 +388,7 @@ export function checkstatusByCell(cell, a){
let foucsStatus =cell;
let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
if(a in tf){
if(a in tf || (a=="fs" && isInlineStringCell(cell)) ){
if(foucsStatus == null){
foucsStatus = "0";
}

80
src/index.html

@ -78,46 +78,46 @@
forceCalculation:false,
plugins: ['chart'],
data:
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
// [{"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":[
// {"r":0,"c":0,
// "v":{
// "ct":{
// "fa":"General",
// "t":"inlineStr",
// "s":[
// {
// "ff":"Arial", //font family
// "fc":"#fff000",//font color
// "fs":12,//font size
// "cl":0,//strike
// "un":0,//underline
// "bl":0,//blod
// "it":0,//italic
// v:"我在马路\r\n边捡到\r\n\r\n一分钱"
// },
// {
// "ff":"Arial", //font family
// "fc":"#ff0000",//font color
// "fs":14,//font size
// "cl":"1",//strike
// "un":"1",//underline
// "bl":"1",//blod
// "it":"0",//italic
// v:"交给警\r\n察叔叔\r\n"
// },
// ]
// },
// "fs":11,
// "ff":"等线",
// "vt":0,
// "tb":2,
// "v":"",
// "qp":1,
// }
// },
// {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
// ],"calcChain":[]}]
// [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
[{"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":[
{"r":0,"c":0,
"v":{
"ct":{
"fa":"General",
"t":"inlineStr",
"s":[
{
"ff":"Arial", //font family
"fc":"#fff000",//font color
"fs":12,//font size
"cl":0,//strike
"un":0,//underline
"bl":0,//blod
"it":0,//italic
v:"我在马路\r\n边捡到\r\n\r\n一分钱"
},
{
"ff":"Arial", //font family
"fc":"#ff0000",//font color
"fs":14,//font size
"cl":"1",//strike
"un":"1",//underline
"bl":"1",//blod
"it":"0",//italic
v:"交给警\r\n察叔叔\r\n"
},
]
},
"fs":11,
"ff":"等线",
"vt":0,
"tb":2,
"v":"",
"qp":1,
}
},
{"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
],"calcChain":[]}]
})
})

Loading…
Cancel
Save