Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS -- Implement app object #12631

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters that much for how this will be used, but we do have a bunch of colorspace conversion code that does a better job than the simplistic conversions given by the spec: https://github.com/mozilla/pdf.js/blob/master/src/core/colorspace.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that but afaik the end goal is to be able to set a color in a textfield or whatever I think too that it doesn't matter.
FYI, pdfium code does the same here.

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