@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;eighthsToPixels
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;emuToPixels
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;emuToTwips
Convert EMUs to twips
declare function emuToTwips(emu: number): number;formatPx
Format a pixel value as CSS string
declare function formatPx(px: number): string;halfPointsToPixels
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;halfPointsToPoints
Convert half-points to points
declare function halfPointsToPoints(halfPoints: number): number;pixelsToEmu
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;pixelsToTwips
Convert pixels to twips
declare function pixelsToTwips(px: number): number;pointsToHalfPoints
Convert points to half-points
declare function pointsToHalfPoints(points: number): number;pointsToPixels
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;roundPixels
Round a pixel value to avoid sub-pixel rendering issues
declare function roundPixels(px: number, decimalPlaces?: number): number;twipsToEmu
Convert twips to EMUs
declare function twipsToEmu(twips: number): number;twipsToPixels
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
Pixels per inch at standard DPI
PIXELS_PER_INCH = 96TWIPS_PER_INCH
Twips per inch (1 inch = 1440 twips)
TWIPS_PER_INCH = 1440