Skip to content

drawTextShape 列头怎么画两个不同样式的文字呢,大家有什么思路么 #1458

Closed Answered by lijinke666
Chasen-Zhang asked this question in Q&A
Discussion options

You must be logged in to vote

把文字拆分成两个 shape, 分别绘制, 测量前一个文字 String 的文字宽度, 得到 name 的起始 X 坐标

参考

protected drawTextShape() {

伪代码如下:

  drawTextShape() {
    // 得到原始文字的坐标样式信息
    const textStyle = this.getTextStyle();
    const position = this.getTextPosition();

    const textA = 'String';
    const textB = 'name';

    const textAStyle = {
      ...textStyle,
      fontSize: 10,
      fill: 'red',
    };

    const textBStyle = {
      ...textStyle,
      fontSize: 20,
      fill: 'blue',
    };
    const textAWidth = measureTextWidth(textA, textAStyle);

    // 绘制 String
    renderText(position.x, position.y, textA);
    // 绘制 name
    rende…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YardWill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants