Open Lucas-C opened 1 month ago
At the moment, I think that proposed solution would result in infinite recursion. We'd have to move the part of set_font()
that sets self.current_font
into an internal method _set_font()
to avoid this, and only use that one from the other property setters.
I agree that in the user facing API, we should try to treat "bold", "italic", and "underline" as similarly as possible. When storing them internally though, collecting them into a single "emphasis" string seems to make their use a bit cumbersome. Alternatively we could just as well store three booleans seperately, and only combine them into a string when the user requests one. It will take a bit of code analysis to figure out which strategy will result in the simpler code overall. Currently the font selection key is created by appendeing a "[b]?[i]?" string to the family, though. Is there a more straightforward way to do that?
At the moment, I think that proposed solution would result in infinite recursion. We'd have to move the part of
set_font()
that setsself.current_font
into an internal method_set_font()
to avoid this, and only use that one from the other property setters.
Yes, you are right, we would have to take care of that.
When storing them internally though, collecting them into a single "emphasis" string seems to make their use a bit cumbersome.
Could you please develop a bit why?
This may be subjective, I find this actually a lot more elegant & handy than having 3 attributes 😅
I see the following "factual" benefits of having a single attribute (._emphasis
) instead of 4 distinct ones:
fpdf2
source code involving this classHowever, I agree that having 4 distinct attributes would probably make the code often simpler to grasp, and would hence be better for the readibility of fpdf2
source code.
Problem As demonstrated in https://github.com/py-pdf/fpdf2/issues/1220#issuecomment-2221497527, currently setting
pdf.font_style = "B"
does not properly apply a bold emphasis to the following text:Describe the solution you'd like
As part of this change, I suggest to replace the
.underline
&.font_style
attributes ofFPDF
by getters & setters modifying an underlying._emphasis
property.RFC: Whad fo you think of this proposal?