@itwin/core-common 5.1.0-dev.52 → 5.1.0-dev.54
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/annotation/TextAnnotation.d.ts +5 -1
- package/lib/cjs/annotation/TextAnnotation.d.ts.map +1 -1
- package/lib/cjs/annotation/TextAnnotation.js +5 -1
- package/lib/cjs/annotation/TextAnnotation.js.map +1 -1
- package/lib/esm/annotation/TextAnnotation.d.ts +5 -1
- package/lib/esm/annotation/TextAnnotation.d.ts.map +1 -1
- package/lib/esm/annotation/TextAnnotation.js +4 -0
- package/lib/esm/annotation/TextAnnotation.js.map +1 -1
- package/package.json +6 -6
|
@@ -31,7 +31,11 @@ export interface TextAnnotationAnchor {
|
|
|
31
31
|
/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]
|
|
32
32
|
* @beta
|
|
33
33
|
*/
|
|
34
|
-
export
|
|
34
|
+
export declare const textAnnotationFrameShapes: readonly ["none", "line", "rectangle", "circle", "equilateralTriangle", "diamond", "square", "pentagon", "hexagon", "octagon", "capsule", "roundedRectangle"];
|
|
35
|
+
/** Describes a predefined shape that can be computed and drawn around the margins of a [[TextBlock]]
|
|
36
|
+
* @beta
|
|
37
|
+
*/
|
|
38
|
+
export type TextAnnotationFrameShape = typeof textAnnotationFrameShapes[number];
|
|
35
39
|
/**
|
|
36
40
|
* Describes what color to use when filling the frame around a [[TextBlock]].
|
|
37
41
|
* If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,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SAAS;IAUxD;;;OAGG;IACI,kBAAkB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO;IAyBxD,0EAA0E;IACnE,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;CAW9C"}
|
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
* @module Annotation
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TextAnnotation = void 0;
|
|
10
|
+
exports.TextAnnotation = exports.textAnnotationFrameShapes = void 0;
|
|
11
11
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
12
12
|
const TextBlock_1 = require("./TextBlock");
|
|
13
|
+
/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
exports.textAnnotationFrameShapes = ["none", "line", "rectangle", "circle", "equilateralTriangle", "diamond", "square", "pentagon", "hexagon", "octagon", "capsule", "roundedRectangle"];
|
|
13
17
|
/**
|
|
14
18
|
* Represents a formatted block of text positioned in 2d or 3d space.
|
|
15
19
|
* [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAoH;AACpH,2CAAwD;AA2FxD;;;;;;;;;;;;GAYG;AACH,MAAa,cAAc;IACzB;;OAEG;IACI,WAAW,CAAqB;IACvC,8BAA8B;IACvB,SAAS,CAAY;IAC5B,iEAAiE;IAC1D,MAAM,CAAuB;IACpC,8IAA8I;IACvI,MAAM,CAAU;IACvB,iDAAiD;IAC1C,KAAK,CAAuB;IAEnC,YAAoB,MAAe,EAAE,MAA0B,EAAE,SAAoB,EAAE,MAA4B,EAAE,KAA2B;QAC9I,IAAI,CAAC,MAA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AAC,CAAC,CAAC;IAC9B,CAAC;IAED,0EAA0E;IACnE,MAAM,CAAC,KAAqB;QACjC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,KAAK,CAAC,KAAK,EAAE,KAAK;eACvD,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,KAAK,EAAE,IAAI;eACtC,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,EAAE,MAAM;eAC1C,IAAI,CAAC,KAAK,EAAE,YAAY,KAAK,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC;QAE5D,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;eAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;eACtC,WAAW,CAAC;IACnB,CAAC;CACF;AAxID,wCAwIC","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 Annotation\n */\n\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\nimport { TextStyleColor } from \"./TextStyle\";\n\n/** Describes how to compute the \"anchor point\" for a [[TextAnnotation]].\n * The anchor point is a point on or inside of the 2d bounding box enclosing the contents of the annotation's [[TextBlock]].\n * The annotation can be rotated and translated relative to the anchor point. The anchor point also serves as the snap point\n * when [AccuSnap]($frontend) is set to [SnapMode.Origin]($frontend).\n * [[TextAnnotation.computeTransform]] will align the anchor point with (0, 0).\n * @see [[TextAnnotation]] for a description of how the anchor point is computed.\n * @beta\n */\nexport interface TextAnnotationAnchor {\n /**\n * The vertical alignment of the anchor point.\n * \"top\" aligns the anchor point with the top of the text's bounding box.\n * \"middle\" aligns the anchor point with the middle of the text's bounding box.\n * \"bottom\" aligns the anchor point with the bottom of the text's bounding box.\n */\n vertical: \"top\" | \"middle\" | \"bottom\";\n\n /**\n * The horizontal alignment of the anchor point.\n * \"left\" aligns the anchor point with left side of the text's bounding box.\n * \"center\" aligns the anchor point with center of the text with's bounding box.\n * \"right\" aligns the anchor point with right side of the text's bounding box.\n */\n horizontal: \"left\" | \"center\" | \"right\";\n}\n\n/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport type TextAnnotationFrameShape = \"none\" | \"line\" | \"rectangle\" | \"circle\" | \"equilateralTriangle\" | \"diamond\" | \"square\" | \"pentagon\" | \"hexagon\" | \"octagon\" | \"capsule\" | \"roundedRectangle\";\n\n\n/**\n * Describes what color to use when filling the frame around a [[TextBlock]].\n * If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.\n * @beta\n */\nexport type TextAnnotationFillColor = TextStyleColor | \"background\";\n\n/**\n * Describes how to draw the frame around a [[TextBlock]].\n * The frame can be a simple line, a filled shape, or both.\n * @beta\n */\nexport interface TextFrameStyleProps {\n /** Shape of the frame. Default: \"rectangle\" */\n shape?: TextAnnotationFrameShape;\n /** The color to fill the shape of the text frame. This fill will is applied using [[FillDisplay.Blanking]]. Default: no fill */\n fill?: TextAnnotationFillColor;\n /** The color of the text frame's outline. Default: black */\n border?: TextStyleColor;\n /** This will be used to set the [[GeometryParams.weight]] property of the frame (in pixels). Default: 1px */\n borderWeight?: number;\n}\n\n/**\n * JSON representation of a [[TextAnnotation]].\n * @beta\n */\nexport interface TextAnnotationProps {\n /** See [[TextAnnotation.offset]]. Default: [0, 0, 0]. */\n offset?: XYZProps;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollProps;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlockProps;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/** Arguments supplied to [[TextAnnotation.create]].\n * @beta\n */\nexport interface TextAnnotationCreateArgs {\n /** See [[TextAnnotation.offset]]. Default: (0, 0, 0). */\n offset?: Point3d;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollAngles;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlock;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/**\n * Represents a formatted block of text positioned in 2d or 3d space.\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.\n * Other types of elements may store multiple TextAnnotations, positioned relative to one another.\n * The annotation's position and orientation relative to the host element's [Placement]($common) is determined as follows:\n * - First, a bounding box is computed enclosing the contents of the [[textBlock].\n * - Then, an \"anchor point\" is computed based on the bounding box and the [[anchor]] property. The anchor point can be at one of the four corners of the box, in the middle of one of its four\n * edges, or in the center of the box.\n * - The [[orientation]] is applied to rotate the box around the anchor point.\n * - Finally, the [[offset]] is added to the anchor point to apply translation.\n * @see [appendTextAnnotationGeometry]($backend) to construct the geometry and append it to an [[ElementGeometry.Builder]].\n * @beta\n */\nexport class TextAnnotation {\n /** The rotation of the annotation.\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\n */\n public orientation: YawPitchRollAngles;\n /** The formatted document. */\n public textBlock: TextBlock;\n /** Describes how to compute the [[textBlock]]'s anchor point. */\n public anchor: TextAnnotationAnchor;\n /** An offset applied to the anchor point that can be used to position annotations within the same geometry stream relative to one another. */\n public offset: Point3d;\n /** The frame settings of the text annotation. */\n public frame?: TextFrameStyleProps;\n\n private constructor(offset: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor, frame?: TextFrameStyleProps) {\n this.offset = offset;\n this.orientation = angles;\n this.textBlock = textBlock;\n this.anchor = anchor;\n this.frame = frame\n }\n\n /** Creates a new TextAnnotation. */\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\n const offset = args?.offset ?? new Point3d();\n const angles = args?.orientation ?? new YawPitchRollAngles();\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\n // If the user supplies a frame, but doesn't supply a shape, default the shape to \"rectangle\"\n const shape: TextAnnotationFrameShape = args?.frame?.shape ?? \"rectangle\";\n const frame = args?.frame ? { shape, ...args.frame } : undefined;\n\n return new TextAnnotation(offset, angles, textBlock, anchor, frame);\n }\n\n /**\n * Creates a new TextAnnotation instance from its JSON representation.\n */\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\n return TextAnnotation.create({\n offset: props?.offset ? Point3d.fromJSON(props.offset) : undefined,\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\n anchor: props?.anchor ? { ...props.anchor } : undefined,\n frame: props?.frame ? { shape: \"rectangle\", ...props.frame } : undefined,\n });\n }\n\n /**\n * Converts this annotation to its JSON representation.\n */\n public toJSON(): TextAnnotationProps {\n const props: TextAnnotationProps = {};\n\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\n // so the user can pick up where they left off editing it next time.\n props.textBlock = this.textBlock.toJSON();\n\n if (!this.offset.isZero) {\n props.offset = this.offset.toJSON();\n }\n\n if (!this.orientation.isIdentity()) {\n props.orientation = this.orientation.toJSON();\n }\n\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\n props.anchor = { ...this.anchor };\n }\n\n // Default frame to \"none\"\n props.frame = this.frame ? { ...this.frame } : undefined;\n\n return props;\n }\n\n /** Compute the transform that positions and orients this annotation relative to its anchor point, based on the [[textBlock]]'s computed bounding box.\n * The anchor point is computed as specified by this annotation's [[anchor]] setting. For example, if the text block is anchored\n * at the bottom left, then the transform will be relative to the bottom-left corner of `textBlockExtents`.\n * The text block will be rotated around the fixed anchor point according to [[orientation]], then translated by [[offset]].\n * The anchor point will coincide with (0, 0, 0) unless an [[offset]] is present.\n * @param boundingBox A box fully containing the [[textBlock]]. This range should include the margins.\n * @see [[computeAnchorPoint]] to compute the transform's anchor point.\n * @see [computeLayoutTextBlockResult]($backend) to lay out a `TextBlock`.\n */\n public computeTransform(boundingBox: Range2d): Transform {\n const anchorPt = this.computeAnchorPoint(boundingBox);\n const matrix = this.orientation.toMatrix3d();\n\n const rotation = Transform.createFixedPointAndMatrix(anchorPt, matrix);\n const translation = Transform.createTranslation(this.offset.minus(anchorPt));\n\n return translation.multiplyTransformTransform(rotation, rotation);\n }\n\n /** Compute the anchor point of this annotation as specified by [[anchor]].\n * @param boundingBox A box fully containing the [[textBlock]].\n * @see [[computeTransform]] to compute the transform relative to the anchor point.\n */\n public computeAnchorPoint(boundingBox: Range2d): Point3d {\n let x = boundingBox.low.x;\n let y = boundingBox.high.y;\n\n switch (this.anchor.horizontal) {\n case \"center\":\n x += boundingBox.xLength() / 2;\n break;\n case \"right\":\n x += boundingBox.xLength();\n break;\n }\n\n switch (this.anchor.vertical) {\n case \"middle\":\n y -= boundingBox.yLength() / 2;\n break;\n case \"bottom\":\n y -= boundingBox.yLength();\n break;\n }\n\n return new Point3d(x, y, 0);\n }\n\n /** Returns true if this annotation is logically equivalent to `other`. */\n public equals(other: TextAnnotation): boolean {\n const framesMatch = this.frame?.shape === other.frame?.shape\n && this.frame?.fill === other.frame?.fill\n && this.frame?.border === other.frame?.border\n && this.frame?.borderWeight === other.frame?.borderWeight;\n\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\n && this.orientation.isAlmostEqual(other.orientation) && this.offset.isAlmostEqual(other.offset)\n && this.textBlock.equals(other.textBlock)\n && framesMatch;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAoH;AACpH,2CAAwD;AA6BxD;;EAEE;AACW,QAAA,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,qBAAqB,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,CAAU,CAAC;AA+DvM;;;;;;;;;;;;GAYG;AACH,MAAa,cAAc;IACzB;;OAEG;IACI,WAAW,CAAqB;IACvC,8BAA8B;IACvB,SAAS,CAAY;IAC5B,iEAAiE;IAC1D,MAAM,CAAuB;IACpC,8IAA8I;IACvI,MAAM,CAAU;IACvB,iDAAiD;IAC1C,KAAK,CAAuB;IAEnC,YAAoB,MAAe,EAAE,MAA0B,EAAE,SAAoB,EAAE,MAA4B,EAAE,KAA2B;QAC9I,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,oCAAoC;IAC7B,MAAM,CAAC,MAAM,CAAC,IAA+B;QAClD,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,uBAAO,EAAE,CAAC;QAC7C,MAAM,MAAM,GAA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,CAAC,KAAK,EAAE,YAAY,CAAC;QAE5D,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;eAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;eACtC,WAAW,CAAC;IACnB,CAAC;CACF;AAxID,wCAwIC","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 Annotation\n */\n\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\nimport { TextStyleColor } from \"./TextStyle\";\n\n/** Describes how to compute the \"anchor point\" for a [[TextAnnotation]].\n * The anchor point is a point on or inside of the 2d bounding box enclosing the contents of the annotation's [[TextBlock]].\n * The annotation can be rotated and translated relative to the anchor point. The anchor point also serves as the snap point\n * when [AccuSnap]($frontend) is set to [SnapMode.Origin]($frontend).\n * [[TextAnnotation.computeTransform]] will align the anchor point with (0, 0).\n * @see [[TextAnnotation]] for a description of how the anchor point is computed.\n * @beta\n */\nexport interface TextAnnotationAnchor {\n /**\n * The vertical alignment of the anchor point.\n * \"top\" aligns the anchor point with the top of the text's bounding box.\n * \"middle\" aligns the anchor point with the middle of the text's bounding box.\n * \"bottom\" aligns the anchor point with the bottom of the text's bounding box.\n */\n vertical: \"top\" | \"middle\" | \"bottom\";\n\n /**\n * The horizontal alignment of the anchor point.\n * \"left\" aligns the anchor point with left side of the text's bounding box.\n * \"center\" aligns the anchor point with center of the text with's bounding box.\n * \"right\" aligns the anchor point with right side of the text's bounding box.\n */\n horizontal: \"left\" | \"center\" | \"right\";\n}\n\n/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport const textAnnotationFrameShapes = [\"none\", \"line\", \"rectangle\", \"circle\", \"equilateralTriangle\", \"diamond\", \"square\", \"pentagon\", \"hexagon\", \"octagon\", \"capsule\", \"roundedRectangle\"] as const;\n\n/** Describes a predefined shape that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport type TextAnnotationFrameShape = typeof textAnnotationFrameShapes[number];\n\n/**\n * Describes what color to use when filling the frame around a [[TextBlock]].\n * If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.\n * @beta\n */\nexport type TextAnnotationFillColor = TextStyleColor | \"background\";\n\n/**\n * Describes how to draw the frame around a [[TextBlock]].\n * The frame can be a simple line, a filled shape, or both.\n * @beta\n */\nexport interface TextFrameStyleProps {\n /** Shape of the frame. Default: \"rectangle\" */\n shape?: TextAnnotationFrameShape;\n /** The color to fill the shape of the text frame. This fill will is applied using [[FillDisplay.Blanking]]. Default: no fill */\n fill?: TextAnnotationFillColor;\n /** The color of the text frame's outline. Default: black */\n border?: TextStyleColor;\n /** This will be used to set the [[GeometryParams.weight]] property of the frame (in pixels). Default: 1px */\n borderWeight?: number;\n}\n\n/**\n * JSON representation of a [[TextAnnotation]].\n * @beta\n */\nexport interface TextAnnotationProps {\n /** See [[TextAnnotation.offset]]. Default: [0, 0, 0]. */\n offset?: XYZProps;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollProps;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlockProps;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/** Arguments supplied to [[TextAnnotation.create]].\n * @beta\n */\nexport interface TextAnnotationCreateArgs {\n /** See [[TextAnnotation.offset]]. Default: (0, 0, 0). */\n offset?: Point3d;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollAngles;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlock;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/**\n * Represents a formatted block of text positioned in 2d or 3d space.\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.\n * Other types of elements may store multiple TextAnnotations, positioned relative to one another.\n * The annotation's position and orientation relative to the host element's [Placement]($common) is determined as follows:\n * - First, a bounding box is computed enclosing the contents of the [[textBlock].\n * - Then, an \"anchor point\" is computed based on the bounding box and the [[anchor]] property. The anchor point can be at one of the four corners of the box, in the middle of one of its four\n * edges, or in the center of the box.\n * - The [[orientation]] is applied to rotate the box around the anchor point.\n * - Finally, the [[offset]] is added to the anchor point to apply translation.\n * @see [appendTextAnnotationGeometry]($backend) to construct the geometry and append it to an [[ElementGeometry.Builder]].\n * @beta\n */\nexport class TextAnnotation {\n /** The rotation of the annotation.\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\n */\n public orientation: YawPitchRollAngles;\n /** The formatted document. */\n public textBlock: TextBlock;\n /** Describes how to compute the [[textBlock]]'s anchor point. */\n public anchor: TextAnnotationAnchor;\n /** An offset applied to the anchor point that can be used to position annotations within the same geometry stream relative to one another. */\n public offset: Point3d;\n /** The frame settings of the text annotation. */\n public frame?: TextFrameStyleProps;\n\n private constructor(offset: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor, frame?: TextFrameStyleProps) {\n this.offset = offset;\n this.orientation = angles;\n this.textBlock = textBlock;\n this.anchor = anchor;\n this.frame = frame\n }\n\n /** Creates a new TextAnnotation. */\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\n const offset = args?.offset ?? new Point3d();\n const angles = args?.orientation ?? new YawPitchRollAngles();\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\n // If the user supplies a frame, but doesn't supply a shape, default the shape to \"rectangle\"\n const shape: TextAnnotationFrameShape = args?.frame?.shape ?? \"rectangle\";\n const frame = args?.frame ? { shape, ...args.frame } : undefined;\n\n return new TextAnnotation(offset, angles, textBlock, anchor, frame);\n }\n\n /**\n * Creates a new TextAnnotation instance from its JSON representation.\n */\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\n return TextAnnotation.create({\n offset: props?.offset ? Point3d.fromJSON(props.offset) : undefined,\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\n anchor: props?.anchor ? { ...props.anchor } : undefined,\n frame: props?.frame ? { shape: \"rectangle\", ...props.frame } : undefined,\n });\n }\n\n /**\n * Converts this annotation to its JSON representation.\n */\n public toJSON(): TextAnnotationProps {\n const props: TextAnnotationProps = {};\n\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\n // so the user can pick up where they left off editing it next time.\n props.textBlock = this.textBlock.toJSON();\n\n if (!this.offset.isZero) {\n props.offset = this.offset.toJSON();\n }\n\n if (!this.orientation.isIdentity()) {\n props.orientation = this.orientation.toJSON();\n }\n\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\n props.anchor = { ...this.anchor };\n }\n\n // Default frame to \"none\"\n props.frame = this.frame ? { ...this.frame } : undefined;\n\n return props;\n }\n\n /** Compute the transform that positions and orients this annotation relative to its anchor point, based on the [[textBlock]]'s computed bounding box.\n * The anchor point is computed as specified by this annotation's [[anchor]] setting. For example, if the text block is anchored\n * at the bottom left, then the transform will be relative to the bottom-left corner of `textBlockExtents`.\n * The text block will be rotated around the fixed anchor point according to [[orientation]], then translated by [[offset]].\n * The anchor point will coincide with (0, 0, 0) unless an [[offset]] is present.\n * @param boundingBox A box fully containing the [[textBlock]]. This range should include the margins.\n * @see [[computeAnchorPoint]] to compute the transform's anchor point.\n * @see [computeLayoutTextBlockResult]($backend) to lay out a `TextBlock`.\n */\n public computeTransform(boundingBox: Range2d): Transform {\n const anchorPt = this.computeAnchorPoint(boundingBox);\n const matrix = this.orientation.toMatrix3d();\n\n const rotation = Transform.createFixedPointAndMatrix(anchorPt, matrix);\n const translation = Transform.createTranslation(this.offset.minus(anchorPt));\n\n return translation.multiplyTransformTransform(rotation, rotation);\n }\n\n /** Compute the anchor point of this annotation as specified by [[anchor]].\n * @param boundingBox A box fully containing the [[textBlock]].\n * @see [[computeTransform]] to compute the transform relative to the anchor point.\n */\n public computeAnchorPoint(boundingBox: Range2d): Point3d {\n let x = boundingBox.low.x;\n let y = boundingBox.high.y;\n\n switch (this.anchor.horizontal) {\n case \"center\":\n x += boundingBox.xLength() / 2;\n break;\n case \"right\":\n x += boundingBox.xLength();\n break;\n }\n\n switch (this.anchor.vertical) {\n case \"middle\":\n y -= boundingBox.yLength() / 2;\n break;\n case \"bottom\":\n y -= boundingBox.yLength();\n break;\n }\n\n return new Point3d(x, y, 0);\n }\n\n /** Returns true if this annotation is logically equivalent to `other`. */\n public equals(other: TextAnnotation): boolean {\n const framesMatch = this.frame?.shape === other.frame?.shape\n && this.frame?.fill === other.frame?.fill\n && this.frame?.border === other.frame?.border\n && this.frame?.borderWeight === other.frame?.borderWeight;\n\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\n && this.orientation.isAlmostEqual(other.orientation) && this.offset.isAlmostEqual(other.offset)\n && this.textBlock.equals(other.textBlock)\n && framesMatch;\n }\n}\n"]}
|
|
@@ -31,7 +31,11 @@ export interface TextAnnotationAnchor {
|
|
|
31
31
|
/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]
|
|
32
32
|
* @beta
|
|
33
33
|
*/
|
|
34
|
-
export
|
|
34
|
+
export declare const textAnnotationFrameShapes: readonly ["none", "line", "rectangle", "circle", "equilateralTriangle", "diamond", "square", "pentagon", "hexagon", "octagon", "capsule", "roundedRectangle"];
|
|
35
|
+
/** Describes a predefined shape that can be computed and drawn around the margins of a [[TextBlock]]
|
|
36
|
+
* @beta
|
|
37
|
+
*/
|
|
38
|
+
export type TextAnnotationFrameShape = typeof textAnnotationFrameShapes[number];
|
|
35
39
|
/**
|
|
36
40
|
* Describes what color to use when filling the frame around a [[TextBlock]].
|
|
37
41
|
* If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEtC;;;;;OAKG;IACH,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACzC;AAED;;EAEE;AACF,
|
|
1
|
+
{"version":3,"file":"TextAnnotation.d.ts","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EA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AAgE;IAChE,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,sEAAsE;IACtE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,wDAAwD;IACxD,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,sDAAsD;IACtD,KAAK,CAAC,EAAE,mBAAmB,CAAA;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAc;IACzB;;OAEG;IACI,WAAW,EAAE,kBAAkB,CAAC;IACvC,8BAA8B;IACvB,SAAS,EAAE,SAAS,CAAC;IAC5B,iEAAiE;IAC1D,MAAM,EAAE,oBAAoB,CAAC;IACpC,8IAA8I;IACvI,MAAM,EAAE,OAAO,CAAC;IACvB,iDAAiD;IAC1C,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAEnC,OAAO;IAQP,oCAAoC;WACtB,MAAM,CAAC,IAAI,CAAC,EAAE,wBAAwB,GAAG,cAAc;IAYrE;;OAEG;WACW,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,SAAS,GAAG,cAAc;IAU9E;;OAEG;IACI,MAAM,IAAI,mBAAmB;IAyBpC;;;;;;;;OAQG;IACI,gBAAgB,CAAC,WAAW,EAAE,OAAO,GAAG,SAAS;IAUxD;;;OAGG;IACI,kBAAkB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO;IAyBxD,0EAA0E;IACnE,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;CAW9C"}
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Point3d, Transform, YawPitchRollAngles } from "@itwin/core-geometry";
|
|
9
9
|
import { TextBlock } from "./TextBlock";
|
|
10
|
+
/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export const textAnnotationFrameShapes = ["none", "line", "rectangle", "circle", "equilateralTriangle", "diamond", "square", "pentagon", "hexagon", "octagon", "capsule", "roundedRectangle"];
|
|
10
14
|
/**
|
|
11
15
|
* Represents a formatted block of text positioned in 2d or 3d space.
|
|
12
16
|
* [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAW,SAAS,EAAY,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AA2FxD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IACzB;;OAEG;IACI,WAAW,CAAqB;IACvC,8BAA8B;IACvB,SAAS,CAAY;IAC5B,iEAAiE;IAC1D,MAAM,CAAuB;IACpC,8IAA8I;IACvI,MAAM,CAAU;IACvB,iDAAiD;IAC1C,KAAK,CAAuB;IAEnC,YAAoB,MAAe,EAAE,MAA0B,EAAE,SAAoB,EAAE,MAA4B,EAAE,KAA2B;QAC9I,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,oCAAoC;IAC7B,MAAM,CAAC,MAAM,CAAC,IAA+B;QAClD,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,EAAE,WAAW,IAAI,IAAI,kBAAkB,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC7D,MAAM,MAAM,GAAG,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,MAAM,CAAC,QAAQ;eACtG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;eAC5F,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;eACtC,WAAW,CAAC;IACnB,CAAC;CACF","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 Annotation\n */\n\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\nimport { TextStyleColor } from \"./TextStyle\";\n\n/** Describes how to compute the \"anchor point\" for a [[TextAnnotation]].\n * The anchor point is a point on or inside of the 2d bounding box enclosing the contents of the annotation's [[TextBlock]].\n * The annotation can be rotated and translated relative to the anchor point. The anchor point also serves as the snap point\n * when [AccuSnap]($frontend) is set to [SnapMode.Origin]($frontend).\n * [[TextAnnotation.computeTransform]] will align the anchor point with (0, 0).\n * @see [[TextAnnotation]] for a description of how the anchor point is computed.\n * @beta\n */\nexport interface TextAnnotationAnchor {\n /**\n * The vertical alignment of the anchor point.\n * \"top\" aligns the anchor point with the top of the text's bounding box.\n * \"middle\" aligns the anchor point with the middle of the text's bounding box.\n * \"bottom\" aligns the anchor point with the bottom of the text's bounding box.\n */\n vertical: \"top\" | \"middle\" | \"bottom\";\n\n /**\n * The horizontal alignment of the anchor point.\n * \"left\" aligns the anchor point with left side of the text's bounding box.\n * \"center\" aligns the anchor point with center of the text with's bounding box.\n * \"right\" aligns the anchor point with right side of the text's bounding box.\n */\n horizontal: \"left\" | \"center\" | \"right\";\n}\n\n/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport type TextAnnotationFrameShape = \"none\" | \"line\" | \"rectangle\" | \"circle\" | \"equilateralTriangle\" | \"diamond\" | \"square\" | \"pentagon\" | \"hexagon\" | \"octagon\" | \"capsule\" | \"roundedRectangle\";\n\n\n/**\n * Describes what color to use when filling the frame around a [[TextBlock]].\n * If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.\n * @beta\n */\nexport type TextAnnotationFillColor = TextStyleColor | \"background\";\n\n/**\n * Describes how to draw the frame around a [[TextBlock]].\n * The frame can be a simple line, a filled shape, or both.\n * @beta\n */\nexport interface TextFrameStyleProps {\n /** Shape of the frame. Default: \"rectangle\" */\n shape?: TextAnnotationFrameShape;\n /** The color to fill the shape of the text frame. This fill will is applied using [[FillDisplay.Blanking]]. Default: no fill */\n fill?: TextAnnotationFillColor;\n /** The color of the text frame's outline. Default: black */\n border?: TextStyleColor;\n /** This will be used to set the [[GeometryParams.weight]] property of the frame (in pixels). Default: 1px */\n borderWeight?: number;\n}\n\n/**\n * JSON representation of a [[TextAnnotation]].\n * @beta\n */\nexport interface TextAnnotationProps {\n /** See [[TextAnnotation.offset]]. Default: [0, 0, 0]. */\n offset?: XYZProps;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollProps;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlockProps;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/** Arguments supplied to [[TextAnnotation.create]].\n * @beta\n */\nexport interface TextAnnotationCreateArgs {\n /** See [[TextAnnotation.offset]]. Default: (0, 0, 0). */\n offset?: Point3d;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollAngles;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlock;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/**\n * Represents a formatted block of text positioned in 2d or 3d space.\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.\n * Other types of elements may store multiple TextAnnotations, positioned relative to one another.\n * The annotation's position and orientation relative to the host element's [Placement]($common) is determined as follows:\n * - First, a bounding box is computed enclosing the contents of the [[textBlock].\n * - Then, an \"anchor point\" is computed based on the bounding box and the [[anchor]] property. The anchor point can be at one of the four corners of the box, in the middle of one of its four\n * edges, or in the center of the box.\n * - The [[orientation]] is applied to rotate the box around the anchor point.\n * - Finally, the [[offset]] is added to the anchor point to apply translation.\n * @see [appendTextAnnotationGeometry]($backend) to construct the geometry and append it to an [[ElementGeometry.Builder]].\n * @beta\n */\nexport class TextAnnotation {\n /** The rotation of the annotation.\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\n */\n public orientation: YawPitchRollAngles;\n /** The formatted document. */\n public textBlock: TextBlock;\n /** Describes how to compute the [[textBlock]]'s anchor point. */\n public anchor: TextAnnotationAnchor;\n /** An offset applied to the anchor point that can be used to position annotations within the same geometry stream relative to one another. */\n public offset: Point3d;\n /** The frame settings of the text annotation. */\n public frame?: TextFrameStyleProps;\n\n private constructor(offset: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor, frame?: TextFrameStyleProps) {\n this.offset = offset;\n this.orientation = angles;\n this.textBlock = textBlock;\n this.anchor = anchor;\n this.frame = frame\n }\n\n /** Creates a new TextAnnotation. */\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\n const offset = args?.offset ?? new Point3d();\n const angles = args?.orientation ?? new YawPitchRollAngles();\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\n // If the user supplies a frame, but doesn't supply a shape, default the shape to \"rectangle\"\n const shape: TextAnnotationFrameShape = args?.frame?.shape ?? \"rectangle\";\n const frame = args?.frame ? { shape, ...args.frame } : undefined;\n\n return new TextAnnotation(offset, angles, textBlock, anchor, frame);\n }\n\n /**\n * Creates a new TextAnnotation instance from its JSON representation.\n */\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\n return TextAnnotation.create({\n offset: props?.offset ? Point3d.fromJSON(props.offset) : undefined,\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\n anchor: props?.anchor ? { ...props.anchor } : undefined,\n frame: props?.frame ? { shape: \"rectangle\", ...props.frame } : undefined,\n });\n }\n\n /**\n * Converts this annotation to its JSON representation.\n */\n public toJSON(): TextAnnotationProps {\n const props: TextAnnotationProps = {};\n\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\n // so the user can pick up where they left off editing it next time.\n props.textBlock = this.textBlock.toJSON();\n\n if (!this.offset.isZero) {\n props.offset = this.offset.toJSON();\n }\n\n if (!this.orientation.isIdentity()) {\n props.orientation = this.orientation.toJSON();\n }\n\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\n props.anchor = { ...this.anchor };\n }\n\n // Default frame to \"none\"\n props.frame = this.frame ? { ...this.frame } : undefined;\n\n return props;\n }\n\n /** Compute the transform that positions and orients this annotation relative to its anchor point, based on the [[textBlock]]'s computed bounding box.\n * The anchor point is computed as specified by this annotation's [[anchor]] setting. For example, if the text block is anchored\n * at the bottom left, then the transform will be relative to the bottom-left corner of `textBlockExtents`.\n * The text block will be rotated around the fixed anchor point according to [[orientation]], then translated by [[offset]].\n * The anchor point will coincide with (0, 0, 0) unless an [[offset]] is present.\n * @param boundingBox A box fully containing the [[textBlock]]. This range should include the margins.\n * @see [[computeAnchorPoint]] to compute the transform's anchor point.\n * @see [computeLayoutTextBlockResult]($backend) to lay out a `TextBlock`.\n */\n public computeTransform(boundingBox: Range2d): Transform {\n const anchorPt = this.computeAnchorPoint(boundingBox);\n const matrix = this.orientation.toMatrix3d();\n\n const rotation = Transform.createFixedPointAndMatrix(anchorPt, matrix);\n const translation = Transform.createTranslation(this.offset.minus(anchorPt));\n\n return translation.multiplyTransformTransform(rotation, rotation);\n }\n\n /** Compute the anchor point of this annotation as specified by [[anchor]].\n * @param boundingBox A box fully containing the [[textBlock]].\n * @see [[computeTransform]] to compute the transform relative to the anchor point.\n */\n public computeAnchorPoint(boundingBox: Range2d): Point3d {\n let x = boundingBox.low.x;\n let y = boundingBox.high.y;\n\n switch (this.anchor.horizontal) {\n case \"center\":\n x += boundingBox.xLength() / 2;\n break;\n case \"right\":\n x += boundingBox.xLength();\n break;\n }\n\n switch (this.anchor.vertical) {\n case \"middle\":\n y -= boundingBox.yLength() / 2;\n break;\n case \"bottom\":\n y -= boundingBox.yLength();\n break;\n }\n\n return new Point3d(x, y, 0);\n }\n\n /** Returns true if this annotation is logically equivalent to `other`. */\n public equals(other: TextAnnotation): boolean {\n const framesMatch = this.frame?.shape === other.frame?.shape\n && this.frame?.fill === other.frame?.fill\n && this.frame?.border === other.frame?.border\n && this.frame?.borderWeight === other.frame?.borderWeight;\n\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\n && this.orientation.isAlmostEqual(other.orientation) && this.offset.isAlmostEqual(other.offset)\n && this.textBlock.equals(other.textBlock)\n && framesMatch;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TextAnnotation.js","sourceRoot":"","sources":["../../../src/annotation/TextAnnotation.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAW,SAAS,EAAY,kBAAkB,EAAqB,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AA6BxD;;EAEE;AACF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,MAAM,E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Content":["/*---------------------------------------------------------------------------------------------\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 Annotation\n */\n\nimport { Point3d, Range2d, Transform, XYZProps, YawPitchRollAngles, YawPitchRollProps } from \"@itwin/core-geometry\";\nimport { TextBlock, TextBlockProps } from \"./TextBlock\";\nimport { TextStyleColor } from \"./TextStyle\";\n\n/** Describes how to compute the \"anchor point\" for a [[TextAnnotation]].\n * The anchor point is a point on or inside of the 2d bounding box enclosing the contents of the annotation's [[TextBlock]].\n * The annotation can be rotated and translated relative to the anchor point. The anchor point also serves as the snap point\n * when [AccuSnap]($frontend) is set to [SnapMode.Origin]($frontend).\n * [[TextAnnotation.computeTransform]] will align the anchor point with (0, 0).\n * @see [[TextAnnotation]] for a description of how the anchor point is computed.\n * @beta\n */\nexport interface TextAnnotationAnchor {\n /**\n * The vertical alignment of the anchor point.\n * \"top\" aligns the anchor point with the top of the text's bounding box.\n * \"middle\" aligns the anchor point with the middle of the text's bounding box.\n * \"bottom\" aligns the anchor point with the bottom of the text's bounding box.\n */\n vertical: \"top\" | \"middle\" | \"bottom\";\n\n /**\n * The horizontal alignment of the anchor point.\n * \"left\" aligns the anchor point with left side of the text's bounding box.\n * \"center\" aligns the anchor point with center of the text with's bounding box.\n * \"right\" aligns the anchor point with right side of the text's bounding box.\n */\n horizontal: \"left\" | \"center\" | \"right\";\n}\n\n/** Set of predefined shapes that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport const textAnnotationFrameShapes = [\"none\", \"line\", \"rectangle\", \"circle\", \"equilateralTriangle\", \"diamond\", \"square\", \"pentagon\", \"hexagon\", \"octagon\", \"capsule\", \"roundedRectangle\"] as const;\n\n/** Describes a predefined shape that can be computed and drawn around the margins of a [[TextBlock]]\n * @beta\n*/\nexport type TextAnnotationFrameShape = typeof textAnnotationFrameShapes[number];\n\n/**\n * Describes what color to use when filling the frame around a [[TextBlock]].\n * If `background` is specified, [[GeometryParams.BackgroundFill]] will be set to `BackgroundFill.Outline`.\n * @beta\n */\nexport type TextAnnotationFillColor = TextStyleColor | \"background\";\n\n/**\n * Describes how to draw the frame around a [[TextBlock]].\n * The frame can be a simple line, a filled shape, or both.\n * @beta\n */\nexport interface TextFrameStyleProps {\n /** Shape of the frame. Default: \"rectangle\" */\n shape?: TextAnnotationFrameShape;\n /** The color to fill the shape of the text frame. This fill will is applied using [[FillDisplay.Blanking]]. Default: no fill */\n fill?: TextAnnotationFillColor;\n /** The color of the text frame's outline. Default: black */\n border?: TextStyleColor;\n /** This will be used to set the [[GeometryParams.weight]] property of the frame (in pixels). Default: 1px */\n borderWeight?: number;\n}\n\n/**\n * JSON representation of a [[TextAnnotation]].\n * @beta\n */\nexport interface TextAnnotationProps {\n /** See [[TextAnnotation.offset]]. Default: [0, 0, 0]. */\n offset?: XYZProps;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollProps;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlockProps;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/** Arguments supplied to [[TextAnnotation.create]].\n * @beta\n */\nexport interface TextAnnotationCreateArgs {\n /** See [[TextAnnotation.offset]]. Default: (0, 0, 0). */\n offset?: Point3d;\n /** See [[TextAnnotation.orientation]]. Default: no rotation. */\n orientation?: YawPitchRollAngles;\n /** See [[TextAnnotation.textBlock]]. Default: an empty text block. */\n textBlock?: TextBlock;\n /** See [[TextAnnotation.anchor]]. Default: top-left. */\n anchor?: TextAnnotationAnchor;\n /** See [[TextAnnotation.frame]]. Default: no frame */\n frame?: TextFrameStyleProps\n}\n\n/**\n * Represents a formatted block of text positioned in 2d or 3d space.\n * [TextAnnotation2d]($backend) and [TextAnnotation3d]($backend) elements store a single TextAnnotation from which their geometric representation is generated.\n * Other types of elements may store multiple TextAnnotations, positioned relative to one another.\n * The annotation's position and orientation relative to the host element's [Placement]($common) is determined as follows:\n * - First, a bounding box is computed enclosing the contents of the [[textBlock].\n * - Then, an \"anchor point\" is computed based on the bounding box and the [[anchor]] property. The anchor point can be at one of the four corners of the box, in the middle of one of its four\n * edges, or in the center of the box.\n * - The [[orientation]] is applied to rotate the box around the anchor point.\n * - Finally, the [[offset]] is added to the anchor point to apply translation.\n * @see [appendTextAnnotationGeometry]($backend) to construct the geometry and append it to an [[ElementGeometry.Builder]].\n * @beta\n */\nexport class TextAnnotation {\n /** The rotation of the annotation.\n * @note When defining an annotation for a [TextAnnotation2d]($backend), only the `yaw` component (rotation around the Z axis) is used.\n */\n public orientation: YawPitchRollAngles;\n /** The formatted document. */\n public textBlock: TextBlock;\n /** Describes how to compute the [[textBlock]]'s anchor point. */\n public anchor: TextAnnotationAnchor;\n /** An offset applied to the anchor point that can be used to position annotations within the same geometry stream relative to one another. */\n public offset: Point3d;\n /** The frame settings of the text annotation. */\n public frame?: TextFrameStyleProps;\n\n private constructor(offset: Point3d, angles: YawPitchRollAngles, textBlock: TextBlock, anchor: TextAnnotationAnchor, frame?: TextFrameStyleProps) {\n this.offset = offset;\n this.orientation = angles;\n this.textBlock = textBlock;\n this.anchor = anchor;\n this.frame = frame\n }\n\n /** Creates a new TextAnnotation. */\n public static create(args?: TextAnnotationCreateArgs): TextAnnotation {\n const offset = args?.offset ?? new Point3d();\n const angles = args?.orientation ?? new YawPitchRollAngles();\n const textBlock = args?.textBlock ?? TextBlock.createEmpty();\n const anchor = args?.anchor ?? { vertical: \"top\", horizontal: \"left\" };\n // If the user supplies a frame, but doesn't supply a shape, default the shape to \"rectangle\"\n const shape: TextAnnotationFrameShape = args?.frame?.shape ?? \"rectangle\";\n const frame = args?.frame ? { shape, ...args.frame } : undefined;\n\n return new TextAnnotation(offset, angles, textBlock, anchor, frame);\n }\n\n /**\n * Creates a new TextAnnotation instance from its JSON representation.\n */\n public static fromJSON(props: TextAnnotationProps | undefined): TextAnnotation {\n return TextAnnotation.create({\n offset: props?.offset ? Point3d.fromJSON(props.offset) : undefined,\n orientation: props?.orientation ? YawPitchRollAngles.fromJSON(props.orientation) : undefined,\n textBlock: props?.textBlock ? TextBlock.create(props.textBlock) : undefined,\n anchor: props?.anchor ? { ...props.anchor } : undefined,\n frame: props?.frame ? { shape: \"rectangle\", ...props.frame } : undefined,\n });\n }\n\n /**\n * Converts this annotation to its JSON representation.\n */\n public toJSON(): TextAnnotationProps {\n const props: TextAnnotationProps = {};\n\n // Even if the text block is empty, we want to record its style name and overrides, e.g.,\n // so the user can pick up where they left off editing it next time.\n props.textBlock = this.textBlock.toJSON();\n\n if (!this.offset.isZero) {\n props.offset = this.offset.toJSON();\n }\n\n if (!this.orientation.isIdentity()) {\n props.orientation = this.orientation.toJSON();\n }\n\n if (this.anchor.vertical !== \"top\" || this.anchor.horizontal !== \"left\") {\n props.anchor = { ...this.anchor };\n }\n\n // Default frame to \"none\"\n props.frame = this.frame ? { ...this.frame } : undefined;\n\n return props;\n }\n\n /** Compute the transform that positions and orients this annotation relative to its anchor point, based on the [[textBlock]]'s computed bounding box.\n * The anchor point is computed as specified by this annotation's [[anchor]] setting. For example, if the text block is anchored\n * at the bottom left, then the transform will be relative to the bottom-left corner of `textBlockExtents`.\n * The text block will be rotated around the fixed anchor point according to [[orientation]], then translated by [[offset]].\n * The anchor point will coincide with (0, 0, 0) unless an [[offset]] is present.\n * @param boundingBox A box fully containing the [[textBlock]]. This range should include the margins.\n * @see [[computeAnchorPoint]] to compute the transform's anchor point.\n * @see [computeLayoutTextBlockResult]($backend) to lay out a `TextBlock`.\n */\n public computeTransform(boundingBox: Range2d): Transform {\n const anchorPt = this.computeAnchorPoint(boundingBox);\n const matrix = this.orientation.toMatrix3d();\n\n const rotation = Transform.createFixedPointAndMatrix(anchorPt, matrix);\n const translation = Transform.createTranslation(this.offset.minus(anchorPt));\n\n return translation.multiplyTransformTransform(rotation, rotation);\n }\n\n /** Compute the anchor point of this annotation as specified by [[anchor]].\n * @param boundingBox A box fully containing the [[textBlock]].\n * @see [[computeTransform]] to compute the transform relative to the anchor point.\n */\n public computeAnchorPoint(boundingBox: Range2d): Point3d {\n let x = boundingBox.low.x;\n let y = boundingBox.high.y;\n\n switch (this.anchor.horizontal) {\n case \"center\":\n x += boundingBox.xLength() / 2;\n break;\n case \"right\":\n x += boundingBox.xLength();\n break;\n }\n\n switch (this.anchor.vertical) {\n case \"middle\":\n y -= boundingBox.yLength() / 2;\n break;\n case \"bottom\":\n y -= boundingBox.yLength();\n break;\n }\n\n return new Point3d(x, y, 0);\n }\n\n /** Returns true if this annotation is logically equivalent to `other`. */\n public equals(other: TextAnnotation): boolean {\n const framesMatch = this.frame?.shape === other.frame?.shape\n && this.frame?.fill === other.frame?.fill\n && this.frame?.border === other.frame?.border\n && this.frame?.borderWeight === other.frame?.borderWeight;\n\n return this.anchor.horizontal === other.anchor.horizontal && this.anchor.vertical === other.anchor.vertical\n && this.orientation.isAlmostEqual(other.orientation) && this.offset.isAlmostEqual(other.offset)\n && this.textBlock.equals(other.textBlock)\n && framesMatch;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-common",
|
|
3
|
-
"version": "5.1.0-dev.
|
|
3
|
+
"version": "5.1.0-dev.54",
|
|
4
4
|
"description": "iTwin.js components common to frontend and backend",
|
|
5
5
|
"main": "lib/cjs/core-common.js",
|
|
6
6
|
"module": "lib/esm/core-common.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"js-base64": "^3.6.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@itwin/core-bentley": "5.1.0-dev.
|
|
31
|
-
"@itwin/core-geometry": "5.1.0-dev.
|
|
30
|
+
"@itwin/core-bentley": "5.1.0-dev.54",
|
|
31
|
+
"@itwin/core-geometry": "5.1.0-dev.54"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"rimraf": "^6.0.1",
|
|
43
43
|
"typescript": "~5.6.2",
|
|
44
44
|
"vitest": "^3.0.6",
|
|
45
|
-
"@itwin/build-tools": "5.1.0-dev.
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/core-
|
|
45
|
+
"@itwin/build-tools": "5.1.0-dev.54",
|
|
46
|
+
"@itwin/core-bentley": "5.1.0-dev.54",
|
|
47
|
+
"@itwin/core-geometry": "5.1.0-dev.54"
|
|
48
48
|
},
|
|
49
49
|
"nyc": {
|
|
50
50
|
"extends": "./node_modules/@itwin/build-tools/.nycrc",
|