~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(pdf): stop digits rendering as emoji glyphs in exported PDFs (#5050)
LearningCircuit85daefa43fc5
diff --git a/changelog.d/+pdf-digits-emoji-font.bugfix.md b/changelog.d/+pdf-digits-emoji-font.bugfix.mdnew file mode 100644index 0000000000..e5ffd6decb--- /dev/null+++ b/changelog.d/+pdf-digits-emoji-font.bugfix.md@@ -0,0 +1 @@+Fixed numbers in exported PDFs rendering as wide, spaced-out emoji glyphs ("2 0 2 6" instead of "2026"). Digits 0-9 carry the Unicode Emoji property, so listing "Noto Color Emoji" in the PDF font stacks (#4730) made Pango draw every digit with the emoji font. Emoji families are removed from the stacks; emoji still render via fontconfig per-character fallback to the installed emoji font.diff --git a/src/local_deep_research/web/services/pdf_service.py b/src/local_deep_research/web/services/pdf_service.pyindex c73bcbfaec..e197ca21ea 100644--- a/src/local_deep_research/web/services/pdf_service.py+++ b/src/local_deep_research/web/services/pdf_service.py@@ -140,17 +140,17 @@ def get_weasyprint_install_instructions() -> str:# Glyphs still require the corresponding system font (e.g.# fonts-noto-cjk) to actually be installed.#-# The emoji families at the tail of each stack cover emoji-# codepoints that Arial and the CJK fonts lack entirely — without-# them, emojis in the markdown render as "tofu" boxes in the PDF-# even though they look fine in the HTML view. Color first-# (preferred when WeasyPrint can render the CBDT/CBLC bitmap-# tables — the format Debian's fonts-noto-color-emoji ships),-# then a monochrome fallback for renderers without CBDT support.-# Note: "Noto Color Emoji" is provided by fonts-noto-color-emoji;-# the monochrome "Noto Emoji" is a separate package-# (fonts-noto-emoji / fonts-noto-extra) and is a best-effort-# fallback for hosts that happen to have it installed.+# Emoji are deliberately NOT listed in these stacks. They render+# through Pango/fontconfig per-character fallback to whichever emoji+# font is installed (fonts-noto-color-emoji is bundled in the official+# Docker image; docs/faq.md covers other platforms). Listing an emoji+# family explicitly (as #4730 did) makes Pango route every digit 0-9+# plus '#' and '*' — codepoints that carry the Unicode Emoji property+# and have glyphs in Noto Color Emoji — to the emoji font, even though+# earlier families in the stack cover them. The result: all numbers in+# exported reports rendered as wide, square emoji glyphs ("2 0 2 6"+# instead of "2026"). Regression test:+# test_minimal_css_excludes_emoji_font_families.MINIMAL_CSS = """@page {size: A4;@@ -163,9 +163,7 @@ body {"PingFang SC", "PingFang TC", "Hiragino Sans","Hiragino Kaku Gothic ProN", "Apple SD Gothic Neo","Microsoft YaHei", "Microsoft JhengHei",- "Yu Gothic", "Malgun Gothic", "SimSun",- "Noto Color Emoji", "Noto Emoji", "Segoe UI Emoji",- "Apple Color Emoji", sans-serif;+ "Yu Gothic", "Malgun Gothic", "SimSun", sans-serif;font-size: 10pt;line-height: 1.4;}@@ -198,9 +196,7 @@ code, pre {"Noto Sans Mono CJK TC", "Noto Sans Mono CJK JP","Noto Sans Mono CJK KR", "Noto Sans CJK SC","PingFang SC", "Hiragino Sans", "Apple SD Gothic Neo",- "Microsoft YaHei", "SimSun",- "Noto Color Emoji", "Noto Emoji", "Segoe UI Emoji",- "Apple Color Emoji";+ "Microsoft YaHei", "SimSun";background-color: #f5f5f5;}@@ -246,7 +242,7 @@ class PDFService:metadata: Optional metadata dict (author, date, etc.)custom_css: Optional CSS string layered on top of the defaultstylesheet. Rules here win on equal specificity via the- cascade, but the default's CJK/emoji font fallbacks and+ cascade, but the default's CJK font fallbacks andpage setup are always applied.Returns:@@ -272,9 +268,9 @@ class PDFService:# Always apply the default stylesheet first, then layer any# caller-provided custom_css on top. WeasyPrint resolves# conflicts by cascade order, so later stylesheets win on- # equal specificity — this preserves the CJK and emoji font- # fallbacks in MINIMAL_CSS even when a caller supplies their- # own CSS, while still letting them override any default.+ # equal specificity — this preserves the CJK font fallbacks+ # in MINIMAL_CSS even when a caller supplies their own CSS,+ # while still letting them override any default.css_list = [self.minimal_css]if custom_css:css_list.append(CSS(string=custom_css))diff --git a/tests/api_tests_with_login/pytest_tests/test_export_formats.py b/tests/api_tests_with_login/pytest_tests/test_export_formats.pyindex 3e654ad2bd..ca98de0a25 100644--- a/tests/api_tests_with_login/pytest_tests/test_export_formats.py+++ b/tests/api_tests_with_login/pytest_tests/test_export_formats.py@@ -96,8 +96,14 @@ def test_export_latex(auth_session, base_url):print(f" First 200 chars: {content[:200]}...")-def test_export_pdf_via_javascript(auth_session, base_url):- """Test PDF export (generated client-side via JavaScript)"""+def test_export_pdf(auth_session, base_url):+ """Test exporting research report as PDF via the server-side endpoint.++ This is the endpoint the UI's "Download PDF" button calls+ (results.js → POST /api/v1/research/<id>/export/pdf), rendered+ server-side by WeasyPrint. Also guards the digit-capture regression+ (#5050): digits must be drawn with a text font, not an emoji font.+ """session, csrf_token = auth_session# First, start a simple research@@ -140,24 +146,60 @@ def test_export_pdf_via_javascript(auth_session, base_url):# Additional wait to ensure report is savedtime.sleep(2) # allow: unmarked-sleep- # Get the research report content- report_response = session.get(f"{base_url}/api/report/{research_id}")- assert report_response.status_code == 200+ # Export as PDF through the endpoint the UI download button uses+ export_response = session.post(+ f"{base_url}/api/v1/research/{research_id}/export/pdf"+ )- report_data = report_response.json()- assert "content" in report_data, "No content in report"+ assert export_response.status_code == 200, (+ f"PDF export failed: {export_response.text}"+ )- content = report_data.get("content", "")- assert len(content) > 100, (- f"Report content too short for PDF: {len(content)} bytes"+ content_type = export_response.headers.get("Content-Type", "")+ assert "application/pdf" in content_type, (+ f"Unexpected content type: {content_type}")- print(- f"✓ Report has content suitable for PDF export - {len(content)} bytes"+ pdf_bytes = export_response.content+ assert pdf_bytes[:4] == b"%PDF", "Response is not a PDF document"+ assert len(pdf_bytes) > 1000, f"PDF too small: {len(pdf_bytes)} bytes"++ content_disposition = export_response.headers.get("Content-Disposition", "")+ assert ".pdf" in content_disposition, (+ f"Expected .pdf file in Content-Disposition: {content_disposition}")- # Note: PDF generation happens client-side via jsPDF- # We can't test the actual PDF generation here, but we've verified the content exists+ # Digit-capture regression (#5050): no digit glyph may come from an+ # emoji font. Skipped silently when pdfminer isn't installed.+ try:+ import io++ from pdfminer.high_level import extract_pages+ from pdfminer.layout import LTChar, LTTextContainer, LTTextLine+ except ImportError:+ print("pdfminer not available — skipping digit font check")+ else:+ digit_fonts = set()+ for page in extract_pages(io.BytesIO(pdf_bytes)):+ for element in page:+ if not isinstance(element, LTTextContainer):+ continue+ for line in element:+ if not isinstance(line, LTTextLine):+ continue+ for char in line:+ if (+ isinstance(char, LTChar)+ and char.get_text().isdigit()+ ):+ digit_fonts.add(char.fontname)+ emoji_fonts = {f for f in digit_fonts if "emoji" in f.lower()}+ assert not emoji_fonts, (+ f"digits in the exported PDF were rendered with an emoji "+ f"font: {emoji_fonts}"+ )++ print(f"✓ PDF export successful - {len(pdf_bytes)} bytes")def test_export_markdown(auth_session, base_url):diff --git a/tests/web/routes/test_export_pdf_rendering.py b/tests/web/routes/test_export_pdf_rendering.pynew file mode 100644index 0000000000..f057ee7eba--- /dev/null+++ b/tests/web/routes/test_export_pdf_rendering.py@@ -0,0 +1,133 @@+"""End-to-end rendering test for the PDF export endpoint.++Drives POST /api/v1/research/<id>/export/pdf — the endpoint the UI's+"Download PDF" button calls — through the real exporter chain+(ExporterRegistry → PDFExporter → PDFService → WeasyPrint). Only the+data layer (DB session, report assembly) is mocked, so the returned+bytes are a genuine WeasyPrint render.++Regression coverage for the digit-capture bug (#5050): listing an emoji+family in the PDF font stacks made Pango draw every digit 0-9 with Noto+Color Emoji, so numbers in exported reports rendered as wide, square+emoji glyphs ("2 0 2 6" instead of "2026"). The service-level tests in+tests/web/services/test_pdf_service.py assert the same property on+PDFService directly; this test pins it to the HTTP surface so a change+anywhere in the export chain (route, exporter registry, service) that+reintroduces the bug still fails CI.+"""++import io+from contextlib import contextmanager+from unittest.mock import MagicMock, patch++import pytest+from flask import Flask++MODULE = "local_deep_research.web.routes.research_routes"+ASSEMBLY_MOD = "local_deep_research.web.services.report_assembly_service"++# Digit-heavy markdown mirroring a real research report (dates, prices,+# token counts, citation markers) — the shapes that were unreadable.+REPORT_MARKDOWN = (+ "# Pricing report 2026-07-11\n\n"+ "As of July 11, 2026, plans cost $20/month and allow 44,000 tokens "+ "per rolling 5-hour window [21][30].\n"+)+++def app():+ flask_app = Flask(__name__)+ flask_app.secret_key = "test-secret-key"+ flask_app.config["TESTING"] = True++ from local_deep_research.web.routes.research_routes import research_bp++ flask_app.register_blueprint(research_bp)++ with patch("local_deep_research.web.auth.decorators.db_manager") as mock_db:+ mock_db.is_user_connected.return_value = True+ yield flask_app+++def client(app):+ return app.test_client()++[email protected](autouse=True)+def _inject_session(app):+ @app.before_request+ def _set_sess():+ from flask import session++ session["username"] = "testuser"+ session["session_id"] = "sid-1"+++@contextmanager+def _ctx(session):+ yield session+++def _digit_fonts(pdf_bytes):+ """Return the set of font names used to draw digit glyphs."""+ from pdfminer.high_level import extract_pages+ from pdfminer.layout import LTChar, LTTextContainer, LTTextLine++ fonts = set()+ for page in extract_pages(io.BytesIO(pdf_bytes)):+ for element in page:+ if not isinstance(element, LTTextContainer):+ continue+ for line in element:+ if not isinstance(line, LTTextLine):+ continue+ for char in line:+ if isinstance(char, LTChar) and char.get_text().isdigit():+ fonts.add(char.fontname)+ return fonts+++def test_export_pdf_endpoint_renders_digits_with_text_font(client):+ """The exported PDF must draw digits with a text font, not an emoji font.++ On hosts with no emoji font installed the emoji-font assertion passes+ trivially, which is correct — there is no emoji font to capture the+ digits.+ """+ from local_deep_research.web.services.pdf_service import (+ weasyprint_available,+ )++ if not weasyprint_available():+ pytest.skip("WeasyPrint system libraries not available")+ pytest.importorskip("pdfminer.high_level")++ research = MagicMock()+ research.id = "res-1"+ research.title = "Pricing report"+ research.query = "pricing"+ mock_session = MagicMock()+ mock_session.query.return_value.filter_by.return_value.first.return_value = research++ with (+ patch(f"{MODULE}.get_user_db_session", return_value=_ctx(mock_session)),+ patch(+ f"{ASSEMBLY_MOD}.assemble_full_report",+ return_value=REPORT_MARKDOWN,+ ),+ ):+ resp = client.post("/api/v1/research/res-1/export/pdf")++ assert resp.status_code == 200+ assert resp.content_type == "application/pdf"+ assert resp.data[:4] == b"%PDF"++ digit_fonts = _digit_fonts(resp.data)+ assert digit_fonts, "expected the rendered PDF to contain digits"+ emoji_fonts = {f for f in digit_fonts if "emoji" in f.lower()}+ assert not emoji_fonts, (+ f"digits in the exported PDF were rendered with an emoji font: "+ f"{emoji_fonts}"+ )diff --git a/tests/web/services/test_pdf_service.py b/tests/web/services/test_pdf_service.pyindex 10d18cfa99..93a66f1fe2 100644--- a/tests/web/services/test_pdf_service.py+++ b/tests/web/services/test_pdf_service.py@@ -33,35 +33,76 @@ class TestPDFServiceInit:# The CSS string should be accessibleassert service.minimal_css is not None- def test_minimal_css_includes_emoji_font_families(self):- """Body and code font stacks must fall back to an emoji font.-- Without an emoji family in the stack, WeasyPrint renders emoji- codepoints as "tofu" boxes because Arial and the CJK fonts have- no emoji coverage. Regression test for the emoji font stack.+ def test_minimal_css_excludes_emoji_font_families(self):+ """No font-family stack may list an emoji font explicitly.++ Digits 0-9, '#' and '*' carry the Unicode Emoji property and have+ glyphs in Noto Color Emoji, so Pango routes them to an explicitly+ listed emoji font even when an earlier family in the stack covers+ them — every number in an exported report then renders as wide,+ square emoji glyphs ("2 0 2 6" instead of "2026"). Emoji still+ render via Pango/fontconfig per-character fallback to an installed+ emoji font, so the stacks must not name one. Regression test for+ the digit-capture bug introduced by #4730."""- from local_deep_research.web.services.pdf_service import MINIMAL_CSS-- assert "Noto Color Emoji" in MINIMAL_CSS- assert "Noto Emoji" in MINIMAL_CSS-- # Both the body and code/mono stacks should have emoji fallbacks.- # Pull out just the font-family declarations to make the assertion- # resilient to other CSS edits.import re+ from local_deep_research.web.services.pdf_service import MINIMAL_CSS+font_family_blocks = re.findall(r"font-family:\s*([^;]+);", MINIMAL_CSS)assert len(font_family_blocks) >= 2, ("expected at least body + code font-family declarations")for block in font_family_blocks:- assert "Noto Color Emoji" in block, (- f"font-family block missing color emoji fallback: {block!r}"- )- assert "Noto Emoji" in block, (- f"font-family block missing monochrome emoji fallback: {block!r}"+ assert "emoji" not in block.lower(), (+ f"font-family block must not list an emoji font (it would "+ f"capture digits): {block!r}")+ def test_digits_not_rendered_with_emoji_font(self):+ """Digits in a rendered PDF must come from a text font, not an emoji font.++ Functional regression test for the digit-capture bug: with an emoji+ family in the font-family stack, Pango renders 0-9 with Noto Color+ Emoji (wide square glyphs). Renders a digit-heavy document and+ asserts no digit glyph is drawn with an emoji font. On hosts with+ no emoji font installed the assertion passes trivially, which is+ correct — there is no emoji font to capture the digits.+ """+ import io++ pytest.importorskip("pdfminer.high_level")+ from pdfminer.high_level import extract_pages+ from pdfminer.layout import LTChar, LTTextContainer, LTTextLine++ from local_deep_research.web.services.pdf_service import PDFService++ service = PDFService()+ pdf_bytes = service.markdown_to_pdf(+ "As of July 11, 2026, plans cost $20/month [21][30]."+ )++ digit_fonts = set()+ for page in extract_pages(io.BytesIO(pdf_bytes)):+ for element in page:+ if not isinstance(element, LTTextContainer):+ continue+ for line in element:+ if not isinstance(line, LTTextLine):+ continue+ for char in line:+ if (+ isinstance(char, LTChar)+ and char.get_text().isdigit()+ ):+ digit_fonts.add(char.fontname)++ assert digit_fonts, "expected the rendered PDF to contain digits"+ emoji_fonts = {f for f in digit_fonts if "emoji" in f.lower()}+ assert not emoji_fonts, (+ f"digits were rendered with an emoji font: {emoji_fonts}"+ )+class TestMarkdownToHTML:"""Tests for _markdown_to_html method."""@@ -233,8 +274,8 @@ class TestMarkdownToPDF:Regression test: previously markdown_to_pdf used an if/else thatdropped self.minimal_css entirely when custom_css was provided,- silently losing the CJK and emoji font fallbacks. Verify the- default stylesheet is always passed to WeasyPrint.+ silently losing the CJK font fallbacks. Verify the default+ stylesheet is always passed to WeasyPrint."""from unittest.mock import patch, MagicMockfrom local_deep_research.web.services.pdf_service import PDFService