Class: Emfsvg::TransformStack
- Inherits:
-
Object
- Object
- Emfsvg::TransformStack
- Defined in:
- lib/emfsvg/transform_stack.rb
Overview
SaveDC/RestoreDC stack of DeviceContext snapshots.
IMPORTANT: libemf2svg's restoreDeviceContext WALKS the stack to find the target level but does NOT remove entries — the same save can be restored multiple times. This mirrors Windows GDI behavior where RestoreDC's saved_dc argument identifies a level (not a one-shot pop). We replicate that exactly: restore() reads the target snapshot but leaves the stack intact.
Instance Method Summary collapse
-
#initialize ⇒ TransformStack
constructor
A new instance of TransformStack.
- #push(dc) ⇒ Object
-
#restore(saved_dc) ⇒ Object
Returns the snapshot at the target level.
- #size ⇒ Object
Constructor Details
#initialize ⇒ TransformStack
Returns a new instance of TransformStack.
13 14 15 |
# File 'lib/emfsvg/transform_stack.rb', line 13 def initialize @stack = [] end |
Instance Method Details
#push(dc) ⇒ Object
17 18 19 |
# File 'lib/emfsvg/transform_stack.rb', line 17 def push(dc) @stack.push(dc.dup) end |
#restore(saved_dc) ⇒ Object
Returns the snapshot at the target level. The stack is NOT modified. saved_dc semantics match libemf2svg: negative N = "N levels back from the top" (so -1 is the top, -2 is one below, etc.); positive N is treated as the equivalent 1-based absolute level.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/emfsvg/transform_stack.rb', line 25 def restore(saved_dc) target_index = if saved_dc.negative? @stack.size + saved_dc else saved_dc - 1 end return nil if target_index.negative? || target_index >= @stack.size @stack[target_index] end |
#size ⇒ Object
36 37 38 |
# File 'lib/emfsvg/transform_stack.rb', line 36 def size @stack.size end |