Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 2117fd4

Browse files
committed
[DEV] InkRanges workaround in shape rendering
1 parent f7f03c5 commit 2117fd4

File tree

6 files changed

+72
-38
lines changed

6 files changed

+72
-38
lines changed

dist/myscript.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5274,9 +5274,14 @@ MyScript = {
52745274
*/
52755275
function ShapeDocument(obj) {
52765276
this.segments = [];
5277+
this.inkRanges = [];
52775278
if (obj) {
52785279
for (var i in obj.segments) {
52795280
this.segments.push(new scope.ShapeSegment(obj.segments[i]));
5281+
for(j in this.segments[i].getInkRanges()){
5282+
this.inkRanges.push(this.segments[i].getInkRanges()[j]);
5283+
}
5284+
52805285
}
52815286
}
52825287
}
@@ -5298,11 +5303,7 @@ MyScript = {
52985303
* @returns {ShapeInkRange[]}
52995304
*/
53005305
ShapeDocument.prototype.getInkRanges = function () {
5301-
var inkRanges = [];
5302-
for (var i in this.segments) {
5303-
inkRanges = inkRanges.concat(this.segments[i].getInkRanges());
5304-
}
5305-
return inkRanges;
5306+
return this.inkRanges;
53065307
};
53075308

53085309
/**
@@ -12256,6 +12257,7 @@ MyScript = {
1225612257
*/
1225712258
function ShapeRenderer(context) {
1225812259
scope.AbstractRenderer.call(this, context);
12260+
this.inkRanges = [];
1225912261
}
1226012262

1226112263
/**
@@ -12279,16 +12281,7 @@ MyScript = {
1227912281
this.clear();
1228012282
if (document && (document instanceof scope.ShapeDocument)) {
1228112283
this.drawShapes(components, document.getSegments());
12282-
var lastComponents = [];
12283-
var processedComponents = _extractComponents(components, document.getInkRanges());
12284-
12285-
for (var i in components) {
12286-
var component = components[i];
12287-
if (processedComponents.indexOf(component) !== -1) {
12288-
lastComponents.push(component);
12289-
}
12290-
}
12291-
this.drawComponents(lastComponents);
12284+
this.drawShapesNotYetRecognized(components, document.getInkRanges());
1229212285
} else {
1229312286
this.drawComponents(components);
1229412287
}
@@ -12326,6 +12319,30 @@ MyScript = {
1232612319
}
1232712320
};
1232812321

12322+
ShapeRenderer.prototype.drawShapesNotYetRecognized = function (components, inkRanges){
12323+
for (var k in inkRanges) {
12324+
this.inkRanges.push(inkRanges[k]);
12325+
}
12326+
function contains(a, obj) {
12327+
var i = a.length;
12328+
while (i--) {
12329+
if (JSON.stringify(a[i]) === JSON.stringify(obj)) {
12330+
return true;
12331+
}
12332+
}
12333+
return false;
12334+
}
12335+
12336+
var lastComponents = [];
12337+
for (var i in components) {
12338+
var component = components[i];
12339+
if (!contains(_extractComponents(components, this.inkRanges), component)) {
12340+
lastComponents.push(component);
12341+
}
12342+
}
12343+
this.drawComponents(lastComponents);
12344+
};
12345+
1232912346
/**
1233012347
* Draw shape segment
1233112348
*

dist/myscript.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/myscript.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/myscript.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/output/shape/shapeDocument.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
*/
1111
function ShapeDocument(obj) {
1212
this.segments = [];
13+
this.inkRanges = [];
1314
if (obj) {
1415
for (var i in obj.segments) {
1516
this.segments.push(new scope.ShapeSegment(obj.segments[i]));
17+
for(j in this.segments[i].getInkRanges()){
18+
this.inkRanges.push(this.segments[i].getInkRanges()[j]);
19+
}
20+
1621
}
1722
}
1823
}
@@ -34,11 +39,7 @@
3439
* @returns {ShapeInkRange[]}
3540
*/
3641
ShapeDocument.prototype.getInkRanges = function () {
37-
var inkRanges = [];
38-
for (var i in this.segments) {
39-
inkRanges = inkRanges.concat(this.segments[i].getInkRanges());
40-
}
41-
return inkRanges;
42+
return this.inkRanges;
4243
};
4344

4445
/**

src/rendering/shapeRenderer.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
function ShapeRenderer(context) {
1313
scope.AbstractRenderer.call(this, context);
14+
this.inkRanges = [];
1415
}
1516

1617
/**
@@ -34,16 +35,7 @@
3435
this.clear();
3536
if (document && (document instanceof scope.ShapeDocument)) {
3637
this.drawShapes(components, document.getSegments());
37-
var lastComponents = [];
38-
var processedComponents = _extractComponents(components, document.getInkRanges());
39-
40-
for (var i in components) {
41-
var component = components[i];
42-
if (processedComponents.indexOf(component) !== -1) {
43-
lastComponents.push(component);
44-
}
45-
}
46-
this.drawComponents(lastComponents);
38+
this.drawShapesNotYetRecognized(components, document.getInkRanges());
4739
} else {
4840
this.drawComponents(components);
4941
}
@@ -81,6 +73,30 @@
8173
}
8274
};
8375

76+
ShapeRenderer.prototype.drawShapesNotYetRecognized = function (components, inkRanges){
77+
for (var k in inkRanges) {
78+
this.inkRanges.push(inkRanges[k]);
79+
}
80+
function contains(a, obj) {
81+
var i = a.length;
82+
while (i--) {
83+
if (JSON.stringify(a[i]) === JSON.stringify(obj)) {
84+
return true;
85+
}
86+
}
87+
return false;
88+
}
89+
90+
var lastComponents = [];
91+
for (var i in components) {
92+
var component = components[i];
93+
if (!contains(_extractComponents(components, this.inkRanges), component)) {
94+
lastComponents.push(component);
95+
}
96+
}
97+
this.drawComponents(lastComponents);
98+
};
99+
84100
/**
85101
* Draw shape segment
86102
*

0 commit comments

Comments
 (0)