Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
* support for page number alias substitution with bidirectional / RTL text shaping - _cf._ [issue #1925](https://github.com/py-pdf/fpdf2/issues/1925) - thanks to @prateek-dagar
* `appearance` parameter for [`FPDF.file_attachment_annotation()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.file_attachment_annotation), accepting `FileAttachmentAppearance.HIDDEN` to give the annotation an empty appearance stream so its default icon is not displayed while the file stays embedded and reachable - _cf._ [issue #561](https://github.com/py-pdf/fpdf2/issues/561)
### Fixed
* split font `/ToUnicode` CMap mappings into blocks of at most 100 entries, as required by the PDF specification - _cf._ [issue #1952](https://github.com/py-pdf/fpdf2/issues/1952)
* split font `/ToUnicode` and `/Encoding` CMap mappings into blocks of at most 100 entries, as required by the PDF specification - _cf._ [issue #1952](https://github.com/py-pdf/fpdf2/issues/1952)
* visual gap in rendering subsequent text after `{nb}` page alias when text shaping is enabled - _cf._ [issue #1090](https://github.com/py-pdf/fpdf2/issues/1090) - thanks to @prateek-dagar
* `FPDF.write_html()` no longer raises `IndexError: pop from empty list` when a `<ul>` or `<ol>` element carries a `line-height` that is not a bare number (_e.g._ `line-height: normal` or `line-height: 1.5em`); such values are now ignored, and the default line height is used, consistently with `<p line-height="x">` - _cf._ [PR #1917](https://github.com/py-pdf/fpdf2/pull/1917)
* `FPDF.write_html()` now renders list bullets with correct font styling instead of inheriting preceding heading (e.g. `<h1>`) styles - _cf._ [issue #1921](https://github.com/py-pdf/fpdf2/issues/1921)
Expand Down
16 changes: 8 additions & 8 deletions fpdf/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ def _add_fonts(
"1 begincodespacerange\n"
"<00> <FF>\n"
"endcodespacerange\n"
f"{_build_bfchar_blocks(bfChar)}"
f"{_build_cmap_blocks(bfChar, 'bfchar')}"
"endcmap\n"
"CMapName currentdict /CMap defineresource pop\n"
"end\n"
Expand Down Expand Up @@ -1490,7 +1490,7 @@ def format_code(unicode: int) -> str:
"1 begincodespacerange\n"
"<0000> <FFFF>\n"
"endcodespacerange\n"
f"{_build_bfchar_blocks(bfChar)}"
f"{_build_cmap_blocks(bfChar, 'bfchar')}"
"endcmap\n"
"CMapName currentdict /CMap defineresource pop\n"
"end\n"
Expand Down Expand Up @@ -1525,9 +1525,7 @@ def format_code(unicode: int) -> str:
"1 begincodespacerange\n"
"<0000> <FFFF>\n"
"endcodespacerange\n"
f"{len(cid_mapping)} begincidchar\n"
f"{''.join(cid_mapping)}"
"endcidchar\n"
f"{_build_cmap_blocks(cid_mapping, 'cidchar')}"
"endcmap\n"
"CMapName currentdict /CMap defineresource pop\n"
"end\n"
Expand Down Expand Up @@ -2271,12 +2269,14 @@ def stream_content_for_raster_image(
)


def _build_bfchar_blocks(entries: list[str]) -> str:
"""Limit CMap bfchar blocks to 100 entries (Adobe Technical Note #5014)."""
def _build_cmap_blocks(
entries: list[str], operator: Literal["bfchar", "cidchar"]
) -> str:
"""Limit CMap mapping blocks to 100 entries (Adobe Technical Note #5014)."""
blocks: list[str] = []
for start in range(0, len(entries), 100):
chunk = entries[start : start + 100]
blocks.append(f"{len(chunk)} beginbfchar\n{''.join(chunk)}endbfchar\n")
blocks.append(f"{len(chunk)} begin{operator}\n{''.join(chunk)}end{operator}\n")
return "".join(blocks)


Expand Down
Binary file modified test/fonts/charmap_first_999_chars-SourceHanSansCN-Normal.pdf
Binary file not shown.