Skip to content
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

write_html(): homogenization in handling of tag_styles + new optional arg font_family #1217

Merged
merged 9 commits into from
Jul 5, 2024
3 changes: 1 addition & 2 deletions docs/HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pdf.write_html("""
pdf.output("html.pdf")
```


### Styling HTML tags globally

_New in [:octicons-tag-24: 2.7.9](https://github.com/py-pdf/fpdf2/blob/master/CHANGELOG.md)_
Expand Down Expand Up @@ -135,7 +134,7 @@ However, **Pull Request are welcome** to implement missing features!

## Supported HTML features

* `<h1>` to `<h8>`: headings (and `align` attribute)
* `<h1>` to `<h6>`: headings (and `align` attribute)
* `<p>`: paragraphs (and `align`, `line-height` attributes)
* `<br>` & `<hr>` tags
* `<b>`, `<i>`, `<u>`: bold, italic, underline
Expand Down
16 changes: 12 additions & 4 deletions fpdf/fpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,12 @@ def __init__(
# Graphics state variables defined as properties by GraphicsStateMixin.
# We set their default values here.
self.font_family = "" # current font family
self.font_style = "" # current font style
# current font style (BOLD/ITALICS - does not handle UNDERLINE):
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
self.font_style = ""
self.underline = False # underlining flag
self.font_size_pt = 12 # current font size in points
self.font_stretching = 100 # current font stretching
self.char_spacing = 0 # current character spacing
self.underline = False # underlining flag
self.current_font = None # None or an instance of CoreFont or TTFFont
self.draw_color = self.DEFAULT_DRAW_COLOR
self.fill_color = self.DEFAULT_FILL_COLOR
Expand Down Expand Up @@ -410,11 +411,18 @@ def _set_min_pdf_version(self, version):
self.pdf_version = max(self.pdf_version, version)

@property
def is_ttf_font(self):
def emphasis(self) -> TextEmphasis:
"The current text emphasis: bold, italics and/or underlined."
return TextEmphasis.coerce(
f"{self.font_style}U" if self.underline else self.font_style
)

@property
def is_ttf_font(self) -> bool:
return self.current_font and self.current_font.type == "TTF"

@property
def page_mode(self):
def page_mode(self) -> PageMode:
return self._page_mode

@page_mode.setter
Expand Down
Loading
Loading