[reportlab-users] QRCodeWidget ignores the barFillColor parameter
Lele Gaifax
lele at metapensiero.it
Sun May 31 05:30:16 EDT 2020
Hi,
needing to draw a QRCode painted in white on a dark background, I see that the
method QRCodeWidget.add() ignores the color passed as "barFillColor". I had to
change it like below (see comment "# LG: "):
def draw(self):
self.qr.make()
g = Group()
color = self.barFillColor
border = self.barBorder
width = self.barWidth
height = self.barHeight
x = self.x
y = self.y
g.add(SRect(x, y, width, height, fillColor=None))
moduleCount = self.qr.getModuleCount()
minwh = float(min(width, height))
boxsize = minwh / (moduleCount + border * 2.0)
offsetX = x + (width - minwh) / 2.0
offsetY = y + (minwh - height) / 2.0
for r, row in enumerate(self.qr.modules):
row = map(bool, row)
c = 0
for t, tt in itertools.groupby(row):
isDark = t
count = len(list(tt))
if isDark:
x = (c + border) * boxsize
y = (r + border + 1) * boxsize
# LG: actually use the specified barFillColor
s = SRect(offsetX + x, offsetY + height - y, count * boxsize, boxsize,
fillColor=color)
g.add(s)
c += count
return g
Does this sound right?
thanks&bye, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it | -- Fortunato Depero, 1929.
More information about the reportlab-users
mailing list