Skip to content

Commit 07330bd

Browse files
bold
1 parent 1e7f201 commit 07330bd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

miniprogram_dist/index/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const main = {
6868
* @param {Object} params
6969
*/
7070
drawText(params) {
71-
const { x, y, fontSize, color, baseLine, textAlign, text, opacity = 1, width, lineNum, lineHeight } = params;
71+
const { x, y, fontSize, color, baseLine, textAlign, text, opacity = 1, width, lineNum, lineHeight} = params;
7272
if (Object.prototype.toString.call(text) === '[object Array]') {
7373
let preText = { x, y, baseLine };
7474
text.forEach(item => {
@@ -174,11 +174,12 @@ const handle = {
174174
* 渲染一段文字
175175
*/
176176
_drawSingleText({ x, y, fontSize, color, baseLine, textAlign = 'left', text, opacity = 1, textDecoration = 'none',
177-
width, lineNum = 1, lineHeight = 0 }) {
177+
width, lineNum = 1, lineHeight = 0, bold = 'normal', italic = 'normal', fontFamily = "sans-serif"}) {
178178
this.ctx.save();
179179
this.ctx.beginPath();
180+
this.ctx.font = italic + " " + bold + " " + this.toPx(fontSize) + "px " + fontFamily
180181
this.ctx.setGlobalAlpha(opacity);
181-
this.ctx.setFontSize(this.toPx(fontSize));
182+
// this.ctx.setFontSize(this.toPx(fontSize));
182183
this.ctx.setFillStyle(color);
183184
this.ctx.setTextBaseline(baseLine);
184185
this.ctx.setTextAlign(textAlign);
@@ -325,10 +326,10 @@ const helper = {
325326
});
326327
},
327328
toPx(rpx) {
328-
return rpx * this.factor;
329+
return parseInt(rpx * this.factor);
329330
},
330331
toRpx(px) {
331-
return px / this.factor;
332+
return parseInt(px / this.factor);
332333
},
333334
/**
334335
* 将http转为https

0 commit comments

Comments
 (0)