Skip to content

Commit

Permalink
JS -- Implement app object
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Nov 20, 2020
1 parent c88e805 commit 283aac4
Show file tree
Hide file tree
Showing 12 changed files with 1,259 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import {
addLinkAttributes,
ColorConverters,
DOMSVGFactory,
getFilenameFromUrl,
LinkTarget,
Expand Down Expand Up @@ -567,6 +568,12 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
event.target.setSelectionRange(selStart, selEnd);
}
},
strokeColor() {
const color = detail.strokeColor;
event.target.style.color = ColorConverters[`${color[0]}_HTML`](
color.slice(1)
);
},
};
for (const name of Object.keys(detail)) {
if (name in actions) {
Expand Down
54 changes: 54 additions & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,59 @@ class PDFDateString {
}
}

function makeColorComp(n) {
return Math.floor(Math.max(0, Math.min(1, n)) * 255)
.toString(16)
.padStart(2, "0");
}

const ColorConverters = {
// PDF specifications section 10.3
CMYK_G([c, y, m, k]) {
return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
},
G_CMYK([g]) {
return ["CMYK", 0, 0, 0, 1 - g];
},
G_RGB([g]) {
return ["RGB", g, g, g];
},
G_HTML([g]) {
const G = makeColorComp(g);
return `#${G}${G}${G}`;
},
RGB_G([r, g, b]) {
return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
},
RGB_HTML([r, g, b]) {
const R = makeColorComp(r);
const G = makeColorComp(g);
const B = makeColorComp(b);
return `#${R}${G}${B}`;
},
T_HTML() {
return "#00000000";
},
CMYK_RGB([c, y, m, k]) {
return [
"RGB",
1 - Math.min(1, c + k),
1 - Math.min(1, m + k),
1 - Math.min(1, y + k),
];
},
CMYK_HTML(components) {
return ColorConverters.RGB_HTML(ColorConverters.CMYK_RGB(components));
},
RGB_CMYK([r, g, b]) {
const c = 1 - r;
const m = 1 - g;
const y = 1 - b;
const k = Math.min(c, m, y);
return ["CMYK", c, m, y, k];
},
};

export {
PageViewport,
RenderingCancelledException,
Expand All @@ -645,6 +698,7 @@ export {
BaseCanvasFactory,
DOMCanvasFactory,
BaseCMapReaderFactory,
ColorConverters,
DOMCMapReaderFactory,
DOMSVGFactory,
StatTimer,
Expand Down
Loading

0 comments on commit 283aac4

Please sign in to comment.