@@ -8,7 +8,7 @@ import { parseFloats } from '../utils/parsing'
88import { SvgNode } from './svgnode'
99import { Symbol } from './symbol'
1010import { Viewport } from '../context/viewport'
11- import { RGBColor } from '../utils/rgbcolor '
11+ import { AttributeState } from '../context/attributestate '
1212
1313/**
1414 * 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 {
6161 t = context . pdf . Matrix ( 1 , 0 , 0 , 1 , x , y )
6262 }
6363
64+ const contextColors = AttributeState . getContextColors ( context , true )
6465 const refContext = new Context ( context . pdf , {
6566 refsHandler : context . refsHandler ,
6667 styleSheets : context . styleSheets ,
6768 withinUse : true ,
6869 viewport : refNodeOpensViewport ? new Viewport ( width ! , height ! ) : context . viewport ,
6970 svg2pdfParameters : context . svg2pdfParameters ,
70- textMeasure : context . textMeasure
71+ textMeasure : context . textMeasure ,
72+ attributeState : Object . assign ( AttributeState . default ( ) , contextColors )
7173 } )
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 )
7577 )
7678
7779 context . pdf . saveGraphicsState ( )
@@ -86,14 +88,13 @@ export class Use extends GraphicsNode {
8688 context . pdf . clip ( ) . discardPath ( )
8789 }
8890
89- context . pdf . doFormObject ( context . refsHandler . generateKey ( id , color ) , t )
91+ context . pdf . doFormObject ( context . refsHandler . generateKey ( id , contextColors ) , t )
9092 context . pdf . restoreGraphicsState ( )
9193 }
9294
9395 private static async renderReferencedNode (
9496 node : SvgNode ,
9597 id : string ,
96- color : RGBColor | null ,
9798 refContext : Context
9899 ) : Promise < void > {
99100 let bBox = node . getBoundingBox ( refContext )
@@ -104,15 +105,13 @@ export class Use extends GraphicsNode {
104105 // still within.
105106 bBox = [ bBox [ 0 ] - 0.5 * bBox [ 2 ] , bBox [ 1 ] - 0.5 * bBox [ 3 ] , bBox [ 2 ] * 2 , bBox [ 3 ] * 2 ]
106107
107- // set the color to use for the referenced node
108- refContext . attributeState . color = color
109108 refContext . pdf . beginFormObject ( bBox [ 0 ] , bBox [ 1 ] , bBox [ 2 ] , bBox [ 3 ] , refContext . pdf . unitMatrix )
110109 if ( node instanceof Symbol ) {
111110 await node . apply ( refContext )
112111 } else {
113112 await node . render ( refContext )
114113 }
115- refContext . pdf . endFormObject ( refContext . refsHandler . generateKey ( id , color ) )
114+ refContext . pdf . endFormObject ( refContext . refsHandler . generateKey ( id , refContext . attributeState ) )
116115 }
117116
118117 protected getBoundingBoxCore ( context : Context ) : number [ ] {
0 commit comments