@@ -8,7 +8,7 @@ import { parseFloats } from '../utils/parsing'
8
8
import { SvgNode } from './svgnode'
9
9
import { Symbol } from './symbol'
10
10
import { Viewport } from '../context/viewport'
11
- import { RGBColor } from '../utils/rgbcolor '
11
+ import { AttributeState } from '../context/attributestate '
12
12
13
13
/**
14
14
* Draws the element referenced by a use node, makes use of pdf's XObjects/FormObjects so nodes are only written once
@@ -61,17 +61,19 @@ export class Use extends GraphicsNode {
61
61
t = context . pdf . Matrix ( 1 , 0 , 0 , 1 , x , y )
62
62
}
63
63
64
+ const contextColors = AttributeState . getContextColors ( context , true )
64
65
const refContext = new Context ( context . pdf , {
65
66
refsHandler : context . refsHandler ,
66
67
styleSheets : context . styleSheets ,
67
68
withinUse : true ,
68
69
viewport : refNodeOpensViewport ? new Viewport ( width ! , height ! ) : context . viewport ,
69
70
svg2pdfParameters : context . svg2pdfParameters ,
70
- textMeasure : context . textMeasure
71
+ textMeasure : context . textMeasure ,
72
+ attributeState : Object . assign ( AttributeState . default ( ) , contextColors )
71
73
} )
72
- const color = context . attributeState . color
73
- await context . refsHandler . getRendered ( id , color , node =>
74
- Use . renderReferencedNode ( node , id , color , refContext )
74
+
75
+ await context . refsHandler . getRendered ( id , contextColors , node =>
76
+ Use . renderReferencedNode ( node , id , refContext )
75
77
)
76
78
77
79
context . pdf . saveGraphicsState ( )
@@ -86,14 +88,13 @@ export class Use extends GraphicsNode {
86
88
context . pdf . clip ( ) . discardPath ( )
87
89
}
88
90
89
- context . pdf . doFormObject ( context . refsHandler . generateKey ( id , color ) , t )
91
+ context . pdf . doFormObject ( context . refsHandler . generateKey ( id , contextColors ) , t )
90
92
context . pdf . restoreGraphicsState ( )
91
93
}
92
94
93
95
private static async renderReferencedNode (
94
96
node : SvgNode ,
95
97
id : string ,
96
- color : RGBColor | null ,
97
98
refContext : Context
98
99
) : Promise < void > {
99
100
let bBox = node . getBoundingBox ( refContext )
@@ -104,15 +105,13 @@ export class Use extends GraphicsNode {
104
105
// still within.
105
106
bBox = [ bBox [ 0 ] - 0.5 * bBox [ 2 ] , bBox [ 1 ] - 0.5 * bBox [ 3 ] , bBox [ 2 ] * 2 , bBox [ 3 ] * 2 ]
106
107
107
- // set the color to use for the referenced node
108
- refContext . attributeState . color = color
109
108
refContext . pdf . beginFormObject ( bBox [ 0 ] , bBox [ 1 ] , bBox [ 2 ] , bBox [ 3 ] , refContext . pdf . unitMatrix )
110
109
if ( node instanceof Symbol ) {
111
110
await node . apply ( refContext )
112
111
} else {
113
112
await node . render ( refContext )
114
113
}
115
- refContext . pdf . endFormObject ( refContext . refsHandler . generateKey ( id , color ) )
114
+ refContext . pdf . endFormObject ( refContext . refsHandler . generateKey ( id , refContext . attributeState ) )
116
115
}
117
116
118
117
protected getBoundingBoxCore ( context : Context ) : number [ ] {
0 commit comments