@itwin/core-backend 5.1.0-dev.60 → 5.1.0-dev.62
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/lib/cjs/ECSqlStatement.d.ts.map +1 -1
- package/lib/cjs/ECSqlStatement.js +1 -0
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +5 -2
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +11 -2
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +6 -4
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/annotations/FrameGeometry.d.ts +1 -2
- package/lib/cjs/annotations/FrameGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/FrameGeometry.js +3 -4
- package/lib/cjs/annotations/FrameGeometry.js.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.d.ts +3 -3
- package/lib/cjs/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.js +17 -8
- package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +148 -10
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +296 -28
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationGeometry.d.ts +3 -1
- package/lib/cjs/annotations/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationGeometry.js +13 -14
- package/lib/cjs/annotations/TextAnnotationGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.d.ts +47 -14
- package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.js +109 -38
- package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +0 -1
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/esm/ECSqlStatement.d.ts.map +1 -1
- package/lib/esm/ECSqlStatement.js +1 -0
- package/lib/esm/ECSqlStatement.js.map +1 -1
- package/lib/esm/IModelDb.d.ts +5 -2
- package/lib/esm/IModelDb.d.ts.map +1 -1
- package/lib/esm/IModelDb.js +11 -2
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/LocalHub.d.ts.map +1 -1
- package/lib/esm/LocalHub.js +6 -4
- package/lib/esm/LocalHub.js.map +1 -1
- package/lib/esm/annotations/FrameGeometry.d.ts +1 -2
- package/lib/esm/annotations/FrameGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/FrameGeometry.js +3 -4
- package/lib/esm/annotations/FrameGeometry.js.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.d.ts +3 -3
- package/lib/esm/annotations/LeaderGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.js +17 -8
- package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +148 -10
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +297 -30
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationGeometry.d.ts +3 -1
- package/lib/esm/annotations/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationGeometry.js +13 -14
- package/lib/esm/annotations/TextAnnotationGeometry.js.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.d.ts +47 -14
- package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.js +107 -37
- package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
- package/lib/esm/rpc-impl/IModelReadRpcImpl.d.ts +1 -1
- package/lib/esm/rpc-impl/IModelReadRpcImpl.js +1 -1
- package/lib/esm/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/esm/test/AnnotationTestUtils.d.ts.map +1 -1
- package/lib/esm/test/AnnotationTestUtils.js +8 -2
- package/lib/esm/test/AnnotationTestUtils.js.map +1 -1
- package/lib/esm/test/annotations/FrameGeometry.test.js +12 -4
- package/lib/esm/test/annotations/FrameGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/LeaderGeometry.test.js +21 -16
- package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +180 -121
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/lib/esm/test/annotations/TextBlock.test.js +249 -142
- package/lib/esm/test/annotations/TextBlock.test.js.map +1 -1
- package/lib/esm/test/standalone/ChangesetReader.test.js +96 -0
- package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
- package/lib/esm/workspace/Workspace.d.ts +0 -1
- package/lib/esm/workspace/Workspace.d.ts.map +1 -1
- package/lib/esm/workspace/Workspace.js.map +1 -1
- package/package.json +17 -16
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { expect } from "chai";
|
|
6
|
-
import { computeGraphemeOffsets, layoutTextBlock } from "../../annotations/TextBlockLayout";
|
|
6
|
+
import { computeGraphemeOffsets, layoutTextBlock, TextStyleResolver } from "../../annotations/TextBlockLayout";
|
|
7
7
|
import { Geometry } from "@itwin/core-geometry";
|
|
8
|
-
import { ColorDef, FontType, FractionRun, LineBreakRun, TabRun, TextAnnotation, TextBlock, TextRun, TextStyleSettings } from "@itwin/core-common";
|
|
8
|
+
import { ColorDef, FontType, FractionRun, LineBreakRun, Paragraph, TabRun, TextAnnotation, TextBlock, TextRun, TextStyleSettings } from "@itwin/core-common";
|
|
9
9
|
import { IModelTestUtils } from "../IModelTestUtils";
|
|
10
10
|
import { ProcessDetector } from "@itwin/core-bentley";
|
|
11
11
|
import { produceTextBlockGeometry } from "../../core-backend";
|
|
12
12
|
import { computeTextRangeAsStringLength, doLayout } from "../AnnotationTestUtils";
|
|
13
|
-
function makeTextRun(content
|
|
14
|
-
return TextRun.create({ content
|
|
13
|
+
function makeTextRun(content) {
|
|
14
|
+
return TextRun.create({ content });
|
|
15
15
|
}
|
|
16
16
|
function isIntlSupported() {
|
|
17
17
|
// Node in the mobile add-on does not include Intl, so this test fails. Right now, mobile
|
|
@@ -19,53 +19,156 @@ function isIntlSupported() {
|
|
|
19
19
|
// solution.
|
|
20
20
|
return !ProcessDetector.isMobileAppBackend;
|
|
21
21
|
}
|
|
22
|
+
function findTextStyleImpl(id) {
|
|
23
|
+
if (id === "0x42") {
|
|
24
|
+
return TextStyleSettings.fromJSON({ lineSpacingFactor: 12, fontName: "block", isBold: true });
|
|
25
|
+
}
|
|
26
|
+
return TextStyleSettings.fromJSON({ lineSpacingFactor: 1, fontName: "other" });
|
|
27
|
+
}
|
|
22
28
|
describe("layoutTextBlock", () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
describe("resolves TextStyleSettings", () => {
|
|
30
|
+
it("inherits styling from TextBlock when Paragraph and Run have no style overrides", () => {
|
|
31
|
+
const textBlock = TextBlock.create({ styleId: "0x42" });
|
|
32
|
+
const run = TextRun.create({ content: "test" });
|
|
33
|
+
textBlock.appendParagraph();
|
|
34
|
+
textBlock.appendRun(run);
|
|
35
|
+
const tb = doLayout(textBlock, {
|
|
36
|
+
findTextStyle: findTextStyleImpl,
|
|
37
|
+
});
|
|
38
|
+
expect(tb.lines.length).to.equal(1);
|
|
39
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
40
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
41
|
+
expect(runStyle.fontName).to.equal("block");
|
|
42
|
+
expect(runStyle.lineSpacingFactor).to.equal(12);
|
|
43
|
+
expect(runStyle.isBold).to.be.true;
|
|
44
|
+
});
|
|
45
|
+
it("inherits style overrides from Paragraph when Run has no style overrides", () => {
|
|
46
|
+
const textBlock = TextBlock.create({ styleId: "0x42" });
|
|
47
|
+
const paragraph = Paragraph.create({ styleOverrides: { fontName: "paragraph" } });
|
|
48
|
+
const run = TextRun.create({ content: "test" });
|
|
49
|
+
textBlock.paragraphs.push(paragraph);
|
|
50
|
+
textBlock.appendRun(run);
|
|
51
|
+
const tb = doLayout(textBlock, {
|
|
52
|
+
findTextStyle: findTextStyleImpl,
|
|
53
|
+
});
|
|
54
|
+
expect(tb.lines.length).to.equal(1);
|
|
55
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
56
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
57
|
+
expect(runStyle.fontName).to.equal("paragraph");
|
|
58
|
+
expect(runStyle.isBold).to.be.true;
|
|
59
|
+
});
|
|
60
|
+
it("uses Run style overrides when Run has overrides", () => {
|
|
61
|
+
const textBlock = TextBlock.create({ styleId: "0x42" });
|
|
62
|
+
const paragraph = Paragraph.create({ styleOverrides: { lineSpacingFactor: 55, fontName: "paragraph" } });
|
|
63
|
+
const run = TextRun.create({ content: "test", styleOverrides: { lineSpacingFactor: 99, fontName: "run" } });
|
|
64
|
+
textBlock.paragraphs.push(paragraph);
|
|
65
|
+
textBlock.appendRun(run);
|
|
66
|
+
const tb = doLayout(textBlock, {
|
|
67
|
+
findTextStyle: findTextStyleImpl,
|
|
68
|
+
});
|
|
69
|
+
expect(tb.lines.length).to.equal(1);
|
|
70
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
71
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
72
|
+
expect(runStyle.fontName).to.equal("run");
|
|
73
|
+
expect(runStyle.isBold).to.be.true;
|
|
74
|
+
});
|
|
75
|
+
it("still uses TextBlock specific styles when Run has style overrides", () => {
|
|
76
|
+
// Some style settings only make sense on a TextBlock, so they are always applied from the TextBlock, even if the Run has a style override.
|
|
77
|
+
const textBlock = TextBlock.create({ styleId: "0x42" });
|
|
78
|
+
const run = TextRun.create({ content: "test", styleOverrides: { lineSpacingFactor: 99, fontName: "run" } });
|
|
79
|
+
textBlock.appendParagraph();
|
|
80
|
+
textBlock.appendRun(run);
|
|
81
|
+
const tb = doLayout(textBlock, {
|
|
82
|
+
findTextStyle: findTextStyleImpl,
|
|
83
|
+
});
|
|
84
|
+
expect(tb.lines.length).to.equal(1);
|
|
85
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
86
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
87
|
+
expect(runStyle.lineSpacingFactor).to.equal(12);
|
|
88
|
+
});
|
|
89
|
+
it("inherits overrides from TextBlock, Paragraph and Run when there is no styleId", () => {
|
|
90
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { widthFactor: 34, lineHeight: 3, lineSpacingFactor: 12, isBold: true } });
|
|
91
|
+
const paragraph = Paragraph.create({ styleOverrides: { lineHeight: 56, color: 0xff0000, frame: { shape: "octagon" } } });
|
|
92
|
+
const run = TextRun.create({ content: "test", styleOverrides: { widthFactor: 78, fontName: "override", leader: { wantElbow: true } } });
|
|
93
|
+
textBlock.paragraphs.push(paragraph);
|
|
94
|
+
textBlock.appendRun(run);
|
|
95
|
+
const tb = doLayout(textBlock, {
|
|
96
|
+
findTextStyle: findTextStyleImpl,
|
|
97
|
+
});
|
|
98
|
+
expect(tb.lines.length).to.equal(1);
|
|
99
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
100
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
101
|
+
// widthFactor is always taken from the TextBlock, even if the Run has overrides
|
|
102
|
+
expect(runStyle.widthFactor).to.equal(34);
|
|
103
|
+
// lineHeight is always taken from the TextBlock, even if the Run has overrides
|
|
104
|
+
expect(runStyle.lineHeight).to.equal(3);
|
|
105
|
+
// lineSpacingFactor is always taken from the TextBlock, even if the Run has overrides
|
|
106
|
+
expect(runStyle.lineSpacingFactor).to.equal(12);
|
|
107
|
+
// frame settings are always taken from the TextBlock, even if the Paragraph or Run has overrides
|
|
108
|
+
expect(runStyle.frame.shape).to.equal("none");
|
|
109
|
+
// leader settings are always taken from the TextBlock, even if the Paragraph or Run has overrides
|
|
110
|
+
expect(runStyle.leader.wantElbow).to.be.false;
|
|
111
|
+
expect(runStyle.fontName).to.equal("override");
|
|
112
|
+
expect(runStyle.color).to.equal(0xff0000);
|
|
113
|
+
expect(runStyle.isBold).to.be.true;
|
|
114
|
+
});
|
|
115
|
+
it("does not inherit overrides in TextBlock or Paragraph when Run has same propertied overriden - unless they are TextBlock specific settings", () => {
|
|
116
|
+
const textBlock = TextBlock.create({ styleId: "0x42", styleOverrides: { widthFactor: 34, lineHeight: 3, lineSpacingFactor: 12, isBold: true } });
|
|
117
|
+
const paragraph = Paragraph.create({ styleOverrides: { lineHeight: 56, color: 0xff0000 } });
|
|
118
|
+
const run = TextRun.create({ content: "test", styleOverrides: { widthFactor: 78, lineHeight: 6, lineSpacingFactor: 24, fontName: "override", isBold: false } });
|
|
119
|
+
textBlock.paragraphs.push(paragraph);
|
|
120
|
+
textBlock.appendRun(run);
|
|
121
|
+
const tb = doLayout(textBlock, {
|
|
122
|
+
findTextStyle: findTextStyleImpl,
|
|
123
|
+
});
|
|
124
|
+
expect(tb.lines.length).to.equal(1);
|
|
125
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
126
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
127
|
+
// widthFactor is always taken from the TextBlock, even if the Run has a styleId or overrides
|
|
128
|
+
expect(runStyle.widthFactor).to.equal(34);
|
|
129
|
+
// lineHeight is always taken from the TextBlock, even if the Run has a styleId or overrides
|
|
130
|
+
expect(runStyle.lineHeight).to.equal(3);
|
|
131
|
+
// lineSpacingFactor is always taken from the TextBlock, even if the Run has a styleId or overrides
|
|
132
|
+
expect(runStyle.lineSpacingFactor).to.equal(12);
|
|
133
|
+
expect(runStyle.fontName).to.equal("override");
|
|
134
|
+
expect(runStyle.color).to.equal(0xff0000);
|
|
135
|
+
expect(runStyle.isBold).to.be.false;
|
|
136
|
+
});
|
|
137
|
+
it("takes child overrides over parent overrides", () => {
|
|
138
|
+
//...unless they are TextBlock specific as covered in other tests
|
|
139
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { fontName: "grandparent" } });
|
|
140
|
+
const paragraph = Paragraph.create({ styleOverrides: { fontName: "parent" } });
|
|
141
|
+
const run = TextRun.create({ content: "test", styleOverrides: { fontName: "child" } });
|
|
142
|
+
textBlock.paragraphs.push(paragraph);
|
|
143
|
+
textBlock.appendRun(run);
|
|
144
|
+
const tb = doLayout(textBlock, {
|
|
145
|
+
findTextStyle: findTextStyleImpl,
|
|
146
|
+
});
|
|
147
|
+
expect(tb.lines.length).to.equal(1);
|
|
148
|
+
expect(tb.lines[0].runs.length).to.equal(1);
|
|
149
|
+
const runStyle = tb.lines[0].runs[0].style;
|
|
150
|
+
expect(runStyle.fontName).to.equal("child");
|
|
31
151
|
});
|
|
32
|
-
expect(tb.lines.length).to.equal(1);
|
|
33
|
-
expect(tb.lines[0].runs.length).to.equal(2);
|
|
34
|
-
const s0 = tb.lines[0].runs[0].style;
|
|
35
|
-
expect(s0.lineHeight).to.equal(1);
|
|
36
|
-
expect(s0.lineSpacingFactor).to.equal(12);
|
|
37
|
-
expect(s0.widthFactor).to.equal(34);
|
|
38
|
-
expect(s0.fontName).to.equal("run");
|
|
39
|
-
expect(s0.color).to.equal(0xff0000);
|
|
40
|
-
const s1 = tb.lines[0].runs[1].style;
|
|
41
|
-
expect(s1.widthFactor).to.equal(34);
|
|
42
|
-
expect(s1.lineSpacingFactor).to.equal(12);
|
|
43
|
-
expect(s1.lineHeight).to.equal(1);
|
|
44
|
-
expect(s1.fontName).to.equal("run1");
|
|
45
|
-
expect(s1.color).to.equal("subcategory");
|
|
46
152
|
});
|
|
47
153
|
it("has consistent data when converted to a layout result", function () {
|
|
48
154
|
if (!isIntlSupported()) {
|
|
49
155
|
this.skip();
|
|
50
156
|
}
|
|
51
157
|
// Initialize a new TextBlockLayout object
|
|
52
|
-
const textBlock = TextBlock.create({ width: 50,
|
|
158
|
+
const textBlock = TextBlock.create({ width: 50, styleId: "", styleOverrides: { widthFactor: 34, color: 0x00ff00, fontName: "arial" } });
|
|
53
159
|
const run0 = TextRun.create({
|
|
54
160
|
content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium mi sit amet magna malesuada, at venenatis ante eleifend.",
|
|
55
|
-
styleName: "",
|
|
56
161
|
styleOverrides: { lineHeight: 56, color: 0xff0000 },
|
|
57
162
|
});
|
|
58
163
|
const run1 = TextRun.create({
|
|
59
164
|
content: "Donec sit amet semper sapien. Nullam commodo, libero a accumsan lacinia, metus enim pharetra lacus, eu facilisis sem nisi eu dui.",
|
|
60
|
-
styleName: "",
|
|
61
165
|
styleOverrides: { widthFactor: 78, fontName: "run1" },
|
|
62
166
|
});
|
|
63
167
|
const run2 = TextRun.create({
|
|
64
168
|
content: "Duis dui quam, suscipit quis feugiat id, fermentum ut augue. Mauris iaculis odio rhoncus lorem eleifend, posuere viverra turpis elementum.",
|
|
65
|
-
styleName: "",
|
|
66
169
|
styleOverrides: {},
|
|
67
170
|
});
|
|
68
|
-
const fractionRun = FractionRun.create({ numerator: "num", denominator: "denom",
|
|
171
|
+
const fractionRun = FractionRun.create({ numerator: "num", denominator: "denom", styleOverrides: {} });
|
|
69
172
|
textBlock.appendRun(run0);
|
|
70
173
|
textBlock.appendRun(fractionRun);
|
|
71
174
|
textBlock.appendParagraph();
|
|
@@ -159,7 +262,7 @@ describe("layoutTextBlock", () => {
|
|
|
159
262
|
expect(marginRange.high.y).to.equal(layoutRange.high.y + (margins.top ?? 0));
|
|
160
263
|
};
|
|
161
264
|
const makeTextBlock = (margins) => {
|
|
162
|
-
const textBlock = TextBlock.create({
|
|
265
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineSpacingFactor: 0 }, margins });
|
|
163
266
|
textBlock.appendRun(makeTextRun("abc"));
|
|
164
267
|
textBlock.appendRun(makeTextRun("defg"));
|
|
165
268
|
return textBlock;
|
|
@@ -184,9 +287,9 @@ describe("layoutTextBlock", () => {
|
|
|
184
287
|
});
|
|
185
288
|
describe("range", () => {
|
|
186
289
|
it("aligns text to center based on height of stacked fraction", () => {
|
|
187
|
-
const textBlock = TextBlock.create({
|
|
188
|
-
const fractionRun = FractionRun.create({ numerator: "1", denominator: "2"
|
|
189
|
-
const textRun = TextRun.create({ content: "text"
|
|
290
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
291
|
+
const fractionRun = FractionRun.create({ numerator: "1", denominator: "2" });
|
|
292
|
+
const textRun = TextRun.create({ content: "text" });
|
|
190
293
|
textBlock.appendRun(fractionRun);
|
|
191
294
|
textBlock.appendRun(textRun);
|
|
192
295
|
const layout = doLayout(textBlock);
|
|
@@ -202,7 +305,7 @@ describe("layoutTextBlock", () => {
|
|
|
202
305
|
expect(round(textLayout.offsetFromLine.y, 3)).to.equal(.375);
|
|
203
306
|
});
|
|
204
307
|
it("produces one line per paragraph if document width <= 0", () => {
|
|
205
|
-
const textBlock = TextBlock.create({
|
|
308
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
206
309
|
for (let i = 0; i < 4; i++) {
|
|
207
310
|
const layout = doLayout(textBlock);
|
|
208
311
|
if (i === 0) {
|
|
@@ -233,20 +336,20 @@ describe("layoutTextBlock", () => {
|
|
|
233
336
|
}
|
|
234
337
|
const p = textBlock.appendParagraph();
|
|
235
338
|
for (let j = 0; j <= i; j++) {
|
|
236
|
-
p.runs.push(TextRun.create({
|
|
339
|
+
p.runs.push(TextRun.create({ content: "Run" }));
|
|
237
340
|
}
|
|
238
341
|
}
|
|
239
342
|
});
|
|
240
343
|
it("produces a new line for each LineBreakRun", () => {
|
|
241
344
|
const lineSpacingFactor = 0.5;
|
|
242
345
|
const lineHeight = 1;
|
|
243
|
-
const textBlock = TextBlock.create({
|
|
244
|
-
textBlock.appendRun(TextRun.create({
|
|
245
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
246
|
-
textBlock.appendRun(TextRun.create({
|
|
247
|
-
textBlock.appendRun(TextRun.create({
|
|
248
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
249
|
-
textBlock.appendRun(TextRun.create({
|
|
346
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineSpacingFactor, lineHeight } });
|
|
347
|
+
textBlock.appendRun(TextRun.create({ content: "abc" }));
|
|
348
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
349
|
+
textBlock.appendRun(TextRun.create({ content: "def" }));
|
|
350
|
+
textBlock.appendRun(TextRun.create({ content: "ghi" }));
|
|
351
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
352
|
+
textBlock.appendRun(TextRun.create({ content: "jkl" }));
|
|
250
353
|
const tb = doLayout(textBlock);
|
|
251
354
|
expect(tb.lines.length).to.equal(3);
|
|
252
355
|
expect(tb.lines[0].runs.length).to.equal(2);
|
|
@@ -260,17 +363,16 @@ describe("layoutTextBlock", () => {
|
|
|
260
363
|
it("applies tab shifts", () => {
|
|
261
364
|
const lineHeight = 1;
|
|
262
365
|
const tabInterval = 6;
|
|
263
|
-
const
|
|
264
|
-
const textBlock = TextBlock.create({ styleName, styleOverrides: { lineHeight, tabInterval } });
|
|
366
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineHeight, tabInterval } });
|
|
265
367
|
// Appends a line that looks like `stringOne` TAB `stringTwo` LINEBREAK
|
|
266
368
|
const appendLine = (stringOne, stringTwo, wantLineBreak = true) => {
|
|
267
369
|
if (stringOne.length > 0)
|
|
268
|
-
textBlock.appendRun(TextRun.create({
|
|
269
|
-
textBlock.appendRun(TabRun.create({
|
|
370
|
+
textBlock.appendRun(TextRun.create({ content: stringOne }));
|
|
371
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
270
372
|
if (stringTwo.length > 0)
|
|
271
|
-
textBlock.appendRun(TextRun.create({
|
|
373
|
+
textBlock.appendRun(TextRun.create({ content: stringTwo }));
|
|
272
374
|
if (wantLineBreak)
|
|
273
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
375
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
274
376
|
};
|
|
275
377
|
// The extra whitespace is intentional to show where the tab stops should be.
|
|
276
378
|
appendLine("", "a");
|
|
@@ -293,32 +395,31 @@ describe("layoutTextBlock", () => {
|
|
|
293
395
|
it("applies consecutive tab shifts", () => {
|
|
294
396
|
const lineHeight = 1;
|
|
295
397
|
const tabInterval = 6;
|
|
296
|
-
const
|
|
297
|
-
const textBlock = TextBlock.create({ styleName, styleOverrides: { lineHeight, tabInterval } });
|
|
398
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineHeight, tabInterval } });
|
|
298
399
|
// line 0: ----->----->----->LINEBREAK
|
|
299
|
-
textBlock.appendRun(TabRun.create({
|
|
300
|
-
textBlock.appendRun(TabRun.create({
|
|
301
|
-
textBlock.appendRun(TabRun.create({
|
|
302
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
400
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
401
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
402
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
403
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
303
404
|
// line 1: abc-->----->LINEBREAK
|
|
304
|
-
textBlock.appendRun(TextRun.create({
|
|
305
|
-
textBlock.appendRun(TabRun.create({
|
|
306
|
-
textBlock.appendRun(TabRun.create({
|
|
307
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
405
|
+
textBlock.appendRun(TextRun.create({ content: "abc" }));
|
|
406
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
407
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval } }));
|
|
408
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
308
409
|
// line 2: abc--->->------>LINEBREAK
|
|
309
|
-
textBlock.appendRun(TextRun.create({
|
|
310
|
-
textBlock.appendRun(TabRun.create({
|
|
311
|
-
textBlock.appendRun(TabRun.create({
|
|
312
|
-
textBlock.appendRun(TabRun.create({
|
|
313
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
410
|
+
textBlock.appendRun(TextRun.create({ content: "abc" }));
|
|
411
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
412
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 2 } }));
|
|
413
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
414
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
314
415
|
// line 3: abc--->1/23->abcde->LINEBREAK
|
|
315
|
-
textBlock.appendRun(TextRun.create({
|
|
316
|
-
textBlock.appendRun(TabRun.create({
|
|
317
|
-
textBlock.appendRun(FractionRun.create({
|
|
318
|
-
textBlock.appendRun(TabRun.create({
|
|
319
|
-
textBlock.appendRun(TextRun.create({
|
|
320
|
-
textBlock.appendRun(TabRun.create({
|
|
321
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
416
|
+
textBlock.appendRun(TextRun.create({ content: "abc" }));
|
|
417
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
418
|
+
textBlock.appendRun(FractionRun.create({ numerator: "1", denominator: "23" }));
|
|
419
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
420
|
+
textBlock.appendRun(TextRun.create({ content: "abcde" }));
|
|
421
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
422
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
322
423
|
const tb = doLayout(textBlock);
|
|
323
424
|
const line0 = tb.lines[0];
|
|
324
425
|
const line1 = tb.lines[1];
|
|
@@ -336,13 +437,13 @@ describe("layoutTextBlock", () => {
|
|
|
336
437
|
it("computes ranges based on custom line spacing and line height", () => {
|
|
337
438
|
const lineSpacingFactor = 2;
|
|
338
439
|
const lineHeight = 3;
|
|
339
|
-
const textBlock = TextBlock.create({
|
|
340
|
-
textBlock.appendRun(TextRun.create({
|
|
341
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
342
|
-
textBlock.appendRun(TextRun.create({
|
|
343
|
-
textBlock.appendRun(TextRun.create({
|
|
344
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
345
|
-
textBlock.appendRun(TextRun.create({
|
|
440
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineSpacingFactor, lineHeight } });
|
|
441
|
+
textBlock.appendRun(TextRun.create({ content: "abc" }));
|
|
442
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
443
|
+
textBlock.appendRun(TextRun.create({ content: "def" }));
|
|
444
|
+
textBlock.appendRun(TextRun.create({ content: "ghi" }));
|
|
445
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
446
|
+
textBlock.appendRun(TextRun.create({ content: "jkl" }));
|
|
346
447
|
const tb = doLayout(textBlock);
|
|
347
448
|
expect(tb.lines.length).to.equal(3);
|
|
348
449
|
expect(tb.lines[0].runs.length).to.equal(2);
|
|
@@ -366,7 +467,7 @@ describe("layoutTextBlock", () => {
|
|
|
366
467
|
if (!isIntlSupported()) {
|
|
367
468
|
this.skip();
|
|
368
469
|
}
|
|
369
|
-
const block = TextBlock.create({
|
|
470
|
+
const block = TextBlock.create({ styleId: "", width: 3, styleOverrides: { lineHeight: 1, lineSpacingFactor: 0 } });
|
|
370
471
|
function expectBlockRange(width, height) {
|
|
371
472
|
const layout = doLayout(block);
|
|
372
473
|
expectRange(width, height, layout.range);
|
|
@@ -390,7 +491,7 @@ describe("layoutTextBlock", () => {
|
|
|
390
491
|
if (!isIntlSupported()) {
|
|
391
492
|
this.skip();
|
|
392
493
|
}
|
|
393
|
-
const block = TextBlock.create({
|
|
494
|
+
const block = TextBlock.create({ styleId: "", styleOverrides: { lineHeight: 1, lineSpacingFactor: 0 } });
|
|
394
495
|
function expectBlockRange(width, height) {
|
|
395
496
|
const layout = doLayout(block);
|
|
396
497
|
expectRange(width, height, layout.range);
|
|
@@ -407,7 +508,7 @@ describe("layoutTextBlock", () => {
|
|
|
407
508
|
if (!isIntlSupported()) {
|
|
408
509
|
this.skip();
|
|
409
510
|
}
|
|
410
|
-
const block = TextBlock.create({
|
|
511
|
+
const block = TextBlock.create({ styleId: "", styleOverrides: { lineSpacingFactor: 0 } });
|
|
411
512
|
function expectBlockRange(width, height) {
|
|
412
513
|
const layout = doLayout(block);
|
|
413
514
|
expectRange(width, height, layout.range);
|
|
@@ -481,7 +582,7 @@ describe("layoutTextBlock", () => {
|
|
|
481
582
|
});
|
|
482
583
|
describe("word-wrapping", () => {
|
|
483
584
|
function expectLines(input, width, expectedLines) {
|
|
484
|
-
const textBlock = TextBlock.create({
|
|
585
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
485
586
|
textBlock.width = width;
|
|
486
587
|
const run = makeTextRun(input);
|
|
487
588
|
textBlock.appendRun(run);
|
|
@@ -495,7 +596,7 @@ describe("layoutTextBlock", () => {
|
|
|
495
596
|
if (!isIntlSupported()) {
|
|
496
597
|
this.skip();
|
|
497
598
|
}
|
|
498
|
-
const textBlock = TextBlock.create({
|
|
599
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
499
600
|
textBlock.width = 6;
|
|
500
601
|
textBlock.appendRun(makeTextRun("ab"));
|
|
501
602
|
expect(doLayout(textBlock).lines.length).to.equal(1);
|
|
@@ -584,29 +685,28 @@ describe("layoutTextBlock", () => {
|
|
|
584
685
|
this.skip();
|
|
585
686
|
}
|
|
586
687
|
const lineHeight = 1;
|
|
587
|
-
const
|
|
588
|
-
const textBlock = TextBlock.create({ styleName, styleOverrides: { lineHeight } });
|
|
688
|
+
const textBlock = TextBlock.create({ styleId: "", styleOverrides: { lineHeight } });
|
|
589
689
|
// line 0: -->-->------> LINEBREAK
|
|
590
|
-
textBlock.appendRun(TabRun.create({
|
|
591
|
-
textBlock.appendRun(TabRun.create({
|
|
592
|
-
textBlock.appendRun(TabRun.create({
|
|
593
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
690
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
691
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
692
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
693
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
594
694
|
// line 1: a->b->cd-----> LINEBREAK
|
|
595
|
-
textBlock.appendRun(TextRun.create({
|
|
596
|
-
textBlock.appendRun(TabRun.create({
|
|
597
|
-
textBlock.appendRun(TextRun.create({
|
|
598
|
-
textBlock.appendRun(TabRun.create({
|
|
599
|
-
textBlock.appendRun(TextRun.create({
|
|
600
|
-
textBlock.appendRun(TabRun.create({
|
|
601
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
695
|
+
textBlock.appendRun(TextRun.create({ content: "a" }));
|
|
696
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
697
|
+
textBlock.appendRun(TextRun.create({ content: "b" }));
|
|
698
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
699
|
+
textBlock.appendRun(TextRun.create({ content: "cd" }));
|
|
700
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
701
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
602
702
|
// line 2: -->a->b------>cd LINEBREAK
|
|
603
|
-
textBlock.appendRun(TabRun.create({
|
|
604
|
-
textBlock.appendRun(TextRun.create({
|
|
605
|
-
textBlock.appendRun(TabRun.create({
|
|
606
|
-
textBlock.appendRun(TextRun.create({
|
|
607
|
-
textBlock.appendRun(TabRun.create({
|
|
608
|
-
textBlock.appendRun(TextRun.create({
|
|
609
|
-
textBlock.appendRun(LineBreakRun.create(
|
|
703
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
704
|
+
textBlock.appendRun(TextRun.create({ content: "a" }));
|
|
705
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 3 } }));
|
|
706
|
+
textBlock.appendRun(TextRun.create({ content: "b" }));
|
|
707
|
+
textBlock.appendRun(TabRun.create({ styleOverrides: { tabInterval: 7 } }));
|
|
708
|
+
textBlock.appendRun(TextRun.create({ content: "cd" }));
|
|
709
|
+
textBlock.appendRun(LineBreakRun.create());
|
|
610
710
|
/* Full Width:
|
|
611
711
|
* -->-->------>
|
|
612
712
|
* a->b->cd---->
|
|
@@ -655,7 +755,7 @@ describe("layoutTextBlock", () => {
|
|
|
655
755
|
if (!isIntlSupported()) {
|
|
656
756
|
this.skip();
|
|
657
757
|
}
|
|
658
|
-
const textBlock = TextBlock.create({
|
|
758
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
659
759
|
for (const str of ["The ", "quick brown", " fox jumped over ", "the lazy ", "dog"]) {
|
|
660
760
|
textBlock.appendRun(makeTextRun(str));
|
|
661
761
|
}
|
|
@@ -699,7 +799,7 @@ describe("layoutTextBlock", () => {
|
|
|
699
799
|
if (!isIntlSupported()) {
|
|
700
800
|
this.skip();
|
|
701
801
|
}
|
|
702
|
-
const block = TextBlock.create({
|
|
802
|
+
const block = TextBlock.create({ styleId: "" });
|
|
703
803
|
block.appendRun(makeTextRun("aa")); // 2 chars wide
|
|
704
804
|
block.appendRun(makeTextRun("bb ccc d ee")); // 11 chars wide
|
|
705
805
|
block.appendRun(makeTextRun("ff ggg h")); // 8 chars wide
|
|
@@ -739,7 +839,7 @@ describe("layoutTextBlock", () => {
|
|
|
739
839
|
if (!isIntlSupported()) {
|
|
740
840
|
this.skip();
|
|
741
841
|
}
|
|
742
|
-
const block = TextBlock.create({
|
|
842
|
+
const block = TextBlock.create({ styleId: "", styleOverrides: { lineHeight: 1, lineSpacingFactor: 0 } });
|
|
743
843
|
block.appendRun(makeTextRun("abc defg"));
|
|
744
844
|
const layout1 = doLayout(block);
|
|
745
845
|
let width = layout1.range.xLength();
|
|
@@ -751,16 +851,26 @@ describe("layoutTextBlock", () => {
|
|
|
751
851
|
});
|
|
752
852
|
});
|
|
753
853
|
describe("grapheme offsets", () => {
|
|
754
|
-
|
|
755
|
-
const textBlock = TextBlock.create({ styleName: "" });
|
|
756
|
-
const fractionRun = FractionRun.create({ numerator: "1", denominator: "2", styleName: "fraction" });
|
|
757
|
-
textBlock.appendRun(fractionRun);
|
|
854
|
+
function getLayoutResultAndStyleResolver(textBlock) {
|
|
758
855
|
const layout = doLayout(textBlock);
|
|
759
856
|
const result = layout.toResult();
|
|
857
|
+
const textStyleResolver = new TextStyleResolver({
|
|
858
|
+
textBlock,
|
|
859
|
+
iModel: {},
|
|
860
|
+
modelId: undefined,
|
|
861
|
+
findTextStyle: () => TextStyleSettings.defaults
|
|
862
|
+
});
|
|
863
|
+
return { textStyleResolver, result };
|
|
864
|
+
}
|
|
865
|
+
it("should return an empty array if source type is not text", function () {
|
|
866
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
867
|
+
const fractionRun = FractionRun.create({ numerator: "1", denominator: "2" });
|
|
868
|
+
textBlock.appendRun(fractionRun);
|
|
869
|
+
const { textStyleResolver, result } = getLayoutResultAndStyleResolver(textBlock);
|
|
760
870
|
const args = {
|
|
761
871
|
textBlock,
|
|
762
872
|
iModel: {},
|
|
763
|
-
|
|
873
|
+
textStyleResolver,
|
|
764
874
|
findFontId: () => 0,
|
|
765
875
|
computeTextRange: computeTextRangeAsStringLength,
|
|
766
876
|
paragraphIndex: result.lines[0].sourceParagraphIndex,
|
|
@@ -771,15 +881,14 @@ describe("layoutTextBlock", () => {
|
|
|
771
881
|
expect(graphemeRanges).to.be.an("array").that.is.empty;
|
|
772
882
|
});
|
|
773
883
|
it("should handle empty text content", function () {
|
|
774
|
-
const textBlock = TextBlock.create({
|
|
775
|
-
const textRun = TextRun.create({ content: ""
|
|
884
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
885
|
+
const textRun = TextRun.create({ content: "" });
|
|
776
886
|
textBlock.appendRun(textRun);
|
|
777
|
-
const
|
|
778
|
-
const result = layout.toResult();
|
|
887
|
+
const { textStyleResolver, result } = getLayoutResultAndStyleResolver(textBlock);
|
|
779
888
|
const args = {
|
|
780
889
|
textBlock,
|
|
781
890
|
iModel: {},
|
|
782
|
-
|
|
891
|
+
textStyleResolver,
|
|
783
892
|
findFontId: () => 0,
|
|
784
893
|
computeTextRange: computeTextRangeAsStringLength,
|
|
785
894
|
paragraphIndex: result.lines[0].sourceParagraphIndex,
|
|
@@ -790,15 +899,14 @@ describe("layoutTextBlock", () => {
|
|
|
790
899
|
expect(graphemeRanges).to.be.an("array").that.is.empty;
|
|
791
900
|
});
|
|
792
901
|
it("should compute grapheme offsets correctly for a given text", function () {
|
|
793
|
-
const textBlock = TextBlock.create({
|
|
794
|
-
const textRun = TextRun.create({ content: "hello"
|
|
902
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
903
|
+
const textRun = TextRun.create({ content: "hello" });
|
|
795
904
|
textBlock.appendRun(textRun);
|
|
796
|
-
const
|
|
797
|
-
const result = layout.toResult();
|
|
905
|
+
const { textStyleResolver, result } = getLayoutResultAndStyleResolver(textBlock);
|
|
798
906
|
const args = {
|
|
799
907
|
textBlock,
|
|
800
908
|
iModel: {},
|
|
801
|
-
|
|
909
|
+
textStyleResolver,
|
|
802
910
|
findFontId: () => 0,
|
|
803
911
|
computeTextRange: computeTextRangeAsStringLength,
|
|
804
912
|
paragraphIndex: result.lines[0].sourceParagraphIndex,
|
|
@@ -811,16 +919,15 @@ describe("layoutTextBlock", () => {
|
|
|
811
919
|
expect(graphemeRanges[4].high.x).to.equal(5);
|
|
812
920
|
});
|
|
813
921
|
it("should compute grapheme offsets correctly for non-English text", function () {
|
|
814
|
-
const textBlock = TextBlock.create({
|
|
922
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
815
923
|
// Hindi - "Paragraph"
|
|
816
|
-
const textRun = TextRun.create({ content: "अनुच्छेद"
|
|
924
|
+
const textRun = TextRun.create({ content: "अनुच्छेद" });
|
|
817
925
|
textBlock.appendRun(textRun);
|
|
818
|
-
const
|
|
819
|
-
const result = layout.toResult();
|
|
926
|
+
const { textStyleResolver, result } = getLayoutResultAndStyleResolver(textBlock);
|
|
820
927
|
const args = {
|
|
821
928
|
textBlock,
|
|
822
929
|
iModel: {},
|
|
823
|
-
|
|
930
|
+
textStyleResolver,
|
|
824
931
|
findFontId: () => 0,
|
|
825
932
|
computeTextRange: computeTextRangeAsStringLength,
|
|
826
933
|
paragraphIndex: result.lines[0].sourceParagraphIndex,
|
|
@@ -835,15 +942,14 @@ describe("layoutTextBlock", () => {
|
|
|
835
942
|
expect(graphemeRanges[3].high.x).to.equal(8);
|
|
836
943
|
});
|
|
837
944
|
it("should compute grapheme offsets correctly for emoji content", function () {
|
|
838
|
-
const textBlock = TextBlock.create({
|
|
839
|
-
const textRun = TextRun.create({ content: "👨👦"
|
|
945
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
946
|
+
const textRun = TextRun.create({ content: "👨👦" });
|
|
840
947
|
textBlock.appendRun(textRun);
|
|
841
|
-
const
|
|
842
|
-
const result = layout.toResult();
|
|
948
|
+
const { textStyleResolver, result } = getLayoutResultAndStyleResolver(textBlock);
|
|
843
949
|
const args = {
|
|
844
950
|
textBlock,
|
|
845
951
|
iModel: {},
|
|
846
|
-
|
|
952
|
+
textStyleResolver,
|
|
847
953
|
findFontId: () => 0,
|
|
848
954
|
computeTextRange: computeTextRangeAsStringLength,
|
|
849
955
|
paragraphIndex: result.lines[0].sourceParagraphIndex,
|
|
@@ -873,9 +979,10 @@ describe("layoutTextBlock", () => {
|
|
|
873
979
|
expect(comic).to.equal(3);
|
|
874
980
|
expect(iModel.fonts.findId({ name: "Consolas" })).to.be.undefined;
|
|
875
981
|
function test(fontName, expectedFontId) {
|
|
876
|
-
const textBlock = TextBlock.create({
|
|
877
|
-
textBlock.appendRun(TextRun.create({
|
|
878
|
-
const
|
|
982
|
+
const textBlock = TextBlock.create({ styleId: "" });
|
|
983
|
+
textBlock.appendRun(TextRun.create({ styleOverrides: { fontName } }));
|
|
984
|
+
const textStyleResolver = new TextStyleResolver({ textBlock, iModel });
|
|
985
|
+
const layout = layoutTextBlock({ textBlock, iModel, textStyleResolver });
|
|
879
986
|
const run = layout.lines[0].runs[0];
|
|
880
987
|
expect(run).not.to.be.undefined;
|
|
881
988
|
expect(run.fontId).to.equal(expectedFontId);
|
|
@@ -888,14 +995,13 @@ describe("layoutTextBlock", () => {
|
|
|
888
995
|
});
|
|
889
996
|
function computeDimensions(args) {
|
|
890
997
|
const textBlock = TextBlock.create({
|
|
891
|
-
|
|
998
|
+
styleId: "",
|
|
892
999
|
styleOverrides: {
|
|
893
1000
|
lineHeight: args.height,
|
|
894
1001
|
widthFactor: args.width,
|
|
895
1002
|
},
|
|
896
1003
|
});
|
|
897
1004
|
textBlock.appendRun(TextRun.create({
|
|
898
|
-
styleName: "",
|
|
899
1005
|
content: args.content ?? "This is a string of text.",
|
|
900
1006
|
styleOverrides: {
|
|
901
1007
|
isBold: args.bold,
|
|
@@ -903,7 +1009,8 @@ describe("layoutTextBlock", () => {
|
|
|
903
1009
|
fontName: args.font ?? "Vera",
|
|
904
1010
|
},
|
|
905
1011
|
}));
|
|
906
|
-
const
|
|
1012
|
+
const textStyleResolver = new TextStyleResolver({ textBlock, iModel });
|
|
1013
|
+
const range = layoutTextBlock({ textBlock, iModel, textStyleResolver }).range;
|
|
907
1014
|
return { x: range.high.x - range.low.x, y: range.high.y - range.low.y };
|
|
908
1015
|
}
|
|
909
1016
|
it("computes different ranges for different strings", () => {
|
|
@@ -967,18 +1074,18 @@ describe("layoutTextBlock", () => {
|
|
|
967
1074
|
describe("produceTextBlockGeometry", () => {
|
|
968
1075
|
function makeText(color) {
|
|
969
1076
|
const styleOverrides = undefined !== color ? { color: color instanceof ColorDef ? color.toJSON() : color } : undefined;
|
|
970
|
-
return TextRun.create({
|
|
1077
|
+
return TextRun.create({ styleOverrides, content: "text" });
|
|
971
1078
|
}
|
|
972
1079
|
function makeFraction(color) {
|
|
973
1080
|
const styleOverrides = undefined !== color ? { color: color instanceof ColorDef ? color.toJSON() : color } : undefined;
|
|
974
|
-
return FractionRun.create({ numerator: "num", denominator: "denom",
|
|
1081
|
+
return FractionRun.create({ numerator: "num", denominator: "denom", styleOverrides });
|
|
975
1082
|
}
|
|
976
1083
|
function makeBreak(color) {
|
|
977
1084
|
const styleOverrides = undefined !== color ? { color: color instanceof ColorDef ? color.toJSON() : color } : undefined;
|
|
978
|
-
return LineBreakRun.create({
|
|
1085
|
+
return LineBreakRun.create({ styleOverrides });
|
|
979
1086
|
}
|
|
980
1087
|
function makeTextBlock(runs) {
|
|
981
|
-
const block = TextBlock.create({
|
|
1088
|
+
const block = TextBlock.create({ styleId: "" });
|
|
982
1089
|
for (const run of runs) {
|
|
983
1090
|
block.appendRun(run);
|
|
984
1091
|
}
|