Skip to content

When displaying RTL vertical epub with cfi specified, offset is shifted #1271

Open
@tjmtmmnk

Description

@tjmtmmnk

Conditions

Problem

Offset is shifted when calling display(cfi).
Screen Shot 2022-04-26 at 18 22 46

Possible Causes

  • When calling display(cfi), DefaultViewManger.display -> DefaultViewManager.moveTo is executed and offset is adjusted.
  • Looking at DefaultViewerManager.next, it executes scrollBy for this.layout.delta in the x direction when ltr and this.layout.height in the y direction when rtl and vertical.
  • On the other hand, for moveTo, if rtl and vertical, it executes scrollTo for distY = Math.floor(offset.top / this. layout.delta) * this.layout.delta;
    • distY = Math.floor(offset.top / this.layout.delta) * this.layout.delta;
    • Therefore, it is not a constant multiple of this.layout.height and is considered to be shifted.

countermeasure

I believe we need to change this.layout.delta in distY = Math.floor(offset.top / this.layout.delta) * this.layout.delta; to this.layout.height.

distY = Math.floor(offset.top / this.layout.delta) * this.layout.delta;
if (distY + this.layout.delta > this.container.scrollHeight) {
distY = this.container.scrollHeight - this.layout.delta;

- distY = Math.floor(offset.top / this.layout.delta) * this.layout.delta;
- if (distY + this.layout.delta > this.container.scrollHeight) {
-  distY = this.container.scrollHeight - this.layout.delta;
}

+ distY = Math.floor(offset.top / this.layout.height) * this.layout.height;
+ if (distY + this.layout.height > this.container.scrollHeight) {
+   distY = this.container.scrollHeight - this.layout.height;
}

Results of measures

before after
before after
  • Confirmed that the offset shift was gone.
  • I also confirmed that for horizontal epub, offset.top < this.layout.delta always holds and distY=0, with no effect.

If this change is considered reasonable I would like to submit a PR. Thank you!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @tjmtmmnk

      Issue actions

        When displaying RTL vertical epub with cfi specified, offset is shifted · Issue #1271 · futurepress/epub.js