class HexaPDF::Content::GraphicsState

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

Attributes

alpha_source[RW]

A boolean specifying whether the current soft mask and alpha parameters should be interpreted as shape values or opacity values.

blend_mode[RW]

The current blend mode for the transparent imaging model.

character_spacing[R]

The character spacing in unscaled text units.

It specifies the additional spacing used for the horizontal or vertical displacement of glyphs.

ctm[RW]

The current transformation matrix.

fill_alpha[RW]

The alpha constant for non-stroking operations in the transparent imaging model.

fill_color[RW]

The current color used for all other (i.e. non-stroking) painting operations.

font[RW]

The font for the text.

font_size[R]

The font size.

horizontal_scaling[R]

The horizontal text scaling.

The value specifies the percentage of the normal width that should be used.

leading[RW]

The leading in unscaled text units.

It specifies the distance between the baselines of adjacent lines of text.

line_cap_style[RW]

The current line cap style (for the available values see LineCapStyle).

line_dash_pattern[RW]

The line dash pattern (see LineDashPattern).

line_join_style[RW]

The current line join style (for the available values see LineJoinStyle).

line_width[RW]

The current line width in user space units.

miter_limit[RW]

The maximum line length of mitered line joins for stroked paths.

rendering_intent[RW]

The rendering intent (only used for CIE-based colors; for the available values see RenderingIntent).

scaled_character_spacing[R]

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

scaled_font_size[R]

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

scaled_horizontal_scaling[R]

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

scaled_word_spacing[R]

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

soft_mask[RW]

The soft mask specifying the mask shape or mask opacity value to be used in the transparent imaging model.

stroke_adjustment[RW]

The stroke adjustment for very small line width.

stroke_alpha[RW]

The alpha constant for stroking operations in the transparent imaging model.

stroke_color[RW]

The current color used for stroking operations during painting.

stroke_color_space[RW]

The current color space for stroking operations during painting.

text_knockout[RW]

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).

text_rendering_mode[RW]

The text rendering mode.

It determines if and how the glyphs of a text should be shown (for all available values see TextRenderingMode).

text_rise[RW]

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.

tlm[RW]

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.

tm[RW]

The text matrix.

This attribute is non-nil only when inside a text object.

word_spacing[R]

The word spacing in unscaled text units.

It works like the character spacing but is only applied to the ASCII space character.

Public Class Methods

new() click to toggle source

Initializes the graphics state parameters to their default values.

# File lib/hexapdf/content/graphics_state.rb, line 445
def initialize
  @ctm = TransformationMatrix.new
  @stroke_color = @fill_color =
    GlobalConfiguration.constantize('color_space.map', :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

Public Instance Methods

restore() click to toggle source

Restores the graphics state from the internal stack.

Raises an error if the stack is empty.

# File lib/hexapdf/content/graphics_state.rb, line 497
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() click to toggle source

Saves the current graphics state on the internal stack.

# File lib/hexapdf/content/graphics_state.rb, line 482
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?() click to toggle source

Returns true if the internal stack of saved graphic states contains entries.

# File lib/hexapdf/content/graphics_state.rb, line 512
def saved_states?
  !@stack.empty?
end