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

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

parent 54e3909a
...@@ -39,7 +39,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -39,7 +39,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
if (data) { if (data) {
this.item = data; this.item = data;
} }
console.log(JSON.stringify(data)); console.log(data);
this.init(); this.init();
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
......
...@@ -12,6 +12,8 @@ export class Exercises { ...@@ -12,6 +12,8 @@ export class Exercises {
index: number; index: number;
bgWidth : number;
bg: ShapeRect; bg: ShapeRect;
answer: ShapeRect; answer: ShapeRect;
...@@ -56,12 +58,11 @@ export class Exercises { ...@@ -56,12 +58,11 @@ export class Exercises {
this.initExercises(); this.initExercises();
let w = 1280 * this.scaleX;
let h = 140 * this.scaleY; let h = 140 * this.scaleY;
h = this.answer.height > h ? this.answer.height : h; 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; this.answer.y = (h - this.answer.height) / 2;
...@@ -189,7 +190,7 @@ export class Exercises { ...@@ -189,7 +190,7 @@ export class Exercises {
text.boldFontName = 'GOTHICB'; text.boldFontName = 'GOTHICB';
text.textArr = getTextArr(); text.textArr = getTextArr();
text.disH = 20; text.disH = 20;
text.maxWidth = 980; text.maxWidth = 1056;
text.setScaleXY(this.scaleX); text.setScaleXY(this.scaleX);
text.refreshSize(); text.refreshSize();
......
...@@ -1193,34 +1193,49 @@ export class RichText extends Label { ...@@ -1193,34 +1193,49 @@ export class RichText extends Label {
let text = this.textArr[i]; let text = this.textArr[i];
let c = this.textArr[i].val; let c = this.textArr[i].val;
if (text.val != ' ') { var re = /\n/;
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 { if (c.match(re)) {
row.push(tempArr); row.push(tempArr);
temp = ' ' + tempStr; temp = ' ' + tempStr;
tempArr = []; tempArr = [];
tempArr.push(getBlank()); tempArr.push(getBlank());
tempArr.push(this.textArr[i]); 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 != ' ') { if (temp != ' ') {
......
...@@ -107,7 +107,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -107,7 +107,7 @@ export class PlayComponent implements OnInit, OnDestroy {
else { else {
this.data = defaultVal; this.data = defaultVal;
} }
//console.log('data:', JSON.stringify(data)); console.log('data:', data);
// 初始化 各事件监听 // 初始化 各事件监听
this.initListener(); this.initListener();
...@@ -613,9 +613,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -613,9 +613,8 @@ export class PlayComponent implements OnInit, OnDestroy {
let exercises = new Exercises(); let exercises = new Exercises();
exercises.index = index; exercises.index = index;
exercises.bgWidth = this.canvasWidth;
exercises.init(this.images, this.data.backgroudColor, item, this.mapScale, this.mapScale); exercises.init(this.images, this.data.backgroudColor, item, this.mapScale, this.mapScale);
return exercises; return exercises;
} }
...@@ -629,7 +628,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -629,7 +628,7 @@ export class PlayComponent implements OnInit, OnDestroy {
let dH = 35 * this.mapScale; let dH = 35 * this.mapScale;
let w = 1280 * this.mapScale; let w = this.canvasWidth;
let h = 0 * this.mapScale; 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