Commit 7a700602 authored by Chen Jiping's avatar Chen Jiping

fix:支持用户手动换行,并修复句子背景宽度问题

parent 54e3909a
......@@ -39,7 +39,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
if (data) {
this.item = data;
}
console.log(JSON.stringify(data));
console.log(data);
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
......
......@@ -12,6 +12,8 @@ export class Exercises {
index: number;
bgWidth : number;
bg: ShapeRect;
answer: ShapeRect;
......@@ -56,12 +58,11 @@ export class Exercises {
this.initExercises();
let w = 1280 * this.scaleX;
let h = 140 * this.scaleY;
h = this.answer.height > h ? this.answer.height : h;
this.bg.setSize(w, h);
this.bg.setSize(this.bgWidth, h);
this.answer.y = (h - this.answer.height) / 2;
......@@ -189,7 +190,7 @@ export class Exercises {
text.boldFontName = 'GOTHICB';
text.textArr = getTextArr();
text.disH = 20;
text.maxWidth = 980;
text.maxWidth = 1056;
text.setScaleXY(this.scaleX);
text.refreshSize();
......
......@@ -1193,34 +1193,49 @@ export class RichText extends Label {
let text = this.textArr[i];
let c = this.textArr[i].val;
if (text.val != ' ') {
if (text.bold) {
this.ctx.font = `${this.fontSize}px ${this.boldFontName}`;
}
else {
this.ctx.font = `${this.fontSize}px ${this.fontName}`;
}
this.textArr[i].width = this.ctx.measureText(c).width;
tempStr += text.val;
tempArr.push(this.textArr[i]);
continue
}
if (this.ctx.measureText(temp).width < w && this.ctx.measureText(temp + (tempStr)).width <= w) {
temp += ' ' + tempStr;
tempArr.push(getBlank());
tempArr.push(this.textArr[i]);
var re = /\n/;
} else {
if (c.match(re)) {
row.push(tempArr);
temp = ' ' + tempStr;
tempArr = [];
tempArr.push(getBlank());
tempArr.push(this.textArr[i]);
tempStr = "";
}
else {
if (text.val != ' ') {
if (text.bold) {
this.ctx.font = `${this.fontSize}px ${this.boldFontName}`;
}
else {
this.ctx.font = `${this.fontSize}px ${this.fontName}`;
}
this.textArr[i].width = this.ctx.measureText(c).width;
tempStr += text.val;
tempArr.push(this.textArr[i]);
continue
}
if (this.ctx.measureText(temp).width < w && this.ctx.measureText(temp + (tempStr)).width <= w) {
temp += ' ' + tempStr;
tempArr.push(getBlank());
tempArr.push(this.textArr[i]);
} else {
row.push(tempArr);
temp = ' ' + tempStr;
tempArr = [];
tempArr.push(getBlank());
tempArr.push(this.textArr[i]);
}
tempStr = "";
}
tempStr = "";
}
if (temp != ' ') {
......
......@@ -107,7 +107,7 @@ export class PlayComponent implements OnInit, OnDestroy {
else {
this.data = defaultVal;
}
//console.log('data:', JSON.stringify(data));
console.log('data:', data);
// 初始化 各事件监听
this.initListener();
......@@ -613,9 +613,8 @@ export class PlayComponent implements OnInit, OnDestroy {
let exercises = new Exercises();
exercises.index = index;
exercises.bgWidth = this.canvasWidth;
exercises.init(this.images, this.data.backgroudColor, item, this.mapScale, this.mapScale);
return exercises;
}
......@@ -629,7 +628,7 @@ export class PlayComponent implements OnInit, OnDestroy {
let dH = 35 * this.mapScale;
let w = 1280 * this.mapScale;
let w = this.canvasWidth;
let h = 0 * this.mapScale;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment