Class: HexaPDF::Content::GraphicsState
- Inherits:
-
Object
- Object
- HexaPDF::Content::GraphicsState
- Defined in:
- lib/hexapdf/content/graphics_state.rb
Overview
A GraphicsState object holds all the graphic control parameters needed for correct operation when parsing or creating a content stream with a Processor object.
While a content stream is parsed/created, operations may use the current parameters or modify them.
The device-dependent graphics state parameters have not been implemented!
See: PDF1.7 s8.4.1
Instance Attribute Summary collapse
-
#alpha_source ⇒ Object
A boolean specifying whether the current soft mask and alpha parameters should be interpreted as shape values or opacity values.
-
#blend_mode ⇒ Object
The current blend mode for the transparent imaging model.
-
#character_spacing ⇒ Object
The character spacing in unscaled text units.
-
#ctm ⇒ Object
The current transformation matrix.
-
#fill_alpha ⇒ Object
The alpha constant for non-stroking operations in the transparent imaging model.
-
#fill_color ⇒ Object
The current color used for all other (i.e. non-stroking) painting operations.
-
#font ⇒ Object
The font for the text.
-
#font_size ⇒ Object
The font size.
-
#horizontal_scaling ⇒ Object
The horizontal text scaling.
-
#leading ⇒ Object
The leading in unscaled text units.
-
#line_cap_style ⇒ Object
The current line cap style (for the available values see LineCapStyle).
-
#line_dash_pattern ⇒ Object
The line dash pattern (see LineDashPattern).
-
#line_join_style ⇒ Object
The current line join style (for the available values see LineJoinStyle).
-
#line_width ⇒ Object
The current line width in user space units.
-
#miter_limit ⇒ Object
The maximum line length of mitered line joins for stroked paths.
-
#rendering_intent ⇒ Object
The rendering intent (only used for CIE-based colors; for the available values see RenderingIntent).
-
#scaled_character_spacing ⇒ Object
readonly
The scaled character spacing used in glyph displacement calculations.
-
#scaled_font_size ⇒ Object
readonly
The scaled font size used in glyph displacement calculations.
-
#scaled_horizontal_scaling ⇒ Object
readonly
The scaled horizontal scaling used in glyph displacement calculations.
-
#scaled_word_spacing ⇒ Object
readonly
The scaled word spacing used in glyph displacement calculations.
-
#soft_mask ⇒ Object
The soft mask specifying the mask shape or mask opacity value to be used in the transparent imaging model.
-
#stroke_adjustment ⇒ Object
The stroke adjustment for very small line width.
-
#stroke_alpha ⇒ Object
The alpha constant for stroking operations in the transparent imaging model.
-
#stroke_color ⇒ Object
The current color used for stroking operations during painting.
-
#text_knockout ⇒ Object
The text knockout, a boolean value.
-
#text_rendering_mode ⇒ Object
The text rendering mode.
-
#text_rise ⇒ Object
The text rise distance in unscaled text units.
-
#tlm ⇒ Object
The text line matrix which captures the state of the text matrix at the beginning of a line.
-
#tm ⇒ Object
The text matrix.
-
#word_spacing ⇒ Object
The word spacing in unscaled text units.
Instance Method Summary collapse
-
#fill_color_space ⇒ Object
:nodoc:.
-
#fill_color_space=(color_space) ⇒ Object
:nodoc:.
-
#initialize ⇒ GraphicsState
constructor
Initializes the graphics state parameters to their default values.
-
#restore ⇒ Object
Restores the graphics state from the internal stack.
-
#save ⇒ Object
Saves the current graphics state on the internal stack.
-
#saved_states? ⇒ Boolean
Returns
true
if the internal stack of saved graphic states contains entries. -
#stroke_color_space ⇒ Object
:nodoc:.
-
#stroke_color_space=(color_space) ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ GraphicsState
Initializes the graphics state parameters to their default values.
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/hexapdf/content/graphics_state.rb', line 437 def initialize @ctm = TransformationMatrix.new @stroke_color = @fill_color = GlobalConfiguration.constantize('color_space.map'.freeze, :DeviceGray).new.default_color @line_width = 1.0 @line_cap_style = LineCapStyle::BUTT_CAP @line_join_style = LineJoinStyle::MITER_JOIN @miter_limit = 10.0 @line_dash_pattern = LineDashPattern.new @rendering_intent = RenderingIntent::RELATIVE_COLORIMETRIC @stroke_adjustment = false @blend_mode = :Normal @soft_mask = :None @stroke_alpha = @fill_alpha = 1.0 @alpha_source = false @tm = nil @tlm = nil @character_spacing = 0 @word_spacing = 0 @horizontal_scaling = 100 @leading = 0 @font = nil @font_size = 0 @text_rendering_mode = TextRenderingMode::FILL @text_rise = 0 @text_knockout = true @scaled_character_spacing = 0 @scaled_word_spacing = 0 @scaled_font_size = 0 @scaled_horizontal_scaling = 1 @stack = [] end |
Instance Attribute Details
#alpha_source ⇒ Object
A boolean specifying whether the current soft mask and alpha parameters should be interpreted as shape values or opacity values.
346 347 348 |
# File 'lib/hexapdf/content/graphics_state.rb', line 346 def alpha_source @alpha_source end |
#blend_mode ⇒ Object
The current blend mode for the transparent imaging model.
332 333 334 |
# File 'lib/hexapdf/content/graphics_state.rb', line 332 def blend_mode @blend_mode end |
#character_spacing ⇒ Object
The character spacing in unscaled text units.
It specifies the additional spacing used for the horizontal or vertical displacement of glyphs.
363 364 365 |
# File 'lib/hexapdf/content/graphics_state.rb', line 363 def character_spacing @character_spacing end |
#ctm ⇒ Object
The current transformation matrix.
301 302 303 |
# File 'lib/hexapdf/content/graphics_state.rb', line 301 def ctm @ctm end |
#fill_alpha ⇒ Object
The alpha constant for non-stroking operations in the transparent imaging model.
342 343 344 |
# File 'lib/hexapdf/content/graphics_state.rb', line 342 def fill_alpha @fill_alpha end |
#fill_color ⇒ Object
The current color used for all other (i.e. non-stroking) painting operations.
307 308 309 |
# File 'lib/hexapdf/content/graphics_state.rb', line 307 def fill_color @fill_color end |
#font ⇒ Object
The font for the text.
381 382 383 |
# File 'lib/hexapdf/content/graphics_state.rb', line 381 def font @font end |
#font_size ⇒ Object
The font size.
384 385 386 |
# File 'lib/hexapdf/content/graphics_state.rb', line 384 def font_size @font_size end |
#horizontal_scaling ⇒ Object
The horizontal text scaling.
The value specifies the percentage of the normal width that should be used.
373 374 375 |
# File 'lib/hexapdf/content/graphics_state.rb', line 373 def horizontal_scaling @horizontal_scaling end |
#leading ⇒ Object
The leading in unscaled text units.
It specifies the distance between the baselines of adjacent lines of text.
378 379 380 |
# File 'lib/hexapdf/content/graphics_state.rb', line 378 def leading @leading end |
#line_cap_style ⇒ Object
The current line cap style (for the available values see LineCapStyle).
313 314 315 |
# File 'lib/hexapdf/content/graphics_state.rb', line 313 def line_cap_style @line_cap_style end |
#line_dash_pattern ⇒ Object
The line dash pattern (see LineDashPattern).
322 323 324 |
# File 'lib/hexapdf/content/graphics_state.rb', line 322 def line_dash_pattern @line_dash_pattern end |
#line_join_style ⇒ Object
The current line join style (for the available values see LineJoinStyle).
316 317 318 |
# File 'lib/hexapdf/content/graphics_state.rb', line 316 def line_join_style @line_join_style end |
#line_width ⇒ Object
The current line width in user space units.
310 311 312 |
# File 'lib/hexapdf/content/graphics_state.rb', line 310 def line_width @line_width end |
#miter_limit ⇒ Object
The maximum line length of mitered line joins for stroked paths.
319 320 321 |
# File 'lib/hexapdf/content/graphics_state.rb', line 319 def miter_limit @miter_limit end |
#rendering_intent ⇒ Object
The rendering intent (only used for CIE-based colors; for the available values see RenderingIntent).
326 327 328 |
# File 'lib/hexapdf/content/graphics_state.rb', line 326 def rendering_intent @rendering_intent end |
#scaled_character_spacing ⇒ Object (readonly)
The scaled character spacing used in glyph displacement calculations.
This returns the value T_c multiplied by #scaled_horizontal_scaling.
See PDF1.7 s9.4.4
411 412 413 |
# File 'lib/hexapdf/content/graphics_state.rb', line 411 def scaled_character_spacing @scaled_character_spacing end |
#scaled_font_size ⇒ Object (readonly)
The scaled font size used in glyph displacement calculations.
This returns the value T_fs / 1000 multiplied by #scaled_horizontal_scaling.
See PDF1.7 s9.4.4
425 426 427 |
# File 'lib/hexapdf/content/graphics_state.rb', line 425 def scaled_font_size @scaled_font_size end |
#scaled_horizontal_scaling ⇒ Object (readonly)
The scaled horizontal scaling used in glyph displacement calculations.
Since the horizontal scaling attribute is stored in percent of 100, this method returns the correct value for calculations.
See PDF1.7 s9.4.4
433 434 435 |
# File 'lib/hexapdf/content/graphics_state.rb', line 433 def scaled_horizontal_scaling @scaled_horizontal_scaling end |
#scaled_word_spacing ⇒ Object (readonly)
The scaled word spacing used in glyph displacement calculations.
This returns the value T_w multiplied by #scaled_horizontal_scaling.
See PDF1.7 s9.4.4
418 419 420 |
# File 'lib/hexapdf/content/graphics_state.rb', line 418 def scaled_word_spacing @scaled_word_spacing end |
#soft_mask ⇒ Object
The soft mask specifying the mask shape or mask opacity value to be used in the transparent imaging model.
336 337 338 |
# File 'lib/hexapdf/content/graphics_state.rb', line 336 def soft_mask @soft_mask end |
#stroke_adjustment ⇒ Object
The stroke adjustment for very small line width.
329 330 331 |
# File 'lib/hexapdf/content/graphics_state.rb', line 329 def stroke_adjustment @stroke_adjustment end |
#stroke_alpha ⇒ Object
The alpha constant for stroking operations in the transparent imaging model.
339 340 341 |
# File 'lib/hexapdf/content/graphics_state.rb', line 339 def stroke_alpha @stroke_alpha end |
#stroke_color ⇒ Object
The current color used for stroking operations during painting.
304 305 306 |
# File 'lib/hexapdf/content/graphics_state.rb', line 304 def stroke_color @stroke_color end |
#text_knockout ⇒ Object
The text knockout, a boolean value.
It specifies whether each glyph should be treated as separate elementary object for the purpose of color compositing in the transparent imaging model (knockout = false
) or if all glyphs together are treated as one elementary object (knockout = true
).
403 404 405 |
# File 'lib/hexapdf/content/graphics_state.rb', line 403 def text_knockout @text_knockout end |
#text_rendering_mode ⇒ Object
The text rendering mode.
It determines if and how the glyphs of a text should be shown (for all available values see TextRenderingMode).
390 391 392 |
# File 'lib/hexapdf/content/graphics_state.rb', line 390 def text_rendering_mode @text_rendering_mode end |
#text_rise ⇒ Object
The text rise distance in unscaled text units.
It specifies the distance that the baseline should be moved up or down from its default location.
396 397 398 |
# File 'lib/hexapdf/content/graphics_state.rb', line 396 def text_rise @text_rise end |
#tlm ⇒ Object
The text line matrix which captures the state of the text matrix at the beginning of a line.
As with the text matrix the text line matrix is non-nil only when inside a text object.
357 358 359 |
# File 'lib/hexapdf/content/graphics_state.rb', line 357 def tlm @tlm end |
#tm ⇒ Object
The text matrix.
This attribute is non-nil only when inside a text object.
352 353 354 |
# File 'lib/hexapdf/content/graphics_state.rb', line 352 def tm @tm end |
#word_spacing ⇒ Object
The word spacing in unscaled text units.
It works like the character spacing but is only applied to the ASCII space character.
368 369 370 |
# File 'lib/hexapdf/content/graphics_state.rb', line 368 def word_spacing @word_spacing end |
Instance Method Details
#fill_color_space ⇒ Object
:nodoc:
528 529 530 |
# File 'lib/hexapdf/content/graphics_state.rb', line 528 def fill_color_space @fill_color.color_space end |
#fill_color_space=(color_space) ⇒ Object
:nodoc:
532 533 534 |
# File 'lib/hexapdf/content/graphics_state.rb', line 532 def fill_color_space=(color_space) #:nodoc: self.fill_color = color_space.default_color end |
#restore ⇒ Object
Restores the graphics state from the internal stack.
Raises an error if the stack is empty.
489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/hexapdf/content/graphics_state.rb', line 489 def restore if @stack.empty? raise HexaPDF::Error, "Can't restore graphics state because the stack is empty" end @ctm, @stroke_color, @fill_color, @line_width, @line_cap_style, @line_join_style, @miter_limit, @line_dash_pattern, @rendering_intent, @stroke_adjustment, @blend_mode, @soft_mask, @stroke_alpha, @fill_alpha, @alpha_source, @character_spacing, @word_spacing, @horizontal_scaling, @leading, @font, @font_size, @text_rendering_mode, @text_rise, @text_knockout, @scaled_character_spacing, @scaled_word_spacing, @scaled_font_size, @scaled_horizontal_scaling = @stack.pop end |
#save ⇒ Object
Saves the current graphics state on the internal stack.
474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/hexapdf/content/graphics_state.rb', line 474 def save @stack.push([@ctm, @stroke_color, @fill_color, @line_width, @line_cap_style, @line_join_style, @miter_limit, @line_dash_pattern, @rendering_intent, @stroke_adjustment, @blend_mode, @soft_mask, @stroke_alpha, @fill_alpha, @alpha_source, @character_spacing, @word_spacing, @horizontal_scaling, @leading, @font, @font_size, @text_rendering_mode, @text_rise, @text_knockout, @scaled_character_spacing, @scaled_word_spacing, @scaled_font_size, @scaled_horizontal_scaling]) @ctm = @ctm.dup end |
#saved_states? ⇒ Boolean
Returns true
if the internal stack of saved graphic states contains entries.
504 505 506 |
# File 'lib/hexapdf/content/graphics_state.rb', line 504 def saved_states? !@stack.empty? end |
#stroke_color_space ⇒ Object
:nodoc:
514 515 516 |
# File 'lib/hexapdf/content/graphics_state.rb', line 514 def stroke_color_space @stroke_color.color_space end |
#stroke_color_space=(color_space) ⇒ Object
:nodoc:
518 519 520 |
# File 'lib/hexapdf/content/graphics_state.rb', line 518 def stroke_color_space=(color_space) # :nodoc: self.stroke_color = color_space.default_color end |