brown.core.document

classes

The document root object.

This object should not be created directly by users - it is instantiated by brown.setup(), which creates a global instance of this class which can be then accessed as brown.document.

NOTE: Paper gutters are not yet implemented

Unit: The visual horizontal gap between pages on the canvas.

This only affects page display in the rendered preview, and has no effect on exported documents.

To change this, set constants.PAGE_DISPLAY_GAP.

Render all items in the document.

Returns: None

__init__ (paper=None) permalink view source

arguments:

paper (Paper): The paper to use in the document. If None, this defaults to constants.DEFAULT_PAPER_TYPE

properties

paper: Paper The paper type of the document permalink view source

pages: PageSupplier The Pages in the document. permalink view source

Pages are created on-demand by accessing this property.

This property can be treated like a managed list:

>>> from brown.core import brown; brown.setup()
>>> len(brown.document.pages)             # No pages exist yet
0
>>> first_page = brown.document.pages[0]  # Get the first page
>>> len(brown.document.pages)             # One page now exists
1
>>> sixth_page = brown.document.pages[5]  # Get the sixth page
>>> len(brown.document.pages)             # 5 new pages are created
6
# Pages can be accessed by negative indexing too
>>> assert(first_page == brown.document.pages[-6])
>>> assert(sixth_page == brown.document.pages[-1])
For more information on this object, see PageSupplier.

read-only.

methods

page_range_of (graphic_objects) permalink view source

Find the page indices an iter of GraphicObjects appears on.

arguments:

graphic_objects (iter[GraphicObject]):

returns:

range: The range from the first page index to one after the last. In order to be consistent with python's range semantics, the range goes 1 past the maximum page objects appear on.

>>> from brown.common import *
>>> brown.setup()
>>> graphic_objects = [
...     InvisibleObject((0, 0), brown.document.pages[1]),
...     InvisibleObject((0, 0), brown.document.pages[5]),
... ]
>>> brown.document.page_range_of(graphic_objects)
range(1, 6)

page_origin (page_number) permalink view source

Find the origin point of a given page number.

arguments:

page_number (int): The number of the page to locate, where 0 is the first page.

returns:

Point: The position of the origin of the given page. The page number of this Point will be 0, as this is considered relative to the document's origin.

The origin is the top left corner of the live area, equivalent to the real page corner + margins and gutter.

paper_origin (page_number) permalink view source

Find the paper origin point of a given page number.

arguments:

page_number (int): The number of the page to locate, where 0 is the first page.

returns:

Point: The position of the paper origin of the given page. The page number of this Point will be 0, as this is considered relative to the document's origin.

This gives the position of the top left corner of the actual sheet of paper - regardless of margins and gutter.

canvas_pos_of (graphic_object) permalink view source

Find the paged document position of a GraphicObject.

arguments:

graphic_object (GraphicObject): Any object in the document.

returns:

Point: The object's paged position relative to the document.

page_bounding_rect (page_number) permalink view source

Find the bounding rect of a page in the document.

arguments:

page_number (int):

returns:

The resulting rect will cover the live page area - that is, the area within the margins of the page

paper_bounding_rect (page_number) permalink view source

Find the paper bounding rect of a page in the document.

arguments:

page_number (int):

returns:

The resulting rect will cover the entire paper sheet - regardless of margins and gutter.