|
8 | 8 |
|
9 | 9 | namespace Contoso.NoteTaker.JSON.Format |
10 | 10 | { |
11 | | - public class InkRecognizerStroke |
12 | | - { |
13 | | - [JsonIgnore] |
14 | | - private InkStroke inkStrokeInternal { get; set; } |
15 | | - |
16 | | - [JsonProperty(PropertyName = "id")] |
17 | | - public UInt64 Id { get { return inkStrokeInternal.Id; } } |
18 | | - |
19 | | - [JsonProperty(PropertyName = "language", NullValueHandling = NullValueHandling.Ignore)] |
20 | | - public string Language { get; set; } = null; |
21 | | - |
22 | | - [JsonProperty(PropertyName ="kind", NullValueHandling = NullValueHandling.Ignore)] |
23 | | - public StrokeKind? Kind { get; set; } = null; |
24 | | - |
25 | | - [JsonProperty(PropertyName = "points"), JsonConverter(typeof(InkPointsToStringConverter))] |
26 | | - public IReadOnlyList<InkPoint> Points { get; protected set; } |
27 | | - |
28 | | - public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY) |
29 | | - { |
30 | | - inkStrokeInternal = stroke; |
31 | | - |
32 | | - var pointsInPixels = inkStrokeInternal.GetInkPoints(); |
33 | | - Points = ConvertPixelsToMillimeters(pointsInPixels, DpiX, DpiY).AsReadOnly(); |
34 | | - } |
35 | | - |
36 | | - private List<InkPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY) |
37 | | - { |
38 | | - var transformedInkPoints = new List<InkPoint>(); |
39 | | - const float inchToMillimeterFactor = 25.4f; |
40 | | - |
41 | | - |
42 | | - foreach (var point in pointsInPixels) |
43 | | - { |
44 | | - var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor; |
45 | | - var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor; |
46 | | - var transformedPoint = new Point(transformedX, transformedY); |
47 | | - var transformedInkPoint = new InkPoint(transformedPoint, point.Pressure); |
48 | | - |
49 | | - transformedInkPoints.Add(transformedInkPoint); |
50 | | - } |
51 | | - |
52 | | - return transformedInkPoints; |
53 | | - } |
| 11 | + public class InkRecognizerPoint |
| 12 | + { |
| 13 | + [JsonIgnore] |
| 14 | + private double x; |
| 15 | + [JsonIgnore] |
| 16 | + private double y; |
| 17 | + [JsonProperty(PropertyName = "x")] |
| 18 | + public double X { get { return x; } } |
| 19 | + |
| 20 | + [JsonProperty(PropertyName = "y")] |
| 21 | + public double Y { get { return y; } } |
| 22 | + |
| 23 | + public InkRecognizerPoint(double x, double y) |
| 24 | + { |
| 25 | + this.x = x; |
| 26 | + this.y = y; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public class InkRecognizerStroke |
| 31 | + { |
| 32 | + [JsonIgnore] |
| 33 | + private InkStroke inkStrokeInternal { get; set; } |
| 34 | + |
| 35 | + [JsonProperty(PropertyName = "id")] |
| 36 | + public UInt64 Id { get { return inkStrokeInternal.Id; } } |
| 37 | + |
| 38 | + [JsonProperty(PropertyName = "language", NullValueHandling = NullValueHandling.Ignore)] |
| 39 | + public string Language { get; set; } = null; |
| 40 | + |
| 41 | + [JsonProperty(PropertyName = "kind", NullValueHandling = NullValueHandling.Ignore)] |
| 42 | + public StrokeKind? Kind { get; set; } = null; |
| 43 | + |
| 44 | + [JsonProperty(PropertyName = "points", NullValueHandling = NullValueHandling.Ignore)] |
| 45 | + public IReadOnlyList<InkRecognizerPoint> Points { get; protected set; } |
| 46 | + |
| 47 | + public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY) |
| 48 | + { |
| 49 | + inkStrokeInternal = stroke; |
| 50 | + |
| 51 | + var pointsInPixels = inkStrokeInternal.GetInkPoints(); |
| 52 | + Points = ConvertPixelsToMillimeters(pointsInPixels, DpiX, DpiY).AsReadOnly(); |
| 53 | + } |
| 54 | + |
| 55 | + private List<InkRecognizerPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY) |
| 56 | + { |
| 57 | + var transformedInkPoints = new List<InkRecognizerPoint>(); |
| 58 | + const float inchToMillimeterFactor = 25.4f; |
| 59 | + |
| 60 | + |
| 61 | + foreach (var point in pointsInPixels) |
| 62 | + { |
| 63 | + var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor; |
| 64 | + var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor; |
| 65 | + var transformedInkPoint = new InkRecognizerPoint(transformedX, transformedY); |
| 66 | + |
| 67 | + transformedInkPoints.Add(transformedInkPoint); |
| 68 | + } |
| 69 | + |
| 70 | + return transformedInkPoints; |
| 71 | + } |
54 | 72 | } |
55 | 73 |
|
56 | 74 | public enum StrokeKind |
|
0 commit comments