@itwin/core-backend 5.3.0-dev.2 → 5.3.0-dev.4
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/IModelDb.js +1 -1
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/annotations/FrameGeometry.js +6 -6
- package/lib/cjs/annotations/FrameGeometry.js.map +1 -1
- package/lib/cjs/annotations/LeaderGeometry.js +4 -4
- package/lib/cjs/annotations/LeaderGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.d.ts +101 -20
- package/lib/cjs/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/cjs/annotations/TextAnnotationElement.js +202 -64
- package/lib/cjs/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/annotations/TextBlockGeometry.js +3 -3
- package/lib/cjs/annotations/TextBlockGeometry.js.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.d.ts +2 -2
- package/lib/cjs/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/cjs/annotations/TextBlockLayout.js +52 -25
- package/lib/cjs/annotations/TextBlockLayout.js.map +1 -1
- package/lib/esm/IModelDb.js +1 -1
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/annotations/FrameGeometry.js +6 -6
- package/lib/esm/annotations/FrameGeometry.js.map +1 -1
- package/lib/esm/annotations/LeaderGeometry.js +4 -4
- package/lib/esm/annotations/LeaderGeometry.js.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.d.ts +101 -20
- package/lib/esm/annotations/TextAnnotationElement.d.ts.map +1 -1
- package/lib/esm/annotations/TextAnnotationElement.js +201 -63
- package/lib/esm/annotations/TextAnnotationElement.js.map +1 -1
- package/lib/esm/annotations/TextBlockGeometry.js +3 -3
- package/lib/esm/annotations/TextBlockGeometry.js.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.d.ts +2 -2
- package/lib/esm/annotations/TextBlockLayout.d.ts.map +1 -1
- package/lib/esm/annotations/TextBlockLayout.js +52 -25
- package/lib/esm/annotations/TextBlockLayout.js.map +1 -1
- package/lib/esm/test/AnnotationTestUtils.js +1 -1
- package/lib/esm/test/AnnotationTestUtils.js.map +1 -1
- package/lib/esm/test/annotations/Fields.test.js +2 -2
- package/lib/esm/test/annotations/Fields.test.js.map +1 -1
- package/lib/esm/test/annotations/FrameGeometry.test.js +4 -4
- package/lib/esm/test/annotations/FrameGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/LeaderGeometry.test.js +8 -8
- package/lib/esm/test/annotations/LeaderGeometry.test.js.map +1 -1
- package/lib/esm/test/annotations/TextAnnotation.test.js +130 -35
- package/lib/esm/test/annotations/TextAnnotation.test.js.map +1 -1
- package/lib/esm/test/annotations/TextBlock.test.js +218 -151
- package/lib/esm/test/annotations/TextBlock.test.js.map +1 -1
- package/package.json +14 -14
|
@@ -6,7 +6,7 @@ import { expect } from "chai";
|
|
|
6
6
|
import { Angle, Point3d, Range2d, Range3d, YawPitchRollAngles } from "@itwin/core-geometry";
|
|
7
7
|
import { FractionRun, SubCategoryAppearance, TextAnnotation, TextBlock, TextRun, TextStyleSettings } from "@itwin/core-common";
|
|
8
8
|
import { StandaloneDb } from "../../IModelDb";
|
|
9
|
-
import { AnnotationTextStyle, TextAnnotation2d, TextAnnotation3d } from "../../annotations/TextAnnotationElement";
|
|
9
|
+
import { AnnotationTextStyle, TEXT_ANNOTATION_JSON_VERSION, TEXT_STYLE_SETTINGS_JSON_VERSION, TextAnnotation2d, TextAnnotation3d } from "../../annotations/TextAnnotationElement";
|
|
10
10
|
import { IModelTestUtils } from "../IModelTestUtils";
|
|
11
11
|
import { Subject } from "../../Element";
|
|
12
12
|
import { Guid, Id64 } from "@itwin/core-bentley";
|
|
@@ -30,13 +30,12 @@ function mockIModel() {
|
|
|
30
30
|
return iModel;
|
|
31
31
|
}
|
|
32
32
|
function createAnnotation(textBlock) {
|
|
33
|
-
const styleOverrides = {
|
|
33
|
+
const styleOverrides = { font: { name: "Karla" }, margins: { left: 0, right: 1, top: 2, bottom: 3 } };
|
|
34
34
|
const block = textBlock ?? TextBlock.create({ styleOverrides });
|
|
35
35
|
if (!textBlock) {
|
|
36
36
|
block.appendRun(TextRun.create({ content: "Run, Barry,", styleOverrides }));
|
|
37
37
|
block.appendRun(TextRun.create({ content: " RUN!!! ", styleOverrides }));
|
|
38
38
|
block.appendRun(FractionRun.create({ numerator: "Harrison", denominator: "Wells", styleOverrides }));
|
|
39
|
-
block.margins = { left: 0, right: 1, top: 2, bottom: 3 };
|
|
40
39
|
}
|
|
41
40
|
const annotation = TextAnnotation.fromJSON({ textBlock: block.toJSON() });
|
|
42
41
|
annotation.anchor = { vertical: "middle", horizontal: "right" };
|
|
@@ -83,8 +82,13 @@ const createIModel = async (name) => {
|
|
|
83
82
|
});
|
|
84
83
|
return iModel;
|
|
85
84
|
};
|
|
86
|
-
const createAnnotationTextStyle = (iModel,
|
|
87
|
-
return AnnotationTextStyle.create(iModel,
|
|
85
|
+
const createAnnotationTextStyle = (iModel, definitionModelId, name, settings = TextStyleSettings.defaultProps) => {
|
|
86
|
+
return AnnotationTextStyle.create(iModel, {
|
|
87
|
+
definitionModelId,
|
|
88
|
+
name,
|
|
89
|
+
settings,
|
|
90
|
+
description: "description",
|
|
91
|
+
});
|
|
88
92
|
};
|
|
89
93
|
function createElement2d(imodel, createArgs) {
|
|
90
94
|
const placement = {
|
|
@@ -124,13 +128,56 @@ describe("TextAnnotation element", () => {
|
|
|
124
128
|
...props,
|
|
125
129
|
}, mockIModel());
|
|
126
130
|
}
|
|
131
|
+
describe("versioning", () => {
|
|
132
|
+
it("throws if the JSON has no version", () => {
|
|
133
|
+
expect(() => makeElement({
|
|
134
|
+
textAnnotationData: JSON.stringify({
|
|
135
|
+
data: {
|
|
136
|
+
textBlock: TextBlock.create().toJSON()
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
})).to.throw("JSON version is missing or invalid.");
|
|
140
|
+
});
|
|
141
|
+
it("throws if the JSON has no data", () => {
|
|
142
|
+
expect(() => makeElement({
|
|
143
|
+
textAnnotationData: JSON.stringify({
|
|
144
|
+
version: TEXT_ANNOTATION_JSON_VERSION,
|
|
145
|
+
}),
|
|
146
|
+
})).to.throw("JSON data is missing or invalid.");
|
|
147
|
+
});
|
|
148
|
+
it("throws if the JSON version is too new", () => {
|
|
149
|
+
expect(() => makeElement({
|
|
150
|
+
textAnnotationData: JSON.stringify({
|
|
151
|
+
version: "999.999.999",
|
|
152
|
+
data: {
|
|
153
|
+
textBlock: TextBlock.create().toJSON()
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
})).to.throw(`JSON version 999.999.999 is newer than supported version ${TEXT_ANNOTATION_JSON_VERSION}. Application update required to understand data.`);
|
|
157
|
+
});
|
|
158
|
+
it("throws if the JSON version is old and cannot be migrated", () => {
|
|
159
|
+
expect(() => makeElement({
|
|
160
|
+
textAnnotationData: JSON.stringify({
|
|
161
|
+
version: "0.0.1",
|
|
162
|
+
data: {
|
|
163
|
+
textBlock: TextBlock.create().toJSON()
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
})).to.throw(`Migration for textAnnotationData from version 0.0.1 to ${TEXT_ANNOTATION_JSON_VERSION} failed.`);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
127
169
|
describe("getAnnotation", () => {
|
|
128
170
|
it("returns undefined if not provided", () => {
|
|
129
171
|
expect(makeElement().getAnnotation()).to.be.undefined;
|
|
130
172
|
});
|
|
131
173
|
it("converts JSON string to class instance", () => {
|
|
132
174
|
const elem = makeElement({
|
|
133
|
-
textAnnotationData: JSON.stringify({
|
|
175
|
+
textAnnotationData: JSON.stringify({
|
|
176
|
+
version: TEXT_ANNOTATION_JSON_VERSION,
|
|
177
|
+
data: {
|
|
178
|
+
textBlock: TextBlock.create().toJSON()
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
134
181
|
defaultTextStyle: new TextAnnotationUsesTextStyleByDefault("0x42").toJSON()
|
|
135
182
|
});
|
|
136
183
|
const anno = elem.getAnnotation();
|
|
@@ -141,7 +188,12 @@ describe("TextAnnotation element", () => {
|
|
|
141
188
|
});
|
|
142
189
|
it("produces a new object each time it is called", () => {
|
|
143
190
|
const elem = makeElement({
|
|
144
|
-
textAnnotationData: JSON.stringify({
|
|
191
|
+
textAnnotationData: JSON.stringify({
|
|
192
|
+
version: TEXT_ANNOTATION_JSON_VERSION,
|
|
193
|
+
data: {
|
|
194
|
+
textBlock: TextBlock.create().toJSON()
|
|
195
|
+
}
|
|
196
|
+
}),
|
|
145
197
|
});
|
|
146
198
|
const anno1 = elem.getAnnotation();
|
|
147
199
|
const anno2 = elem.getAnnotation();
|
|
@@ -168,7 +220,7 @@ describe("TextAnnotation element", () => {
|
|
|
168
220
|
const jobSubjectId = createJobSubjectElement(imodel, "Job").insert();
|
|
169
221
|
const definitionModel = DefinitionModel.insert(imodel, jobSubjectId, "Definition");
|
|
170
222
|
const { category, model } = insertSpatialModel(imodel, jobSubjectId, definitionModel);
|
|
171
|
-
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", {
|
|
223
|
+
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", { font: { name: "Totally Real Font" }, textHeight: 0.25, isItalic: true }).insert();
|
|
172
224
|
expect(jobSubjectId).not.to.be.undefined;
|
|
173
225
|
expect(category).not.to.be.undefined;
|
|
174
226
|
expect(model).not.to.be.undefined;
|
|
@@ -178,7 +230,7 @@ describe("TextAnnotation element", () => {
|
|
|
178
230
|
after(() => imodel.close());
|
|
179
231
|
it("creating element does not automatically compute the geometry", () => {
|
|
180
232
|
const annotation = createAnnotation();
|
|
181
|
-
const args = { ...createElement3dArgs,
|
|
233
|
+
const args = { ...createElement3dArgs, textAnnotationProps: annotation.toJSON() };
|
|
182
234
|
const el = createElement3d(imodel, args);
|
|
183
235
|
expect(el.getAnnotation().equals(annotation)).to.be.true;
|
|
184
236
|
expect(el.geom).to.be.undefined;
|
|
@@ -239,7 +291,7 @@ describe("TextAnnotation element", () => {
|
|
|
239
291
|
});
|
|
240
292
|
it("creating element does not automatically compute the geometry", () => {
|
|
241
293
|
const annotation = createAnnotation();
|
|
242
|
-
const args = { ...createElement2dArgs,
|
|
294
|
+
const args = { ...createElement2dArgs, textAnnotationProps: annotation.toJSON() };
|
|
243
295
|
const el = createElement2d(imodel, args);
|
|
244
296
|
expect(el.getAnnotation().equals(annotation)).to.be.true;
|
|
245
297
|
expect(el.geom).to.be.undefined;
|
|
@@ -289,8 +341,8 @@ describe("TextAnnotation element", () => {
|
|
|
289
341
|
imodel = await createIModel("DefaultTextStyle");
|
|
290
342
|
const jobSubjectId = createJobSubjectElement(imodel, "Job").insert();
|
|
291
343
|
const definitionModel = DefinitionModel.insert(imodel, jobSubjectId, "Definition");
|
|
292
|
-
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", {
|
|
293
|
-
const differentStyleId = createAnnotationTextStyle(imodel, definitionModel, "alt", {
|
|
344
|
+
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", { font: { name: "Totally Real Font" }, textHeight: 0.25, isItalic: true }).insert();
|
|
345
|
+
const differentStyleId = createAnnotationTextStyle(imodel, definitionModel, "alt", { font: { name: "Karla" }, textHeight: 0.5, isBold: true }).insert();
|
|
294
346
|
expect(jobSubjectId).not.to.be.undefined;
|
|
295
347
|
expect(definitionModel).not.to.be.undefined;
|
|
296
348
|
expect(styleId).not.to.be.undefined;
|
|
@@ -314,7 +366,7 @@ describe("TextAnnotation element", () => {
|
|
|
314
366
|
});
|
|
315
367
|
it("preserves defaultTextStyle after round trip", () => {
|
|
316
368
|
const annotation = createAnnotation();
|
|
317
|
-
const args = { ...createElement2dArgs,
|
|
369
|
+
const args = { ...createElement2dArgs, textAnnotationProps: annotation.toJSON(), defaultTextStyleId: seedStyleId };
|
|
318
370
|
const el0 = createElement2d(imodel, args);
|
|
319
371
|
expect(el0.defaultTextStyle).not.to.be.undefined;
|
|
320
372
|
expect(el0.defaultTextStyle.id).to.equal(seedStyleId);
|
|
@@ -327,7 +379,7 @@ describe("TextAnnotation element", () => {
|
|
|
327
379
|
});
|
|
328
380
|
it("produces different geometry when defaultTextStyle changes", () => {
|
|
329
381
|
const annotation = createAnnotation();
|
|
330
|
-
const args = { ...createElement2dArgs,
|
|
382
|
+
const args = { ...createElement2dArgs, textAnnotationProps: annotation.toJSON() };
|
|
331
383
|
const el0 = createElement2d(imodel, args);
|
|
332
384
|
el0.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(seedStyleId);
|
|
333
385
|
const geom1 = el0.toJSON().elementGeometryBuilderParams;
|
|
@@ -337,7 +389,7 @@ describe("TextAnnotation element", () => {
|
|
|
337
389
|
});
|
|
338
390
|
it("allows defaultTextStyle to be undefined", () => {
|
|
339
391
|
const annotation = createAnnotation();
|
|
340
|
-
const args = { ...createElement2dArgs,
|
|
392
|
+
const args = { ...createElement2dArgs, textAnnotationProps: annotation.toJSON() };
|
|
341
393
|
const el0 = createElement2d(imodel, args);
|
|
342
394
|
el0.defaultTextStyle = undefined;
|
|
343
395
|
const elId = el0.insert();
|
|
@@ -358,7 +410,7 @@ describe("TextAnnotation element", () => {
|
|
|
358
410
|
});
|
|
359
411
|
it("preserves defaultTextStyle after round trip", () => {
|
|
360
412
|
const annotation = createAnnotation();
|
|
361
|
-
const args = { ...createElement3dArgs,
|
|
413
|
+
const args = { ...createElement3dArgs, textAnnotationProps: annotation.toJSON(), defaultTextStyleId: seedStyleId };
|
|
362
414
|
const el0 = createElement3d(imodel, args);
|
|
363
415
|
expect(el0.defaultTextStyle).not.to.be.undefined;
|
|
364
416
|
expect(el0.defaultTextStyle.id).to.equal(seedStyleId);
|
|
@@ -371,7 +423,7 @@ describe("TextAnnotation element", () => {
|
|
|
371
423
|
});
|
|
372
424
|
it("produces different geometry when defaultTextStyle changes", () => {
|
|
373
425
|
const annotation = createAnnotation();
|
|
374
|
-
const args = { ...createElement3dArgs,
|
|
426
|
+
const args = { ...createElement3dArgs, textAnnotationProps: annotation.toJSON() };
|
|
375
427
|
const el0 = createElement3d(imodel, args);
|
|
376
428
|
el0.defaultTextStyle = new TextAnnotationUsesTextStyleByDefault(seedStyleId);
|
|
377
429
|
const geom1 = el0.toJSON().elementGeometryBuilderParams;
|
|
@@ -381,7 +433,7 @@ describe("TextAnnotation element", () => {
|
|
|
381
433
|
});
|
|
382
434
|
it("allows defaultTextStyle to be undefined", () => {
|
|
383
435
|
const annotation = createAnnotation();
|
|
384
|
-
const args = { ...createElement3dArgs,
|
|
436
|
+
const args = { ...createElement3dArgs, textAnnotationProps: annotation.toJSON() };
|
|
385
437
|
const el0 = createElement3d(imodel, args);
|
|
386
438
|
el0.defaultTextStyle = undefined;
|
|
387
439
|
const elId = el0.insert();
|
|
@@ -412,9 +464,9 @@ describe("AnnotationTextStyle", () => {
|
|
|
412
464
|
});
|
|
413
465
|
it("inserts a style and round-trips through JSON", async () => {
|
|
414
466
|
const textStyle = TextStyleSettings.fromJSON({
|
|
415
|
-
|
|
467
|
+
font: { name: "Totally Real Font" },
|
|
416
468
|
isUnderlined: true,
|
|
417
|
-
|
|
469
|
+
textHeight: 0.5
|
|
418
470
|
});
|
|
419
471
|
const el0 = createAnnotationTextStyle(imodel, seedDefinitionModel, "round-trip", textStyle.toJSON());
|
|
420
472
|
const elId = el0.insert();
|
|
@@ -431,27 +483,27 @@ describe("AnnotationTextStyle", () => {
|
|
|
431
483
|
let annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "default");
|
|
432
484
|
expect(() => annotationTextStyle.insert()).to.throw();
|
|
433
485
|
// font is required
|
|
434
|
-
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "no font", {
|
|
486
|
+
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "no font", { font: { name: "" } });
|
|
435
487
|
expect(() => annotationTextStyle.insert()).to.throw();
|
|
436
|
-
//
|
|
437
|
-
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "invalid
|
|
488
|
+
// textHeight should be positive
|
|
489
|
+
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "invalid textHeight", { font: { name: "Totally Real Font" }, textHeight: 0 });
|
|
438
490
|
expect(() => annotationTextStyle.insert()).to.throw();
|
|
439
491
|
// stackedFractionScale should be positive
|
|
440
|
-
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "invalid stackedFractionScale", {
|
|
492
|
+
annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "invalid stackedFractionScale", { font: { name: "Totally Real Font" }, stackedFractionScale: 0 });
|
|
441
493
|
expect(() => annotationTextStyle.insert()).to.throw();
|
|
442
494
|
});
|
|
443
495
|
it("does not allow updating of elements to invalid styles", async () => {
|
|
444
|
-
const annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "valid style", {
|
|
496
|
+
const annotationTextStyle = createAnnotationTextStyle(imodel, seedDefinitionModel, "valid style", { font: { name: "Totally Real Font" } });
|
|
445
497
|
const elId = annotationTextStyle.insert();
|
|
446
498
|
expect(Id64.isValidId64(elId)).to.be.true;
|
|
447
499
|
const el1 = imodel.elements.getElement(elId);
|
|
448
500
|
expect(el1).not.to.be.undefined;
|
|
449
501
|
expect(el1 instanceof AnnotationTextStyle).to.be.true;
|
|
450
|
-
el1.settings = el1.settings.clone({
|
|
502
|
+
el1.settings = el1.settings.clone({ font: { name: "" } });
|
|
451
503
|
expect(() => el1.update()).to.throw();
|
|
452
|
-
el1.settings = el1.settings.clone({
|
|
504
|
+
el1.settings = el1.settings.clone({ font: { name: "Totally Real Font" }, textHeight: 0 });
|
|
453
505
|
expect(() => el1.update()).to.throw();
|
|
454
|
-
el1.settings = el1.settings.clone({
|
|
506
|
+
el1.settings = el1.settings.clone({ textHeight: 2, stackedFractionScale: 0 });
|
|
455
507
|
expect(() => el1.update()).to.throw();
|
|
456
508
|
el1.settings = el1.settings.clone({ stackedFractionScale: 0.45 });
|
|
457
509
|
el1.update();
|
|
@@ -468,12 +520,56 @@ describe("AnnotationTextStyle", () => {
|
|
|
468
520
|
expect(el0.settings.toJSON()).to.deep.equal(TextStyleSettings.defaultProps);
|
|
469
521
|
});
|
|
470
522
|
it("can update style via cloning", async () => {
|
|
471
|
-
const el0 = createAnnotationTextStyle(imodel, seedDefinitionModel, "cloning", {
|
|
523
|
+
const el0 = createAnnotationTextStyle(imodel, seedDefinitionModel, "cloning", { font: { name: "Totally Real Font" } });
|
|
472
524
|
const newStyle = el0.settings.clone({ isBold: true, lineSpacingFactor: 3 });
|
|
473
525
|
expect(el0.settings.toJSON()).to.not.deep.equal(newStyle.toJSON());
|
|
474
526
|
el0.settings = newStyle;
|
|
475
527
|
expect(el0.settings.toJSON()).to.deep.equal(newStyle.toJSON());
|
|
476
528
|
});
|
|
529
|
+
describe("versioning", () => {
|
|
530
|
+
function makeStyle(props) {
|
|
531
|
+
return AnnotationTextStyle.fromJSON({
|
|
532
|
+
model: "0x34",
|
|
533
|
+
code: {
|
|
534
|
+
spec: "0x56",
|
|
535
|
+
scope: "0x78",
|
|
536
|
+
value: "style"
|
|
537
|
+
},
|
|
538
|
+
classFullName: AnnotationTextStyle.classFullName,
|
|
539
|
+
...props,
|
|
540
|
+
}, mockIModel());
|
|
541
|
+
}
|
|
542
|
+
it("throws if the JSON has no version", () => {
|
|
543
|
+
expect(() => makeStyle({
|
|
544
|
+
settings: JSON.stringify({
|
|
545
|
+
data: TextStyleSettings.defaultProps
|
|
546
|
+
}),
|
|
547
|
+
})).to.throw("JSON version is missing or invalid.");
|
|
548
|
+
});
|
|
549
|
+
it("throws if the JSON has no data", () => {
|
|
550
|
+
expect(() => makeStyle({
|
|
551
|
+
settings: JSON.stringify({
|
|
552
|
+
version: TEXT_STYLE_SETTINGS_JSON_VERSION,
|
|
553
|
+
}),
|
|
554
|
+
})).to.throw("JSON data is missing or invalid.");
|
|
555
|
+
});
|
|
556
|
+
it("throws if the JSON version is too new", () => {
|
|
557
|
+
expect(() => makeStyle({
|
|
558
|
+
settings: JSON.stringify({
|
|
559
|
+
version: "999.999.999",
|
|
560
|
+
data: TextStyleSettings.defaultProps
|
|
561
|
+
}),
|
|
562
|
+
})).to.throw(`JSON version 999.999.999 is newer than supported version ${TEXT_STYLE_SETTINGS_JSON_VERSION}. Application update required to understand data.`);
|
|
563
|
+
});
|
|
564
|
+
it("throws if the JSON version is old and cannot be migrated", () => {
|
|
565
|
+
expect(() => makeStyle({
|
|
566
|
+
settings: JSON.stringify({
|
|
567
|
+
version: "0.0.1",
|
|
568
|
+
data: TextStyleSettings.defaultProps
|
|
569
|
+
}),
|
|
570
|
+
})).to.throw(`Migration for settings from version 0.0.1 to ${TEXT_STYLE_SETTINGS_JSON_VERSION} failed.`);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
477
573
|
});
|
|
478
574
|
describe("appendTextAnnotationGeometry", () => {
|
|
479
575
|
let imodel;
|
|
@@ -486,8 +582,8 @@ describe("appendTextAnnotationGeometry", () => {
|
|
|
486
582
|
const jobSubjectId = createJobSubjectElement(imodel, "Job").insert();
|
|
487
583
|
const definitionModel = DefinitionModel.insert(imodel, jobSubjectId, "Definition");
|
|
488
584
|
const { category, model } = insertDrawingModel(imodel, jobSubjectId, definitionModel);
|
|
489
|
-
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", {
|
|
490
|
-
const differentStyleId = createAnnotationTextStyle(imodel, definitionModel, "alt", {
|
|
585
|
+
const styleId = createAnnotationTextStyle(imodel, definitionModel, "test", { font: { name: "Totally Real Font" }, textHeight: 0.25, isItalic: true }).insert();
|
|
586
|
+
const differentStyleId = createAnnotationTextStyle(imodel, definitionModel, "alt", { font: { name: "Karla" }, textHeight: 0.5, isBold: true }).insert();
|
|
491
587
|
expect(jobSubjectId).not.to.be.undefined;
|
|
492
588
|
expect(definitionModel).not.to.be.undefined;
|
|
493
589
|
expect(category).not.to.be.undefined;
|
|
@@ -541,7 +637,7 @@ describe("appendTextAnnotationGeometry", () => {
|
|
|
541
637
|
const block = TextBlock.create();
|
|
542
638
|
const annotation = TextAnnotation.fromJSON({ textBlock: block.toJSON() });
|
|
543
639
|
const styleId = createAnnotationTextStyle(imodel, seedDefinitionModelId, "empty anno style", {
|
|
544
|
-
|
|
640
|
+
font: { name: "Totally Real Font" },
|
|
545
641
|
frame: {
|
|
546
642
|
shape: "rectangle",
|
|
547
643
|
}
|
|
@@ -554,7 +650,7 @@ describe("appendTextAnnotationGeometry", () => {
|
|
|
554
650
|
it("produces different geometry when given different text-content in annotations", () => {
|
|
555
651
|
const anno1 = createAnnotation();
|
|
556
652
|
const anno2 = createAnnotation();
|
|
557
|
-
anno2.textBlock.appendRun(TextRun.create({ content: "extra", styleOverrides: {
|
|
653
|
+
anno2.textBlock.appendRun(TextRun.create({ content: "extra", styleOverrides: { font: { name: "Totally Real Font" } } }));
|
|
558
654
|
const builder1 = runAppendTextAnnotationGeometry(anno1, seedStyleId);
|
|
559
655
|
const builder2 = runAppendTextAnnotationGeometry(anno2, seedStyleId);
|
|
560
656
|
expect(builder1.geometries).to.not.deep.equal(builder2.geometries);
|
|
@@ -569,12 +665,12 @@ describe("appendTextAnnotationGeometry", () => {
|
|
|
569
665
|
});
|
|
570
666
|
it("accounts for style overrides in the text", () => {
|
|
571
667
|
const block = TextBlock.create();
|
|
668
|
+
block.styleOverrides = { margins: { left: 0, right: 1, top: 2, bottom: 3 } };
|
|
572
669
|
block.appendParagraph();
|
|
573
670
|
block.children[0].styleOverrides = { isBold: true };
|
|
574
671
|
block.appendRun(TextRun.create({ content: "Run, Barry," }));
|
|
575
672
|
block.appendParagraph();
|
|
576
673
|
block.appendRun(TextRun.create({ content: " RUN!!! ", styleOverrides: { isItalic: false } }));
|
|
577
|
-
block.margins = { left: 0, right: 1, top: 2, bottom: 3 };
|
|
578
674
|
const annotation = createAnnotation(block);
|
|
579
675
|
const builder = runAppendTextAnnotationGeometry(annotation, seedStyleId);
|
|
580
676
|
expect(builder.textStrings.length).to.equal(2);
|
|
@@ -592,7 +688,6 @@ describe("appendTextAnnotationGeometry", () => {
|
|
|
592
688
|
it("uses TextStyleSettings.defaults when no default style is provided", () => {
|
|
593
689
|
const block = TextBlock.create();
|
|
594
690
|
block.appendRun(TextRun.create({ content: "Run, Barry," }));
|
|
595
|
-
block.margins = { left: 0, right: 1, top: 2, bottom: 3 };
|
|
596
691
|
const annotation = createAnnotation(block);
|
|
597
692
|
const builder = runAppendTextAnnotationGeometry(annotation, "");
|
|
598
693
|
expect(builder.textStrings.length).to.equal(1);
|