当前位置: 首页> 娱乐> 八卦 > 在线ps手机版网页版_今日体育新闻最新消息_百度查询最火的关键词_网络营销的工具有哪些

在线ps手机版网页版_今日体育新闻最新消息_百度查询最火的关键词_网络营销的工具有哪些

时间:2025/7/16 16:08:19来源:https://blog.csdn.net/new_public/article/details/147125572 浏览次数:0次
在线ps手机版网页版_今日体育新闻最新消息_百度查询最火的关键词_网络营销的工具有哪些

/**

     * 画布文本换行绘制

     * canvasContext 画布实例

     * text 要写入的文本

     * x 初始x轴位置

     * y 初始y轴位置

     * ySpacing 换行后,每行直接的间隔

     * maxWidth 此文本写入画布的最大宽度,超过此宽度就换行

     * color 文本颜色

     * size 文本字体大小

     * align 文本方向 left rigt center 额一直搞不清楚这个方向是怎么个原理

     * @returns { textY 绘制最后一行文本的Y轴结束坐标,drawNum 画布本次绘制了几次 }

     */

    canvasTextNewlinedraw (options) {

        const { canvasContext, text = '', x = 0, y = 0, ySpacing = 0, maxWidth = 0, color, size, align } = options

        return new Promise((resolve, reject) => {

            size && canvasContext.setFontSize(size)

            align && canvasContext.setTextAlign(align)

            color && canvasContext.setFillStyle(color)

            const textList = text.split('')

            let currText = '', textY = 0, drawNum = 0

            for (let i = 0; i < textList.length; i++) {

                if (canvasContext.measureText(currText + textList[i]).width + x > maxWidth - 10) {

                    textY += textY === 0 ? y : ySpacing

                    canvasContext.fillText(currText, x, textY)

                    currText = textList[i]

                    drawNum++

                } else {

                    currText += textList[i]

                }

            }

            textY = textY === 0 ? y : textY + ySpacing

            canvasContext.fillText(currText, x, textY)

            drawNum++

            canvasContext.draw(true, _ => {

                setTimeout(() => {

                    resolve({ y: textY, res: _, drawNum })

                }, 100)

            })

        })

    }

关键字:在线ps手机版网页版_今日体育新闻最新消息_百度查询最火的关键词_网络营销的工具有哪些

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: