Add WebGL FPS cap and texture word reveal

This commit is contained in:
2026-06-06 15:37:44 +02:00
parent bc736513d4
commit 431e305df9
5 changed files with 219 additions and 18 deletions
+12 -1
View File
@@ -77,9 +77,12 @@ class BookPaginationModule extends BaseModule {
const layout = this.layoutTextBlock(block, type);
if (!layout?.lines?.length) return;
let blockWordCursor = 0;
cursorLine += layout.topSpaceLines;
layout.lines.forEach((line) => {
const geometry = this.getLineGeometry(cursorLine);
const lineWordCount = line.nodes.filter(node => node?.type === 'box' && node.value).length;
if (!spreads[geometry.spreadIndex]) {
spreads[geometry.spreadIndex] = { index: geometry.spreadIndex, left: [], right: [] };
}
@@ -93,10 +96,13 @@ class BookPaginationModule extends BaseModule {
pageLine: geometry.pageLine,
fontPx: layout.fontPx,
lineHeightPx: layout.lineHeightPx,
fontStyle: layout.fontStyle
fontStyle: layout.fontStyle,
blockWordStart: blockWordCursor
});
blockWordCursor += lineWordCount;
cursorLine += 1;
});
cursorLine += layout.bottomSpaceLines;
});
return spreads.filter(Boolean);
@@ -109,6 +115,8 @@ class BookPaginationModule extends BaseModule {
const typography = this.metrics.typography;
const role = block.role || block.metadata?.role || (type === 'heading' ? 'chapter-heading' : 'body');
const isHeading = type === 'heading' || role === 'chapter-heading' || role === 'section-heading';
const topSpaceLines = role === 'chapter-heading' ? 2 : role === 'section-heading' || block.addTopSpace || block.metadata?.addTopSpace ? 1 : 0;
const bottomSpaceLines = role === 'chapter-heading' || role === 'section-heading' ? 1 : 0;
const lineHeightPx = Math.max(1, Number(this.metrics.typographyLineHeightPx || 1));
const fontPx = Math.max(1, Number(this.metrics.bodyFontSizePx || lineHeightPx / 1.5));
const indent = (isHeading || block.isFirstParagraphInChapter || block.metadata?.isFirstParagraphInChapter || block.addTopSpace)
@@ -123,6 +131,7 @@ class BookPaginationModule extends BaseModule {
measures,
fontSize: `${fontPx}px`,
fontFamily: typography.fontFamily,
fontFeatureSettings: '"kern" on, "liga" on, "onum" on, "pnum" on, "dlig" on, "clig" on, "calt" on',
lineHeightPx,
lineHeight: lineHeightPx / fontPx
});
@@ -133,6 +142,8 @@ class BookPaginationModule extends BaseModule {
fontPx,
lineHeightPx,
fontStyle: isHeading ? 'italic' : 'normal',
topSpaceLines,
bottomSpaceLines,
lines: this.extractLines(layout, {
measures,
lineOffsets,