z***@126.com
z***@126.com
  • 发布:2024-04-10 16:14
  • 更新:2024-04-11 14:49
  • 阅读:689

【报Bug】微信小程序真机canvas 字体不生效,微信开发工具正常

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 12.3

HBuilderX类型: 正式

HBuilderX版本号: 3.99

第三方开发者工具版本号: 1.06.2402040

基础库版本号: 3.4.0

项目创建方式: HBuilderX

示例代码:

字体文件是base64格式的

操作步骤:

使用微信小程序真机复现,输入示例文字点击确认,没有对应生成字体

预期结果:

应该与示例文字字体一致

实际结果:

还是显示默认字体

bug描述:

<template>  
    <view class="page-body">  
        <view class="uni-padding-wrap uni-common-mt">  
            <view class="font_tt">  
                示例文字:孢子体可  
            </view>  
            <view class="writing-input">  
                <input type="text" v-model="writingData.writing" placeholder-class="writing-pl" :placeholder="placeholder">  
            </view>  
            <canvas :canvas-id="canvas_rid" :hidpi="true" :id="canvas_rid"   :width="canvasWidth"  
                :height="canvasHeight"></canvas>  

            <button @click="CreateWriting">确认</button>  
        </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                placeholder: "文字定制",  
                canvasWidth: 300,  
                canvasHeight: 300,  
                canvas_rid: 'canvas_writing',  
                ctx: "", //canvas上下文  
                writing_width: 0, //文字图片宽度  
                writing_height: 0, //文字图片高度  
                writingData: {  
                    writing: "",  
                    rowType: "horizontal", // 横排 == horizontal 竖排 == vertical  
                    color: "#000000",  
                    typeface: "ZQKNLT",  
                },  
            }  
        },  
        onLoad() {  
        //  this.tap()  
        },  
        methods: {  
            async CreateWriting() {  
                uni.showLoading({  
                    title: "生成文字中...",  
                });  
                const ctx = uni.createCanvasContext(this.canvas_rid, this);  
                this.ctx = ctx;  

                //清空之前的canvas  
                ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);  
                ctx.draw(true,async ()=>{  
                    await this.drawWritingText(ctx);  

                    uni.hideLoading();  
                });  

            },  
            /**  
             * @description 绘制文字  
             * @param {Object} ctx  
             */  
            drawWritingText(ctx){  
                return new Promise((revolve,reject)=>{  
                    let fontSize = 16;  
                    let typeface = this.writingData.typeface;  
                    let color = this.writingData.color;  
                    let text = this.writingData.writing;  
                    //normal  
                    ctx.font = `normal ${fontSize}px ${typeface}`; // 字体  
                    //ctx.  
                    console.log("ctx.font:",ctx.font)  
                    ctx.setFillStyle(color) //文字颜色:默认黑色  

                    let measure = ctx.measureText(text).width;  
                    this.writing_width = 0;  
                    this.writing_height = 0;  
                    if (this.writingData.rowType == 'horizontal') {  
                        //横排  
                        this.writing_width = measure;  
                        this.writing_height = 32;  
                        ctx.setTextAlign('left');  
                        ctx.fillText(text, 0, 40); //文字内容、x坐标,y坐标  
                    } else if (this.writingData.rowType == 'vertical') {  
                        //垂直  
                        this.drawTextVertical(ctx, text, 40, 40);  
                        this.writing_width = 32;  
                        this.writing_height = measure;  
                        if (text.length > 0) {  
                            this.writing_height += 40;  
                        }  
                    }  

                    ctx.draw(true,()=>{  
                        revolve();  
                    })  
                })  
            },  
        }  
    }  
</script>  

<style scoped lang="scss">  
    @import url("/static/stylesheet.css");  
    @font-face {  
    font-family: 'ZQKNLT';  
    src: url('data:font/woff2;charset=utf-8;base64,d09GMgABAAAAABJ0ABAAAAAAI7gAABIZAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GYACCYggaCYJzEQgKsRSocwsSAAE2AiQDGAQgBYorB1oMThtoHqOilpNW8CIqOK2yfx7YxtIHgyQoesbCs4jBMc+DhlTThdTxbwT/7KPCM1Ro07Iz3HEjJJnl4fv9/rf2OfeLGGbvDRcVb1S8iSYaicgQIpHpbzrQbLqn9/P8Nv/ce18S+h6tGO8Zby4U0GYFVoK4YA3oIoFV6aJ+LdI1/gpdov5Y/Ar3q8rFtUxsY+kB0fghSBJ+Rk4BkZqePvjfpfpFJXo6O2vDjgVQXwFy/IK6YAn5ohL9km7a+5w1z026B/L4v6mzl3Y7QIFwaxiJVP933l06MhjHTsdUTdrtM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2u4cbWhuTD86pMM8Ky0WEAWftbEkwDbLLLWiQ7vm6RAz54VZEuftOT1BApg4eXmpXAVyleuEHrx1QB3fE53XIeXn2SWnRH8o0escDpbmFuQ+Zn52AH4CZNkFcEwju5ZbwO9OiYPH7nQITw/a7sizyx3yXIHcdu6OO+aHvPRzjtRNkBftr4M7NzqWzossiM9jUcfprk3rMd+2B+AEOfj11ZXO7Vh7Y/qUFp8zrFJwrfSMJzT8+InGR6I75lUMN7tcb+Hx4JlZe2/wd1nQNY+3Y3LTvDHNAy3vrfTv1t6LWkcCnOm6g1jbL1p8IB2tXpnjbbqlDFxyvRTOrdj9iU3uL/k92/qUdO3XxdkEk0kfDPtNyWR16ycgHwj95gN/kwIjgihEI4ZduXRBYXVRQVDbpqrq6tyykuJNFfbN3yhzFLvjABUDkJAqqBzBHrt5rwnsMhmh11fguBJkz/sGEIWmShzccwM=') format('woff2');  
    font-weight: normal;  
    font-style: normal;  
    font-display: swap;  
}  

    .font_tt{  
        font-family: "ZQKNLT";  
    }  
</style>
2024-04-10 16:14 负责人:无 分享
已邀请:
JXWang

JXWang

微信小程序原生写法应该也有这个问题,类似问题

要回复问题请先登录注册