File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use super::*;
33/// A builder for a content stream.
44pub struct Content {
55 buf : Vec < u8 > ,
6+ q_depth : usize ,
67}
78
89/// Core methods.
@@ -16,7 +17,7 @@ impl Content {
1617
1718 /// Create a new content stream with the specified initial buffer capacity.
1819 pub fn with_capacity ( capacity : usize ) -> Self {
19- Self { buf : Vec :: with_capacity ( capacity) }
20+ Self { buf : Vec :: with_capacity ( capacity) , q_depth : 0 }
2021 }
2122
2223 /// Start writing an arbitrary operation.
@@ -243,16 +244,24 @@ impl Content {
243244 #[ inline]
244245 pub fn save_state ( & mut self ) -> & mut Self {
245246 self . op ( "q" ) ;
247+ self . q_depth = self . q_depth . saturating_add ( 1 ) ;
246248 self
247249 }
248250
249251 /// `Q`: Restore the graphics state from the stack.
250252 #[ inline]
251253 pub fn restore_state ( & mut self ) -> & mut Self {
252254 self . op ( "Q" ) ;
255+ self . q_depth = self . q_depth . saturating_sub ( 1 ) ;
253256 self
254257 }
255258
259+ /// The current `q` nesting depth.
260+ #[ inline]
261+ pub fn state_nesting_depth ( & self ) -> usize {
262+ self . q_depth
263+ }
264+
256265 /// `cm`: Pre-concatenate the `matrix` with the current transformation
257266 /// matrix.
258267 #[ inline]
You can’t perform that action at this time.
0 commit comments