Class: Postsvg::GraphicsContext
- Inherits:
-
Object
- Object
- Postsvg::GraphicsContext
- Defined in:
- lib/postsvg/graphics_context.rb
Overview
Immutable graphics state snapshot. Mutations return new instances
via with(...). The GraphicsStack pushes/pops these.
Fields mirror PLRM ยง7.2 graphics state operators. Optional fields
are nil meaning "not set in this state"; the renderer falls back
to defaults at emit time.
Constant Summary collapse
- DEFAULTS =
{ ctm: Matrix.new, fill_color: Color::BLACK, stroke_color: Color::BLACK, stroke_width: 1.0, line_cap: :butt, line_join: :miter, miter_limit: 10.0, dash: nil, font_name: "Helvetica", font_size: 12.0, clip_paths: [], last_text_position: nil, fill_rule: :nonzero, }.freeze
Instance Attribute Summary collapse
-
#clip_paths ⇒ Object
readonly
Returns the value of attribute clip_paths.
-
#ctm ⇒ Object
readonly
Returns the value of attribute ctm.
-
#dash ⇒ Object
readonly
Returns the value of attribute dash.
-
#fill_color ⇒ Object
readonly
Returns the value of attribute fill_color.
-
#fill_rule ⇒ Object
readonly
Returns the value of attribute fill_rule.
-
#font_name ⇒ Object
readonly
Returns the value of attribute font_name.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
-
#last_text_position ⇒ Object
readonly
Returns the value of attribute last_text_position.
-
#line_cap ⇒ Object
readonly
Returns the value of attribute line_cap.
-
#line_join ⇒ Object
readonly
Returns the value of attribute line_join.
-
#miter_limit ⇒ Object
readonly
Returns the value of attribute miter_limit.
-
#stroke_color ⇒ Object
readonly
Returns the value of attribute stroke_color.
-
#stroke_width ⇒ Object
readonly
Returns the value of attribute stroke_width.
Instance Method Summary collapse
- #clipped? ⇒ Boolean
- #identity_ctm? ⇒ Boolean
-
#initialize(**fields) ⇒ GraphicsContext
constructor
A new instance of GraphicsContext.
- #push_clip_path(path_d) ⇒ Object
- #with(**overrides) ⇒ Object
Constructor Details
#initialize(**fields) ⇒ GraphicsContext
Returns a new instance of GraphicsContext.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/postsvg/graphics_context.rb', line 32 def initialize(**fields) merged = DEFAULTS.merge(fields) @ctm = merged[:ctm] @fill_color = merged[:fill_color] @stroke_color = merged[:stroke_color] @stroke_width = merged[:stroke_width] @line_cap = merged[:line_cap] @line_join = merged[:line_join] @miter_limit = merged[:miter_limit] @dash = merged[:dash] @font_name = merged[:font_name] @font_size = merged[:font_size] @clip_paths = merged[:clip_paths].freeze @last_text_position = merged[:last_text_position] @fill_rule = merged[:fill_rule] freeze end |
Instance Attribute Details
#clip_paths ⇒ Object (readonly)
Returns the value of attribute clip_paths.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def clip_paths @clip_paths end |
#ctm ⇒ Object (readonly)
Returns the value of attribute ctm.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def ctm @ctm end |
#dash ⇒ Object (readonly)
Returns the value of attribute dash.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def dash @dash end |
#fill_color ⇒ Object (readonly)
Returns the value of attribute fill_color.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def fill_color @fill_color end |
#fill_rule ⇒ Object (readonly)
Returns the value of attribute fill_rule.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def fill_rule @fill_rule end |
#font_name ⇒ Object (readonly)
Returns the value of attribute font_name.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def font_name @font_name end |
#font_size ⇒ Object (readonly)
Returns the value of attribute font_size.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def font_size @font_size end |
#last_text_position ⇒ Object (readonly)
Returns the value of attribute last_text_position.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def last_text_position @last_text_position end |
#line_cap ⇒ Object (readonly)
Returns the value of attribute line_cap.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def line_cap @line_cap end |
#line_join ⇒ Object (readonly)
Returns the value of attribute line_join.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def line_join @line_join end |
#miter_limit ⇒ Object (readonly)
Returns the value of attribute miter_limit.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def miter_limit @miter_limit end |
#stroke_color ⇒ Object (readonly)
Returns the value of attribute stroke_color.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def stroke_color @stroke_color end |
#stroke_width ⇒ Object (readonly)
Returns the value of attribute stroke_width.
11 12 13 |
# File 'lib/postsvg/graphics_context.rb', line 11 def stroke_width @stroke_width end |
Instance Method Details
#clipped? ⇒ Boolean
76 77 78 |
# File 'lib/postsvg/graphics_context.rb', line 76 def clipped? !@clip_paths.empty? end |
#identity_ctm? ⇒ Boolean
72 73 74 |
# File 'lib/postsvg/graphics_context.rb', line 72 def identity_ctm? @ctm.identity? end |
#push_clip_path(path_d) ⇒ Object
68 69 70 |
# File 'lib/postsvg/graphics_context.rb', line 68 def push_clip_path(path_d) with(clip_paths: @clip_paths + [path_d]) end |
#with(**overrides) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/postsvg/graphics_context.rb', line 50 def with(**overrides) GraphicsContext.new( ctm: overrides.fetch(:ctm, @ctm), fill_color: overrides.fetch(:fill_color, @fill_color), stroke_color: overrides.fetch(:stroke_color, @stroke_color), stroke_width: overrides.fetch(:stroke_width, @stroke_width), line_cap: overrides.fetch(:line_cap, @line_cap), line_join: overrides.fetch(:line_join, @line_join), miter_limit: overrides.fetch(:miter_limit, @miter_limit), dash: overrides.fetch(:dash, @dash), font_name: overrides.fetch(:font_name, @font_name), font_size: overrides.fetch(:font_size, @font_size), clip_paths: overrides.fetch(:clip_paths, @clip_paths), last_text_position: overrides.fetch(:last_text_position, @last_text_position), fill_rule: overrides.fetch(:fill_rule, @fill_rule), ) end |