xhtml2pdf 0.2.24__tar.gz → 0.2.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xhtml2pdf-0.2.24/xhtml2pdf.egg-info → xhtml2pdf-0.2.26}/PKG-INFO +14 -211
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/README.rst +6 -3
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/pyproject.toml +15 -6
- xhtml2pdf-0.2.26/tests/test_block_margins.py +88 -0
- xhtml2pdf-0.2.26/tests/test_block_width.py +86 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_flex.py +5 -1
- xhtml2pdf-0.2.26/tests/test_font_isolation.py +90 -0
- xhtml2pdf-0.2.26/tests/test_frame_align.py +68 -0
- xhtml2pdf-0.2.26/tests/test_frame_pages.py +62 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_inline_box.py +20 -2
- xhtml2pdf-0.2.26/tests/test_optional_dependencies.py +85 -0
- xhtml2pdf-0.2.26/tests/test_page_numbering.py +113 -0
- xhtml2pdf-0.2.26/tests/test_page_padding.py +79 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_reportlab_api.py +2 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_tags.py +183 -1
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/__init__.py +1 -1
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/block.py +219 -9
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/flex.py +9 -4
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/charts.py +118 -25
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/context.py +110 -47
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/default.py +1 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/document.py +85 -60
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/paragraph.py +3 -1
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/parser.py +70 -6
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/properties.py +5 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/reportlab_paragraph.py +20 -3
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/tables.py +6 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/tags.py +32 -3
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/xhtml2pdf_reportlab.py +102 -7
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26/xhtml2pdf.egg-info}/PKG-INFO +14 -211
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf.egg-info/SOURCES.txt +8 -1
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf.egg-info/requires.txt +8 -2
- xhtml2pdf-0.2.24/AUTHORS.rst +0 -60
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/LICENSE.txt +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/MANIFEST.in +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/setup.cfg +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_asian_font_support.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_bidi.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_block_box.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_cli.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_css_media_rule.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_css_parser.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_css_variables.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_document.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_files.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_flex_flowable.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_flex_layout.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_fonts.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_http.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_inline_block.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_paragraph.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_paragraph_height.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_parser.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_pdf.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_position.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_reportlab.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_reportlab_paragraph.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_resource_policy.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_right_to_left_font_support.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_security_limits.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_selectors.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_signatures.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_special_css.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_table_border_radius.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_table_css.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_tables.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_update_face_name.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_utils.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_watermarks.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_word_breaking.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/tests/test_wsgi.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/__main__.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/_bidi_data.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/bidi.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/__init__.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/flex_layout.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/position.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/signs.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/builders/watermarks.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/config/__init__.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/config/httpconfig.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/config/resources.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/files.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/pdf.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/pisa.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/util.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/__init__.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/css.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/cssDOMElementInterface.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/cssParser.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/cssSpecial.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/w3c/css_variables.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf/wsgi.py +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf.egg-info/dependency_links.txt +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf.egg-info/entry_points.txt +0 -0
- {xhtml2pdf-0.2.24 → xhtml2pdf-0.2.26}/xhtml2pdf.egg-info/top_level.txt +0 -0
|
@@ -1,218 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xhtml2pdf
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.26
|
|
4
4
|
Summary: PDF generator using HTML and CSS
|
|
5
5
|
Author-email: Dirk Holtwick <dirk.holtwick@gmail.com>
|
|
6
6
|
Maintainer-email: Luis Zarate <luisza14@gmail.com>, Timo Brembeck <opensource@timo.brembeck.email>
|
|
7
|
-
License:
|
|
8
|
-
Apache License
|
|
9
|
-
Version 2.0, January 2004
|
|
10
|
-
http://www.apache.org/licenses/
|
|
11
|
-
|
|
12
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
13
|
-
|
|
14
|
-
1. Definitions.
|
|
15
|
-
|
|
16
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
17
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
18
|
-
|
|
19
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
20
|
-
the copyright owner that is granting the License.
|
|
21
|
-
|
|
22
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
23
|
-
other entities that control, are controlled by, or are under common
|
|
24
|
-
control with that entity. For the purposes of this definition,
|
|
25
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
26
|
-
direction or management of such entity, whether by contract or
|
|
27
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
28
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
29
|
-
|
|
30
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
31
|
-
exercising permissions granted by this License.
|
|
32
|
-
|
|
33
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
34
|
-
including but not limited to software source code, documentation
|
|
35
|
-
source, and configuration files.
|
|
36
|
-
|
|
37
|
-
"Object" form shall mean any form resulting from mechanical
|
|
38
|
-
transformation or translation of a Source form, including but
|
|
39
|
-
not limited to compiled object code, generated documentation,
|
|
40
|
-
and conversions to other media types.
|
|
41
|
-
|
|
42
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
43
|
-
Object form, made available under the License, as indicated by a
|
|
44
|
-
copyright notice that is included in or attached to the work
|
|
45
|
-
(an example is provided in the Appendix below).
|
|
46
|
-
|
|
47
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
48
|
-
form, that is based on (or derived from) the Work and for which the
|
|
49
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
50
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
51
|
-
of this License, Derivative Works shall not include works that remain
|
|
52
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
53
|
-
the Work and Derivative Works thereof.
|
|
54
|
-
|
|
55
|
-
"Contribution" shall mean any work of authorship, including
|
|
56
|
-
the original version of the Work and any modifications or additions
|
|
57
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
58
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
59
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
60
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
61
|
-
means any form of electronic, verbal, or written communication sent
|
|
62
|
-
to the Licensor or its representatives, including but not limited to
|
|
63
|
-
communication on electronic mailing lists, source code control systems,
|
|
64
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
65
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
66
|
-
excluding communication that is conspicuously marked or otherwise
|
|
67
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
68
|
-
|
|
69
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
70
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
71
|
-
subsequently incorporated within the Work.
|
|
72
|
-
|
|
73
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
77
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
78
|
-
Work and such Derivative Works in Source or Object form.
|
|
79
|
-
|
|
80
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
81
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
-
(except as stated in this section) patent license to make, have made,
|
|
84
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
85
|
-
where such license applies only to those patent claims licensable
|
|
86
|
-
by such Contributor that are necessarily infringed by their
|
|
87
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
88
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
89
|
-
institute patent litigation against any entity (including a
|
|
90
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
91
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
92
|
-
or contributory patent infringement, then any patent licenses
|
|
93
|
-
granted to You under this License for that Work shall terminate
|
|
94
|
-
as of the date such litigation is filed.
|
|
95
|
-
|
|
96
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
97
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
98
|
-
modifications, and in Source or Object form, provided that You
|
|
99
|
-
meet the following conditions:
|
|
100
|
-
|
|
101
|
-
(a) You must give any other recipients of the Work or
|
|
102
|
-
Derivative Works a copy of this License; and
|
|
103
|
-
|
|
104
|
-
(b) You must cause any modified files to carry prominent notices
|
|
105
|
-
stating that You changed the files; and
|
|
106
|
-
|
|
107
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
108
|
-
that You distribute, all copyright, patent, trademark, and
|
|
109
|
-
attribution notices from the Source form of the Work,
|
|
110
|
-
excluding those notices that do not pertain to any part of
|
|
111
|
-
the Derivative Works; and
|
|
112
|
-
|
|
113
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
114
|
-
distribution, then any Derivative Works that You distribute must
|
|
115
|
-
include a readable copy of the attribution notices contained
|
|
116
|
-
within such NOTICE file, excluding those notices that do not
|
|
117
|
-
pertain to any part of the Derivative Works, in at least one
|
|
118
|
-
of the following places: within a NOTICE text file distributed
|
|
119
|
-
as part of the Derivative Works; within the Source form or
|
|
120
|
-
documentation, if provided along with the Derivative Works; or,
|
|
121
|
-
within a display generated by the Derivative Works, if and
|
|
122
|
-
wherever such third-party notices normally appear. The contents
|
|
123
|
-
of the NOTICE file are for informational purposes only and
|
|
124
|
-
do not modify the License. You may add Your own attribution
|
|
125
|
-
notices within Derivative Works that You distribute, alongside
|
|
126
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
127
|
-
that such additional attribution notices cannot be construed
|
|
128
|
-
as modifying the License.
|
|
129
|
-
|
|
130
|
-
You may add Your own copyright statement to Your modifications and
|
|
131
|
-
may provide additional or different license terms and conditions
|
|
132
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
133
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
134
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
135
|
-
the conditions stated in this License.
|
|
136
|
-
|
|
137
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
138
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
139
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
140
|
-
this License, without any additional terms or conditions.
|
|
141
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
142
|
-
the terms of any separate license agreement you may have executed
|
|
143
|
-
with Licensor regarding such Contributions.
|
|
144
|
-
|
|
145
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
146
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
147
|
-
except as required for reasonable and customary use in describing the
|
|
148
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
149
|
-
|
|
150
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
151
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
152
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
153
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
154
|
-
implied, including, without limitation, any warranties or conditions
|
|
155
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
156
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
157
|
-
appropriateness of using or redistributing the Work and assume any
|
|
158
|
-
risks associated with Your exercise of permissions under this License.
|
|
159
|
-
|
|
160
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
161
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
162
|
-
unless required by applicable law (such as deliberate and grossly
|
|
163
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
164
|
-
liable to You for damages, including any direct, indirect, special,
|
|
165
|
-
incidental, or consequential damages of any character arising as a
|
|
166
|
-
result of this License or out of the use or inability to use the
|
|
167
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
168
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
169
|
-
other commercial damages or losses), even if such Contributor
|
|
170
|
-
has been advised of the possibility of such damages.
|
|
171
|
-
|
|
172
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
173
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
174
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
175
|
-
or other liability obligations and/or rights consistent with this
|
|
176
|
-
License. However, in accepting such obligations, You may act only
|
|
177
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
178
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
179
|
-
defend, and hold each Contributor harmless for any liability
|
|
180
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
181
|
-
of your accepting any such warranty or additional liability.
|
|
182
|
-
|
|
183
|
-
END OF TERMS AND CONDITIONS
|
|
184
|
-
|
|
185
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
186
|
-
|
|
187
|
-
To apply the Apache License to your work, attach the following
|
|
188
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
189
|
-
replaced with your own identifying information. (Don't include
|
|
190
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
191
|
-
comment syntax for the file format. We also recommend that a
|
|
192
|
-
file or class name and description of purpose be included on the
|
|
193
|
-
same "printed page" as the copyright notice for easier
|
|
194
|
-
identification within third-party archives.
|
|
195
|
-
|
|
196
|
-
Copyright [yyyy] [name of copyright owner]
|
|
197
|
-
|
|
198
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
199
|
-
you may not use this file except in compliance with the License.
|
|
200
|
-
You may obtain a copy of the License at
|
|
201
|
-
|
|
202
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
203
|
-
|
|
204
|
-
Unless required by applicable law or agreed to in writing, software
|
|
205
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
206
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
207
|
-
See the License for the specific language governing permissions and
|
|
208
|
-
limitations under the License.
|
|
209
|
-
|
|
7
|
+
License-Expression: Apache-2.0
|
|
210
8
|
Project-URL: Repository, https://github.com/xhtml2pdf/xhtml2pdf
|
|
211
9
|
Project-URL: Bug tracker, https://github.com/xhtml2pdf/xhtml2pdf/issues
|
|
212
10
|
Project-URL: Documentation, https://xhtml2pdf.readthedocs.io/
|
|
213
11
|
Project-URL: Changelog, https://xhtml2pdf.readthedocs.io/en/latest/release-notes.html
|
|
214
12
|
Keywords: PDF,HTML,HTML,XML,CSS
|
|
215
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
216
13
|
Classifier: Development Status :: 4 - Beta
|
|
217
14
|
Classifier: Environment :: Console
|
|
218
15
|
Classifier: Environment :: Other Environment
|
|
@@ -242,20 +39,23 @@ Classifier: Topic :: Utilities
|
|
|
242
39
|
Requires-Python: >=3.10
|
|
243
40
|
Description-Content-Type: text/x-rst
|
|
244
41
|
License-File: LICENSE.txt
|
|
245
|
-
License-File: AUTHORS.rst
|
|
246
42
|
Requires-Dist: arabic-reshaper>=3.0.0
|
|
247
43
|
Requires-Dist: html5lib>=1.1
|
|
248
44
|
Requires-Dist: Pillow>=8.1.1
|
|
249
|
-
Requires-Dist: pyHanko>=0.37.0
|
|
250
|
-
Requires-Dist: pyhanko-certvalidator>=0.32.1
|
|
251
45
|
Requires-Dist: pypdf>=3.1.0
|
|
252
46
|
Requires-Dist: reportlab<6,>=4.4.9
|
|
253
47
|
Requires-Dist: svglib>=1.2.1
|
|
48
|
+
Provides-Extra: signing
|
|
49
|
+
Requires-Dist: pyHanko>=0.37.0; extra == "signing"
|
|
50
|
+
Requires-Dist: pyhanko-certvalidator>=0.32.1; extra == "signing"
|
|
51
|
+
Provides-Extra: all
|
|
52
|
+
Requires-Dist: xhtml2pdf[signing]; extra == "all"
|
|
254
53
|
Provides-Extra: pycairo
|
|
255
54
|
Requires-Dist: reportlab[pycairo]<6,>=4.4.9; extra == "pycairo"
|
|
256
55
|
Provides-Extra: renderpm
|
|
257
56
|
Requires-Dist: xhtml2pdf[pycairo]; extra == "renderpm"
|
|
258
57
|
Provides-Extra: test
|
|
58
|
+
Requires-Dist: xhtml2pdf[signing]; extra == "test"
|
|
259
59
|
Requires-Dist: tomli>=2.0.1; python_version < "3.11" and extra == "test"
|
|
260
60
|
Requires-Dist: tox; extra == "test"
|
|
261
61
|
Requires-Dist: coverage>=5.3; extra == "test"
|
|
@@ -360,7 +160,7 @@ Quick start
|
|
|
360
160
|
|
|
361
161
|
.. code:: bash
|
|
362
162
|
|
|
363
|
-
pip install xhtml2pdf
|
|
163
|
+
pip install xhtml2pdf[all]
|
|
364
164
|
|
|
365
165
|
.. code:: python
|
|
366
166
|
|
|
@@ -462,10 +262,13 @@ Installation
|
|
|
462
262
|
|
|
463
263
|
.. code:: bash
|
|
464
264
|
|
|
465
|
-
pip install xhtml2pdf
|
|
265
|
+
pip install xhtml2pdf[all]
|
|
466
266
|
|
|
467
267
|
Python 3.10 and newer is tested and supported. Every mandatory requirement is
|
|
468
|
-
listed in ``pyproject.toml`` and installed with xhtml2pdf
|
|
268
|
+
listed in ``pyproject.toml`` and installed with xhtml2pdf; ``all`` adds the
|
|
269
|
+
optional ones: pyHanko, for digital signatures, which is also the
|
|
270
|
+
``signing`` extra on its own. ``pip install xhtml2pdf`` leaves it out:
|
|
271
|
+
asking for a signature then raises an ``ImportError`` that names the extra.
|
|
469
272
|
|
|
470
273
|
ReportLab needs a rendering backend to turn vector graphics into bitmaps (for
|
|
471
274
|
charts and SVG rasterised into the page). The supported one is `cairo
|
|
@@ -86,7 +86,7 @@ Quick start
|
|
|
86
86
|
|
|
87
87
|
.. code:: bash
|
|
88
88
|
|
|
89
|
-
pip install xhtml2pdf
|
|
89
|
+
pip install xhtml2pdf[all]
|
|
90
90
|
|
|
91
91
|
.. code:: python
|
|
92
92
|
|
|
@@ -188,10 +188,13 @@ Installation
|
|
|
188
188
|
|
|
189
189
|
.. code:: bash
|
|
190
190
|
|
|
191
|
-
pip install xhtml2pdf
|
|
191
|
+
pip install xhtml2pdf[all]
|
|
192
192
|
|
|
193
193
|
Python 3.10 and newer is tested and supported. Every mandatory requirement is
|
|
194
|
-
listed in ``pyproject.toml`` and installed with xhtml2pdf
|
|
194
|
+
listed in ``pyproject.toml`` and installed with xhtml2pdf; ``all`` adds the
|
|
195
|
+
optional ones: pyHanko, for digital signatures, which is also the
|
|
196
|
+
``signing`` extra on its own. ``pip install xhtml2pdf`` leaves it out:
|
|
197
|
+
asking for a signature then raises an ``ImportError`` that names the extra.
|
|
195
198
|
|
|
196
199
|
ReportLab needs a rendering backend to turn vector graphics into bitmaps (for
|
|
197
200
|
charts and SVG rasterised into the page). The supported one is `cairo
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools"]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
|
|
@@ -15,9 +15,9 @@ maintainers = [
|
|
|
15
15
|
description = "PDF generator using HTML and CSS"
|
|
16
16
|
keywords = ["PDF", "HTML", "HTML", "XML", "CSS"]
|
|
17
17
|
readme = "README.rst"
|
|
18
|
-
license =
|
|
18
|
+
license = "Apache-2.0"
|
|
19
|
+
license-files = ["LICENSE.txt"]
|
|
19
20
|
classifiers = [
|
|
20
|
-
"License :: OSI Approved :: Apache Software License",
|
|
21
21
|
"Development Status :: 4 - Beta",
|
|
22
22
|
"Environment :: Console",
|
|
23
23
|
"Environment :: Other Environment",
|
|
@@ -50,11 +50,9 @@ dependencies = [
|
|
|
50
50
|
"arabic-reshaper>=3.0.0",
|
|
51
51
|
"html5lib>=1.1",
|
|
52
52
|
"Pillow>=8.1.1",
|
|
53
|
-
"pyHanko>=0.37.0",
|
|
54
|
-
"pyhanko-certvalidator>=0.32.1",
|
|
55
53
|
"pypdf>=3.1.0",
|
|
56
54
|
"reportlab>=4.4.9,<6",
|
|
57
|
-
"svglib>=1.2.1"
|
|
55
|
+
"svglib>=1.2.1",
|
|
58
56
|
]
|
|
59
57
|
dynamic = ["version"]
|
|
60
58
|
|
|
@@ -65,6 +63,15 @@ Documentation = "https://xhtml2pdf.readthedocs.io/"
|
|
|
65
63
|
Changelog = "https://xhtml2pdf.readthedocs.io/en/latest/release-notes.html"
|
|
66
64
|
|
|
67
65
|
[project.optional-dependencies]
|
|
66
|
+
# Digital signatures (the `signature` argument and the CLI's signing options).
|
|
67
|
+
signing = [
|
|
68
|
+
"pyHanko>=0.37.0",
|
|
69
|
+
"pyhanko-certvalidator>=0.32.1",
|
|
70
|
+
]
|
|
71
|
+
# Every optional feature that needs nothing outside Python.
|
|
72
|
+
all = [
|
|
73
|
+
"xhtml2pdf[signing]",
|
|
74
|
+
]
|
|
68
75
|
pycairo = [
|
|
69
76
|
"reportlab[pycairo]>=4.4.9,<6",
|
|
70
77
|
]
|
|
@@ -76,6 +83,7 @@ renderpm = [
|
|
|
76
83
|
"xhtml2pdf[pycairo]",
|
|
77
84
|
]
|
|
78
85
|
test = [
|
|
86
|
+
"xhtml2pdf[signing]",
|
|
79
87
|
"tomli>=2.0.1; python_version<'3.11'",
|
|
80
88
|
"tox",
|
|
81
89
|
"coverage>=5.3"
|
|
@@ -115,6 +123,7 @@ legacy_tox_ini = """
|
|
|
115
123
|
envlist = py{3.10,3.11,3.12,3.13,3.14}-rl{4,5}, py3.10-rlmin
|
|
116
124
|
|
|
117
125
|
[testenv]
|
|
126
|
+
extras = signing
|
|
118
127
|
deps =
|
|
119
128
|
coverage[toml]
|
|
120
129
|
rl4: reportlab>=4.4.9,<5
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The vertical margins of a block without padding, a border or a background.
|
|
3
|
+
|
|
4
|
+
Such a block draws nothing of its own: its top margin goes above the first
|
|
5
|
+
thing it holds and its bottom margin below the last, each collapsing with
|
|
6
|
+
the margin of that child and of the blocks around it, the larger one
|
|
7
|
+
winning (CSS 2.1, 8.3.1).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from io import BytesIO
|
|
11
|
+
from unittest import TestCase
|
|
12
|
+
|
|
13
|
+
from pypdf import PdfReader
|
|
14
|
+
|
|
15
|
+
from xhtml2pdf import pisa
|
|
16
|
+
|
|
17
|
+
#: Every line is this tall, so a gap between two baselines minus it is the
|
|
18
|
+
#: margin between their blocks.
|
|
19
|
+
LINE = 15.0
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def baselines(body: str) -> dict[str, float]:
|
|
23
|
+
"""The baseline of each run of text, by its text, down from the top."""
|
|
24
|
+
html = (
|
|
25
|
+
"<html><head><style>body { font-size: 11pt; line-height: 15pt }"
|
|
26
|
+
" p { margin: 0 }</style></head><body>" + body + "</body></html>"
|
|
27
|
+
)
|
|
28
|
+
output = BytesIO()
|
|
29
|
+
result = pisa.CreatePDF(html, dest=output)
|
|
30
|
+
assert not result.err
|
|
31
|
+
found: dict[str, float] = {}
|
|
32
|
+
|
|
33
|
+
def visit(text, cm, tm, _font, _size) -> None:
|
|
34
|
+
if text.strip():
|
|
35
|
+
found[text.strip()] = -(tm[4] * cm[1] + tm[5] * cm[3] + cm[5])
|
|
36
|
+
|
|
37
|
+
PdfReader(BytesIO(output.getvalue())).pages[0].extract_text(visitor_text=visit)
|
|
38
|
+
return found
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class BlockMarginTest(TestCase):
|
|
42
|
+
@staticmethod
|
|
43
|
+
def gap(lines: dict[str, float], above: str, below: str) -> float:
|
|
44
|
+
return round(lines[below] - lines[above] - LINE, 1)
|
|
45
|
+
|
|
46
|
+
def test_the_margins_of_a_block_around_a_paragraph_without_margins(self) -> None:
|
|
47
|
+
lines = baselines(
|
|
48
|
+
"<div style='margin-bottom: 1in'><p>first</p></div>"
|
|
49
|
+
"<p>second</p>"
|
|
50
|
+
"<div style='margin-top: 1in'><p>third</p></div>"
|
|
51
|
+
)
|
|
52
|
+
self.assertEqual(72, self.gap(lines, "first", "second"))
|
|
53
|
+
self.assertEqual(72, self.gap(lines, "second", "third"))
|
|
54
|
+
|
|
55
|
+
def test_nested_top_margins_collapse_to_the_largest(self) -> None:
|
|
56
|
+
lines = baselines(
|
|
57
|
+
"<p>before</p>"
|
|
58
|
+
"<div style='margin-top: 20pt'><div style='margin-top: 10pt'>"
|
|
59
|
+
"<p style='margin-top: 5pt'>inside</p></div></div>"
|
|
60
|
+
)
|
|
61
|
+
self.assertEqual(20, self.gap(lines, "before", "inside"))
|
|
62
|
+
|
|
63
|
+
def test_a_last_child_margin_larger_than_its_block_wins(self) -> None:
|
|
64
|
+
lines = baselines(
|
|
65
|
+
"<div style='margin-bottom: 30pt'><p style='margin-bottom: 40pt'>last</p>"
|
|
66
|
+
"</div><p>after</p>"
|
|
67
|
+
)
|
|
68
|
+
self.assertEqual(40, self.gap(lines, "last", "after"))
|
|
69
|
+
|
|
70
|
+
def test_the_text_of_a_block_takes_its_margins_once(self) -> None:
|
|
71
|
+
lines = baselines(
|
|
72
|
+
"<p>start</p>"
|
|
73
|
+
"<div style='margin: 30pt 0 40pt 0'>leading"
|
|
74
|
+
"<p style='margin: 5pt 0'>inner</p>trailing</div>"
|
|
75
|
+
"<p>end</p>"
|
|
76
|
+
)
|
|
77
|
+
self.assertEqual(30, self.gap(lines, "start", "leading"))
|
|
78
|
+
self.assertEqual(5, self.gap(lines, "leading", "inner"))
|
|
79
|
+
self.assertEqual(5, self.gap(lines, "inner", "trailing"))
|
|
80
|
+
self.assertEqual(40, self.gap(lines, "trailing", "end"))
|
|
81
|
+
|
|
82
|
+
def test_a_child_does_not_inherit_the_margins_of_its_block(self) -> None:
|
|
83
|
+
lines = baselines(
|
|
84
|
+
"<div style='margin-bottom: 20pt'><div><p>one</p></div>"
|
|
85
|
+
"<div><p>two</p></div></div><p>after</p>"
|
|
86
|
+
)
|
|
87
|
+
self.assertEqual(0, self.gap(lines, "one", "two"))
|
|
88
|
+
self.assertEqual(20, self.gap(lines, "two", "after"))
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The CSS width of a <div>, a <p> or any other block.
|
|
3
|
+
|
|
4
|
+
It is the width of the block's content box, a length or a share of the
|
|
5
|
+
block that contains it. An auto margin takes what the box leaves of the
|
|
6
|
+
line, so margin: 0 auto centres the block.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from io import BytesIO
|
|
10
|
+
from unittest import TestCase
|
|
11
|
+
|
|
12
|
+
from pypdf import PdfReader
|
|
13
|
+
from reportlab.pdfgen.canvas import Canvas
|
|
14
|
+
|
|
15
|
+
from xhtml2pdf import pisa
|
|
16
|
+
from xhtml2pdf.builders.block import BlockBox
|
|
17
|
+
from xhtml2pdf.document import pisaStory
|
|
18
|
+
|
|
19
|
+
AVAIL = 500.0
|
|
20
|
+
TEXT = " ".join(f"word{n}" for n in range(60))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def box(html: str) -> BlockBox:
|
|
24
|
+
"""The block box the HTML makes, laid out AVAIL points wide."""
|
|
25
|
+
context = pisaStory(html)
|
|
26
|
+
assert context.err == 0
|
|
27
|
+
(found,) = [f for f in context.story if isinstance(f, BlockBox)]
|
|
28
|
+
found.wrapOn(Canvas(BytesIO()), AVAIL, 10000)
|
|
29
|
+
return found
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class BlockWidthTest(TestCase):
|
|
33
|
+
def test_a_percentage_of_the_containing_block(self) -> None:
|
|
34
|
+
found = box(f"<div style='width: 50%'>{TEXT}</div>")
|
|
35
|
+
self.assertAlmostEqual(250, found._inner)
|
|
36
|
+
self.assertAlmostEqual(0, found._left)
|
|
37
|
+
|
|
38
|
+
def test_a_length(self) -> None:
|
|
39
|
+
found = box(f"<p style='width: 200pt'>{TEXT}</p>")
|
|
40
|
+
self.assertAlmostEqual(200, found._inner)
|
|
41
|
+
|
|
42
|
+
def test_the_width_is_the_content_box(self) -> None:
|
|
43
|
+
found = box(
|
|
44
|
+
f"<div style='width: 200pt; padding: 10pt; border: 2pt solid'>{TEXT}</div>"
|
|
45
|
+
)
|
|
46
|
+
self.assertAlmostEqual(200, found._inner)
|
|
47
|
+
self.assertAlmostEqual(AVAIL - 224, found._right)
|
|
48
|
+
|
|
49
|
+
def test_auto_margins_centre_it(self) -> None:
|
|
50
|
+
found = box(f"<div style='width: 300pt; margin: 0 auto'>{TEXT}</div>")
|
|
51
|
+
self.assertAlmostEqual(100, found._left)
|
|
52
|
+
self.assertAlmostEqual(100, found._right)
|
|
53
|
+
|
|
54
|
+
def test_an_auto_left_margin_puts_it_on_the_right(self) -> None:
|
|
55
|
+
found = box(f"<div style='width: 300pt; margin-left: auto'>{TEXT}</div>")
|
|
56
|
+
self.assertAlmostEqual(200, found._left)
|
|
57
|
+
|
|
58
|
+
def test_a_percentage_is_of_the_block_not_of_what_its_margin_leaves(self) -> None:
|
|
59
|
+
found = box(f"<div style='width: 50%; margin-left: 20pt'>{TEXT}</div>")
|
|
60
|
+
self.assertAlmostEqual(20, found._left)
|
|
61
|
+
self.assertAlmostEqual(250, found._inner)
|
|
62
|
+
|
|
63
|
+
def test_a_width_wider_than_the_line_is_held_to_it(self) -> None:
|
|
64
|
+
found = box(f"<div style='width: 900pt'>{TEXT}</div>")
|
|
65
|
+
self.assertAlmostEqual(AVAIL, found._inner)
|
|
66
|
+
|
|
67
|
+
def test_the_text_wraps_at_the_width(self) -> None:
|
|
68
|
+
def lines(style: str) -> int:
|
|
69
|
+
output = BytesIO()
|
|
70
|
+
result = pisa.CreatePDF(
|
|
71
|
+
f"<html><body><div style='{style}'>{TEXT}</div></body></html>",
|
|
72
|
+
dest=output,
|
|
73
|
+
)
|
|
74
|
+
self.assertEqual(0, result.err)
|
|
75
|
+
heights: set[float] = set()
|
|
76
|
+
|
|
77
|
+
def visit(text, cm, tm, _font, _size) -> None:
|
|
78
|
+
if text.strip():
|
|
79
|
+
heights.add(round(tm[5] * cm[3] + cm[5], 1))
|
|
80
|
+
|
|
81
|
+
PdfReader(BytesIO(output.getvalue())).pages[0].extract_text(
|
|
82
|
+
visitor_text=visit
|
|
83
|
+
)
|
|
84
|
+
return len(heights)
|
|
85
|
+
|
|
86
|
+
self.assertGreater(lines("width: 40%"), 2 * lines(""))
|
|
@@ -13,6 +13,7 @@ from unittest import TestCase
|
|
|
13
13
|
from pypdf import PdfReader
|
|
14
14
|
|
|
15
15
|
from xhtml2pdf import pisa
|
|
16
|
+
from xhtml2pdf.builders.block import BlockBox
|
|
16
17
|
from xhtml2pdf.builders.flex import FlexContainer
|
|
17
18
|
from xhtml2pdf.document import pisaStory
|
|
18
19
|
from xhtml2pdf.xhtml2pdf_reportlab import PmlParagraph, PmlTable
|
|
@@ -155,10 +156,13 @@ class FlexPropertiesTest(TestCase):
|
|
|
155
156
|
self.assertEqual(("length", 12.0), second.height)
|
|
156
157
|
|
|
157
158
|
def test_a_block_does_not_hand_its_width_to_what_is_inside_it(self) -> None:
|
|
158
|
-
container
|
|
159
|
+
# The block's width makes it a box, with the container inside.
|
|
160
|
+
context = pisaStory(
|
|
159
161
|
"<div style='width: 300pt'><div style='display:flex'>"
|
|
160
162
|
"<div>a</div></div></div>"
|
|
161
163
|
)
|
|
164
|
+
(box,) = [f for f in context.story if isinstance(f, BlockBox)]
|
|
165
|
+
(container,) = [f for f in box.content if isinstance(f, FlexContainer)]
|
|
162
166
|
self.assertEqual("auto", container.css_width.kind)
|
|
163
167
|
self.assertEqual("auto", container.items[0].width.kind)
|
|
164
168
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Each document draws with the fonts it declares, whatever others in the
|
|
3
|
+
process declare.
|
|
4
|
+
|
|
5
|
+
Two documents may name a font-family the same and embed different files,
|
|
6
|
+
one after the other or at the same time in different threads: each gets
|
|
7
|
+
its own files, regular, bold and italic.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import io
|
|
12
|
+
import threading
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from unittest import TestCase
|
|
15
|
+
|
|
16
|
+
from pypdf import PdfReader
|
|
17
|
+
|
|
18
|
+
from xhtml2pdf import pisa
|
|
19
|
+
from xhtml2pdf.config.resources import ResourceAccessPolicy
|
|
20
|
+
|
|
21
|
+
FONTS = Path(__file__).parent / "samples" / "font"
|
|
22
|
+
NOTO = {
|
|
23
|
+
("normal", "normal"): FONTS / "Noto_Sans" / "NotoSans-Regular.ttf",
|
|
24
|
+
("bold", "normal"): FONTS / "Noto_Sans" / "NotoSans-Bold.ttf",
|
|
25
|
+
("normal", "italic"): FONTS / "Noto_Sans" / "NotoSans-Italic.ttf",
|
|
26
|
+
}
|
|
27
|
+
MARKAZI = {
|
|
28
|
+
("normal", "normal"): FONTS / "Arabic_font" / "MarkaziText-Regular.ttf",
|
|
29
|
+
("bold", "normal"): FONTS / "Arabic_font" / "MarkaziText-Bold.ttf",
|
|
30
|
+
}
|
|
31
|
+
POLICY = ResourceAccessPolicy(allow_local_outside_base=True)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def render(faces: dict) -> set[tuple[str, str]]:
|
|
35
|
+
"""The embedded fonts of the document: (name, digest of the file)."""
|
|
36
|
+
css = "".join(
|
|
37
|
+
f"@font-face {{ font-family: Shared; font-weight: {weight};"
|
|
38
|
+
f' font-style: {style}; src: url("{path}"); }}'
|
|
39
|
+
for (weight, style), path in faces.items()
|
|
40
|
+
)
|
|
41
|
+
html = (
|
|
42
|
+
f"<html><head><style>{css} body {{ font-family: Shared }}</style></head>"
|
|
43
|
+
"<body><p>plain <b>bold</b> <i>italic</i></p></body></html>"
|
|
44
|
+
)
|
|
45
|
+
output = io.BytesIO()
|
|
46
|
+
result = pisa.CreatePDF(html, dest=output, resource_policy=POLICY)
|
|
47
|
+
assert not result.err
|
|
48
|
+
embedded = set()
|
|
49
|
+
for page in PdfReader(io.BytesIO(output.getvalue())).pages:
|
|
50
|
+
for font in page["/Resources"]["/Font"].values():
|
|
51
|
+
font = font.get_object()
|
|
52
|
+
descriptor = font.get("/FontDescriptor")
|
|
53
|
+
if descriptor is None:
|
|
54
|
+
continue
|
|
55
|
+
data = descriptor.get_object()["/FontFile2"].get_object().get_data()
|
|
56
|
+
name = str(font["/BaseFont"]).split("+")[-1]
|
|
57
|
+
embedded.add((name, hashlib.md5(data).hexdigest()))
|
|
58
|
+
return embedded
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class FontIsolationTest(TestCase):
|
|
62
|
+
def test_a_second_document_embeds_its_own_file_for_the_same_family(self) -> None:
|
|
63
|
+
noto = render(NOTO)
|
|
64
|
+
markazi = render(MARKAZI)
|
|
65
|
+
self.assertEqual(
|
|
66
|
+
{"NotoSans", "NotoSans-Bold", "NotoSans-Italic"}, {name for name, _ in noto}
|
|
67
|
+
)
|
|
68
|
+
self.assertEqual(
|
|
69
|
+
{"MarkaziText-Regular", "MarkaziText-Bold"}, {name for name, _ in markazi}
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
def test_documents_rendered_at_once_in_threads_keep_their_fonts(self) -> None:
|
|
73
|
+
expected = {"noto": render(NOTO), "markazi": render(MARKAZI)}
|
|
74
|
+
found: list[tuple[str, set]] = []
|
|
75
|
+
|
|
76
|
+
def work(kind: str) -> None:
|
|
77
|
+
faces = NOTO if kind == "noto" else MARKAZI
|
|
78
|
+
found.extend((kind, render(faces)) for _ in range(3))
|
|
79
|
+
|
|
80
|
+
threads = [
|
|
81
|
+
threading.Thread(target=work, args=("noto" if n % 2 else "markazi",))
|
|
82
|
+
for n in range(6)
|
|
83
|
+
]
|
|
84
|
+
for thread in threads:
|
|
85
|
+
thread.start()
|
|
86
|
+
for thread in threads:
|
|
87
|
+
thread.join()
|
|
88
|
+
self.assertEqual(18, len(found))
|
|
89
|
+
for kind, embedded in found:
|
|
90
|
+
self.assertEqual(expected[kind], embedded, kind)
|