Skip to content

Commit 2cc0b1c

Browse files
committed
fix background color affecting page color (fixes #5521)
1 parent b3f2175 commit 2cc0b1c

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/SumatraPDF.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,8 +2687,10 @@ static void RerenderFixedPage() {
26872687

26882688
void UpdateDocumentColors() {
26892689
COLORREF bg;
2690-
COLORREF text = ThemeDocumentColors(bg);
2691-
// logfa("retrieved doc colors in UpdateDocumentColors: 0x%x 0x%x\n", text, bg);
2690+
// use ThemePageRenderColors instead of ThemeDocumentColors
2691+
// so that engine-type background color settings (fixedPageUI.backgroundColor etc.)
2692+
// only affect the canvas/window background, not the PDF page rendering
2693+
COLORREF text = ThemePageRenderColors(bg);
26922694

26932695
if ((text == gRenderCache->textColor) && (bg == gRenderCache->backgroundColor)) {
26942696
return; // colors didn't change

src/SumatraStartup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ int APIENTRY WinMain(_In_ HINSTANCE /*hInstance*/, _In_opt_ HINSTANCE, _In_ LPST
14571457

14581458
gCrashOnOpen = flags.crashOnOpen;
14591459

1460-
gRenderCache->textColor = ThemeDocumentColors(gRenderCache->backgroundColor);
1460+
gRenderCache->textColor = ThemePageRenderColors(gRenderCache->backgroundColor);
14611461
// logfa("retrieved doc colors in WinMain: 0x%x 0x%x\n", gRenderCache->textColor, gRenderCache->backgroundColor);
14621462

14631463
gIsStartup = true;

src/Theme.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,34 @@ COLORREF ThemeDocumentColors(COLORREF& bg, bool isEbook) {
358358
return text;
359359
}
360360

361+
// colors for page bitmap recoloring (render cache)
362+
// only affected by invertColors / theme, not by engine-type background color settings
363+
// (those only affect the canvas/window background around the page)
364+
COLORREF ThemePageRenderColors(COLORREF& bg) {
365+
COLORREF text = kColBlack;
366+
bg = kColWhite;
367+
368+
if (!gGlobalPrefs->fixedPageUI.invertColors) {
369+
return text;
370+
}
371+
372+
// default colors
373+
if (gCurrentTheme == gThemeLight) {
374+
std::swap(text, bg);
375+
return text;
376+
}
377+
378+
// if we're inverting in non-default themes, the colors
379+
// should match the colors of the window
380+
text = ThemeWindowTextColor();
381+
bg = ThemeMainWindowBackgroundColor();
382+
383+
if (gCurrThemeIndex < 3) {
384+
bg = AccentColor(bg, 8);
385+
}
386+
return text;
387+
}
388+
361389
COLORREF ThemeControlBackgroundColor() {
362390
// note: we can change it in ThemeUpdateAfterLoadSettings()
363391
auto col = GetThemeCol(gCurrentTheme->controlBackgroundColor, kRedColor);

src/Theme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void SelectNextTheme();
77
void CreateThemeCommands();
88

99
COLORREF ThemeDocumentColors(COLORREF&, bool isEbook = false);
10+
COLORREF ThemePageRenderColors(COLORREF&);
1011
COLORREF ThemeMainWindowBackgroundColor();
1112
COLORREF ThemeControlBackgroundColor();
1213
COLORREF ThemeWindowBackgroundColor();

0 commit comments

Comments
 (0)