Skip to content

Commit

Permalink
Extra fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Nov 20, 2024
1 parent a0d944d commit a70c6f1
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 140 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
* [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): now parses `<title>` tags to set the [document title](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.set_title). By default, it is added as PDF metadata, but not rendered in the document body. However, this can be enabled by passing `render_title_tag=True` to `FPDF.write_html()`.
* support for LZWDecode compression [issue #1271](https://github.com/py-pdf/fpdf2/issues/1271)
### Fixed
* support for `align=` in [`FPDF.table()`](https://py-pdf.github.io/fpdf2/Tables.html#setting-table-column-widths)
* support for `align=` in [`FPDF.table()`](https://py-pdf.github.io/fpdf2/Tables.html#setting-table-column-widths). Due to this correction, tables are now properly horizontally aligned on the page by default. This was always specified in the documentation, but was not in effect until now. You can revert to have left-aligned tables by passing `align="LEFT"` to `FPDF.table()`.
* `FPDF.set_text_shaping(False)` was broken since version 2.7.8 and is now working properly - [issue #1287](https://github.com/py-pdf/fpdf2/issues/1287)
* fixed bug where cells with `rowspan`, `colspan` > 1 and null text were not displayed properly - [issue #1293](https://github.com/py-pdf/fpdf2/issues/1293)
### Changed
Expand Down
9 changes: 7 additions & 2 deletions docs/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ We use [black](https://github.com/psf/black) as a code prettifier.
This _"uncomprimising Python code formatter"_ must be installed
in your development environment in order to auto-format source code before any commit:
```
pip install --upgrade . -r test/linters-requirements.txt
pip install black
black . # inside fpdf2 root directory
```

## Linting
We use [pylint](https://github.com/PyCQA/pylint/) as a static code analyzer
to detect potential issues in the code.
You can install & execute it by running those commands:
```
pip install pylint
pylint fpdf/ test/
```

In case of special "false positive" cases,
checks can be disabled locally with `#pylint disable=XXX` code comments,
Expand All @@ -60,7 +65,7 @@ and you will just have to run `git commit -a` again.

To install pre-commit hooks on your computer, run:
```
pip install --upgrade . -r test/linters-requirements.txt
pip install pre-commit
pre-commit install
```

Expand Down
17 changes: 9 additions & 8 deletions fpdf/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ def render(self):
# Starting with some sanity checks:
self._cols_count = max(row.cols_count for row in self.rows) if self.rows else 0
if self._width is None:
if self._col_widths:
if isinstance(self._col_widths, Number):
self._width = self._cols_count * self._col_widths
else:
self._width = sum(self._col_widths)
if self._col_widths and isinstance(self._col_widths, Number):
self._width = self._cols_count * self._col_widths
else:
self._width = self._fpdf.epw
elif self._col_widths and isinstance(self._col_widths, Number):
if self._cols_count * self._col_widths != self._width:
raise ValueError(
f"Invalid value provided width={self._width} should be a multiple of col_widths={self._col_widths}"
)
if self._width > self._fpdf.epw:
raise ValueError(
f"Invalid value provided width={self._width}: effective page width is {self._fpdf.epw}"
Expand Down Expand Up @@ -209,7 +211,7 @@ def render(self):
self._fpdf.l_margin = self._fpdf.x

# Pre-Compute the relative x-positions of the individual columns:
xx = self._outer_border_margin[0]
xx = self._fpdf.l_margin + self._outer_border_margin[0]
cell_x_positions = [xx]
if self.rows:
for i in range(self._cols_count):
Expand Down Expand Up @@ -398,8 +400,7 @@ def _render_table_cell(
cell_x = 0
else:
cell_x = cell_x_positions[j]

self._fpdf.set_x(self._fpdf.l_margin + cell_x)
self._fpdf.set_x(cell_x)

# render cell border and background

Expand Down
Binary file modified test/embed_file_all_optionals.pdf
Binary file not shown.
Binary file modified test/embed_file_self.pdf
Binary file not shown.
Binary file modified test/file_attachment_annotation.pdf
Binary file not shown.
Binary file modified test/table/table_with_fixed_col_width.pdf
Binary file not shown.
Binary file modified test/table/table_with_fixed_col_width_and_align.pdf
Binary file not shown.
Binary file added test/table/table_with_gutter_and_width.pdf
Binary file not shown.
Loading

0 comments on commit a70c6f1

Please sign in to comment.