Skip to content

Center pdf manual zoom mode#10246

Merged
Frenzie merged 3 commits into
koreader:masterfrom
nairyosangha:center_pdf_manual_zoom_mode
Mar 31, 2023
Merged

Center pdf manual zoom mode#10246
Frenzie merged 3 commits into
koreader:masterfrom
nairyosangha:center_pdf_manual_zoom_mode

Conversation

@nairyosangha

@nairyosangha nairyosangha commented Mar 25, 2023

Copy link
Copy Markdown
Contributor

Should fix #9967
I noticed it was done in a similar way here for paged mode:

if self.dimen.w > self.visible_area.w then
self.state.offset.x = (self.dimen.w - self.visible_area.w) / 2
end

Two things I've noticed, and don't know whether it's intentional, so I didn't touch it:

  • when in cont scroll mode, switching to manual zoom resets it back to paged mode
  • y page offset is always set to 0. If I'm in cont scroll mode, and 2 pages are displayed on the screen, the second page should have a non 0 y offset I would think

This change is Reviewable

@nairyosangha

Copy link
Copy Markdown
Contributor Author

I realized calling the offset passed into getNext/PrevPageState 'image_offset' isn't quite right, it doesn't really have anything to do with images, but I wanted to differ from the page_offset I created within the functions.

As I understand it:

  • image_offset represents the offset of the top of the page(s) that are displayed on screen. e.g. if you're reading a PDF and you closed it with the bottom half of page 80 being displayed on screen, it should show that same area of page 80 again when you reopen it
  • page_offset represents the offset of the top left of the screen
    So maybe I should call them page_offset and screen_offset respectively?

@Frenzie Frenzie added the bug label Mar 25, 2023
@Frenzie Frenzie added this to the 2023.04 milestone Mar 25, 2023
@Frenzie

Frenzie commented Mar 25, 2023

Copy link
Copy Markdown
Member

The spec says it expects an offset of x = 0 and now it's changed to 17. Given what it's testing I have to say 17 sounds a bit suspicious?

spec/front/unit/readerlink_spec.lua:187: Expected objects to be the same.
Passed in:
(table: 0x7f6cc6ef34d8) {
 *[1] = {
    [gamma] = 1
   *[offset] = {
     *[x] = 17
      [y] = 0 }
    [page] = 3
    [page_area] = {
      [h] = 800
      [w] = 566
      [x] = 0
      [y] = 0 }
    [rotation] = 0
    [visible_area] = {
      [h] = 106
      [w] = 566
      [x] = 0
      [y] = 694 }
    [zoom] = 0.95032191328269044472 }
  [2] = {
    [gamma] = 1
    [offset] = {
      [x] = 17
      [y] = 0 }
    [page] = 4
    [page_area] = {
      [h] = 800
      [w] = 566
      [x] = 0
      [y] = 0 }
    [rotation] = 0
    [visible_area] = {
      [h] = 686
      [w] = 566
      [x] = 0
      [y] = 0 }
    [zoom] = 0.95032191328269044472 } }
Expected:
(table: 0x7f6cc77672a0) {
 *[1] = {
    [gamma] = 1
   *[offset] = {
     *[x] = 0
      [y] = 0 }
    [page] = 3
    [page_area] = {
      [h] = 800
      [w] = 566
      [x] = 0
      [y] = 0 }
    [rotation] = 0
    [visible_area] = {
      [h] = 106
      [w] = 566
      [x] = 0
      [y] = 694 }
    [zoom] = 0.95032191328269044472 }
  [2] = {
    [gamma] = 1
    [offset] = {
      [x] = 0
      [y] = 0 }
    [page] = 4
    [page_area] = {
      [h] = 800
      [w] = 566
      [x] = 0
      [y] = 0 }
    [rotation] = 0
    [visible_area] = {
      [h] = 686
      [w] = 566
      [x] = 0
      [y] = 0 }
    [zoom] = 0.95032191328269044472 } }

@nairyosangha

Copy link
Copy Markdown
Contributor Author

I'm wondering if it's actually wrong though 🤔 It seems like the problem described in the issue also occurs when the zoom is set to 'page'.

e.g. with the current code on master, zoom mode displayed, view mode set to 'page':
image
same zoom mode, but view mode set to continuous:
image

It looks like the test expects it to look like that, but isn't it better if that's centered as well? If not, it's easily remedied by checking whether the zoom_mode is set to manual

@Frenzie

Frenzie commented Mar 26, 2023

Copy link
Copy Markdown
Member

I overlooked that it was setting scoll mode along the way. In that case the test should be updated, but please double check and double check some more.

@nairyosangha

Copy link
Copy Markdown
Contributor Author

Messed around with it a bit more, trying different zoom/page modes, it seems fine to me.

I did notice one thing that doesn't seem to work:
image
If I put the zoom mode like this, and then set it the view mode to continuous scroll, it will only scroll down, as if there's only one column, even though there's content off to the right which it should show first. This works fine in page mode.

This is already the case on master as well, so it wasn't introduced here

@Frenzie Frenzie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@poire-z

poire-z commented Mar 31, 2023

Copy link
Copy Markdown
Contributor

Can't really say anything about this PR (rarely reading PDF, so I don't really know what we got and expect and will get with this - and not familiar at all with the code impacted by the changes).

@Frenzie Frenzie merged commit 983e083 into koreader:master Mar 31, 2023
@NiLuJe

NiLuJe commented Mar 31, 2023

Copy link
Copy Markdown
Member

Same, the offset stuff drove me mad the last time I attempted to figure it out, but this seems sensible enough ;).

@molivier-io

Copy link
Copy Markdown

I tried the latest nightly build and your patch works very well. 👌
Thank you, the issue was disturbing when reading PDF in horizontal mode.

TranHHoang added a commit to TranHHoang/koreader that referenced this pull request May 26, 2023
KOReader 2023.04 "Solar Panel"

![koreader-2023-04-fs8](https://user-images.githubusercontent.com/202757/234975122-d7739c71-74aa-4cb0-a086-72a4bba70f52.png)

It's been another busy month squashing many bugs. Our Mac users will be happy to hear that I told macOS we've supported HiDPI since long before anyone came up with such terminology (koreader#10341), and that the program can now natively build on M1 devices (koreader#10291).

Solar panel credit: <https://openclipart.org/detail/294030/solar-energy> by gnokii

We'd like to thank all contributors for their efforts. Some highlights since the previous release include:

* Readerzooming: fix use of default settings (koreader#10205) @hius07
* ButtonDialog/ButtonDialogTitle: consistent 'width' handling (koreader#10230) @poire-z
* MovableContainer: add support for anchoring initial position (koreader#10230) @poire-z
* Book map, Page browser: add top left menu (koreader#10230) @poire-z
* Book style tweak: add button with CSS suggestions (koreader#10230) @poire-z
* crengine: fix parsing of multibytes encodings (koreader#10230) @poire-z
* readerstyletweak: update profiles on unregistering in dispatcher (koreader#10247) @hius07
* Filesearcher: add search in book metadata (koreader#10198) @hius07
* Fix: Updated legacy directory, which crashed the program (koreader#10260) @Mochitto
* ReaderLink: allow a forward location stack (koreader#10228) @yparitcher
* BookInfo: add page information (koreader#10255) @hius07
* Center pdf manual zoom mode (koreader#10246) @nairyosangha
* File browser: add Folder Menu (koreader#10275) @hius07
* Calendar view: add options to change start time of days (koreader#10254) @weijiuqiao
* filechooser: fix crash on "unreadable content" (koreader#10283) @hius07
* Sync book statistics: add to dispatcher (koreader#10285) @ptrm
* [plugin] Exporter: use util.getSafeFilename() to remove illegal characters from output filename (koreader#10282) @Mochitto
* readerbookmark: fix writing pdf annotation (koreader#10287) @hius07
* Folder Menu: sign for Home folder (koreader#10288) @hius07
* ListMenu: show mark for books with highlights (koreader#10276) @hius07
* Calendar view's day view: thicker separator at 00:00 (koreader#10289) @poire-z
* PageBrowser: tweak scrolling behaviour at book start/end (koreader#10289) @poire-z
* Make `kodev check` feature complete (koreader#8682) @yparitcher
* macOS: support for M1 building (koreader#10291) @ptrm
* Reader: do not apply font size and spacing out of range (koreader#10295, koreader#10307) @hius07
* File browser: show Folder Menu on long-press on Home icon (koreader#10298) @hius07
* SSH.koplugin: fix cant stop SSH server bug when pid file's stale (koreader#10300) @weijiuqiao
* PM: Optimize task queue handling around standby (koreader#10203) @zwim
* statistic.koplugin: fix today's timeline showing next day when within custom offset (koreader#10299) @weijiuqiao
* ReaderThumbnails: update cached page thumbnail on bookmark note change (koreader#10303) @hius07
* SDL: add multitouch support (koreader#10334) @Frenzie
* SDL: add HiDPI support (koreader#10341) @Frenzie
* BookInfo: fix crash on show cover (koreader#10315) @hius07
* Deal with table.pack corner-cases properly (koreader#10350) @NiLuJe
* Android: add Tagus Gea support (<koreader/android-luajit-launcher#412>) @Alfedi

[Full changelog](koreader/koreader@v2023.03...v2023.04) — [closed milestone issues](https://github.com/koreader/koreader/milestone/63?closed=1)

---

Installation instructions: [Android](https://github.com/koreader/koreader/wiki/Installation-on-Android-devices) • [Cervantes](https://github.com/koreader/koreader/wiki/Installation-on-BQ-devices) • [ChromeOS](https://github.com/koreader/koreader/wiki/Installation-on-Chromebook-devices) • [Kindle](https://github.com/koreader/koreader/wiki/Installation-on-Kindle-devices) • [Kobo](https://github.com/koreader/koreader/wiki/Installation-on-Kobo-devices) • [PocketBook](https://github.com/koreader/koreader/wiki/Installation-on-PocketBook-devices) • [ReMarkable](https://github.com/koreader/koreader/wiki/Installation-on-ReMarkable) • [Desktop Linux](https://github.com/koreader/koreader/wiki/Installation-on-desktop-linux) • [MacOS](https://github.com/koreader/koreader/wiki/Installation-on-MacOS)
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Center PDF content when its width is smaller than the screen

fix koreader#9967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Center PDF when using Zoom facter

5 participants