|
@@ -229,26 +229,27 @@ Page({
|
|
|
// ctx.textBaseline = 'top';
|
|
|
ctx.setFontSize(fontTouch.fontSize);
|
|
|
ctx.setFillStyle(fontTouch.isColor);
|
|
|
- const metrics = ctx.measureText(fontTouch.fontContent)
|
|
|
- let movex = fontTouch.x + metrics.width / 2;
|
|
|
- let movey = fontTouch.y + simulationFont.height / 2;
|
|
|
- ctx.translate(movex, movey);
|
|
|
- ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
- ctx.fillText(fontTouch.fontContent, -metrics.width / 2, -simulationFont.height / 2 + simulationFont.height / 5 * 4);
|
|
|
-
|
|
|
- console.log(metrics,"文本的宽度")
|
|
|
+ ctx.font = `'bold' ${fontTouch.fontSize} ${fontTouch.isColor} 'sans-serif'`;
|
|
|
+ // const metrics = ctx.measureText(fontTouch.fontContent)
|
|
|
+ // let movex = fontTouch.x + metrics.width / 2;
|
|
|
+ // let movey = fontTouch.y + simulationFont.height / 2;
|
|
|
+ // ctx.translate(movex, movey);
|
|
|
+ // ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
+ // ctx.fillText(fontTouch.fontContent, -metrics.width / 2, -simulationFont.height / 2 + simulationFont.height / 5 * 4);
|
|
|
+ ctx.fillText(fontTouch.fontContent, 0, simulationFont.height / 5 * 4)
|
|
|
ctx.draw(false,function () {
|
|
|
wx.canvasToTempFilePath({
|
|
|
canvasId: 'comb-font'+i,
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
- let imgArray = that.data.imgSrcArray;
|
|
|
- imgArray.push(res.tempFilePath)
|
|
|
- that.setData({
|
|
|
- imgSrcArray: imgArray
|
|
|
- })
|
|
|
- console.log(that.data.imgSrcArray, "that.data.imgSrcArray")
|
|
|
- that.getComb(that, that.data.imgSrcArray,i,true)
|
|
|
+ that.getCombFontImg(that, res.tempFilePath, fontTouch,i)
|
|
|
+ // let imgArray = that.data.imgSrcArray;
|
|
|
+ // imgArray.push(res.tempFilePath)
|
|
|
+ // that.setData({
|
|
|
+ // imgSrcArray: imgArray
|
|
|
+ // })
|
|
|
+ // console.log(that.data.imgSrcArray, "that.data.imgSrcArray")
|
|
|
+ // that.getComb(that, that.data.imgSrcArray,i,true)
|
|
|
}
|
|
|
}, that)
|
|
|
})
|
|
@@ -257,6 +258,40 @@ Page({
|
|
|
}
|
|
|
|
|
|
},
|
|
|
+ getCombFontImg(that, img, fontTouch,i){ // 生产字体图片后在进行处理一次
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: function (res) {
|
|
|
+ let rpx = res.windowWidth / 750;
|
|
|
+ that.setData({
|
|
|
+ rpx: rpx
|
|
|
+ });
|
|
|
+ // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
|
|
|
+ console.log(res)
|
|
|
+ // canvas截图区域与图片的宽度比例
|
|
|
+ const ctx = wx.createCanvasContext('comb-font' + i + '-2');
|
|
|
+ //画布中点坐标转移到图片中心
|
|
|
+ let movex = fontTouch.x + 218 * rpx / 2;
|
|
|
+ let movey = fontTouch.y + 218 * rpx / 2;
|
|
|
+ ctx.translate(movex, movey);
|
|
|
+ ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
+ ctx.drawImage(img, -218 * rpx / 2, -218 * rpx / 2, 218 * rpx, 218 * rpx)
|
|
|
+ ctx.draw(false, function () {
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvasId: 'comb-font' + i + '-2',
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res)
|
|
|
+ let imgArray = that.data.imgSrcArray;
|
|
|
+ imgArray.push(res.tempFilePath)
|
|
|
+ that.setData({
|
|
|
+ imgSrcArray: imgArray
|
|
|
+ })
|
|
|
+ that.getComb(that, that.data.imgSrcArray,i,true)
|
|
|
+ }
|
|
|
+ }, that)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ })
|
|
|
+ },
|
|
|
getComb(that, imgSrcArray,i,_static) {
|
|
|
console.log(imgSrcArray,"imgSrcArray")
|
|
|
if(_static){
|