4***@qq.com
4***@qq.com
  • 发布:2020-09-15 11:08
  • 更新:2020-10-15 18:04
  • 阅读:1072

【报Bug】Canvas.measureText 在APP端返回计算结果一直0,其他端正常

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win7 旗舰版 Service Pack 1

HBuilderX类型: 正式

HBuilderX版本号: 2.8.3

手机系统: Android

手机系统版本号: Android 7.0

手机厂商: 三星

手机机型: SM-G9250

页面类型: vue

打包方式: 离线

项目创建方式: HBuilderX

操作步骤:

DrawText(context, text, x, y, w, fontsize) {
var chr = text.split("");
var temp = "";
var row = [];
context.font = fontsize + "px uniicons";
context.fillStyle = "#333333";
context.textBaseline = "middle";
let _lineHeight = 1.5;

            for (var a = 0; a < chr.length; a++) {  
                if (context.measureText(temp).width < w && context.measureText(temp + (chr[a])).width < w) {  
                    temp += chr[a];  
                } else {  
                    row.push(temp);  
                    temp = chr[a];  
                }  
            }  
            row.push(temp);  
            var TextWidth = context.measureText(row[0]); //这里计算文本的宽度  
            console.log(TextWidth.width);  //这里显示文本的宽度  
            //文字全部显示  
            for (var b = 0; b < row.length; b++) {  
                context.fillText(row[b], (w / 2) - (TextWidth.width / 2), (y + (b + 1) * _lineHeight) + (fontsize - _lineHeight));  
            }  
            return context;  
        }

预期结果:

console.log 按照文本字数计算返回正常的文本宽度数值

实际结果:

console.log 在app端返回结果0 ,其他端正常返回计算值

bug描述:

Canvas.measureText 在APP计算文本宽度的返回结果一直为0,在H5\小程序端却能返回正常的计算结果

之前使用HBuilderX 正式版 2.7.9版本时,在APP端使用也是可以正常计算的,升级后就不行了。

2020-09-15 11:08 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

measureText 在 App 端确实有问题,接下来也会修复

  • 4***@qq.com (作者)

    嗯嗯,由于部分功能需要这块功能,期待尽快修复....辛苦了。

    2020-09-15 11:49

DCloud_UNI_GSQ

DCloud_UNI_GSQ

HBuilder 2.9.3+ 已修复

该问题目前已经被锁定, 无法添加新回复