@itwin/core-backend 4.8.0-dev.3 → 4.8.0-dev.31
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/CHANGELOG.md +57 -1
- package/lib/cjs/BackendHubAccess.d.ts +18 -16
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js +16 -15
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +3 -1
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +2 -0
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BisCoreSchema.js.map +1 -1
- package/lib/cjs/BlobContainerService.d.ts +3 -3
- package/lib/cjs/BlobContainerService.d.ts.map +1 -1
- package/lib/cjs/BlobContainerService.js.map +1 -1
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +19 -11
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +0 -6
- package/lib/cjs/Category.d.ts.map +1 -1
- package/lib/cjs/Category.js +0 -6
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -1
- package/lib/cjs/ChangeSummaryManager.js +13 -11
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +1 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +6 -4
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/ChangedElementsManager.js.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.d.ts.map +1 -1
- package/lib/cjs/ChangesetECAdaptor.js +242 -237
- package/lib/cjs/ChangesetECAdaptor.js.map +1 -1
- package/lib/cjs/ChannelControl.d.ts +4 -26
- package/lib/cjs/ChannelControl.d.ts.map +1 -1
- package/lib/cjs/ChannelControl.js +2 -101
- package/lib/cjs/ChannelControl.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +5 -3
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +8 -7
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +49 -24
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +66 -7
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +4 -4
- package/lib/cjs/CodeService.d.ts.map +1 -1
- package/lib/cjs/CodeService.js.map +1 -1
- package/lib/cjs/CodeSpecs.js.map +1 -1
- package/lib/cjs/ConcurrentQuery.js.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +2 -1
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +0 -3
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +0 -3
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +6 -1
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +19 -14
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +2 -2
- package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
- package/lib/cjs/ECSqlStatement.d.ts +6 -3
- package/lib/cjs/ECSqlStatement.d.ts.map +1 -1
- package/lib/cjs/ECSqlStatement.js +3 -3
- package/lib/cjs/ECSqlStatement.js.map +1 -1
- package/lib/cjs/Element.d.ts +3 -60
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +8 -64
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +0 -5
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +4 -8
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.d.ts.map +1 -1
- package/lib/cjs/ElementGraphics.js +2 -1
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/ElementTreeWalker.js.map +1 -1
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/EntityReferences.js.map +1 -1
- package/lib/cjs/ExportGraphics.js.map +1 -1
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +10 -0
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
- package/lib/cjs/GeoCoordConfig.js +22 -24
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeographicCRSServices.js +2 -2
- package/lib/cjs/GeographicCRSServices.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts.map +1 -1
- package/lib/cjs/GeometrySummary.js +49 -48
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +33 -98
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +250 -164
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelElementCloneContext.js +5 -4
- package/lib/cjs/IModelElementCloneContext.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +13 -4
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +39 -32
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +15 -13
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LineStyle.js.map +1 -1
- package/lib/cjs/LocalHub.d.ts +2 -2
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +18 -18
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/LockControl.d.ts +73 -0
- package/lib/cjs/LockControl.d.ts.map +1 -0
- package/lib/cjs/LockControl.js +11 -0
- package/lib/cjs/LockControl.js.map +1 -0
- package/lib/cjs/Material.d.ts +2 -5
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +6 -4
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +0 -22
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +5 -26
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeAppStorage.js.map +1 -1
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/NavigationRelationship.js.map +1 -1
- package/lib/cjs/PromiseMemoizer.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +17 -7
- package/lib/cjs/PropertyStore.d.ts.map +1 -1
- package/lib/cjs/PropertyStore.js +11 -5
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +0 -12
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +5 -16
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/RpcBackend.js.map +1 -1
- package/lib/cjs/SQLiteDb.d.ts +8 -4
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +25 -19
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/Schema.js.map +1 -1
- package/lib/cjs/SchemaSync.d.ts +4 -1
- package/lib/cjs/SchemaSync.d.ts.map +1 -1
- package/lib/cjs/SchemaSync.js +24 -11
- package/lib/cjs/SchemaSync.js.map +1 -1
- package/lib/cjs/SchemaUtils.js +3 -3
- package/lib/cjs/SchemaUtils.js.map +1 -1
- package/lib/cjs/SqliteChangesetReader.d.ts.map +1 -1
- package/lib/cjs/SqliteChangesetReader.js +2 -2
- package/lib/cjs/SqliteChangesetReader.js.map +1 -1
- package/lib/cjs/SqliteStatement.js +2 -2
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/TextAnnotationElement.js.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts +5 -1
- package/lib/cjs/TextAnnotationGeometry.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationGeometry.js +11 -8
- package/lib/cjs/TextAnnotationGeometry.js.map +1 -1
- package/lib/cjs/TextAnnotationLayout.d.ts +21 -13
- package/lib/cjs/TextAnnotationLayout.d.ts.map +1 -1
- package/lib/cjs/TextAnnotationLayout.js +134 -92
- package/lib/cjs/TextAnnotationLayout.js.map +1 -1
- package/lib/cjs/Texture.js.map +1 -1
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +2 -1
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +4 -2
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +1 -18
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +1 -18
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStateHydrator.js.map +1 -1
- package/lib/cjs/ViewStore.d.ts +16 -2
- package/lib/cjs/ViewStore.d.ts.map +1 -1
- package/lib/cjs/ViewStore.js +20 -6
- package/lib/cjs/ViewStore.js.map +1 -1
- package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
- package/lib/cjs/assets/Settings/Schemas/Base.Schema.json +33 -0
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +27 -31
- package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +94 -52
- package/lib/cjs/assets/Settings/backend.setting.json5 +21 -132
- package/lib/cjs/core-backend.d.ts +4 -2
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +5 -6
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +0 -10
- package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalElements.js +0 -10
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.js +2 -1
- package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +0 -18
- package/lib/cjs/domains/GenericElements.d.ts.map +1 -1
- package/lib/cjs/domains/GenericElements.js +0 -18
- package/lib/cjs/domains/GenericElements.js.map +1 -1
- package/lib/cjs/domains/GenericSchema.js.map +1 -1
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts +24 -0
- package/lib/cjs/internal/ChangesetConflictArgs.d.ts.map +1 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js +7 -0
- package/lib/cjs/internal/ChangesetConflictArgs.js.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts +34 -0
- package/lib/cjs/internal/ChannelAdmin.d.ts.map +1 -0
- package/lib/cjs/internal/ChannelAdmin.js +117 -0
- package/lib/cjs/internal/ChannelAdmin.js.map +1 -0
- package/lib/cjs/internal/NativePlatform.d.ts +15 -0
- package/lib/cjs/internal/NativePlatform.d.ts.map +1 -0
- package/lib/cjs/internal/NativePlatform.js +49 -0
- package/lib/cjs/internal/NativePlatform.js.map +1 -0
- package/lib/cjs/internal/NoLocks.d.ts +6 -0
- package/lib/cjs/internal/NoLocks.d.ts.map +1 -0
- package/lib/cjs/internal/NoLocks.js +31 -0
- package/lib/cjs/internal/NoLocks.js.map +1 -0
- package/lib/cjs/{ServerBasedLocks.d.ts → internal/ServerBasedLocks.d.ts} +10 -16
- package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -0
- package/lib/cjs/{ServerBasedLocks.js → internal/ServerBasedLocks.js} +29 -18
- package/lib/cjs/internal/ServerBasedLocks.js.map +1 -0
- package/lib/cjs/internal/Symbols.d.ts +11 -0
- package/lib/cjs/internal/Symbols.d.ts.map +1 -0
- package/lib/cjs/internal/Symbols.js +21 -0
- package/lib/cjs/internal/Symbols.js.map +1 -0
- package/lib/cjs/internal/cross-package.d.ts +4 -0
- package/lib/cjs/internal/cross-package.d.ts.map +1 -0
- package/lib/cjs/internal/cross-package.js +16 -0
- package/lib/cjs/internal/cross-package.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts +43 -0
- package/lib/cjs/internal/workspace/SettingsImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js +161 -0
- package/lib/cjs/internal/workspace/SettingsImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts +6 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js +276 -0
- package/lib/cjs/internal/workspace/SettingsSchemasImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts +41 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js +696 -0
- package/lib/cjs/internal/workspace/WorkspaceImpl.js.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts +10 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.d.ts.map +1 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js +42 -0
- package/lib/cjs/internal/workspace/WorkspaceSqliteDb.js.map +1 -0
- package/lib/cjs/rpc/multipart.js.map +1 -1
- package/lib/cjs/rpc/tracing.d.ts.map +1 -1
- package/lib/cjs/rpc/tracing.js +5 -2
- package/lib/cjs/rpc/tracing.js.map +1 -1
- package/lib/cjs/rpc/web/logging.js.map +1 -1
- package/lib/cjs/rpc/web/request.js.map +1 -1
- package/lib/cjs/rpc/web/response.js.map +1 -1
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +1 -0
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +10 -6
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +5 -3
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts +167 -138
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +68 -138
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +112 -48
- package/lib/cjs/workspace/SettingsSchemas.d.ts.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.js +1 -172
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +411 -277
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +76 -457
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/lib/cjs/workspace/WorkspaceEditor.d.ts +245 -0
- package/lib/cjs/workspace/WorkspaceEditor.d.ts.map +1 -0
- package/lib/cjs/workspace/WorkspaceEditor.js +34 -0
- package/lib/cjs/workspace/WorkspaceEditor.js.map +1 -0
- package/package.json +15 -14
- package/lib/cjs/ServerBasedLocks.d.ts.map +0 -1
- package/lib/cjs/ServerBasedLocks.js.map +0 -1
- package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +0 -45
|
@@ -12,6 +12,10 @@ export interface ProduceTextAnnotationGeometryArgs {
|
|
|
12
12
|
annotation: TextAnnotation;
|
|
13
13
|
/** The iModel from which to obtain fonts and text styles. */
|
|
14
14
|
iModel: IModelDb;
|
|
15
|
+
/** For debugging purposes only, whether to include geometry representing the bounding box and anchor point of the annotation.
|
|
16
|
+
* If true, two red lines indicating the horizontal and vertical extents of the bounding box will be included, intersecting at the anchor point.
|
|
17
|
+
*/
|
|
18
|
+
debugAnchorPointAndRange?: boolean;
|
|
15
19
|
/** @internal chiefly for tests */
|
|
16
20
|
computeTextRange?: ComputeRangesForTextLayout;
|
|
17
21
|
/** @internal chiefly for tests */
|
|
@@ -19,7 +23,7 @@ export interface ProduceTextAnnotationGeometryArgs {
|
|
|
19
23
|
/** @internal chiefly for tests */
|
|
20
24
|
findFontId?: FindFontId;
|
|
21
25
|
}
|
|
22
|
-
/** Produce a geometric representation of a text annotation.
|
|
26
|
+
/** Produce a geometric representation of a text annotation, with the annotation's anchor point at the origin.
|
|
23
27
|
* The result can be supplied to [GeometryStreamBuilder.appendTextBlock]($common).
|
|
24
28
|
* @see [[TextAnnotation2d.setAnnotation]] and [[TextAnnotation3d.setAnnotation]] to update the annotation, geometry, and placement of an annotation element.
|
|
25
29
|
* @beta
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotationGeometry.d.ts","sourceRoot":"","sources":["../../src/TextAnnotationGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,cAAc,EAAE,sBAAsB,EAA2D,MAAM,oBAAoB,CAAC;AAC/I,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,aAAa,EAA+C,MAAM,wBAAwB,CAAC;AAG5I,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"TextAnnotationGeometry.d.ts","sourceRoot":"","sources":["../../src/TextAnnotationGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAY,cAAc,EAAE,sBAAsB,EAA2D,MAAM,oBAAoB,CAAC;AAC/I,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,aAAa,EAA+C,MAAM,wBAAwB,CAAC;AAG5I,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmKtC;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,yDAAyD;IACzD,UAAU,EAAE,cAAc,CAAC;IAC3B,6DAA6D;IAC7D,MAAM,EAAE,QAAQ,CAAC;IACjB;;OAEG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;IAC9C,kCAAkC;IAClC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,kCAAkC;IAClC,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,iCAAiC,GAAG,sBAAsB,CAW7G"}
|
|
@@ -120,22 +120,26 @@ function produceTextBlockGeometry(layout, documentTransform, debugAnchorPt) {
|
|
|
120
120
|
context.entries.push({
|
|
121
121
|
color: core_common_1.ColorDef.red.toJSON(),
|
|
122
122
|
});
|
|
123
|
+
const lx = layout.range.low.x - debugAnchorPt.x;
|
|
124
|
+
const ly = layout.range.low.y - debugAnchorPt.y;
|
|
125
|
+
const hx = layout.range.high.x - debugAnchorPt.x;
|
|
126
|
+
const hy = layout.range.high.y - debugAnchorPt.y;
|
|
123
127
|
context.entries.push({
|
|
124
128
|
separator: {
|
|
125
|
-
startPoint: [
|
|
126
|
-
endPoint: [
|
|
129
|
+
startPoint: [lx, 0, 0],
|
|
130
|
+
endPoint: [hx, 0, 0],
|
|
127
131
|
},
|
|
128
132
|
});
|
|
129
133
|
context.entries.push({
|
|
130
134
|
separator: {
|
|
131
|
-
startPoint: [
|
|
132
|
-
endPoint: [
|
|
135
|
+
startPoint: [0, ly, 0],
|
|
136
|
+
endPoint: [0, hy, 0],
|
|
133
137
|
},
|
|
134
138
|
});
|
|
135
139
|
}
|
|
136
140
|
return { entries: context.entries };
|
|
137
141
|
}
|
|
138
|
-
/** Produce a geometric representation of a text annotation.
|
|
142
|
+
/** Produce a geometric representation of a text annotation, with the annotation's anchor point at the origin.
|
|
139
143
|
* The result can be supplied to [GeometryStreamBuilder.appendTextBlock]($common).
|
|
140
144
|
* @see [[TextAnnotation2d.setAnnotation]] and [[TextAnnotation3d.setAnnotation]] to update the annotation, geometry, and placement of an annotation element.
|
|
141
145
|
* @beta
|
|
@@ -145,10 +149,9 @@ function produceTextAnnotationGeometry(args) {
|
|
|
145
149
|
...args,
|
|
146
150
|
textBlock: args.annotation.textBlock,
|
|
147
151
|
});
|
|
148
|
-
const dimensions = layout.range
|
|
152
|
+
const dimensions = layout.range;
|
|
149
153
|
const transform = args.annotation.computeTransform(dimensions);
|
|
150
|
-
const
|
|
151
|
-
const anchorPoint = debugAnchorPointAndRange ? args.annotation.computeAnchorPoint(dimensions) : undefined;
|
|
154
|
+
const anchorPoint = args.debugAnchorPointAndRange ? args.annotation.computeAnchorPoint(dimensions) : undefined;
|
|
152
155
|
return produceTextBlockGeometry(layout, transform, anchorPoint);
|
|
153
156
|
}
|
|
154
157
|
exports.produceTextAnnotationGeometry = produceTextAnnotationGeometry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotationGeometry.js","sourceRoot":"","sources":["../../src/TextAnnotationGeometry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+I;AAC/I,iEAA4I;AAC5I,wDAA4F;AAC5F,sDAA6C;AAQ7C,SAAS,QAAQ,CAAC,KAAqB,EAAE,OAAwB;IAC/D,IAAI,KAAK,KAAK,OAAO,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,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAClE,CAAC;AAZD,sEAYC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ElementGeometry\r\n */\r\n\r\nimport { ColorDef, TextAnnotation, TextBlockGeometryProps, TextBlockGeometryPropsEntry, TextString, TextStyleColor } from \"@itwin/core-common\";\r\nimport { ComputeRangesForTextLayout, FindFontId, FindTextStyle, layoutTextBlock, RunLayout, TextBlockLayout } from \"./TextAnnotationLayout\";\r\nimport { LineSegment3d, Point3d, Range2d, Transform, Vector2d } from \"@itwin/core-geometry\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { IModelDb } from \"./IModelDb\";\r\n\r\ninterface GeometryContext {\r\n curColor?: TextStyleColor;\r\n entries: TextBlockGeometryPropsEntry[];\r\n}\r\n\r\nfunction setColor(color: TextStyleColor, context: GeometryContext): void {\r\n if (color !== context.curColor) {\r\n context.curColor = color;\r\n context.entries.push({ color });\r\n }\r\n}\r\n\r\nfunction createTextString(text: string, run: RunLayout, origin?: Point3d): TextString {\r\n assert(text.length > 0);\r\n\r\n const { lineHeight, widthFactor, isBold, isItalic, isUnderlined } = run.style;\r\n\r\n return new TextString({\r\n text,\r\n font: run.fontId,\r\n height: lineHeight,\r\n widthFactor,\r\n bold: isBold,\r\n italic: isItalic,\r\n underline: isUnderlined,\r\n origin,\r\n });\r\n}\r\n\r\nfunction processTextRun(run: RunLayout, transform: Transform, context: GeometryContext): void {\r\n assert(run.source.type === \"text\");\r\n const text = run.source.content.substring(run.charOffset, run.charOffset + run.numChars);\r\n if (text.length === 0) {\r\n return;\r\n }\r\n\r\n const ts = createTextString(text, run);\r\n if (\"none\" !== run.source.baselineShift) {\r\n const isSub = \"subscript\" === run.source.baselineShift;\r\n const offsetFactor = run.style[isSub ? \"subScriptOffsetFactor\" : \"superScriptOffsetFactor\"];\r\n const scale = run.style[isSub ? \"subScriptScale\" : \"superScriptScale\"];\r\n\r\n ts.origin.y += offsetFactor * ts.height;\r\n ts.height *= scale;\r\n }\r\n\r\n ts.transformInPlace(transform);\r\n\r\n setColor(run.style.color, context);\r\n context.entries.push({ text: ts});\r\n}\r\n\r\nfunction createFractionTextString(text: string, run: RunLayout, origin: Point3d, transform: Transform): TextString {\r\n const ts = createTextString(text, run, origin);\r\n assert(undefined !== ts.widthFactor);\r\n\r\n ts.height *= run.style.stackedFractionScale;\r\n\r\n ts.transformInPlace(transform);\r\n\r\n return ts;\r\n}\r\n\r\nfunction processFractionRun(run: RunLayout, transform: Transform, context: GeometryContext): void {\r\n const source = run.source;\r\n assert(source.type === \"fraction\");\r\n\r\n if (source.numerator.length === 0 && source.denominator.length === 0) {\r\n return;\r\n }\r\n\r\n assert(undefined !== run.numeratorRange && undefined !== run.denominatorRange);\r\n\r\n const fontSize = new Vector2d(run.style.lineHeight * run.style.widthFactor, run.style.lineHeight);\r\n fontSize.scale(run.style.stackedFractionScale, fontSize);\r\n\r\n const numeratorOffset = new Point3d(run.numeratorRange.low.x, run.numeratorRange.low.y, 0);\r\n const denominatorOffset = new Point3d(run.denominatorRange.low.x, run.denominatorRange.low.y, 0);\r\n\r\n setColor(run.style.color, context);\r\n\r\n if (source.numerator.length > 0) {\r\n context.entries.push({ text: createFractionTextString(source.numerator, run, numeratorOffset, transform) });\r\n }\r\n\r\n const numeratorRange = Range2d.fromJSON(run.numeratorRange);\r\n const denominatorRange = Range2d.fromJSON(run.denominatorRange);\r\n\r\n let separator: LineSegment3d;\r\n if (run.style.stackedFractionType === \"horizontal\") {\r\n const fractionWidth = Math.max(numeratorRange.xLength(), denominatorRange.xLength());\r\n const y = 1.25 * denominatorRange.yLength();\r\n separator = LineSegment3d.createXYXY(0, y, fractionWidth, y);\r\n } else {\r\n const p0 = new Point3d(denominatorRange.low.x - fontSize.x / 2, denominatorRange.low.y + fontSize.y * (1 / 3), 0);\r\n const p1 = new Point3d(p0.x + fontSize.x, p0.y + fontSize.y * 1.5, 0);\r\n separator = LineSegment3d.createCapture(p0, p1);\r\n }\r\n\r\n separator.tryTransformInPlace(transform);\r\n\r\n context.entries.push({\r\n separator: {\r\n startPoint: separator.point0Ref.toJSON(),\r\n endPoint: separator.point1Ref.toJSON(),\r\n },\r\n });\r\n\r\n if (source.denominator.length > 0) {\r\n context.entries.push({ text: createFractionTextString(source.denominator, run,denominatorOffset, transform) });\r\n }\r\n}\r\n\r\nfunction produceTextBlockGeometry(layout: TextBlockLayout, documentTransform: Transform, debugAnchorPt?: Point3d): TextBlockGeometryProps {\r\n const context: GeometryContext = { entries: [] };\r\n for (const line of layout.lines) {\r\n const lineTrans = Transform.createTranslationXYZ(line.offsetFromDocument.x, line.offsetFromDocument.y, 0);\r\n for (const run of line.runs) {\r\n if (\"linebreak\" === run.source.type) {\r\n continue;\r\n }\r\n\r\n const runTrans = Transform.createTranslationXYZ(run.offsetFromLine.x, run.offsetFromLine.y, 0);\r\n lineTrans.multiplyTransformTransform(runTrans, runTrans);\r\n documentTransform.multiplyTransformTransform(runTrans, runTrans);\r\n if (\"text\" === run.source.type) {\r\n processTextRun(run, runTrans, context);\r\n } else {\r\n processFractionRun(run, runTrans, context);\r\n }\r\n }\r\n }\r\n\r\n if (debugAnchorPt) {\r\n // Draw lines representing the horizontal and vertical ranges, intersecting at the anchor point.\r\n context.entries.push({\r\n color: ColorDef.red.toJSON(),\r\n });\r\n\r\n context.entries.push({\r\n separator: {\r\n startPoint: [layout.range.low.x, debugAnchorPt.y, 0],\r\n endPoint: [layout.range.high.x, debugAnchorPt.y, 0],\r\n },\r\n });\r\n context.entries.push({\r\n separator: {\r\n startPoint: [debugAnchorPt.x, layout.range.low.y, 0],\r\n endPoint: [debugAnchorPt.x, layout.range.high.y, 0],\r\n },\r\n });\r\n }\r\n\r\n return { entries: context.entries };\r\n}\r\n\r\n/** Arguments supplied to [[produceTextAnnotationGeometry]].\r\n * @beta\r\n */\r\nexport interface ProduceTextAnnotationGeometryArgs {\r\n /** The annotation from which to produce the geometry. */\r\n annotation: TextAnnotation;\r\n /** The iModel from which to obtain fonts and text styles. */\r\n iModel: IModelDb;\r\n /** @internal chiefly for tests */\r\n computeTextRange?: ComputeRangesForTextLayout;\r\n /** @internal chiefly for tests */\r\n findTextStyle?: FindTextStyle;\r\n /** @internal chiefly for tests */\r\n findFontId?: FindFontId;\r\n}\r\n\r\n/** Produce a geometric representation of a text annotation.\r\n * The result can be supplied to [GeometryStreamBuilder.appendTextBlock]($common).\r\n * @see [[TextAnnotation2d.setAnnotation]] and [[TextAnnotation3d.setAnnotation]] to update the annotation, geometry, and placement of an annotation element.\r\n * @beta\r\n */\r\nexport function produceTextAnnotationGeometry(args: ProduceTextAnnotationGeometryArgs): TextBlockGeometryProps {\r\n const layout = layoutTextBlock({\r\n ...args,\r\n textBlock: args.annotation.textBlock,\r\n });\r\n\r\n const dimensions = layout.range.diagonal();\r\n const transform = args.annotation.computeTransform(dimensions);\r\n\r\n const debugAnchorPointAndRange = false;\r\n const anchorPoint = debugAnchorPointAndRange ? args.annotation.computeAnchorPoint(dimensions) : undefined;\r\n return produceTextBlockGeometry(layout, transform, anchorPoint);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotationGeometry.js","sourceRoot":"","sources":["../../src/TextAnnotationGeometry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+I;AAC/I,iEAA4I;AAC5I,wDAA4F;AAC5F,sDAA6C;AAQ7C,SAAS,QAAQ,CAAC,KAAqB,EAAE,OAAwB;IAC/D,IAAI,KAAK,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;QACzB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAClC,CAAC;A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AAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAClE,CAAC;AAXD,sEAWC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module ElementGeometry\n */\n\nimport { ColorDef, TextAnnotation, TextBlockGeometryProps, TextBlockGeometryPropsEntry, TextString, TextStyleColor } from \"@itwin/core-common\";\nimport { ComputeRangesForTextLayout, FindFontId, FindTextStyle, layoutTextBlock, RunLayout, TextBlockLayout } from \"./TextAnnotationLayout\";\nimport { LineSegment3d, Point3d, Range2d, Transform, Vector2d } from \"@itwin/core-geometry\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { IModelDb } from \"./IModelDb\";\n\ninterface GeometryContext {\n curColor?: TextStyleColor;\n entries: TextBlockGeometryPropsEntry[];\n}\n\nfunction setColor(color: TextStyleColor, context: GeometryContext): void {\n if (color !== context.curColor) {\n context.curColor = color;\n context.entries.push({ color });\n }\n}\n\nfunction createTextString(text: string, run: RunLayout, origin?: Point3d): TextString {\n assert(text.length > 0);\n\n const { lineHeight, widthFactor, isBold, isItalic, isUnderlined } = run.style;\n\n return new TextString({\n text,\n font: run.fontId,\n height: lineHeight,\n widthFactor,\n bold: isBold,\n italic: isItalic,\n underline: isUnderlined,\n origin,\n });\n}\n\nfunction processTextRun(run: RunLayout, transform: Transform, context: GeometryContext): void {\n assert(run.source.type === \"text\");\n const text = run.source.content.substring(run.charOffset, run.charOffset + run.numChars);\n if (text.length === 0) {\n return;\n }\n\n const ts = createTextString(text, run);\n if (\"none\" !== run.source.baselineShift) {\n const isSub = \"subscript\" === run.source.baselineShift;\n const offsetFactor = run.style[isSub ? \"subScriptOffsetFactor\" : \"superScriptOffsetFactor\"];\n const scale = run.style[isSub ? \"subScriptScale\" : \"superScriptScale\"];\n\n ts.origin.y += offsetFactor * ts.height;\n ts.height *= scale;\n }\n\n ts.transformInPlace(transform);\n\n setColor(run.style.color, context);\n context.entries.push({ text: ts});\n}\n\nfunction createFractionTextString(text: string, run: RunLayout, origin: Point3d, transform: Transform): TextString {\n const ts = createTextString(text, run, origin);\n assert(undefined !== ts.widthFactor);\n\n ts.height *= run.style.stackedFractionScale;\n\n ts.transformInPlace(transform);\n\n return ts;\n}\n\nfunction processFractionRun(run: RunLayout, transform: Transform, context: GeometryContext): void {\n const source = run.source;\n assert(source.type === \"fraction\");\n\n if (source.numerator.length === 0 && source.denominator.length === 0) {\n return;\n }\n\n assert(undefined !== run.numeratorRange && undefined !== run.denominatorRange);\n\n const fontSize = new Vector2d(run.style.lineHeight * run.style.widthFactor, run.style.lineHeight);\n fontSize.scale(run.style.stackedFractionScale, fontSize);\n\n const numeratorOffset = new Point3d(run.numeratorRange.low.x, run.numeratorRange.low.y, 0);\n const denominatorOffset = new Point3d(run.denominatorRange.low.x, run.denominatorRange.low.y, 0);\n\n setColor(run.style.color, context);\n\n if (source.numerator.length > 0) {\n context.entries.push({ text: createFractionTextString(source.numerator, run, numeratorOffset, transform) });\n }\n\n const numeratorRange = Range2d.fromJSON(run.numeratorRange);\n const denominatorRange = Range2d.fromJSON(run.denominatorRange);\n\n let separator: LineSegment3d;\n if (run.style.stackedFractionType === \"horizontal\") {\n const fractionWidth = Math.max(numeratorRange.xLength(), denominatorRange.xLength());\n const y = 1.25 * denominatorRange.yLength();\n separator = LineSegment3d.createXYXY(0, y, fractionWidth, y);\n } else {\n const p0 = new Point3d(denominatorRange.low.x - fontSize.x / 2, denominatorRange.low.y + fontSize.y * (1 / 3), 0);\n const p1 = new Point3d(p0.x + fontSize.x, p0.y + fontSize.y * 1.5, 0);\n separator = LineSegment3d.createCapture(p0, p1);\n }\n\n separator.tryTransformInPlace(transform);\n\n context.entries.push({\n separator: {\n startPoint: separator.point0Ref.toJSON(),\n endPoint: separator.point1Ref.toJSON(),\n },\n });\n\n if (source.denominator.length > 0) {\n context.entries.push({ text: createFractionTextString(source.denominator, run,denominatorOffset, transform) });\n }\n}\n\nfunction produceTextBlockGeometry(layout: TextBlockLayout, documentTransform: Transform, debugAnchorPt?: Point3d): TextBlockGeometryProps {\n const context: GeometryContext = { entries: [] };\n for (const line of layout.lines) {\n const lineTrans = Transform.createTranslationXYZ(line.offsetFromDocument.x, line.offsetFromDocument.y, 0);\n for (const run of line.runs) {\n if (\"linebreak\" === run.source.type) {\n continue;\n }\n\n const runTrans = Transform.createTranslationXYZ(run.offsetFromLine.x, run.offsetFromLine.y, 0);\n lineTrans.multiplyTransformTransform(runTrans, runTrans);\n documentTransform.multiplyTransformTransform(runTrans, runTrans);\n if (\"text\" === run.source.type) {\n processTextRun(run, runTrans, context);\n } else {\n processFractionRun(run, runTrans, context);\n }\n }\n }\n\n if (debugAnchorPt) {\n // Draw lines representing the horizontal and vertical ranges, intersecting at the anchor point.\n context.entries.push({\n color: ColorDef.red.toJSON(),\n });\n\n const lx = layout.range.low.x - debugAnchorPt.x;\n const ly = layout.range.low.y - debugAnchorPt.y;\n const hx = layout.range.high.x - debugAnchorPt.x;\n const hy = layout.range.high.y - debugAnchorPt.y;\n\n context.entries.push({\n separator: {\n startPoint: [lx, 0, 0],\n endPoint: [hx, 0, 0],\n },\n });\n context.entries.push({\n separator: {\n startPoint: [0, ly, 0],\n endPoint: [0, hy, 0],\n },\n });\n }\n\n return { entries: context.entries };\n}\n\n/** Arguments supplied to [[produceTextAnnotationGeometry]].\n * @beta\n */\nexport interface ProduceTextAnnotationGeometryArgs {\n /** The annotation from which to produce the geometry. */\n annotation: TextAnnotation;\n /** The iModel from which to obtain fonts and text styles. */\n iModel: IModelDb;\n /** For debugging purposes only, whether to include geometry representing the bounding box and anchor point of the annotation.\n * If true, two red lines indicating the horizontal and vertical extents of the bounding box will be included, intersecting at the anchor point.\n */\n debugAnchorPointAndRange?: boolean;\n /** @internal chiefly for tests */\n computeTextRange?: ComputeRangesForTextLayout;\n /** @internal chiefly for tests */\n findTextStyle?: FindTextStyle;\n /** @internal chiefly for tests */\n findFontId?: FindFontId;\n}\n\n/** Produce a geometric representation of a text annotation, with the annotation's anchor point at the origin.\n * The result can be supplied to [GeometryStreamBuilder.appendTextBlock]($common).\n * @see [[TextAnnotation2d.setAnnotation]] and [[TextAnnotation3d.setAnnotation]] to update the annotation, geometry, and placement of an annotation element.\n * @beta\n */\nexport function produceTextAnnotationGeometry(args: ProduceTextAnnotationGeometryArgs): TextBlockGeometryProps {\n const layout = layoutTextBlock({\n ...args,\n textBlock: args.annotation.textBlock,\n });\n\n const dimensions = layout.range;\n const transform = args.annotation.computeTransform(dimensions);\n\n const anchorPoint = args.debugAnchorPointAndRange ? args.annotation.computeAnchorPoint(dimensions) : undefined;\n return produceTextBlockGeometry(layout, transform, anchorPoint);\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module ElementGeometry
|
|
3
3
|
*/
|
|
4
|
-
import { BaselineShift, FontId, FractionRun, Paragraph, Run, TextBlock, TextRun, TextStyleSettings } from "@itwin/core-common";
|
|
5
|
-
import { Range2d
|
|
4
|
+
import { BaselineShift, FontId, FractionRun, LineLayoutResult, Paragraph, Run, RunLayoutResult, TextBlock, TextBlockLayoutResult, TextRun, TextStyleSettings } from "@itwin/core-common";
|
|
5
|
+
import { Range2d } from "@itwin/core-geometry";
|
|
6
6
|
import { IModelDb } from "./IModelDb";
|
|
7
7
|
/** @internal */
|
|
8
8
|
export interface TextLayoutRanges {
|
|
@@ -29,17 +29,15 @@ export type ComputeRangesForTextLayout = (args: ComputeRangesForTextLayoutArgs)
|
|
|
29
29
|
export type FindFontId = (name: string) => FontId;
|
|
30
30
|
/** @internal */
|
|
31
31
|
export type FindTextStyle = (name: string) => TextStyleSettings;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Arguments supplied to [[computeLayoutTextBlockResult]].
|
|
33
34
|
* @beta
|
|
34
35
|
*/
|
|
35
|
-
export interface
|
|
36
|
+
export interface LayoutTextBlockArgs {
|
|
36
37
|
/** The text block whose extents are to be computed. */
|
|
37
38
|
textBlock: TextBlock;
|
|
38
39
|
/** The iModel from which to obtain fonts and [TextStyle]($common)s when laying out glyphs. */
|
|
39
40
|
iModel: IModelDb;
|
|
40
|
-
}
|
|
41
|
-
/** @internal */
|
|
42
|
-
export interface LayoutTextBlockArgs extends ComputeTextBlockExtentsArgs {
|
|
43
41
|
/** @internal chiefly for tests, by default uses IModelJsNative.DgnDb.computeRangesForText. */
|
|
44
42
|
computeTextRange?: ComputeRangesForTextLayout;
|
|
45
43
|
/** @internal chiefly for tests, by default looks up styles from a workspace. */
|
|
@@ -53,16 +51,17 @@ export interface LayoutTextBlockArgs extends ComputeTextBlockExtentsArgs {
|
|
|
53
51
|
* Each series of consecutive non-linebreak runs within a paragraph is concatenated into one line.
|
|
54
52
|
* If the document specifies a width > 0, individual lines are split to try to avoid exceeding that width.
|
|
55
53
|
* Individual TextRuns can be split onto multiple lines at word boundaries if necessary. Individual FractionRuns are never split.
|
|
54
|
+
* @see [[computeLayoutTextBlockResult]]
|
|
56
55
|
* @internal
|
|
57
56
|
*/
|
|
58
57
|
export declare function layoutTextBlock(args: LayoutTextBlockArgs): TextBlockLayout;
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* The
|
|
58
|
+
/**
|
|
59
|
+
* Gets the result of laying out the the contents of a TextBlock into a series of lines containing runs.
|
|
60
|
+
* The visual layout accounts for the [TextStyle]($common)s, fonts, and [TextBlock.width]($common). It applies word-wrapping if needed.
|
|
61
|
+
* The layout returned matches the visual layout of the geometry produced by [[produceTextAnnotationGeometry]].
|
|
63
62
|
* @beta
|
|
64
63
|
*/
|
|
65
|
-
export declare function
|
|
64
|
+
export declare function computeLayoutTextBlockResult(args: LayoutTextBlockArgs): TextBlockLayoutResult;
|
|
66
65
|
declare class LayoutContext {
|
|
67
66
|
private readonly _computeTextRange;
|
|
68
67
|
private readonly _findTextStyle;
|
|
@@ -99,11 +98,14 @@ export declare class RunLayout {
|
|
|
99
98
|
fontId: FontId;
|
|
100
99
|
private constructor();
|
|
101
100
|
static create(source: Run, context: LayoutContext): RunLayout;
|
|
101
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
102
|
+
stringify(): string;
|
|
102
103
|
canWrap(): this is {
|
|
103
104
|
source: TextRun;
|
|
104
105
|
};
|
|
105
106
|
private cloneForWrap;
|
|
106
|
-
|
|
107
|
+
split(context: LayoutContext): RunLayout[];
|
|
108
|
+
toResult(paragraph: Paragraph): RunLayoutResult;
|
|
107
109
|
}
|
|
108
110
|
/** @internal */
|
|
109
111
|
export declare class LineLayout {
|
|
@@ -116,12 +118,15 @@ export declare class LineLayout {
|
|
|
116
118
|
};
|
|
117
119
|
private _runs;
|
|
118
120
|
constructor(source: Paragraph);
|
|
121
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
122
|
+
stringify(): string;
|
|
119
123
|
get runs(): ReadonlyArray<RunLayout>;
|
|
120
124
|
get isEmpty(): boolean;
|
|
121
125
|
get back(): RunLayout;
|
|
122
126
|
append(run: RunLayout): void;
|
|
123
127
|
/** Invoked every time a run is appended,. */
|
|
124
128
|
private computeRanges;
|
|
129
|
+
toResult(textBlock: TextBlock): LineLayoutResult;
|
|
125
130
|
}
|
|
126
131
|
/**
|
|
127
132
|
* Describes the layout of a text block as a collection of lines containing runs.
|
|
@@ -132,6 +137,9 @@ export declare class TextBlockLayout {
|
|
|
132
137
|
range: Range2d;
|
|
133
138
|
lines: LineLayout[];
|
|
134
139
|
constructor(source: TextBlock, context: LayoutContext);
|
|
140
|
+
toResult(): TextBlockLayoutResult;
|
|
141
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
142
|
+
stringify(): string;
|
|
135
143
|
private get _back();
|
|
136
144
|
private populateLines;
|
|
137
145
|
private justifyLines;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotationLayout.d.ts","sourceRoot":"","sources":["../../src/TextAnnotationLayout.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"TextAnnotationLayout.d.ts","sourceRoot":"","sources":["../../src/TextAnnotationLayout.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,qBAAqB,EAAE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,oBAAoB,CAAC;AACjN,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,gBAAgB;AAChB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,8BAA8B,KAAK,gBAAgB,CAAC;AAEpG,gBAAgB;AAChB,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAElD,gBAAgB;AAChB,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,iBAAiB,CAAC;AAEhE;;;GAGG;AACH,MAAM,WA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I,SAAS,CAG3B;IAEM,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI;IAKnC,6CAA6C;IAC7C,OAAO,CAAC,aAAa;IA0Bd,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,gBAAgB;CASxD;AAED;;;GAGG;AACH,qBAAa,eAAe;IACnB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,UAAiB;IACtB,KAAK,EAAE,UAAU,EAAE,CAAM;gBAEb,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa;IAYrD,QAAQ,IAAI,qBAAqB;IAOxC,yEAAyE;IAClE,SAAS,IAAI,MAAM;IAI1B,OAAO,KAAK,KAAK,GAGhB;IAED,OAAO,CAAC,aAAa;IAqDrB,OAAO,CAAC,YAAY;IA4BpB,OAAO,CAAC,SAAS;CAoClB"}
|
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
* @module ElementGeometry
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TextBlockLayout = exports.LineLayout = exports.RunLayout = exports.
|
|
10
|
+
exports.TextBlockLayout = exports.LineLayout = exports.RunLayout = exports.computeLayoutTextBlockResult = exports.layoutTextBlock = void 0;
|
|
11
11
|
const core_common_1 = require("@itwin/core-common");
|
|
12
12
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
13
13
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
14
|
+
const LineBreaker = require("linebreak");
|
|
14
15
|
/**
|
|
15
16
|
* Lays out the contents of a TextBlock into a series of lines containing runs.
|
|
16
17
|
* Each paragraph is decomposed into a series of lines.
|
|
17
18
|
* Each series of consecutive non-linebreak runs within a paragraph is concatenated into one line.
|
|
18
19
|
* If the document specifies a width > 0, individual lines are split to try to avoid exceeding that width.
|
|
19
20
|
* Individual TextRuns can be split onto multiple lines at word boundaries if necessary. Individual FractionRuns are never split.
|
|
21
|
+
* @see [[computeLayoutTextBlockResult]]
|
|
20
22
|
* @internal
|
|
21
23
|
*/
|
|
22
24
|
function layoutTextBlock(args) {
|
|
@@ -27,18 +29,17 @@ function layoutTextBlock(args) {
|
|
|
27
29
|
return new TextBlockLayout(args.textBlock, new LayoutContext(args.textBlock, computeTextRange, findTextStyle, findFontId));
|
|
28
30
|
}
|
|
29
31
|
exports.layoutTextBlock = layoutTextBlock;
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* The
|
|
32
|
+
/**
|
|
33
|
+
* Gets the result of laying out the the contents of a TextBlock into a series of lines containing runs.
|
|
34
|
+
* The visual layout accounts for the [TextStyle]($common)s, fonts, and [TextBlock.width]($common). It applies word-wrapping if needed.
|
|
35
|
+
* The layout returned matches the visual layout of the geometry produced by [[produceTextAnnotationGeometry]].
|
|
34
36
|
* @beta
|
|
35
37
|
*/
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
return { x: range.high.x, y: range.high.y };
|
|
38
|
+
function computeLayoutTextBlockResult(args) {
|
|
39
|
+
const layout = layoutTextBlock(args);
|
|
40
|
+
return layout.toResult();
|
|
40
41
|
}
|
|
41
|
-
exports.
|
|
42
|
+
exports.computeLayoutTextBlockResult = computeLayoutTextBlockResult;
|
|
42
43
|
function scaleRange(range, scale) {
|
|
43
44
|
range.low.scaleInPlace(scale);
|
|
44
45
|
range.high.scaleInPlace(scale);
|
|
@@ -147,6 +148,22 @@ class LayoutContext {
|
|
|
147
148
|
return { layout, numerator, denominator };
|
|
148
149
|
}
|
|
149
150
|
}
|
|
151
|
+
function split(source) {
|
|
152
|
+
if (source.length === 0) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
let index = 0;
|
|
156
|
+
const segments = [];
|
|
157
|
+
const breaker = new LineBreaker(source);
|
|
158
|
+
for (let brk = breaker.nextBreak(); brk; brk = breaker.nextBreak()) {
|
|
159
|
+
segments.push({
|
|
160
|
+
segment: source.slice(index, brk.position),
|
|
161
|
+
index,
|
|
162
|
+
});
|
|
163
|
+
index = brk.position;
|
|
164
|
+
}
|
|
165
|
+
return segments;
|
|
166
|
+
}
|
|
150
167
|
/** @internal */
|
|
151
168
|
class RunLayout {
|
|
152
169
|
constructor(props) {
|
|
@@ -192,6 +209,10 @@ class RunLayout {
|
|
|
192
209
|
}
|
|
193
210
|
return new RunLayout({ source, charOffset, numChars, range, justificationRange, denominatorRange, numeratorRange, offsetFromLine, style, fontId });
|
|
194
211
|
}
|
|
212
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
213
|
+
stringify() {
|
|
214
|
+
return this.source.type === "text" ? this.source.content.substring(this.charOffset, this.charOffset + this.numChars) : this.source.stringify();
|
|
215
|
+
}
|
|
195
216
|
canWrap() {
|
|
196
217
|
return this.source.type === "text";
|
|
197
218
|
}
|
|
@@ -206,48 +227,44 @@ class RunLayout {
|
|
|
206
227
|
offsetFromLine: { ...this.offsetFromLine },
|
|
207
228
|
});
|
|
208
229
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
230
|
+
split(context) {
|
|
231
|
+
(0, core_bentley_1.assert)(this.charOffset === 0, "cannot re-split a run");
|
|
232
|
+
if (!this.canWrap() || this.charOffset > 0) {
|
|
233
|
+
return [this];
|
|
212
234
|
}
|
|
213
|
-
// An optimization that tracks the computed width so far so we don't have to repeatedly recompute preceding character ranges.
|
|
214
|
-
// Assumes (to the best of Jeff's knowledge) that characters before a break point can't affect the shaping of subsequent characters.
|
|
215
|
-
let runningWidth = 0;
|
|
216
|
-
let breakPos = 0;
|
|
217
|
-
// ###TODO TypeScript only provides type declarations for Intl.Segmenter if targeting ES2022+.
|
|
218
|
-
// But doing so causes inexplicable issues with initialization of Model.modeledElement.
|
|
219
|
-
// So until that's resolved, access it via cast to any.
|
|
220
|
-
const segmenter = new global.Intl.Segmenter(undefined, { granularity: "word" });
|
|
221
235
|
const myText = this.source.content.substring(this.charOffset, this.charOffset + this.numChars);
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
const segments = split(myText);
|
|
237
|
+
if (segments.length <= 1) {
|
|
238
|
+
return [this];
|
|
224
239
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
240
|
+
return segments.map((segment) => {
|
|
241
|
+
return this.cloneForWrap({
|
|
242
|
+
ranges: context.computeRangeForText(segment.segment, this.style, this.source.baselineShift),
|
|
243
|
+
charOffset: segment.index,
|
|
244
|
+
numChars: segment.segment.length,
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
toResult(paragraph) {
|
|
249
|
+
const result = {
|
|
250
|
+
sourceRunIndex: paragraph.runs.indexOf(this.source),
|
|
251
|
+
fontId: this.fontId,
|
|
252
|
+
characterOffset: this.charOffset,
|
|
253
|
+
characterCount: this.numChars,
|
|
254
|
+
range: this.range.toJSON(),
|
|
255
|
+
offsetFromLine: this.offsetFromLine,
|
|
256
|
+
textStyle: this.style.toJSON(),
|
|
257
|
+
};
|
|
258
|
+
if (this.justificationRange) {
|
|
259
|
+
result.justificationRange = this.justificationRange.toJSON();
|
|
236
260
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return undefined;
|
|
261
|
+
if (this.numeratorRange) {
|
|
262
|
+
result.numeratorRange = this.numeratorRange.toJSON();
|
|
240
263
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const leftover = this.source.content.substring(charOffset, charOffset + numChars);
|
|
246
|
-
return this.cloneForWrap({
|
|
247
|
-
ranges: context.computeRangeForText(leftover, this.style, this.source.baselineShift),
|
|
248
|
-
charOffset,
|
|
249
|
-
numChars,
|
|
250
|
-
});
|
|
264
|
+
if (this.denominatorRange) {
|
|
265
|
+
result.denominatorRange = this.denominatorRange.toJSON();
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
251
268
|
}
|
|
252
269
|
}
|
|
253
270
|
exports.RunLayout = RunLayout;
|
|
@@ -260,6 +277,11 @@ class LineLayout {
|
|
|
260
277
|
this._runs = [];
|
|
261
278
|
this.source = source;
|
|
262
279
|
}
|
|
280
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
281
|
+
stringify() {
|
|
282
|
+
const runs = this._runs.map((run) => run.stringify());
|
|
283
|
+
return `${runs.join("")}`;
|
|
284
|
+
}
|
|
263
285
|
get runs() { return this._runs; }
|
|
264
286
|
get isEmpty() { return this._runs.length === 0; }
|
|
265
287
|
get back() {
|
|
@@ -274,8 +296,15 @@ class LineLayout {
|
|
|
274
296
|
computeRanges() {
|
|
275
297
|
this.range.low.setZero();
|
|
276
298
|
this.range.high.setZero();
|
|
299
|
+
// Some runs (fractions) are taller than others.
|
|
300
|
+
// We want to center each run vertically inside the line.
|
|
301
|
+
let lineHeight = 0;
|
|
277
302
|
for (const run of this._runs) {
|
|
278
|
-
|
|
303
|
+
lineHeight = Math.max(lineHeight, run.range.yLength());
|
|
304
|
+
}
|
|
305
|
+
for (const run of this._runs) {
|
|
306
|
+
const runHeight = run.range.yLength();
|
|
307
|
+
const runOffset = { x: this.range.high.x, y: (lineHeight - runHeight) / 2 };
|
|
279
308
|
run.offsetFromLine = runOffset;
|
|
280
309
|
const runLayoutRange = run.range.cloneTranslated(runOffset);
|
|
281
310
|
this.range.extendRange(runLayoutRange);
|
|
@@ -285,6 +314,15 @@ class LineLayout {
|
|
|
285
314
|
}
|
|
286
315
|
}
|
|
287
316
|
}
|
|
317
|
+
toResult(textBlock) {
|
|
318
|
+
return {
|
|
319
|
+
sourceParagraphIndex: textBlock.paragraphs.indexOf(this.source),
|
|
320
|
+
runs: this.runs.map((x) => x.toResult(this.source)),
|
|
321
|
+
range: this.range.toJSON(),
|
|
322
|
+
justificationRange: this.justificationRange.toJSON(),
|
|
323
|
+
offsetFromDocument: this.offsetFromDocument,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
288
326
|
}
|
|
289
327
|
exports.LineLayout = LineLayout;
|
|
290
328
|
/**
|
|
@@ -296,9 +334,23 @@ class TextBlockLayout {
|
|
|
296
334
|
this.range = new core_geometry_1.Range2d();
|
|
297
335
|
this.lines = [];
|
|
298
336
|
this.source = source;
|
|
337
|
+
if (source.width > 0) {
|
|
338
|
+
this.range.low.x = 0;
|
|
339
|
+
this.range.high.x = source.width;
|
|
340
|
+
}
|
|
299
341
|
this.populateLines(context);
|
|
300
342
|
this.justifyLines();
|
|
301
343
|
}
|
|
344
|
+
toResult() {
|
|
345
|
+
return {
|
|
346
|
+
lines: this.lines.map((x) => x.toResult(this.source)),
|
|
347
|
+
range: this.range.toJSON(),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/** Compute a string representation, primarily for debugging purposes. */
|
|
351
|
+
stringify() {
|
|
352
|
+
return this.lines.map((line) => line.stringify()).join("\n");
|
|
353
|
+
}
|
|
302
354
|
get _back() {
|
|
303
355
|
(0, core_bentley_1.assert)(this.lines.length > 0);
|
|
304
356
|
return this.lines[this.lines.length - 1];
|
|
@@ -308,66 +360,53 @@ class TextBlockLayout {
|
|
|
308
360
|
if (doc.paragraphs.length === 0) {
|
|
309
361
|
return;
|
|
310
362
|
}
|
|
311
|
-
const
|
|
312
|
-
let
|
|
363
|
+
const doWrap = doc.width > 0;
|
|
364
|
+
let curLine = new LineLayout(doc.paragraphs[0]);
|
|
313
365
|
for (let i = 0; i < doc.paragraphs.length; i++) {
|
|
314
366
|
const paragraph = doc.paragraphs[i];
|
|
315
367
|
if (i > 0) {
|
|
316
|
-
|
|
368
|
+
curLine = this.flushLine(context, curLine, paragraph);
|
|
369
|
+
}
|
|
370
|
+
let runs = paragraph.runs.map((run) => RunLayout.create(run, context));
|
|
371
|
+
if (doWrap) {
|
|
372
|
+
runs = runs.map((run) => run.split(context)).flat();
|
|
317
373
|
}
|
|
318
|
-
for (const run of
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
line.append(layoutRun);
|
|
323
|
-
line = this.flushLine(context, line);
|
|
374
|
+
for (const run of runs) {
|
|
375
|
+
if ("linebreak" === run.source.type) {
|
|
376
|
+
curLine.append(run);
|
|
377
|
+
curLine = this.flushLine(context, curLine);
|
|
324
378
|
continue;
|
|
325
379
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
// Do we fit (no wrapping or narrow enough)? Append and go around to the next run.
|
|
329
|
-
if (effectiveRunWidth < effectiveRemainingWidth) {
|
|
330
|
-
line.append(layoutRun);
|
|
380
|
+
if (!doWrap) {
|
|
381
|
+
curLine.append(run);
|
|
331
382
|
continue;
|
|
332
383
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
line.append(layoutRun);
|
|
338
|
-
line = this.flushLine(context, line);
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
line = this.flushLine(context, line);
|
|
342
|
-
line.append(layoutRun);
|
|
343
|
-
}
|
|
384
|
+
const runWidth = run.range.xLength();
|
|
385
|
+
const lineWidth = curLine.range.xLength();
|
|
386
|
+
if (runWidth + lineWidth <= doc.width) {
|
|
387
|
+
curLine.append(run);
|
|
344
388
|
continue;
|
|
345
389
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
390
|
+
if (curLine.runs.length === 0) {
|
|
391
|
+
curLine.append(run);
|
|
392
|
+
curLine = this.flushLine(context, curLine);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
curLine = this.flushLine(context, curLine);
|
|
396
|
+
curLine.append(run);
|
|
397
|
+
}
|
|
354
398
|
}
|
|
355
399
|
}
|
|
356
|
-
if (
|
|
357
|
-
this.flushLine(context,
|
|
400
|
+
if (curLine.runs.length > 0) {
|
|
401
|
+
this.flushLine(context, curLine);
|
|
358
402
|
}
|
|
359
403
|
}
|
|
360
404
|
justifyLines() {
|
|
361
405
|
if (this.lines.length <= 1 || "left" === this.source.justification) {
|
|
362
406
|
return;
|
|
363
407
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
for (const line of this.lines) {
|
|
367
|
-
const lineWidth = line.justificationRange.xLength();
|
|
368
|
-
docWidth = Math.max(docWidth, lineWidth);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
408
|
+
// This is the minimum width of the document's bounding box.
|
|
409
|
+
const docWidth = this.source.width;
|
|
371
410
|
let minOffset = Number.MAX_VALUE;
|
|
372
411
|
for (const line of this.lines) {
|
|
373
412
|
const lineWidth = line.justificationRange.xLength();
|
|
@@ -378,8 +417,11 @@ class TextBlockLayout {
|
|
|
378
417
|
line.offsetFromDocument.x += offset;
|
|
379
418
|
minOffset = Math.min(offset, minOffset);
|
|
380
419
|
}
|
|
381
|
-
|
|
382
|
-
|
|
420
|
+
if (minOffset < 0) {
|
|
421
|
+
// Shift left to accomodate lines that exceeded the document's minimum width.
|
|
422
|
+
this.range.low.x += minOffset;
|
|
423
|
+
this.range.high.x += minOffset;
|
|
424
|
+
}
|
|
383
425
|
}
|
|
384
426
|
flushLine(context, line, nextParagraph) {
|
|
385
427
|
nextParagraph = nextParagraph ?? line.source;
|