././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1662636 weasyprint-67.0/LICENSE0000644000000000000000000000277615113607644011631 0ustar00BSD 3-Clause License Copyright (c) 2011-2021, Simon Sapin and contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1662636 weasyprint-67.0/README.rst0000644000000000000000000000314515113607644012302 0ustar00**The Awesome Document Factory** WeasyPrint is a smart solution helping web developers to create PDF documents. It turns simple HTML pages into gorgeous statistical reports, invoices, tickets… From a technical point of view, WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing. WeasyPrint is free software made available under a BSD license. It is based on various libraries but *not* on a full rendering engine like WebKit or Gecko. The CSS layout engine is written in Python, designed for pagination, and meant to be easy to hack on. * Free software: BSD license * For Python 3.10+, tested on CPython and PyPy * Documentation: https://doc.courtbouillon.org/weasyprint * Examples: https://weasyprint.org/#samples * Changelog: https://github.com/Kozea/WeasyPrint/releases * Code, issues, tests: https://github.com/Kozea/WeasyPrint * Code of conduct: https://www.courtbouillon.org/code-of-conduct * Professional support: https://www.courtbouillon.org * Donation: https://opencollective.com/courtbouillon WeasyPrint has been created and developed by Kozea (https://kozea.fr/). Professional support, maintenance and community management is provided by CourtBouillon (https://www.courtbouillon.org/). Copyrights are retained by their contributors, no copyright assignment is required to contribute to WeasyPrint. Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion is licensed under the BSD 3-clause license, without any additional terms or conditions. For full authorship information, see the version control history. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1662636 weasyprint-67.0/docs/api_reference.rst0000644000000000000000000010120015113607644015053 0ustar00API Reference ============= .. currentmodule:: weasyprint This page is for WeasyPrint |version|. See :doc:`changelog ` for older versions. API Stability ------------- Everything described here is considered “public”: this is what you can rely on. We will try to maintain backward-compatibility, and we really often do, but there is no hard promise. Anything else should not be used outside of WeasyPrint itself. We reserve the right to change it or remove it at any point. Use it at your own risk, or have dependency to a specific WeasyPrint version. Versioning ---------- WeasyPrint provides frequent major releases, and minor releases with only bug fixes. Versioning is close to what many browsers do, including Firefox and Chrome: big major numbers, small minor numbers. Even if each version does not break the API, each version does break the way documents are rendered, which is what really matters at the end. Providing minor versions would give the illusion that developers can just update WeasyPrint without checking that everything works. Unfortunately, we have the same problem as the other browsers: when a new version is released, most of the user's websites are rendered exactly the same, but a small part is not. And the only ways to know that, for web developers, are to read the changelog and to check that their pages are correctly rendered. More about this choice can be found in issue `#900`_. .. _#900: https://github.com/Kozea/WeasyPrint/issues/900 Command-line API ---------------- .. autofunction:: weasyprint.__main__.main(argv=sys.argv) Python API ---------- .. autoclass:: HTML(input, **kwargs) :members: .. autoclass:: CSS(input, **kwargs) .. autoclass:: Attachment(input, **kwargs) .. autofunction:: default_url_fetcher .. autodata:: DEFAULT_OPTIONS .. module:: weasyprint.document .. autoclass:: Document :members: .. autoclass:: DocumentMetadata() :members: .. autoclass:: Page() :members: :exclude-members: paint .. module:: weasyprint.text.fonts .. autoclass:: FontConfiguration() .. module:: weasyprint.css.counters .. autoclass:: CounterStyle() Supported Features ------------------ URLs ~~~~ WeasyPrint can read normal files, HTTP, FTP and `data URIs`_. It will follow HTTP redirects but more advanced features like cookies and authentication are currently not supported, although a custom :ref:`URL fetcher ` can help. .. _data URIs: https://en.wikipedia.org/wiki/Data_URI_scheme HTML ~~~~ Supported HTML Tags +++++++++++++++++++ Many HTML elements are implemented in CSS through the HTML5 `User-Agent stylesheet`_. Some elements need special treatment: * The ```` element, if present, determines the base for relative URLs. * CSS stylesheets can be embedded in `` … Automatic hyphenation can be disabled again with the ``manual`` value: .. code-block:: css html { hyphens: auto } a[href]::after { content: ' [' attr(href) ']'; hyphens: manual } The other features provided by `CSS Text Module Level 3`_ are **not** supported: - the ``line-break`` property; - the ``match-parent`` value of the ``text-align`` property; - the ``text-indent`` and ``hanging-punctuation`` properties. The other features provided by `CSS Text Module Level 4`_ are **not** supported: - the ``text-space-collapse`` and ``text-space-trim`` properties; - the ``text-wrap``, ``wrap-before``, ``wrap-after`` and ``wrap-inside`` properties; - the ``text-align`` property with an alignment character; - the ``pre-wrap-auto`` value of the ``white-space`` property; and - the ``text-spacing`` property. .. _#1153: https://github.com/Kozea/WeasyPrint/issues/1153 .. _supported by Pyphen: https://github.com/Kozea/Pyphen/tree/main/pyphen/dictionaries .. _hyphenation: https://www.w3.org/TR/css-text-3/#hyphenation .. _CSS Text Module Level 3: https://www.w3.org/TR/css-text-3/ .. _CSS Text Module Level 4: https://www.w3.org/TR/css-text-4/ CSS Fonts Module Level 3 / 4 ++++++++++++++++++++++++++++ The `CSS Fonts Module Level 3`_ is a candidate recommendation describing "how font properties are specified and how font resources are loaded dynamically". WeasyPrint supports the ``font-size``, ``font-stretch``, ``font-style`` and ``font-weight`` properties, coming from CSS 2.1. WeasyPrint also supports the following font features added in Level 3: - ``font-kerning``, - ``font-variant-ligatures``, - ``font-variant-position``, - ``font-variant-caps``, - ``font-variant-numeric``, - ``font-variant-east-asian``, - ``font-feature-settings``, and - ``font-language-override``. ``font-family`` is supported. The string is given to Pango that tries to find a matching font in a way different from what is defined in the recommendation, but that should not be a problem for common use. The shorthand ``font`` and ``font-variant`` properties are supported. WeasyPrint supports the ``@font-face`` rule. WeasyPrint does **not** support the ``@font-feature-values`` rule and the values of ``font-variant-alternates`` other than ``normal`` and ``historical-forms``. From `CSS Fonts Module Level 4`_ we only support the ``font-variation-settings`` property enabling specific font variations. .. _CSS Fonts Module Level 3: https://www.w3.org/TR/css-fonts-3/ .. _CSS Fonts Module Level 4: https://www.w3.org/TR/css-fonts-4/ CSS Paged Media Module Level 3 ++++++++++++++++++++++++++++++ The `CSS Paged Media Module Level 3`_ is a working draft including features for paged media "describing how: - page breaks are created and avoided; - the page properties such as size, orientation, margins, border, and padding are specified; - headers and footers are established within the page margins; - content such as page counters are placed in the headers and footers; and - orphans and widows can be controlled." All the features of this draft are available, including: - the ``@page`` rule and the ``:left``, ``:right``, ``:first`` and ``:blank`` selectors; - the page margin boxes; - the page-based counters (with known limitations `#93`_); - the page ``size``, ``bleed`` and ``marks`` properties; - the named pages. .. _CSS Paged Media Module Level 3: https://drafts.csswg.org/css-page-3/ .. _#93: https://github.com/Kozea/WeasyPrint/issues/93 CSS Generated Content for Paged Media Module ++++++++++++++++++++++++++++++++++++++++++++ The `CSS Generated Content for Paged Media Module`_ (GCPM) is a working draft defining "new properties and values, so that authors may bring new techniques (running headers and footers, footnotes, page selection) to paged media". `Page selectors`_ are supported by WeasyPrint. You can select pages according to their position in the document: .. code-block:: css @page :nth(3) { background: red } /* Third page */ @page :nth(2n+1) { background: green } /* Odd pages */ @page :nth(1 of chapter) { background: blue } /* First pages of chapters */ You can also use `running elements`_ to put HTML boxes into the page margins (but the ``start`` parameter of ``element()`` is not supported). Footnotes_ are supported. You can put a box in the footnote area using the ``float: footnote`` property. Footnote markers and footnote calls can be defined using the ``::footnote-marker`` and ``::footnote-call`` pseudo-elements. You can also change the way footnotes are displayed using the ``footnote-display`` property (``compact`` is not supported), and influence over the rendering of difficult pages with ``footnote-policy``. .. _CSS Generated Content for Paged Media Module: https://www.w3.org/TR/css-gcpm-3/ .. _Page selectors: https://www.w3.org/TR/css-gcpm-3/#document-page-selectors .. _running elements: https://www.w3.org/TR/css-gcpm-3/#running-elements .. _Footnotes: https://www.w3.org/TR/css-gcpm-3/#footnotes CSS Generated Content Module Level 3 ++++++++++++++++++++++++++++++++++++ The `CSS Generated Content Module Level 3`_ is a working draft helping "authors [who] sometimes want user agents to render content that does not come from the document tree. One familiar example of this is numbered headings […]. Similarly, authors may want the user agent to insert the word "Figure" before the caption of a figure […], or replacing elements with images or other multimedia content." `Named strings`_ are supported by WeasyPrint. You can define strings related to the first or last element of a type present on a page, and display these strings in page borders. This feature is really useful to add the title of the current chapter at the top of the pages of a book for example. The named strings can embed static strings, counters, cross-references, tag contents and tag attributes. .. code-block:: css @top-center { content: string(chapter) } h2 { string-set: chapter "Current chapter: " content() } `Cross-references`_ retrieve counter or content values from targets (anchors or identifiers) in the current document: .. code-block:: css a::after { content: ", on page " target-counter(attr(href), page) } a::after { content: ", see " target-text(attr(href)) } In particular, ``target-counter()`` and ``target-text()`` are useful when it comes to tables of contents (see `an example`_). You can also control `PDF bookmarks`_ with WeasyPrint. Using the ``bookmark-level``, ``bookmark-label`` and ``bookmark-state`` properties, you can add bookmarks that will be available in your PDF reader. Bookmarks have already been added in the WeasyPrint's `user agent stylesheet`_, so your generated documents will automatically have bookmarks on headers (from ``

`` to ``

``). But for example, if you have only one top-level ``

`` and do not wish to include it in the bookmarks, add this in your stylesheet: .. code-block:: css h1 { bookmark-level: none } `Leaders`_ are also supported: .. code-block:: css li a::after { content: ' ' leader(dotted) ' ' target-counter(attr(href), page); } The other features of this module are **not** implemented: - quotes (``content: *-quote``); .. _CSS Generated Content Module Level 3: https://www.w3.org/TR/css-content-3/ .. _Quotes: https://www.w3.org/TR/css-content-3/#quotes .. _Named strings: https://www.w3.org/TR/css-content-3/#named-strings .. _Cross-references: https://www.w3.org/TR/css-content-3/#cross-references .. _an example: https://github.com/Kozea/WeasyPrint/pull/652#issuecomment-403276559 .. _PDF bookmarks: https://www.w3.org/TR/css-content-3/#bookmark-generation .. _user agent stylesheet: https://github.com/Kozea/WeasyPrint/blob/main/weasyprint/css/html5_ua.css .. _Leaders: https://www.w3.org/TR/css-content-3/#leaders CSS Color Module Level 4 / 5 ++++++++++++++++++++++++++++ The `CSS Color Module Level 4`_ is a recommendation defining "CSS properties which allow authors to specify the foreground color and opacity of the text content of an element". Its main goal is to specify how colors are defined, including color keywords and many color notations including ``#rgba``, ``rgb()``, ``hsl()``, ``hwb()``, ``lab()``, etc. The standard ``color()`` function gives a common way to define colors giving their color space. Opacity and alpha compositing are also defined in this document. This recommendation is fully implemented in WeasyPrint, except the deprecated System Colors. The `CSS Color Module Level 5`_ is a working draft adding "color modification functions, custom color spaces (ICC profiles), ``contrast-color()``, ``light-dark()`` and ``device-cmyk()``" to level 4. WeasyPrint supports the ``light-dark()`` and ``device-cmyk()`` properties, and the ``@color-profile`` at-rule. WeasyPrint does **not** support the ``color-mix()`` and ``contrast-color()`` properties. .. _CSS Color Module Level 4: https://www.w3.org/TR/css-color-4/ .. _CSS Color Module Level 5: https://www.w3.org/TR/css-color-5/ CSS Transforms Module Level 1 +++++++++++++++++++++++++++++ The `CSS Transforms Module Level 1`_ working draft "describes a coordinate system within each element is positioned. This coordinate space can be modified with the transform property. Using transform, elements can be translated, rotated and scaled in two or three dimensional space." WeasyPrint supports the ``transform`` and ``transform-origin`` properties, and all the 2D transformations (``matrix``, ``rotate``, ``translate``, ``translateX``, ``translateY``, ``scale``, ``scaleX``, ``scaleY``, ``skew``, ``skewX``, ``skewY``). WeasyPrint does **not** support the ``transform-style``, ``perspective``, ``perspective-origin`` and ``backface-visibility`` properties, and all the 3D transformations (``matrix3d``, ``rotate3d``, ``rotateX``, ``rotateY``, ``rotateZ``, ``translate3d``, ``translateZ``, ``scale3d``, ``scaleZ``). .. _CSS Transforms Module Level 1: https://drafts.csswg.org/css-transforms-1/ CSS Backgrounds and Borders Module Level 3 ++++++++++++++++++++++++++++++++++++++++++ The `CSS Backgrounds and Borders Module Level 3`_ is a candidate recommendation defining properties dealing "with the decoration of the border area and with the background of the content, padding and border areas". The `border part`_ of this module is supported, as it is already included in the the CSS 2.1 specification. WeasyPrint supports the `background part`_ of this module (allowing multiple background layers per box), including the ``background``, ``background-color``, ``background-image``, ``background-repeat``, ``background-attachment``, ``background-position``, ``background-clip``, ``background-origin`` and ``background-size`` properties. WeasyPrint also supports the `rounded corners part`_ of this module, including the ``border-radius`` property. WeasyPrint also supports the `border images part`_ of this module, including the ``border-image``, ``border-image-source``, ``border-image-slice``, ``border-image-width``, ``border-image-outset`` and ``border-image-repeat`` properties. WeasyPrint does **not** support the `box shadow part`_ of this module, including the ``box-shadow`` property. This feature has been implemented in a `git branch`_ that is not released, as it relies on raster implementation of shadows. .. _CSS Backgrounds and Borders Level 3: https://www.w3.org/TR/css-backgrounds-3/ .. _border part: https://www.w3.org/TR/css-backgrounds-3/#borders .. _background part: https://www.w3.org/TR/css-backgrounds-3/#backgrounds .. _rounded corners part: https://www.w3.org/TR/css-backgrounds-3/#corners .. _border images part: https://www.w3.org/TR/css-backgrounds-3/#border-images .. _box shadow part: https://www.w3.org/TR/css-backgrounds-3/#misc .. _git branch: https://github.com/Kozea/WeasyPrint/pull/149 CSS Image Values and Replaced Content Module Level 3 / 4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The `Image Values and Replaced Content Module Level 3`_ is a candidate recommendation introducing "additional ways of representing 2D images, for example as a list of URIs denoting fallbacks, or as a gradient", defining "several properties for manipulating raster images and for sizing or positioning replaced elements" and "generic sizing algorithm for replaced elements". The `Image Values and Replaced Content Module Level 4`_ is a working draft on the same subject. The ``linear-gradient()``, ``radial-gradient()`` and ``repeating-radial-gradient()`` properties are supported as background images. The the ``url()`` notation is supported, but the ``image()`` notation is **not** supported for background images. The ``object-fit`` and ``object-position`` properties are supported. The ``from-image`` and ``snap`` values of the ``image-resolution`` property are **not** supported, but the ``resolution`` value is supported. The ``image-rendering`` and ``image-orientation`` properties are supported. .. _Image Values and Replaced Content Module Level 3: https://www.w3.org/TR/css-images-3/ .. _Image Values and Replaced Content Module Level 4: https://www.w3.org/TR/css-images-4/ CSS Box Sizing Module Level 3 +++++++++++++++++++++++++++++ The `CSS Box Sizing Module Level 3`_ is a candidate recommendation extending "the CSS sizing properties with keywords that represent content-based 'intrinsic' sizes and context-based 'extrinsic' sizes." The new property defined in this document is implemented in WeasyPrint: ``box-sizing``. The ``min-content``, ``max-content`` and ``fit-content()`` sizing values are **not** supported. .. _CSS Box Sizing Module Level 3: https://www.w3.org/TR/css-sizing-3/ CSS Overflow Module Level 3 +++++++++++++++++++++++++++ The `CSS Overflow Module Level 3`_ is a working draft containing "the features of CSS relating to scrollable overflow handling in visual media." The ``overflow`` property is supported, as defined in CSS2. ``overflow-x``, ``overflow-y``, ``overflow-clip-margin``, ``overflow-inline`` and ``overflow-block`` are **not** supported. The ``text-overflow``, ``block-ellipsis``, ``line-clamp``, ``max-lines`` and ``continue`` properties are supported. .. _CSS Overflow Module Level 3: https://www.w3.org/TR/2020/WD-css-overflow-3-20200603/ CSS Values and Units Module Level 3 +++++++++++++++++++++++++++++++++++ The `CSS Values and Units Module Level 3`_ defines various units and keywords used in "value definition field of each CSS property". The ``initial`` and ``inherit`` CSS-wide keywords are supported, but the ``unset`` keyword is **not** supported. Quoted strings, URLs and numeric data types are supported. Font-related lengths (``em``, ``ex``, ``ch``, ``rem``), absolute lengths (``cm``, ``mm``, ``q``, ``in``, ``pt``, ``pc``, ``px``), angles (``rad``, ``grad``, ``turn``, ``deg``), resolutions (``dpi``, ``dpcm``, ``dppx``) are supported. The ``attr()`` functional notation is allowed in the ``content`` and ``string-set`` properties. The ``calc()`` function is **not** supported. Viewport-percentage lengths (``vw``, ``vh``, ``vmin``, ``vmax``) are **not** supported. .. _CSS Values and Units Module Level 3: https://www.w3.org/TR/css3-values/ CSS Multi-column Layout Module ++++++++++++++++++++++++++++++ The `CSS Multi-column Layout Module`_ "describes multi-column layouts in CSS, a style sheet language for the web. Using functionality described in the specification, content can be flowed into multiple columns with a gap and a rule between them." Simple multi-column layouts are supported in WeasyPrint. Features such as constrained height, spanning columns or column breaks are **not** supported. Pagination and overflow are not seriously tested. The ``column-width`` and ``column-count`` properties, and the ``columns`` shorthand property are supported. The ``column-gap``, ``column-rule-color``, ``column-rule-style`` and ``column-rule-width`` properties, and the ``column-rule`` shorthand property are supported. The ``break-before``, ``break-after`` and ``break-inside`` properties are supported. The ``column-span`` property is supported for direct children of columns. The ``column-fill`` property is supported, with a column balancing algorithm that should be efficient with simple cases. .. _CSS Multi-column Layout Module: https://www.w3.org/TR/css-multicol-1/ CSS Fragmentation Module Level 3 / 4 ++++++++++++++++++++++++++++++++++++ The `CSS Fragmentation Module Level 3`_ "describes the fragmentation model that partitions a flow into pages, columns, or regions. It builds on the Page model module and introduces and defines the fragmentation model. It adds functionality for pagination, breaking variable fragment size and orientation, widows and orphans." The `CSS Fragmentation Module Level 4`_ is a working draft on the same subject. The ``break-before``, ``break-after`` and ``break-inside`` properties are supported for pages, but **not** for columns and regions. ``page-break-*`` aliases as defined in CSS2 are supported too. The ``orphans`` and ``widows`` properties are supported. The ``box-decoration-break`` property is supported, but backgrounds are always repeated and not extended through the whole box as it should be with 'slice' value. The ``margin-break`` property is supported. .. _CSS Fragmentation Module Level 3: https://www.w3.org/TR/css-break-3/ .. _CSS Fragmentation Module Level 4: https://www.w3.org/TR/css-break-4/ CSS Custom Properties for Cascading Variables Module Level 1 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The `CSS Custom Properties for Cascading Variables Module Level 1`_ "introduces cascading variables as a new primitive value type that is accepted by all CSS properties, and custom properties for defining them." The custom properties and the ``var()`` notation are supported. .. _CSS Custom Properties for Cascading Variables Module Level 1: https://www.w3.org/TR/css-variables/ CSS Text Decoration Module Level 3 / 4 ++++++++++++++++++++++++++++++++++++++ The `CSS Text Decoration Module Level 3`_ "contains the features of CSS relating to text decoration, such as underlines, text shadows, and emphasis marks." The `CSS Text Decoration Module Level 4`_ is a working draft on the same subject. The ``text-decoration-line``, ``text-decoration-style``, ``text-decoration-color``, ``text-decoration-thickness`` and ``text-underline-offset`` properties are supported. The ``text-decoration`` shorthand is also supported. The other properties (``text-underline-position``, ``text-emphasis-*``, ``text-shadow``) are not supported. .. _CSS Text Decoration Module Level 3: https://www.w3.org/TR/css-text-decor-3/ .. _CSS Text Decoration Module Level 4: https://www.w3.org/TR/css-text-decor-4/ CSS Flexible Box Layout Module Level 1 ++++++++++++++++++++++++++++++++++++++ The `CSS Flexible Box Layout Module Level 1`_ "describes a CSS box model optimized for user interface design", also known as "flexbox". This module works for simple use cases but is not deeply tested. All the ``flex-*``, ``align-*``, ``justify-*`` and ``order`` properties are supported. The ``flex`` and ``flex-flow`` shorthands are supported too. .. _CSS Flexible Box Layout Module Level 1: https://www.w3.org/TR/css-flexbox-1/ CSS Grid Layout Module Level 2 ++++++++++++++++++++++++++++++ The `CSS Grid Layout Module Level 2`_ "defines a two-dimensional grid-based layout system, optimized for user interface design". This module works for simple cases, but has some limitations. Here are non-exhaustive lists of supported/unsupported features. Supported: - ``display: grid``, - ``grid-auto-*``, ``grid-template-*`` and other ``grid-*`` properties, - ``grid`` and other ``grid-*`` shorthands, - flexible lengths (``fr`` unit), - line names, - grid areas, - auto rows and auto columns, - ``z-index``, - ``repeat(X, *)``, - ``minmax()``, - ``align-*`` and ``justify-*`` alignment properties, - ``gap`` and ``*-gap`` properties for gutters, - dense auto flow, - ``order``, - margins, borders, padding on grid containers and grid items, - fragmentation between rows. Unsupported or untested: - ``display: inline-grid``, - auto content size for grid containers, - ``grid-auto-flow: column``, - subgrids, - ``repeat(auto-fill, *)`` and ``repeat(auto-fit, *)``, - auto margins for grid items, - ``span`` with line names, - ``span`` for flexible tracks, - ``safe`` and ``unsafe`` alignments, - baseline alignment, - grid items with intrinsic size (images), - distribute space beyond limits, - grid items larger than grid containers, - ``min-width``, ``max-width``, ``min-height``, ``max-height`` on grid items, - complex ``min-content`` and ``max-content`` cases, - absolutely positioned and floating grid items, - fragmentation in rows. .. _CSS Grid Layout Module Level 2: https://www.w3.org/TR/css-grid-2/ CSS Basic User Interface Module Level 3/4 +++++++++++++++++++++++++++++++++++++++++ The `CSS Basic User Interface Module Level 3/4`_ "enables authors to style user interface related properties and values." The ``outline-width``, ``outline-style``, ``outline-color`` properties and the ``outline`` shorthand are supported. The ``outline-offset`` property is also supported. The ``resize``, ``cursor``, ``caret-*`` and ``nav-*`` properties are **not** supported. The ``appearance`` property is supported. When set to ``auto``, it displays form fields as PDF form fields (supported for text inputs, check boxes, text areas, and select only). The ``accent-color`` property is **not** supported. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/changelog.rst0000644000000000000000000041510115113607644014223 0ustar00Changelog ========= Version 67.0 ------------ Released on 2025-12-02. Dependencies: * Python 3.10+ is now needed, Python 3.9 is not supported anymore * tinycss2 1.5.0+ is now needed * fontTools 4.59.2+ is now needed Features: * `#2560 `_, `#640 `_, `#844 `_, `#1091 `_, `#2517 `_: Support CMYK colors, PDF/X, color profiles and light-dark() function * `#2558 `_, `#1175 `_: Support ::first-line, with financial support from Karte Technology * `#2552 `_: Support CSS layers, with financial support from Code & Co. * `#2564 `_, `#2599 `_, `#2397 `_: Allow page breaks in grid rows, with financial support from Ocean Recap * `#2568 `_, `#357 `_: Support calc() and other mathematical functions * `#2575 `_, `#2574 `_: Support PDF/A-1a, PDF/A-2a and PDF/A-3a * `#2611 `_, `#2573 `_: Support PDF/A-4e and PDF/A-4f * `#2523 `_: Display tofu for missing glyphs * `#2581 `_: Add option to disable protocols in URL resolution * `#2570 `_: Support rch, cap, rcap, rex, ic and ric font-relative units * `#2547 `_, `#2140 `_: Support "only" keyword in media queries Bug fixes: * `#2516 `_, `#1510 `_: Fix rendering of first line of text with nested right float * `#2510 `_, `#1073 `_, `#2507 `_: Avoid Pango crashes and font mismatches with @font-face rules referencing local fonts * `#2532 `_, `#2531 `_: Use fonttools instancer instead of deprecated mutator API * `#2541 `_: Fix syntax of functions * `#2543 `_: Allow font-related units to access @font-face fonts * `#2525 `_: Respect top margins and avoid overlapping footnotes for columns, with financial support from Code & Co. * `#2536 `_: Remove Subtype key from font descriptor * `#2539 `_: Fix min width for SVGs with intrinsic ratio but no intrinsic size * `#2537 `_, `#2533 `_: Fix order of operators when drawing SVGs * `#2538 `_: Don’t crash with nested unknown functions * `#2542 `_: Don’t crash when lh and rlh are used for line height or font size * `#2540 `_, `#2528 `_: Use locale encoding instead of filesystem encoding for font paths * `#2563 `_, `#2479 `_: Don’t avoid float collisions for atomic flex items * `#2569 `_: Don’t be case-sensitive for units * `#2567 `_, `#2566 `_: Add x-default attribute for metadata description to be compliant with PDF/A * `#2586 `_, `#2571 `_: Improve formatting contexts management * `#2600 `_: Fix SVG image aspect ratio when only width or height is specified * `#2612 `_, `#2595 `_: Clean block layout and fix corner cases * `#2522 `_: Ignore preserveAspectRatio when SVG has no viewBox * `#2544 `_: Allow to use a variable twice in a function * `#2555 `_: Fix flex gap in right-to-left context * `#2591 `_: Respect non-auto widths and fix padding of grid items * `#2601 `_: Don’t crash when tagged tables are not displayed as tables * `#2607 `_: Fix rendering of multiline textareas with PDF forms * `#2106 `_: Force variable initialization to avoid crashes during column layout * `#2618 `_, `#2617 `_: Fix rendering of relative grid and flex items Documentation: * `#2535 `_: `#2534 `_: Removed reference to defunct site Contributors: * Guillaume Ayoub * Fazle Rabbi Ferdaus * Lucie Anglade * Luca Vercelli * ChickenF622 * Ernie Chu * Mark Pullin * Malte Laukötter * Markus Mohanty * Yvonne Kothmeier * Jarom Ort * kuypan Backers and sponsors: * Spacinov * Syslifters * Kobalt * Simon Sapin * Grip Angebotssoftware * Manuel Barkhau * Simonsoft * KontextWork * Menutech * TrainingSparkle * Healthchecks.io * Method B * FieldHub * Hammerbacher * Yanal-Yves Fargialla * Morntag * Piloterr * Xavid * Charlie S. * Prothesis Dental Solutions * Kai DeLorenzo Version 66.0 ------------ Released on 2025-07-24. Features: * `#2475 `_: Add support for 'lh' and 'rlh' units * `#2432 `_, `#2437 `_: Report footnotes when text overflows because of orphans, with financial support from Code & Co. * `#2256 `_, `#2466 `_: Handle transform-origin in SVG * `#2445 `_: Add parameter to have additional HTTP headers for url_fetcher Bug fixes: * `#2471 `_, `#2506 `_, `#2500 `_, `#2460 `_, `#2363 `_, `#2470 `_, `#1872 `_, `#2153 `_, `#1838 `_, `#1837 `_, `#1784 `_, `#1835 `_, `#2444 `_, `#2497 `_, `#2505 `_, `#2503 `_, `#1836 `_, `#2467 `_: Improve PDF/UA support, with financial support from NLnet * `#2425 `_, `#1557 `_: Improve position of outside markers * `#2409 `_, `#2265 `_: Draw circles instead of rectangles when drawing dotted borders * `#2416 `_, `#2270 `_: Correctly split words for automatic hyphenation * `#2439 `_, `#2426 `_: Don’t rely on URL protocols outside URL fetcher function * `#2433 `_: Disable style for deprecated outline algorithm * `#2447 `_, `#2441 `_, `#2448 `_: Improve min- and max-content calculation, with financial support from Menutech * `#2454 `_, `#2442 `_, `#2449 `_: Minor fixes for flex layout * `#2473 `_, `#2459 `_: Include out-of-flow boxes in page layout progress, with financial support from Pathfindr * `#2458 `_: Replace deprecated warn logger function * `#2494 `_, `#1856 `_: Fix bug with bottom margins in columns * `#2435 `_: Make footnote calls inherit from footnotes * `#2484 `_, `#2456 `_: Allow to avoid page breaks after table-row-group elements * `#2450 `_: Draw background and borders for relative grid containers * `#2453 `_: Don’t advance position_y for collapsed margins of discarded children * `#2493 `_: Fix endless loop with CSS variables referencing each other * `#2502 `_: Ignore bottom margin when calculating footnote overflow Contributors: * Guillaume Ayoub * Lucie Anglade * Alvaro Garcia Fernandez * Emmanuel Ferdman * Gabriel Corona * Markus Mohanty * Luca Vercelli * Tre Huang Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Simon Sapin * Manuel Barkhau * Simonsoft * Menutech * KontextWork * TrainingSparkle * Healthchecks.io * Hammerbacher * DocRaptor * Yanal-Yves Fargialla * Method B * FieldHub * Morntag * Xavid * Kai DeLorenzo * Charlie S. * Alan Villalobos Version 65.1 ------------ Released on 2025-04-14. Bug fixes: * `#2414 `_: Correctly handle flex columns split between pages * `1b24ad9 `_: Include padding in outer size of item elements * `#2419 `_: Set main tag as block by default * `#2415 `_: Fix support of replaced block box as flex items * `83da2fe0 `_: Fix margins and padding for rtl lists * `#2429 `_, `#1076 `_, `#2431 `_: Fix page groups Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Simon Sapin * Manuel Barkhau * Simonsoft * Menutech * KontextWork * TrainingSparkle * Healthchecks.io * Hammerbacher * DocRaptor * Yanal-Yves Fargialla * Method B * FieldHub * Morntag * Xavid * Kai DeLorenzo * Charlie S. * Alan Villalobos Version 65.0 ------------ Released on 2025-03-20. Dependencies: * CSSSelect2 0.8.0 is now needed Features: * `#1665 `_: Support gap properties in Flex layout, with financial support from NLnet * `#378 `_, `#2405 `_: Handle @font-face unicode-range * `#2394 `_: Modernize and improve default user agent stylesheets Bug fixes: * `#2362 `_, `#2387 `_, `#601 `_, `#1967 `_, `#1805 `_, `#2163 `_, `#2342 `_, `#2374 `_, `#1109 `_, `#1356 `_, `#1327 `_, `#1563 `_, `#1652 `_, `#2351 `_, `#2312 `_, `#2340 `_, `#1311 `_, `#2066 `_, `#2359 `_, `#2053 `_: Improve Flex layout, with financial support from NLnet. * `#1686 `_, `#2404 `_: Fix duplicate text selection with right-to-left text * `#2372 `_, `#2389 `_: Fix justification of right-to-left text * `#2403 `_: Fix emoji rendering with older versions of Pango * `#2392 `_: Fix complex cases involving nested SVG text anchors * `#2396 `_, `#2398 `_: Fix and improve font names in PDF * `#2269 `_, `#2390 `_: Apply justification to non-breaking spaces * `#2362 `_, `#2387 `_: Improve Flex layout, with financial support from NLnet. Contributors: * Guillaume Ayoub * Luca Vercelli Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Simon Sapin * Manuel Barkhau * Simonsoft * Menutech * KontextWork * TrainingSparkle * Healthchecks.io * Hammerbacher * DocRaptor * Yanal-Yves Fargialla * Method B * FieldHub * Morntag * Xavid * Kai DeLorenzo * Charlie S. * Alan Villalobos Version 64.1 ------------ Released on 2025-02-20. Bug fixes: * `#2368 `_: Fix ascent and descent font values * `#2370 `_: Avoid endless recursion for variables in nested functions * `#2275 `_: Use correct containing block to render waiting children * `#2375 `_: Ensure that we handle text-anchor only on text content elements * `#2090 `_: Only create font temporary folder when adding fonts * `#2383 `_: Fix grid-template-areas validation and allow uppercase identifiers for grid lines Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Simon Sapin * Manuel Barkhau * Simonsoft * Menutech * KontextWork * TrainingSparkle * Healthchecks.io * Hammerbacher * DocRaptor * Yanal-Yves Fargialla * Method B * FieldHub * Morntag * Xavid * Kai DeLorenzo * Charlie S. Version 64.0 ------------ Released on 2025-01-30. Features: * `#2338 `_: Allow custom RDF metadata for PDF/A and eInvoices * `#123 `_, `#2345 `_: Handle small-caps synthesis * `#2343 `_: Support outline-offset * `#2361 `_: Support text-underline-offset and text-decoration-thickness * `#2296 `_: Don’t crash with tables with rounded corners split between pages Bug fixes: * `#2360 `_: Fix gradients with non-RGB colors * `#2355 `_, `#2358 `_: Align png emojis to the surrounding text * `#2353 `_: Fix alignment of SVG text with multiple nested text-anchor values * `#2350 `_: Fix logging restoration in capture_logs * `#2341 `_: Fix page groups * `#2314 `_: Use CSS 'image-rendering' attribute for images in SVGs * `#2332 `_: Fix opacity for translated SVG elements * `#2329 `_: Refactor text.line_break.get_log_attrs * `#2325 `_, `#2326 `_: Fix table overflow edge cases Performance: * `#2347 `_, `#2364 `_: Improve rendering speed for text Documentation: * `#2352 `_: Add more use cases in documentation, use Furo theme Contributors: * Guillaume Ayoub * Kesara Rathnayake * Xavid Pretzer * David Tagatac * Ernesto Ruge * Niko Abeler * Noam Kushinsky Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Simon Sapin * Manuel Barkhau * Simonsoft * Menutech * KontextWork * TrainingSparkle * Healthchecks.io * Hammerbacher * DocRaptor * Yanal-Yves Fargialla * Method B * FieldHub * Morntag * Xavid * Kai DeLorenzo * Charlie S. Version 63.1 ------------ Released on 2024-12-10. Dependencies: * `#2297 `_: Remove upper bounds for dependencies Bug fixes: * `#2300 `_, `#2292 `_: Don’t avoid floats for flex items * `#2301 `_, `#2293 `_: Include floats in calculation of minimum cell height * `#2303 `_, `#2302 `_: Set alpha even when current color channels didn’t change * `#2306 `_: Don’t try to increase column width when there’s no extra width * `#2304 `_: Don’t forget skip stack when drawing flex items * `#2316 `_: Don’t crash with SVG symbols * `#2320 `_: Fix currentcolor detection when parsing gradient color stops * `#2322 `_, `#2289 `_: Don’t add DLL directories when using Windows executable * `#2323 `_, `#2305 `_: Fix different rendering test Performance: * `#2319 `_: Fix memory leaks Documentation: * `#2299 `_: Update install instructions for Alpine * `#2321 `_: Add example invocation of WeasyPrint on the "Contribute" page Contributors: * Guillaume Ayoub * Jó Ágila Bitsch * Lucie Anglade * Alexander Gitter * Luke Cousins Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * TrainingSparkle * Healthchecks.io * Hammerbacher * Advance Insight * Docraptor * Method B * FieldHub * Yanal-Yves Fargialla * Morntag * Xavid Version 63.0 ------------ Released on 2024-10-29. Dependencies: * Python 3.13 is now supported * pydyf 0.11.0+ is now needed * tinycss2 1.4.0+ is now needed * tinyhtml5 2.0.0+ is now needed, instead of html5lib Features: * `#2252 `_, `#895 `_: Handle page groups, with financial support from Code & Co. * `#1630 `_, `#2286 `_: Support CSS Color Level 4 * `#2192 `_: Add PDF variant for debugging purpose * `#2208 `_: Support submit inputs in PDF forms * `#2139 `_: Support ``mask-border-*`` properties * `#1831 `_, `#2143 `_: Support radio inputs in PDF forms Bug fixes: * `#2262 `_: Avoid integer overflows when converting units from/to doubles * `#2260 `_: Avoid float collision with box establishing formatting context * `#2240 `_, `#2242 `_: Handle ``svg`` tags with no size * `#2231 `_, `#1171 `_, `#2222 `_, `#1208 `_: Fix several problems related to ``flex-direction: column`` * `#2239 `_: Don’t fail when SVG markers are undefined references * `#2230 `_, `#2238 `_: Set explicit flags when loading DLLs on Windows * `#2228 `_, `#1942 `_: Store original and PDF stream images in different cache slots * `#2234 `_: Apply stylesheet and other basic operations to SVG root tag * `#2054 `_, `#2233 `_: Keep auto margins on flex layout boxes * `#1883 `_: Don’t crash with empty list marker strings * `#2216 `_: Fix vertical alignment of out-of-flow elements in tables * `#996 `_, `#2219 `_: Don’t ignore absolutely positioned elements inside flex boxes * `#2217 `_: Don’t crash with ``normal`` column gaps * `#1817 `_: Don’t assume that lines break after spaces * `#1868 `_: Don’t break rows with atomic cells * `#2166 `_: Don’t display bottom border on cells in split rows * `61852c4 `_: Capture fontTools logs when subsetting fonts * `#2190 `_: Don’t use a pattern when drawing backgrounds for no-repeat background images * `#2185 `_: Check that Harfbuzz version is at least 4.1.0 to subset fonts * `#2180 `_: Store width for all glyphs when font is not subset * `#2183 `_: Respect ``break-inside: avoid`` for flex items * `#2055 `_, `#2058 `_: Fix right-to-left tables with collapsed borders * `#2179 `_, `#1128 `_: Handle buggy Adobe Photoshop CMYK JPEGs * `#2175 `_: Don’t compress PDF metadata for PDF/A-1 * `#2174 `_: Fix extra width distribution for auto table layout Performance: * `#1155 `_: Improve rendering speed for large colspan values * `#2120 `_, `#2178 `_: Use Harfbuzz to subset fonts by default Documentation: * `#2282 `_, `#2284 `_: Simplify Alpine install instructions * `#2254 `_: Add warning about antivirus false detection * `#2220 `_: Add extra information to debug logs * `#2211 `_: Fix link to samples * `#2195 `_: Update cache argument documentation * `#2105 `_, `#2151 `_: Use MSYS2 instead of GTK+3 for Windows Contributors: * Guillaume Ayoub * David Huggins-Daines * Xavid Pretzer * Yann Trividic * Kevin Kays * Alejandro Avilés * Gianluca Teti * Gregory Goodson * Lucie Anglade * Roman Sirokov Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Syslifters * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * TrainingSparkle * Healthchecks.io * Hammerbacher * Advance Insight * Docraptor * Method B * FieldHub * Yanal-Yves Fargialla * Morntag * Xavid Version 62.3 ------------ Released on 2024-06-21. Bug fixes: * `#2174 `_: Fix extra width distribution for auto table layout * `#2175 `_: Don’t compress PDF metadata for PDF/A-1 * `61f8bb3 `_: Set default PDF variant values in options before generating PDF * `2c4351e `_: Avoid PDF artifacts when drawing 0-width borders * `d9d7f62 `_: Don’t duplicate column when container is split on multiple pages * `4617b94 `_: Don’t set default Fontconfig values for unset properties * `4c81663 `_: Fix layout when all footnotes are removed from the footnote area * `#2184 `_: Make items overflowing grid wrap to the next row/column * `#2187 `_: Don’t append useless tracks when grid elements are positioned Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * René Fritz * TrainingSparkle * Healthchecks.io * Hammerbacher * Docraptor * Yanal-Yves Fargialla * Douwe van Loenen * Morntag * Xavid Version 62.2 ------------ Released on 2024-06-04. Features: * `#2142 `_, `#2162 `_: Support grid-auto-flow: column, with financial support from Menutech Bug fixes: * `#2167 `_: Fix space added by CSS gap at the end * `#2134 `_: Remove absolute placeholders from discarded content * `#2154 `_: Don’t crash when grid items have auto margins * `8cdd66f `_: Fix CSS nesting for nested selectors with comma * `3359db5 `_: Fix and test grid shorthand * `82deda4 `_: Fix wrong resume_at for split floats * `ff2acf1 `_: Ensure that gradient size is positive to please some PDF readers Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * René Fritz * TrainingSparkle * Healthchecks.io * Hammerbacher * Docraptor * Yanal-Yves Fargialla * Douwe van Loenen * Morntag * Xavid Version 62.1 ------------ Released on 2024-05-06. Bug fixes: * `#2144 `_, `#2149 `_: Avoid broken fonts when generating multiple documents * `c10c6892 `_: Display at least one grid row on empty pages * `#2146 `_: Don’t crash when flex container’s parent’s height is auto Contributors: * Guillaume Ayoub * Claudius Ellsel Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * René Fritz * TrainingSparkle * Healthchecks.io * Docraptor * Yanal-Yves Fargialla * Douwe van Loenen * Morntag * Xavid Version 62.0 ------------ Released on 2024-04-30. Dependencies: * Python 3.9+ is now needed, Python 3.7 and 3.8 are not supported anymore * pydyf 0.10.0+ is now needed * tinycss2 1.3.0+ is now needed Features: * `#543 `_, `#2121 `_: Support CSS Grid layout * `#2124 `_, `#2125 `_: Support border-image-* properties * `#2084 `_, `#2077 `_: Support CSS nesting * `#2101 `_: Support HTML maxlength attribute for form fields * `#2095 `_: Apply overflow to replaced boxes * `245e4f5 `_: Add support of PDF/A-?u Bug fixes: * `#2136 `_: Don’t clip aligned text in SVG * `#2135 `_: Allow column-direction flex containers to use percentage-based heights * `#2128 `_: Don’t crash when a FontConfig object is destroyed early * `#2079 `_: Fix executable file for some Windows versions * `#2131 `_: Fix alpha for images before/after transparent text * `#2111 `_: Handle auto and none values for CSS quotes property * `#2103 `_: Don’t crash with overconstrained columns * `#2100 `_: Fix rounding error when detecting overflows * `#2093 `_, `#2097 `_, `#2094 `_: Mark use of md5() and sha1() as not for security * `#1956 `_, `#2087 `_: Use CSS table module level 3 to compute widths * `#2086 `_: Fix selects with empty values displaying None * `#1112 `_, `#2082 `_, `#2085 `_: Fix computation for outer min-content width for table cells * `016bd81 `_: Fix many different bugs with SVG markers Performance: * `#2130 `_: Cache font key instead of whole font content Documentation: * `#2108 `_: Update documentation about CSS leader() function Contributors: * Guillaume Ayoub * Lucie Anglade * Xavid Pretzer * kygoh * Germain Gueutier * Vagner José Nicolodi Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Simon Sapin * René Fritz * TrainingSparkle * Healthchecks.io * Docraptor * Yanal-Yves Fargialla * Douwe van Loenen * Morntag * Xavid Version 61.2 ------------ Released on 2024-03-08. **This is a security update.** We strongly recommend to upgrade WeasyPrint to the latest version if you use WeasyPrint 61.0 or 61.1. Older versions are not impacted. Security: - Always use URL fetcher for attachments Contributors: * Guillaume Ayoub * Ilia Novoselov Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * René Fritz * Simon Sapin * Arcanite * TrainingSparkle * Healthchecks.io * Hammerbacher * Docraptor * Yanal-Yves Fargialla * Morntag * NBCO Version 61.1 ------------ Released on 2024-02-26. Bug fixes: - `#2075 `_: Use default value when variable is not defined - `#2070 `_: Don’t crash when rendering SVGs with non-text a children - Don’t crash when SVG file can’t be rendered Documentation: - `#2067 `_: Suggest "dnf" instead of "yum" to install Fedora packages - Improve documentation for Windows - Fix required version of TinyCSS2 Contributors: * Guillaume Ayoub * Felix Schwarz * Lucie Anglade Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * René Fritz * Simon Sapin * Arcanite * TrainingSparkle * Healthchecks.io * Hammerbacher * Docraptor * Yanal-Yves Fargialla * Morntag * NBCO Version 61.0 ------------ Released on 2024-02-12. Python API: * ``DocumentMetadata.attachments`` is now a list of ``Attachment`` objects, not a list of ``(url, description)`` tuples. New features: * `#1219 `_, `#2017 `_: Support var() in shorthand and multiple-value functions * `#1986 `_: Support percentages for opacity * `#2050 `_: Build executable file for Windows * `#2000 `_: Support select fields * `#1993 `_: Handle background-attachment: fixed to cover the whole page * `#2023 `_, `#2022 `_: Allow text-based file objects for HTML and CSS classes * `#2014 `_: Remove warnings for PDF/A and PDF/UA compatibility Bug fixes: * `#2052 `_, `#1869 `_: Handle attachments for PDF/A documents * `#2013 `_, `#2051 `_: Apply margin to running tables * `#1278 `_, `#1884 `_: Draw collapsed borders of running tables * `#2029 `_: Fix page counter in non-root absolute boxes * `#2043 `_: Fix text-anchor on SVG tspan elements * `#1968 `_, `#2039 `_: Use cell's border-height to calculate table row height * `#2030 `_: Ensure that bounding box is set to invisible text tags * `#2040 `_, `#2041 `_: Don’t crash on malformed URLs * `#2026 `_: Don’t break pages when fixed-height elements don’t overflow page * `#2038 `_: Don’t mix original streams when drawing transparent text * `#2016 `_: Avoid duplication when breaking out-of-flow boxes * `#2012 `_: Don’t crash when CSS properties have no value * `#2010 `_, `#1287 `_: Fix many corner cases with CSS variables * `#1996 `_: Don’t crash when drawing groove/ridge collapsed borders * `#1982 `_: Fix SVG markers size, position and drawing Documentation: * `#2021 `_, `#2048 `_: Replace non-virtualenv installation instructions with distribution packages Contributors: * Guillaume Ayoub * kygoh * Lucie Anglade * Timo Ramsauer * Alexander Gitter * Michael Lisitsa * Vagner José Nicolodi * Manolis Stamatogiannakis * Pascal de Bruijn * Viktor Shevtsov * Eduardo Gonzalez * Kesara Rathnayake Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * René Fritz * Simon Sapin * Arcanite * TrainingSparkle * Healthchecks.io * Hammerbacher * Docraptor * Yanal-Yves Fargialla * Morntag * NBCO Version 60.2 ------------ Released on 2023-12-11. Bug fixes: * `#1982 `_: Fix SVG markers size, position and drawing * `23cfc775 `_: Draw background behind absolutely positioned replaced boxes * `fe2f0c69 `_: Don’t crash with bitmap fonts with no "glyf" table * `14605225 `_: Improve SVG text-anchor attribute Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Nicola Auchmuty * Syslifters * Hammerbacher * TrainingSparkle * Daniel Kucharski * Healthchecks.io * Yanal-Yves Fargialla * WakaTime * Paheko * Synapsium * DocRaptor Version 60.1 ------------ Released on 2023-09-29. Bug fixes: * `#1973 `_: Fix crash caused by wrong UTF-8 indices Contributors: * Guillaume Ayoub Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Nicola Auchmuty * Syslifters * Hammerbacher * TrainingSparkle * Daniel Kucharski * Healthchecks.io * Yanal-Yves Fargialla * WakaTime * Paheko * Synapsium * DocRaptor Version 60.0 ------------ Released on 2023-09-25. New features: * `#1903 `_: Print form fields * `#1922 `_: Add support for textLength and lengthAdjust in SVG text elements * `#1965 `_: Handle tag * `#1970 `_: Handle y offset of glyphs * `#1909 `_: Add a --timeout option Bug fixes: * `#1887 `_: Fix footnote-call displayed incorrectly for some fonts * `#1890 `_: Fix page-margin boxes layout algorithm * `#1908 `_: Fix IndexError when rendering PDF version 1.4 * `#1906 `_: Apply text transformations to first-letter pseudo elements * `#1915 `_: Avoid footnote appearing before its call * `#1934 `_: Fix balance before "column-span: all" * `#1935 `_: Only draw required glyph with OpenType-SVG fonts * `#1595 `_: Don’t draw clipPath when defined after reference * `#1895 `_: Don’t ignore min-width when computing cell size * `#1899 `_: Fix named pages inheritance * `#1936 `_: Avoid page breaks caused by children of overflow hidden boxes * `#1943 `_: Use bleed area for page’s painting area * `#1946 `_: Use margin box of children to define available width for leaders Contributors: * Guillaume Ayoub * Sahil Rohilla * Azharuddin Syed * kygoh * Andy Lenards * Gaurav Samudra * Michael Wedl * Lucie Anglade * Obeida Shamoun * Evgeniy Krysanov Backers and sponsors: * Spacinov * Kobalt * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Nicola Auchmuty * Syslifters * Hammerbacher * TrainingSparkle * Daniel Kucharski * Healthchecks.io * Yanal-Yves Fargialla * WakaTime * Paheko * Synapsium * DocRaptor Version 59.0 ------------ Released on 2023-05-11. This version also includes the changes from unstable b1 version listed below. Bug fixes: * `#1864 `_: Handle overflow for svg and symbol tags in SVG images * `#1867 `_: Remove duplicate compression of attachments * `d0ad5c1 `_: Override use tag children instead of drawing their references * `93df1a5 `_: Don’t resize the same image twice when the --dpi option is set * `#1874 `_: Drawn underline and overline behind text Contributors: * Guillaume Ayoub * Timo Ramsauer * Alexander Mankuta Backers and sponsors: * Castedo Ellerman * Kobalt * Spacinov * Grip Angebotssoftware * Crisp BV * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Moritz Mahringer * Yanal-Yves Fargialla * Piotr Horzycki * Healthchecks.io * TrainingSparkle * Hammerbacher * Synapsium Version 59.0b1 -------------- Released on 2023-04-14. **This version is experimental, don't use it in production. If you find bugs, please report them!** Command-line API: * The ``--optimize-size`` option and its short equivalent ``-O`` have been deprecated. To activate or deactivate different size optimizations, you can now use: * ``--uncompressed-pdf``, * ``--optimize-images``, * ``--full-fonts``, * ``--hinting``, * ``--dpi ``, and * ``--jpeg-quality ``. * A new ``--cache-folder `` option has been added to store temporary data in the given folder on the disk instead of keeping them in memory. Python API: * Global rendering options are now given in ``**options`` instead of dedicated parameters, with slightly different names. It means that the signature of the ``HTML.render()``, ``HTML.write_pdf()`` and ``Document.write_pdf()`` has changed. Here are the steps to port your Python code to v59.0: 1. Use named parameters for these functions, not positioned parameters. 2. Rename some the parameters: * ``image_cache`` becomes ``cache`` (see below), * ``identifier`` becomes ``pdf_identifier``, * ``variant`` becomes ``pdf_variant``, * ``version`` becomes ``pdf_version``, * ``forms`` becomes ``pdf_forms``. * The ``optimize_size`` parameter of ``HTML.render()``, ``HTML.write_pdf()`` and ``Document()`` has been removed and will be ignored. You can now use the ``uncompressed_pdf``, ``full_fonts``, ``hinting``, ``dpi`` and ``jpeg_quality`` parameters that are included in ``**options``. * The ``cache`` parameter can be included in ``**options`` to replace ``image_cache``. If it is a dictionary, this dictionary will be used to store temporary data in memory, and can be even shared between multiple documents. If it’s a folder Path or string, WeasyPrint stores temporary data in the given temporary folder on disk instead of keeping them in memory. New features: * `#1853 `_, `#1854 `_: Reduce PDF size, with financial support from Code & Co. * `#1824 `_, `#1829 `_: Reduce memory use for images * `#1858 `_: Add an option to keep hinting information in embedded fonts Bug fixes: * `#1855 `_: Fix position of emojis in justified text * `#1852 `_: Don’t crash when line can be split before trailing spaces * `#1843 `_: Fix syntax of dates in metadata * `#1827 `_, `#1832 `_: Fix word-spacing problems with nested tags Documentation: * `#1841 `_: Add a paragraph about unsupported calc() function Contributors: * Guillaume Ayoub * Lucie Anglade * Alex Ch * whi_ne * Jonas Castro Backers and sponsors: * Castedo Ellerman * Kobalt * Spacinov * Grip Angebotssoftware * Crisp BV * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Moritz Mahringer * Yanal-Yves Fargialla * Piotr Horzycki * Healthchecks.io * TrainingSparkle * Hammerbacher * Synapsium Version 58.1 ------------ Released on 2023-03-07. Bug fixes: * `#1815 `_: Fix bookmarks coordinates * `#1822 `_, `#1823 `_: Fix vertical positioning for absolute replaced elements Documentation: * `#1814 `_: Fix broken link pointing to samples Contributors: * Guillaume Ayoub * Jonas Castro * Lucie Anglade * Menelaos Kotoglou Backers and sponsors: * Kobalt * Grip Angebotssoftware * Spacinov * Crisp BV * Castedo Ellerman * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Moritz Mahringer * Yanal-Yves Fargialla * Piotr Horzycki * Healthchecks.io * Hammerbacher * TrainingSparkle * Synapsium Version 58.0 ------------ Released on 2023-02-17. This version also includes the changes from unstable b1 version listed below. Bug fixes: * `#1807 `_: Don’t crash when out-of-flow box is split in out-of-flow parent * `#1806 `_: Don’t crash when fixed elements aren’t displayed yet in aborted line * `#1809 `_: Fix background drawing for out-of-the-page transformed boxes Contributors: * Guillaume Ayoub Backers and sponsors: * Kobalt * Grip Angebotssoftware * Crisp BV * Spacinov * Castedo Ellerman * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Moritz Mahringer * Yanal-Yves Fargialla * Piotr Horzycki * Healthchecks.io Version 58.0b1 -------------- Released on 2023-02-03. **This version is experimental, don't use it in production. If you find bugs, please report them!** New features: * `#61 `_, `#1796 `_: Support PDF forms, with financial support from Personalkollen * `#1173 `_: Add style for form fields Bug fixes: * `#1777 `_: Detect JPEG/MPO images as normal JPEG files * `#1771 `_: Improve SVG gradients Contributors: * Guillaume Ayoub * Lucie Anglade Backers and sponsors: * Kobalt * Grip Angebotssoftware * Crisp BV * Spacinov * Castedo Ellerman * Manuel Barkhau * SimonSoft * Menutech * KontextWork * NCC Group * René Fritz * Moritz Mahringer * Yanal-Yves Fargialla * Piotr Horzycki * Healthchecks.io Version 57.2 ------------ Released on 2022-12-23. Bug fixes: * `0f2e377 `_: Print annotations with PDF/A * `0e9426f `_: Hide annotations with PDF/UA * `#1764 `_: Use reference instead of stream for annotation appearance stream * `#1783 `_: Fix multiple font weights for @font-face declarations Contributors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Tom Pohl * Castedo Ellerman * Moritz Mahringer * Piotr Horzycki * Gábor Nyers * Sidharth Kapur Version 57.1 ------------ Released on 2022-11-04. Dependencies: * `#1754 `_: Pillow 9.1.0 is now needed Bug fixes: * `#1756 `_: Fix rem font size for SVG images * `#1755 `_: Keep format when transposing images * `#1753 `_: Don’t use deprecated ``read_text`` function when ``files`` is available * `#1741 `_: Generate better manpage * `#1747 `_: Correctly set target counters in pages’ absolute elements * `#1748 `_: Always set font size when font is changed in line * `2b05137 `_: Fix stability of font identifiers Documentation: * `#1750 `_: Fix documentation spelling Contributors: * Guillaume Ayoub * Eli Schwartz * Mikhail Anikin * Scott Kitterman Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Tom Pohl * John R Ellis * Castedo Ellerman * Moritz Mahringer * Gábor * Piotr Horzycki Version 57.0 ------------ Released on 2022-10-18. This version also includes the changes from unstable b1 version listed below. New features: * `a4fc7a1 `_: Support image-orientation Bug fixes: * `#1739 `_: Set baseline on all flex containers * `#1740 `_: Don’t crash when currentColor is set on root svg tag * `#1718 `_: Don’t crash with empty bitmap glyphs * `#1736 `_: Always use the font’s vector variant when possible * `eef8b4d `_: Always set color and state before drawing * `#1662 `_: Use a stable key to store stream fonts * `#1733 `_: Don’t remove attachments when adding internal anchors * `3c4fa50 `_, `c215697 `_, `d275dac `_, `b04bfff `_: Fix many bugs related to PDF/UA structure Performance: * `dfccf1b `_: Use faces as fonts dictionary keys * `0dc12b6 `_: Cache add_font to avoid calling get_face too often * `75e17bf `_: Don’t call process_whitespace twice on many children * `498d3e1 `_: Optimize __missing__ functions Documentation: * `863b3d6 `_: Update documentation of installation on macOS with Homebrew Contributors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Tom Pohl * John R Ellis * Castedo Ellerman * Moritz Mahringer * Gábor * Piotr Horzycki Version 57.0b1 -------------- Released on 2022-09-22. **This version is experimental, don't use it in production. If you find bugs, please report them!** New features: * `#1704 `_: Support PDF/UA, with financial support from Novareto * `#1454 `_: Support variable fonts Bug fixes: * `#1058 `_: Fix bullet position after page break, with financial support from OpenZeppelin * `#1707 `_: Fix footnote positioning in multicolumn layout, with financial support from Code & Co. * `#1722 `_: Handle skew transformation with only one parameter * `#1715 `_: Don’t crash when images are truncated * `#1697 `_: Don’t crash when attr() is used in text-decoration-color * `#1695 `_: Include language information in PDF metadata * `#1612 `_: Don’t lowercase letters when capitalizing text * `#1700 `_: Fix crash when rendering footnote with repagination * `#1667 `_: Follow EXIF metadata for image rotation * `#1669 `_: Take care of floats when remvoving placeholders * `#1638 `_: Use the original box when breaking waiting children Contributors: * Guillaume Ayoub * Konstantin Weddige * VeteraNovis * Lucie Anglade Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Tom Pohl * John R Ellis * Moritz Mahringer * Gábor * Piotr Horzycki * Andrew Ittner Version 56.1 ------------ Released on 2022-07-24. Bug fixes: * `#1674 `_: Follow max-height on footnot area, with financial support from Code & Co. * `#1678 `_: Fix gradients with opacity set Contributors: * Guillaume Ayoub * Lucie Anglade Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki * Andrew Ittner Version 56.0 ------------ Released on 2022-07-07. This version also includes the changes from unstable b1 version listed below. New features: * `70f9b62 `_: Support format 5 for bitmap glyphs Bug fixes: * `#1666 `_ Fix reproducible PDF generation with embedded images * `#1668 `_: Fix @page:nth() selector * `3bd9a8e `_: Don’t limit the opacity groups to the original box size * `cb9540b `_, `76d174f `_, `9ce6547 `_: Minor bugfixes for split table rows Contributors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Des images et des mots * Andreas Zettl * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 56.0b1 -------------- Released on 2022-06-17. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * pydyf 0.2.0+ is now needed New features: * `#1660 `_: Support nested line-clamp, with financial support from Expert Germany * `#1644 `_, `#1645 `_: Support bitmap fonts, with financial support from Expert Germany * `#1651 `_, `#630 `_: Support PDF/A, with financial support from Blueshoe Bug fixes: * `#1656 `_: Fix chained variables in the same selector block * `#1028 `_: Fix font weight management in @font-face rules * `#1653 `_: Don’t crash when @font-face’s src ends with a comma * `#1650 `_: Don’t check origin when URL only contains fragment * `e38bff8 `_: Don’t crash when inherited SVG attributes are not set on the parent Performance: * `e6021da `_: Launch tests in parallel by default Contributors: * Guillaume Ayoub * aschmitz * Lucie Anglade Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Des images et des mots * Andreas Zettl * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 55.0 ------------ Released on 2022-05-12. This version also includes the changes from unstable b1 version listed below. Bug fixes: * `#1626 `_, `3802f88 `_: Fix the vertical position and available height of absolute boxes * `9641098 `_, `e5e6b88 `_: Minor fixes for multi-column layout * `0fcc7de `_: Don’t stop rendering SVG when CSS parsing fails * `#1636 `_: Fix sequential footnotes that could disappear when overflowing * `#1637 `_: Fix position of absolute boxes with right-to-left direction * `#1641 `_: Fix relative paths for SVG files stored as data URLs Contributors: * Guillaume Ayoub * aschmitz Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * Spacinov * KontextWork * René Fritz * NCC Group * Kobalt * Nathalie Gutton * Andreas Zettl * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 55.0b1 -------------- Released on 2022-04-15. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * Python 3.7+ is now needed, Python 3.6 is not supported anymore New features: * `#1534 `_: Support ``word-break: break-all`` * `#489 `_, `#1619 `_: Support column breaks * `#1553 `_: Allow reproducible PDF generation Bug fixes: * `#1007 `_, `#1524 `_: Handle ``inherit`` in shorthand properties * `#1539 `_, `#1541 `_: Space out no-repeat patterns * `#1554 `_: Avoid invalid PDF operators when drawing SVG text * `#1564 `_, `#1566 `_, `#1570 `_: Don’t output footnotes before their call sites * `#1020 `_, `#1597 `_: Prevent infinite loops in multi-column layout * `#1512 `_, `#1613 `_: Fix position of absolute boxes in right-to-left contexts * `#1093 `_: Draw borders around absolute replaced boxes * `#984 `_, `#1604 `_: Fix skip stacks for columns * `#1621 `_: Better support of nested ``text-decoration`` properties * `fe1f3d9 `_: Fix absolute blocks in lines * `4650b70 `_: Clear adjoining margins when a container’s child doesn’t fit Performance: * `#1548 `_: Improve tests speed * `3b0ae92 `_, `#1457 `_: Improve fonts management * `#1597 `_: Improve column layout speed * `#1587 `_, `#1607 `_, `#1608 `_: Cache ``ch`` and ``ex`` units calculations Contributors: * Guillaume Ayoub * aschmitz * Lucie Anglade * Christoph Kepper * Jack Lin * Rian McGuire Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * KontextWork * Maykin Media * René Fritz * NCC Group * Spacinov * Nathalie Gutton * Andreas Zettl * Tom Pohl * Kobalt * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki * DeivGuerrero Version 54.3 ------------ Released on 2022-04-04. Bug fixes: * `#1588 `_: Support position: absolute in footnotes * `#1586 `_: Fix discarded text-align values Contributors: * aschmitz * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * KontextWork * Maykin Media * René Fritz * NCC Group * Spacinov * Nathalie Gutton * Andreas Zettl * Tom Pohl * Kobalt * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki * DeivGuerrero Version 54.2 ------------ Released on 2022-02-27. Bug fixes: * `#1575 `_: Always store parent blocks children as lists * `#1574 `_, `#1559 `_: Fix float rounding errors * `#1571 `_: Ignore unknown glyphs * `#1561 `_, `#1562 `_: Fix line break when breaks occur between a nbsp and an inline block * `#1560 `_: Always set the child index * `#1558 `_: Fix patterns with use tags Contributors: * Guillaume Ayoub * Lucie Anglade * Jack Lin * aschmitz Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * Crisp BV * SimonSoft * Menutech * KontextWork * Maykin Media * René Fritz * NCC Group * Spacinov * Nathalie Gutton * Andreas Zettl * Tom Pohl * Kobalt * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki * DeivGuerrero Version 54.1 ------------ Released on 2022-01-31. New features: * `#1547 `_: Handle break-inside: avoid on tr tags Bug fixes: * `#1540 `_, `#1239 `_: Handle absolute children in running elements * `#1538 `_: Handle invalid values in text-align * `#1536 `_: Handle absolute flex boxes Contirbutors: * Guillaume Ayoub * Lucie Anglade Backers and sponsors: * H-Net: Humanities and Social Sciences Online * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Crisp BV * Maykin Media * René Fritz * Simon Sapin * NCC Group * Nathalie Gutton * Andreas Zettl * Tom Pohl * Spacinov * Des images et des mots * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 54.0 ------------ Released on 2022-01-08. This version also includes the changes from unstable b1 version listed below. Bug fixes: * `#1531 `_: Always use absolute paths to get hrefs in SVG * `#1523 `_: Fix many rendering problems of broken tables * `e1aee70 `_: Fix support of fonts with SVG emojis Contirbutors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Crisp BV * Maykin Media * René Fritz * Simon Sapin * NCC Group * Nathalie Gutton * Andreas Zettl * Tom Pohl * Des images et des mots * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 54.0b1 -------------- Released on 2021-12-13. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * html5lib 1.1+ is now needed. New features: * `#1509 `_: Support footnotes, with financial support from Code & Co. * `#36 `_: Handle parallel flows for floats, absolutes, table-cells * `#1389 `_: Support ``text-align-last`` and ``text-align-all`` properties * `#1434 `_: Draw SVG and PNG emojis * `#1520 `_: Support ``overflow-wrap: anywhere`` * `#1435 `_: Add environment variable to set DLL folder on Windows Performance: * `#1439 `_: Cache SVG ``use`` tags * `#1481 `_: Encode non-JPEG images as PNGs instead of JPEG2000s Bug fixes: * `#137 `_: Don’t use ``text-transform`` text for content-based uses * `#1443 `_: Don’t serialize and parse again inline SVG files * `#607 `_: Correctly handle whitespaces in bookmark labels * `#1094 `_: Fix column height with ``column-span`` content * `#1473 `_: Fix absolutely positioned boxes in duplicated pages * `#1491 `_: Fix ``target-counter`` attribute in flex items * `#1515 `_, `#1508 `_: Don’t draw empty glyphs * `#1499 `_: Don’t crash when font size is really small Documentation: * `#1519 `_: Fix typo Packaging: * The source package does not include a ``setup.py`` file anymore. You can find more information about this in `issue #1410 `_. Contirbutors: * Guillaume Ayoub * Lucie Anglade * Colin Kinloch * aschmitz * Pablo González * Rian McGuire Backers and sponsors: * Grip Angebotssoftware * Manuel Barkhau * SimonSoft * Menutech * KontextWork * Crisp BV * Maykin Media * René Fritz * Simon Sapin * NCC Group * Nathalie Gutton * Andreas Zettl * Tom Pohl * Des images et des mots * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * Gábor * Piotr Horzycki Version 53.4 ------------ Released on 2021-11-14. Bug fixes: * `#1446 `_: Fix background on pages with a bleed property * `#1455 `_: Use SVG width/height as inner size when no viewBox is given * `#1469 `_: Only enable letter- and word-spacing when needed * `#1471 `_: Don’t display inputs with "hidden" type * `#1485 `_: Allow quotes in url() syntax for SVG, Use better approximations for font ascent and descent values in SVG * `#1486 `_: Fix images embedded from multiple pages * `#1489 `_: Use a better hash for fonts to avoid collisions * `abd54c4 `_: Set SVG ratio when width and height are 0 Contributors: * Guillaume Ayoub * Lucie Anglade Backers and sponsors: * Grip Angebotssoftware * SimonSoft * Menutech * Manuel Barkhau * Simon Sapin * KontextWork * René Fritz * Maykin Media * NCC Group * Crisp BV * Des images et des mots * Andreas Zettl * Nathalie Gutton * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla * G. Allard * Gábor Version 53.3 ------------ Released on 2021-09-10. Bug fixes: * `#1431 `_, `#1440 `_: Fix crashes and malformed PDF files * `#1430 `_: Handle cx and cy in SVG rotations * `#1436 `_: Fix marker-start being drawn on mid vertices Contributors: * Guillaume Ayoub * Rian McGuire * Lucie Anglade Backers and sponsors: * Grip Angebotssoftware * SimonSoft * Menutech * Manuel Barkhau * Simon Sapin * KontextWork * René Fritz * Maykin Media * NCC Group * Des images et des mots * Andreas Zettl * Nathalie Gutton * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla Version 53.2 ------------ Released on 2021-08-27. New features: * `#1428 `_: Re-add the ``make_bookmark_tree()`` method Bug fixes: * `#1429 `_: Fix package deployed on PyPI Contributors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * PDF Blocks * SimonSoft * Menutech * Manuel Barkhau * Simon Sapin * KontextWork * René Fritz * Maykin Media * NCC Group * Des images et des mots * Andreas Zettl * Nathalie Gutton * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla Version 53.1 ------------ Released on 2021-08-22. Bug fixes: * `#1409 `_: Don’t crash when leaders are in floats * `#1414 `_: Embed images once * `#1417 `_: Fix crash with SVG intrinsic ratio Documentation: * `#1422 `_: Include ``weasyprint.tools`` removal in documentation Contributors: * Guillaume Ayoub Backers and sponsors: * Grip Angebotssoftware * PDF Blocks * SimonSoft * Menutech * Manuel Barkhau * Simon Sapin * KontextWork * René Fritz * Maykin Media * NCC Group * Des images et des mots * Andreas Zettl * Nathalie Gutton * Tom Pohl * Moritz Mahringer * Florian Demmer * Yanal-Yves Fargialla Version 53.0 ------------ Released on 2021-07-31. This version also includes the changes from unstable b1 and b2 versions listed below. Dependencies: * Pango 1.44.0+ is now needed. * pydyf 0.0.3+ is now needed. * fontTools 4.0.0+ is now needed. * html5lib 1.0.1+ is now needed. API changes: * ``FontConfiguration`` is now in the ``weasyprint.text.fonts`` module. * ``--format`` and ``--resolution`` options have been deprecated, PDF is the only output format supported. * ``--optimize-images`` option has been deprecated and replaced by ``--optimize-size``, allowing ``images``, ``fonts``, ``all`` and ``none`` values. * ``weasyprint.tools`` have been removed. * ``Document.resolve_links``, ``Document.make_bookmark_tree`` and ``Document.add_hyperlinks`` have been removed. Performance: * Improve image management New features: * `#1374 `_: Support basic "clipPath" in SVG Bug fixes: * `#1369 `_: Render use path in SVG * `#1370 `_: Fix fill color on use path in SVG * `#1371 `_: Handle stroke-opacity and fill-opacity * `#1378 `_: Fix crash with borders whose widths are in em * `#1394 `_: Fix crash on draw_pattern * `#880 `_: Handle stacking contexts put in contexts by previous generations * `#1386 `_: Catch font subsetting errors * `#1403 `_: Fix how x and y attributes are handled in SVG * `#1399 `_, `#1401 `_: Don’t crash when use tags reference non-existing element * `#1393 `_: Handle font collections * `#1408 `_: Handle x and y attributes in use tags Documentation: * `#1391 `_, `#1405 `_: Add documentation for installation Contributors: * Guillaume Ayoub * Lucie Anglade * Pelle Bo Regener * aschmitz * John Jackson * Felix Schwarz * Syrus Dark * Christoph Päper Backers and sponsors: * OpenEdition * Grip Angebotssoftware * Simonsoft * PDF Blocks * Menutech * Manuel Barkhau * print-css.rocks * Simon Sapin * KontextWork * René Fritz * Maykin Media * Nathalie Gutton * Andreas Zettl * Tom Pohl * NCC Group * Moritz Mahringer * Florian Demmer * Des images et des mots * Mohammed Y. Alnajdi * Yanal-Yves Fargialla * Yevhenii Hyzyla Version 53.0b2 -------------- Released on 2021-05-30. **This version is experimental, don't use it in production. If you find bugs, please report them!** New features: * `#359 `_: Embed full sets of fonts in PDF Bug fixes: * `#1345 `_: Fix position of SVG use tags * `#1346 `_: Handle "stroke-dasharray: none" * `#1352 `_, `#1358 `_: Sort link target identifiers * `#1357 `_: Fix font information * `#1362 `_: Handle visibility and display properties in SVG * `#1365 `_: Cascade inherited attributes for use tags * `#1366 `_: Correctly handle style attributes in SVG * `#1367 `_: Include line stroke in box bounding Documentation: * `#1341 `_: Fix typos Contributors: * Guillaume Ayoub * aschmitz * John Jackson * Lucie Anglade * Pelle Bo Regener Backers and sponsors: * OpenEdition * print-css.rocks * Simonsoft * PDF Blocks * Menutech * Manuel Barkhau * Simon Sapin * Grip Angebotssoftware * KontextWork * René Fritz * Nathalie Gutton * Andreas Zettl * Tom Pohl * Maykin Media * Moritz Mahringer * Florian Demmer * Mohammed Y. Alnajdi * NCC Group * Des images et des mots * Yanal-Yves Fargialla * Yevhenii Hyzyla Version 53.0b1 -------------- Released on 2021-04-22. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * This version uses its own PDF generator instead of Cairo. Rendering may be different for text, gradients, SVG images… * Packaging is now done with Flit. New features: * `#1328 `_: Add ISO and JIS paper sizes * `#1309 `_: Leader support, with financial support from Simonsoft Bug fixes: * `#504 `_: Fix rendering bugs with PDF gradients * `#606 `_: Fix rounding errors on PDF dimensions * `#1264 `_: Include witdh/height when calculating auto margins of absolute boxes * `#1191 `_: Don’t try to get an earlier page break between columns * `#1235 `_: Include padding, border, padding when calculating inline-block width * `#1199 `_: Fix kerning issues with small fonts Documentation: * `#1298 `_: Rewrite documentation Contributors: * Guillaume Ayoub * Lucie Anglade * Felix Schwarz * Syrus Dark * Christoph Päper Backers and sponsors: * Simonsoft * PDF Blocks * Menutech * Manuel Barkhau * Simon Sapin * Nathalie Gutton * Andreas Zettl * René Fritz * Tom Pohl * KontextWork * Moritz Mahringer * Florian Demmer * Maykin Media * Yanal-Yves Fargialla * Des images et des mots * Yevhenii Hyzyla Version 52.5 ------------ Released on 2021-04-17. Bug fixes: * `#1336 `_: Fix text breaking exception * `#1318 `_: Fix @font-face rules with Pango 1.48.3+ Contributors: * Guillaume Ayoub Backers and sponsors: * Simonsoft * PDF Blocks * Menutech * Manuel Barkhau * Simon Sapin * Nathalie Gutton * Andreas Zettl * René Fritz * Tom Pohl * KontextWork * Moritz Mahringer * Florian Demmer * Maykin Media * Yanal-Yves Fargialla * Des images et des mots * Yevhenii Hyzyla Version 52.4 ------------ Released on 2021-03-11. Bug fixes: * `#1304 `_: Don’t try to draw SVG files with no size * `ece5f066 `_: Avoid crash on last word detection * `4ee42e48 `_: Remove last word before ellipses when hyphenated Contributors: * Guillaume Ayoub Backers and sponsors: * PDF Blocks * Simonsoft * Menutech * Simon Sapin * Manuel Barkhau * Andreas Zettl * Nathalie Gutton * Tom Pohl * René Fritz * Moritz Mahringer * Florian Demmer * KontextWork * Michele Mostarda Version 52.3 ------------ Released on 2021-03-02. Bug fixes: * `#1299 `_: Fix imports with url() and quotes New features: * `#1300 `_: Add support of line-clamp, with financial support from expert Germany Contributors: * Guillaume Ayoub * Lucie Anglade Backers and sponsors: * PDF Blocks * Simonsoft * Menutech * Simon Sapin * Manuel Barkhau * Andreas Zettl * Nathalie Gutton * Tom Pohl * Moritz Mahringer * Florian Demmer * KontextWork * Michele Mostarda Version 52.2 ------------ Released on 2020-12-06. Bug fixes: * `238e214 `_: Fix URL handling with tinycss2 * `#1248 `_: Include missing test data * `#1254 `_: Top margins removed from children when tables are displayed on multiple pages * `#1250 `_: Correctly draw borders on the last line of split tables * `a6f9c80 `_: Add a nice gif to please gdk-pixbuf 2.42.0 Contributors: * Guillaume Ayoub * Lucie Anglade * Felix Schwarz Backers and sponsors: * PDF Blocks * Simonsoft * Menutech * Simon Sapin * Nathalie Gutton * Andreas Zetti * Tom Pohl * Florian Demmer * Moritz Mahringer Version 52.1 ------------ Released on 2020-11-02. Bug fixes: * `238e214 `_: Fix URL handling with tinycss2 Contributors: * Guillaume Ayoub Backers and sponsors: * Simonsoft * Simon Sapin * Nathalie Gutton * Andreas Zettl * Florian Demmer * Moritz Mahringer Version 52 ---------- Released on 2020-10-29. Dependencies: * Python 3.6+ is now needed, Python 3.5 is not supported anymore * WeasyPrint now depends on Pillow New features: * `#1019 `_: Implement ``counter-set`` * `#1080 `_: Don’t display ``template`` tags * `#1210 `_: Use ``download`` attribute in ``a`` tags for attachment's filename * `#1206 `_: Handle strings in ``list-style-type`` * `#1165 `_: Add support for concatenating ``var()`` functions in ``content`` declarations * `c56b96b `_: Add an option to optimize embedded images size, with financial support from Hashbang * `#969 `_: Add an image cache that can be shared between documents, with financial support from Hashbang Bug fixes: * `#1141 `_: Don’t clip page margins on account of ``body`` overflow * `#1000 `_: Don’t apply ``text-indent`` twice on inline blocks * `#1051 `_: Avoid random line breaks * `#1120 `_: Gather target counters in page margins * `#1110 `_: Handle most cases for boxes avoiding floats in rtl containers, with financial support from Innovative Software * `#1111 `_: Fix horizontal position of last rtl line, with financial support from Innovative Software * `#1114 `_: Fix bug with transparent borders in tables * `#1146 `_: Don’t gather bookmarks twice for blocks that are displayed on two pages * `#1237 `_: Use fallback fonts on unsupported WOFF2 and WOFF fonts * `#1025 `_: Don’t insert the same layout attributes multiple times * `#1027 `_: Don’t try to break tables after the header or before the footer * `#1050 `_: Don’t crash on absolute SVG files with no intrinsic size * `#1204 `_: Fix a crash with a flexbox corner case * `#1030 `_: Fix frozen builds * `#1089 `_: Fix Pyinstaller builds * `#1216 `_: Fix embedded files * `#1225 `_: Initial support of RTL direction in flexbox layout Documentation: * `#1149 `_: Add the ``--quiet`` CLI option in the documentation * `#1061 `_: Update install instructions on Windows Tests: * `#1209 `_: Use GitHub Actions instead of Travis Contributors: * Guillaume Ayoub * Lucie Anglade * Tontyna * Mohammed Y. Alnajdi * Mike Voets * Bjarni Þórisson * Balázs Dukai * Bart Broere * Endalkachew * Felix Schwarz * Julien Sanchez * Konstantin Alekseev * Nicolas Hart * Nikolaus Schlemm * Thomas J. Lampoltshammer * mPyth * nempoBu4 * saddy001 Backers and sponsors: * Hashbang * Innovative Software * Screenbreak * Simon Sapin * Lisa Warshaw * Nathalie Gutton * Andreas Zettl * Florian Demmer * Moritz Mahringer Version 51 ---------- Released on 2019-12-23. Dependencies: * Pyphen 0.9.1+ is now needed New features: * `#882 `_: Add support of ``element()`` and ``running()`` * `#972 `_: Add HTML element to Box class * `7a4d6f8 `_: Support ``larger`` and ``smaller`` values for ``font-size`` Bug fixes: * `#960 `_: Fix how fonts used for macOS tests are installed * `#956 `_: Fix various crashes due to line breaking bugs * `#983 `_: Fix typo in variable name * `#975 `_: Don’t crash when ``string-set`` is set to ``none`` * `#998 `_: Keep font attributes when text lines are modified * `#1005 `_: Don’t let presentational hints add decorations on tables with no borders * `#974 `_: Don’t crash on improper ``var()`` values * `#1012 `_: Fix rendering of header and footer for empty tables * `#1013 `_: Avoid quadratic time relative to tree depth when setting page names Contributors: - Lucie Anglade - Guillaume Ayoub - Guillermo Bonvehí - Holger Brunn - Felix Schwarz - Tontyna Version 50 ---------- Released on 2019-09-19. New features: * `#209 `_: Make ``break-*`` properties work inside tables * `#661 `_: Make blocks with ``overflow: auto`` grow to include floating children Bug fixes: * `#945 `_: Don't break pages between a list item and its marker * `#727 `_: Avoid tables lost between pages * `#831 `_: Ignore auto margins on flex containers * `#923 `_: Fix a couple of crashes when splitting a line twice * `#896 `_: Fix skip stack order when using a reverse flex direction Contributors: - Lucie Anglade - Guillaume Ayoub Version 49 ---------- Released on 2019-09-11. Performance: * Speed and memory use have been largely improved. New features: * `#700 `_: Handle ``::marker`` pseudo-selector * `135dc06c `_: Handle ``recto`` and ``verso`` parameters for page breaks * `#907 `_: Provide a clean way to build layout contexts Bug fixes: * `#937 `_: Fix rendering of tables with empty lines and rowspans * `#897 `_: Don't crash when small columns are wrapped in absolute blocks * `#913 `_: Fix a test about gradient colors * `#924 `_: Fix title for document with attachments * `#917 `_: Fix tests with Pango 1.44 * `#919 `_: Fix padding and margin management for column flex boxes * `#901 `_: Fix width of replaced boxes with no intrinsic width * `#906 `_: Don't respect table cell width when content doesn't fit * `#927 `_: Don't use deprecated ``logger.warn`` anymore * `a8662794 `_: Fix margin collapsing between caption and table wrapper * `87d9e84f `_: Avoid infinite loops when rendering columns * `789b80e6 `_: Only use in flow children to set columns height * `615e298a `_: Don't include floating elements each time we try to render a column * `48d8632e `_: Avoid not in flow children to compute column height * `e7c452ce `_: Fix collapsing margins for columns * `fb0887cf `_: Fix crash when using currentColor in gradients * `f66df067 `_: Don't crash when using ex units in word-spacing in letter-spacing * `c790ff20 `_: Don't crash when properties needing base URL use var functions * `d63eac31 `_: Don't crash with object-fit: non images with no intrinsic size Documentation: * `#900 `_: Add documentation about semantic versioning * `#692 `_: Add a snippet about PDF magnification * `#899 `_: Add .NET wrapper link * `#893 `_: Fixed wrong nested list comprehension example * `#902 `_: Add ``state`` to the ``make_bookmark_tree`` documentation * `#921 `_: Fix typos in the documentation * `#328 `_: Add CSS sample for forms Contributors: - Lucie Anglade - Guillaume Ayoub - Raphael Gaschignard - Stani - Szmen - Thomas Dexter - Tontyna Version 48 ---------- Released on 2019-07-08. Dependencies: * CairoSVG 2.4.0+ is now needed New features: * `#891 `_: Handle ``text-overflow`` * `#878 `_: Handle ``column-span`` * `#855 `_: Handle all the ``text-decoration`` features * `#238 `_: Don't repeat background images when it's not needed * `#875 `_: Handle ``object-fit`` and ``object-position`` * `#870 `_: Handle ``bookmark-state`` Bug fixes: * `#686 `_: Fix column balance when children are not inline * `#885 `_: Actually use the content box to resolve flex items percentages * `#867 `_: Fix rendering of KaTeX output, including (1) set row baseline of tables when no cells are baseline-aligned, (2) set baseline for inline tables, (3) don't align lines larger than their parents, (4) force CairoSVG to respect image size defined by CSS. * `#873 `_: Set a minimum height for empty list elements with outside marker * `#811 `_: Don't use translations to align flex items * `#851 `_, `#860 `_: Don't cut pages when content overflows a very little bit * `#862 `_: Don't crash when using UTC dates in metadata Documentation: * `#854 `_: Add a "Tips & Tricks" section Contributors: - Gabriel Corona - Guillaume Ayoub - Manuel Barkhau - Nathan de Maestri - Lucie Anglade - theopeek Version 47 ---------- Released on 2019-04-12. New features: * `#843 `_: Handle CSS variables * `#846 `_: Handle ``:nth()`` page selector * `#847 `_: Allow users to use a custom SSL context for HTTP requests Bug fixes: * `#797 `_: Fix underlined justified text * `#836 `_: Fix crash when flex items are replaced boxes * `#835 `_: Fix ``margin-break: auto`` Version 46 ---------- Released on 2019-03-20. New features: * `#771 `_: Handle ``box-decoration-break`` * `#115 `_: Handle ``margin-break`` * `#821 `_: Continuous integration includes tests on Windows Bug fixes: * `#765 `_, `#754 `_, `#800 `_: Fix many crashes related to the flex layout * `#783 `_: Fix a couple of crashes with strange texts * `#827 `_: Named strings and counters are case-sensitive * `#823 `_: Shrink min/max-height/width according to box-sizing * `#728 `_, `#171 `_: Don't crash when fixed boxes are nested * `#610 `_, `#828 `_: Don't crash when preformatted text lines end with a space * `#808 `_, `#387 `_: Fix position of some images * `#813 `_: Don't crash when long preformatted text lines end with ``\n`` Documentation: * `#815 `_: Add documentation about custom ``url_fetcher`` Version 45 ---------- Released on 2019-02-20. WeasyPrint now has a `code of conduct `_. A new website has been launched, with beautiful and useful graphs about speed and memory use across versions: check `WeasyPerf `_. Dependencies: * Python 3.5+ is now needed, Python 3.4 is not supported anymore Bug fixes: * `#798 `_: Prevent endless loop and index out of range in pagination * `#767 `_: Add a ``--quiet`` CLI parameter * `#784 `_: Fix library loading on Alpine * `#791 `_: Use path2url in tests for Windows * `#789 `_: Add LICENSE file to distributed sources * `#788 `_: Fix pending references * `#780 `_: Don't draw patterns for empty page backgrounds * `#774 `_: Don't crash when links include quotes * `#637 `_: Fix a problem with justified text * `#763 `_: Launch tests with Python 3.7 * `#704 `_: Fix a corner case with tables * `#804 `_: Don't logger handlers defined before importing WeasyPrint * `#109 `_, `#748 `_: Don't include punctuation for hyphenation * `#770 `_: Don't crash when people use uppercase words from old-fashioned Microsoft fonts in tables, especially when there's an 5th column * Use a `separate logger `_ to report the rendering process * Add a ``--debug`` CLI parameter and set debug level for unknown prefixed CSS properties * Define minimal versions of Python and setuptools in setup.cfg Documentation: * `#796 `_: Fix a small typo in the tutorial * `#792 `_: Document no alignment character support * `#773 `_: Fix phrasing in Hacking section * `#402 `_: Add a paragraph about fontconfig error * `#764 `_: Fix list of dependencies for Alpine * Fix API documentation of HTML and CSS classes Version 44 ---------- Released on 2018-12-29. Bug fixes: * `#742 `_: Don't crash during PDF generation when locale uses commas as decimal separator * `#746 `_: Close file when reading VERSION * Improve speed and memory usage for long texts. Documentation: * `#733 `_: Small documentation fixes * `#735 `_: Fix broken links in NEWS.rst Version 43 ---------- Released on 2018-11-09. Bug fixes: * `#726 `_: Make empty strings clear previous values of named strings * `#729 `_: Include tools in packaging This version also includes the changes from unstable rc1 and rc2 versions listed below. Version 43rc2 ------------- Released on 2018-11-02. **This version is experimental, don't use it in production. If you find bugs, please report them!** Bug fixes: * `#706 `_: Fix text-indent at the beginning of a page * `#687 `_: Allow query strings in file:// URIs * `#720 `_: Optimize minimum size calculation of long inline elements * `#717 `_: Display
tags as blocks * `#691 `_: Don't recalculate max content widths when distributing extra space for tables * `#722 `_: Fix bookmarks and strings set on images * `#723 `_: Warn users when string() is not used in page margin Version 43rc1 ------------- Released on 2018-10-15. **This version is experimental, don't use it in production. If you find bugs, please report them!** Dependencies: * Python 3.4+ is now needed, Python 2.x is not supported anymore * Cairo 1.15.4+ is now needed, but 1.10+ should work with missing features (such as links, outlines and metadata) * Pdfrw is not needed anymore New features: * `Beautiful website `_ * `#579 `_: Initial support of flexbox * `#592 `_: Support @font-face on Windows * `#306 `_: Add a timeout parameter to the URL fetcher functions * `#594 `_: Split tests using modern pytest features * `#599 `_: Make tests pass on Windows * `#604 `_: Handle target counters and target texts * `#631 `_: Enable counter-increment and counter-reset in page context * `#622 `_: Allow pathlib.Path objects for HTML, CSS and Attachment classes * `#674 `_: Add extensive installation instructions for Windows Bug fixes: * `#558 `_: Fix attachments * `#565 `_, `#596 `_, `#539 `_: Fix many PDF rendering, printing and compatibility problems * `#614 `_: Avoid crashes and endless loops caused by a Pango bug * `#662 `_: Fix warnings and errors when generating documentation * `#666 `_, `#685 `_: Fix many table layout rendering problems * `#680 `_: Don't crash when there's no font available * `#662 `_: Fix support of some align values in tables Version 0.42.3 -------------- Released on 2018-03-27. Bug fixes: * `#583 `_: Fix floating-point number error to fix floating box layout * `#586 `_: Don't optimize resume_at when splitting lines with trailing spaces * `#582 `_: Fix table layout with no overflow * `#580 `_: Fix inline box breaking function * `#576 `_: Split replaced_min_content_width and replaced_max_content_width * `#574 `_: Respect text direction and don't translate rtl columns twice * `#569 `_: Get only first line's width of inline children to get linebox width Version 0.42.2 -------------- Released on 2018-02-04. Bug fixes: * `#560 `_: Fix a couple of crashes and endless loops when breaking lines. Version 0.42.1 -------------- Released on 2018-02-01. Bug fixes: * `#566 `_: Don't crash when using @font-config. * `#567 `_: Fix text-indent with text-align: justify. * `#465 `_: Fix string(\*, start). * `#562 `_: Handle named pages with pseudo-class. * `#507 `_: Fix running headers. * `#557 `_: Avoid infinite loops in inline_line_width. * `#555 `_: Fix margins, borders and padding in column layouts. Version 0.42 ------------ Released on 2017-12-26. WeasyPrint is not tested with (end-of-life) Python 3.3 anymore. **This release is probably the last version of the 0.x series.** Next version may include big changes: - end of Python 2.7 support, - initial support of bidirectional text, - initial support of flexbox, - improvements for speed and memory usage. New features: * `#532 `_: Support relative file URIs when using CLI. Bug fixes: * `#553 `_: Fix slow performance for pre-formatted boxes with a lot of children. * `#409 `_: Don't crash when rendering some tables. * `#39 `_: Fix rendering of floats in inlines. * `#301 `_: Split lines carefully. * `#530 `_: Fix root when frozen with Pyinstaller. * `#534 `_: Handle SVGs containing images embedded as data URIs. * `#360 `_: Fix border-radius rendering problem with some PDF readers. * `#525 `_: Fix pipenv support. * `#227 `_: Smartly handle replaced boxes with percentage width in auto-width parents. * `#520 `_: Don't ignore CSS @page rules that are imported by an @import rule. Version 0.41 ------------ Released on 2017-10-05. WeasyPrint now depends on pdfrw >= 0.4. New features: * `#471 `_: Support page marks and bleed. Bug fixes: * `#513 `_: Don't crash on unsupported image-resolution values. * `#506 `_: Fix @font-face use with write_* methods. * `#500 `_: Improve readability of _select_source function. * `#498 `_: Use CSS prefixes as recommended by the CSSWG. * `#441 `_: Fix rendering problems and crashes when using @font-face. * `bb3a4db `_: Try to break pages after a block before trying to break inside it. * `1d1654c `_: Fix and test corner cases about named pages. Documentation: * `#508 `_: Add missing libpangocairo dependency for Debian and Ubuntu. * `a7b17fb `_: Add documentation on logged rendering steps. Version 0.40 ------------ Released on 2017-08-17. WeasyPrint now depends on cssselect2 instead of cssselect and lxml. New features: * `#57 `_: Named pages. * Unprefix properties, see `#498 `_. * Add a "verbose" option logging the document generation steps. Bug fixes: * `#483 `_: Fix slow performance with long pre-formatted texts. * `#70 `_: Improve speed and memory usage for long documents. * `#487 `_: Don't crash on local() fonts with a space and no quotes. Version 0.39 ------------ Released on 2017-06-24. Bug fixes: * Fix the use of WeasyPrint's URL fetcher with CairoSVG. Version 0.38 ------------ Released on 2017-06-16. Bug fixes: * `#477 `_: Don't crash on font-face's src attributes with local functions. Version 0.37 ------------ Released on 2017-06-15. WeasyPrint now depends on tinycss2 instead of tinycss. New features: * `#437 `_: Support local links in generated PDFs. Bug fixes: * `#412 `_: Use a NullHandler log handler when WeasyPrint is used as a library. * `#417 `_, `#472 `_: Don't crash on some line breaks. * `#327 `_: Don't crash with replaced elements with height set in percentages. * `#467 `_: Remove incorrect line breaks. * `#446 `_: Let the logging module do the string interpolation. Version 0.36 ------------ Released on 2017-02-25. New features: * `#407 `_: Handle ::first-letter. * `#423 `_: Warn user about broken cairo versions. Bug fixes: * `#411 `_: Typos fixed in command-line help. Version 0.35 ------------ Released on 2017-02-25. Bug fixes: * `#410 `_: Fix AssertionError in split_text_box. Version 0.34 ------------ Released on 2016-12-21. Bug fixes: * `#398 `_: Honor the presentational_hints option for PDFs. * `#399 `_: Avoid CairoSVG-2.0.0rc* on Python 2. * `#396 `_: Correctly close files open by mkstemp. * `#403 `_: Cast the number of columns into int. * Fix multi-page multi-columns and add related tests. Version 0.33 ------------ Released on 2016-11-28. New features: * `#393 `_: Add tests on MacOS. * `#370 `_: Enable @font-face on MacOS. Bug fixes: * `#389 `_: Always update resume_at when splitting lines. * `#394 `_: Don't build universal wheels. * `#388 `_: Fix logic when finishing block formatting context. Version 0.32 ------------ Released on 2016-11-17. New features: * `#28 `_: Support @font-face on Linux. * Support CSS fonts level 3 almost entirely, including OpenType features. * `#253 `_: Support presentational hints (optional). * Support break-after, break-before and break-inside for pages and columns. * `#384 `_: Major performance boost. Bux fixes: * `#368 `_: Respect white-space for shrink-to-fit. * `#382 `_: Fix the preferred width for column groups. * Handle relative boxes in column-layout boxes. Documentation: * Add more and more documentation about Windows installation. * `#355 `_: Add fonts requirements for tests. Version 0.31 ------------ Released on 2016-08-28. New features: * `#124 `_: Add MIME sniffing for images. * `#60 `_: CSS Multi-column Layout. * `#197 `_: Add hyphens at line breaks activated by a soft hyphen. Bux fixes: * `#132 `_: Fix Python 3 compatibility on Windows. Documentation: * `#329 `_: Add documentation about installation on Windows. Version 0.30 ------------ Released on 2016-07-18. WeasyPrint now depends on html5lib-0.999999999. Bux fixes: * Fix Acid2 * `#325 `_: Cutting lines is broken in page margin boxes. * `#334 `_: Newest html5lib 0.999999999 breaks rendering. Version 0.29 ------------ Released on 2016-06-17. Bug fixes: * `#263 `_: Don't crash with floats with percents in positions. * `#323 `_: Fix CairoSVG 2.0 pre-release dependency in Python 2.x. Version 0.28 ------------ Released on 2016-05-16. Bug fixes: * `#189 `_: ``white-space: nowrap`` still wraps on hyphens * `#305 `_: Fix crashes on some tables * Don't crash when transform matrix isn't invertible * Don't crash when rendering ratio-only SVG images * Fix margins and borders on some tables Version 0.27 ------------ Released on 2016-04-08. New features: * `#295 `_: Support the 'rem' unit. * `#299 `_: Enhance the support of SVG images. Bug fixes: * `#307 `_: Fix the layout of cells larger than their tables. Documentation: * The website is now on GitHub Pages, the documentation is on Read the Docs. * `#297 `_: Rewrite the CSS chapter of the documentation. Version 0.26 ------------ Released on 2016-01-29. New features: * Support the `empty-cells` attribute. * Respect table, column and cell widths. Bug fixes: * `#172 `_: Unable to set table column width on tables td's. * `#151 `_: Table background colour bleeds beyond table cell boundaries. * `#260 `_: TypeError: unsupported operand type(s) for +: 'float' and 'str'. * `#288 `_: Unwanted line-breaks in bold text. * `#286 `_: AttributeError: 'Namespace' object has no attribute 'attachments'. Version 0.25 ------------ Released on 2015-12-17. New features: * Support the 'q' unit. Bug fixes: * `#285 `_: Fix a crash happening when splitting lines. * `#284 `_: Escape parenthesis in PDF links. * `#280 `_: Replace utf8 with utf-8 for gettext/django compatibility. * `#269 `_: Add support for use when frozen. * `#250 `_: Don't crash when attachments are not available. Version 0.24 ------------ Released on 2015-08-04. New features: * `#174 `_: Basic support for Named strings. Bug fixes: * `#207 `_: Draw rounded corners on replaced boxes. * `#224 `_: Rely on the font size for rounding bug workaround. * `#31 `_: Honor the vertical-align property in fixed-height cells. * `#202 `_: Remove unreachable area/border at bottom of page. * `#225 `_: Don't allow unknown units during line-height validation. * Fix some wrong conflict resolutions for table borders with inset and outset styles. Version 0.23 ------------ Released on 2014-09-16. Bug fixes: * `#196 `_: Use the default image sizing algorithm for images’s preferred size. * `#194 `_: Try more library aliases with ``dlopen()``. * `#201 `_: Consider ``page-break-after-avoid`` when pushing floats to the next page. * `#217 `_: Avoid a crash on zero-sized background images. Release process: * Start testing on Python 3.4 on Travis-CI. Version 0.22 ------------ Released on 2014-05-05. New features: * `#86 `_: Support gzip and deflate encoding in HTTP responses * `#177 `_: Support for PDF attachments. Bug fixes: * `#169 `_: Fix a crash on percentage-width columns in an auto-width table. * `#168 `_: Make ``
`` a block in the user-agent stylesheet. * `#175 `_: Fix some ``dlopen()`` library loading issues on OS X. * `#183 `_: Break to the next page before a float that would overflow the page. (It might still overflow if it’s bigger than the page.) * `#188 `_: Require a recent enough version of Pyphen Release process: * Drop Python 3.1 support. * Set up [Travis CI](https://travis-ci.org/) to automatically test all pushes and pull requests. * Start testing on Python 3.4 locally. (Travis does not support 3.4 yet.) Version 0.21 ------------ Released on 2014-01-11. New features: * Add the `overflow-wrap `_ property, allowing line breaks inside otherwise-unbreakable words. Thanks Frédérick Deslandes! * Add the `image-resolution `_ property, allowing images to be sized proportionally to their intrinsic size at a resolution other than 96 image pixels per CSS ``in`` (ie. one image pixel per CSS ``px``) Bug fixes: * `#145 `_: Fix parsing HTML from an HTTP URL on Python 3.x * `#40 `_: Use more general hyphenation dictionaries for specific document languages. (E.g. use ``hyph_fr.dic`` for ``lang="fr_FR"``.) * `#26 `_: Fix ``min-width`` and ``max-width`` on floats. * `#100 `_: Fix a crash on trailing whitespace with ``font-size: 0`` * `#82 `_: Borders on tables with ``border-collapse: collapse`` were sometimes drawn at an incorrect position. * `#30 `_: Fix positioning of images with ``position: absolute``. * `#118 `_: Fix a crash when using ``position: absolute`` inside a ``position: relative`` element. * Fix ``visibility: collapse`` to behave like ``visibility: hidden`` on elements other than table rows and table columns. * `#147 `_ and `#153 `_: Fix dependencies to require lxml 3.0 or a more recent version. Thanks gizmonerd and Thomas Grainger! * `#152 `_: Fix a crash on percentage-sized table cells in auto-sized tables. Thanks Johannes Duschl! Version 0.20.2 -------------- Released on 2013-12-18. * Fix `#146 `_: don't crash when drawing really small boxes with dotted/dashed borders Version 0.20.1 -------------- Released on 2013-12-16. * Depend on html5lib >= 0.99 instead of 1.0b3 to fix pip 1.4 support. * Fix `#74 `_: don't crash on space followed by dot at line break. * Fix `#78 `_: nicer colors for border-style: ridge/groove/inset/outset. Version 0.20 ------------ Released on 2013-12-14. * Add support for ``border-radius``. * Feature `#77 `_: Add PDF metadata from HTML. * Feature `#12 `_: Use html5lib. * Tables: handle percentages for column groups, columns and cells, and values for row height. * Bug fixes: * Fix `#84 `_: don't crash when stylesheets are not available. * Fix `#101 `_: use page ids instead of page numbers in PDF bookmarks. * Use ``logger.warning`` instead of deprecated ``logger.warn``. * Add 'font-stretch' in the 'font' shorthand. Version 0.19.2 -------------- Released on 2013-06-18. Bug fix release: * Fix `#88 `_: ``text-decoration: overline`` not being drawn above the text * Bug fix: Actually draw multiple lines when multiple values are given to ``text-decoration``. * Use the font metrics for text decoration positioning. * Bug fix: Don't clip the border with ``overflow: hidden``. * Fix `#99 `_: Regression: JPEG images not loading with cairo 1.8.x. Version 0.19.1 -------------- Released on 2013-04-30. Bug fix release: * Fix incorrect intrinsic width calculation leading to unnecessary line breaks in floats, tables, etc. * Tweak border painting to look better * Fix unnecessary page break before big tables. * Fix table row overflowing at the bottom of the page when there are margins above the table. * Fix ``position: fixed`` to actually repeat on every page. * Fix `#76 `_: repeat ```` and ```` elements on every page, even with table border collapsing. Version 0.19 ------------ Released on 2013-04-18. * Add support for ``linear-gradient()`` and ``radial-gradient`` in background images. * Add support for the ``ex`` and ``ch`` length units. (``1ex`` is based on the font instead of being always ``0.5em`` as before.) * Add experimental support for Level 4 hyphenation properties. * Drop support for CFFI < 0.6 and cairocffi < 0.4. * Many bug fixes, including: * Fix `#54 `_: min/max-width/height on block-level images. * Fix `#71 `_: Crash when parsing nested functional notation. Version 0.18 ------------ Released on 2013-03-30. * Add support for Level 3 backgrounds, including multiple background layers per element/box. * Forward-compatibility with (future releases of) cairocffi 0.4+ and CFFI 0.6+. * Bug fixes: * Avoid some unnecessary line breaks for elements sized based on their content (aka. “shrink-to-fit”) such as floats and page headers. * Allow page breaks between empty blocks. * Fix `#66 `_: Resolve images’ auto width from non-auto height and intrinsic ratio. * Fix `#21 `_: The ``data:`` URL scheme is case-insensitive. * Fix `#53 `_: Crash when backtracking for ``break-before/after: avoid``. Version 0.17.1 -------------- Released on 2013-03-18. Bug fixes: * Fix `#41 `_: GObject initialization when GDK-PixBuf is not installed. * Fix `#42 `_: absolute URLs without a base URL (ie. document parsed from a string.) * Fix some whitespace collapsing bugs. * Fix absolutely-positioned elements inside inline elements. * Fix URL escaping of image references from CSS. * Fix `#49 `_: Division by 0 on dashed or dotted border smaller than one dot/dash. * Fix `#44 `_: bad interaction of ``page-break-before/after: avoid`` and floats. Version 0.17 ------------ Released on 2013-02-27. * Added `text hyphenation`_ with the ``-weasy-hyphens`` property. * When a document includes JPEG images, embed them as JPEG in the PDF output. This often results in smaller PDF file size compared to the default *deflate* compression. * Switched to using CFFI instead of PyGTK or PyGObject-introspection. * Layout bug fixes: - Correctly trim whitespace at the end of lines. - Fix some cases with floats within inline content. .. _text hyphenation: https://weasyprint.readthedocs.io/en/latest/features.html#css-text-module-level-3-4 Version 0.16 ------------ Released on 2012-12-13. * Add the ``zoom`` parameter to ``HTML.write_pdf`` and ``Document.write_pdf() `` * Fix compatibility with old (and buggy) pycairo versions. WeasyPrint is now tested on 1.8.8 in addition to the latest. * Fix layout bugs related to line trailing spaces. Version 0.15 ------------ Released on 2012-10-09. * Add a low-level API that enables painting pages individually on any cairo surface. * **Backward-incompatible change**: remove the ``HTML.get_png_pages`` method. The new low-level API covers this functionality and more. * Add support for the ``font-stretch`` property. * Add support for ``@page:blank`` to select blank pages. * New Sphinx-based and improved docs * Bug fixes: - Importing Pango in some PyGTK installations. - Layout of inline-blocks with `vertical-align: top` or `bottom`. - Do not repeat a block’s margin-top or padding-top after a page break. - Performance problem with large tables split across many pages. - Anchors and hyperlinks areas now follow CSS transforms. Since PDF links have to be axis-aligned rectangles, the bounding box is used. This may be larger than expected with rotations that are not a multiple of 90 degrees. Version 0.14 ------------ Released on 2012-08-03. * Add a public API to choose media type used for @media. (It still defaults to ``print``). Thanks Chung Lu! * Add ``--base-url`` and ``--resolution`` to the command-line API, making it as complete as the Python one. * Add support for the ```` element in HTML. * Add support for CSS outlines * Switch to gdk-pixbuf instead of Pystacia for loading raster images. * Bug fixes: - Handling of filenames and URLs on Windows - Unicode filenames with older version of py2cairo - ``base_url`` now behaves as expected when set to a directory name. - Make some tests more robust Version 0.13 ------------ Released on 2012-07-23. * Add support for PyGTK, as an alternative to PyGObject + introspection. This should make WeasyPrint easier to run on platforms that not not have packages for PyGObject 3.x yet. * Bug fix: crash in PDF outlines for some malformed HTML documents Version 0.12 ------------ Released on 2012-07-19. * Add support for collapsed borders on tables. This is currently incompatible with repeating header and footer row groups on each page: headers and footers are treated as normal row groups on table with ``border-collapse: collapse``. * Add ``url_fetcher`` to the public API. This enables users to hook into WeasyPrint for fetching linked stylesheets or images, eg. to generate them on the fly without going through the network. This enables the creation of `Flask-WeasyPrint `_. Version 0.11 ------------ Released on 2012-07-04. * Add support for floats and clear. Together with various bug fixes, this enables WeasyPrint to pass the Acid2 test! Acid2 is now part of our automated test suite. * Add support for the width, min-width, max-width, height, min-height and max-height properties in @page. The size property is now the size of the page’s containing block. * Switch the Variable Dimension rules to `the new proposal `_. The previous implementation was broken in many cases. * The ``image-rendering``, ``transform``, ``transform-origin`` and ``size`` properties are now unprefixed. The prefixed form (eg. -weasy-size) is ignored but gives a specific warning. Version 0.10 ------------ Released on 2012-06-25. * Add ``get_png_pages()`` to the public API. It returns each page as a separate PNG image. * Add a ``resolution`` parameter for PNG. * Add *WeasyPrint Navigator*, a web application that shows WeasyPrint’s output with clickable links. Yes, that’s a browser in your browser. Start it with ``python -m weasyprint.navigator`` * Add support for `vertical-align: top` and `vertical-align: bottom` * Add support for `page-break-before: avoid` and `page-break-after: avoid` * Bug fixes Version 0.9 ----------- Released on 2012-06-04. * Relative, absolute and fixed positioning * Proper painting order (z-index) * In PDF: support for internal and external hyperlinks as well as bookmarks. * Added the ``tree`` parameter to the ``HTML`` class: accepts a parsed lxml object. * Bug fixes, including many crashes. Bookmarks can be controlled by the ``-weasy-bookmark-level`` and ``-weasy-bookmark-label`` properties, as described in `CSS Generated Content for Paged Media Module `_. The default UA stylesheet sets a matching bookmark level on all ``

`` to ``

`` elements. Version 0.8 ----------- Released on 2012-05-07. * Switch from cssutils to tinycss_ as the CSS parser. * Switch to the new cssselect_, almost all level 3 selectors are supported now. * Support for inline blocks and inline tables * Automatic table layout (column widths) * Support for the ``min-width``, ``max-width``, ``min-height`` and ``max-height`` properties, except on table-related and page-related boxes. * Speed improvements on big stylesheets / small documents thanks to tinycss. * Many bug fixes .. _tinycss: https://packages.python.org/tinycss/ .. _cssselect: https://packages.python.org/cssselect/ Version 0.7.1 ------------- Released on 2012-03-21. Change the license from AGPL to BSD. Version 0.7 ----------- Released on 2012-03-21. * Support page breaks between table rows * Support for the ``orphans`` and ``widows`` properties. * Support for ``page-break-inside: avoid`` * Bug fixes Only avoiding page breaks before/after an element is still missing. Version 0.6.1 ------------- Released on 2012-03-01. Fix a packaging bug. (Remove use_2to3 in setup.py. We use the same codebase for Python 2 and 3.) Version 0.6 ----------- Released on 2012-02-29. * *Backward incompatible*: completely change the Python API. See the documentation: https://weasyprint.readthedocs.io/en/latest/tutorial.html#as-a-python-library * *Backward incompatible*: Proper margin collapsing. This changes how blocks are rendered: adjoining margins "collapse" (their maximum is used) instead of accumulating. * Support images in ``embed`` or ``object`` elements. * Switch to pystacia instead of PIL for raster images * Add compatibility with CPython 2.6 and 3.2. (Previously only 2.7 was supported) * Many bug fixes Version 0.5 ----------- Released on 2012-02-08. * Support for the ``overflow`` and ``clip`` properties. * Support for the ``opacity`` property from CSS3 Colors. * Support for CSS 2D Transforms. These are prefixed, so you need to use ``-weasy-transform`` and ``-weasy-transform-origin``. Version 0.4 ----------- Released on 2012-02-07. * Support ``text-align: justify``, ``word-spacing`` and ``letter-spacing``. * Partial support for CSS3 Paged Media: page size and margin boxes with page-based counters. * All CSS 2.1 border styles * Fix SVG images with non-pixel units. Requires CairoSVG 0.3 * Support for ``page-break-before`` and ``page-break-after``, except for the value ``avoid``. * Support for the ``background-clip``, ``background-origin`` and ``background-size`` from CSS3 (but still with a single background per element) * Support for the ``image-rendering`` from SVG. This one is prefixed, use ``-weasy-image-rendering``. It only has an effect on PNG output. Version 0.3.1 ------------- Released on 2011-12-14. Compatibility with CairoSVG 0.1.2 Version 0.3 ----------- Released on 2011-12-13. * **Backward-incompatible change:** the 'size' property is now prefixed (since it is in an experimental specification). Use '-weasy-size' instead. * cssutils 0.9.8 or higher is now required. * Support SVG images with CairoSVG * Support generated content: the ``:before`` and ``:after`` pseudo-elements, the ``content``, ``quotes`` and ``counter-*`` properties. * Support ordered lists: all CSS 2.1 values of the ``list-style-type`` property. * New user-agent stylesheet with HTML 5 elements and automatic quotes for many languages. Thanks Peter Moulder! * Disable cssutils validation warnings, they are redundant with WeasyPrint’s. * Add ``--version`` to the command-line script. * Various bug fixes Version 0.2 ----------- Released on 2011-11-25. * Support for tables. * Support the `box-sizing` property from CSS 3 Basic User Interface * Support all values of vertical-align except top and bottom. They are interpreted as text-top and text-bottom. * Minor bug fixes Tables have some limitations: Only the fixed layout and separate border model are supported. There are also no page break inside tables so a table higher than a page will overflow. Version 0.1 ----------- Released on 2011-10-28. First packaged release. Supports "simple" CSS 2.1 pages: there is no support for floats, tables, or absolute positioning. Other than that most of CSS 2.1 is supported, as well as CSS 3 Colors and Selectors. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/common_use_cases.rst0000644000000000000000000005474415113607644015632 0ustar00Common Use Cases ================ Include in Web Applications --------------------------- Using WeasyPrint in web applications sometimes requires attention on some details. Security Problems ................. First of all, rendering untrusted HTML and CSS files can lead to :ref:`security problems `. Please be sure to carefully follow the different proposed solutions if you allow your users to modify the source of the rendered documents in any way. Rights Management ................. Another problem is rights management: you often need to render templates that can only be accessed by authenticated users, and WeasyPrint installed on the server doesn’t send the same cookies as the ones sent by the users. Extensions such as Flask-WeasyPrint_ (for Flask_) or Django-WeasyPrint_ (for Django_) solve this issue with a small amount of code. If you use another framework, you can read these extensions and probably find an equivalent workaround. .. _Flask-Weasyprint: https://github.com/Kozea/Flask-WeasyPrint .. _Flask: https://flask.palletsprojects.com/ .. _Django-WeasyPrint: https://github.com/fdemmer/django-weasyprint .. _Django: https://www.djangoproject.com/ Server Side Requests & Self-Signed SSL Certificates ................................................... If your server is requesting data from itself, you may encounter a self-signed certificate error, even if you have a valid certificate. You need to add yourself as a Certificate Authority, so that your self-signed SSL certificates can be requested. .. code-block:: bash # If you have not yet created a certificate. sudo openssl req -x509 \ -sha256 \ -nodes \ -newkey rsa:4096 \ -days 365 \ -keyout localhost.key \ -out localhost.crt # Follow the prompts about your certificate and the domain name. openssl x509 -text -noout -in localhost.crt Add your new self-signed SSL certificate to your nginx.conf, below the line ``server_name 123.123.123.123;``: .. code-block:: bash ssl_certificate /etc/ssl/certs/localhost.crt; ssl_certificate_key /etc/ssl/private/localhost.key; The SSL certificate will be valid when accessing your website from the internet. However, images will not render when requesting files from the same server. You will need to add your new self-signed certificates as trusted: .. code-block:: bash sudo cp /etc/ssl/certs/localhost.crt /usr/local/share/ca-certificates/localhost.crt sudo cp /etc/ssl/private/localhost.key /usr/local/share/ca-certificates/localhost.key # Update the certificate authority trusted certificates. sudo update-ca-certificates # Export your newly updated Certificate Authority Bundle file. # If using Django, it will use the newly signed certificate authority as # valid and images will load properly. sudo tee -a /etc/environment <<< 'export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt' Adjust Document Dimensions -------------------------- WeasyPrint does not provide support for adjusting page size or document margins via command-line flags. This is best accomplished with the CSS ``@page`` at-rule. Consider the following example: .. code-block:: css @page { size: Letter; /* Change from the default size of A4 */ margin: 3cm; /* Set margin on each page */ } There is much more which can be achieved with the ``@page`` at-rule, such as page numbers, headers, etc. Read more about the page_ at-rule. .. _page: https://developer.mozilla.org/en-US/docs/Web/CSS/@page Generate Specialized PDFs ------------------------- WeasyPrint can generate different PDF variants, including PDF/UA and PDF/A. The feature is available by using the ``--pdf-variant`` CLI option, or the ``pdf_variant`` Python parameter of :func:`HTML.write_pdf `. .. code-block:: python from weasyprint import HTML HTML(string="

document

").write_pdf("document.pdf", pdf_variant="pdf/a-3u") .. code-block:: sh $ weasyprint document.html --pdf-variant="pdf/ua-1" document.pdf The different supported variants can be listed using ``weasyprint --help``. Even if WeasyPrint tries to generate valid documents, the result is not guaranteed: the HTML, CSS and PDF features chosen by the user must follow the limitations defined by the different specifications. PDF/A (Archiving) ................. PDF/A documents are specialized for archiving purposes. They are a simple subset of PDF, with a lot of limitations: no audio, video or JavaScript, defined color spaces, embedded fonts, etc. If possible, PDF/A-3u should be preferred: it allows transparency layers that are forbidden in A-1, and arbitrary formats for attached files that are forbidden in A-2. The "u" part of the variant indicates that the PDF text is available as Unicode. PDF/A documents include a PDF identifier, that is mainly useful to indicate that a PDF is a new version of another PDF. By default, WeasyPrint generates a valid PDF identifier, but you can provide your own with the ``--pdf-identifier`` CLI option or ``pdf_identifier`` Python parameter. If your document includes images, you must set the ``image-rendering: crisp-edges`` property to avoid anti-aliasing, that is forbidden by PDF/A. PDF/UA (Universal Accessibility) ................................ PDF/UA documents are specialized for accessibility purposes. They include extra metadata that define document information and content structure. The main constraint to get valid PDF/UA documents is to use a correct HTML structure, to avoid inconsistencies in the PDF structure. The HTML order is also used to define the order of the PDF content. Some information is required in your HTML file, including a ```` tag, and a ``lang`` attribute set on the ``<html>`` tag. PDF/X (Graphics Exchange) ......................... PDF/X documents facilitate graphics exchange and adds printing-related requirements such as color profiles. The easiest way to fulfill these requirements is to use device-dependent CMYK colors and images everywhere in your document. For colors, you can use the ``device-cmyk()`` function: .. code-block:: css body { color: device-cmyk(0% 10% 0% 80%) } You also have to define the output profile color to use. .. code-block:: css @color-profile device-cmyk { components: cyan, magenta, yellow, black; src: url(path/to/cmyk-profile.icc); } If possible, PDF/X-4 should be preferred: it allows transparency layers that are forbidden by previous variants. Factur-X / ZUGFeRD (Electronic Invoices) ........................................ Factur-X / ZUGFeRD is a Franco-German standard for hybrid e-invoice, the first implementation of the European Semantic Standard EN 16931. It enables users to include normalized metadata in PDF invoices, such as companies information or invoice amounts, so that compatible software can automatically read this information. This standard is based on PDF/A-3b. WeasyPrint can generate Factur-X / ZUGFeRD documents. Invoice metadata must be generated by the user and included in the PDF document when rendered. Two different metadata files are required: - the first one is RDF metadata, containing document metadata and PDF/A extension information; - the second one is Factur-X / ZUGFeRD metadata, containing invoice amounts, plus seller and buyer information. Here is an example of Factur-X document generation. ``rdf.xml``: .. code-block:: xml <x:xmpmeta xmlns:x="adobe:ns:meta/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" xmlns:fx="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#"> <!-- placeholder --> <rdf:RDF> <rdf:Description rdf:about=""> <fx:ConformanceLevel>MINIMUM</fx:ConformanceLevel> <fx:DocumentFileName>factur-x.xml</fx:DocumentFileName> <fx:DocumentType>INVOICE</fx:DocumentType> <fx:Version>1.0</fx:Version> </rdf:Description> <rdf:Description rdf:about=""> <pdfaExtension:schemas> <rdf:Bag> <rdf:li rdf:parseType="Resource"> <pdfaSchema:schema>Factur-X PDFA Extension Schema</pdfaSchema:schema> <pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI> <pdfaSchema:prefix>fx</pdfaSchema:prefix> <pdfaSchema:property> <rdf:Seq> <rdf:li rdf:parseType="Resource"> <pdfaProperty:name>DocumentFileName</pdfaProperty:name> <pdfaProperty:valueType>Text</pdfaProperty:valueType> <pdfaProperty:category>external</pdfaProperty:category> <pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description> </rdf:li> <rdf:li rdf:parseType="Resource"> <pdfaProperty:name>DocumentType</pdfaProperty:name> <pdfaProperty:valueType>Text</pdfaProperty:valueType> <pdfaProperty:category>external</pdfaProperty:category> <pdfaProperty:description>INVOICE</pdfaProperty:description> </rdf:li> <rdf:li rdf:parseType="Resource"> <pdfaProperty:name>Version</pdfaProperty:name> <pdfaProperty:valueType>Text</pdfaProperty:valueType> <pdfaProperty:category>external</pdfaProperty:category> <pdfaProperty:description>The actual version of the Factur-X XML schema</pdfaProperty:description> </rdf:li> <rdf:li rdf:parseType="Resource"> <pdfaProperty:name>ConformanceLevel</pdfaProperty:name> <pdfaProperty:valueType>Text</pdfaProperty:valueType> <pdfaProperty:category>external</pdfaProperty:category> <pdfaProperty:description>The conformance level of the embedded Factur-X data</pdfaProperty:description> </rdf:li> </rdf:Seq> </pdfaSchema:property> </rdf:li> </rdf:Bag> </pdfaExtension:schemas> </rdf:Description> </rdf:RDF> </x:xmpmeta> ``factur-x.xml``: .. code-block:: xml <rsm:CrossIndustryInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"> <rsm:ExchangedDocumentContext> <ram:BusinessProcessSpecifiedDocumentContextParameter> <ram:ID>A1</ram:ID> </ram:BusinessProcessSpecifiedDocumentContextParameter> <ram:GuidelineSpecifiedDocumentContextParameter> <ram:ID>urn:factur-x.eu:1p0:minimum</ram:ID> </ram:GuidelineSpecifiedDocumentContextParameter> </rsm:ExchangedDocumentContext> <rsm:ExchangedDocument> <ram:ID>123</ram:ID> <ram:TypeCode>380</ram:TypeCode> <ram:IssueDateTime> <udt:DateTimeString format="102">20200131</udt:DateTimeString> </ram:IssueDateTime> </rsm:ExchangedDocument> <rsm:SupplyChainTradeTransaction> <ram:ApplicableHeaderTradeAgreement> <ram:BuyerReference>Buyer</ram:BuyerReference> <ram:SellerTradeParty> <ram:Name>Supplyer Corp</ram:Name> <ram:SpecifiedLegalOrganization> <ram:ID schemeID="0002">123456782</ram:ID> </ram:SpecifiedLegalOrganization> <ram:PostalTradeAddress> <ram:CountryID>FR</ram:CountryID> </ram:PostalTradeAddress> <ram:SpecifiedTaxRegistration> <ram:ID schemeID="VA">FR11123456782</ram:ID> </ram:SpecifiedTaxRegistration> </ram:SellerTradeParty> <ram:BuyerTradeParty> <ram:Name>Buyer Corp</ram:Name> <ram:SpecifiedLegalOrganization> <ram:ID schemeID="0002">987654324</ram:ID> </ram:SpecifiedLegalOrganization> </ram:BuyerTradeParty> <ram:BuyerOrderReferencedDocument > <ram:IssuerAssignedID>456</ram:IssuerAssignedID> </ram:BuyerOrderReferencedDocument> </ram:ApplicableHeaderTradeAgreement> <ram:ApplicableHeaderTradeDelivery/> <ram:ApplicableHeaderTradeSettlement> <ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode> <ram:SpecifiedTradeSettlementHeaderMonetarySummation> <ram:TaxBasisTotalAmount>100.00</ram:TaxBasisTotalAmount> <ram:TaxTotalAmount currencyID="EUR">20.00</ram:TaxTotalAmount> <ram:GrandTotalAmount>120.00</ram:GrandTotalAmount> <ram:DuePayableAmount>120.00</ram:DuePayableAmount> </ram:SpecifiedTradeSettlementHeaderMonetarySummation> </ram:ApplicableHeaderTradeSettlement> </rsm:SupplyChainTradeTransaction> </rsm:CrossIndustryInvoice> ``invoice.py``: .. code-block:: python from pathlib import Path from weasyprint import Attachment, HTML def generate_rdf_metadata(metadata, variant, version, conformance): original_rdf = generate_original_rdf_metadata(metadata, variant, version, conformance) return Path("rdf.xml").read_bytes().replace(b"<!-- placeholder -->", original_rdf) document = HTML(string="<h1>Invoice</h1>").render() generate_original_rdf_metadata = document.metadata.generate_rdf_metadata factur_x_xml = Path("factur-x.xml").read_text() attachment = Attachment(string=factur_x_xml, name="factur-x.xml", relationship="Data") document.metadata.attachments = [attachment] document.metadata.generate_rdf_metadata = generate_rdf_metadata document.write_pdf("invoice.pdf", pdf_variant="pdf/a-3b") Of course, the content of these files has to be adapted to the content of real invoices. Using XML generators instead of plain text manipulation is also highly recommended. A more detailed blog article is available on `Binary Butterfly’s website <https://binary-butterfly.de/artikel/factur-x-zugferd-e-invoices-with-python/>`_. Include PDF Forms ----------------- By default, form fields are transformed into pure text and graphical shapes when exported to PDF. But WeasyPrint gives the possibility to generate real PDF forms that can be filled with a PDF reader. These forms can even send requests with the data filled in the PDF, just as the same form would do in a web browser. To transform all HTML forms into PDF forms, you can use the ``--pdf-forms`` CLI option or ``pdf_forms`` Python parameter. .. code-block:: python from weasyprint import HTML HTML(string="<input value='test'>").write_pdf("test.pdf", pdf_forms=True) .. code-block:: sh $ weasyprint document.html --pdf-forms document.pdf You can also define which specific fields (``input``, ``select``, ``textarea``, ``button``) have to be transformed into PDF forms by setting the ``appearance`` CSS property to ``auto`` on them. In this case, as for browsers, you’ll have to manually override the default style set by the user agent stylesheet. Reading `the stylesheet set by the --pdf-forms option <https://github.com/Kozea/WeasyPrint/blob/main/weasyprint/css/html5_ua_form.css>`_ can help to override this style. .. code-block:: html <style> label { display: block } .pdf-form { appearance: auto } .pdf-form::before { visibility: hidden } </style> <label> Can't be modified in PDF <input value="static"> </label> <label> Can be modified in PDF <input class="pdf-form" value="dynamic"> </label> PDF forms support can be quite poor depending on the PDF reader you use. If a feature doesn’t work for you, please check that this feature is actually supported by your PDF reader before reporting a bug. Define PDF Metadata ------------------- PDF documents can include various metadata, such as title, authors or creation date. The easiest way to define them is to include them in your HTML file: these fields are normalized and can be automatically picked up by WeasyPrint. .. code-block:: html <html lang="en"> <head> <title>PDF Sample with Metadata HTML metadata values listed here, including language and title, are stored in the corresponding, normalized fields in PDF. If you use custom metadata fields, they are not stored in PDF by default. You can include them in the PDF info dictionary using the ``--custom-metadata`` CLI option or the ``custsom_metadata`` Python parameter. .. code-block:: python from weasyprint import HTML HTML(string="").write_pdf("recipe.pdf", custom_metadata=True) .. code-block:: sh $ weasyprint document.html --custom-metadata document.pdf Attach Files ------------ You can attach files to your generated PDF. These files can be opened when a link is clicked in the PDF, or just available in the list of attached files in your PDF reader. To attach a file with a regular link, you can use a regular anchor with the ``rel`` attribute set to ``attachment``. .. code-block:: html view attached note To attach a file globally to the document, you can add a ``link`` tag in your ``head``: .. code-block:: html If you don’t want to attach your files using HTML tags, you can also use the ``--attachment`` CLI option, multiple times if needed. .. code-block:: sh $ weasyprint document.html --attachment note.txt --attachment photo.jpg document.pdf In a Python script, you can also attach files using the :class:`weasyprint.Attachment` class. .. code-block:: python from weasyprint import Attachment, HTML attachments = [Attachment("note.txt"), Attachment("photo.jpg")] HTML(string="

PDF with attachments

").write_pdf("recipe.pdf", attachments=attachments) Cache and Optimize Images ------------------------- WeasyPrint provides many options to deal with images: ``optimize_images``, ``jpeg_quality``, ``dpi`` and ``cache``. ``optimize_images`` can enable size optimization for images. When enabled, the generated PDF will include smaller images with no quality penalty, but the rendering time may be slightly increased. The ``jpeg_quality`` option can be set to decrease the quality of JPEG images included in the PDF. You can set a value between 95 (best quality) to 0 (smaller image size), depending on your needs. The ``dpi`` option offers the possibility to reduce the size (in pixels, and thus in bytes) of all included raster images. The resolution, set in dots per inch, indicates the maximum number of pixels included in one inch on the generated PDF. .. code-block:: python # Original high-quality images, faster, but generated PDF is larger HTML('https://weasyprint.org/').write_pdf('weasyprint.pdf') # Optimized lower-quality images, a bit slower, but generated PDF is smaller HTML('https://weasyprint.org/').write_pdf( 'weasyprint.pdf', optimize_images=True, jpeg_quality=60, dpi=150) ``cache`` gives the possibility to use a cache for images, avoiding to download, parse and optimize them each time they are used. By default, the cache is used document by document, but you can share it between documents if needed. This feature can save a lot of network and CPU time when you render a lot of documents that use the same images. .. code-block:: python cache = {} for i in range(10): HTML(f'https://weasyprint.org/').write_pdf( f'example-{i}.pdf', cache=cache) It’s also possible to cache images on disk instead of keeping them in memory. The ``--cache-folder`` CLI option can be used to define the folder used to store temporary images. You can also provide this folder path as a string for ``cache``. Improve Rendering Speed and Memory Use -------------------------------------- WeasyPrint is often slower than other web engines. Python is the usual suspect, but it’s not the main culprit here. :ref:`Optimization is not the main goal of WeasyPrint ` and it may lead to unbearable long rendering times. First of all: WeasyPrint’s performance gets generally better with time. You can check WeasyPerf_ to compare time and memory needed across versions. Some tips may help you to get better results. - A high number of CSS properties with a high number of HTML tags can lead to a huge amount of time spent for the cascade. Avoiding large CSS frameworks can drastically reduce the rendering time. - Tables are known to be slow, especially when they are rendered on multiple pages. When possible, using a common block layout instead gives much faster renderings. - Optimizing images and fonts can reduce the PDF size, but increase the rendering time. Moreover, caching images gives the possibility to read and optimize images only once, and thus to save time when the same image is used multiple times. See :ref:`Cache and Optimize Images`. .. _WeasyPerf: https://kozea.github.io/WeasyPerf/ Show Log Messages ----------------- Most errors (unsupported CSS property, missing image…) are not fatal and will not prevent a document from being rendered. WeasyPrint uses the :mod:`logging` module from the Python standard library to log these errors and let you know about them. When WeasyPrint is launched in a terminal, logged messages will go to the standard error stream (``stderr``) by default. When used as a library, logs are not displayed at all. You can change that by configuring the ``weasyprint`` logger object: .. code-block:: python import logging logger = logging.getLogger('weasyprint') # Display warnings, errors and critical messages. logger.setLevel(logging.WARNING) # Save logs to the weasyprint.log file. logger.addHandler(logging.FileHandler('weasyprint.log')) # Print logs on console. logger.addHandler(logging.StreamHandler()) The ``weasyprint.progress`` logger is used to report the rendering progress. It is useful to get feedback when WeasyPrint is launched in a terminal (using the ``--verbose`` or ``--debug`` option), or to give this feedback to end users when used as a library. See the documentation of the :mod:`logging` module for details. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/conf.py0000644000000000000000000000550215113607644013041 0ustar00# WeasyPrint documentation build configuration file. import weasyprint # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.autosectionlabel'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = 'WeasyPrint' copyright = 'Simon Sapin and contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The full version, including alpha/beta/rc tags. release = weasyprint.__version__ # The short X.Y version. version = release # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'monokai' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'furo' html_theme_options = { 'top_of_page_buttons': ['edit'], 'source_edit_link': 'https://github.com/Kozea/WeasyPrint/edit/main/docs/{filename}', } # Favicon URL html_favicon = 'https://www.courtbouillon.org/static/images/favicon.png' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = [] # These paths are either relative to html_static_path # or fully qualified paths (eg. https://...) html_css_files = [ 'https://www.courtbouillon.org/static/docs-furo.css', ] # Output file base name for HTML help builder. htmlhelp_basename = 'weasyprintdoc' # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('manpage', 'weasyprint', 'The Awesome Document Factory', ['Simon Sapin and contributors'], 1) ] # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [( 'index', 'WeasyPrint', 'WeasyPrint Documentation', 'Simon Sapin and contributors', 'WeasyPrint', 'The Awesome Document Factory', 'Miscellaneous'), ] # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { 'python': ('https://docs.python.org/3/', None), 'pydyf': ('https://doc.courtbouillon.org/pydyf/stable/', None), } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/contribute.rst0000644000000000000000000000426015113607644014452 0ustar00Contribute ========== You want to add some code to WeasyPrint, launch its tests or improve its documentation? Thank you very much! Here are some tips to help you play with WeasyPrint in good conditions. The first step is to clone the repository, create a virtual environment and install WeasyPrint dependencies: .. code-block:: shell git clone https://github.com/Kozea/WeasyPrint.git cd WeasyPrint python -m venv venv venv/bin/pip install -e '.[doc,test]' You can then launch Python to test your changes: .. code-block:: shell venv/bin/python Running WeasyPrint might look something like this: .. code-block:: shell venv/bin/python -m weasyprint example.html example.pdf Code & Issues ------------- If you’ve found a bug in WeasyPrint, it’s time to report it, and to fix it if you can! You can report bugs and feature requests on `GitHub`_. If you want to add or fix some code, please fork the repository and create a pull request, we’ll be happy to review your work. You can find more information about the code architecture in the :ref:`Dive into the Source` section. .. _GitHub: https://github.com/Kozea/WeasyPrint Tests ----- Tests are stored in the ``tests`` folder at the top of the repository. They use the pytest_ library. Tests require Ghostscript_ to be installed and available on the local path. You should also install all the `DejaVu fonts`_ if you’re on Linux. You can launch tests using the following command:: venv/bin/python -m pytest WeasyPrint also uses ruff_ to check the coding style:: venv/bin/python -m ruff check .. _pytest: https://docs.pytest.org/ .. _Ghostscript: https://www.ghostscript.com/ .. _DejaVu fonts: https://dejavu-fonts.github.io/ .. _ruff: https://docs.astral.sh/ruff/ Documentation ------------- Documentation is stored in the ``docs`` folder at the top of the repository. It relies on the `Sphinx`_ library. You can build the documentation using the following command:: venv/bin/sphinx-build docs docs/_build The documentation home page can now be found in the ``/path/to/weasyprint/docs/_build/index.html`` file. You can open this file in a browser to see the final rendering. .. _Sphinx: https://www.sphinx-doc.org/ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/first_steps.rst0000644000000000000000000005356615113607644014656 0ustar00First Steps =========== .. currentmodule:: weasyprint Installation ------------ WeasyPrint |version| depends on: * Python_ ≥ 3.10.0 * Pango_ ≥ 1.44.0 * pydyf_ ≥ 0.11.0 * CFFI_ ≥ 0.6 * tinyhtml5_ ≥ 2.0.0b1 * tinycss2_ ≥ 1.5.0 * cssselect2_ ≥ 0.8.0 * Pyphen_ ≥ 0.9.1 * Pillow_ ≥ 9.1.0 * fontTools_ ≥ 4.59.2 .. _Python: https://www.python.org/ .. _Pango: https://pango.gnome.org/ .. _CFFI: https://cffi.readthedocs.io/ .. _pydyf: https://doc.courtbouillon.org/pydyf/ .. _tinyhtml5: https://doc.courtbouillon.org/tinyhtml5/ .. _tinycss2: https://doc.courtbouillon.org/tinycss2/ .. _cssselect2: https://doc.courtbouillon.org/cssselect2/ .. _Pyphen: https://pyphen.org/ .. _Pillow: https://python-pillow.org/ .. _fontTools: https://github.com/fonttools/fonttools There are many ways to install WeasyPrint, depending on the system you use. Linux ~~~~~ The easiest way to install WeasyPrint on Linux is to use the package manager of your distribution. WeasyPrint is packaged for recent versions of Debian_, Ubuntu_, Fedora_, Archlinux_, Gentoo_… .. _Debian: https://packages.debian.org/search?keywords=weasyprint&searchon=names&suite=all§ion=all .. _Ubuntu: https://packages.ubuntu.com/search?keywords=weasyprint&searchon=names&suite=all§ion=all .. _Fedora: https://src.fedoraproject.org/rpms/weasyprint .. _Archlinux: https://aur.archlinux.org/packages/python-weasyprint .. _Gentoo: https://packages.gentoo.org/packages/dev-python/weasyprint If WeasyPrint is not available on your distribution, or if you want to use a more recent version of WeasyPrint, you have to be sure that Python_ and Pango_ are installed on your system, and that they are recent enough. You can verify this by launching:: python3 --version pango-view --version If the version of Pango provided by your distribution is too old, you can use version 52.5 of WeasyPrint which does not need recent Pango features. When everything is OK, you can install WeasyPrint directly on your system or in a `virtual environment`_ using `pip`_:: python3 -m venv venv source venv/bin/activate pip install weasyprint weasyprint --info .. _virtual environment: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/ .. _pip: https://pip.pypa.io/ Alpine ≥ 3.17 +++++++++++++ To install WeasyPrint using your distribution’s package:: apk add weasyprint To install WeasyPrint inside a virtualenv using wheels (if possible), you need the following packages:: apk add py3-pip so:libgobject-2.0.so.0 so:libpango-1.0.so.0 so:libharfbuzz.so.0 so:libharfbuzz-subset.so.0 so:libfontconfig.so.1 so:libpangoft2-1.0.so.0 To install WeasyPrint inside a virtualenv without using wheels, you need the following packages:: apk add py3-pip so:libgobject-2.0.so.0 so:libpango-1.0.so.0 so:libharfbuzz.so.0 so:libharfbuzz-subset.so.0 so:libfontconfig.so.1 so:libpangoft2-1.0.so.0 apk add gcc musl-dev python3-dev zlib-dev jpeg-dev openjpeg-dev libwebp-dev g++ libffi-dev Archlinux +++++++++ To install WeasyPrint using your distribution’s package:: pacman -S python-weasyprint To install WeasyPrint inside a virtualenv using wheels (if possible), you need the following packages:: pacman -S python-pip pango To install WeasyPrint inside a virtualenv without using wheels, you need the following packages:: pacman -S python-pip pango gcc libjpeg-turbo openjpeg2 Debian ≥ 11 +++++++++++ To install WeasyPrint using your distribution’s package:: apt install weasyprint To install WeasyPrint inside a virtualenv using wheels (if possible), you need the following packages:: apt install python3-pip libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 To install WeasyPrint inside a virtualenv without using wheels, you need the following packages:: apt install python3-pip libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 libjpeg-dev libopenjp2-7-dev libffi-dev Fedora ≥ 39 +++++++++++ To install WeasyPrint using your distribution’s package:: dnf install weasyprint To install WeasyPrint inside a virtualenv using wheels (if possible), you need the following packages:: dnf install python-pip pango To install WeasyPrint inside a virtualenv without using wheels, you need the following packages:: dnf install python3-pip pango gcc python3-devel gcc-c++ zlib-devel libjpeg-devel openjpeg2-devel libffi-devel Ubuntu ≥ 20.04 ++++++++++++++ To install WeasyPrint using your distribution’s package:: apt install weasyprint To install WeasyPrint inside a virtualenv using wheels (if possible), you need the following packages:: apt install python3-pip libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 libharfbuzz-subset0 To install WeasyPrint inside a virtualenv without using wheels, you need the following packages:: apt install python3-pip libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 libharfbuzz-subset0 libffi-dev libjpeg-dev libopenjp2-7-dev macOS ~~~~~ The easiest way to install WeasyPrint on macOS is to use Homebrew_:: brew install weasyprint .. _Homebrew: https://brew.sh/ Windows ~~~~~~~ To use WeasyPrint on Windows, the easiest way is to use the `executable`_ of the latest release. .. warning:: WeasyPrint is regularly marked as malware by different antivirus companies. See `#2081`_ or `#2092`_ to get more information on this topic. Don’t hesitate to report the false positive detection to your antivirus company in order to improve malware detection for future versions. If you want to use WeasyPrint as a Python library, you’ll have to follow a few extra steps. Please read this chapter carefully. The first step is to install the latest version of Python from the `Microsoft Store`_. When Python is installed, you have to install Pango and its dependencies. The easiest way to install these libraries is to use MSYS2. Here are the steps you have to follow: - Install `MSYS2`_ keeping the default options. - After installation, in MSYS2’s shell, execute ``pacman -S mingw-w64-x86_64-pango``. - Close MSYS2’s shell. You can then launch a Windows command prompt by clicking on the Start menu, typing ``cmd`` and clicking the "Command Prompt" icon. Install WeasyPrint in a `virtual environment`_ using `pip`_:: python3 -m venv venv venv\Scripts\activate.bat python3 -m pip install weasyprint python3 -m weasyprint --info .. _executable: https://github.com/Kozea/WeasyPrint/releases .. _#2081: https://github.com/Kozea/WeasyPrint/issues/2081 .. _#2092: https://github.com/Kozea/WeasyPrint/issues/2092 .. _Microsoft Store: https://apps.microsoft.com/store/search/python .. _MSYS2: https://www.msys2.org/#installation Other Solutions ~~~~~~~~~~~~~~~ Other solutions are available to install WeasyPrint. These solutions are not tested but they are known to work for some use cases on specific platforms. Macports ++++++++ On macOS, you can install WeasyPrint’s dependencies with Macports_:: sudo port install py-pip pango libffi You can then install WeasyPrint in a `virtual environment`_ using `pip`_:: python3 -m venv venv source venv/bin/activate pip install weasyprint weasyprint --info .. _Macports: https://www.macports.org/ Conda +++++ On Linux and macOS, WeasyPrint is available on Conda_, with `a WeasyPrint package on Conda Forge`_. .. _Conda: https://docs.conda.io/projects/conda/en/latest/ .. _a WeasyPrint package on Conda Forge: https://anaconda.org/conda-forge/weasyprint WSL +++ On Windows, you can also use WSL_ and install WeasyPrint the same way it has to be installed on Linux. .. _WSL: https://docs.microsoft.com/en-us/windows/wsl/ .NET Wrapper ++++++++++++ On Windows, Bader Albarrak maintains `a .NET wrapper`_. .. _a .NET wrapper: https://github.com/balbarak/WeasyPrint-netcore AWS +++ Kotify maintains `an AWS Lambda layer`_, see issue `#1003`_ for more information. .. _an AWS Lambda layer: https://github.com/kotify/cloud-print-utils .. _#1003: https://github.com/Kozea/WeasyPrint/issues/1003 Docker ++++++ Luca Vercelli maintains `Docker images`_. .. _an AWS Lambda layer: https://github.com/kotify/cloud-print-utils .. _Docker images: https://github.com/luca-vercelli/WeasyPrint-docker-images/ Troubleshooting ~~~~~~~~~~~~~~~ Most of the installation problems have already been met, and some `issues on GitHub`_ could help you to solve them. If the solutions here don’t solve your problem, please open a new issue (and don’t add comments to closed issues). .. _issues on GitHub: https://github.com/Kozea/WeasyPrint/issues Missing Library +++++++++++++++ On Windows or macOS, most of the problems come from unreachable libraries. If you get an error like ``cannot load library 'xxx': error xxx``, it means that WeasyPrint can’t find this library. On Windows, you can set the ``WEASYPRINT_DLL_DIRECTORIES`` environment variable to list the folders where the DLL files can be found. For example, in ``cmd.exe``:: set WEASYPRINT_DLL_DIRECTORIES=C:\msys64\mingw64\bin On macOS, you can set the ``DYLD_FALLBACK_LIBRARY_PATH`` environment variable:: export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_FALLBACK_LIBRARY_PATH Of course, check that the folders you set actually contain the ``.dll`` (on Windows) or ``.dylib`` (on macOS) files WeasyPrint requires. Missing Fonts +++++++++++++ If no character is drawn in the generated PDF, or if you get squares instead of letters, you have to install fonts and make them available to WeasyPrint. Following the standard way to install fonts on your system should be enough. You can also use ``@font-face`` rules to explicitly reference fonts using URLs. Command-Line ------------ Using the WeasyPrint command line interface can be as simple as this: .. code-block:: sh weasyprint https://weasyprint.org /tmp/weasyprint-website.pdf You may see warnings on the standard error output about unsupported CSS properties. See :ref:`Command-Line API` for the details of all available options. In particular, the ``-s`` option can add a filename for a :ref:`user stylesheet `. For quick experimentation however, you may not want to create a file. In bash or zsh, you can use the shell’s redirection instead: .. code-block:: sh weasyprint https://weasyprint.org /tmp/weasyprint-website.pdf \ -s <(echo 'body { font-family: serif !important }') If you have many documents to convert you may prefer using the Python API in long-lived processes to avoid paying the start-up costs every time. Python Library -------------- .. attention:: Using WeasyPrint with untrusted HTML or untrusted CSS may lead to various :ref:`security problems `. Quickstart ~~~~~~~~~~ The Python version of the above example goes like this: .. code-block:: python from weasyprint import HTML HTML('https://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf') … or with the inline stylesheet: .. code-block:: python from weasyprint import HTML, CSS HTML('https://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf', stylesheets=[CSS(string='body { font-family: serif !important }')]) Instantiating HTML and CSS Objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you have a file name, an absolute URL or a readable :term:`file object`, you can just pass it to :class:`HTML` or :class:`CSS` to create an instance. Alternatively, use a named argument so that no guessing is involved: .. code-block:: python from weasyprint import HTML HTML('../foo.html') # Same as … HTML(filename='../foo.html') HTML('https://weasyprint.org') # Same as … HTML(url='https://weasyprint.org') HTML(sys.stdin) # Same as … HTML(file_obj=sys.stdin) If you have a byte string or Unicode string already in memory you can also pass that, although the argument must be named: .. code-block:: python from weasyprint import HTML, CSS # HTML('

foo') would be filename HTML(string='''

The title

Content goes here ''') CSS(string='@page { size: A3; margin: 1cm }') If you have ``@font-face`` rules in your CSS, you have to create a ``FontConfiguration`` object: .. code-block:: python from weasyprint import HTML, CSS from weasyprint.text.fonts import FontConfiguration font_config = FontConfiguration() html = HTML(string='

The title

') css = CSS(string=''' @font-face { font-family: Gentium; src: url(https://example.com/fonts/Gentium.otf); } h1 { font-family: Gentium }''', font_config=font_config) html.write_pdf( '/tmp/example.pdf', stylesheets=[css], font_config=font_config) Rendering to a Single File ~~~~~~~~~~~~~~~~~~~~~~~~~~ Once you have a :class:`HTML` object, call its :meth:`HTML.write_pdf` method to get the rendered document in a single PDF file. Without arguments, this method returns a byte string in memory. If you pass a file name or a writable :term:`file object`, they will write there directly instead. (**Warning**: with a filename, these methods will overwrite existing files silently.) Rendering Individual Pages ~~~~~~~~~~~~~~~~~~~~~~~~~~ If you want more than a single PDF, the :meth:`HTML.render` method gives you a :class:`document.Document` object with access to individual :class:`document.Page` objects. Thus you can get the number of pages, their size\ [#]_, the details of hyperlinks and bookmarks, etc. Documents also have a :meth:`document.Document.write_pdf` method, and you can get a subset of the pages with :meth:`document.Document.copy()`. .. [#] Pages in the same document do not always have the same size. See the :ref:`Python API` for details. A few random examples: .. code-block:: python # Write odd and even pages separately: # Lists count from 0 but page numbers usually from 1 # [::2] is a slice of even list indexes but odd-numbered pages. document.copy(document.pages[::2]).write_pdf('odd_pages.pdf') document.copy(document.pages[1::2]).write_pdf('even_pages.pdf') .. code-block:: python # Print the outline of the document. # Output on https://www.w3.org/TR/CSS21/intro.html # 1. Introduction to CSS 2.1 (page 2) # 1. A brief CSS 2.1 tutorial for HTML (page 2) # 2. A brief CSS 2.1 tutorial for XML (page 5) # 3. The CSS 2.1 processing model (page 6) # 1. The canvas (page 7) # 2. CSS 2.1 addressing model (page 7) # 4. CSS design principles (page 8) def print_outline(bookmarks, indent=0): for i, bookmark in enumerate(bookmarks, 1): page = bookmark.destination[0] print('%s%d. %s (page %d)' % ( ' ' * indent, i, bookmark.label.lstrip('0123456789. '), page)) print_outline(bookmark.children, indent + 2) print_outline(document.make_bookmark_tree()) URL Fetchers ~~~~~~~~~~~~ WeasyPrint goes through a *URL fetcher* to fetch external resources such as images or CSS stylesheets. The default fetcher can natively open file and HTTP URLs, but the HTTP client does not support advanced features like cookies or authentication. This can be worked-around by passing a custom ``url_fetcher`` callable to the :class:`HTML` or :class:`CSS` classes. It must have the same signature as :func:`default_url_fetcher`. Custom fetchers can choose to handle some URLs and defer others to the default fetcher: .. code-block:: python from weasyprint import default_url_fetcher, HTML def my_fetcher(url): if url.startswith('graph:'): graph_data = map(float, url[6:].split(',')) string = generate_graph(graph_data) return {'string': string, 'mime_type': 'image/png'} return default_url_fetcher(url) source = '' HTML(string=source, url_fetcher=my_fetcher).write_pdf('out.pdf') Flask-WeasyPrint_ for Flask_ and Django-Weasyprint_ for Django_ both make use of a custom URL fetcher to integrate WeasyPrint and use the filesystem instead of a network call for static and media files. A custom fetcher should be returning a :obj:`dict` with * One of ``string`` (a :obj:`bytestring `) or ``file_obj`` (a :term:`file object`). * Optionally: ``mime_type``, a MIME type extracted e.g. from a *Content-Type* header. If not provided, the type is guessed from the file extension in the URL. * Optionally: ``encoding``, a character encoding extracted e.g. from a *charset* parameter in a *Content-Type* header * Optionally: ``redirected_url``, the actual URL of the resource if there were e.g. HTTP redirects. * Optionally: ``filename``, the filename of the resource. Usually derived from the *filename* parameter in a *Content-Disposition* header If a ``file_obj`` is given, the resource will be closed automatically by the function internally used by WeasyPrint to retrieve data. .. _Flask-Weasyprint: https://github.com/Kozea/Flask-WeasyPrint .. _Flask: https://flask.pocoo.org/ .. _Django-WeasyPrint: https://github.com/fdemmer/django-weasyprint .. _Django: https://www.djangoproject.com/ Security -------- *This section has been added thanks to the very useful reports and advice from Raz Becker.* When used with untrusted HTML or untrusted CSS, WeasyPrint can meet security problems. You will need extra configuration in your Python application to avoid high memory use, endless renderings or local files leaks. As for any service dealing with untrusted data, you should at least follow basic security rules with WeasyPrint: don’t launch the service as root, launch it as a user with limited access to filesystem, network and memory. Using a container can also be a simple way to limit the possibilities given to an attacker in case of security breach. Long Renderings ~~~~~~~~~~~~~~~ WeasyPrint is pretty slow and can take a long time to render long documents or specially crafted HTML pages. When WeasyPrint used on a server with HTML or CSS files from untrusted sources, this problem can lead to very long time renderings, with processes with high CPU and memory use. Even small documents may lead to really long rendering times, restricting HTML document size is not enough. If you use WeasyPrint on a server with HTML or CSS samples coming from untrusted users, you should: - limit rendering time and memory use of your process, for example using ``evil-reload-on-as`` and ``harakiri`` options if you use uWSGI, - limit memory use at the OS level, for example with ``ulimit`` on Linux, - automatically kill the process when it uses too much memory or when the rendering time is too high, by regularly launching a script to do so if no better option is available, - truncate and sanitize HTML and CSS input to avoid very long documents and access to external URLs. Infinite Requests ~~~~~~~~~~~~~~~~~ WeasyPrint can reach files on the network, for example using ``https://`` URIs. For various reasons, HTTP requests may take a long time and lead to problems similar to :ref:`Long Renderings`. WeasyPrint has a default timeout of 10 seconds for HTTP, HTTPS and FTP resources. This timeout has no effect with other protocols, including access to ``file://`` URIs. If you use WeasyPrint on a server with HTML or CSS samples coming from untrusted users, or need to reach network resources, you should: - use a custom :ref:`URL fetcher `, - follow solutions listed in :ref:`Long Renderings`. Infinite Loops ~~~~~~~~~~~~~~ WeasyPrint has been hit by a large number of bugs, including infinite loops. Specially crafted HTML and CSS files can quite easily lead to infinite loops and infinite rendering times. If you use WeasyPrint on a server with HTML or CSS samples coming from untrusted users, you should: - follow solutions listed in :ref:`Long Renderings`. Huge Values ~~~~~~~~~~~ WeasyPrint doesn't restrict integer and float values used in CSS. Using huge values for some properties (page sizes, font sizes, block sizes) can lead to various problems, including infinite rendering times, huge PDF files, high memory use and crashes. This problem is really hard to avoid. Even parsing CSS stylesheets and searching for huge values is not enough, as it is quite easy to trick CSS pre-processors using relative units (``em`` and ``%`` for example). If you use WeasyPrint on a server with HTML or CSS samples coming from untrusted users, you should: - follow solutions listed in :ref:`Long Renderings`. Access to Local Files ~~~~~~~~~~~~~~~~~~~~~ As any web renderer, WeasyPrint can reach files on the local filesystem using ``file://`` URIs. These files can be shown in ``img`` or ``embed`` tags for example. When WeasyPrint used on a server with HTML or CSS files from untrusted sources, this feature may be used to know if files are present on the server filesystem, and to embed them in generated documents. Unix-like systems also have special local files with infinite size, like ``/dev/urandom``. Referencing these files in HTML or CSS files obviously lead to infinite time renderings. If you use WeasyPrint on a server with HTML or CSS samples coming from untrusted users, you should: - restrict your process access to trusted files using sandboxing solutions, - use a custom :ref:`URL fetcher ` that doesn't allow ``file://`` URLs or filters access depending on given paths. - follow solutions listed in :ref:`Long Renderings`. System Information Leaks ~~~~~~~~~~~~~~~~~~~~~~~~ WeasyPrint relies on many libraries that can leak hardware and software information. Even when this information looks useless, it can be used by attackers to exploit other security breaches. Leaks can include (but are not restricted to): - locally installed fonts (using ``font-family`` and ``@font-face``), - network configuration (IPv4 and IPv6 support, IP addressing, firewall configuration, using ``https://`` URIs and tracking time used to render documents), - Python, Pango and other libraries versions (implementation details lead to different renderings). SVG Images ~~~~~~~~~~ Rendering SVG images more or less suffers from the same problems as the ones listed here for WeasyPrint. Security advices apply for untrusted SVG files as they apply for untrusted HTML and CSS documents. Note that WeasyPrint’s URL fetcher is used to render SVG files. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/going_further.rst0000644000000000000000000002677615113607644015156 0ustar00Going Further ============= .. currentmodule:: weasyprint Why WeasyPrint? --------------- Automatic document generation is a common need of many applications, even if a lot of operations do not require printed paper anymore. Invoices, tickets, leaflets, diplomas, documentation, books… All these documents are read and used on paper, but also on electronical readers, on smartphones, on computers. PDF is a great format to store and display them in a reliable way, with pagination. Using HTML and CSS to generate static and paged content can be strange at first glance: browsers display only one page, with variable dimensions, often in a very dynamic way. But paged media layout is actually included in CSS2_, which was already a W3C recommendation in 1998. Other well-known tools can be used to automatically generate PDF documents, like LaTeX and LibreOffice, but they miss many advantages that HTML and CSS offer. HTML and CSS are very widely known, by developers but also by webdesigners. They are specified in a backwards-compatible way, and regularly adapted to please the use of billions of people. They are really easy to write and generate, with a ridiculous amount of tools that are finely adapted to the needs and taste of their users. However, the web engines that are used for browsers were very limited for pagination when WeasyPrint was created in 2011. Even now, they lack a lot of basic features. That’s why projects such as wkhtmltopdf_ and PagedJS_ have been created: they add some of these features to existing browsers. Other solutions have beed developed, including web engine dedicated to paged media. Prince_, Antennahouse_ or `Typeset.sh`_ created original renderers supporting many features related to pagination. These tools are very powerful, but they are not open source. Building a free and open source web renderer generating high-quality documents is the main goal of WeasyPrint. Do you think that it was a little bit crazy to create such a big project from scratch? Here is what `Simon Sapin`_ wrote in WeasyPrint’s documentation one month after the beginning: Are we crazy? Yes. But not that much. Each modern web browser did take many developers’ many years of work to get where they are now, but WeasyPrint’s scope is much smaller: there is no user-interaction, no JavaScript, no live rendering (the document doesn’t changed after it was first parsed) and no quirks mode (we don’t need to support every broken page of the web.) We still need however to implement the whole CSS box model and visual rendering. This is a lot of work, but we feel we can get something useful much quicker than “Let’s build a rendering engine!” may seem. Simon is often right. .. _CSS2: https://www.w3.org/TR/1998/REC-CSS2-19980512/ .. _wkhtmltopdf: https://wkhtmltopdf.org/ .. _PagedJS: https://www.pagedjs.org/ .. _Prince: https://www.princexml.com/ .. _Antennahouse: https://www.antennahouse.com/ .. _Typeset.sh: https://typeset.sh/ .. _Simon Sapin: https://exyr.org/ Why Python? ----------- Python is a really good language to design a small, OS-agnostic parser. As it is object-oriented, it gives the possibility to follow the specification with high-level classes and a small amount of very simple code. Speed is not WeasyPrint’s main goal. Web rendering is a very complex task, and following :pep:`the Zen of Python <20>` helped a lot to keep our sanity (both in our code and in our heads): code simplicity, maintainability and flexibility are the most important goals for this library, as they give the ability to stay really close to the specification and to fix bugs easily. Dive into the Source -------------------- This chapter is a high-level overview of WeasyPrint’s source code. For more details, see the various docstrings or even the code itself. When in doubt, feel free to :ref:`ask `! Much `like in web browsers`_, the rendering of a document in WeasyPrint goes like this: 1. The HTML document is fetched and parsed into a tree of elements (like DOM). 2. CSS stylesheets (either found in the HTML or supplied by the user) are fetched and parsed. 3. The stylesheets are applied to the DOM-like tree. 4. The DOM-like tree with styles is transformed into a *formatting structure* made of rectangular boxes. 5. These boxes are *laid-out* with fixed dimensions and position onto pages. 6. For each page, the boxes are re-ordered to observe stacking rules, and are drawn on a PDF page. 7. Metadata −such as document information, attachments, embedded files, hyperlinks, and PDF trim and bleed boxes− are added to the PDF. .. _like in web browsers: https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#The_main_flow Parsing HTML ............ Not much to see here. The :class:`HTML` class handles step 1 and gives a tree of HTML *elements*. Although the actual API is different, this tree is conceptually the same as what web browsers call *the DOM*. Parsing CSS ........... As with HTML, CSS stylesheets are parsed in the :class:`CSS` class with an external library, tinycss2_. In addition to the actual parsing, the ``css`` and ``css.validation`` modules do some pre-processing: * Unknown and unsupported declarations are ignored with warnings. Remaining property values are parsed in a property-specific way from raw tinycss2 tokens into a higher-level form. * Shorthand properties are expanded. For example, ``margin`` becomes ``margin-top``, ``margin-right``, ``margin-bottom`` and ``margin-left``. * Hyphens in property names are replaced by underscores (``margin-top`` becomes ``margin_top``). This transformation is safe since none of the known (not ignored) properties have an underscore character. * Selectors are pre-compiled with cssselect2_. .. _tinycss2: https://pypi.python.org/pypi/tinycss2 .. _cssselect2: https://pypi.python.org/pypi/cssselect2 The Cascade ........... After that and still in the ``css`` package, the cascade_ (that’s the C in CSS!) applies the stylesheets to the element tree. Selectors associate property declarations to elements. In case of conflicting declarations (different values for the same property on the same element), the one with the highest *weight* wins. Weights are based on the stylesheet’s :ref:`origin `, ``!important`` markers, selector specificity and source order. Missing values are filled in through *inheritance* (from the parent element) or the property’s *initial value*, so that every element has a *specified value* for every property. .. _cascade: https://www.w3.org/TR/CSS21/cascade.html These *specified values* are turned into *computed values* in the ``css.computed_values`` module. Keywords and lengths in various units are converted to pixels, etc. At this point the value for some properties can be represented by a single number or string, but some require more complex objects. For example, a ``Dimension`` object can be either an absolute length or a percentage. The final result of the ``css.get_all_computed_styles`` function is a big dict where keys are ``(element, pseudo_element_type)`` tuples, and keys are style dict objects. Elements are ElementTree elements, while the type of pseudo-element is a string for eg. ``::first-line`` selectors, or :obj:`None` for “normal” elements. Style dict objects are dicts mapping property names to the computed values. (The return value is not the dict itself, but a convenience ``style_for`` function for accessing it.) Formatting Structure .................... The `visual formatting model`_ explains how *elements* (from the ElementTree tree) generate *boxes* (in the formatting structure). This is step 4 above. Boxes may have children and thus form a tree, much like elements. This tree is generally close but not identical to the ElementTree tree: some elements generate more than one box or none. .. _visual formatting model: https://www.w3.org/TR/CSS21/visuren.html Boxes are of a lot of different kinds. For example you should not confuse *block-level boxes* and *block containers*, though *block boxes* are both. The ``formatting_structure.boxes`` module has a whole hierarchy of classes to represent all these boxes. We won’t go into the details here, see the module and class docstrings. The ``formatting_structure.build`` module takes an ElementTree tree with associated computed styles, and builds a formatting structure. It generates the right boxes for each element and ensures they conform to the models rules (eg. an inline box can not contain a block). Each box has a ``style`` attribute containing the style dict of computed values. The main logic is based on the ``display`` property, but it can be overridden for some elements by adding a handler in the ``html`` module. This is how ```` and ```` are currently implemented, for example. This module is rather short as most of HTML is defined in CSS rather than in Python, in the `user agent stylesheet`_. The ``formatting_structure.build.build_formatting_structure`` function returns the box for the root element (and, through its ``children`` attribute, the whole tree). .. _user agent stylesheet: https://github.com/Kozea/WeasyPrint/blob/main/weasyprint/css/html5_ua.css Layout ...... Step 5 is the layout. You could say the everything else is glue code and this is where the magic happens. During the layout the document’s content is, well, laid out on pages. This is when we decide where to do line breaks and page breaks. If a break happens inside of a box, that box is split into two (or more) boxes in the layout result. According to the `box model`_, each box has rectangular margin, border, padding and content areas: .. _box model: https://www.w3.org/TR/CSS21/box.html .. image:: https://www.w3.org/TR/CSS21/images/boxdim.png :alt: CSS Box Model :class: dark-invert While ``box.style`` contains computed values, the `used values`_ are set as attributes of the ``Box`` object itself during the layout. This include resolving percentages and especially ``auto`` values into absolute, pixel lengths. Once the layout done, each box has used values for margins, border width, padding of each four sides, as well as the ``width`` and ``height`` of the content area. They also have ``position_x`` and ``position_y``, the absolute coordinates of the top-left corner of the margin box (**not** the content box) from the top-left corner of the page.\ [#]_ Boxes also have helpers methods such as ``content_box_y`` and ``margin_width`` that give other metrics that can be useful in various parts of the code. The final result of the layout is a list of ``PageBox`` objects. .. [#] These are the coordinates *if* no `CSS transform`_ applies. Transforms change the actual location of boxes, but they are applied later during drawing and do not affect layout. .. _used values: https://www.w3.org/TR/CSS21/cascade.html#used-value .. _CSS transform: https://www.w3.org/TR/css-transforms-1/ Stacking & Drawing .................. In step 6, the boxes are reordered by the ``stacking`` module to observe `stacking rules`_ such as the ``z-index`` property. The result is a tree of *stacking contexts*. Next, each laid-out page is *drawn* onto a PDF page. Since each box has absolute coordinates on the page from the layout step, the logic here should be minimal. If you find yourself adding a lot of logic here, maybe it should go in the layout or stacking instead. The code lives in the ``draw`` module. .. _stacking rules: https://www.w3.org/TR/CSS21/zindex.html Metadata ........ Finally (step 7), the ``pdf`` adds metadata to the PDF file: document information, attachments, hyperlinks, embedded files, trim box and bleed box. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/index.rst0000644000000000000000000000046415113607644013405 0ustar00WeasyPrint ========== .. currentmodule:: weasyprint .. include:: ../README.rst .. toctree:: :caption: Documentation :maxdepth: 2 first_steps common_use_cases api_reference going_further .. toctree:: :caption: Extra Information :maxdepth: 2 changelog contribute support ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1672635 weasyprint-67.0/docs/manpage.rst0000644000000000000000000000026415113607644013704 0ustar00:orphan: .. currentmodule:: weasyprint Description ----------- .. autofunction:: weasyprint.__main__.main(argv=sys.argv) :noindex: About ----- .. include:: ../README.rst ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/docs/support.rst0000644000000000000000000000156215113607644014012 0ustar00Support ======= Sponsorship ----------- With `donations and sponsorship`, you help make the projects better. Donations allow the CourtBouillon team to have more time dedicated to add new features, fix bugs, and improve documentation. .. _donations and sponsorship: https://opencollective.com/courtbouillon Professional Support -------------------- You can improve your experience with CourtBouillon’s tools thanks to our professional support. You want bugs fixed as soon as possible? Your projects would highly benefit from some new features? You or your team would like to get new skills with one of the technologies we master? Please contact us by mail, by chat, or by tweet to get in touch and find the best way we can help you. .. _mail: mailto:contact@courtbouillon.org .. _chat: https://gitter.im/CourtBouillon/tinycss2 .. _tweet: https://twitter.com/BouillonCourt ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/pyproject.toml0000644000000000000000000000442415113607644013530 0ustar00[build-system] requires = ['flit_core >=3.2,<4'] build-backend = 'flit_core.buildapi' [project] name = 'weasyprint' description = 'The Awesome Document Factory' keywords = ['html', 'css', 'pdf', 'converter'] authors = [{name = 'Simon Sapin', email = 'simon.sapin@exyr.org'}] maintainers = [{name = 'CourtBouillon', email = 'contact@courtbouillon.org'}] requires-python = '>=3.10' readme = {file = 'README.rst', content-type = 'text/x-rst'} license = {file = 'LICENSE'} dependencies = [ 'pydyf >=0.11.0', 'cffi >=0.6', 'tinyhtml5 >=2.0.0b1', 'tinycss2 >=1.5.0', 'cssselect2 >=0.8.0', 'Pyphen >=0.9.1', 'Pillow >=9.1.0', 'fonttools[woff] >=4.59.2', ] classifiers = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Text Processing :: Markup :: HTML', 'Topic :: Multimedia :: Graphics :: Graphics Conversion', 'Topic :: Printing', ] dynamic = ['version'] [project.urls] Homepage = 'https://weasyprint.org/' Documentation = 'https://doc.courtbouillon.org/weasyprint/' Code = 'https://github.com/Kozea/WeasyPrint' Issues = 'https://github.com/Kozea/WeasyPrint/issues' Changelog = 'https://github.com/Kozea/WeasyPrint/releases' Donation = 'https://opencollective.com/courtbouillon' [project.optional-dependencies] doc = ['sphinx', 'furo'] test = ['pytest', 'ruff'] [project.scripts] weasyprint = 'weasyprint.__main__:main' [tool.flit.sdist] exclude = ['.*'] [tool.coverage.run] branch = true include = ['tests/*', 'weasyprint/*'] [tool.coverage.report] exclude_lines = ['pragma: no cover', 'def __repr__', 'raise NotImplementedError'] [tool.ruff.lint] select = ['E', 'W', 'F', 'I', 'N', 'RUF', 'T20', 'PIE', 'PT', 'RSE', 'UP'] ignore = ['E226', 'RUF001', 'RUF002', 'RUF003', 'RUF039', 'RUF059', 'UP031'] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/tests/__init__.py0000644000000000000000000000004115113607644014056 0ustar00"""The Weasyprint test suite.""" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/tests/conftest.py0000644000000000000000000000700715113607644014155 0ustar00"""Configuration for WeasyPrint tests. This module adds a PNG export based on Ghostscript. Note that Ghostscript is released under AGPL. """ import io import os import shutil from subprocess import PIPE, run from tempfile import NamedTemporaryFile import pytest from PIL import Image from weasyprint import HTML from weasyprint.document import Document from . import draw MAGIC_NUMBER = b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a' def document_write_png(document, target=None, resolution=96, antialiasing=1, zoom=4/30, split_images=False): # Use temporary files because gs on Windows doesn’t accept binary on stdin with NamedTemporaryFile(delete=False) as pdf: document.write_pdf(pdf, zoom=zoom) command = ( 'gs', '-q', '-sDEVICE=png16m', f'-dTextAlphaBits={antialiasing}', f'-dGraphicsAlphaBits={antialiasing}', '-dBATCH', '-dNOPAUSE', '-dPDFSTOPONERROR', f'-r{resolution / zoom}', '-dUsePDFX3Profile', '-sOutputFile=-', pdf.name) pngs = run(command, stdout=PIPE).stdout os.remove(pdf.name) error = pngs.split(MAGIC_NUMBER)[0].decode().strip() or 'no output' assert pngs.startswith(MAGIC_NUMBER), f'Ghostscript error: {error}' if split_images: assert target is None # TODO: use a different way to find PNG files in stream magic_numbers = pngs.count(MAGIC_NUMBER) if magic_numbers == 1: if target is None: return [pngs] if split_images else pngs png = io.BytesIO(pngs) else: images = [MAGIC_NUMBER + png for png in pngs[8:].split(MAGIC_NUMBER)] if split_images: return images images = [Image.open(io.BytesIO(image)) for image in images] width = max(image.width for image in images) height = sum(image.height for image in images) output_image = Image.new('RGBA', (width, height)) top = 0 for image in images: output_image.paste(image, (int((width - image.width) / 2), top)) top += image.height png = io.BytesIO() output_image.save(png, format='png') png.seek(0) if target is None: return png.read() if hasattr(target, 'write'): shutil.copyfileobj(png, target) else: with open(target, 'wb') as fd: shutil.copyfileobj(png, fd) def html_write_png(document, target=None, font_config=None, counter_style=None, resolution=96, **options): document = document.render(font_config, counter_style, **options) return document.write_png(target, resolution) Document.write_png = document_write_png HTML.write_png = html_write_png def test_filename(filename): return ''.join( character if character.isalnum() else '_' for character in filename[5:50]).rstrip('_') @pytest.fixture def assert_pixels(request, *args, **kwargs): return lambda *args, **kwargs: draw.assert_pixels( test_filename(request.node.name), *args, **kwargs) @pytest.fixture def assert_same_renderings(request, *args, **kwargs): return lambda *args, **kwargs: draw.assert_same_renderings( test_filename(request.node.name), *args, **kwargs) @pytest.fixture def assert_different_renderings(request, *args, **kwargs): return lambda *args, **kwargs: draw.assert_different_renderings( test_filename(request.node.name), *args, **kwargs) @pytest.fixture def assert_pixels_equal(request, *args, **kwargs): return lambda *args, **kwargs: draw.assert_pixels_equal( test_filename(request.node.name), *args, **kwargs) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/tests/css/__init__.py0000644000000000000000000000003115113607644014645 0ustar00"""Test CSS features.""" ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/tests/css/test_common.py0000644000000000000000000001642215113607644015450 0ustar00"""Test the CSS parsing, cascade, inherited and computed values.""" from math import isclose import pytest from weasyprint import CSS, default_url_fetcher from weasyprint.css import find_stylesheets, get_all_computed_styles from weasyprint.urls import path2url from ..testing_utils import ( # isort:skip BASE_URL, FakeHTML, assert_no_logs, capture_logs, resource_path) @assert_no_logs def test_find_stylesheets(): html = FakeHTML(resource_path('doc1.html')) sheets = list(find_stylesheets( html.wrapper_element, 'print', default_url_fetcher, html.base_url, font_config=None, counter_style=None, color_profiles=None, page_rules=None, layers=None)) assert len(sheets) == 2 # Also test that stylesheets are in tree order. sheet_names = [ sheet.base_url.rsplit('/', 1)[-1].rsplit(',', 1)[-1] for sheet in sheets] assert sheet_names == ['a%7Bcolor%3AcurrentColor%7D', 'doc1.html'] rules = [] for sheet in sheets: for sheet_rules in sheet.matcher.lower_local_name_selectors.values(): for rule in sheet_rules: rules.append(rule) for rule in sheet.page_rules: rules.append(rule) assert len(rules) == 10 # TODO: Test that the values are correct too. @assert_no_logs def test_annotate_document(): document = FakeHTML(resource_path('doc1.html')) document._ua_stylesheets = ( lambda *_, **__: [CSS(resource_path('mini_ua.css'))]) style_for = get_all_computed_styles( document, user_stylesheets=[CSS(resource_path('user.css'))]) # Element objects behave as lists of their children. _head, body = document.etree_element h1, p, ul, div = body li_0, _li_1 = ul a, = li_0 span1, = div span2, = span1 h1 = style_for(h1) p = style_for(p) ul = style_for(ul) li_0 = style_for(li_0) div = style_for(div) after = style_for(a, 'after') a = style_for(a) span1 = style_for(span1) span2 = style_for(span2) assert h1['background_image'] == ( ('url', path2url(resource_path('logo_small.png'))),) assert h1['font_weight'] == 700 assert h1['font_size'] == 40 # 2em # x-large * initial = 3/2 * 16 = 24 assert p['margin_top'] == (24, 'px') assert p['margin_right'] == (0, 'px') assert p['margin_bottom'] == (24, 'px') assert p['margin_left'] == (0, 'px') assert p['background_color'] == 'currentcolor' # 2em * 1.25ex = 2 * 20 * 1.25 * 0.8 = 40 # 2.5ex * 1.25ex = 2.5 * 0.8 * 20 * 1.25 * 0.8 = 40 # TODO: ex unit doesn't work with @font-face fonts, see computed_values.py # assert ul['margin_top'] == (40, 'px') # assert ul['margin_right'] == (40, 'px') # assert ul['margin_bottom'] == (40, 'px') # assert ul['margin_left'] == (40, 'px') assert ul['font_weight'] == 400 # thick = 5px, 0.25 inches = 96*.25 = 24px assert ul['border_top_width'] == 0 assert ul['border_right_width'] == 5 assert ul['border_bottom_width'] == 0 assert ul['border_left_width'] == 24 assert li_0['font_weight'] == 700 assert li_0['font_size'] == 8 # 6pt assert li_0['margin_top'] == (16, 'px') # 2em assert li_0['margin_right'] == (0, 'px') assert li_0['margin_bottom'] == (16, 'px') assert li_0['margin_left'] == (32, 'px') # 4em assert a['text_decoration_line'] == {'underline'} assert a['font_weight'] == 900 assert a['font_size'] == 24 # 300% of 8px assert a['padding_top'] == (1, 'px') assert a['padding_right'] == (2, 'px') assert a['padding_bottom'] == (3, 'px') assert a['padding_left'] == (4, 'px') assert a['border_top_width'] == 42 assert a['border_bottom_width'] == 42 assert a['color'] == (1, 0, 0, 1) assert a['border_top_color'] == 'currentcolor' assert div['font_size'] == 40 # 2 * 20px assert span1['width'] == (160, 'px') # 10 * 16px (root default is 16px) assert span1['height'] == (400, 'px') # 10 * (2 * 20px) assert span2['font_size'] == 32 # The href attr should be as in the source, not made absolute. assert after['content'] == ( ('string', ' ['), ('string', 'home.html'), ('string', ']')) assert after['background_color'] == (1, 0, 0, 1) assert after['border_top_width'] == 42 assert after['border_bottom_width'] == 3 # TODO: much more tests here: test that origin and selector precedence # and inheritance are correct… @assert_no_logs def test_important(): document = FakeHTML(string='''

''') page, = document.render(stylesheets=[CSS(string=''' body p:nth-child(1) { color: red } p:nth-child(2) { color: lime !important } p:nth-child(4) { color: lime !important } body p:nth-child(4) { color: red } ''')]).pages html, = page._page_box.children body, = html.children for paragraph in body.children: assert paragraph.style['color'] == (0, 1, 0, 1) # lime (light green) @assert_no_logs @pytest.mark.parametrize(('value', 'width'), [ ('96px', 96), ('1in', 96), ('72pt', 96), ('6pc', 96), ('2.54cm', 96), ('25.4mm', 96), ('101.6q', 96), ('1.1em', 11), ('1.1rem', 17.6), ('1.1ch', 11), ('1.1rch', 17.6), ('1.1cap', 11), ('1.1rcap', 17.6), ('1.5ex', 12), ('2rex', 25.6), ('1ic', 20), ('1ric', 32), ('1.1lh', 13.2), ('1.1rlh', 26.4), ]) def test_units(value, width): document = FakeHTML(base_url=BASE_URL, string='''

''' % (value, value.upper())) page, = document.render().pages html, = page._page_box.children body, = html.children p1, p2 = body.children assert p1.margin_left == p2.margin_left assert isclose(p1.margin_left, width, rel_tol=0.01) @assert_no_logs @pytest.mark.parametrize('property', ['line-height', 'font-size']) def test_recursive_lh(property): document = FakeHTML(base_url=BASE_URL, string=''' a''' % (property, property)) document.render().pages document = FakeHTML(base_url=BASE_URL, string=''' a''' % (property, property)) document.render().pages @pytest.mark.parametrize(('media', 'width', 'warning'), [ ('@media screen { @page { size: 10px } }', 20, False), ('@media print { @page { size: 10px } }', 10, False), ('@media ("unknown content") { @page { size: 10px } }', 20, True), ]) def test_media_queries(media, width, warning): document = FakeHTML(string='

ab') with capture_logs() as logs: page, = document.render( stylesheets=[CSS(string='@page{size:20px}%s' % media)]).pages html, = page._page_box.children assert html.width == width assert (logs if warning else not logs) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1764691876.1682634 weasyprint-67.0/tests/css/test_counters.py0000644000000000000000000004624315113607644016026 0ustar00"""Test CSS counters.""" import pytest from ..testing_utils import ( # isort:skip FakeHTML, assert_no_logs, assert_tree, parse_all, render_pages) RENDER = FakeHTML(string='')._ua_counter_style()[0].render_value @assert_no_logs def test_counters_1(): assert_tree(parse_all('''

'''), [ ('p', 'Block', [ ('p', 'Line', [ ('p::before', 'Inline', [ ('p::before', 'Text', counter)])])]) for counter in '0 1 3 2 4 6 -11 -9 -7 44 46 48'.split()]) @assert_no_logs def test_counters_2(): assert_tree(parse_all('''
'''), [ ('ol', 'Block', [ ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '1. ')])])]), ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '2. ')])])]), ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '3. ')])])]), ('li', 'Block', [ ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '4. ')])])]), ('ol', 'Block', [ ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '1. ')])])]), ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '1. ')])])]), ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '2. ')])])])])]), ('li', 'Block', [ ('li', 'Line', [ ('li::marker', 'Inline', [ ('li::marker', 'Text', '5. ')])])])])]) @assert_no_logs def test_counters_3(): assert_tree(parse_all('''

'''), [ ('div', 'Block', [ ('p', 'Block', [ ('p', 'Line', [ ('p::marker', 'Inline', [ ('p::marker', 'Text', '1. ')])])]), ('p', 'Block', [ ('p', 'Line', [ ('p::marker', 'Inline', [ ('p::marker', 'Text', '2. ')])])]), ('p', 'Block', [ ('p', 'Line', [ ('p::marker', 'Inline', [ ('p::marker', 'Text', '-55. ')])])])]), ('p', 'Block', [ ('p', 'Line', [ ('p::marker', 'Inline', [ ('p::marker', 'Text', '1. ')])])])]) @assert_no_logs def test_counters_4(): assert_tree(parse_all('''

'''), [ ('section', 'Block', [ ('section', 'Block', [ ('section', 'Line', [ ('section::before', 'Inline', [])])]), ('h1', 'Block', [ ('h1', 'Line', [ ('h1::before', 'Inline', [ ('h1::before', 'Text', '1')])])]), ('h1', 'Block', [ ('h1', 'Line', [ ('h1::before', 'Inline', [ ('h1::before', 'Text', '2')])])]), ('section', 'Block', [ ('section', 'Block', [ ('section', 'Line', [ ('section::before', 'Inline', [])])]), ('h1', 'Block', [ ('h1', 'Line', [ ('h1::before', 'Inline', [ ('h1::before', 'Text', '2.1')])])]), ('h1', 'Block', [ ('h1', 'Line', [ ('h1::before', 'Inline', [ ('h1::before', 'Text', '2.2')])])])]), ('h1', 'Block', [ ('h1', 'Line', [ ('h1::before', 'Inline', [ ('h1::before', 'Text', '3')])])])])]) @assert_no_logs def test_counters_5(): assert_tree(parse_all('''
Scope created now, deleted after the div

'''), [ ('div', 'Block', [ ('div', 'Line', [ ('span', 'Inline', [ ('span', 'Text', 'Scope created now, deleted after the div ')])])]), ('p', 'Block', [ ('p', 'Line', [ ('p::before', 'Inline', [ ('p::before', 'Text', '0')])])])]) @assert_no_logs def test_counters_6(): # counter-increment may interfere with display: list-item assert_tree(parse_all('''

'''), [ ('p', 'Block', [ ('p', 'Line', [ ('p::marker', 'Inline', [ ('p::marker', 'Text', '0. ')])])])]) @assert_no_logs def test_counters_7(): # Regression test for #827. # Test that counters are case-sensitive. assert_tree(parse_all('''

'''), [ ('p', 'Block', [ ('p', 'Line', [ ('p::before', 'Inline', [ ('p::before', 'Text', counter)])])]) for counter in '2.0 2.3 4.3'.split()]) @assert_no_logs def test_counters_8(): assert_tree(parse_all('''

'''), 2 * [ ('p', 'Block', [ ('p::before', 'Block', [ ('p::marker', 'Block', [ ('p::marker', 'Line', [ ('p::marker', 'Text', '• ')])]), ('p::before', 'Block', [ ('p::before', 'Line', [ ('p::before', 'Text', 'a')])])])])]) @pytest.mark.xfail @assert_no_logs def test_counters_9(): page, = render_pages('''
''') html, = page._page_box.children body, = html.children ol1, = body.children oli1, oli2, oli3 = ol1.children marker, ol2 = oli2.children oli21, oli22 = ol2.children assert oli1.children[0].children[0].children[0].text == '1. ' assert oli2.children[0].children[0].children[0].text == '2. ' assert oli21.children[0].children[0].children[0].text == '1. ' assert oli22.children[0].children[0].children[0].text == '2. ' assert oli3.children[0].children[0].children[0].text == '3. ' @assert_no_logs def test_counter_styles_1(): assert_tree(parse_all('''

'''), [ ('p', 'Block', [ ('p', 'Line', [ ('p::before', 'Inline', [ ('p::before', 'Text', counter)])])]) for counter in '-- • ◦ ▪ -7 Counter:-6 -5:Counter'.split()]) @assert_no_logs def test_counter_styles_2(): assert_tree(parse_all('''

'''), [ ('p', 'Block', [ ('p', 'Line', [ ('p::before', 'Inline', [ ('p::before', 'Text', counter)])])]) for counter in '''-1986 -1985 -11 -10 -9 -8 -1 00 01 02 09 10 11 99 100 101 4135 4136'''.split()]) @assert_no_logs def test_counter_styles_3(): assert [RENDER(value, 'decimal-leading-zero') for value in [ -1986, -1985, -11, -10, -9, -8, -1, 0, 1, 2, 9, 10, 11, 99, 100, 101, 4135, 4136 ]] == ''' -1986 -1985 -11 -10 -9 -8 -1 00 01 02 09 10 11 99 100 101 4135 4136 '''.split() @assert_no_logs def test_counter_styles_4(): assert [RENDER(value, 'lower-roman') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 49, 50, 389, 390, 3489, 3490, 3491, 4999, 5000, 5001 ]] == ''' -1986 -1985 -1 0 i ii iii iv v vi vii viii ix x xi xii xlix l ccclxxxix cccxc mmmcdlxxxix mmmcdxc mmmcdxci 4999 5000 5001 '''.split() @assert_no_logs def test_counter_styles_5(): assert [RENDER(value, 'upper-roman') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 49, 50, 389, 390, 3489, 3490, 3491, 4999, 5000, 5001 ]] == ''' -1986 -1985 -1 0 I II III IV V VI VII VIII IX X XI XII XLIX L CCCLXXXIX CCCXC MMMCDLXXXIX MMMCDXC MMMCDXCI 4999 5000 5001 '''.split() @assert_no_logs def test_counter_styles_6(): assert [RENDER(value, 'lower-alpha') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 25, 26, 27, 28, 29, 2002, 2003 ]] == ''' -1986 -1985 -1 0 a b c d y z aa ab ac bxz bya '''.split() @assert_no_logs def test_counter_styles_7(): assert [RENDER(value, 'upper-alpha') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 25, 26, 27, 28, 29, 2002, 2003 ]] == ''' -1986 -1985 -1 0 A B C D Y Z AA AB AC BXZ BYA '''.split() @assert_no_logs def test_counter_styles_8(): assert [RENDER(value, 'lower-latin') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 25, 26, 27, 28, 29, 2002, 2003 ]] == ''' -1986 -1985 -1 0 a b c d y z aa ab ac bxz bya '''.split() @assert_no_logs def test_counter_styles_9(): assert [RENDER(value, 'upper-latin') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 25, 26, 27, 28, 29, 2002, 2003 ]] == ''' -1986 -1985 -1 0 A B C D Y Z AA AB AC BXZ BYA '''.split() @assert_no_logs def test_counter_styles_10(): assert [RENDER(value, 'georgian') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 19999, 20000, 20001 ]] == ''' -1986 -1985 -1 0 ა ბ გ დ ე ვ ზ ჱ თ ი ია იბ კ ლ მ ნ ჲ ო პ ჟ რ ს ტ ჳ ფ ქ ღ ყ შ ჩ ც ძ წ ჭ ხ ჴ ჯ ჰ ჵ ჵჰშჟთ 20000 20001 '''.split() @assert_no_logs def test_counter_styles_11(): assert [RENDER(value, 'armenian') for value in [ -1986, -1985, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 9999, 10000, 10001 ]] == ''' -1986 -1985 -1 0 Ա Բ Գ Դ Ե Զ Է Ը Թ Ժ ԺԱ ԺԲ Ի Լ Խ Ծ Կ Հ Ձ Ղ Ճ Մ Յ Ն Շ Ո Չ Պ Ջ Ռ Ս Վ Տ Ր Ց Ւ Փ Ք ՔՋՂԹ 10000 10001 '''.split() @assert_no_logs @pytest.mark.parametrize(('arguments', 'values'), [ ('cyclic "a" "b" "c"', ('a ', 'b ', 'c ', 'a ')), ('symbolic "a" "b"', ('a ', 'b ', 'aa ', 'bb ')), ('"a" "b"', ('a ', 'b ', 'aa ', 'bb ')), ('alphabetic "a" "b"', ('a ', 'b ', 'aa ', 'ab ')), ('fixed "a" "b"', ('a ', 'b ', '3 ', '4 ')), ('numeric "0" "1" "2"', ('1 ', '2 ', '10 ', '11 ')), ]) def test_counter_symbols(arguments, values): page, = render_pages('''
  1. abc
  2. abc
  3. abc
  4. abc
''' % arguments) html, = page.children body, = html.children ol, = body.children li_1, li_2, li_3, li_4 = ol.children assert li_1.children[0].children[0].children[0].text == values[0] assert li_2.children[0].children[0].children[0].text == values[1] assert li_3.children[0].children[0].children[0].text == values[2] assert li_4.children[0].children[0].children[0].text == values[3] @assert_no_logs @pytest.mark.parametrize(('style_type', 'values'), [ ('decimal', ('1. ', '2. ', '3. ', '4. ')), ('"/"', ('/', '/', '/', '/')), ]) def test_list_style_types(style_type, values): page, = render_pages('''
  1. abc
  2. abc
  3. abc
  4. abc
''' % style_type) html, = page.children body, = html.children ol, = body.children li_1, li_2, li_3, li_4 = ol.children assert li_1.children[0].children[0].children[0].text == values[0] assert li_2.children[0].children[0].children[0].text == values[1] assert li_3.children[0].children[0].children[0].text == values[2] assert li_4.children[0].children[0].children[0].text == values[3] def test_list_style_type_empty_string(): # Regression test for #1883. render_pages('