Module: Writexlsx::ObjectPositioning

Constant Summary

Constants included from Constants

Constants::COL_MAX, Constants::ROW_MAX, Constants::SHEETNAME_MAX, Constants::STR_MAX

Constants included from Utility::ChartFormatting

Utility::ChartFormatting::PATTERN_TYPES

Instance Method Summary collapse

Methods included from Utility::SheetnameQuoting

#quote_sheetname

Methods included from Utility::XmlPrimitives

#r_id_attributes, #write_color, #write_xml_declaration, #xml_str

Methods included from Utility::Url

#escape_url

Methods included from Utility::DateTime

#convert_date_time

Methods included from Utility::Dimensions

#check_dimensions, #check_dimensions_and_update_max_min_values, #store_col_max_min_values, #store_row_max_min_values

Methods included from Utility::ChartFormatting

#color, #dash_types, #fill_properties, #layout_properties, #legend_properties, #line_fill_properties, #line_properties, #palette_color_from_index, #pattern_properties, #value_or_raise, #write_a_solid_fill, #write_a_srgb_clr

Methods included from Utility::CellReference

#row_col_notation, #substitute_cellref, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell

Instance Method Details

#pixels_to_height(pixels) ⇒ Object

Convert the height of a cell from pixels to character units.



89
90
91
92
93
# File 'lib/write_xlsx/object_positioning.rb', line 89

def pixels_to_height(pixels)
  height = 0.75 * pixels
  height = height.to_i if (height - height.to_i).abs < 0.1
  height
end

#pixels_to_width(pixels) ⇒ Object

Convert the width of a cell from pixels to character units.



75
76
77
78
79
80
81
82
83
84
# File 'lib/write_xlsx/object_positioning.rb', line 75

def pixels_to_width(pixels)
  max_digit_width = 7.0
  padding         = 5.0

  if pixels <= 12
    pixels / (max_digit_width + padding)
  else
    (pixels - padding) / max_digit_width
  end
end

#position_object_emus(graphical_object) ⇒ Object

Calculate the vertices that define the position of a graphical object within the worksheet in EMUs.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/write_xlsx/object_positioning.rb', line 53

def position_object_emus(graphical_object) # :nodoc:
  object = graphical_object
  col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs =
    position_object_pixels(
      object.col, object.row, object.x_offset, object.y_offset,
      object.scaled_width, object.scaled_height, object.anchor
    )

  # Convert the pixel values to EMUs. See above.
  x1    = (0.5 + (9_525 * x1)).to_i
  y1    = (0.5 + (9_525 * y1)).to_i
  x2    = (0.5 + (9_525 * x2)).to_i
  y2    = (0.5 + (9_525 * y2)).to_i
  x_abs = (0.5 + (9_525 * x_abs)).to_i
  y_abs = (0.5 + (9_525 * y_abs)).to_i

  [col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs]
end

#position_object_pixels(col_start, row_start, x1, y1, width, height, anchor = nil) ⇒ Object

Calculate the vertices that define the position of a graphical object within the worksheet in pixels.



26
27
28
29
30
31
32
# File 'lib/write_xlsx/object_positioning.rb', line 26

def position_object_pixels(col_start, row_start, x1, y1, width, height, anchor = nil) # :nodoc:
  context = object_positioning_context(anchor)

  position_object_pixels_with_context(
    col_start, row_start, x1, y1, width, height, context
  )
end