Skip to content

Commit 30440ee

Browse files
committed
fix an issue with alpha channel in color and fill pattern
1 parent 330ab0c commit 30440ee

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

src/PaperCanvas.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,26 @@ class PaperCanvas extends React.Component {
446446
this.EnumeratePaperItem(this.paper.project.activeLayer, (item) => {
447447

448448
if (item.fillColor) {
449-
let csscolor = 'rgb(' + Math.round(item.fillColor.red * 255) + ',' + Math.round(item.fillColor.green * 255) + ',' + Math.round(item.fillColor.blue * 255) + ')';
449+
// todo: take account of alpha channel
450+
let csscolor = '';
451+
if (item.fillColor.alpha) {
452+
csscolor = 'rgb(' + Math.round(item.fillColor.red * 255) + ','
453+
+ Math.round(item.fillColor.green * 255) + ','
454+
+ Math.round(item.fillColor.blue * 255) + ','
455+
+ Math.round(item.fillColor.alpha * 255) + ')';
456+
}
457+
else
458+
{
459+
csscolor = 'rgb(' + Math.round(item.fillColor.red * 255) + ',' + Math.round(item.fillColor.green * 255) + ',' + Math.round(item.fillColor.blue * 255) + ')';
460+
461+
}
462+
450463
fcolors[item.fillColor] = csscolor;
451464
}
452465
});
453466

454467
for (const color in fcolors) {
468+
console.log ("color :" + color);
455469
colorlist.push ({color:color, csscolor:fcolors[color]});
456470
}
457471
console.log (colorlist);

src/components/patternstrategy.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,38 @@ class PatternStrategy
1010

1111
getPatternId (fillcolor, linecolor)
1212
{
13-
let csscolor = 'rgb(' + Math.round(fillcolor.red * 255) + ','
13+
let csscolor ='';
14+
if (fillcolor)
15+
{
16+
if (fillcolor.hasOwnProperty('alpha'))
17+
{
18+
csscolor = 'rgb(' + Math.round(fillcolor.red * 255) + ','
19+
+ Math.round(fillcolor.green * 255) + ','
20+
+ Math.round(fillcolor.blue * 255) + ','
21+
+ Math.round(fillcolor.alpha * 255) + ')';
22+
}
23+
else
24+
csscolor = 'rgb(' + Math.round(fillcolor.red * 255) + ','
1425
+ Math.round(fillcolor.green * 255) + ','
1526
+ Math.round(fillcolor.blue * 255) + ')';
16-
17-
//console.log ("search strategy " + fillcolor + " " + csscolor);
27+
28+
}
29+
//console.log ("search strategy " + fillcolor + " " + csscolor + " " + typeof(fillcolor));
1830
if (this.pattern_association.hasOwnProperty(fillcolor))
1931
{
20-
//console.log ("returned pattern " + fillcolor);
32+
//console.group ("returned pattern " );
33+
//console.table(this.pattern_association[fillcolor]);
34+
//console.groupEnd ();
2135
return this.pattern_association[fillcolor];
2236
}
2337
else
2438
{
2539

2640
if (this.pattern_association.hasOwnProperty(csscolor))
2741
{
28-
//console.log ("returned pattern " + csscolor);
42+
//console.group ("returned pattern " );
43+
//console.table (this.pattern_association[csscolor]);
44+
//console.groupEnd ();
2945
return this.pattern_association[csscolor];
3046
}
3147
else

src/pages/Patterns.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Patterns extends React.Component {
4747
{
4848
let fillcolorlist = canv.getFillColorList();
4949
this.setState({fillcolorlist:fillcolorlist});
50+
//console.log (fillcolorlist);
5051
}
5152

5253
}

src/pages/Print.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,6 @@ class Print extends React.Component {
198198
}
199199
}
200200

201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-
214201
HandleRefresh() {
215202

216203
this.paper.project.clear();

0 commit comments

Comments
 (0)