Skip to content

Commit e7c534d

Browse files
authored
Merge branch 'master' into issue-956
2 parents ba92f32 + d81018d commit e7c534d

34 files changed

+945
-275
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# my files
22
.env
3+
.DS_Store
34

45
# codecov.io
56
coverage.xml

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
2121
* [`FPDF.fonts.FontFace`](https://py-pdf.github.io/fpdf2/fpdf/fonts.html#fpdf.fonts.FontFace): Now has a static `combine` method that allows overriding a default FontFace (e.g. for specific cells in a table). Unspecified properties of the override FontFace retain the values of the default.
2222
### Changed
2323
* [`FPDF.table()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.table): If cell styles are provided for cells in heading rows, combine the cell style as an override with the overall heading style.
24+
* SVG importing now supports clipping paths, and `defs` tags anywhere in the SVG file
25+
* [`TextColumns()`](https://py-pdf.github.io/fpdf2/TextColumns.html) can now have images inserted (both raster and vector).
26+
* [`TextColumns()`](https://py-pdf.github.io/fpdf2/TextColumns.html) can now advance to the next column with the new `new_column()` method or a FORM_FEED character (`\u000c`) in the text.
27+
### Fixed
28+
* Previously set dash patterns were not transferred correctly to new pages.
29+
* Inserted Vector images used to ignore the `keep_aspect_ratio` argument.
2430

2531
## [2.7.6] - 2023-10-11
2632
This release is the first performed from the [@py-pdf GitHub org](https://github.com/py-pdf), where `fpdf2` migrated.

docs/Development.md

+19
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pre-commit install
7070
To run tests, `cd` into `fpdf2` repository, install the dependencies using
7171
`pip install -r test/requirements.txt`, and run `pytest`.
7272

73+
You may also need to install [SWIG](https://swig.org/index.html) and [Ghostscript](https://www.ghostscript.com/).
74+
7375
You can run a single test by executing: `pytest -k function_name`.
7476

7577
Alternatively, you can use [Tox](https://tox.readthedocs.io/en/latest/).
@@ -116,9 +118,26 @@ All generated PDF files (including those processed by `qpdf`) will be stored in
116118
last test runs will be saved and then automatically deleted, so you can
117119
check the output in case of a failed test.
118120

121+
### Generating PDF files for testing
119122
In order to generate a "reference" PDF file, simply call `assert_pdf_equal`
120123
once with `generate=True`.
121124

125+
```
126+
import fpdf
127+
128+
svg = fpdf.svg.SVGObject.from_file("path/to/file.svg")
129+
pdf = fpdf.FPDF(unit="pt", format=(svg.width, svg.height))
130+
pdf.add_page()
131+
svg.draw_to_page(pdf)
132+
133+
assert_pdf_equal(
134+
pdf,
135+
"path/for/pdf/output.pdf",
136+
"path/for/pdf/",
137+
generate=True
138+
)
139+
```
140+
122141
## Testing performances
123142

124143
### Code speed & profiling

docs/SVG.md

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Additionally, `cairosvg` offers various options for optimizing the rendering per
190190
- stroke & fill coloring and opacity
191191
- basic stroke styling
192192
- Inline CSS styling via `style="..."` attributes.
193+
- clipping paths
194+
- `defs` tags anywhere in the SVG code
193195

194196
## Currently Unsupported Notable SVG Features ##
195197

docs/TextColumns.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ _New in [:octicons-tag-24: 2.7.6](https://github.com/py-pdf/fpdf2/blob/master/CH
77

88
The `FPDF.text_columns()` method allows to create columnar layouts, with one or several columns. Columns will always be of equal width.
99

10+
### Parameters ###
11+
1012
Beyond the parameters common to all text regions, the following are available for text columns:
1113

1214
* l_margin (float, optional) - override the current left page margin.
1315
* r_margin (float, optional) - override the current right page margin.
1416
* ncols (float, optional) - the number of columns to generate (Default: 2).
1517
* gutter (float, optional) - the horizontal space required between each two columns (Default 10).
18+
* balance (bool, optional) - Create height balanced columns, starting at the current height and ending at approximately the same level.
19+
20+
### Methods ###
21+
22+
Text columns support all the standard text region methods like `.paragraph()`, `.write()`, `.ln()`, and `.render()`. In addition to that:
23+
24+
* `.new_column()` - End the current column and continue at the top of the next one.
25+
26+
A FORM_FEED character (`\u000c`) in the text will have the same effect as an explicit call to `.new_column()`,
27+
28+
Note that when used within balanced columns, switching to a new column manually will result in incorrect balancing.
1629

1730

1831
#### Single-Column Example ####
@@ -85,7 +98,7 @@ with cols:
8598
```
8699
![Balanced Columns](tcols-balanced.png)
87100

88-
Note that column balancing only works reliably when the font size (specifically the line height) doesn't change. If parts of the text use a larger or smaller font than the rest, then the balancing will usually be out of whack. Contributions for a more refined balancing algorithm are welcome.
101+
Note that column balancing only works reliably when the font size (specifically the line height) doesn't change, and if there are no images included. If parts of the text use a larger or smaller font than the rest, then the balancing will usually be out of whack. Contributions for a more refined balancing algorithm are welcome.
89102

90103

91104
### Possible future extensions

docs/TextRegion.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ The horizontal start position will be either at the current x position, if that
4444
In both horizontal and vertical positioning, regions with multiple columns may follow additional rules and restrictions.
4545

4646

47-
### Interaction between Regions ###
47+
### Interaction Between Regions ###
4848

4949
Several region instances can exist at the same time. But only one of them can act as context manager at any given time. It is not currently possible to activate them recursively. But it is possible to use them intermittingly. This will probably most often make sense between a columnar region and a table or a graphic. You may have some running text ending at a given height, then insert a table/graphic, and finally continue the running text at the new height below the table within the existing column(s).
5050

5151

52-
### Common parameters ###
52+
### Common Parameters ###
5353

5454
All types of text regions have the following constructor parameters in common:
5555

@@ -59,14 +59,17 @@ All types of text regions have the following constructor parameters in common:
5959
* print_sh (bool, optional) - Treat a soft-hyphen (\\u00ad) as a printable character, instead of a line breaking opportunity. (Default: False)
6060
* skip_leading_spaces (default: False) - This flag is primarily used by `write_html()`, but may also have other uses. It removes all space characters at the beginning of each line.
6161
* wrapmode (default "WORD") -
62+
* image (str or PIL.Image.Image or io.BytesIO, optional) - An image to add to the region. This is a convenience parameter for cases when no further text or images need to be added to the paragraph. If both "text" and "image" arguments are present, the text will be inserted first. (Default: None)
63+
* image_fill_width (bool, optional) - Indicates whether to increase the size of the image to fill the width of the column. Larger images will always be reduced to column width. (Default: False)
6264

6365
All of those values can be overriden for each individual paragraph.
6466

6567

66-
### Common methods ###
68+
### Common Methods ###
6769

68-
* `.paragraph()` [see characteristics parameters below] - establish a new paragraph in the text. The text added to this paragraph will start on a new line.
70+
* `.paragraph()` [see characteristic parameters below] - establish a new paragraph in the text. The text added to this paragraph will start on a new line.
6971
* `.write(text: str, link: = None)` - write text to the region. This is only permitted when no explicit paragraph is currently active.
72+
* `.image()` [see characteristic parameters below] - insert a vector or raster image in the region, flowing with the text like a paragraph.
7073
* `.ln(h: float = None)` - Start a new line moving either by the current font height or by the parameter "h". Only permitted when no explicit paragraph is currently active.
7174
* `.render()` - if the region is not used as a context manager with "with", this method must be called to actually process the added text.
7275

@@ -87,9 +90,20 @@ For more typographical control, you can use the following arguments. Most of tho
8790
Other than text regions, paragraphs should always be used as context managers and never be reused. Violating those rules may result in the entered text turning up on the page out of sequence.
8891

8992

90-
### Possible future extensions
93+
### Possible Future Extensions ###
9194

9295
Those features are currently not supported, but Pull Requests are welcome to implement them:
9396

9497
* per-paragraph indentation
9598
* first-line indentation
99+
100+
101+
## Images ##
102+
103+
_New in [:octicons-tag-24: 2.7.7](https://github.com/py-pdf/fpdf2/blob/master/CHANGELOG.md)_
104+
105+
Most arguments for inserting images into text regions are the same as for the `FPDF.image()` method, and have the same or equivalent meaning.
106+
Since the image will be placed automatically, the "x" and "y" parameters are not available. The positioning can be controlled with "align", where the default is "LEFT", with the alternatives "RIGHT" and "CENTER".
107+
If neither width nor height are specified, the image will be inserted with the size resulting from the PDF default resolution of 72 dpi. If the "fill_width" parameter is set to True, it increases the size to fill the full column width if necessary. If the image is wider than the column width, it will always be reduced in size proportionally.
108+
The "top_margin" and "bottom_margin" parameters have the same effect as with text paragraphs.
109+

docs/Tutorial-es.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,30 @@ Este ejemplo es una variante del anterior, mostrando cómo poner el texto en mú
155155

156156
[Texto de Julio Verne](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
157157

158-
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
159-
160-
English versions:
161-
162-
* [Tuto 4 - Multi Columns](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-4-multi-columns)
163-
* [Documentation on TextColumns](https://py-pdf.github.io/fpdf2/TextColumns.html
158+
La diferencia clave respecto al tutorial anterior es el uso del
159+
método [`text_columns`](fpdf/fpdf.html#fpdf.fpdf.FPDF.text_column).
160+
Este recoge todo el texto, posiblemente en incrementos, y lo distribuye entre el número de columnas solicitadas, insertando automáticamente saltos de página según sea necesario. Nota que mientras la instancia de `TextColumns` está activa como gestor de contexto, los estilos de texto y otras propiedades de la fuente pueden cambiarse. Estos cambios estarán contenidos en el contexto. Una vez se cierre, la configuración previa será reestablecida.
164161

165162

166163
## Tutorial 5 - Creando tablas ##
167164

165+
Este tutorial explicará cómo crear dos tablas diferentes,
166+
para demostrar lo que se puede lograr con algunos ajustes simples.
167+
168168
```python
169169
{% include "../tutorial/tuto5.py" %}
170170
```
171171

172172
[PDF resultante](https://github.com/py-pdf/fpdf2/raw/master/tutorial/tuto5.pdf) -
173173
[Archivo de texto con países](https://github.com/py-pdf/fpdf2/raw/master/tutorial/countries.txt)
174174

175-
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
176-
177-
English versions:
175+
El primer ejemplo es alcanzado de la forma más básica posible, alimentando datos a [`FPDF.table()`](https://py-pdf.github.io/fpdf2/Tables.html). El resultado es rudimentario pero muy rápido de obtener.
178176

179-
* [Tuto 5 - Creating Tables](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-5-creating-tables)
180-
* [Documentation on tables](https://py-pdf.github.io/fpdf2/Tables.html)
177+
La segunda tabla trae algunas mejoras: colores, ancho de tabla limitado, altura de línea reducida,
178+
títulos centrados, columnas con anchos personalizados, figuras alineadas a la derecha...
179+
Aún más, las líneas horizontales han sido removidas.
180+
Esto se hizo escogiendo un `borders_layout` entre los valores disponibles:
181+
[`TableBordersLayout`](https://py-pdf.github.io/fpdf2/fpdf/enums.html#fpdf.enums.TableBordersLayout).
181182

182183
## Tutorial 6 - Creando enlaces y combinando estilos de texto ##
183184

0 commit comments

Comments
 (0)