getStrW static method

Map getStrW(
  1. dynamic text,
  2. Map style
)

测量文本宽度

Implementation

static Map getStrW(dynamic text, Map style) {
  text = Tools.replaceNumbersWithEight(text.toString());
  Map r = getMeasureTxtStyle(style);
  String id = '$text${r['id']}';
  if (strMap[id] != null) {
    //已经测量过
    // print('$text $id 已经测量过');
    return strMap[id];
  } else {
    //创建测量文本
    measureTextPainter.text = TextSpan(
      text: text,
      style: r['style'],
    );
    measureTextPainter.textDirection = style['textDirection'];
    //测量
    measureTextPainter.layout();
    //存储
    strMap[id] = {
      'width': measureTextPainter.width.ceil().toDouble(),
      'height': measureTextPainter.height.ceil().toDouble()
    };
    // print('测量 $text');
    return strMap[id];
  }
}