|
@@ -23,6 +23,19 @@ Page({
|
|
|
scale: 2.4834437086092715,
|
|
|
angle: 27
|
|
|
},
|
|
|
+ fontTouch:{
|
|
|
+ isActive: "1",
|
|
|
+ fontContent: "Gg",
|
|
|
+ isColor: "#ffffff",
|
|
|
+ x: 10,
|
|
|
+ y: 10,
|
|
|
+ angle: 0,
|
|
|
+ fontSize: 56,
|
|
|
+ clientX: 0,
|
|
|
+ clientY: 0,
|
|
|
+ width:10,
|
|
|
+ height:10
|
|
|
+ },
|
|
|
rpx:1,
|
|
|
obverseImgObject: {
|
|
|
'1': '/customized/images/customized/cup_black_big.png',/*正面 */
|
|
@@ -41,6 +54,11 @@ Page({
|
|
|
imgTouch: wx.getStorageSync('madeCupImgData1')
|
|
|
})
|
|
|
}
|
|
|
+ if (wx.getStorageSync('madeCupFontData1')){
|
|
|
+ this.setData({
|
|
|
+ fontTouch: wx.getStorageSync('madeCupFontData1')
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
|
|
|
},
|
|
@@ -57,7 +75,8 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
- this.getCombImg(this)
|
|
|
+ this.getCombImg(this);
|
|
|
+ this.getCombFont(this)
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -114,10 +133,12 @@ Page({
|
|
|
// canvas截图区域与图片的高度比例
|
|
|
let dHeight = dataPositionObj.height / imgTouch.height;
|
|
|
const ctx = wx.createCanvasContext('comb-img');
|
|
|
- // 设置背景
|
|
|
- // ctx.setFillStyle('red')
|
|
|
- // ctx.fillRect(0, 0, dataPositionObj.width * rpx, dataPositionObj.height * rpx);
|
|
|
- ctx.drawImage(res.tempFilePath,imgTouch.x,imgTouch.y,imgTouch.width * rpx,imgTouch.height * rpx)
|
|
|
+ //画布中点坐标转移到图片中心
|
|
|
+ let movex = imgTouch.x + imgTouch.width * rpx/2;
|
|
|
+ let movey = imgTouch.y + imgTouch.height * rpx/2;
|
|
|
+ ctx.translate(movex, movey);
|
|
|
+ ctx.rotate(imgTouch.angle * Math.PI / 180);
|
|
|
+ ctx.drawImage(res.tempFilePath, -imgTouch.width * rpx / 2, -imgTouch.height * rpx/2,imgTouch.width * rpx,imgTouch.height * rpx)
|
|
|
ctx.draw(true,function(){
|
|
|
wx.canvasToTempFilePath({
|
|
|
canvasId: 'comb-img',
|
|
@@ -134,6 +155,22 @@ Page({
|
|
|
},
|
|
|
})
|
|
|
},
|
|
|
+ getCombFont(that) {
|
|
|
+ let fontTouch = that.data.fontTouch;
|
|
|
+ let dataPositionObj = that.data.dataPositionObj;
|
|
|
+ const ctx = wx.createCanvasContext('comb-font');
|
|
|
+
|
|
|
+ let movex = fontTouch.x + fontTouch.width / 2;
|
|
|
+ let movey = fontTouch.y + fontTouch.height / 2;
|
|
|
+ ctx.translate(movex, movey);
|
|
|
+ ctx.rotate(fontTouch.angle * Math.PI / 180);
|
|
|
+
|
|
|
+ ctx.setFontSize(fontTouch.fontSize);
|
|
|
+ ctx.setFillStyle(fontTouch.isColor);
|
|
|
+ // ctx.fillText(fontTouch.fontContent, fontTouch.x, fontTouch.y + fontTouch.height / 5 *4);
|
|
|
+ ctx.fillText(fontTouch.fontContent, -fontTouch.width / 2, fontTouch.height / 5 * 4 - fontTouch.height / 2);
|
|
|
+ ctx.draw()
|
|
|
+ },
|
|
|
getComb(that,imgSrc){
|
|
|
let imgTouch = that.data.imgTouch;
|
|
|
let dataPositionObj = that.data.dataPositionObj;
|
|
@@ -150,7 +187,6 @@ Page({
|
|
|
// 设置背景
|
|
|
ctx.drawImage(imgSrc, dataPositionObj.left * rpx, dataPositionObj.top * rpx, dataPositionObj.width * rpx, dataPositionObj.height * rpx);
|
|
|
ctx.draw(true)
|
|
|
-
|
|
|
},
|
|
|
})
|
|
|
}
|