feat: 完成三类字母描红开发
This commit is contained in:
@@ -4,29 +4,29 @@ import type {
|
||||
LetterTracingData,
|
||||
HighlightGrid,
|
||||
} from '../generators/letter-tracing-generator';
|
||||
import { fontFamilyOf } from '../data/fontProfiles';
|
||||
import {
|
||||
calcLetterFontSizes,
|
||||
drawFourLineGrid,
|
||||
drawLetterInFourLineGrid,
|
||||
FOUR_LINE_GRID_H,
|
||||
getLetterFontSize,
|
||||
TOY_FONT_LETTER,
|
||||
type LetterFontSizes,
|
||||
} from './drawTools';
|
||||
|
||||
const LINE_INK_ALPHA = 'rgba(50, 46, 37, 1)';
|
||||
const ACCENT_RED = 'rgba(252, 46, 0, 1)';
|
||||
//'Helvetica, Arial, "Segoe UI", Roboto, sans-serif';
|
||||
const LETTER_FACE = `${TOY_FONT_LETTER}, Roboto, sans-serif`;
|
||||
// const TITLE_EMOJI_FONT =
|
||||
// "16px 'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif";
|
||||
const TITLE_TEXT_FONT = '14px sans-serif';
|
||||
const TITLE_ICON_GAP = 4;
|
||||
|
||||
type PictureData = Extract<LetterTracingData, { mode: 'picture-tracing' }>;
|
||||
|
||||
export default class PictureTracingDraw extends BaseDrawService {
|
||||
private letterSizes: LetterFontSizes = calcLetterFontSizes(FOUR_LINE_GRID_H);
|
||||
private letterSizes: LetterFontSizes =
|
||||
calcLetterFontSizes(FOUR_LINE_GRID_H);
|
||||
private get letterFace(): string {
|
||||
return fontFamilyOf(this.letterSizes._profile);
|
||||
}
|
||||
|
||||
async draw(data: PictureData) {
|
||||
this.prepareDraw();
|
||||
@@ -68,7 +68,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
dh,
|
||||
);
|
||||
} catch {
|
||||
ctx.font = `bold 60px ${LETTER_FACE}`;
|
||||
ctx.font = `bold 60px ${this.letterFace}`;
|
||||
ctx.fillStyle = '#111';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
@@ -195,11 +195,11 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
const pairGap = 3;
|
||||
|
||||
const upperFs = getLetterFontSize(upper, sizes);
|
||||
ctx.font = `${upperFs}px ${LETTER_FACE}`;
|
||||
ctx.font = `${upperFs}px ${this.letterFace}`;
|
||||
const upperW = ctx.measureText(upper).width;
|
||||
|
||||
const lowerFs = getLetterFontSize(lower, sizes);
|
||||
ctx.font = `${lowerFs}px ${LETTER_FACE}`;
|
||||
ctx.font = `${lowerFs}px ${this.letterFace}`;
|
||||
const lowerW = ctx.measureText(lower).width;
|
||||
|
||||
const totalPairW = upperW + pairGap + lowerW;
|
||||
@@ -213,7 +213,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
y,
|
||||
FOUR_LINE_GRID_H,
|
||||
sizes,
|
||||
{ fontFamily: LETTER_FACE, color },
|
||||
{ fontFamily: this.letterFace, color },
|
||||
);
|
||||
drawLetterInFourLineGrid(
|
||||
ctx,
|
||||
@@ -222,7 +222,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
y,
|
||||
FOUR_LINE_GRID_H,
|
||||
sizes,
|
||||
{ fontFamily: LETTER_FACE, color },
|
||||
{ fontFamily: this.letterFace, color },
|
||||
);
|
||||
|
||||
ctx.restore();
|
||||
@@ -235,7 +235,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
y: number,
|
||||
) {
|
||||
const ctx = this.ctx;
|
||||
ctx.font = `36px ${LETTER_FACE}`;
|
||||
ctx.font = `36px ${this.letterFace}`;
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'top';
|
||||
|
||||
@@ -286,7 +286,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
ctx.setLineDash([]);
|
||||
ctx.strokeRect(cx, cy, cellSize, cellSize);
|
||||
|
||||
ctx.font = `18px ${LETTER_FACE}`;
|
||||
ctx.font = `18px ${this.letterFace}`;
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
@@ -380,7 +380,7 @@ export default class PictureTracingDraw extends BaseDrawService {
|
||||
);
|
||||
} catch {
|
||||
const fs = Math.min(imgH * 0.6, imgW * 0.18);
|
||||
ctx.font = `bold ${fs}px ${LETTER_FACE}`;
|
||||
ctx.font = `bold ${fs}px ${this.letterFace}`;
|
||||
ctx.fillStyle = '#222';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
|
||||
Reference in New Issue
Block a user