class PrawnHtml::Tags::Col

def find_parent_of_type(klass)

def find_parent_of_type(klass)
  p = parent
  p = p.parent while p && !p.is_a?(klass)
  p
end

def on_context_add(_context)

def on_context_add(_context)
  table_parent = find_parent_of_type(PrawnHtml::Tags::Table)
  return unless table_parent
  width = parse_width
  table_parent.add_col_width(width) if width
end

def parse_width

def parse_width
  return attrs[:colwidth].to_f if attrs[:colwidth]
  return nil if attrs[:style].include?('min-width:')
  if attrs[:style] && attrs[:style] =~ /width:\s*(\d+)px/i
    return Regexp.last_match(1).to_f
  end
  nil
end