From 7e18d27de76bd2b58281841910aee3c4829269dd Mon Sep 17 00:00:00 2001
From: yunahi <60233430+yunahi@users.noreply.github.com>
Date: Thu, 6 Aug 2020 00:21:23 +0900
Subject: fixed bugs after testing

---
 src/client/views/InkingStroke.tsx | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

(limited to 'src/client/views/InkingStroke.tsx')

diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx
index 8e3f72cee..fe5bf1eb2 100644
--- a/src/client/views/InkingStroke.tsx
+++ b/src/client/views/InkingStroke.tsx
@@ -18,6 +18,8 @@ import { Doc } from "../../fields/Doc";
 import FormatShapePane from "./collections/collectionFreeForm/FormatShapePane";
 import { action } from "mobx";
 import { setupMoveUpEvents } from "../../Utils";
+import { undoBatch, UndoManager } from "../util/UndoManager";
+
 
 library.add(faPaintBrush);
 
@@ -26,8 +28,12 @@ const InkDocument = makeInterface(documentSchema);
 
 @observer
 export class InkingStroke extends ViewBoxBaseComponent<FieldViewProps, InkDocument>(InkDocument) {
+    private _controlUndo?: UndoManager.Batch;
+
     public static LayoutString(fieldStr: string) { return FieldView.LayoutString(InkingStroke, fieldStr); }
 
+
+
     private analyzeStrokes = () => {
         const data: InkData = Cast(this.dataDoc[this.fieldKey], InkField)?.inkData ?? [];
         CognitiveServices.Inking.Appliers.ConcatenateHandwriting(this.dataDoc, ["inkAnalysis", "handwriting"], [data]);
@@ -52,6 +58,7 @@ export class InkingStroke extends ViewBoxBaseComponent<FieldViewProps, InkDocume
     @action
     onControlDown = (e: React.PointerEvent, i: number): void => {
         setupMoveUpEvents(this, e, this.onControlMove, this.onControlup, (e) => { });
+        this._controlUndo = UndoManager.StartBatch("DocDecs set radius");
         this._prevX = e.clientX;
         this._prevY = e.clientY;
         this._controlNum = i;
@@ -76,6 +83,8 @@ export class InkingStroke extends ViewBoxBaseComponent<FieldViewProps, InkDocume
         this._prevX = 0;
         this._prevY = 0;
         this._controlNum = 0;
+        this._controlUndo?.end();
+        this._controlUndo = undefined;
     }
 
     public static MaskDim = 50000;
@@ -125,18 +134,17 @@ export class InkingStroke extends ViewBoxBaseComponent<FieldViewProps, InkDocume
             }
             handleLine.push({ X1: data[data.length - 2].X, Y1: data[data.length - 2].Y, X2: data[data.length - 1].X, Y2: data[data.length - 1].Y, X3: data[data.length - 1].X, Y3: data[data.length - 1].Y, dot1: data.length - 1, dot2: data.length - 1 });
 
-
-        }
-        if (data.length <= 4) {
-            handlePoints = [];
-            handleLine = [];
-            controlPoints = [];
-            for (var i = 0; i < data.length; i++) {
-                controlPoints.push({ X: data[i].X, Y: data[i].Y, I: i });
-            }
-
         }
-        const dotsize = String(Math.min(width * scaleX, height * scaleY) / 40);
+        // if (data.length <= 4) {
+        //     handlePoints = [];
+        //     handleLine = [];
+        //     controlPoints = [];
+        //     for (var i = 0; i < data.length; i++) {
+        //         controlPoints.push({ X: data[i].X, Y: data[i].Y, I: i });
+        //     }
+
+        // }
+        const dotsize = String(Math.max(width * scaleX, height * scaleY) / 40);
 
         const controls = controlPoints.map((pts, i) =>
 
-- 
cgit v1.2.3-70-g09d2


From ffa36a87eb1093883dcc80128b08d24d2440f75a Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Wed, 5 Aug 2020 13:01:52 -0400
Subject: fixed perfectly horizontal/vertical lines to display.  make InkFields
 script editable.

---
 src/client/util/type_decls.d             | 5 +++++
 src/client/views/DocumentDecorations.tsx | 2 --
 src/client/views/InkingStroke.tsx        | 8 ++++----
 src/fields/InkField.ts                   | 5 ++++-
 4 files changed, 13 insertions(+), 7 deletions(-)

(limited to 'src/client/views/InkingStroke.tsx')

diff --git a/src/client/util/type_decls.d b/src/client/util/type_decls.d
index 08aec3724..ab6c94f83 100644
--- a/src/client/util/type_decls.d
+++ b/src/client/util/type_decls.d
@@ -187,6 +187,11 @@ declare class List<T extends Field> extends ObjectField {
     [Copy](): ObjectField;
 }
 
+declare class InkField extends ObjectField {
+    constructor(data:Array<{X:number, Y:number}>);
+    [Copy](): ObjectField;
+}
+
 // @ts-ignore
 declare const console: any;
 
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx
index 1ae7d6617..005df6fe0 100644
--- a/src/client/views/DocumentDecorations.tsx
+++ b/src/client/views/DocumentDecorations.tsx
@@ -68,8 +68,6 @@ export class DocumentDecorations extends React.Component<{}, { value: string }>
     private _prevY = 0;
     private _centerPoints: { X: number, Y: number }[] = [];
     private _inkDocs: { x: number, y: number, width: number, height: number }[] = [];
-    private _natWid = 0;
-    private _natHei = 0;
 
     @observable private _accumulatedTitle = "";
     @observable private _titleControlString: string = "#title";
diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx
index fe5bf1eb2..6c5eda256 100644
--- a/src/client/views/InkingStroke.tsx
+++ b/src/client/views/InkingStroke.tsx
@@ -99,10 +99,10 @@ export class InkingStroke extends ViewBoxBaseComponent<FieldViewProps, InkDocume
         const top = Math.min(...ys) - strokeWidth / 2;
         const right = Math.max(...xs) + strokeWidth / 2;
         const bottom = Math.max(...ys) + strokeWidth / 2;
-        const width = right - left;
-        const height = bottom - top;
-        const scaleX = (this.props.PanelWidth() - strokeWidth) / (width - strokeWidth);
-        const scaleY = (this.props.PanelHeight() - strokeWidth) / (height - strokeWidth);
+        const width = Math.max(right - left);
+        const height = Math.max(1, bottom - top);
+        const scaleX = width === strokeWidth ? 1 : (this.props.PanelWidth() - strokeWidth) / (width - strokeWidth);
+        const scaleY = height === strokeWidth ? 1 : (this.props.PanelHeight() - strokeWidth) / (height - strokeWidth);
         const strokeColor = StrCast(this.layoutDoc.color, "");
 
         const points = InteractionUtils.CreatePolyline(data, left, top, strokeColor, strokeWidth, strokeWidth,
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts
index 7cfd74cc4..dbe51b24a 100644
--- a/src/fields/InkField.ts
+++ b/src/fields/InkField.ts
@@ -2,6 +2,7 @@ import { Deserializable } from "../client/util/SerializationHelper";
 import { serializable, custom, createSimpleSchema, list, object, map } from "serializr";
 import { ObjectField } from "./ObjectField";
 import { Copy, ToScriptString, ToString, Update } from "./FieldSymbols";
+import { Scripting } from "../client/util/Scripting";
 
 export enum InkTool {
     None = "none",
@@ -44,9 +45,11 @@ export class InkField extends ObjectField {
     }
 
     [ToScriptString]() {
-        return "invalid";
+        return "new InkField([" + this.inkData.map(i => `{X: ${i.X}, Y: ${i.Y}} `) + "])";
     }
     [ToString]() {
         return "InkField";
     }
 }
+
+Scripting.addGlobal("InkField", InkField);
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

