diff options
author | bob <bcz@cs.brown.edu> | 2019-03-08 09:21:07 -0500 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-03-08 09:21:07 -0500 |
commit | 58a189d13061cdf4b7561c30bad9e1230a57eeff (patch) | |
tree | b3c436704fa9e44f0cde010d4c969fc3b59e382e /src/fields/InkField.ts | |
parent | 22d7f22a60a17373a6e453e09cc616f651c11a9e (diff) | |
parent | c0d9d7fbac952329d97ddc5c6f96fb02d9ab42f3 (diff) |
Merge branch 'master' into PDFNode
Diffstat (limited to 'src/fields/InkField.ts')
-rw-r--r-- | src/fields/InkField.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts new file mode 100644 index 000000000..a475e2aae --- /dev/null +++ b/src/fields/InkField.ts @@ -0,0 +1,47 @@ +import { BasicField } from "./BasicField"; +import { Types } from "../server/Message"; +import { FieldId } from "./Field"; + +export enum InkTool { + None, + Pen, + Highlighter, + Eraser +} +export interface StrokeData { + pathData: Array<{ x: number, y: number }>; + color: string; + width: string; + tool: InkTool; +} +export type StrokeMap = Map<string, StrokeData>; + +export class InkField extends BasicField<StrokeMap> { + constructor(data: StrokeMap = new Map, id?: FieldId, save: boolean = true) { + super(data, save, id); + } + + ToScriptString(): string { + return `new InkField("${this.Data}")`; + } + + Copy() { + return new InkField(this.Data); + } + + ToJson(): { _id: string; type: Types; data: any; } { + return { + type: Types.Ink, + data: this.Data, + _id: this.Id, + } + } + + static FromJson(id: string, data: any): InkField { + let map = new Map<string, StrokeData>(); + Object.keys(data).forEach(key => { + map.set(key, data[key]); + }); + return new InkField(map, id, false); + } +}
\ No newline at end of file |