Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(inline string finished): fix some bus
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Sep 22, 2020
1 parent 76d966f commit 57e7518
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 73 deletions.
61 changes: 50 additions & 11 deletions src/controllers/inlineString.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++){
Expand Down Expand Up @@ -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"){
Expand All @@ -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){
Expand Down Expand Up @@ -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));
Expand All @@ -453,3 +490,5 @@ function getCssText(cssText, attr, value){





12 changes: 9 additions & 3 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)!="="){
Expand Down Expand Up @@ -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 };
Expand Down
4 changes: 2 additions & 2 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
59 changes: 44 additions & 15 deletions src/global/getRowlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++){
Expand All @@ -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++;
}
Expand All @@ -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,
});

}
Expand All @@ -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++;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -691,6 +697,7 @@ function getCellTextInfo(cell , ctx, option){
desc:measureText.actualBoundingBoxDescent,
inline:true,
wrap:true,
fs:sc.fs
});
}

Expand Down Expand Up @@ -738,6 +745,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}

Expand All @@ -761,6 +769,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}
break;
Expand Down Expand Up @@ -790,6 +799,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}

Expand All @@ -813,6 +823,7 @@ function getCellTextInfo(cell , ctx, option){
asc:sc.measureText.actualBoundingBoxAscent,
desc:sc.measureText.actualBoundingBoxDescent,
inline:true,
fs:sc.fs
});
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
});

}
Expand Down Expand Up @@ -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
});
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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"){
Expand All @@ -1407,6 +1428,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top;

item.fs = fs;

wordGroup.underLine.push(item);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
Loading

0 comments on commit 57e7518

Please sign in to comment.