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

Refactor annotation flags code

This patch makes it possible to set and get all possible flags that the PDF specification defines. Even though we do not support all possible annotation types and not all possible annotation flags yet, this general framework makes it easy to access all flags for each annotation such that annotation type implementations can use this information.

We add constants for all possible annotation flags such that we do not need to hardcode the flags in the code anymore. The `isViewable()` and `isPrintable()` methods are now easier to read. Additionally, unit tests have been added to ensure correct behavior.

This is another part of #5218.
This commit is contained in:
Tim van der Meij 2015-11-21 23:25:17 +01:00
parent df46b64045
commit 0991c06395
4 changed files with 107 additions and 44 deletions

View file

@ -1,10 +1,31 @@
/* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
AnnotationBorderStyleType */
AnnotationBorderStyleType, AnnotationFlag */
'use strict';
describe('Annotation layer', function() {
describe('Annotation', function() {
it('should set and get flags', function() {
var dict = new Dict();
dict.set('Subtype', '');
var annotation = new Annotation({ dict: dict, ref: 0 });
annotation.setFlags(13);
expect(annotation.hasFlag(AnnotationFlag.INVISIBLE)).toEqual(true);
expect(annotation.hasFlag(AnnotationFlag.NOZOOM)).toEqual(true);
expect(annotation.hasFlag(AnnotationFlag.PRINT)).toEqual(true);
expect(annotation.hasFlag(AnnotationFlag.READONLY)).toEqual(false);
});
it('should be viewable and not printable by default', function() {
var dict = new Dict();
dict.set('Subtype', '');
var annotation = new Annotation({ dict: dict, ref: 0 });
expect(annotation.viewable).toEqual(true);
expect(annotation.printable).toEqual(false);
});
it('should set and get a valid rectangle', function() {
var dict = new Dict();
dict.set('Subtype', '');