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

harmonize color regex & ignore SVG default black #327

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 bwipjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ var optlist = [
'non-data function characters can be specified by escaped combinations such\n' +
'as ^FNC1, ^FNC4 and ^SFT.' },
{ name: 'height', type: 'float',
desc: 'Height of longest bar, in millimetermillimeters.' },
desc: 'Height of longest bar, in millimetermillimeters. Default is 25.4.' },
{ name: 'width', type: 'float',
desc: 'Stretch the symbol to precisely this width, in millimeters.' },
desc: 'Stretch the symbol to precisely this width, in millimeters. Default is 0.' },
{ name: 'inkspread', type: 'float',
desc: 'Amount by which to reduce the bar widths to compensate for inkspread,\n' +
'in points.' },
Expand Down
25 changes: 12 additions & 13 deletions src/drawing-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function DrawingSVG() {

var opts;
var svg = '';
var path;
var path = '';
var clipid = '';
var clips = [];
var lines = {};
Expand Down Expand Up @@ -138,9 +138,6 @@ function DrawingSVG() {
// orthogonal shapes.
// You will see a series of polygon() calls, followed by a fill().
polygon(pts) {
if (!path) {
path = '<path d="';
}
path += 'M' + transform(pts[0][0], pts[0][1]);
for (var i = 1, n = pts.length; i < n; i++) {
var p = pts[i];
Expand All @@ -160,9 +157,6 @@ function DrawingSVG() {
// to create the bullseye rings. dotcode issues all of its ellipses then a
// fill().
ellipse(x, y, rx, ry, ccw) {
if (!path) {
path = '<path d="';
}
var dx = rx * ELLIPSE_MAGIC;
var dy = ry * ELLIPSE_MAGIC;

Expand All @@ -186,10 +180,12 @@ function DrawingSVG() {
// regions so use even-odd as it is easier to work with.
fill(rgb) {
if (path) {
svg += path + '" fill="#' + rgb + '" fill-rule="evenodd"' +
(clipid ? ' clip-path="url(#' + clipid + ')"' : '') +
' />\n';
path = null;
// Ignore `fill` "black" if BG is "transparent"
svg += '<path d="' + path + '"' +
(!opts.hasOwnProperty('backgroundcolor') && /^0{6}$/.test(''+rgb) ? '' : ' fill="#' + rgb + '"') +
(clipid ? ' clip-path="url(#' + clipid + ')"' : '') +
' fill-rule="evenodd" />\n';
path = '';
}
},
// Currently only used by swissqrcode. The `polys` area is an array of
Expand Down Expand Up @@ -255,7 +251,10 @@ function DrawingSVG() {
x += glyph.advance + dx;
}
if (path) {
svg += '<path d="' + path + '" fill="#' + rgb + '" />\n';
// Ignore `fill` "black" if BG is "transparent"
svg += '<path d="' + path + '"' +
(!opts.hasOwnProperty('backgroundcolor') && /^0{6}$/.test(''+rgb) ? '' : ' fill="#' + rgb + '"') +
' />\n';
}
},
// Called after all drawing is complete. The return value from this method
Expand All @@ -268,7 +267,7 @@ function DrawingSVG() {
var bg = opts.backgroundcolor;
return '<svg viewBox="0 0 ' + gs_width + ' ' + gs_height + '" xmlns="http://www.w3.org/2000/svg">\n' +
(clips.length ? '<defs>' + clips.join('') + '</defs>' : '') +
(/^[0-9A-Fa-f]{6}$/.test(''+bg)
(/^[0-9a-fA-F]{6}$/.test(''+bg)
? '<rect width="100%" height="100%" fill="#' + bg + '" />\n'
: '') +
linesvg + svg + '</svg>\n';
Expand Down