-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature: FPDF.mirror() #536
Comments
I'm not sure if we should overload We already have with pdf.rotation(angle=90, x=x, y=y):
pdf.something() A separate with pdf.shearing(angle=30):
pdf.something() Is the difference betwen shearing and skewing just the direction? Maybe calling them something like Oh, and once we're at it, how about All of those are of course able to be nested, and their application is not limited to text at all. |
Oh you mean that in this case: with pdf.local_context(text_shear=45, text_skew=-45):
pdf.cell(txt="hello world") ...the order of the "skew" & "shear" operations is ambiguous? I agree with the idea of separate context-managers then.
No, I made a distinction between them in my mind, but now I realize the terms were wrong... This feature covers two kind of text transformations:
Good idea! |
Hi, I'm new to fpdf and to the inner workings of the PDF format in general, but I dove a bit into this particular use case and it seems interesting, I am willing to take this. Just a question regarding a possible implementation - From what I understand a
inside of a P.S - I work full-time so I'm not sure everything will be immediate, but I'll do my best! |
Great, thank you for your interest @erap129! 😊
Yes
OK. This property would then be taken in consideration by which methods? All text-rendering ones?
No worry, contribution are always best-effort, volunteer work: you do as much as you want/can, no pressure 😉 |
On second thought, this is silly. The approach you suggest is fine with me @erap129. |
OK after digging in a bit I found that the |
@erap129: based on the page you linked, this effect ( |
The text distinguishes between affine and projective transformations, both of which are linear transformations. The PDF specs use neither of those terms though, but only talk about matrices and transformations without any special qualification. This seems to imply the more general linear transformation type, which would allow for perspective distortion. I guess it's a matter of experimentation about what exactly the various readers can handle. Apart from that, I'd be more interested in how this functionality can be made accessible to users without a higher math education. The most flexible way would be to let the caller specify the full matrix, but that is also the least convenient approach for manipulating text (more suitable for transforming graphics in general). Note that I'm not saying that you need to implement every possible variation now. In fact, I'd recommend to just start eg. with the text skew operations only. But whatever you start with should be part of a larger concept encompassing the rest. Maybe we should check out other software packages and see what approaches they have taken to present similar functionality. |
You may have found that already, but in general any such new parameters should be implemented in In light of my above reply though, this approach has a disadvantage in this special case, in that it works on a per-fragment basis. With HTML/Markdown styling or through
I'm not sure we need a seperate context manager for that. It should probably be enough to use
|
I'm interested in taking upon the mirror implementation :) @Lucas-C with point reflection, would users have to specify the type of reflection e.g. vertically/horizontally/digaonally? Or would an input argument representing a mirror line be more appropriate? If so, I think two points would be the most flexible approach of representing a line. |
An interesting and important question! A mirror line can be specified in two ways:
While the two are mathematically equivalent, I suspect that most people will first think of an angle when asked to specify the direction of a line. Only in an interactive application does it end up easier to pick two points than to specify an angle, but that is not really our use case. You could also offer both options next to each other: with pdf.mirroring(
origin: Sequence[float, float],
angle: Union[Angle, float] = None,
pt2 : Sequence[float, float] = None
):
.... where exactly one of |
Great! That's very good news @sebastiantia 😊 Go for it!
I fully agree. A basic usage example could then be: with pdf.mirroring(origin=(pdf.epw/2, 0), angle="SOUTH"):
pdf.circle(pdf.epw/4, pdf.epw/2, 50) |
The mirror function has been implemented by @sebastiantia in PR #783 Closing this issue |
Original issue title: New feature: text transformations - skew, diagonal text, mirror
The idea comes from one of @digidigital recipes: https://github.com/digidigital/Extensions-and-Scripts-for-pyFPDF-fpdf2/tree/main/skew_shear_rotate_text#skew-shear-and-rotate-text (cf. #274)
In terms of design / API, a potential user-interface could be to give access to the underlying
Tm
PDF operator throughtext_skew
&text_shear
parameters that could be passed to local_context(), so that this feature could affect calls to.write()
,.cell()
or.text()
:Of course, new unit tests should be added, as well as a bit of user documentation
You are also free to suggest another API/implementation/user-interface
By implementing this feature you, as a benevolent FLOSS developper, will provide access to the large community of fpdf2 users to a useful functionality.
As a contributor you will get review feedbacks from the maintainer & other contributors, and learn about the lifecycle & structure of a Python library on the way.
You will also be added to the contributors list & map.
This issue can count as part of hacktoberfest
The text was updated successfully, but these errors were encountered: