@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
357 lines (356 loc) • 10.6 kB
TypeScript
import { PdfStringFormat } from './pdf-string-format';
import { PdfFont } from './pdf-standard-font';
import { _PdfWordWrapType } from './../enumerator';
import { Size } from '../pdf-type';
/**
* Lays out text into lines within a given size using the specified font and format.
*
* @private
*/
export declare class _PdfStringLayouter {
/**
* Font used to measure and lay out the text.
*
* @private
*/
_font: PdfFont;
/**
* String format settings guiding the layout process.
*
* @private
*/
_format: PdfStringFormat;
/**
* Target width and height used for layout calculations.
*
* @private
*/
_size: number[];
/**
* Target rectangle specified as [x, y, width, height].
*
* @private
*/
_rectangle: number[];
/**
* Page height used for pagination decisions.
*
* @private
*/
_pageHeight: number;
/**
* Tokenizer used to split the input string into layout units.
*
* @private
*/
_reader: _StringTokenizer;
/**
* Performs the full layout pass and returns the computed layout result.
*
* @private
* @param {string} text - Text to layout.
* @param {PdfFont} font - Font used for measuring and layout.
* @param {PdfStringFormat} format - String formatting and wrapping options.
* @param {number[]} size - Target size as [width, height].
* @returns {_PdfStringLayoutResult} The result of the layout operation.
*/
_layout(text: string, font: PdfFont, format: PdfStringFormat, size: number[]): _PdfStringLayoutResult;
/**
* Initializes the layouter with input text font format and target size.
*
* @private
* @param {string} text - Text to layout.
* @param {PdfFont} font - Font used for measuring and drawing.
* @param {PdfStringFormat} format - Formatting options to apply.
* @param {number[]} size - Target size as [width, height].
* @returns {void} nothing.
*/
_initialize(text: string, font: PdfFont, format: PdfStringFormat, size: number[]): void;
/**
* Releases references and closes the tokenizer after layout completes.
*
* @private
* @returns {void} nothing.
*/
_clear(): void;
/**
* Iterates through input lines and builds the layout using wrapping rules.
*
* @private
* @returns {_PdfStringLayoutResult} The final aggregated layout result.
*/
_doLayout(): _PdfStringLayoutResult;
/**
* Calculates the indent for the current line based on format and line position.
*
* @private
* @param {boolean} firstLine - Whether the current line is the first in the paragraph.
* @returns {number} The computed indent in points.
*/
_getLineIndent(firstLine: boolean): number;
/**
* Returns the line height using font metrics and optional line spacing.
*
* @private
* @returns {number} The line height in points.
*/
_getLineHeight(): number;
/**
* Returns the line width using font metrics and optional line spacing.
*
* @private
* @param {string} line to get the width.
* @returns {number} The width in points.
*/
_getLineWidth(line: string): number;
/**
* Breaks a single input line into layout chunks according to wrap rules.
*
* @private
* @param {string} line - Source line to be laid out.
* @param {number} lineIndent - Current line indent to apply.
* @returns {_PdfStringLayoutResult} The layout result for this line.
*/
_layoutLine(line: string, lineIndent: number): _PdfStringLayoutResult;
/**
* Adds a computed line to the result and updates accumulated size.
*
* @private
* @param {_PdfStringLayoutResult} lineResult - The per-line layout result to update.
* @param {_LineInfo[]} lines - Accumulated lines buffer.
* @param {string} line - Text of the current line.
* @param {number} lineWidth - Measured line width.
* @param {_LineType} breakType - Line break flags for this line.
* @returns {void} nothing.
*/
_addToLineResult(lineResult: _PdfStringLayoutResult, lines: _LineInfo[], line: string, lineWidth: number, breakType: _LineType): void;
/**
* Copies laid out lines into the final result respecting height limits.
*
* @private
* @param {_PdfStringLayoutResult} result - Aggregated layout result to append to.
* @param {_PdfStringLayoutResult} lineResult - Per line layout result to consume.
* @param {_LineInfo[]} lines - Temporary buffer for accepted lines.
* @param {number} flag - Placeholder/offset reference; updated with consumed char count.
* @returns {{ success: boolean, flag: number }} Copy outcome and consumed character count.
*/
_copyToResult(result: _PdfStringLayoutResult, lineResult: _PdfStringLayoutResult, lines: _LineInfo[], flag: number): {
success: boolean;
flag: number;
};
/**
* Finalizes the layout result with remaining text and line metrics.
*
* @private
* @param {_PdfStringLayoutResult} result - The layout result to finalize.
* @param {_LineInfo[]} lines - Accepted lines to attach to the result.
* @returns {void} nothing.
*/
_finalizeResult(result: _PdfStringLayoutResult, lines: _LineInfo[]): void;
/**
* Trims leading and trailing spaces and recomputes the line width if needed.
*
* @private
* @param {_LineInfo} info - Line information to trim/update.
* @param {boolean} firstLine - Whether this is the first paragraph line.
* @returns {_LineInfo} The updated line information.
*/
_trimLine(info: _LineInfo, firstLine: boolean): _LineInfo;
/**
* Resolves the active word wrap mode from the current format.
*
* @private
* @returns {_PdfWordWrapType} Active word wrap mode.
*/
_getWrapType(): _PdfWordWrapType;
}
/**
* Holds the outcome of a text layout operation including lines and sizes.
*
* @private
*/
export declare class _PdfStringLayoutResult {
/**
* Lines produced as the result of the string layout.
*
* @private
*/
_layoutLines: _LineInfo[];
/**
* Remaining text that did not fit in the layout area.
*
* @private
*/
_remainder: string;
/**
* Final size occupied by the laid out text.
*
* @private
*/
_size: Size;
/**
* Height of each laid out line.
*
* @private
*/
_lineHeight: number;
/**
* Gets the measured size of the laid out content with lazy initialization.
*
* @private
* @returns {Size} The measured size.
*/
readonly _actualSize: Size;
/**
* Gets the array of laid out line information entries.
*
* @private
* @returns {_LineInfo[]} The laid out lines.
*/
readonly _lines: _LineInfo[];
/**
* Indicates whether the layout result contains no lines.
*
* @private
* @returns {boolean} `true` if empty; otherwise `false`.
*/
readonly _empty: boolean;
/**
* Gets the total number of lines in the layout result.
*
* @private
* @returns {number} The line count.
*/
readonly _lineCount: number;
}
/**
* Represents a single laid out line with its text width and break flags.
*
* @private
*/
export declare class _LineInfo {
/**
* Text content of the current line.
*
* @private
*/
_text: string;
/**
* Measured width of the current line.
*
* @private
*/
_width: number;
/**
* Indicates the type of the line (e.g., first, middle, last).
*
* @private
*/
_lineType: _LineType;
}
/**
* Specifies flags that describe how a line is broken and positioned.
*
* @private
*/
export declare enum _LineType {
none = 0,
newLineBreak = 1,
layoutBreak = 2,
firstParagraphLine = 4,
lastParagraphLine = 8
}
/**
* Parses text into lines words and characters while tracking position.
*
* @private
*/
export declare class _StringTokenizer {
/**
* Source text to be tokenized.
*
* @private
*/
_text: string;
/**
* Current reading position within the source text.
*
* @private
*/
_position: number;
static readonly _whiteSpace: string;
static readonly _tab: string;
static readonly _spaces: string[];
constructor(textValue: string);
/**
* Gets the total length of the underlying text.
*
* @private
* @returns {number} The total text length.
*/
readonly _length: number;
/**
* Indicates whether the tokenizer has reached the end of the text.
*
* @private
* @returns {boolean} `true` if end of text; otherwise `false`.
*/
readonly _end: boolean;
/**
* Reads the next line from the current position and advances the cursor.
*
* @private
* @returns {string} The next line, or `null` when no lines remain.
*/
_readLine(): string;
/**
* Peeks the next line without advancing the current position.
*
* @private
* @returns {string} The next line, or `null` if none.
*/
_peekLine(): string;
/**
* Reads the next word or delimiter run and advances the position.
*
* @private
* @returns {string} The next word or delimiter sequence, or `null` if none.
*/
_readWord(): string;
/**
* Peeks the next word or delimiter run without moving the position.
*
* @private
* @returns {string} The next word or delimiter sequence, or `null` if none.
*/
_peekWord(): string;
/**
* Reads one character or the requested number of characters from the current position.
*
* @private
* @returns {string} The next character.
*/
_read(): string;
_read(count: number): string;
/**
* Returns the current character without advancing the position.
*
* @private
* @returns {string} The current character, or '0' if at end.
*/
_peek(): string;
/**
* Releases tokenizer resources by clearing the backing text.
*
* @private
* @returns {void} nothing.
*/
_close(): void;
/**
* Reads all remaining text from the current position and advances to the end.
*
* @private
* @returns {string} The remaining text from the current position.
*/
_readToEnd(): string;
}