66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { BaseDrawService } from '../../../service/baseDraw';
|
|
import { drawCompareContent } from './compareContentDraw';
|
|
|
|
/**
|
|
* 数一数比大小绘制服务
|
|
* 组合使用基础绘制服务和内容区域绘制服务
|
|
*/
|
|
class CompareDraw extends BaseDrawService {
|
|
compareData: {
|
|
problems: Array<{
|
|
leftCount: number;
|
|
rightCount: number;
|
|
leftImageIndex: number;
|
|
rightImageIndex: number;
|
|
imageType: 'fruits' | 'twelve-animals';
|
|
}>;
|
|
} | null;
|
|
|
|
constructor(
|
|
canvas: Canvas,
|
|
ctx: RenderingContext,
|
|
options?: Record<string, any>,
|
|
) {
|
|
super(canvas, ctx, options);
|
|
this.compareData = null;
|
|
}
|
|
|
|
async draw(compareData: {
|
|
problems: Array<{
|
|
leftCount: number;
|
|
rightCount: number;
|
|
leftImageIndex: number;
|
|
rightImageIndex: number;
|
|
imageType: 'fruits' | 'twelve-animals';
|
|
}>;
|
|
}) {
|
|
if (!compareData || !compareData.problems) {
|
|
return;
|
|
}
|
|
|
|
this.setPrintConfig();
|
|
this.compareData = compareData;
|
|
this.clear();
|
|
this.setPaper();
|
|
|
|
// 绘制Header
|
|
if (this.headerType !== 'minimal') {
|
|
await this.drawHeader();
|
|
} else {
|
|
this.drawMiniHeader();
|
|
}
|
|
|
|
// 绘制内容区域(数一数比大小)
|
|
this.drawDivider();
|
|
await drawCompareContent({
|
|
canvas: this.canvas,
|
|
ctx: this.ctx,
|
|
compareData: this.compareData,
|
|
canvasWidth: this.canvasWidth,
|
|
startY: this.currentY,
|
|
});
|
|
}
|
|
}
|
|
|
|
export default CompareDraw;
|