Class: CTioga2::Graphics::Styles::BaseTextStyle

Inherits:
BasicStyle
  • Object
show all
Defined in:
lib/ctioga2/graphics/styles/texts.rb

Overview

TODO:

alignement and justification are poor names. halign

The style of a text object. This class is suitable for inclusion as a Hash to FigureMaker#show_axis, for the tick labels.

and/or valign would be better.

Direct Known Subclasses

FullTextStyle

Constant Summary

Constants inherited from BasicStyle

CTioga2::Graphics::Styles::BasicStyle::AllStyles, CTioga2::Graphics::Styles::BasicStyle::OldAttrAccessor

Instance Method Summary collapse

Methods inherited from BasicStyle

alias_for, aliases, attr_accessor, attribute_type, attribute_types, attributes, convert_string_hash, defined_aliases, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, normalize_hash, normalize_in, normalize_out, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other, #use_defaults_from

Instance Method Details

#draw_text(t, text, x_or_loc, y = nil, measure = nil) ⇒ Object

Draw the text at the given location with the given style. If y is nil, or [:pos, value] then x_or_loc is taken to be a location (see FigureMaker#show_text).



64
65
66
67
68
69
# File 'lib/ctioga2/graphics/styles/texts.rb', line 64

def draw_text(t, text, x_or_loc, y = nil, measure = nil)
  t.context do
    dict = prepare_show_text_dict(t, text, x_or_loc, y, measure)
    t.show_text(dict)
  end
end

#hash_for_tioga(t) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ctioga2/graphics/styles/texts.rb', line 85

def hash_for_tioga(t)
  dict = self.to_hash
  if dict.key? 'shift'
    dim = dict['shift']
    dict['shift'] = dim.to_dy(t)
  end
  if dict.key? 'scale'
    dim = dict['scale']
    dict['scale'] = dim.to_dy(t)
  end
  dict.delete('text_width')
  return dict
end

#scale_dy(t) ⇒ Object



78
79
80
81
82
83
# File 'lib/ctioga2/graphics/styles/texts.rb', line 78

def scale_dy(t)
  if @scale
    return @scale.to_dy(t)
  end
  return nil
end

#shift_dy(t) ⇒ Object



71
72
73
74
75
76
# File 'lib/ctioga2/graphics/styles/texts.rb', line 71

def shift_dy(t)
  if @shift
    return @shift.to_dy(t)
  end
  return nil
end

#vertical?(loc) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
# File 'lib/ctioga2/graphics/styles/texts.rb', line 99

def vertical?(loc)
  if loc
    return Types::PlotLocation.new(loc).vertical?
  else
    ang = angle || 0
    return Math.sin(ang*3.14/180)**2 > 0.5
  end
end