# wx.html.HtmlDCRenderer¶

This class can render HTML document into a specified area of a DC.

You can use it in your own printing code, although use of wx.html.HtmlEasyPrinting or wx.html.HtmlPrintout is strongly recommended.

## Class Hierarchy¶

Inheritance diagram for class HtmlDCRenderer:

## Methods Summary¶

 __init__ Constructor. FindNextPageBreak Finds the next page break after the specified (vertical) position. GetTotalHeight Returns the height of the HTML text in pixels. GetTotalWidth Returns the width of the HTML text in pixels. Render Renders HTML text to the DC. SetDC Assign DC instance to the renderer. SetFonts This function sets font sizes and faces. SetHtmlCell Associate the given HTML contents to the renderer. SetHtmlText Assign text to the renderer. SetSize Set size of output rectangle, in pixels. SetStandardFonts Sets font sizes to be relative to the given size or the system default size; use either specified or default font.

## Class API¶

class wx.html.HtmlDCRenderer(Object)

Possible constructors:

HtmlDCRenderer()


This class can render HTML document into a specified area of a DC.

### Methods¶

__init__(self)

Constructor.

FindNextPageBreak(self, pos)

Finds the next page break after the specified (vertical) position.

An example of using this method:

pages = []
while pos != wx.NOT_FOUND:
pos = renderer.FindNextPageBreak(pos)
pages.append(pos)

# "pages" now contains all page break positions and, in
# particular, its size is the number of pages

Parameters

pos (int) – Absolute position of the last page break. For the initial call of this function, it should be 0 and for the subsequent ones it should be the previous return value.

Return type

int

Returns

Position of the next page break or NOT_FOUND if there are no more of them.

New in version 4.1/wxWidgets-3.1.2.

GetTotalHeight(self)

Returns the height of the HTML text in pixels.

If the height of the area used with this renderer (see wx.html.HtmlDCRenderer.SetSize ) is smaller that total height, the renderer will produce more than one page of output.

Return type

int

GetTotalWidth(self)

Returns the width of the HTML text in pixels.

This can be compared with the width parameter of SetSize to check if the document being printed fits into the page boundary.

Return type

int

New in version 2.9.0.

Render(self, x, y, from_=0, to_=INT_MAX)

Renders HTML text to the DC.

When using multi-page documents, FindNextPageBreak can be used to find the values for from and to, which should be the consecutive page breaks returned by that function.

Parameters
• x (int) –

• y (int) – position of upper-left corner of printing rectangle (see SetSize ).

• from_ (int) –

• to_ (int) –

y-coordinate of the very first visible cell.

y-coordinate of the last visible cell or INT_MAX to use the full page height.

Note

The following three methods must always be called before any call to Render , in this order:

SetDC(self, dc, pixel_scale=1.0)

Assign DC instance to the renderer.

pixel_scale can be used when rendering to high-resolution DCs (e.g. printer) to adjust size of pixel metrics. (Many dimensions in HTML are given in pixels – e.g. image sizes. 300x300 image would be only one inch wide on typical printer. With pixel_scale = 3.0 it would be 3 inches.)

Parameters
• dc (wx.DC) –

• pixel_scale (float) –

SetFonts(self, normal_face, fixed_face, sizes)

This function sets font sizes and faces.

Parameters
• normal_face (string) – This is face name for normal (i.e. non-fixed) font. It can be either empty string (then the default face is chosen) or platform-specific face name. Examples are “helvetica” under Unix or “Times New Roman” under Windows.

• fixed_face (string) – The same thing for fixed face ( <TT>..</TT> )

• sizes (list of integers) – This is an array of 7 items of int type. The values represent size of font with HTML size from -2 to +4 ( <FONT SIZE=-2> to <FONT SIZE=+4> ). Default sizes are used if sizes is None.

SetHtmlCell(self, cell)

Associate the given HTML contents to the renderer.

This is similar to SetHtmlText , but is more efficient as the text can be parsed only once, using wx.html.HtmlParser.Parse , and then passed to wx.html.HtmlDCRenderer multiple times or already reused for other purposes.

Note that cell will be modified (e.g. laid out) by this function.

Parameters

cell (wx.html.HtmlContainerCell) –

New in version 4.1/wxWidgets-3.1.2.

SetHtmlText(self, html, basepath="", isdir=True)

Assign text to the renderer.

Render then draws the text onto DC.

Parameters
• html (string) – HTML text. This is not a filename.

• basepath (string) – base directory (html string would be stored there if it was in file). It is used to determine path for loading images, for example.

• isdir (bool) – False if basepath is filename, True if it is directory name (see wx.FileSystem for detailed explanation).

SetSize(self, width, height)

Set size of output rectangle, in pixels.

Note that you can’t change width of the rectangle between calls to Render ! (You can freely change height.)

Parameters
• width (int) –

• height (int) –

SetStandardFonts(self, size=-1, normal_face="", fixed_face="")

Sets font sizes to be relative to the given size or the system default size; use either specified or default font.

Parameters
• size (int) – Point size of the default HTML text

• normal_face (string) – This is face name for normal (i.e. non-fixed) font. It can be either empty string (then the default face is chosen) or platform-specific face name. Examples are “helvetica” under Unix or “Times New Roman” under Windows.

• fixed_face (string) – The same thing for fixed face ( <TT>..</TT> )

### Properties¶

TotalHeight

TotalWidth