Skip to content

Commit

Permalink
Merge pull request #702 from vivliostyle/fix/issue701
Browse files Browse the repository at this point in the history
fix(core): Wrong page counter value when page counter is reset in the previous doc
  • Loading branch information
MurakamiShinyu authored Feb 28, 2021
2 parents d56feda + a4d9e18 commit 9f90253
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/core/src/vivliostyle/epub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2505,8 +2505,10 @@ export class OPFView implements Vgen.CustomRendererFactory {
const isVersoFirstPage = this.spineItems[0]?.instance.isVersoFirstPage;
const previousViewItem = this.spineItems[spineIndex - 1];
let pageNumberOffset: number;
let pageCounterOffset: number;
if (item.startPage !== null) {
pageNumberOffset = item.startPage - 1;
pageCounterOffset = pageNumberOffset;
} else {
if (
spineIndex > 0 &&
Expand All @@ -2523,17 +2525,28 @@ export class OPFView implements Vgen.CustomRendererFactory {
// (odd and even are reversed if isVersoFirstPage is true)
pageNumberOffset++;
}
pageCounterOffset = pageNumberOffset;
} else {
pageNumberOffset = previousViewItem
? previousViewItem.instance.pageNumberOffset +
previousViewItem.pages.length
: 0;
const counters = this.counterStore.currentPageCounters["page"];
pageCounterOffset =
!counters || !counters.length
? pageNumberOffset
: counters[counters.length - 1];

// Note: The "page" counter value differs to the "page-number" value
// if the "page" counter has been reset by counter-reset/increment.
// (Fix for issue #701)
}
if (item.skipPagesBefore !== null) {
pageNumberOffset += item.skipPagesBefore;
pageCounterOffset += item.skipPagesBefore;
}
}
this.counterStore.forceSetPageCounter(pageNumberOffset);
this.counterStore.forceSetPageCounter(pageCounterOffset);
const instance = new OPS.StyleInstance(
style,
xmldoc,
Expand Down

1 comment on commit 9f90253

@vercel
Copy link

@vercel vercel bot commented on 9f90253 Feb 28, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.