Skip to content

Commit 5446e8e

Browse files
committed
documentation updates
1 parent 87cf95b commit 5446e8e

File tree

6 files changed

+58
-43
lines changed

6 files changed

+58
-43
lines changed

docs/irect.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ IRect is a rectangular bounding box similar to :ref:`Rect`, except that all corn
9393

9494
:rtype: bool
9595

96-
.. method:: morph(point, matrix)
96+
.. method:: morph(pivot, matrix)
9797

9898
*(New in version 1.17.0)*
9999

100100
Return a new quad after applying a matrix to it using a pivotal point.
101101

102-
:arg point_like point: the pivotal point.
102+
:arg point_like pivot: the pivotal point.
103103
:arg matrix_like matrix: the matrix.
104-
:returns: a new quad.
104+
:returns: a new :ref:`Quad`. This a wrapper of the same-named quad method.
105105

106106
.. method:: norm()
107107

docs/page.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ In a nutshell, this is what you can do with PyMuPDF:
5959
:meth:`Page.drawSquiggle` PDF only: draw a squiggly line
6060
:meth:`Page.drawZigzag` PDF only: draw a zig-zagged line
6161
:meth:`Page.getFontList` PDF only: get list of used fonts
62-
:meth:`Page.getImageBbox` PDF only: get bbox of inserted image
62+
:meth:`Page.getImageBbox` PDF only: get bbox of embedded image
6363
:meth:`Page.getImageList` PDF only: get list of used images
6464
:meth:`Page.getLinks` get all links
6565
:meth:`Page.getPixmap` create a page image in raster format
@@ -269,7 +269,7 @@ In a nutshell, this is what you can do with PyMuPDF:
269269
>>> quads = page.searchFor("pymupdf", hit_max=100, quads=True)
270270
>>> page.addHighlightAnnot(quads)
271271

272-
:arg rect_like,quad_like,list,tuple quads: *(Changed in v1.14.20)* the rectangles or quads containing the to-be-marked text (locations). A list or tuple must consist of :data:`rect_like` or :data:`quad_like` items (or even a mixture of either). You should prefer using quads, because this will automatically support non-horizontal text and avoid rectangle-to-quad conversion effort. *(Changed in v1.16.14)* **Set this parameter to** *None* if you want to use the following arguments.
272+
:arg rect_like,quad_like,list,tuple quads: *(Changed in v1.14.20)* the location(s) -- rectangle(s) or quad(s) -- to be marked. A list or tuple must consist of :data:`rect_like` or :data:`quad_like` items (or even a mixture of either). Every item must be finite, convex and not empty (as applicable). *(Changed in v1.16.14)* **Set this parameter to** *None* if you want to use the following arguments.
273273
:arg point_like start: *(New in v1.16.14)* start text marking at this point. Defaults to the top-left point of *clip*.
274274
:arg point_like stop: *(New in v1.16.14)* stop text marking at this point. Defaults to the bottom-right point of *clip*.
275275
:arg rect_like clip: *(New in v1.16.14)* only consider text lines intersecting this area. Defaults to the page rectangle.
@@ -797,16 +797,16 @@ In a nutshell, this is what you can do with PyMuPDF:
797797

798798
*Changed in version 1.17.0:*
799799

800-
* The method should deliver mostly correct results now.
800+
* The method should deliver correct results now.
801801
* The page's ``/Contents`` are no longer modified by this method.
802-
* Images occurring inside embedded PDF pages (i.e. in **Form XObjects**) never correctly worked and are now ignored. Use the items of :meth:`Document.getPageXObjectList` to determine the bboxes of embedded PDF pages.
802+
* Images occurring inside embedded PDF pages (i.e. in **Form XObjects**) never correctly worked and are now ignored [#f5]_. Use the items of :meth:`Document.getPageXObjectList` to determine the bboxes of embedded PDF pages.
803803

804-
:arg list,str item: an item of the list :meth:`Page.getImageList` with *full=True* specified, or the **name** entry of such an item, which is item[-3] (or item[7] respectively). *Changed in v1.17.0:* only images are considered where item[1] == 0. This are images **directly** referenced by the page.
804+
:arg list,str item: an item of the list :meth:`Page.getImageList` with *full=True* specified, or the **name** entry of such an item, which is item[-3] (or item[7] respectively). *Changed in v1.17.0:* only images are considered where item[1] == 0 [#f5]_. This are images **directly** referenced by the page.
805805

806806
:rtype: :ref:`Rect`
807807
:returns: the boundary box of the image.
808808
*(Changed in version 1.16.7)* If the page in fact does not display this image, an infinite rectangle is returned now. In previous versions, an exception was raised.
809-
*(Changed in version 1.17.0)* Only images referenced directly by the page are considered. This means that images occurring in embedded PDF pages are ignored and an infinite rectangle is returned.
809+
*(Changed in version 1.17.0)* Only images referenced directly by the page are considered. This means that images occurring in embedded PDF pages are ignored and an exception is raised.
810810

811811
.. note::
812812

@@ -1192,3 +1192,5 @@ The page number "pno"` is a 0-based integer *-inf < pno < pageCount*.
11921192
.. [#f3] Not all PDF readers display these fonts at all. Some others do, but use a wrong character spacing, etc.
11931193
11941194
.. [#f4] You are generally free to choose any of the :ref:`mupdficons` you consider adequate.
1195+
1196+
.. [#f5] This restriction will be removed with the next MuPDF version again: all inserted images shown on the page will be reported correctly, whether the page itself invokes them or some of its Form XObjects.

docs/quad.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
1414

1515
* Attribute :attr:`Quad.rect` obtains the envelopping rectangle. Vice versa, rectangles now have attributes :attr:`Rect.quad`, resp. :attr:`IRect.quad` to obtain their respective tetragon versions.
1616

17+
1718
============================= =======================================================
1819
**Methods / Attributes** **Short Description**
1920
============================= =======================================================
@@ -56,17 +57,19 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
5657

5758
:arg matrix_like matrix: the matrix.
5859

59-
.. method:: morph(point, matrix)
60+
.. method:: morph(pivot, matrix)
6061

6162
*(New in version 1.17.0)* "Morph" the quad with a matrix-like using a point-like as pivotal point.
6263

63-
:arg point_like point: the point.
64+
:arg point_like pivot: the point.
6465
:arg matrix_like matrix: the matrix.
65-
:returns: a new quad. The effect is achieved by using the following code snippet::
66+
:returns: a new quad. The effect is achieved by using the following code::
6667

67-
>>> T = fitz.Matrix(1, 1).preTranslate(point.x, point.y)
68+
>>> T = fitz.Matrix(1, 1).preTranslate(pivot.x, pivot.y)
6869
>>> result = self * ~T * matrix * T
6970

71+
So the quad is translated such, that pivot becomes the origin (0, 0), then the matrix is applied to it, and finally a reverse translation is done.
72+
7073
Typical uses include rotating the quad around a desired point.
7174

7275
.. attribute:: rect
@@ -105,19 +108,19 @@ Quads can **be obtained** as results of text search methods (:meth:`Page.searchF
105108

106109
*(New in version 1.16.1)*
107110

108-
True if all lines are contained in the quad which connect two points of the quad.
111+
True if every line connecting two points of the quad is inside the quad. We in addition also make sure here, that the quad is not "degenerate", i.e. not all corners are on the same line (which would still qualify as convexity in the mathematical sense).
109112

110113
:type: bool
111114

112115
.. attribute:: isEmpty
113116

114-
True if enclosed area is zero, which means that all four points are on the same line. If this is false, the quad may still be degenerate or not look like a rectangle at all (triangles, parallelograms, trapezoids, ...).
117+
True if enclosed area is zero, which means that at least three of the four corners are on the same line. If this is false, the quad may still be degenerate or not look like a tetragon at all (triangles, parallelograms, trapezoids, ...).
115118

116119
:type: bool
117120

118121
.. attribute:: isRectangular
119122

120-
True if all angles are 90 degrees. This also implies that the area is **not empty** and **convex**.
123+
True if all corner angles are 90 degrees. This implies that the quad is **convex and not empty**.
121124

122125
:type: bool
123126

docs/rect.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ Hence some useful classification:
153153

154154
:rtype: bool
155155

156-
.. method:: morph(point, matrix)
156+
.. method:: morph(pivot, matrix)
157157

158158
*(New in version 1.17.0)*
159159

160160
Return a new quad after applying a matrix to it using a pivotal point.
161161

162-
:arg point_like point: the pivotal point.
162+
:arg point_like pivot: the pivotal point.
163163
:arg matrix_like matrix: the matrix.
164-
:returns: a new quad.
164+
:returns: a new :ref:`Quad`. This a wrapper for the same-named quad method.
165165

166166
.. method:: norm()
167167

docs/textwriter.rst

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
TextWriter
55
================
66

7-
*(New in v1.16.18)* This class represents a MuPDF *text* object. It can be thought of as a store of text spans -- each span having its own position, font and font size. It is an elegant alternative for writing text to PDF pages, when compared with methods :meth:`Page.insertText` and friends:
7+
*(New in v1.16.18)* This class represents a MuPDF *text* object. It can be thought of as a collection of text spans. Each span has its own starting position and its font and font size. It is an elegant alternative for writing text to PDF pages, when compared with methods :meth:`Page.insertText` and friends:
88

9-
* **Improved text positioning:** The position of the last inserted character is returned, as well as the combined rectangle of text stored so far.
10-
* **Automatic fallback fonts:** If a character is not represented by the chosen font, alternative fonts are automatically checked. This significantly reduces the risk of seeing unprintable symbols in the output, so-called "TOFUs". PyMuPDF now also comes with a **"universal"** font, which supports **all Latin** characters (incuding Cyrillic and Greek), and **all CJK** characters (Chinese, Japanese, Korean).
11-
* **Reusability:** A TextWriter exists independent from any page. The same text can be written multiple times, to the same or other pages, same or different PDFs, choosing different colors or transparency.
12-
* **Transparency support:** Parameter *opacity* is supported. This offers a handy way to write watermark-style text.
9+
* **Improved text positioning:** Choose any point where insertion of a text span should start. The position of the last inserted character is returned, as well as the combined rectangle of all spans stored so far.
10+
* **Free font choice:** Each text span has its own font and fontsize. This lets you easily switch between normal, bold and italic versions of either the same or a different font when composing a larger text.
11+
* **Automatic fallback fonts:** If a character is not represented by the chosen font, alternative fonts are automatically checked. This significantly reduces the risk of seeing unprintable symbols in the output, so-called "TOFUs". PyMuPDF now also comes with the **universal font "Droid Sans Fallback Regular"**, which supports **all Latin** characters (incuding Cyrillic and Greek), and **all CJK** characters (Chinese, Japanese, Korean).
12+
* **Transparency support:** Parameter *opacity* is supported. This offers a handy way to create watermark-style text.
1313
* **Justified text:** Supported for any font -- not just simple fonts as in :meth:`Page.insertText`.
14+
* **Reusability:** A TextWriter exists independent from any page. The same text can be written multiple times, either to the same or to other pages, in the same or in different PDFs, choosing different colors or transparency.
1415

1516
Using this object entails three steps:
1617

17-
1. When **created**, a TextWriter object requires a fixed **page rectangle** in relation to which it calculates text positions. Pages with different dimensions cannot use this TextWriter object.
18-
2. Store text in the TextWriter using method either :meth:`TextWriter.append` or :meth:`TextWriter.fillTextbox`.
19-
3. Output the stored text on any PDF page with the same rectangle. This is the only point, where pages are referenced.
18+
1. When **created**, a TextWriter object requires a fixed **page rectangle** in relation to which it calculates text positions. Text can be written to a page if and only if the page's size equals that of the TextWriter.
19+
2. Store text in the TextWriter using methods :meth:`TextWriter.append` or :meth:`TextWriter.fillTextbox` any number of times.
20+
3. Output the stored text on some PDF page (having the same rectangle).
2021

21-
TextWriters do not support text rotation. But the new method :meth:`Page.writeText` is able to combine one or more TextWriters and jointly write them to **any rectangle** and with **any rotation angle** -- much like :meth:`Page.showPDFpage`.
22+
Starting with version 1.17.0, TextWriters **do support** text rotation via the *morph* parameter of :meth:`TextWriter.writeText`.
23+
24+
There also exists :meth:`Page.writeText` which is able to combine one or more TextWriters and jointly write them to a given rectangle and with a given any rotation angle -- much like :meth:`Page.showPDFpage`.
2225

2326
**Class API**
2427

@@ -41,12 +44,11 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
4144
:arg float fontsize: the fontsize, a positive number, default 11.
4245
:arg str language: the language to use, e.g. "en" for English. Meaningful values should be compliant with the ISO 639 standards 1, 2, 3 or 5. Reserved for future use: currently has no effect as far as we know.
4346

44-
:returns: :attr:`textRect` and :attr:`lastPoint` after this text has been added.
45-
47+
:returns: :attr:`textRect` and :attr:`lastPoint`.
4648

4749
.. method:: fillTextbox(rect, text, font="helv", fontsize=11, align=0, warn=True)
4850

49-
Fill a given rectangle with text. This is a convenience method to use instead of :meth:`append` (which is internally invoked).
51+
Fill a given rectangle with text. This is a convenience method to use instead of :meth:`append`.
5052

5153
:arg rect_like rect: the area to fill. No part of the text will appear outside of this.
5254
:arg str,sequ text: the text. Can be specified as a (UTF-8) string or a list / tuple of strings. A string will first be converted to a list using *splitlines()*. Every list item will begin on a new line (forced line breaks).
@@ -55,23 +57,27 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
5557
:arg int align: text alignment. Use one of TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_JUSTIFY.
5658
:arg bool warn: print a warning if the area is too small, or raise an exception.
5759

58-
.. method:: writeText(page, opacity=None, color=None, overlay=True)
60+
.. note:: Use these methods as often as is required -- there is no technical limit, except memory constraints of your system. You can also mix appends and text boxes and have multiple of both. Text positioning is controlled by the insertion point. There is no need to adhere to any reading order.
61+
62+
63+
.. method:: writeText(page, opacity=None, color=None, morph=None, overlay=True)
5964

60-
Write the accumulated text to the page.
65+
Write the TextWriter text to a page.
6166

6267
:arg page: write to this :ref:`Page`.
63-
:arg float opacity: overwrite the value of the TextWriter for this output.
64-
:arg sequ color: overwrite the value of the TextWriter for this output.
68+
:arg float opacity: override the value of the TextWriter for this output.
69+
:arg sequ color: override the value of the TextWriter for this output.
70+
:arg sequ morph: modify the text appearance by applying a matrix to it. If provided, this must be a sequence *(pivot, matrix)* with a point-like *pivot* and a matrix-like *matrix*. A typical example is rotating the text around *pivot*.
6571
:arg bool overlay: put in foreground (default) or background.
6672

6773

6874
.. attribute:: textRect
6975

70-
The area currently occupied. This value changes when more text is added.
76+
The :ref:`Rect` currently occupied. This value changes when more text is added.
7177

7278
.. attribute:: lastPoint
7379

74-
The "cursor position" after the last written character.
80+
The "cursor position" -- a :ref:`Point` -- after the last written character (its bottom-right).
7581

7682
.. attribute:: opacity
7783

@@ -83,11 +89,15 @@ TextWriters do not support text rotation. But the new method :meth:`Page.writeTe
8389

8490
.. attribute:: rect
8591

86-
The rectangle for which this TextWriter was created. Must not be modified.
92+
The page rectangle for which this TextWriter was created. Must not be modified.
93+
94+
95+
To see some demo scripts dealing with TextWriter, have a look at `this <https://github.com/pymupdf/PyMuPDF-Utilities/tree/master/textwriter>`_ rpository.
96+
8797

8898
.. note::
8999

90100
1. Opacity and color apply to **all the text** in this object.
91-
2. If you need different colors / transpareny, you must create a separate TextWriter. Whenever you determine the color should change, simply append the text to the respective TextWriter using the previously returned :attr:`lastPoint` as position for the new text.
92-
3. Appending items can occur in arbitrary order: only the position parameter controls where text appears.
101+
2. If you need different colors / transpareny, you must create a separate TextWriter. Whenever you determine the color should change, simply append the text to the respective TextWriter using the previously returned :attr:`lastPoint` as position for the new text span.
102+
3. Appending items or text boxes can occur in arbitrary order: only the position parameter controls where text appears.
93103
4. Font and fontsize can freely vary within the same TextWriter. This can be used to let text with different properties appear on the same displayed line: just specify *pos* accordingly, and e.g. set it to :attr:`lastPoint` of the previously added item.

installation/ubuntu/ubuntu_pymupdf.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
wget https://mupdf.com/downloads/archive/mupdf-1.16.1-source.tar.gz
2-
tar -zxvf mupdf-1.16.1-source.tar.gz
1+
wget https://mupdf.com/downloads/archive/mupdf-1.17.0-source.tar.gz
2+
tar -zxvf mupdf-1.17.0-source.tar.gz
33

4-
cd mupdf-1.16.1-source
4+
cd mupdf-1.17.0-source
55

66
export CFLAGS="-fPIC"
77
# install some prerequirement

0 commit comments

Comments
 (0)