Skip to content

Commit d66c6ae

Browse files
committed
upload docu for v1.17.5
1 parent 60e0c1f commit d66c6ae

File tree

7 files changed

+133
-40
lines changed

7 files changed

+133
-40
lines changed

docs/changes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Change Logs
22
===============
33

4+
Changes in Version 1.17.5
5+
---------------------------
6+
* **Fixed** issue `#561 <https://github.com/pymupdf/PyMuPDF/issues/561>`_ -- second go: certain :ref:`TextWriter` usages with many alternating fonts did not work correctly.
7+
* **Fixed** issue `#566 <https://github.com/pymupdf/PyMuPDF/issues/566>`_.
8+
* **Fixed** issue `#568 <https://github.com/pymupdf/PyMuPDF/issues/568>`_.
9+
* **Fixed** -- opacity is now correctly taken from the :ref:`TextWriter` object, if not given in :meth:`TextWriter.writeText`.
10+
* **Added** a new global attribute :attr:`fitz_fontdescriptors`. Contains information about usable fonts from repository `pymupdf-fonts <https://github.com/pymupdf/pymupdf-fonts>`_.
11+
* **Added** :meth:`Font.valid_codepoints` which returns an array of unicode codepoints for which the font has a glyph.
12+
* **Added** option ``text_as_path`` to :meth:`Page.getSVGimage`. this implements `#580 <https://github.com/pymupdf/PyMuPDF/issues/580>`_. Generates much smaller SVG files with parseable text if set to *False*.
13+
14+
415
Changes in Version 1.17.4
516
---------------------------
617
* **Fixed** issue `#561 <https://github.com/pymupdf/PyMuPDF/issues/561>`_. Handling of more than 10 :ref:`Font` objects on one page should now work correctly.

docs/conf.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
# Add any Sphinx extension module names here, as strings. They can be
1818
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1919
# ones.
20-
extensions = [
21-
"sphinx.ext.autodoc",
22-
# "sphinx.ext.todo",
23-
"sphinx.ext.coverage",
24-
"sphinx.ext.ifconfig",
25-
# "sphinx.ext.imgmath",
26-
]
20+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.ifconfig"]
21+
if sys.platform == "win32":
22+
extensions.extend(["sphinx.ext.autodoc", "rst2pdf.pdfbuilder"])
2723

2824
# Add any paths that contain templates here, relative to this directory.
2925
templates_path = ["_templates"]
@@ -46,7 +42,7 @@
4642
# built documents.
4743
#
4844
# The full version, including alpha/beta/rc tags.
49-
release = "1.17.4"
45+
release = "1.17.5"
5046

5147
# The short X.Y version
5248
version = release
@@ -222,7 +218,7 @@
222218
pdf_documents = [("index", "PyMuPDF", "PyMuPDF Manual", "Jorj McKie")]
223219

224220
# A comma-separated list of custom stylesheets. Example:
225-
pdf_stylesheets = ["sphinx", "bahnschrift"]
221+
pdf_stylesheets = ["sphinx", "bahnschrift", "a4"]
226222

227223
# Create a compressed PDF
228224
pdf_compressed = True

docs/font.rst

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ A Font object also contains useful general information, like the font bbox, the
1818

1919
Font constructor. The large number of parameters are used to locate font, which most closely resembles the requirements. Not all parameters are ever required -- see the below pseudo code explaining the logic how the parameters are evaluated.
2020

21-
:arg str fontname: one of the :ref:`Base-14-Fonts` or CJK fontnames. Also possible are a select few of other names like (watch the correct spelling): "Arial", "Times", "Times Roman".
21+
:arg str fontname: one of the :ref:`Base-14-Fonts` or CJK fontnames. Also possible are a select few other names like (watch the correct spelling): "Arial", "Times", "Times Roman".
2222

23-
*(Changed in v1.17.4)*
23+
*(Changed in v1.17.5)*
2424

25-
If you have installed `pymupdf-fonts <https://pypi.org/project/pymupdf-fonts/>`_, you can also use the following new "reserved" fontnames: "figo", "figbo", "figit", "figbi", "fimo", and "fimbo". This will provide one of the "FiraGo" or resp. "FiraMono" fonts, created by Mozilla.org.
25+
If you have installed `pymupdf-fonts <https://pypi.org/project/pymupdf-fonts/>`_, there are also new "reserved" fontnames available, which are listed in :attr:`fitz_fonts` and in the table further down.
2626

2727
:arg str filename: the filename of a fontfile somewhere on your system [#f1]_.
2828
:arg bytes,bytearray,io.BytesIO fontbuffer: a fontfile loaded in memory [#f1]_.
@@ -54,7 +54,10 @@ A Font object also contains useful general information, like the font bbox, the
5454

5555
.. note::
5656

57-
With the usual abbreviations "helv", "tiro", etc., you will create fonts with the expected names "Helvetica", "Times-Roman" and so on.
57+
With the usual reserved names "helv", "tiro", etc., you will create fonts with the expected names "Helvetica", "Times-Roman" and so on. **However**, and in contrast to :meth:`Page.insertFont` and friends,
58+
59+
* a font file will **always** be embedded in your PDF,
60+
* Greek and Cyrillic characters are supported without needing the *encoding* parameter.
5861

5962
Using *ordering >= 0*, or fontnames starting with "china", "japan" or "korea" will always create the same **"universal"** font **"Droid Sans Fallback Regular"**. This font supports **all CJK and all Latin characters**.
6063

@@ -64,30 +67,75 @@ A Font object also contains useful general information, like the font bbox, the
6467

6568
But if you do specify a Base-14 fontname, you will still be able to also write CJK characters! MuPDF automatically detects this situation and silently falls back to the universal font (which will then of course also be embedded in your PDF).
6669

67-
*(New in v1.17.4)* Optionally, a set of new "reserved" fontnames becomes available if you install `pymupdf-fonts <https://pypi.org/project/pymupdf-fonts/>`_. The currently available fonts are from the Fira fonts family created by Mozilla. "Fira Mono" is a nice mono-spaced sans font set and FiraGO is another non-serifed "universal" font, set which supports all European languages (including Cyrillic and Greek) plus Thai, Arabian, Hewbrew and Devanagari -- however none of the CJK languages. The size of a FiraGO font is only a quarter of the "Droid Sans Fallback" size (compressed 400 KB vs. 1.65 MB) -- and the style variants bold and italic are available..The following table maps a fontname to the corresponding font:
70+
*(New in v1.17.5)* Optionally, some new "reserved" fontnames become available if you install `pymupdf-fonts <https://pypi.org/project/pymupdf-fonts/>`_. **"Fira Mono"** is a nice mono-spaced sans font set and **FiraGO** is another non-serifed "universal" font, set which supports all European languages (including Cyrillic and Greek) plus Thai, Arabian, Hewbrew and Devanagari -- however none of the CJK languages. The size of a FiraGO font is only a quarter of the "Droid Sans Fallback" size (compressed 400 KB vs. 1.65 MB) -- **and** it provides the style variants bold, italic, bold-italic.
71+
72+
**"Space Mono"** is another nice and small fixed-width font from Google Fonts, which supports Latin Extended characters.
6873

69-
=========== =======================================
70-
Fontname Font
71-
=========== =======================================
72-
figo FiraGO Regular
73-
figbo FiraGO Bold
74-
figit FiraGO Italic
75-
figbi FiraGO Bold Italic
76-
fimo Fira Mono Regular
77-
fimbo Fira Mono Bold
78-
=========== =======================================
74+
The following table maps a fontname to the corresponding font:
7975

80-
**All fonts mentioned here** also support Greek and Cyrillic letters.
76+
=========== =========================== ==============
77+
Fontname Font Added in
78+
=========== =========================== ==============
79+
figo FiraGO Regular v1.0.0
80+
figbo FiraGO Bold v1.0.0
81+
figit FiraGO Italic v1.0.0
82+
figbi FiraGO Bold Italic v1.0.0
83+
fimo Fira Mono Regular v1.0.0
84+
fimbo Fira Mono Bold v1.0.0
85+
spacemo Space Mono Regular v1.0.1
86+
spacembo Space Mono Bold v1.0.1
87+
spacemit Space Mono Italic v1.0.1
88+
spacembi Space Mono Bold-Italic v1.0.1
89+
math Noto Sans Math Regular v1.0.2
90+
music Noto Music Regular v1.0.2
91+
symbol1 Noto Sans Symbols Regular v1.0.2
92+
symbol2 Noto Sans Symbols2 Regular v1.0.2
93+
=========== =========================== ==============
8194

82-
.. method:: has_glyph(chr, language=None, script=0)
95+
96+
.. method:: has_glyph(chr, language=None, script=0, fallback=False)
8397

8498
Check whether the unicode *chr* exists in the font or some fallback. May be used to check whether any "TOFU" symbols will appear on output.
8599

86100
:arg int chr: the unicode of the character (i.e. *ord()*).
87101
:arg str language: the language -- currently unused.
88102
:arg int script: the UCDN script number.
103+
:arg bool fallback: *(new in v1.17.5)* perform an extended search in fallback fonts or restrict to current font (default).
89104
:returns: *True* or *False*.
90105

106+
.. method:: valid_codepoints()
107+
108+
*(New in v1.17.5)* Return an array of unicodes which are supported by this font.
109+
110+
:returns: an *array.array* [#f2]_ of length :attr:`Font.glyph_count` (or less). I.e. *chr()* of every item in this array will be found in the font without using fallbacks. This is an example display of the supported glyphs:
111+
112+
>>> import fitz
113+
>>> font = fitz.Font("math")
114+
>>> vuc = font.valid_codepoints()
115+
>>> for i in vuc:
116+
print("%04X %s (%s)" % (i, chr(i), font.unicode_to_glyph_name(i)))
117+
0000
118+
000D (CR)
119+
0020 (space)
120+
0021 ! (exclam)
121+
0022 " (quotedbl)
122+
0023 # (numbersign)
123+
0024 $ (dollar)
124+
0025 % (percent)
125+
...
126+
00AC ¬ (logicalnot)
127+
00B1 ± (plusminus)
128+
...
129+
21D0 ⇐ (arrowdblleft)
130+
21D1 ⇑ (arrowdblup)
131+
21D2 ⇒ (arrowdblright)
132+
21D3 ⇓ (arrowdbldown)
133+
21D4 ⇔ (arrowdblboth)
134+
...
135+
221E ∞ (infinity)
136+
...
137+
138+
91139
.. method:: glyph_advance(chr, language=None, script=0, wmode=0)
92140

93141
Calculate the "width" of the character's glyph (visual representation).
@@ -104,7 +152,11 @@ A Font object also contains useful general information, like the font bbox, the
104152

105153
:arg str name: The name of the glyph.
106154

107-
:returns: The unicode integer, or 65533 = 0xFFFD if the name is unknown. Examples: ``font.glyph_name_to_unicode("Sigma") = 931``, ``font.glyph_name_to_unicode("sigma") = 963``. Refer to e.g. `this <https://github.com/adobe-type-tools/agl-aglfn/blob/master/glyphlist.txt>`_ publication for a list of glyph names and their unicode numbers.
155+
:returns: The unicode integer, or 65533 = 0xFFFD if the name is unknown. Examples: ``font.glyph_name_to_unicode("Sigma") = 931``, ``font.glyph_name_to_unicode("sigma") = 963``. Refer to e.g. `this <https://github.com/adobe-type-tools/agl-aglfn/blob/master/glyphlist.txt>`_ publication for a list of glyph names and their unicode numbers. Example:
156+
157+
>>> font = fitz.Font("helv")
158+
>>> font.has_glyph(font.glyph_name_to_unicode("infinity"))
159+
True
108160

109161
.. method:: unicode_to_glyph_name(chr, language=None, script=0, wmode=0)
110162

@@ -139,3 +191,5 @@ A Font object also contains useful general information, like the font bbox, the
139191
.. rubric:: Footnotes
140192

141193
.. [#f1] MuPDF does not support all fontfiles with this feature and will raise exceptions like *"mupdf: FT_New_Memory_Face((null)): unknown file format"*, if encounters issues.
194+
195+
.. [#f2] Builtin module *array* has been chosen for its speed and its compact representation of values with an identical type.

docs/functions.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ Yet others are handy, general-purpose utilities.
173173

174174
A dictionary of pre-defines paper formats. Used as basis for :meth:`PaperSize`.
175175

176+
-----
177+
178+
.. attribute:: fitz_fontdescriptors
179+
180+
*(New in v1.17.5)*
181+
182+
A dictionary of usable fonts from repository `pymupdf-fonts <https://pypi.org/project/pymupdf-fonts/>`_. Items are keyed by their reserved fontname and provide information like this::
183+
184+
In [2]: fitz.fitz_fontdescriptors.keys()
185+
Out[2]: dict_keys(['figbo', 'figo', 'figbi', 'figit', 'fimbo', 'fimo',
186+
'spacembo', 'spacembi', 'spacemit', 'spacemo', 'math', 'music', 'symbol1',
187+
'symbol2'])
188+
In [3]: fitz.fitz_fontdescriptors["fimo"]
189+
Out[3]:
190+
{'name': 'Fira Mono Regular',
191+
'size': 125712,
192+
'mono': True,
193+
'bold': False,
194+
'italic': False,
195+
'serif': True,
196+
'glyphs': 1485}
197+
198+
176199
-----
177200

178201
.. method:: getPDFnow()

docs/page.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,19 @@ In a nutshell, this is what you can do with PyMuPDF:
234234
:arg str fontname: *(New in v1.16.12)* the font to use when *text* is given, otherwise ignored. The same rules apply as for :meth:`Page.insertTextbox` -- which is the method :meth:`Page.apply_redactions` internally invokes. The replacement text will be **vertically centered**, if this is one of the CJK or :ref:`Base-14-Fonts`.
235235

236236
.. note::
237-
For an **existing** font of the page, use its reference name as *fontname* (*item[4]* of its entry in :meth:`Page.getFontList`). To use a new, non-builtin font, proceed as follows::
237+
238+
* For an **existing** font of the page, use its reference name as *fontname* (this is *item[4]* of its entry in :meth:`Page.getFontList`).
239+
* For a **new, non-builtin** font, proceed as follows::
238240

239241
page.insertText(point, # anywhere, but outside all redaction rectangles
240-
"somthing", # some non-empty string
241-
fontname="newname", # new, unused reference name
242-
fontfile="...", # desired font file
243-
render_mode=3, # makes the text invisible
242+
"somthing", # some non-empty string
243+
fontname="newname", # new, unused reference name
244+
fontfile="...", # desired font file
245+
render_mode=3, # makes the text invisible
244246
)
245247
page.addRedactAnnot(..., fontname="newname")
246248

247-
:arg float fontsize: *(New in v1.16.12)* the fontsize to use for the replacing text. If the text is too large to fit, several insertion attempts will be made, gradually reducing this value down to 4. If then the text will still not fit, no text insertion will take place at all.
249+
:arg float fontsize: *(New in v1.16.12)* the fontsize to use for the replacing text. If the text is too large to fit, several insertion attempts will be made, gradually reducing the fontsize to no less than 4. If then the text will still not fit, no text insertion will take place at all.
248250

249251
:arg int align: *(New in v1.16.12)* the horizontal alignment for the replacing text. See :meth:`insertTextbox` for available values. The vertical alignment is (approximately) centered if a PDF built-in font is used (CJK or :ref:`Base-14-Fonts`).
250252

@@ -831,8 +833,8 @@ In a nutshell, this is what you can do with PyMuPDF:
831833

832834
:rtype: :ref:`Rect`
833835
:returns: the boundary box of the image.
834-
*(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.
835-
*(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.
836+
*(Changed in v1.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.
837+
*(Changed in v.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.
836838

837839
.. note::
838840

@@ -842,11 +844,12 @@ In a nutshell, this is what you can do with PyMuPDF:
842844
.. index::
843845
pair: matrix; getSVGimage
844846

845-
.. method:: getSVGimage(matrix=fitz.Identity)
847+
.. method:: getSVGimage(matrix=fitz.Identity, text_as_path=True)
846848

847849
Create an SVG image from the page. Only full page images are currently supported.
848850

849851
:arg matrix_like matrix: a matrix, default is :ref:`Identity`.
852+
:arg bool text_as_path: *(new in v1.17.5)* -- controls how text is represented. *True* outputs each character as a series of elementary draw commands, which leads to a more precise text display in browsers, but a **very much larger** output for text-oriented pages. Display quality for *False* relies on the presence of the referenced fonts on the current system. For missing fonts, the internet browser will fall back to some default -- leading to unpleasant appearances. Choose *False* if you want to parse the text of the SVG.
850853

851854
:returns: a UTF-8 encoded string that contains the image. Because SVG has XML syntax it can be saved in a text file with extension *.svg*.
852855

@@ -1012,7 +1015,7 @@ In a nutshell, this is what you can do with PyMuPDF:
10121015

10131016
:arg str text: Text to search for. Upper / lower case is ignored. The string may contain spaces.
10141017

1015-
:arg int hit_max: Maximum number of occurrences accepted.
1018+
:arg int hit_max: Maximum number of returned occurrences.
10161019
:arg bool quads: Return :ref:`Quad` instead of :ref:`Rect` objects.
10171020
:arg int flags: Control the data extracted by the underlying :ref:`TextPage`. Default is 0 (ligatures are dissolved, white space is replaced with space and excessive spaces are not suppressed).
10181021

@@ -1022,6 +1025,10 @@ In a nutshell, this is what you can do with PyMuPDF:
10221025

10231026
.. note:: In this way, the effect supports multi-line text marker annotations.
10241027

1028+
.. note:: The number of returned objects will never exceed *hit_max*. Hence, if the returned list has this many items, you cannot know whether there really exist more on the page. So please make sure you provide a hit_max value which is large enough.
1029+
1030+
.. note:: Please also be aware of a trickier aspect: the search logic regards **contiguous multiple** occurrences of the search string as one: assuming your search string is "abc", and the page contains "abc" and "abcabc", then only **two** rectangles will be returned, one containing "abc", and a second one containing "abcabc".
1031+
10251032

10261033
.. method:: setMediaBox(r)
10271034

@@ -1217,7 +1224,7 @@ This is an overview of homologous methods on the :ref:`Document` and on the :ref
12171224
*Document.searchPageFor(pno, ...)* :meth:`Page.searchFor`
12181225
====================================== =====================================
12191226

1220-
The page number "pno"` is a 0-based integer *-inf < pno < pageCount*.
1227+
The page number "pno" is a 0-based integer *-inf < pno < pageCount*.
12211228

12221229
.. note::
12231230

docs/pixmap.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ Have a look at the :ref:`FAQ` section to see some pixmap usage "at work".
307307

308308
.. method:: pillowData(*args, **kwargs)
309309

310-
Return the pixmap as a bytes object in the specified format using Pillow. For example ``stream = pix.pillowData(format="JPEG", optimize=True)``. For details on possible parameters see the Pillow documentation.
310+
*(New in v1.17.3)*
311+
312+
Return an image as a bytes object in the specified format using Pillow. For example ``stream = pix.pillowData(format="JPEG", optimize=True)``. Also see above. For details on possible parameters see the Pillow documentation.
311313

312314

313315
.. attribute:: alpha

docs/version.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Covered Version
22
--------------------
33

4-
This documentation covers PyMuPDF v1.17.4 features as of **2020-07-20 18:09:40**.
4+
This documentation covers PyMuPDF v1.17.5 features as of **2020-08-06 06:31:06**.
55

66
.. note:: The major and minor versions of **PyMuPDF** and **MuPDF** will always be the same. Only the third qualifier (patch level) may deviate from that of MuPDF.

0 commit comments

Comments
 (0)