New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-core/utils/units

Unit Conversion Utilities - Convert OOXML units to CSS/pixels

OOXML uses various unit systems that need conversion for rendering: - Twips: 1/20 of a point (1440 twips = 1 inch) - EMUs (English Metric Units): 914400 EMUs = 1 inch - Half-points: 1/2 of a point (144 half-points = 1 inch) - Points: 72 points = 1 inch - Eighths of a point: 1/8 of a point (576 eighths = 1 inch)

Standard assumption: 96 DPI (pixels per inch)

Functions(14)

Clamp a value between min and max

declare function clamp(value: number, min: number, max: number): number;

Convert eighths of a point to pixels (at 96 DPI)

Eighths of a point are used for border widths in OOXML.

declare function eighthsToPixels(eighths: number): number;

Convert EMUs to pixels (at 96 DPI)

1 inch = 914400 EMUs = 96 pixels Returns 0 for null/undefined/NaN inputs.

declare function emuToPixels(emu: number | undefined | null): number;

Convert EMUs to twips

declare function emuToTwips(emu: number): number;

Format a pixel value as CSS string

declare function formatPx(px: number): string;

Convert half-points to pixels (at 96 DPI)

Half-points are commonly used for font sizes in OOXML (w:sz).

declare function halfPointsToPixels(halfPoints: number): number;

Convert half-points to points

declare function halfPointsToPoints(halfPoints: number): number;

Convert pixels to EMUs. EMU coordinates in OOXML are integer-typed (xs:long); rounding here keeps floating-point drift (e.g. 52 px → 495299.99999999994) out of the document.

declare function pixelsToEmu(px: number): number;

Convert pixels to twips

declare function pixelsToTwips(px: number): number;

Convert points to half-points

declare function pointsToHalfPoints(points: number): number;

Convert points to pixels (at 96 DPI)

1 inch = 72 points = 96 pixels → 1 point = 96/72 pixels = 4/3 pixels

declare function pointsToPixels(points: number): number;

Round a pixel value to avoid sub-pixel rendering issues

declare function roundPixels(px: number, decimalPlaces?: number): number;

Convert twips to EMUs

declare function twipsToEmu(twips: number): number;

Convert twips to pixels (at 96 DPI)

1 inch = 1440 twips = 96 pixels → 1 twip = 96/1440 pixels = 1/15 pixels

declare function twipsToPixels(twips: number): number;

Variables(2)

Pixels per inch at standard DPI

PIXELS_PER_INCH = 96

Twips per inch (1 inch = 1440 twips)

TWIPS_PER_INCH = 1440