@@ -1288,14 +1288,18 @@ def _write_soft_mask_groups(self):
1288
1288
self .output (* content )
1289
1289
self .endStream ()
1290
1290
1291
- def hatchPattern (self , hatch_style ):
1291
+ def hatchPattern (self , hatch_style , forced_alpha ):
1292
1292
# The colors may come in as numpy arrays, which aren't hashable
1293
1293
if hatch_style is not None :
1294
1294
edge , face , hatch = hatch_style
1295
1295
if edge is not None :
1296
1296
edge = tuple (edge )
1297
+ if forced_alpha : # reset alpha if forced
1298
+ edge = edge [:3 ] + (1.0 ,)
1297
1299
if face is not None :
1298
1300
face = tuple (face )
1301
+ if forced_alpha : # reset alpha if forced
1302
+ face = face [:3 ] + (1.0 ,)
1299
1303
hatch_style = (edge , face , hatch )
1300
1304
1301
1305
pattern = self .hatchPatterns .get (hatch_style , None )
@@ -1310,10 +1314,14 @@ def writeHatches(self):
1310
1314
hatchDict = dict ()
1311
1315
sidelen = 72.0
1312
1316
for hatch_style , name in self .hatchPatterns .items ():
1317
+ stroke_rgb , fill_rgb , path = hatch_style
1313
1318
ob = self .reserveObject ('hatch pattern' )
1314
1319
hatchDict [name ] = ob
1315
1320
res = {'Procsets' :
1316
1321
[Name (x ) for x in "PDF Text ImageB ImageC ImageI" .split ()]}
1322
+ if stroke_rgb [3 ] != 1.0 :
1323
+ res ['ExtGState' ] = self ._extGStateObject
1324
+
1317
1325
self .beginStream (
1318
1326
ob .id , None ,
1319
1327
{'Type' : Name ('Pattern' ),
@@ -1324,7 +1332,9 @@ def writeHatches(self):
1324
1332
# Change origin to match Agg at top-left.
1325
1333
'Matrix' : [1 , 0 , 0 , 1 , 0 , self .height * 72 ]})
1326
1334
1327
- stroke_rgb , fill_rgb , path = hatch_style
1335
+ if stroke_rgb [3 ] != 1.0 :
1336
+ gstate = self .alphaState ((stroke_rgb [3 ], fill_rgb [3 ]))
1337
+ self .output (gstate , Op .setgstate )
1328
1338
self .output (stroke_rgb [0 ], stroke_rgb [1 ], stroke_rgb [2 ],
1329
1339
Op .setrgb_stroke )
1330
1340
if fill_rgb is not None :
@@ -2245,15 +2255,15 @@ def alpha_cmd(self, alpha, forced, effective_alphas):
2245
2255
name = self .file .alphaState (effective_alphas )
2246
2256
return [name , Op .setgstate ]
2247
2257
2248
- def hatch_cmd (self , hatch , hatch_color ):
2258
+ def hatch_cmd (self , hatch , hatch_color , forced_alpha ):
2249
2259
if not hatch :
2250
2260
if self ._fillcolor is not None :
2251
2261
return self .fillcolor_cmd (self ._fillcolor )
2252
2262
else :
2253
2263
return [Name ('DeviceRGB' ), Op .setcolorspace_nonstroke ]
2254
2264
else :
2255
2265
hatch_style = (hatch_color , self ._fillcolor , hatch )
2256
- name = self .file .hatchPattern (hatch_style )
2266
+ name = self .file .hatchPattern (hatch_style , forced_alpha )
2257
2267
return [Name ('Pattern' ), Op .setcolorspace_nonstroke ,
2258
2268
name , Op .setcolor_nonstroke ]
2259
2269
@@ -2311,13 +2321,15 @@ def clip_cmd(self, cliprect, clippath):
2311
2321
(('_cliprect' , '_clippath' ), clip_cmd ),
2312
2322
(('_alpha' , '_forced_alpha' , '_effective_alphas' ), alpha_cmd ),
2313
2323
(('_capstyle' ,), capstyle_cmd ),
2324
+ # If you change the next line also fix the check in delta
2314
2325
(('_fillcolor' ,), fillcolor_cmd ),
2315
2326
(('_joinstyle' ,), joinstyle_cmd ),
2316
2327
(('_linewidth' ,), linewidth_cmd ),
2317
2328
(('_dashes' ,), dash_cmd ),
2318
2329
(('_rgb' ,), rgb_cmd ),
2319
2330
# must come after fillcolor and rgb
2320
- (('_hatch' , '_hatch_color' ), hatch_cmd ),
2331
+ # If you change the next line also fix the check in delta
2332
+ (('_hatch' , '_hatch_color' , '_forced_alpha' ), hatch_cmd ),
2321
2333
)
2322
2334
2323
2335
def delta (self , other ):
@@ -2346,7 +2358,8 @@ def delta(self, other):
2346
2358
break
2347
2359
2348
2360
# Need to update hatching if we also updated fillcolor
2349
- if params == ('_hatch' , '_hatch_color' ) and fill_performed :
2361
+ if (params == ('_hatch' , '_hatch_color' , '_forced_alpha' )
2362
+ and fill_performed ):
2350
2363
different = True
2351
2364
2352
2365
if different :
0 commit comments