Skip to content

Commit

Permalink
fix(g-svg): should not handle fontSize < 12 for text, close antvis#465
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Apr 8, 2020
1 parent 65eb610 commit 3f2da8b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 1 addition & 6 deletions packages/g-svg/src/shape/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Text extends ShapeBase {

_setFont() {
const el = this.get('el');
const { fontSize, textBaseline, textAlign } = this.attr();
const { textBaseline, textAlign } = this.attr();

const browser = detect();
if (browser && browser.name === 'firefox') {
Expand All @@ -88,11 +88,6 @@ class Text extends ShapeBase {
}

el.setAttribute('text-anchor', ANCHOR_MAP[textAlign] || 'left');
if (fontSize && +fontSize < 12) {
// 小于 12 像素的文本进行 scale 处理
this.attr('matrix', [1, 0, 0, 0, 1, 0, 0, 0, 1]);
this.transform();
}
}

_setText(text) {
Expand Down
29 changes: 29 additions & 0 deletions packages/g-svg/tests/bugs/issue-465-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const expect = require('chai').expect;
import Canvas from '../../../g-svg/src/canvas';

const dom = document.createElement('div');
document.body.appendChild(dom);
dom.id = 'c1';

describe('#465', () => {
const canvas = new Canvas({
container: dom,
width: 400,
height: 400,
});

it('text of fontSize < 12 should be rendered', () => {
const text = canvas.addShape('text', {
attrs: {
x: 50,
y: 100,
fontFamily: 'PingFang SC',
text: '文本文本',
fontSize: 10,
stroke: 'red',
},
});
const el = text.get('el');
expect(el.getAttribute('stroke')).eqls('red');
});
});

0 comments on commit 3f2da8b

Please sign in to comment.