Skip to content

Commit e741336

Browse files
committed
Document vector graphics output
1 parent af475a7 commit e741336

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

docs/textpage.rst

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ For a description of what this class is all about, see Appendix 2.
4848

4949
Textpage content as a list of text lines grouped by block. Each list items looks like this::
5050

51-
(x0, y0, x1, y1, "lines in the block", block_no, block_type)
51+
``(x0, y0, x1, y1, "lines in the block", block_no, block_type)``
5252

53-
The first four entries are the block's bbox coordinates, *block_type* is 1 for an image block, 0 for text. *block_no* is the block sequence number. Multiple text lines are joined via line breaks.
53+
The first four entries are the block's bbox coordinates, *block_type* is 1 for an image block, 3 for a vector block, and 0 for text. *block_no* is the block sequence number. Multiple text lines are joined via line breaks.
5454

55-
For an image block, its bbox and a text line with some image meta information is included -- **not the image content**.
55+
For an **image block**, its bbox and a text line with some image meta information is included -- not the image **content**. Image blocks are included only if the extraction flag bit :data:`TEXT_PRESERVE_IMAGES` is set. An image block tuple will look like this::
56+
57+
``(x0, y0, x1, y1, "<image: colorspace-name, w: width, h: height, bpc: bits_per_component>\n", block_no, 1)``
58+
59+
For a **vector block**, the following item will be included. Vector blocks are included only if the extraction flag bit :data:`TEXT_COLLECT_VECTORS` is set. A vector block tuple will look like this::
60+
61+
``(x0, y0, x1, y1, "<vector stroked, color: #rrggbb, alpha: 255, is-rect: true, continues: false>\n", block_no, 3)``
62+
63+
The keyword "vector" is followed by either "stroked" or "filled". The color is given in HTML (hexadecimal RGB) format. Property ``is-rect`` is true, if the vector is no curve and parallel to the x- or y-axis. So in essence is either a real rectangle or a line segment. Property ``continues`` indicates whether the vector is part of a path (and the not the first item).
64+
65+
.. note:: When no further details are needed (as provided by :meth:`Page.get_drawings`), then this extraction method is an inexpensive way to extract vector graphics. Another advantage is that all block types (text, images and vectors) are included in the output in the same order as they are present in the page's :data:`contents` stream.
5666

5767
This is a high-speed method with just enough information to output plain text in desired reading sequence.
5868

@@ -200,7 +210,24 @@ blocks *list* of block dictionaries
200210

201211
Block Dictionaries
202212
~~~~~~~~~~~~~~~~~~
203-
Block dictionaries come in two different formats for **image blocks** and for **text blocks**.
213+
Block dictionaries come in different formats for **vector blocks**, **image blocks** and **text blocks**. Vector blocks are included only if the extraction flag bit :data:`TEXT_COLLECT_VECTORS` is set. Image blocks are included only if the extraction flag bit :data:`TEXT_PRESERVE_IMAGES` is set.
214+
215+
**Vector block:**
216+
217+
=============== =========================================================================================================================
218+
**Key** **Value**
219+
=============== =========================================================================================================================
220+
type 3 = vector (``int``)
221+
bbox vector bbox on page (:data:`rect_like`)
222+
number block count (``int``)
223+
stroked either stroked (``True``) or filled (``False``) (``bool``)
224+
isrect whether the vector is axis-parallel (``bool``). Can be a line or a rectangle. Curves or diagonal lines are ``False``.
225+
continues whether the vector is (not the first) part of a sequence of vectors in a path (``bool``).
226+
color sRGB integer, e.g. 0xRRGGBB (``int``).
227+
alpha Transparency, a value in ``range(256)`` (``int``).
228+
=============== =========================================================================================================================
229+
230+
This information is a true subset of the output of :meth:`Page.get_drawings`. Its advantage is its speed (because extracted with one :ref:`TextPage` creation) and the fact that vector blocks are included in the overall page content sequence together with text and images.
204231

205232
**Image block:**
206233

0 commit comments

Comments
 (0)