Skip to content

Commit

Permalink
fix: hidden的text #59
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Aug 1, 2020
1 parent 395e6c6 commit db3215a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
18 changes: 10 additions & 8 deletions index.js

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

2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/node/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,23 @@ class Text extends Node {
}

render(renderMode, ctx) {
const { isDestroyed, computedStyle } = this;
let vd = this.__virtualDom = {
type: 'text',
children: [],
};
const { isDestroyed, computedStyle, lineBoxes } = this;
if(isDestroyed || computedStyle.display === 'none' || computedStyle.visibility === 'hidden') {
return;
}
if(renderMode === mode.CANVAS) {
ctx.font = css.setFontStyle(computedStyle);
ctx.fillStyle = util.int2rgba(computedStyle.color);
}
this.lineBoxes.forEach(item => {
lineBoxes.forEach(item => {
item.render(renderMode, ctx, computedStyle);
});
if(renderMode === mode.SVG) {
this.__virtualDom = {
type: 'text',
children: this.lineBoxes.map(lineBox => lineBox.virtualDom),
};
vd.children = lineBoxes.map(lineBox => lineBox.virtualDom);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/visibility-hidden-inherit-child-svg/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
browser
.url('file://' + path.join(__dirname, 'index.html'))
.waitForElementVisible('body', 1000)
.assert.value('input', '{"bb":[],"children":[{"bb":[],"children":[{},{"bb":[],"children":[{"type":"text","children":[{"type":"item","tagName":"text","props":[["x",8.90625],["y",14.484375],["fill","rgba(0,0,0,1)"],["font-family","arial"],["font-weight",400],["font-style","normal"],["font-size","16px"]],"content":"2"}]}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom","defs":[]}visible')
.assert.value('input', '{"bb":[],"children":[{"bb":[],"children":[{"type":"text","children":[]},{"bb":[],"children":[{"type":"text","children":[{"type":"item","tagName":"text","props":[["x",8.90625],["y",14.484375],["fill","rgba(0,0,0,1)"],["font-family","arial"],["font-weight",400],["font-style","normal"],["font-size","16px"]],"content":"2"}]}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom","defs":[]}visible')
.end();
}
};
2 changes: 1 addition & 1 deletion test/visibility-hidden-inherit-geom-svg/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
browser
.url('file://' + path.join(__dirname, 'index.html'))
.waitForElementVisible('body', 1000)
.assert.value('input', '{"bb":[],"children":[{"bb":[],"children":[{},{"bb":[],"children":[],"opacity":1,"type":"geom"}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom","defs":[]}hidden')
.assert.value('input', '{"bb":[],"children":[{"bb":[],"children":[{"type":"text","children":[]},{"bb":[],"children":[],"opacity":1,"type":"geom"}],"opacity":1,"type":"dom"}],"opacity":1,"type":"dom","defs":[]}hidden')
.end();
}
};

0 comments on commit db3215a

Please sign in to comment.