1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Merge pull request #8950 from timvandermeij/polygon-polyline-annotations

Implement support for polyline and polygon annotations
This commit is contained in:
Jonas Jenwald 2017-09-24 15:16:14 +02:00 committed by GitHub
commit 10727572a2
6 changed files with 125 additions and 1 deletions

View file

@ -87,6 +87,12 @@ class AnnotationFactory {
case 'Circle':
return new CircleAnnotation(parameters);
case 'PolyLine':
return new PolylineAnnotation(parameters);
case 'Polygon':
return new PolygonAnnotation(parameters);
case 'Highlight':
return new HighlightAnnotation(parameters);
@ -913,6 +919,39 @@ class CircleAnnotation extends Annotation {
}
}
class PolylineAnnotation extends Annotation {
constructor(parameters) {
super(parameters);
this.data.annotationType = AnnotationType.POLYLINE;
// The vertices array is an array of numbers representing the alternating
// horizontal and vertical coordinates, respectively, of each vertex.
// Convert this to an array of objects with x and y coordinates.
let dict = parameters.dict;
let rawVertices = dict.getArray('Vertices');
this.data.vertices = [];
for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
this.data.vertices.push({
x: rawVertices[i],
y: rawVertices[i + 1],
});
}
this._preparePopup(dict);
}
}
class PolygonAnnotation extends PolylineAnnotation {
constructor(parameters) {
// Polygons are specific forms of polylines, so reuse their logic.
super(parameters);
this.data.annotationType = AnnotationType.POLYGON;
}
}
class HighlightAnnotation extends Annotation {
constructor(parameters) {
super(parameters);