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

Replace css color rgb(...) by #... #12555

Merged
merged 1 commit into from
Nov 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
4 changes: 2 additions & 2 deletions src/core/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
ratio[0] = t0 + i * step;
fn(ratio, 0, color, 0);
rgbColor = cs.getRgb(color, 0);
var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
var cssColor = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
}

var background = "transparent";
if (dict.has("Background")) {
rgbColor = cs.getRgb(dict.get("Background"), 0);
background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
}

if (!extendStart) {
Expand Down
4 changes: 2 additions & 2 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class AnnotationElement {
}

if (data.color) {
container.style.borderColor = Util.makeCssRgb(
container.style.borderColor = Util.makeHexColor(
data.color[0] | 0,
data.color[1] | 0,
data.color[2] | 0
Expand Down Expand Up @@ -860,7 +860,7 @@ class PopupElement {
const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
popup.style.backgroundColor = Util.makeHexColor(r | 0, g | 0, b | 0);
}

const title = document.createElement("h1");
Expand Down
4 changes: 2 additions & 2 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1951,12 +1951,12 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.patternFill = true;
},
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
const color = Util.makeCssRgb(r, g, b);
const color = Util.makeHexColor(r, g, b);
this.ctx.strokeStyle = color;
this.current.strokeColor = color;
},
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
const color = Util.makeCssRgb(r, g, b);
const color = Util.makeHexColor(r, g, b);
this.ctx.fillStyle = color;
this.current.fillColor = color;
this.current.patternFill = false;
Expand Down
2 changes: 1 addition & 1 deletion src/display/pattern_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const TilingPattern = (function TilingPatternClosure() {
current.strokeColor = ctx.strokeStyle;
break;
case PaintType.UNCOLORED:
const cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
const cssColor = Util.makeHexColor(color[0], color[1], color[2]);
context.fillStyle = cssColor;
context.strokeStyle = cssColor;
// Set color needed by image masks (fixes issues 3226 and 8741).
Expand Down
6 changes: 3 additions & 3 deletions src/display/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,15 +1049,15 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
}

setStrokeRGBColor(r, g, b) {
this.current.strokeColor = Util.makeCssRgb(r, g, b);
this.current.strokeColor = Util.makeHexColor(r, g, b);
}

setFillAlpha(fillAlpha) {
this.current.fillAlpha = fillAlpha;
}

setFillRGBColor(r, g, b) {
this.current.fillColor = Util.makeCssRgb(r, g, b);
this.current.fillColor = Util.makeHexColor(r, g, b);
this.current.tspan = this.svgFactory.createElement("svg:tspan");
this.current.xcoords = [];
this.current.ycoords = [];
Expand Down Expand Up @@ -1143,7 +1143,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this.svg = bbox;
this.transformMatrix = matrix;
if (paintType === 2) {
const cssColor = Util.makeCssRgb(...color);
const cssColor = Util.makeHexColor(...color);
this.current.fillColor = cssColor;
this.current.strokeColor = cssColor;
}
Expand Down
13 changes: 5 additions & 8 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,13 @@ const IsEvalSupportedCached = {
},
};

const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
const hexNumbers = [...Array(256).keys()].map(n =>
n.toString(16).padStart(2, "0")
);

class Util {
// makeCssRgb() can be called thousands of times. Using ´rgbBuf` avoids
// creating many intermediate strings.
static makeCssRgb(r, g, b) {
rgbBuf[1] = r;
rgbBuf[3] = g;
rgbBuf[5] = b;
return rgbBuf.join("");
static makeHexColor(r, g, b) {
return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
}

// Concatenates two transformation matrices together and returns the result.
Expand Down