Skip to content

Commit 381fc41

Browse files
kjkclaude
andcommitted
fix per-file checkered background not working for PDF documents
The checkered pattern and kColorUnset both used the same sentinel value, so Canvas.cpp couldn't distinguish "no per-file color" from "per-file checkered". Added bgColorCheckered flag to WindowTab to track this explicitly. Also fixed the no-gradient branch to use colDocBg instead of ThemeMainWindowBackgroundColor(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 94dd3b4 commit 381fc41

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/Canvas.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,9 @@ static bool DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) {
14841484

14851485
// per-document background color from FileState overrides everything
14861486
WindowTab* curTab = win->CurrentTab();
1487-
if (curTab && curTab->bgColor != kColorUnset) {
1487+
if (curTab && curTab->bgColorCheckered) {
1488+
colDocBg = kColorUnset;
1489+
} else if (curTab && curTab->bgColor != kColorUnset) {
14881490
colDocBg = curTab->bgColor;
14891491
}
14901492

@@ -1505,8 +1507,7 @@ static bool DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) {
15051507
} else if (colDocBg == kColorUnset) {
15061508
paintBgOrCheckerboard(colDocBg, rcArea);
15071509
} else if (0 == nGCols) {
1508-
auto col = ThemeMainWindowBackgroundColor();
1509-
AutoDeleteBrush brush = CreateSolidBrush(col);
1510+
AutoDeleteBrush brush = CreateSolidBrush(colDocBg);
15101511
FillRect(hdc, rcArea, brush);
15111512
} else {
15121513
COLORREF colors[3];

src/SumatraPDF.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,7 @@ static void ReplaceDocumentInCurrentTab(LoadArgs* args, DocController* ctrl, Fil
14261426
ParsedColor* bgParsed = GetPrefsColor(fs->bgCol);
14271427
if (bgParsed->parsedOk) {
14281428
tab->bgColor = bgParsed->col;
1429+
tab->bgColorCheckered = (bgParsed->col == kColorUnset);
14291430
}
14301431
ParsedColor* tabColParsed = GetPrefsColor(fs->tabCol);
14311432
if (tabColParsed->parsedOk) {
@@ -4438,6 +4439,7 @@ static void OnMenuChangeBackgroundColor(MainWindow* win) {
44384439
str::ReplaceWithCopy(&fs->bgCol, "");
44394440
}
44404441
tab->bgColor = kColorUnset;
4442+
tab->bgColorCheckered = false;
44414443
SaveSettings();
44424444
} else {
44434445
// apply to this file only
@@ -4447,6 +4449,7 @@ static void OnMenuChangeBackgroundColor(MainWindow* win) {
44474449
fs->bgColParsed.wasParsed = false;
44484450
}
44494451
tab->bgColor = newColor;
4452+
tab->bgColorCheckered = result.isCheckered;
44504453
SaveSettings();
44514454
}
44524455
// trigger repaint

src/WindowTab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct WindowTab {
5757

5858
// per-document background color from FileState; kColorUnset = use default
5959
COLORREF bgColor = kColorUnset;
60+
// true if per-document background is explicitly set to checkered pattern
61+
bool bgColorCheckered = false;
6062
// per-document tab color from FileState; kColorUnset = use default
6163
COLORREF tabColor = kColorUnset;
6264

0 commit comments

Comments
 (0)