mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 00:28:06 +02:00
Add the color changes in the annotation storage
This commit is contained in:
parent
7ae5a0fef7
commit
d16d1f0d23
4 changed files with 57 additions and 12 deletions
|
@ -331,9 +331,13 @@ class AnnotationElement {
|
|||
get _commonActions() {
|
||||
const setColor = (jsName, styleName, event) => {
|
||||
const color = event.detail[jsName];
|
||||
event.target.style[styleName] = ColorConverters[`${color[0]}_HTML`](
|
||||
color.slice(1)
|
||||
);
|
||||
const colorType = color[0];
|
||||
const colorArray = color.slice(1);
|
||||
event.target.style[styleName] =
|
||||
ColorConverters[`${colorType}_HTML`](colorArray);
|
||||
this.annotationStorage.setValue(this.data.id, {
|
||||
[styleName]: ColorConverters[`${colorType}_rgb`](colorArray),
|
||||
});
|
||||
};
|
||||
|
||||
return shadow(this, "_commonActions", {
|
||||
|
|
|
@ -26,6 +26,10 @@ function makeColorComp(n) {
|
|||
.padStart(2, "0");
|
||||
}
|
||||
|
||||
function scaleAndClamp(x) {
|
||||
return Math.max(0, Math.min(255, 255 * x));
|
||||
}
|
||||
|
||||
// PDF specifications section 10.3
|
||||
class ColorConverters {
|
||||
static CMYK_G([c, y, m, k]) {
|
||||
|
@ -40,6 +44,11 @@ class ColorConverters {
|
|||
return ["RGB", g, g, g];
|
||||
}
|
||||
|
||||
static G_rgb([g]) {
|
||||
g = scaleAndClamp(g);
|
||||
return [g, g, g];
|
||||
}
|
||||
|
||||
static G_HTML([g]) {
|
||||
const G = makeColorComp(g);
|
||||
return `#${G}${G}${G}`;
|
||||
|
@ -49,17 +58,22 @@ class ColorConverters {
|
|||
return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
|
||||
}
|
||||
|
||||
static RGB_HTML([r, g, b]) {
|
||||
const R = makeColorComp(r);
|
||||
const G = makeColorComp(g);
|
||||
const B = makeColorComp(b);
|
||||
return `#${R}${G}${B}`;
|
||||
static RGB_rgb(color) {
|
||||
return color.map(scaleAndClamp);
|
||||
}
|
||||
|
||||
static RGB_HTML(color) {
|
||||
return `#${color.map(makeColorComp).join("")}`;
|
||||
}
|
||||
|
||||
static T_HTML() {
|
||||
return "#00000000";
|
||||
}
|
||||
|
||||
static T_rgb() {
|
||||
return [null];
|
||||
}
|
||||
|
||||
static CMYK_RGB([c, y, m, k]) {
|
||||
return [
|
||||
"RGB",
|
||||
|
@ -69,6 +83,14 @@ class ColorConverters {
|
|||
];
|
||||
}
|
||||
|
||||
static CMYK_rgb([c, y, m, k]) {
|
||||
return [
|
||||
scaleAndClamp(1 - Math.min(1, c + k)),
|
||||
scaleAndClamp(1 - Math.min(1, m + k)),
|
||||
scaleAndClamp(1 - Math.min(1, y + k)),
|
||||
];
|
||||
}
|
||||
|
||||
static CMYK_HTML(components) {
|
||||
const rgb = this.CMYK_RGB(components).slice(1);
|
||||
return this.RGB_HTML(rgb);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue