How sumatrapdfreader/sumatrapdf works
Purpose and entry points
SumatraPDF is a native, multi-format document reader primarily for Windows: PDF, EPUB/MOBI/FB2, comics, CHM, XPS, DjVu, and images. The desktop process starts through src/SumatraPDF.cpp and startup orchestration in src/SumatraStartup.cpp; application/window state is centered on src/MainWindow.cpp. Separate entry points build shell preview and Windows Search integration: src/previewer/PdfPreviewDll.cpp and src/ifilter/SearchFilterDll.cpp.
Application shell and UI
The application is a Win32 desktop client, with its own UI abstractions layered over Windows controls. src/MainWindow.cpp coordinates windows, commands, document tabs, and active views; src/WindowTab.cpp and src/Tabs.cpp represent per-document and tab-group behavior. UI rendering/control wrappers live behind src/wingui/WinGui.h, src/wingui/Wnd.cpp, and src/mui/Mui.cpp. WebView2 is vendored under packages/Microsoft.Web.WebView2.1.0.4022.49 for browser-backed UI surfaces.
Document engine boundary
src/EngineBase.h defines the document-engine abstraction consumed by the viewer. src/EngineCreate.cpp selects an implementation based on input type; engines include MuPDF-backed documents (src/EngineMupdf.cpp), e-books (src/EngineEbook.cpp), images (src/EngineImages.cpp), DjVu, PostScript, and CHM. This boundary keeps format parsing/page access separate from UI and display logic.
Rendering, layout, and interaction flow
Opening a file flows from engine creation to a document controller/view model, then layout and cached page rendering. src/DisplayModel.cpp and src/DocumentLayout.cpp compute visible-page presentation; src/RenderCache.cpp manages rendered-page reuse; src/Canvas.cpp draws the document surface. Search and text selection use engine-provided text data through src/TextSearch.cpp, src/TextSelection.cpp, and src/Selection.cpp. PDF annotations/forms/printing are application-level extensions in src/Annotation.cpp, src/FormFields.cpp, and src/Print.cpp.
MuPDF and format-processing core
The vendored mupdf/ tree is the principal parsing and rasterization runtime. Its generic graphics/document foundation is mupdf/source/fitz/; PDF interpretation is mupdf/source/pdf/; HTML/EPUB and related reflow formats are handled in mupdf/source/html/. Sumatra’s adapter, src/EngineMupdf.cpp, bridges this C library into its engine interface. MuPDF brings embedded resources, fonts, compression, OCR-related facilities, color handling, and support for several document/image formats.
Persistence, OS integration, and services
User preferences, file history, favorites, themes, and settings serialization are handled by src/AppSettings.cpp, src/GlobalPrefs.cpp, and src/FileHistory.cpp. Windows-specific capabilities include registry installation (src/RegistryInstaller.cpp), DDE/search integration (src/SearchAndDDE.cpp), UI Automation providers (src/uia/Provider.cpp), crash handling (src/CrashHandler.cpp), and update checks (src/UpdateCheck.cpp). Network access is abstracted in src/base/Http.h with Windows and macOS implementations.
Build and delivery architecture
The production code is C/C++ with TypeScript/Bun scripts driving builds and generation. cmd/build.ts is the general build driver; premake5.lua generates project definitions, including vs2022/SumatraPDF.sln. Dependencies are largely vendored under ext/ and mupdf/, including HarfBuzz, FreeType, image codecs, compression libraries, archive readers, and MuPDF. CI runs through GitHub Actions (.github/workflows/build.yml) across Windows-oriented builds plus Linux/macOS build paths; macOS-specific application work is isolated under src/mac/.
Components 22
Windows desktop app
- Desktop entry point
src/SumatraPDF.cpp - Startup orchestration
src/SumatraStartup.cpp - Main window · Coordinates commands, tabs, windows, and active views.
src/MainWindow.cpp - Document tabs
src/WindowTab.cpp - Native UI layer
src/wingui/WinGui.h
Document pipeline
- Document engine API · Separates format access from viewer and display code.
src/EngineBase.h - Engine selection
src/EngineCreate.cpp - MuPDF engine adapter
src/EngineMupdf.cpp - E-book and image engines
src/EngineEbook.cpp - Display and layout · Computes visible-page presentation.
src/DisplayModel.cpp - Rendered-page cache
src/RenderCache.cpp - Document canvas
src/Canvas.cpp
MuPDF runtime
- MuPDF document core · Provides parsing, graphics, rasterization, and format support.
- PDF interpreter
- HTML and EPUB layer
OS and persistence
- Preferences and history
src/AppSettings.cpp - Windows integration · Registry, DDE/search, UI Automation, crash handling, and updates.
src/SearchAndDDE.cpp - Shell preview handler
src/previewer/PdfPreviewDll.cpp - Windows Search filter
src/ifilter/SearchFilterDll.cpp
Build and delivery
- Build driver
cmd/build.ts - Project generation · Generates project definitions including the Visual Studio solution.
premake5.lua - Cross-platform CI
.github/workflows/build.yml
Connections 24
- Desktop entry point → Startup orchestration: starts
- Startup orchestration → Main window: initializes
- Main window → Document tabs: manages
- Main window → Native UI layer: uses
- Main window → Preferences and history: loads and saves
- Main window → Windows integration: integrates with
- Main window → Engine selection: opens documents through
- Engine selection → Document engine API: returns
- Engine selection → MuPDF engine adapter: selects
- Engine selection → E-book and image engines: selects
- MuPDF engine adapter → Document engine API: implements
- E-book and image engines → Document engine API: implement
- Document engine API → Display and layout: supplies pages and text
- Display and layout → Rendered-page cache: requests rendered pages
- Rendered-page cache → Document canvas: provides cached output
- Document canvas → Native UI layer: draws into
- MuPDF engine adapter → MuPDF document core: bridges to
- MuPDF document core → PDF interpreter: includes
- MuPDF document core → HTML and EPUB layer: includes
- Shell preview handler → MuPDF engine adapter: renders PDFs through
- Windows Search filter → MuPDF engine adapter: extracts document data through
- Build driver → Project generation: drives
- Project generation → Desktop entry point: builds
- Cross-platform CI → Build driver: runs