htmlMap - WIN
Class htmlMap
Inherits from __classBase.
The htmlMap class provides a sequential index table of formatting
elements to draw a html document. While the class is defined as
local to the API, an object can be obtained through browserWindow:get_map,
which is necessary if drawing the document to a printer.
Properties
line |
number |
The current line while constructing the map. |
column |
number |
The current column while constructing the
map. |
width |
number |
The width the map was formatted to. |
color |
number |
The body text color of the document. |
bgcolor |
number |
The body background color of the document. |
Methods
Formatting Elements
The htmlMap object is also an indexed table of formatting elements
of the document. Each line in the document has at least one
formatting element, starting from the top. No formatting element
spans multiple lines. The formatting element contains information to
draw that element at its correct location. The line and column
values are zero based, document relative. Each element contains the
following keys:
line |
number |
The document line number the element is on. |
column |
number |
The document column (character) position the
element starts at. |
text |
string |
The text of the element. This value is always
a string but may be zero length. |
color |
number |
The text color of the element. |
bgcolor |
number |
The background color of the element. |
erase |
number |
The color the document line should be erased
to, or nil if no erasure. The process must record line
erasures, as every element of the line records this value
but only the first of the line should erase the whole line. |
align |
string |
The alignment of the element. Column
positions are already adjusted for alignment. This value
should be ignored during drawing. |
node |
table |
The html node (of the htmlDoc object) this
formatting element's range is within. |
To gain a htmlMap object for printing call browserWindow:get_map,
where view is a browserWindow object:
local map = view:get_map
(page_width)
To print the line range of text only using the map:
function appFrame:on_print_page (gdi, page, data)
local width, height = gdi:get_page_size ()
local map = view:get_map (width)
local top_line = ((page - 1) * height)
local first, last = map:get_range (top_line, top_line + height - 1)
gdi:set_colors (term.colors.black, term.colors.white)
if first then
for i = first, last, 1 do
local element = map[i]
if element.text:len () > 0 then
gdi:write (element.text, element.column, (element.line - top_line))
end
end
end
return (last < #map)
end
To print the line range in color using the map:
function appFrame:on_print_page (gdi, page, data)
local width, height = gdi:get_page_size ()
local map = view:get_map (width)
local top_line = ((page - 1) * height)
local first, last = map:get_range (top_line, top_line + height - 1)
-- color whole page to background
gdi:set_colors (nil, map.bgcolor)
gdi:clear (0, 0, width, height)
if first then
local erase_line = -1
local erase = ""
if map:get_width () > 0 then
erase = string.rep (" ", map:get_width ())
end
for index = first, last, 1 do
local element = map[index]
if element.erase and element.line ~= erase_line then
gdi:set_colors (nil, element.erase)
gdi:write (erase, 0, (element.line - top_line))
erase_line = element.line
end
if element.text:len () > 0 then
gdi:set_colors (element.color, element.bgcolor)
gdi:write (element.text, element.column, (element.line - top_line))
end
end
end
return (last < #map)
end
See also HTML API,
API Reference,
WIN.
htmlMap:add
htmlMap:add (color, bgcolor, align, erase, node, text)
Adds an element to the end of the map.
Parameters
color |
number |
The text color of the element. |
bgcolor |
number |
The background color of the element. |
align |
string |
The alignment of the element. |
erase |
number/nil |
The line erasing color for the element, nil
if none. |
node |
table |
The node the element is within. |
text |
string |
The display text value for the element, which
may be nil if none. |
Returns
Remarks
This method is used during the mapping process, and is not used to
draw the formatted document.
top
htmlMap:advance
htmlMap:advance (color, bgcolor, align, erase, node)
Advances the map formatting to the next line, making an entry if
necessary. If no entry is made the parameters are not used.
Parameters
color |
number |
The text color of the element. |
bgcolor |
number |
The background color of the element. |
align |
string |
The alignment of the element. |
erase |
number/nil |
The line erasing color for the element, nil
if none. |
node |
table |
The node the element is within. |
Returns
Remarks
This method is used during the mapping process, and is not used to
draw the formatted document.
top
htmlMap:constructor
map htmlMap:constructor (width, color, bgcolor)
Constructs and returns the instantiated html map object.
Parameters
width |
number |
The width to format the document to. |
color |
number |
The body text color. |
bgcolor |
number |
The body background color. |
Returns
map |
htmlMap |
The instantiated map object. |
Remarks
top
htmlMap:get_range
first_map, last_map htmlMap:get_range (first_line, last_line)
Returns the one based table indexes of the formatting elements for
the zero based document line range given.
Parameters
first_line |
number |
The first line in the desired range. |
last_line |
number/nil |
The last line (inclusive) in the desired
range. If nil the mapping elements for the first_line only
are returned. |
Returns
first_map |
number/nil |
The index of the first mapping element in the
range. If first_line is beyond the number of lines in the
document nil is returned. |
last_map |
number/nil |
The index of the last mapping element in the
range. If last_line is beyond the number of lines in the
document this is the last map index. If first_line is beyond
then nil is returned. |
Remarks
top
htmlMap:get_width
width htmlMap:get_width ()
Returns the formatted width of the document map.
Parameters
Returns
width |
number |
The document formatted width. |
Remarks
See htmlDoc:get_width.
top
htmlMap:last_line
line htmlMap:last_line ()
Returns the zero based last document line in the map, or -1 if none.
Parameters
Returns
line |
number |
The last document line. |
Remarks
See htmlMap:lines.
top
htmlMap:lines
lines htmlMap:lines ()
Returns the count of document lines in the map.
Parameters
Returns
lines |
number |
The number of lines in the document. |
Remarks
See htmlMap:last_line.
top
htmlMap:node_from_point
node htmlMap:node_from_point (x, y)
Returns the html node at the given point. The coordinates are left,
top zero based.
Parameters
x |
number |
The horizontal document relative position. |
y |
number |
The vertical document relative position. |
Returns
node |
table |
The node at the given point or nil if none. |
Remarks
See browserWindow:node_from_point.
top
htmlMap:set_alignment
htmlMap:set_alignment ()
Called at the end of mapping to adjust the positions of the elements
relevant to their alignment.
Parameters
Returns
Remarks
This method is used during the mapping process, and is not used to
draw the formatted document.
top
htmlMap:start_block
htmlMap:start_block (color, bgcolor, align, erase, node)
Prepares the map for a new block level element, making an entry if
necessary. If no entry is made the parameters are not used.
Parameters
color |
number |
The text color of the element. |
bgcolor |
number |
The background color of the element. |
align |
string |
The alignment of the element. |
erase |
number/nil |
The line erasing color for the element, nil
if none. |
node |
table |
The node the element is within. |
Returns
Remarks
This method is used during the mapping process, and is not used to
draw the formatted document.
top
See also HTML API,
API Reference,
WIN.