Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjMcKie committed Dec 14, 2023
1 parent c7f7298 commit 5cc558c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 7 additions & 8 deletions docs/page.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,16 @@ In a nutshell, this is what you can do with PyMuPDF:

PDF only. Insert text into the specified rectangle. The method has similarities with methods :meth:`Page.insert_textbox` and :meth:`TextWriter.fill_textbox`, but is **much more powerful**. This is achieved by letting a :ref:`Story` object do all the required processing.

* Parameter "text" may be a string as in the other methods. But it will be **interpreted as HTML source** and may therefore also contain HTML language elements -- including styling. The "css" parameter may be used to pass in additional styling instructions.
* Parameter `text` may be a string as in the other methods. But it will be **interpreted as HTML source** and may therefore also contain HTML language elements -- including styling. The `css` parameter may be used to pass in additional styling instructions.

* Automatic line breaks are inserted at word boundaries. The "soft hyphen" character `"&#173;"` can be used to cause hyphenation and thus also cause line breaks. **Forced** line breaks however are only achievable via the HTML tag `<br>` - `"\\n"` is ignored and will be treated like a space.

* With this method the following can be achieved:

- Styling effects like bold, italic, text color, text alignment, font size or font switching.
- The text may inlude arbitrary languages -- **including rigt-to-left** languages.
- The text may inlude arbitrary languages -- **including right-to-left** languages.
- Scripts like `Devanagari <https://en.wikipedia.org/wiki/Devanagari>`_ and several others in Asia have a highly complex system of ligatures, where two or more unicodes together yield one glyph. The Story uses the software package `HarfBuzz <https://harfbuzz.github.io/>`_ , to deal with these things and produce correct output.
- One can also **include images** via HTML tag `<img>` -- the Story code will take care of the appropriate layout. This is an alternative option to insert images, compared to :meth:`Page.insert_image`.
- One can also **include images** via HTML tag `<img>` -- the Story will take care of the appropriate layout. This is an alternative option to insert images, compared to :meth:`Page.insert_image`.
- HTML tables (tag `<table>`) may be included in the text and will be handled appropriately.
- Links are automatically generated when present.

Expand All @@ -663,9 +663,9 @@ In a nutshell, this is what you can do with PyMuPDF:

:arg rect_like rect: rectangle on page to receive the text.
:arg str,Story text: the text to be written. Can contain plain text and HTML tags with styling instructions. Alternatively, a :ref:`Story` object may be specified (in which case the internal Story generation step will be omitted). A Story must have been generated with all required styling and Archive information.
:arg str css: optional string containing additional CSS instructions. Ignored if "text" is a Story.
:arg str css: optional string containing additional CSS instructions. Ignored if `text` is a Story.
:arg float scale_low: if necessary scale down the content until it fits in the target rectangle. This sets the down scaling limit. Detault is 0, no limit. A value of 1 means no down-scaling. A value of e.g. 0.2 means maximum down-scaling by 80%.
:arg Archive archive: an Archive object that points to locations where to find images or non-standard fonts. If "text" refers to images, this parameter is always reqired. Ignored if "text" is a Story.
:arg Archive archive: an Archive object that points to locations where to find images or non-standard fonts. If `text` refers to images, this parameter is always reqired. Ignored if `text` is a Story.
:arg int rotate: one of the values 0, 90, 180, 270. Depending on this, text will be filled:

- 0: top-left to bottom-right.
Expand All @@ -674,15 +674,14 @@ In a nutshell, this is what you can do with PyMuPDF:
- 270: top-right to bottom-left.

.. image:: images/img-rotate.*
:scale: 50

:arg int oc: the xref of an :data:`OCG` / :data:`OCMD` or 0. Please refer to :meth:`Page.show_pdf_page` for details.
:arg bool overlay: put the text in front of other content. Please refer to :meth:`Page.show_pdf_page` for details.

:returns: A tuple of floats (spare_height, scale).

- **spare_height**: -1 if content did not fit, else >= 0. It is the height of the unused (still available) rectangle stripe. Positive only if scale = 1 (no down-scaling happened).
- **scale**: down-scaling factor, 0 < scale <= 1.
- `spare_height`: -1 if content did not fit, else >= 0. It is the height of the unused (still available) rectangle stripe. Positive only if scale = 1 (no down-scaling happened).
- `scale`: down-scaling factor, 0 < scale <= 1.

Please refer to examples in this section of the recipes: :ref:`RecipesText_I_c`.

Expand Down
5 changes: 1 addition & 4 deletions docs/recipes-text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ Please note how the "css" parameter is used to globally select the default "sans
The result will look like this:

.. image:: images/img-htmlbox1.*
:scale: 30

Here is another example that outputs a table with this method. This time, we are including all the styling in the HTML source itself. Please also not, how it works to also include an image - even within a table cell::
Here is another example that outputs a table with this method. This time, we are including all the styling in the HTML source itself. Please also note, how it works to include an image - even within a table cell::

import fitz_new as fitz
import os
Expand Down Expand Up @@ -529,7 +528,6 @@ Here is another example that outputs a table with this method. This time, we are
The result will look like this:

.. image:: images/img-htmlbox2.*
:scale: 30


Our third example will demonstrate the automatic multi-language support that also includes text shaping for complex scripting systems like Devanagari and right-to-left languages::
Expand Down Expand Up @@ -563,6 +561,5 @@ Our third example will demonstrate the automatic multi-language support that als
And this is the output:

.. image:: images/img-htmlbox3.*
:scale: 50

.. include:: footer.rst

0 comments on commit 5cc558c

Please sign in to comment.