@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)
clampfunctionSource ↗
Clamp a value between min and max
declare function clamp(value: number, min: number, max: number): number;eighthsToPixelsfunctionSource ↗
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;emuToPixelsfunctionSource ↗
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;emuToTwipsfunctionSource ↗
Convert EMUs to twips
declare function emuToTwips(emu: number): number;formatPxfunctionSource ↗
Format a pixel value as CSS string
declare function formatPx(px: number): string;halfPointsToPixelsfunctionSource ↗
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;halfPointsToPointsfunctionSource ↗
Convert half-points to points
declare function halfPointsToPoints(halfPoints: number): number;pixelsToEmufunctionSource ↗
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;pixelsToTwipsfunctionSource ↗
Convert pixels to twips
declare function pixelsToTwips(px: number): number;pointsToHalfPointsfunctionSource ↗
Convert points to half-points
declare function pointsToHalfPoints(points: number): number;pointsToPixelsfunctionSource ↗
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;roundPixelsfunctionSource ↗
Round a pixel value to avoid sub-pixel rendering issues
declare function roundPixels(px: number, decimalPlaces?: number): number;twipsToEmufunctionSource ↗
Convert twips to EMUs
declare function twipsToEmu(twips: number): number;twipsToPixelsfunctionSource ↗
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 (3)
AUTO_PARAGRAPH_SPACING_PXconstSource ↗
Automatic paragraph spacing applied for w:beforeAutospacing / w:afterAutospacing (HTML-origin "auto" spacing). Word renders these as ~14px before/after regardless of any explicit w:before/w:after value.
AUTO_PARAGRAPH_SPACING_PX = 14PIXELS_PER_INCHconstSource ↗
Pixels per inch at standard DPI
PIXELS_PER_INCH = 96TWIPS_PER_INCHconstSource ↗
Twips per inch (1 inch = 1440 twips)
TWIPS_PER_INCH = 1440