fix
This commit is contained in:
parent
9a88ab2ab2
commit
301d7d4a15
@ -216,7 +216,7 @@ export default class Painter {
|
|||||||
if (!view.css.fontSize) {
|
if (!view.css.fontSize) {
|
||||||
view.css.fontSize = '20rpx';
|
view.css.fontSize = '20rpx';
|
||||||
}
|
}
|
||||||
this.ctx.font = `${textStyle} ${fontWeight} ${view.css.fontSize.toPx()}px ${view.css.fontFamily ? view.css.fontFamily : 'sans-serif'}`;
|
this.ctx.font = `${textStyle} ${fontWeight} ${view.css.fontSize.toPx()}px "${view.css.fontFamily || 'sans-serif'}"`;
|
||||||
// 计算行数
|
// 计算行数
|
||||||
let lines = 0;
|
let lines = 0;
|
||||||
const linesArray = [];
|
const linesArray = [];
|
||||||
|
|||||||
31
painter.js
31
painter.js
@ -13,6 +13,7 @@ const ACTION_OFFSET = '2rpx';
|
|||||||
Component({
|
Component({
|
||||||
canvasWidthInPx: 0,
|
canvasWidthInPx: 0,
|
||||||
canvasHeightInPx: 0,
|
canvasHeightInPx: 0,
|
||||||
|
canvasNode: null,
|
||||||
paintCount: 0,
|
paintCount: 0,
|
||||||
currentPalette: {},
|
currentPalette: {},
|
||||||
movingCache: {},
|
movingCache: {},
|
||||||
@ -637,10 +638,10 @@ Component({
|
|||||||
this.setData({
|
this.setData({
|
||||||
painterStyle: `width:${width.toPx()}px;height:${height.toPx()}px;`,
|
painterStyle: `width:${width.toPx()}px;height:${height.toPx()}px;`,
|
||||||
});
|
});
|
||||||
this.frontContext || (this.frontContext = await this.getCanvasContext(this.properties.use2D, 'front', width.toPx(), height.toPx()));
|
this.frontContext || (this.frontContext = await this.getCanvasContext(this.properties.use2D, 'front'));
|
||||||
this.bottomContext || (this.bottomContext = await this.getCanvasContext(this.properties.use2D, 'bottom', width.toPx(), height.toPx()));
|
this.bottomContext || (this.bottomContext = await this.getCanvasContext(this.properties.use2D, 'bottom'));
|
||||||
this.topContext || (this.topContext = await this.getCanvasContext(this.properties.use2D, 'top', width.toPx(), height.toPx()));
|
this.topContext || (this.topContext = await this.getCanvasContext(this.properties.use2D, 'top'));
|
||||||
this.globalContext || (this.globalContext = await this.getCanvasContext(this.properties.use2D, 'k-canvas', width.toPx(), height.toPx()));
|
this.globalContext || (this.globalContext = await this.getCanvasContext(this.properties.use2D, 'k-canvas'));
|
||||||
new Pen(this.bottomContext, palette, this.properties.use2D).paint(() => {
|
new Pen(this.bottomContext, palette, this.properties.use2D).paint(() => {
|
||||||
this.isDisabled = false;
|
this.isDisabled = false;
|
||||||
this.isDisabled = this.outterDisabled;
|
this.isDisabled = this.outterDisabled;
|
||||||
@ -678,7 +679,7 @@ Component({
|
|||||||
this.setData({
|
this.setData({
|
||||||
photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`,
|
photoStyle: `width:${this.canvasWidthInPx}px;height:${this.canvasHeightInPx}px;`,
|
||||||
});
|
});
|
||||||
this.photoContext || (this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo', width.toPx(), height.toPx()));
|
this.photoContext || (this.photoContext = await this.getCanvasContext(this.properties.use2D, 'photo'));
|
||||||
|
|
||||||
new Pen(this.photoContext, palette).paint(() => {
|
new Pen(this.photoContext, palette).paint(() => {
|
||||||
this.saveImgToLocal();
|
this.saveImgToLocal();
|
||||||
@ -754,8 +755,9 @@ Component({
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
wx.canvasToTempFilePath({
|
wx.canvasToTempFilePath({
|
||||||
canvasId: 'photo',
|
canvasId: 'photo',
|
||||||
destWidth: that.canvasWidthInPx,
|
canvas: that.properties.use2D ? that.canvasNode : null,
|
||||||
destHeight: that.canvasHeightInPx,
|
destWidth: that.canvasWidthInPx * getApp().systemInfo.pixelRatio,
|
||||||
|
destHeight: that.canvasHeightInPx * getApp().systemInfo.pixelRatio,
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
that.getImageInfo(res.tempFilePath);
|
that.getImageInfo(res.tempFilePath);
|
||||||
},
|
},
|
||||||
@ -770,25 +772,26 @@ Component({
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
getCanvasContext(use2D, id, width, height) {
|
getCanvasContext(use2D, id) {
|
||||||
|
const that = this;
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (use2D) {
|
if (use2D) {
|
||||||
const query = wx.createSelectorQuery().in(this);
|
const query = wx.createSelectorQuery().in(that);
|
||||||
const selectId = `#${id}`;
|
const selectId = `#${id}`;
|
||||||
query.select(selectId)
|
query.select(selectId)
|
||||||
.fields({ node: true, size: true })
|
.fields({ node: true, size: true })
|
||||||
.exec((res) => {
|
.exec((res) => {
|
||||||
const canvasNode = res[0].node;
|
that.canvasNode = res[0].node;
|
||||||
const ctx = canvasNode.getContext('2d');
|
const ctx = that.canvasNode.getContext('2d');
|
||||||
const wxCanvas = new WxCanvas('2d', ctx, id, true, canvasNode);
|
const wxCanvas = new WxCanvas('2d', ctx, id, true, that.canvasNode);
|
||||||
const dpr = wx.getSystemInfoSync().pixelRatio
|
const dpr = Math.min(2, getApp().systemInfo.pixelRatio)
|
||||||
wxCanvas.width = res[0].width * dpr
|
wxCanvas.width = res[0].width * dpr
|
||||||
wxCanvas.height = res[0].height * dpr
|
wxCanvas.height = res[0].height * dpr
|
||||||
wxCanvas.scale(dpr, dpr)
|
wxCanvas.scale(dpr, dpr)
|
||||||
resolve(wxCanvas);
|
resolve(wxCanvas);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const temp = wx.createCanvasContext(id, this);
|
const temp = wx.createCanvasContext(id, that);
|
||||||
resolve(new WxCanvas('mina', temp, id, true));
|
resolve(new WxCanvas('mina', temp, id, true));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user