Class: Stylist

Inherits:
Object
  • Object
show all
Defined in:
lib/stylist.rb

Class Method Summary collapse

Class Method Details

.get_dimensions(node, y_off) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/stylist.rb', line 50

def Stylist.get_dimensions(node, y_off)
  position = node.xpath("ClientRectangle").text.split(",")
  position = position.map {|x| x.to_f}

  x = Util.cm_to_px(position[0])
  y = Util.trans_y(y_off, Util.cm_to_px(position[1]))
  w = Util.cm_to_px(position[2])
  h = Util.cm_to_px(position[3])

  return x, y, w, h
end

.get_font_face(node) ⇒ Object



33
34
35
# File 'lib/stylist.rb', line 33

def Stylist.get_font_face(node)
  node.xpath("Font").text.split(",")[0]
end

.get_font_size(node) ⇒ Object



37
38
39
# File 'lib/stylist.rb', line 37

def Stylist.get_font_size(node)
  node.xpath("Font").text.split(",")[1].to_i
end

.get_font_style(node) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/stylist.rb', line 41

def Stylist.get_font_style(node)
  font_style = node.xpath("Font").text.split(",")[2]
  if font_style.nil?
    return :normal
  else
    return font_style.downcase.to_sym
  end
end

.get_horizontal_align(node) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/stylist.rb', line 17

def Stylist.get_horizontal_align(node)
  if node.xpath("HorAlignment").text != ""
    return node.xpath("HorAlignment").text.downcase.to_sym
  else
    return :left
  end
end

.get_text_colour(node) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/stylist.rb', line 7

def Stylist.get_text_colour(node)
  hue = node.xpath("TextBrush").text
  case hue
  when "Black"
    "000000"
  else
    Stylist.mrt_colour_to_hex(hue)
  end
end

.get_vertical_align(node) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/stylist.rb', line 25

def Stylist.get_vertical_align(node)
  if node.xpath("VertAlignment").text != ""
    return node.xpath("VertAlignment").text.downcase.to_sym
  else
    return :top
  end
end

.mrt_colour_to_hex(mrt_colour) ⇒ Object



2
3
4
5
# File 'lib/stylist.rb', line 2

def Stylist.mrt_colour_to_hex(mrt_colour)
  mrt_colour = mrt_colour.sub("[","").sub("]","").split(":")
  return mrt_colour[0].to_i.to_s(16) << mrt_colour[1].to_i.to_s(16) << mrt_colour[2].to_i.to_s(16)
end