Refactor annotation color handling and add unit tests

This commit is contained in:
Tim van der Meij 2015-07-15 16:59:25 +02:00
parent 2817f008c3
commit a2e9845093
3 changed files with 112 additions and 36 deletions

View file

@ -100,12 +100,12 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
// Border color
if (item.color) {
container.style.borderColor =
Util.makeCssRgb(Math.round(item.color[0] * 255),
Math.round(item.color[1] * 255),
Math.round(item.color[2] * 255));
Util.makeCssRgb(item.color[0] | 0,
item.color[1] | 0,
item.color[2] | 0);
} else {
// Default color is black, but that's not obvious from the spec.
container.style.borderColor = 'rgb(0,0,0)';
// Transparent (invisible) border, so do not draw it at all.
container.style.borderWidth = 0;
}
}
@ -172,17 +172,15 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
content.setAttribute('hidden', true);
var i, ii;
if (item.hasBgColor) {
if (item.hasBgColor && item.color) {
var color = item.color;
// Enlighten the color (70%)
var BACKGROUND_ENLIGHT = 0.7;
var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
(g * 255) | 0,
(b * 255) | 0);
var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
content.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
}
var title = document.createElement('h1');