ecomfe / zrender

A lightweight graphic library providing 2d draw for Apache ECharts

Home Page:https://ecomfe.github.io/zrender-doc/public/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

measureText 计算 fontSize 有误

zhiqingchen opened this issue · comments

text = text || '';
font = font || DEFAULT_FONT;
// Use font size if there is no other method can be used.
const res = /^([0-9]*?)px$/.exec(font);
const fontSize = +(res && res[1]) || DEFAULT_FONT_SIZE;

DEFAULT_FONT 为 12px sans-serif

运行时为 normal normal 12px sans-serif

font = font || DEFAULT_FONT;
const res = /^([0-9]*?)px$/.exec(font);
const fontSize = +(res && res[1]) || DEFAULT_FONT_SIZE;

res 为 null, fontSize 只能为 DEFAULT_FONT_SIZE

normal normal 12px sans-serif 是怎么来的?请提供一个调用时的代码