Skip to content

Commit

Permalink
Minor fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed May 8, 2023
1 parent 47e910f commit e208ab4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/Transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ with pdf.skew(ax=-45, ay=0, x=100, y=170):

## Mirror ##

_New in [:octicons-tag-24: 2.7.5](https://github.com/PyFPDF/fpdf2/blob/master/CHANGELOG.md)_
The `mirror` context-manager applies a mirror transformation to all objects inserted in its indented block over a given mirror line by specifying starting co-ordinate and angle.

```python
x = 100
y = 100
x, y = 100, 100
pdf.text(x, y, txt="mirror this text")
with pdf.mirror((x, y), "EAST"):
pdf.set_text_color(r=255, g=128, b=0)
Expand Down
4 changes: 1 addition & 3 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,12 +2585,10 @@ def mirror(self, origin, angle):
context (with the exception of clickable areas).
Args:
origin (Sequence(float, float)): a point on the mirror line
origin (float, Sequence(float, float)): a point on the mirror line
angle: (fpdf.enums.Angle): the direction of the mirror line
"""
angle = Angle.coerce(angle)
x, y = origin

try:
theta = Angle.coerce(angle).value
except ValueError:
Expand Down
Binary file modified test/mirror_multi_cell.pdf
Binary file not shown.
Binary file renamed help.pdf → test/mirror_with_angle_as_number.pdf
Binary file not shown.
23 changes: 17 additions & 6 deletions test/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ def draw_mirror_line(pdf, origin, angle):
Args:
pdf (fpdf.FPDF): pdf to modify
origin (Sequence[float, float]): a point on the mirror line
origin (float, Sequence[float, float]): a point on the mirror line
angle: (fpdf.enums.Angle): the direction of the mirror line
"""

angle = Angle.coerce(angle)

x, y = origin

theta = angle.value
try:
theta = Angle.coerce(angle).value
except ValueError:
theta = angle

cos_theta, sin_theta = (
math.cos(math.radians(theta)),
Expand Down Expand Up @@ -71,6 +70,18 @@ def test_mirror(tmp_path):
assert_pdf_equal(pdf, HERE / "mirror.pdf", tmp_path)


def test_mirror_with_angle_as_number(tmp_path):
pdf = FPDF()
pdf.set_font("helvetica", size=50)
pdf.add_page()
x, y = 50, 50
pdf.text(x, y, txt="mirror this text")
with pdf.mirror((x, y), 180):
pdf.set_text_color(r=255, g=128, b=0)
pdf.text(x, y, txt="mirror this text")
assert_pdf_equal(pdf, HERE / "mirror_with_angle_as_number.pdf", tmp_path)


def test_mirror_text(tmp_path):
pdf = FPDF()
pdf.add_page()
Expand Down

0 comments on commit e208ab4

Please sign in to comment.