postext 1.102.1 → 1.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/__tests__/annotate/anchors.test.d.ts +2 -0
- package/dist/__tests__/annotate/anchors.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/anchors.test.js +161 -0
- package/dist/__tests__/annotate/anchors.test.js.map +1 -0
- package/dist/__tests__/annotate/fontPx.test.d.ts +2 -0
- package/dist/__tests__/annotate/fontPx.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/fontPx.test.js +25 -0
- package/dist/__tests__/annotate/fontPx.test.js.map +1 -0
- package/dist/__tests__/annotate/marks.test.d.ts +2 -0
- package/dist/__tests__/annotate/marks.test.d.ts.map +1 -0
- package/dist/__tests__/annotate/marks.test.js +205 -0
- package/dist/__tests__/annotate/marks.test.js.map +1 -0
- package/dist/__tests__/exports.test.js +8 -0
- package/dist/__tests__/exports.test.js.map +1 -1
- package/dist/__tests__/geometry/rangeGeometry.test.d.ts +2 -0
- package/dist/__tests__/geometry/rangeGeometry.test.d.ts.map +1 -0
- package/dist/__tests__/geometry/rangeGeometry.test.js +167 -0
- package/dist/__tests__/geometry/rangeGeometry.test.js.map +1 -0
- package/dist/__tests__/paint/pageTransform.test.d.ts +2 -0
- package/dist/__tests__/paint/pageTransform.test.d.ts.map +1 -0
- package/dist/__tests__/paint/pageTransform.test.js +39 -0
- package/dist/__tests__/paint/pageTransform.test.js.map +1 -0
- package/dist/annotate/anchors.d.ts +70 -0
- package/dist/annotate/anchors.d.ts.map +1 -0
- package/dist/annotate/anchors.js +99 -0
- package/dist/annotate/anchors.js.map +1 -0
- package/dist/annotate/edits.d.ts +52 -0
- package/dist/annotate/edits.d.ts.map +1 -0
- package/dist/annotate/edits.js +84 -0
- package/dist/annotate/edits.js.map +1 -0
- package/dist/annotate/index.d.ts +17 -0
- package/dist/annotate/index.d.ts.map +1 -0
- package/dist/annotate/index.js +13 -0
- package/dist/annotate/index.js.map +1 -0
- package/dist/annotate/marks.d.ts +103 -0
- package/dist/annotate/marks.d.ts.map +1 -0
- package/dist/annotate/marks.js +398 -0
- package/dist/annotate/marks.js.map +1 -0
- package/dist/annotate/paint.d.ts +58 -0
- package/dist/annotate/paint.d.ts.map +1 -0
- package/dist/annotate/paint.js +130 -0
- package/dist/annotate/paint.js.map +1 -0
- package/dist/canvas-backend/index.d.ts.map +1 -1
- package/dist/canvas-backend/index.js +3 -0
- package/dist/canvas-backend/index.js.map +1 -1
- package/dist/geometry/balloonText.d.ts +75 -0
- package/dist/geometry/balloonText.d.ts.map +1 -0
- package/dist/geometry/balloonText.js +266 -0
- package/dist/geometry/balloonText.js.map +1 -0
- package/dist/geometry/bandTitle.d.ts +53 -0
- package/dist/geometry/bandTitle.d.ts.map +1 -0
- package/dist/geometry/bandTitle.js +171 -0
- package/dist/geometry/bandTitle.js.map +1 -0
- package/dist/geometry/caret.d.ts +23 -0
- package/dist/geometry/caret.d.ts.map +1 -0
- package/dist/geometry/caret.js +62 -0
- package/dist/geometry/caret.js.map +1 -0
- package/dist/geometry/fontPx.d.ts +15 -0
- package/dist/geometry/fontPx.d.ts.map +1 -0
- package/dist/geometry/fontPx.js +38 -0
- package/dist/geometry/fontPx.js.map +1 -0
- package/dist/geometry/frameSpace.d.ts +31 -0
- package/dist/geometry/frameSpace.d.ts.map +1 -0
- package/dist/geometry/frameSpace.js +68 -0
- package/dist/geometry/frameSpace.js.map +1 -0
- package/dist/geometry/hitTest.d.ts +46 -0
- package/dist/geometry/hitTest.d.ts.map +1 -0
- package/dist/geometry/hitTest.js +162 -0
- package/dist/geometry/hitTest.js.map +1 -0
- package/dist/geometry/index.d.ts +25 -0
- package/dist/geometry/index.d.ts.map +1 -0
- package/dist/geometry/index.js +18 -0
- package/dist/geometry/index.js.map +1 -0
- package/dist/geometry/measureLanguage.d.ts +17 -0
- package/dist/geometry/measureLanguage.d.ts.map +1 -0
- package/dist/geometry/measureLanguage.js +116 -0
- package/dist/geometry/measureLanguage.js.map +1 -0
- package/dist/geometry/placement.d.ts +64 -0
- package/dist/geometry/placement.d.ts.map +1 -0
- package/dist/geometry/placement.js +158 -0
- package/dist/geometry/placement.js.map +1 -0
- package/dist/geometry/rangeGeometry.d.ts +147 -0
- package/dist/geometry/rangeGeometry.d.ts.map +1 -0
- package/dist/geometry/rangeGeometry.js +352 -0
- package/dist/geometry/rangeGeometry.js.map +1 -0
- package/dist/geometry/segmentText.d.ts +57 -0
- package/dist/geometry/segmentText.d.ts.map +1 -0
- package/dist/geometry/segmentText.js +145 -0
- package/dist/geometry/segmentText.js.map +1 -0
- package/dist/geometry/textGeometry.d.ts +59 -0
- package/dist/geometry/textGeometry.d.ts.map +1 -0
- package/dist/geometry/textGeometry.js +336 -0
- package/dist/geometry/textGeometry.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// What lies under a pixel of a page: a design image, a reference, a link,
|
|
2
|
+
// a segment or a page target (#1276: split out of geometry.ts).
|
|
3
|
+
import { pageToFlow, resourceBlockToLocal } from '../vdt.js';
|
|
4
|
+
import { blockFrameMatrix, intoBlockSpace, blockPointShown } from './frameSpace.js';
|
|
5
|
+
import { findResourceLocation, resourceBlocksOnPage, segmentInResourceLines, segmentInBlockLine } from './placement.js';
|
|
6
|
+
/**
|
|
7
|
+
* The image a design slot draws under a page pixel — an opener band's cover
|
|
8
|
+
* picture, a header logo, an advanced heading design's plate — as the blob
|
|
9
|
+
* id the block was resolved to, or null when none is there. Slots paint in
|
|
10
|
+
* order (in-column overlays, then the opener band, header and footer) and
|
|
11
|
+
* later blocks over earlier ones, so the last hit wins. The point is on the
|
|
12
|
+
* sheet: on a vertical page it is turned into the flow frame for every slot
|
|
13
|
+
* but the header and the footer.
|
|
14
|
+
*/
|
|
15
|
+
export function designImageFileIdAtPixel(doc, pageIndex, xPage, yPage) {
|
|
16
|
+
const page = doc.pages[pageIndex];
|
|
17
|
+
if (!page)
|
|
18
|
+
return null;
|
|
19
|
+
const slots = [];
|
|
20
|
+
const flow = pageToFlow(page, xPage, yPage);
|
|
21
|
+
// An overlay is painted in its block's composed frame, if any (#910).
|
|
22
|
+
const inFrame = new Map();
|
|
23
|
+
for (const b of doc.blocks) {
|
|
24
|
+
if (b.pageIndex !== pageIndex || !b.designOverlay)
|
|
25
|
+
continue;
|
|
26
|
+
slots.push(b.designOverlay);
|
|
27
|
+
const m = blockFrameMatrix(page, b.id);
|
|
28
|
+
if (m)
|
|
29
|
+
inFrame.set(b.designOverlay, intoBlockSpace(m, flow.x, flow.y));
|
|
30
|
+
}
|
|
31
|
+
if (page.openerBand)
|
|
32
|
+
slots.push(page.openerBand);
|
|
33
|
+
const sheetSlots = new Set();
|
|
34
|
+
if (page.header) {
|
|
35
|
+
slots.push(page.header);
|
|
36
|
+
sheetSlots.add(page.header);
|
|
37
|
+
}
|
|
38
|
+
if (page.footer) {
|
|
39
|
+
slots.push(page.footer);
|
|
40
|
+
sheetSlots.add(page.footer);
|
|
41
|
+
}
|
|
42
|
+
let hit = null;
|
|
43
|
+
for (const slot of slots) {
|
|
44
|
+
const { x, y } = sheetSlots.has(slot) ? { x: xPage, y: yPage } : inFrame.get(slot) ?? flow;
|
|
45
|
+
for (const block of slot.blocks) {
|
|
46
|
+
if (block.kind !== 'image')
|
|
47
|
+
continue;
|
|
48
|
+
const r = block.bbox;
|
|
49
|
+
if (x >= r.x && x <= r.x + r.width && y >= r.y && y <= r.y + r.height)
|
|
50
|
+
hit = block.fileId;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return hit;
|
|
54
|
+
}
|
|
55
|
+
export function refResourceIdAtPixel(doc, pageIndex, xPage, yPage) {
|
|
56
|
+
const seg = segmentAtPixel(doc, pageIndex, xPage, yPage);
|
|
57
|
+
return seg && !seg.refAnchor ? seg.refResourceId ?? null : null;
|
|
58
|
+
}
|
|
59
|
+
/** The link of the segment at page-space pixel coordinates, or null. */
|
|
60
|
+
export function linkTargetAtPixel(doc, pageIndex, xPage, yPage) {
|
|
61
|
+
const seg = segmentAtPixel(doc, pageIndex, xPage, yPage);
|
|
62
|
+
if (!seg)
|
|
63
|
+
return null;
|
|
64
|
+
if (seg.refResourceId !== undefined) {
|
|
65
|
+
return seg.refAnchor
|
|
66
|
+
? { kind: 'anchor', id: seg.refResourceId, ...(seg.refPageIndex !== undefined ? { pageIndex: seg.refPageIndex } : {}) }
|
|
67
|
+
: { kind: 'resource', id: seg.refResourceId };
|
|
68
|
+
}
|
|
69
|
+
if (seg.footnoteId !== undefined)
|
|
70
|
+
return { kind: 'footnote', id: seg.footnoteId };
|
|
71
|
+
if (seg.pageLink !== undefined)
|
|
72
|
+
return { kind: 'page', pageIndex: seg.pageLink };
|
|
73
|
+
// A link inside the document (`[see](#sec-intro)`, a citation's
|
|
74
|
+
// `#ref-key`) goes to its anchor.
|
|
75
|
+
if (seg.href !== undefined && seg.href.startsWith('#') && seg.href.length > 1)
|
|
76
|
+
return { kind: 'anchor', id: decodeURIComponent(seg.href.slice(1)) };
|
|
77
|
+
if (seg.href !== undefined)
|
|
78
|
+
return { kind: 'url', href: seg.href };
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
/** Where an anchor or a footnote's note landed in `doc` (#265), or null
|
|
82
|
+
* when it is not in this document. */
|
|
83
|
+
export function findLinkLocation(doc, target) {
|
|
84
|
+
if (target.kind === 'resource')
|
|
85
|
+
return findResourceLocation(doc, target.id);
|
|
86
|
+
if (target.kind === 'anchor') {
|
|
87
|
+
const a = doc.anchors?.find((x) => x.id === target.id);
|
|
88
|
+
return a ? { pageIndex: a.pageIndex, x: a.x, y: a.y } : null;
|
|
89
|
+
}
|
|
90
|
+
if (target.kind === 'footnote') {
|
|
91
|
+
const note = doc.blocks.find((b) => b.footnoteNote === target.id && b.pageIndex >= 0 && !b.hidden);
|
|
92
|
+
return note ? { pageIndex: note.pageIndex, x: note.bbox.x, y: note.bbox.y } : null;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/** The segment under page-space pixel coordinates: body text, captions and
|
|
97
|
+
* table cells (float bands included). */
|
|
98
|
+
function segmentAtPixel(doc, pageIndex, xPage, yPage) {
|
|
99
|
+
const candidates = doc.blocks.filter((b) => b.pageIndex === pageIndex && !b.resourceBlock);
|
|
100
|
+
for (const rb of resourceBlocksOnPage(doc, pageIndex))
|
|
101
|
+
candidates.push(rb);
|
|
102
|
+
const page = doc.pages[pageIndex];
|
|
103
|
+
for (const b of candidates) {
|
|
104
|
+
if (b.hidden)
|
|
105
|
+
continue;
|
|
106
|
+
// In the block's composed frame, if any (#910).
|
|
107
|
+
const { x, y } = intoBlockSpace(blockFrameMatrix(page, b.id), xPage, yPage);
|
|
108
|
+
if (!blockPointShown(page, b.id, { x, y }))
|
|
109
|
+
continue;
|
|
110
|
+
if (x < b.bbox.x || x > b.bbox.x + b.bbox.width)
|
|
111
|
+
continue;
|
|
112
|
+
if (y < b.bbox.y || y > b.bbox.y + b.bbox.height)
|
|
113
|
+
continue;
|
|
114
|
+
const rb = b.resourceBlock;
|
|
115
|
+
if (rb) {
|
|
116
|
+
// A rotated block keeps its lines in its upright frame.
|
|
117
|
+
const p = resourceBlockToLocal(rb, x, y);
|
|
118
|
+
const inCaption = segmentInResourceLines(rb.captionLines, p.x, p.y);
|
|
119
|
+
if (inCaption?.refResourceId !== undefined)
|
|
120
|
+
return inCaption;
|
|
121
|
+
if (rb.table) {
|
|
122
|
+
for (const cell of rb.table.cells) {
|
|
123
|
+
const inCell = segmentInResourceLines(cell.lines, p.x, p.y);
|
|
124
|
+
if (inCell?.refResourceId !== undefined)
|
|
125
|
+
return inCell;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
for (const line of b.lines) {
|
|
131
|
+
if (y < line.bbox.y || y > line.bbox.y + line.bbox.height)
|
|
132
|
+
continue;
|
|
133
|
+
const hit = segmentInBlockLine(b, line, x);
|
|
134
|
+
if (hit !== null)
|
|
135
|
+
return hit;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Hit-test a row of the contents (`:::toc`) at page-space pixel
|
|
142
|
+
* coordinates: the book page index the row points at, or null when the
|
|
143
|
+
* click isn't on a row that knows its page.
|
|
144
|
+
*/
|
|
145
|
+
export function pageTargetAtPixel(doc, pageIndex, xPage, yPage) {
|
|
146
|
+
const page = doc.pages[pageIndex];
|
|
147
|
+
for (const b of doc.blocks) {
|
|
148
|
+
if (b.pageIndex !== pageIndex || b.hidden)
|
|
149
|
+
continue;
|
|
150
|
+
const target = b.tocEntry?.pageIndex ?? b.tocPart?.pageIndex;
|
|
151
|
+
if (target === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
const { x, y } = intoBlockSpace(blockFrameMatrix(page, b.id), xPage, yPage);
|
|
154
|
+
if (x < b.bbox.x || x > b.bbox.x + b.bbox.width)
|
|
155
|
+
continue;
|
|
156
|
+
if (y < b.bbox.y || y > b.bbox.y + b.bbox.height)
|
|
157
|
+
continue;
|
|
158
|
+
return target;
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=hitTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hitTest.js","sourceRoot":"","sources":["../../src/geometry/hitTest.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,gEAAgE;AAChE,OAAO,EAAoB,UAAU,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAyB,oBAAoB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB,EA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M;YAAE,SAAS;QACpD,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,IAAI,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,SAAS;QACnC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,cAAc,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5E,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK;YAAE,SAAS;QAC1D,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM;YAAE,SAAS;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `postext/geometry` (#1761): text on the page, read from a laid-out
|
|
3
|
+
* document. The calls a host needs (`rangeRects`, `caretRect`, `caretAt`,
|
|
4
|
+
* `wordAt`, `blockAt`, `wordRangeAt`) are on the main entry too; this
|
|
5
|
+
* entry adds the pieces they are built from, for a host that paints its
|
|
6
|
+
* own caret or selection the way the Sandbox does.
|
|
7
|
+
*/
|
|
8
|
+
export { rangeRects, caretRect, caretAt, blockAt, wordAt, wordRangeAt } from './rangeGeometry.js';
|
|
9
|
+
export type { TextRange, TextRect, TextQuad, TextGeometryOptions, CaretLine, CaretHit, BlockHit, WordRangeOptions } from './rangeGeometry.js';
|
|
10
|
+
export { sourceToPlainIndex, xForPlainInLine, plainRangeInLine, pixelToSourceOffset, sourceHitAt, spaceWidth, lineEndSpaceAdvance } from './textGeometry.js';
|
|
11
|
+
export type { SourceHit } from './textGeometry.js';
|
|
12
|
+
export { segmentPlainLength, opensWithRepeatedHyphen, addsHyphen, foldRefRuns, segmentGraphemeStarts, warichuOffset, xWithinSegment, offsetWithinSegment } from './segmentText.js';
|
|
13
|
+
export type { VDTSegment } from './segmentText.js';
|
|
14
|
+
export { findResourceLocation, segmentInResourceLines, segmentInBlockLine, placeLineSegments, xInPlaced, isMirroredPage, resourceBlocksOnPage } from './placement.js';
|
|
15
|
+
export type { ResourceLocation, PlacedSegment } from './placement.js';
|
|
16
|
+
export { designImageFileIdAtPixel, refResourceIdAtPixel, linkTargetAtPixel, findLinkLocation, pageTargetAtPixel } from './hitTest.js';
|
|
17
|
+
export type { LinkTarget } from './hitTest.js';
|
|
18
|
+
export { bandTitleBlocks, bandTitleOwner, isHiddenUnderBand, bandLineBoxes, bandPrefixX, bandCharAtX, bandPlainToSource, bandSourceToPlain } from './bandTitle.js';
|
|
19
|
+
export type { BandLineBox } from './bandTitle.js';
|
|
20
|
+
export { findCaretBlockIdx, findCarriedCaretBlockIdx } from './caret.js';
|
|
21
|
+
export { blockFrameMatrix, blockPointShown, intoBlockSpace, fromBlockSpace, toBalloonFrame, fromBalloonFrame } from './frameSpace.js';
|
|
22
|
+
export type { FrameAffine, FramePoint, ComposedPageLike } from './frameSpace.js';
|
|
23
|
+
export { documentShapingLanguage, measureInLanguage } from './measureLanguage.js';
|
|
24
|
+
export * from './balloonText.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geometry/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClG,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,mBAAmB,E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BAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAClF,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `postext/geometry` (#1761): text on the page, read from a laid-out
|
|
3
|
+
* document. The calls a host needs (`rangeRects`, `caretRect`, `caretAt`,
|
|
4
|
+
* `wordAt`, `blockAt`, `wordRangeAt`) are on the main entry too; this
|
|
5
|
+
* entry adds the pieces they are built from, for a host that paints its
|
|
6
|
+
* own caret or selection the way the Sandbox does.
|
|
7
|
+
*/
|
|
8
|
+
export { rangeRects, caretRect, caretAt, blockAt, wordAt, wordRangeAt } from './rangeGeometry.js';
|
|
9
|
+
export { sourceToPlainIndex, xForPlainInLine, plainRangeInLine, pixelToSourceOffset, sourceHitAt, spaceWidth, lineEndSpaceAdvance } from './textGeometry.js';
|
|
10
|
+
export { segmentPlainLength, opensWithRepeatedHyphen, addsHyphen, foldRefRuns, segmentGraphemeStarts, warichuOffset, xWithinSegment, offsetWithinSegment } from './segmentText.js';
|
|
11
|
+
export { findResourceLocation, segmentInResourceLines, segmentInBlockLine, placeLineSegments, xInPlaced, isMirroredPage, resourceBlocksOnPage } from './placement.js';
|
|
12
|
+
export { designImageFileIdAtPixel, refResourceIdAtPixel, linkTargetAtPixel, findLinkLocation, pageTargetAtPixel } from './hitTest.js';
|
|
13
|
+
export { bandTitleBlocks, bandTitleOwner, isHiddenUnderBand, bandLineBoxes, bandPrefixX, bandCharAtX, bandPlainToSource, bandSourceToPlain } from './bandTitle.js';
|
|
14
|
+
export { findCaretBlockIdx, findCarriedCaretBlockIdx } from './caret.js';
|
|
15
|
+
export { blockFrameMatrix, blockPointShown, intoBlockSpace, fromBlockSpace, toBalloonFrame, fromBalloonFrame } from './frameSpace.js';
|
|
16
|
+
export { documentShapingLanguage, measureInLanguage } from './measureLanguage.js';
|
|
17
|
+
export * from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,17 @@
|
|
|
1
|
+
import type { VDTDocument } from '../vdt.js';
|
|
2
|
+
/**
|
|
3
|
+
* The language the text of `doc` was measured in and is painted in:
|
|
4
|
+
* undefined for the host's (a document that asks for it), else the
|
|
5
|
+
* document's tag, or the empty string when its locale is no tag.
|
|
6
|
+
*/
|
|
7
|
+
export declare function documentShapingLanguage(doc: Pick<VDTDocument, 'config'>): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The advance of `text` in `font` (a CSS font shorthand), px, measured in
|
|
10
|
+
* `lang`: the language the layout measured the text in and the page
|
|
11
|
+
* paints it in ({@link documentShapingLanguage}). `lang` undefined
|
|
12
|
+
* measures in the host's language, as the Sandbox did before a document
|
|
13
|
+
* could have its own. Null where nothing can measure (no canvas: node,
|
|
14
|
+
* the tests), or when the measure fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare function measureInLanguage(lang: string | undefined, text: string, font: string): number | null;
|
|
17
|
+
//# sourceMappingURL=measureLanguage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureLanguage.d.ts","sourceRoot":"","sources":["../../src/geometry/measureLanguage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AA8B7C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,SAAS,CAO5F;AA0DD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUrG"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { shapingLanguageOf } from '../hyphenation/locale.js';
|
|
2
|
+
/**
|
|
3
|
+
* The language a document's text is measured in, for marks set against
|
|
4
|
+
* the painted page (#770; moved from the Sandbox by #1761).
|
|
5
|
+
*
|
|
6
|
+
* The layout measures every text in one language and the canvas paints in
|
|
7
|
+
* it: the document's own (`bodyText.shapingLanguage: 'document'`, the
|
|
8
|
+
* default since postext 1.30), the host's under `'host'`, which a book
|
|
9
|
+
* stored before keeps. A face answers with other glyphs under a language
|
|
10
|
+
* (Noto Serif SC sets `1` 0.471 em wide in Chinese and 0.55 em in a
|
|
11
|
+
* language it has no forms for; Crimson Pro sets the Catalan dot of `l·l`
|
|
12
|
+
* only in Catalan), so whatever the Sandbox measures to place a mark of
|
|
13
|
+
* its own against the painted page (the caret and the selection of a band
|
|
14
|
+
* title, the character of a balloon under the pointer) is measured in that
|
|
15
|
+
* language too. Measured on Chrome 154, on a page in English: the caret
|
|
16
|
+
* after the `1111` that opens the title of a Chinese book, set in Noto
|
|
17
|
+
* Serif SC at 50 px, stood 11 px past the number, on a context left in the
|
|
18
|
+
* host's language.
|
|
19
|
+
*
|
|
20
|
+
* Most of the Sandbox's geometry needs none of this: the caret, the
|
|
21
|
+
* selection and the hit test of the body text, the captions and the table
|
|
22
|
+
* cells read the places and the widths of the segments the layout
|
|
23
|
+
* measured, and share a segment's width over its characters.
|
|
24
|
+
*/
|
|
25
|
+
/** {@link shapingLanguageOf} of each resolved config: asked on every
|
|
26
|
+
* pointer move and every overlay drawn. */
|
|
27
|
+
const byConfig = new WeakMap();
|
|
28
|
+
/**
|
|
29
|
+
* The language the text of `doc` was measured in and is painted in:
|
|
30
|
+
* undefined for the host's (a document that asks for it), else the
|
|
31
|
+
* document's tag, or the empty string when its locale is no tag.
|
|
32
|
+
*/
|
|
33
|
+
export function documentShapingLanguage(doc) {
|
|
34
|
+
const config = doc.config;
|
|
35
|
+
if (!config)
|
|
36
|
+
return undefined;
|
|
37
|
+
if (byConfig.has(config))
|
|
38
|
+
return byConfig.get(config);
|
|
39
|
+
const lang = shapingLanguageOf(config);
|
|
40
|
+
byConfig.set(config, lang);
|
|
41
|
+
return lang;
|
|
42
|
+
}
|
|
43
|
+
/** A context of the geometry's own, on a canvas never put in the page; null
|
|
44
|
+
* where there is no canvas (node, the tests of other modules). */
|
|
45
|
+
function makeContext() {
|
|
46
|
+
try {
|
|
47
|
+
if (typeof document !== 'undefined')
|
|
48
|
+
return document.createElement('canvas').getContext('2d');
|
|
49
|
+
if (typeof OffscreenCanvas !== 'undefined')
|
|
50
|
+
return new OffscreenCanvas(1, 1).getContext('2d');
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// No canvas here.
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
/** The context of the host's language: left as it comes. */
|
|
58
|
+
let hostContext;
|
|
59
|
+
/** The context of each language measured in. */
|
|
60
|
+
const contexts = new Map();
|
|
61
|
+
/**
|
|
62
|
+
* The context that measures in `lang`: one per language, given its
|
|
63
|
+
* language when it is made and never another.
|
|
64
|
+
*
|
|
65
|
+
* Measured on Chrome 154: a context that measured a text of several words
|
|
66
|
+
* in one language (`2026年的故` in `zh-Hans`) and is then set back to
|
|
67
|
+
* `inherit` answers with the widths of the first language, for that text
|
|
68
|
+
* and for its words (`2026`: 89.24 px at 40 px in Noto Serif SC, where
|
|
69
|
+
* another context left at `inherit` gives 88 px). A context that keeps its
|
|
70
|
+
* language has no such memory, and the engine's own measuring context,
|
|
71
|
+
* which the layout switches from one language to another, is left out of
|
|
72
|
+
* it.
|
|
73
|
+
*
|
|
74
|
+
* The host's context is the one the Sandbox always measured with, its
|
|
75
|
+
* language left alone: a canvas never put in the page has none (on a
|
|
76
|
+
* Chinese page it sets the digits as on an English one), as the layout
|
|
77
|
+
* worker has none. No state is saved on these contexts.
|
|
78
|
+
*/
|
|
79
|
+
function contextIn(lang) {
|
|
80
|
+
if (lang === undefined) {
|
|
81
|
+
if (hostContext === undefined)
|
|
82
|
+
hostContext = makeContext();
|
|
83
|
+
return hostContext;
|
|
84
|
+
}
|
|
85
|
+
let ctx = contexts.get(lang);
|
|
86
|
+
if (ctx === undefined) {
|
|
87
|
+
ctx = makeContext();
|
|
88
|
+
// A browser whose contexts have no language measures as it did.
|
|
89
|
+
if (ctx && 'lang' in ctx)
|
|
90
|
+
ctx.lang = lang;
|
|
91
|
+
contexts.set(lang, ctx);
|
|
92
|
+
}
|
|
93
|
+
return ctx;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The advance of `text` in `font` (a CSS font shorthand), px, measured in
|
|
97
|
+
* `lang`: the language the layout measured the text in and the page
|
|
98
|
+
* paints it in ({@link documentShapingLanguage}). `lang` undefined
|
|
99
|
+
* measures in the host's language, as the Sandbox did before a document
|
|
100
|
+
* could have its own. Null where nothing can measure (no canvas: node,
|
|
101
|
+
* the tests), or when the measure fails.
|
|
102
|
+
*/
|
|
103
|
+
export function measureInLanguage(lang, text, font) {
|
|
104
|
+
const ctx = contextIn(lang);
|
|
105
|
+
if (!ctx)
|
|
106
|
+
return null;
|
|
107
|
+
try {
|
|
108
|
+
ctx.font = font;
|
|
109
|
+
const width = ctx.measureText(text).width;
|
|
110
|
+
return Number.isFinite(width) ? width : null;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=measureLanguage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureLanguage.js","sourceRoot":"","sources":["../../src/geometry/measureLanguage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;4CAC4C;AAC5C,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA8B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAgC;IACtE,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,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CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAwB,EAAE,IAAY,EAAE,IAAY;IACpF,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,IAAI,CAAC;QACH,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;QAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type VDTDocument } from '../vdt.js';
|
|
2
|
+
import { type VDTLine, type VDTSegment, type VDTBlock } from './segmentText.js';
|
|
3
|
+
/** Page-space position of a resource embed (inline block or float band). */
|
|
4
|
+
export interface ResourceLocation {
|
|
5
|
+
pageIndex: number;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Find where a resource ended up in the laid-out document. Inline embeds live
|
|
11
|
+
* in `doc.blocks`; floated resources only exist in their page's float band.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findResourceLocation(doc: VDTDocument, resourceId: string): ResourceLocation | null;
|
|
14
|
+
/** Walk already-positioned resource lines (caption / table cells): segments
|
|
15
|
+
* paint one after another from the line origin at natural widths, in
|
|
16
|
+
* `line.order` when the line holds right-to-left runs. */
|
|
17
|
+
export declare function segmentInResourceLines(lines: VDTLine[], xPage: number, yPage: number): VDTSegment | null;
|
|
18
|
+
/** The segment of a body-text line under `xPage` (flow frame), placed
|
|
19
|
+
* where the renderers paint it (see {@link placeLineSegments}). */
|
|
20
|
+
export declare function segmentInBlockLine(block: VDTBlock, line: VDTLine, xPage: number): VDTSegment | null;
|
|
21
|
+
/**
|
|
22
|
+
* A segment of a line where the renderers paint it, in the page's flow
|
|
23
|
+
* frame: `x` and the advance it gets (`width`, a justified space's share of
|
|
24
|
+
* the slack included), and the plain characters it stands for
|
|
25
|
+
* (`plainStart` is relative to the line). `reversed` says its characters
|
|
26
|
+
* run from its right edge to its left in the flow frame: a right-to-left
|
|
27
|
+
* run on a left-to-right page, or a left-to-right run on a mirrored page,
|
|
28
|
+
* whose flow is the sheet turned about its vertical axis.
|
|
29
|
+
*/
|
|
30
|
+
export interface PlacedSegment {
|
|
31
|
+
seg: VDTSegment;
|
|
32
|
+
x: number;
|
|
33
|
+
width: number;
|
|
34
|
+
plainStart: number;
|
|
35
|
+
plainLen: number;
|
|
36
|
+
reversed: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Where each segment of a body-text line is painted, in logical order,
|
|
40
|
+
* following the canvas line painter: from the line's start (its `measure`
|
|
41
|
+
* span on a block set against its frame), justified lines filling their
|
|
42
|
+
* span, centred and right-aligned lines shifted by their slack (as
|
|
43
|
+
* {@link lineTextAlign} reads the block's alignment), and the segments
|
|
44
|
+
* advancing in `line.order` when the line has one — a line holding
|
|
45
|
+
* right-to-left runs, or any line of a mirrored page. A caret or a click
|
|
46
|
+
* inside a bidi line then lands on the character painted there, not on the
|
|
47
|
+
* one at the same distance from the line's logical start. With `fold`, the
|
|
48
|
+
* runs of one `:ref` painted in pieces are one segment (see
|
|
49
|
+
* {@link foldRefRuns}) spanning all of them. `mirrored`: the line is on a
|
|
50
|
+
* right-to-left page (`pageIsMirrored`). Null for a line without segments.
|
|
51
|
+
*/
|
|
52
|
+
export declare function placeLineSegments(block: VDTBlock, line: VDTLine, mirrored: boolean, fold?: boolean): PlacedSegment[] | null;
|
|
53
|
+
/** The x (flow frame) of plain offset `within` of a placed segment. */
|
|
54
|
+
export declare function xInPlaced(p: PlacedSegment, within: number): number;
|
|
55
|
+
/** Whether page `pageIndex` of `doc` is set right to left in a mirrored
|
|
56
|
+
* flow frame. */
|
|
57
|
+
export declare function isMirroredPage(doc: VDTDocument, pageIndex: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Every visible resource embed painted on a page: inline `::resource` blocks
|
|
60
|
+
* from `doc.blocks` plus the page's float band(s). Float bands may carry
|
|
61
|
+
* non-resource blocks (fixed callouts); only `resourceBlock` carriers count.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resourceBlocksOnPage(doc: VDTDocument, pageIndex: number): VDTBlock[];
|
|
64
|
+
//# sourceMappingURL=placement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/geometry/placement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAiC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAA2E,MAAM,kBAAkB,CAAC;AAEzJ,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,GACjB,gBAAgB,GAAG,IAAI,CAczB;AAED;;2DAE2D;AAC3D,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EAAE,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,UAAU,GAAG,IAAI,CAenB;AAED;oEACoE;AACpE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,GACZ,UAAU,GAAG,IAAI,CAKnB;AASD;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,UAAU,CAAC;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,UAAO,GAAG,aAAa,EAAE,GAAG,IAAI,CAmDxH;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED;kBACkB;AAClB,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAG3E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE,CASpF"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Where things sit on a page: a resource's location, the segments of a
|
|
2
|
+
// line placed in paint order, mirrored pages and a page's resource blocks
|
|
3
|
+
// (#1276: split out of geometry.ts).
|
|
4
|
+
import { lineTextAlign, pageIsMirrored } from '../vdt.js';
|
|
5
|
+
import { segmentPlainLength, addsHyphen, opensWithRepeatedHyphen, xWithinSegment } from './segmentText.js';
|
|
6
|
+
/**
|
|
7
|
+
* Find where a resource ended up in the laid-out document. Inline embeds live
|
|
8
|
+
* in `doc.blocks`; floated resources only exist in their page's float band.
|
|
9
|
+
*/
|
|
10
|
+
export function findResourceLocation(doc, resourceId) {
|
|
11
|
+
for (const b of doc.blocks) {
|
|
12
|
+
if (b.resourceBlock?.resource.id === resourceId) {
|
|
13
|
+
return { pageIndex: b.pageIndex, x: b.bbox.x, y: b.bbox.y };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const page of doc.pages) {
|
|
17
|
+
for (const fb of page.floats ?? []) {
|
|
18
|
+
if (fb.resourceBlock?.resource.id === resourceId) {
|
|
19
|
+
return { pageIndex: page.index, x: fb.bbox.x, y: fb.bbox.y };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/** Walk already-positioned resource lines (caption / table cells): segments
|
|
26
|
+
* paint one after another from the line origin at natural widths, in
|
|
27
|
+
* `line.order` when the line holds right-to-left runs. */
|
|
28
|
+
export function segmentInResourceLines(lines, xPage, yPage) {
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
if (yPage < line.bbox.y || yPage > line.bbox.y + line.bbox.height)
|
|
31
|
+
continue;
|
|
32
|
+
const segs = line.segments;
|
|
33
|
+
if (!segs)
|
|
34
|
+
continue;
|
|
35
|
+
let x = line.bbox.x;
|
|
36
|
+
for (const i of paintOrder(line, segs.length)) {
|
|
37
|
+
const seg = segs[i];
|
|
38
|
+
if (xPage >= x && xPage <= x + seg.width) {
|
|
39
|
+
return seg;
|
|
40
|
+
}
|
|
41
|
+
x += seg.width;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/** The segment of a body-text line under `xPage` (flow frame), placed
|
|
47
|
+
* where the renderers paint it (see {@link placeLineSegments}). */
|
|
48
|
+
export function segmentInBlockLine(block, line, xPage) {
|
|
49
|
+
for (const p of placeLineSegments(block, line, false, false) ?? []) {
|
|
50
|
+
if (xPage >= p.x && xPage <= p.x + p.width)
|
|
51
|
+
return p.seg;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/** The indices of `n` segments in the order the renderers advance through
|
|
56
|
+
* them: `line.order` when it lists them all, else logical order. */
|
|
57
|
+
function paintOrder(line, n) {
|
|
58
|
+
if (line.order && line.order.length === n)
|
|
59
|
+
return line.order;
|
|
60
|
+
return Array.from({ length: n }, (_, i) => i);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Where each segment of a body-text line is painted, in logical order,
|
|
64
|
+
* following the canvas line painter: from the line's start (its `measure`
|
|
65
|
+
* span on a block set against its frame), justified lines filling their
|
|
66
|
+
* span, centred and right-aligned lines shifted by their slack (as
|
|
67
|
+
* {@link lineTextAlign} reads the block's alignment), and the segments
|
|
68
|
+
* advancing in `line.order` when the line has one — a line holding
|
|
69
|
+
* right-to-left runs, or any line of a mirrored page. A caret or a click
|
|
70
|
+
* inside a bidi line then lands on the character painted there, not on the
|
|
71
|
+
* one at the same distance from the line's logical start. With `fold`, the
|
|
72
|
+
* runs of one `:ref` painted in pieces are one segment (see
|
|
73
|
+
* {@link foldRefRuns}) spanning all of them. `mirrored`: the line is on a
|
|
74
|
+
* right-to-left page (`pageIsMirrored`). Null for a line without segments.
|
|
75
|
+
*/
|
|
76
|
+
export function placeLineSegments(block, line, mirrored, fold = true) {
|
|
77
|
+
const segs = line.segments;
|
|
78
|
+
if (!segs || segs.length === 0)
|
|
79
|
+
return null;
|
|
80
|
+
const span = line.measure;
|
|
81
|
+
const lineX = span ? span.x : line.bbox.x;
|
|
82
|
+
const effectiveWidth = span ? span.width : block.bbox.x + block.bbox.width - lineX;
|
|
83
|
+
let naturalWidth = 0;
|
|
84
|
+
let wordWidth = 0;
|
|
85
|
+
let spaceCount = 0;
|
|
86
|
+
for (const seg of segs) {
|
|
87
|
+
naturalWidth += seg.width;
|
|
88
|
+
if (seg.kind === 'space')
|
|
89
|
+
spaceCount++;
|
|
90
|
+
else
|
|
91
|
+
wordWidth += seg.width;
|
|
92
|
+
}
|
|
93
|
+
// A line set ragged inside a justified paragraph (a loose CJK line, a
|
|
94
|
+
// line a URL left unfillable) is painted at its natural width; an
|
|
95
|
+
// overfull last line has its spaces compressed to the measure. A line
|
|
96
|
+
// holding a tab stop is set as measured (#622).
|
|
97
|
+
const justify = block.textAlign === 'justify' && spaceCount > 0 && !line.tabbed
|
|
98
|
+
&& ((line.isLastLine === false && !line.ragged) || naturalWidth > effectiveWidth);
|
|
99
|
+
const spaceWidth = justify ? (effectiveWidth - wordWidth) / spaceCount : undefined;
|
|
100
|
+
const align = lineTextAlign(line, block.textAlign);
|
|
101
|
+
const slack = Math.max(0, effectiveWidth - naturalWidth);
|
|
102
|
+
const start = lineX + (justify ? 0 : align === 'center' ? slack / 2 : align === 'right' ? slack : 0);
|
|
103
|
+
const xs = new Array(segs.length).fill(start);
|
|
104
|
+
const widths = segs.map((seg) => (seg.kind === 'space' && spaceWidth !== undefined ? spaceWidth : seg.width));
|
|
105
|
+
let x = start;
|
|
106
|
+
for (const i of paintOrder(line, segs.length)) {
|
|
107
|
+
xs[i] = x;
|
|
108
|
+
x += widths[i];
|
|
109
|
+
}
|
|
110
|
+
const out = [];
|
|
111
|
+
const lastIdx = segs.length - 1;
|
|
112
|
+
let cum = 0;
|
|
113
|
+
for (let i = 0; i < segs.length; i++) {
|
|
114
|
+
const seg = segs[i];
|
|
115
|
+
const plainLen = segmentPlainLength(seg, i === lastIdx && addsHyphen(line), opensWithRepeatedHyphen(line, i));
|
|
116
|
+
const last = out[out.length - 1];
|
|
117
|
+
if (fold && seg.refContinues && last && last.seg.refResourceId === seg.refResourceId) {
|
|
118
|
+
// One reference painted in pieces: one box over all of them.
|
|
119
|
+
const left = Math.min(last.x, xs[i]);
|
|
120
|
+
const right = Math.max(last.x + last.width, xs[i] + widths[i]);
|
|
121
|
+
out[out.length - 1] = { ...last, seg: { ...last.seg, text: last.seg.text + seg.text, width: last.seg.width + seg.width }, x: left, width: right - left };
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
out.push({ seg, x: xs[i], width: widths[i], plainStart: cum, plainLen, reversed: (seg.rtl === true) !== mirrored });
|
|
125
|
+
}
|
|
126
|
+
cum += plainLen;
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/** The x (flow frame) of plain offset `within` of a placed segment. */
|
|
131
|
+
export function xInPlaced(p, within) {
|
|
132
|
+
const dx = xWithinSegment(p.seg, within, p.plainLen, p.width);
|
|
133
|
+
return p.reversed ? p.x + p.width - dx : p.x + dx;
|
|
134
|
+
}
|
|
135
|
+
/** Whether page `pageIndex` of `doc` is set right to left in a mirrored
|
|
136
|
+
* flow frame. */
|
|
137
|
+
export function isMirroredPage(doc, pageIndex) {
|
|
138
|
+
const page = doc.pages[pageIndex];
|
|
139
|
+
return page ? pageIsMirrored(page) : false;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Every visible resource embed painted on a page: inline `::resource` blocks
|
|
143
|
+
* from `doc.blocks` plus the page's float band(s). Float bands may carry
|
|
144
|
+
* non-resource blocks (fixed callouts); only `resourceBlock` carriers count.
|
|
145
|
+
*/
|
|
146
|
+
export function resourceBlocksOnPage(doc, pageIndex) {
|
|
147
|
+
const out = [];
|
|
148
|
+
for (const b of doc.blocks) {
|
|
149
|
+
if (b.pageIndex === pageIndex && b.resourceBlock && !b.hidden)
|
|
150
|
+
out.push(b);
|
|
151
|
+
}
|
|
152
|
+
for (const fb of doc.pages[pageIndex]?.floats ?? []) {
|
|
153
|
+
if (fb.resourceBlock && !fb.hidden)
|
|
154
|
+
out.push(fb);
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.js","sourceRoot":"","sources":["../../src/geometry/placement.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,qCAAqC;AACrC,OAAO,EAAoB,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAgD,kBAAkB,EAAE,UAAU,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASzJ;;;GAGG;AACH,MAAM,U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