Skip to content

Commit

Permalink
fix keyboard zoom in chm; show notifications in chm (for #4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Aug 19, 2024
1 parent 157d972 commit 653d474
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 42 deletions.
42 changes: 27 additions & 15 deletions src/ChmModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,32 +565,44 @@ TocTree* ChmModel::GetToc() {
float ChmModel::GetNextZoomStep(float towardsLevel) const {
float currZoom = GetZoomVirtual(true);
if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) {
// chm uses browser control which only supports integer zoom levels
// this ensures we're not stuck on a given zoom level i.e. advance by at least 1%
int iCurrZoom2 = (int)GetZoomVirtual(true);
int iCurrZoom = (int)currZoom;
if (iCurrZoom == iCurrZoom2) {
currZoom += 1.f;
}
return currZoom;
}

Vec<float>* zoomLevels = gGlobalPrefs->zoomLevels;
ReportIf(zoomLevels->size() != 0 && (zoomLevels->at(0) < kZoomMin || zoomLevels->Last() > kZoomMax));
ReportIf(zoomLevels->size() != 0 && zoomLevels->at(0) > zoomLevels->Last());

const float FUZZ = 0.01f;
float newZoom = towardsLevel;
if (currZoom < towardsLevel) {
for (size_t i = 0; i < zoomLevels->size(); i++) {
if (zoomLevels->at(i) - FUZZ > currZoom) {
newZoom = zoomLevels->at(i);
int nZoomLevels;
float* zoomLevels = GetDefaultZoomLevels(&nZoomLevels);

// chm uses browser control which only supports integer zoom levels
// this ensures we're not stuck on a given zoom level
// due to float => int truncation
int iCurrZoom = (int)currZoom;
int iTowardsLevel = (int)towardsLevel;
int iNewZoom = iTowardsLevel;
if (iCurrZoom < towardsLevel) {
for (int i = 0; i < nZoomLevels; i++) {
int iZoom = (int)zoomLevels[i];
if (iZoom > iCurrZoom) {
iNewZoom = iZoom;
break;
}
}
} else if (currZoom > towardsLevel) {
for (size_t i = zoomLevels->size(); i > 0; i--) {
if (zoomLevels->at(i - 1) + FUZZ < currZoom) {
newZoom = zoomLevels->at(i - 1);
} else if (iCurrZoom > towardsLevel) {
for (int i = nZoomLevels - 1; i >= 0; i--) {
int iZoom = (int)zoomLevels[i];
if (iZoom < iCurrZoom) {
iNewZoom = iZoom;
break;
}
}
}

return newZoom;
return (float)iNewZoom;
}

void ChmModel::GetDisplayState(FileState* fs) {
Expand Down
1 change: 1 addition & 0 deletions src/DisplayMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ DisplayMode DisplayModeFromString(const char* s, DisplayMode defVal);
float ZoomFromString(const char* s, float defVal);
void ZoomToString(char** dst, float zoom, FileState* stateForIssue2140);
bool MaybeGetNextZoomByIncrement(float* currZoomInOut, float towardsLevel);
float* GetDefaultZoomLevels(int* nZoomLevelsOut);
46 changes: 27 additions & 19 deletions src/DisplayModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,25 +1612,19 @@ bool MaybeGetNextZoomByIncrement(float* currZoomInOut, float towardsLevel) {
return true;
}

float DisplayModel::GetNextZoomStep(float towardsLevel) const {
float currZoom = GetZoomVirtual(true);
if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) {
return currZoom;
}

// differences to Adobe Reader: starts at 8.33 (instead of 1 and 6.25)
// and has four additional intermediary zoom levels ("added")
// clang-format off
static float defaultZooms[] = {
8.33f, 12.5f, 18 /* added */, 25, 33.33f, 50, 66.67f, 75,
100, 125, 150, 200, 300, 400, 600, 800, 1000 /* added */,
1200, 1600, 2000 /* added */, 2400, 3200, 4800 /* added */, 6400
};
// clang-format on
// ReportIf(defaultZooms[0] != kZoomMin || defaultZooms[dimof(defaultZooms)-1] != kZoomMax);

float* zoomLevels = defaultZooms;
int nZoomLevels = dimofi(defaultZooms);
// differences to Adobe Reader: starts at 8.33 (instead of 1 and 6.25)
// and has four additional intermediary zoom levels ("added")
// clang-format off
static float defaultZoomLevels[] = {
8.33f, 12.5f, 18 /* added */, 25, 33.33f, 50, 66.67f, 75,
100, 125, 150, 200, 300, 400, 600, 800, 1000 /* added */,
1200, 1600, 2000 /* added */, 2400, 3200, 4800 /* added */, 6400
};
// clang-format on

float* GetDefaultZoomLevels(int* nZoomLevelsOut) {
float* zoomLevels = defaultZoomLevels;
int nZoomLevels = dimofi(defaultZoomLevels);

int nCustomZooms = gGlobalPrefs->zoomLevels->Size();
if (nCustomZooms > 0) {
Expand All @@ -1639,11 +1633,25 @@ float DisplayModel::GetNextZoomStep(float towardsLevel) const {
zoomLevels = gGlobalPrefs->zoomLevels->LendData();
nZoomLevels = nCustomZooms;
}
*nZoomLevelsOut = nZoomLevels;
return zoomLevels;
}

float DisplayModel::GetNextZoomStep(float towardsLevel) const {
float currZoom = GetZoomVirtual(true);
if (currZoom == towardsLevel) {
return towardsLevel;
}

if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) {
return currZoom;
}

// ReportIf(defaultZooms[0] != kZoomMin || defaultZooms[dimof(defaultZooms)-1] != kZoomMax);

int nZoomLevels;
float* zoomLevels = GetDefaultZoomLevels(&nZoomLevels);

float pageZoom = (float)HUGE_VAL, widthZoom = (float)HUGE_VAL;
for (int pageNo = 1; pageNo <= PageCount(); pageNo++) {
if (PageShown(pageNo)) {
Expand Down
1 change: 1 addition & 0 deletions src/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ NotificationWnd* ShowNotification(const NotificationCreateArgs& args) {
delete wnd;
return nullptr;
}
BringWindowToTop(wnd->hwnd);
NotifsAdd(wnd, args.groupId);
return wnd;
}
Expand Down
16 changes: 8 additions & 8 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ static void UpdatePageInfoHelper(DocController* ctrl, NotificationWnd* wnd, int
}

static void TogglePageInfoHelper(MainWindow* win) {
if (!win || !win->IsDocLoaded()) {
return;
}
NotificationWnd* wnd = GetNotificationForGroup(win->hwndCanvas, kNotifPageInfo);
if (wnd) {
RemoveNotificationsForGroup(win->hwndCanvas, kNotifPageInfo);
Expand Down Expand Up @@ -929,7 +932,6 @@ void ControllerCallbackHandler::PageNoChanged(DocController* ctrl, int pageNo) {
if (!wnd) {
return;
}
ReportIf(!win->AsFixed());
UpdatePageInfoHelper(win->ctrl, wnd, pageNo);
}

Expand Down Expand Up @@ -5811,13 +5813,11 @@ static LRESULT FrameOnCommand(MainWindow* win, HWND hwnd, UINT msg, WPARAM wp, L
ToggleFavorites(win);
break;

case CmdTogglePageInfo:
if (dm) {
// "page info" tip: make figuring out current page and
// total pages count a one-key action (unless they're already visible)
TogglePageInfoHelper(win);
}
break;
case CmdTogglePageInfo: {
// "page info" tip: make figuring out current page and
// total pages count a one-key action (unless they're already visible)
TogglePageInfoHelper(win);
} break;

case CmdInvertColors: {
gGlobalPrefs->fixedPageUI.invertColors ^= true;
Expand Down

0 comments on commit 653d474

Please sign in to comment.