UNPKG

@itwin/core-backend

Version:
177 lines • 7.31 kB
/** @packageDocumentation * @module ElementGeometry */ import { BaselineShift, FontId, FontType, FractionRun, LineLayoutResult, Paragraph, Run, RunLayoutResult, TextBlock, TextBlockLayoutResult, TextRun, TextStyleSettings } from "@itwin/core-common"; import { Range2d } from "@itwin/core-geometry"; import { IModelDb } from "./IModelDb"; /** @internal */ export interface TextLayoutRanges { layout: Range2d; justification: Range2d; } /** Arguments to [[ComputeRangesForTextLayout]]. * @internal */ export interface ComputeRangesForTextLayoutArgs { chars: string; bold: boolean; italic: boolean; baselineShift: BaselineShift; fontId: FontId; widthFactor: number; lineHeight: number; } /** A function that uses a font to compute the layout and justification ranges of a string of text. * @internal */ export type ComputeRangesForTextLayout = (args: ComputeRangesForTextLayoutArgs) => TextLayoutRanges; /** A function that looks up the font Id corresponding to a [FontFamilyDescriptor]($common). * If no type is provided, the function can return a font of any type matching `name` (there may be more than one, of different types). * @internal */ export type FindFontId = (name: string, type?: FontType) => FontId; /** @internal */ export type FindTextStyle = (name: string) => TextStyleSettings; /** * Arguments supplied to [[computeLayoutTextBlockResult]]. * @beta */ export interface LayoutTextBlockArgs { /** The text block whose extents are to be computed. */ textBlock: TextBlock; /** The iModel from which to obtain fonts and [TextStyle]($common)s when laying out glyphs. */ iModel: IModelDb; /** @internal chiefly for tests, by default uses IModelJsNative.DgnDb.computeRangesForText. */ computeTextRange?: ComputeRangesForTextLayout; /** @internal chiefly for tests, by default looks up styles from a workspace. */ findTextStyle?: FindTextStyle; /** @internal chiefly for tests, by default uses IModelDb.fontMap. */ findFontId?: FindFontId; } /** * Lays out the contents of a TextBlock into a series of lines containing runs. * Each paragraph is decomposed into a series of lines. * Each series of consecutive non-linebreak runs within a paragraph is concatenated into one line. * If the document specifies a width > 0, individual lines are split to try to avoid exceeding that width. * Individual TextRuns can be split onto multiple lines at word boundaries if necessary. Individual FractionRuns are never split. * @see [[computeLayoutTextBlockResult]] * @internal */ export declare function layoutTextBlock(args: LayoutTextBlockArgs): TextBlockLayout; /** * Gets the result of laying out the the contents of a TextBlock into a series of lines containing runs. * The visual layout accounts for the [TextStyle]($common)s, fonts, and [TextBlock.width]($common). It applies word-wrapping if needed. * The layout returned matches the visual layout of the geometry produced by [[produceTextAnnotationGeometry]]. * @beta */ export declare function computeLayoutTextBlockResult(args: LayoutTextBlockArgs): TextBlockLayoutResult; /** * Arguments supplied to [[computeGraphemeOffsets]]. * @beta */ export interface ComputeGraphemeOffsetsArgs extends LayoutTextBlockArgs { /** The index of the [Paragraph]($common) in the text block that contains the run layout result text. */ paragraphIndex: number; /** The run layout result for which grapheme ranges will be computed. */ runLayoutResult: RunLayoutResult; /** An array of starting character indexes for each grapheme. Each entry represents the index of the first character in a grapheme. */ graphemeCharIndexes: number[]; } /** * Computes the range from the start of a [RunLayoutResult]($common) to the trailing edge of each grapheme. * It is the responsibility of the caller to determine the number and character indexes of the graphemes. * @returns If the [RunLayoutResult]($common)'s source is a [TextRun]($common), it returns an array containing the range of each grapheme. * Otherwise, it returns and empty array. * @beta */ export declare function computeGraphemeOffsets(args: ComputeGraphemeOffsetsArgs): Range2d[]; declare class LayoutContext { private readonly _computeTextRange; private readonly _findTextStyle; private readonly _findFontId; private readonly _textStyles; private readonly _fontIds; readonly blockSettings: TextStyleSettings; constructor(block: TextBlock, _computeTextRange: ComputeRangesForTextLayout, _findTextStyle: FindTextStyle, _findFontId: FindFontId); findFontId(name: string): FontId; findTextStyle(name: string): TextStyleSettings; createRunSettings(run: Run): TextStyleSettings; computeRangeForText(chars: string, style: TextStyleSettings, baselineShift: BaselineShift): TextLayoutRanges; computeRangeForTextRun(style: TextStyleSettings, run: TextRun, charOffset: number, numChars: number): TextLayoutRanges; computeRangeForFractionRun(style: TextStyleSettings, source: FractionRun): { layout: Range2d; numerator: Range2d; denominator: Range2d; }; } /** @internal */ export declare class RunLayout { source: Run; charOffset: number; numChars: number; range: Range2d; justificationRange?: Range2d; denominatorRange?: Range2d; numeratorRange?: Range2d; offsetFromLine: { x: number; y: number; }; style: TextStyleSettings; fontId: FontId; private constructor(); static create(source: Run, context: LayoutContext): RunLayout; /** Compute a string representation, primarily for debugging purposes. */ stringify(): string; canWrap(): this is { source: TextRun; }; private cloneForWrap; split(context: LayoutContext): RunLayout[]; toResult(paragraph: Paragraph): RunLayoutResult; } /** @internal */ export declare class LineLayout { source: Paragraph; range: Range2d; justificationRange: Range2d; offsetFromDocument: { x: number; y: number; }; private _runs; constructor(source: Paragraph); /** Compute a string representation, primarily for debugging purposes. */ stringify(): string; get runs(): ReadonlyArray<RunLayout>; get isEmpty(): boolean; get back(): RunLayout; append(run: RunLayout): void; /** Invoked every time a run is appended,. */ private computeRanges; toResult(textBlock: TextBlock): LineLayoutResult; } /** * Describes the layout of a text block as a collection of lines containing runs. * @internal */ export declare class TextBlockLayout { source: TextBlock; /** @internal: This is primarily for debugging purposes. This is the range of text geometry */ textRange: Range2d; /** The range including margins of the [[TextBlock]]. */ range: Range2d; lines: LineLayout[]; private _context; constructor(source: TextBlock, context: LayoutContext); toResult(): TextBlockLayoutResult; /** Compute a string representation, primarily for debugging purposes. */ stringify(): string; private get _back(); private populateLines; private justifyLines; private flushLine; private applyMargins; } export {}; //# sourceMappingURL=TextAnnotationLayout.d.ts.map