From c15d6832a313257cb80e558993b65b98bfc9e805 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Sun, 30 Jun 2024 09:57:05 -0700 Subject: [PATCH] Fix a bug when appending bytes in Book --- code/book.js | 4 +- code/kthoom.js | 114 ++++++++++++++++++++++++++----------------------- 2 files changed, 63 insertions(+), 55 deletions(-) diff --git a/code/book.js b/code/book.js index 6eaebb3d..11140b6a 100644 --- a/code/book.js +++ b/code/book.js @@ -162,9 +162,9 @@ export class Book extends EventTarget { * @param {ArrayBuffer} appendBuffer */ appendBytes(appendBuffer) { - let newBuffer = new Uint8Array(this.#arrayBuffer.length + appendBuffer.length); + let newBuffer = new Uint8Array(this.#arrayBuffer.byteLength + appendBuffer.byteLength); newBuffer.set(this.#arrayBuffer, 0); - newBuffer.set(appendBuffer, this.#arrayBuffer.length); + newBuffer.set(appendBuffer, this.#arrayBuffer.byteLength); this.#arrayBuffer = newBuffer; } diff --git a/code/kthoom.js b/code/kthoom.js index bbd97f14..ad1a033c 100755 --- a/code/kthoom.js +++ b/code/kthoom.js @@ -186,68 +186,76 @@ export class KthoomApp { this.viewMenu_.addEventListener(MenuEventType.ITEM_SELECTED, evt => { const id = evt.item.id; switch (id) { - case 'menu-view-rotate-left': - this.bookViewer_.rotateCounterClockwise(); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-rotate-left': { + this.bookViewer_.rotateCounterClockwise(); + this.saveSettings_(); + closeMainMenu(); + } break; - case 'menu-view-rotate-right': - this.bookViewer_.rotateClockwise(); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-rotate-right': { + this.bookViewer_.rotateClockwise(); + this.saveSettings_(); + closeMainMenu(); + } break; - case 'menu-view-one-page': - this.bookViewer_.setNumPagesInViewer(1); - this.viewMenu_.setMenuItemSelected('menu-view-one-page', true); - this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); - this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-one-page': { + this.bookViewer_.setNumPagesInViewer(1); + this.viewMenu_.setMenuItemSelected('menu-view-one-page', true); + this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); + this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); + this.saveSettings_(); + closeMainMenu(); + } break; - case 'menu-view-two-page': - this.bookViewer_.setNumPagesInViewer(2); - this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-two-page', true); - this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); - this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-two-page': { + this.bookViewer_.setNumPagesInViewer(2); + this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-two-page', true); + this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); + this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); + this.saveSettings_(); + closeMainMenu(); + } break; - case 'menu-view-long-strip': - this.bookViewer_.setNumPagesInViewer(3); - this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-long-strip', true); - this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-long-strip': { + this.bookViewer_.setNumPagesInViewer(3); + this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-long-strip', true); + this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', false); + this.saveSettings_(); + closeMainMenu(); + } break; - case 'menu-view-wide-strip': - this.bookViewer_.setNumPagesInViewer(4); - this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); - this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); - this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', true); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-wide-strip': { + this.bookViewer_.setNumPagesInViewer(4); + this.viewMenu_.setMenuItemSelected('menu-view-one-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-two-page', false); + this.viewMenu_.setMenuItemSelected('menu-view-long-strip', false); + this.viewMenu_.setMenuItemSelected('menu-view-wide-strip', true); + this.saveSettings_(); + closeMainMenu(); + } break; - case HIDE_PANEL_BUTTONS_MENU_ITEM: - this.#togglePanelButtons(); - closeMainMenu(); + case HIDE_PANEL_BUTTONS_MENU_ITEM: { + this.#togglePanelButtons(); + closeMainMenu(); + } break; case 'menu-view-fit-best': case 'menu-view-fit-height': - case 'menu-view-fit-width': - const fitMode = (id === 'menu-view-fit-best' ? FitMode.Best : - id === 'menu-view-fit-height' ? FitMode.Height : - id === 'menu-view-fit-width' ? FitMode.Width : undefined); - this.bookViewer_.setFitMode(fitMode); - this.viewMenu_.setMenuItemSelected('menu-view-fit-best', fitMode === FitMode.Best); - this.viewMenu_.setMenuItemSelected('menu-view-fit-height', fitMode === FitMode.Height); - this.viewMenu_.setMenuItemSelected('menu-view-fit-width', fitMode === FitMode.Width); - this.saveSettings_(); - closeMainMenu(); + case 'menu-view-fit-width': { + const fitMode = (id === 'menu-view-fit-best' ? FitMode.Best : + id === 'menu-view-fit-height' ? FitMode.Height : + id === 'menu-view-fit-width' ? FitMode.Width : undefined); + this.bookViewer_.setFitMode(fitMode); + this.viewMenu_.setMenuItemSelected('menu-view-fit-best', fitMode === FitMode.Best); + this.viewMenu_.setMenuItemSelected('menu-view-fit-height', fitMode === FitMode.Height); + this.viewMenu_.setMenuItemSelected('menu-view-fit-width', fitMode === FitMode.Width); + this.saveSettings_(); + closeMainMenu(); + } break; } });