Skip to content

Commit

Permalink
Saving font in text commands
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Mar 8, 2019
1 parent a7ee38e commit 93917bd
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class TextState extends DrawState {

private recordCommandAndReset(imageAnnotator: AiaImageAnnotatorComponent) {
this.currentCommand.setColor(<string>imageAnnotator.drawingCtx.fillStyle);
this.currentCommand.setFont(imageAnnotator.drawingCtx.font);
this.currentCommand.draw(imageAnnotator.drawingCtx);
imageAnnotator.addCommand(this.currentCommand);
this.clearTextBox(imageAnnotator.textBoxRef);
Expand Down Expand Up @@ -184,6 +185,7 @@ export class TextCommand implements DrawCommand {
private position: Point;
private text = '';
private color: string;
private font: string;

constructor(point: Point) {
this.position = point;
Expand All @@ -205,11 +207,18 @@ export class TextCommand implements DrawCommand {
this.color = color;
}

public setFont(font: string) {
this.font = font;
}

public draw(ctx: CanvasRenderingContext2D) {
const currentFillStyle = ctx.fillStyle;
const currentFont = ctx.font;
ctx.fillStyle = this.color;
ctx.font = this.font;
ctx.fillText(this.text, this.position.x, this.position.y);
ctx.fillStyle = currentFillStyle;
ctx.font = currentFont;
}
}

Expand Down

0 comments on commit 93917bd

Please sign in to comment.