public static class UnitConverter
public const double DefaultDpi = 96;
public static Pixel ToPixel(this Inch inch) => inch.ToEmu().ToPixel();
public static Inch ToInch(this Pixel pixel) => pixel.ToEmu().ToInch();
public static Pt ToPt(this Dxa dxa)
return new Pt(dxa.Value / 20);
public static Dxa ToDxa(this Pt pt)
return new Dxa(pt.Value * 20);
public static Inch ToInch(this Dxa dxa)
return new Inch(dxa.Value / 72);
public static Dxa ToDxa(this Inch inch)
return new Dxa(inch.Value * 72);
public static Cm ToCm(this Mm mm)
return new Cm(mm.Value / 10);
public static Mm ToMm(this Cm cm)
return new Mm(cm.Value * 10);
public static Cm ToCm(this Pt pt)
return pt.ToEmu().ToCm();
public static Pt ToPt(this Cm cm)
return cm.ToEmu().ToPt();
public static Mm ToMm(this Pt pt)
public static Pt ToPt(this Mm mm)
public static Pt ToPt(this HalfPoint halfPoint)
return new Pt(halfPoint.Value / 2);
public static HalfPoint ToHalfPoint(this Pt pt)
return new HalfPoint(pt.Value * 2);
public static Pixel ToPixel(this Pt pt)
return new Pixel(pt.Value / 72 * DefaultDpi);
public static Pt ToPoint(this Pixel px)
return new Pt(px.Value * 72 / DefaultDpi);
public static Emu ToEmu(this Inch inch)
return new Emu(inch.Value * 914400);
public static Inch ToInch(this Emu emu)
return new Inch(emu.Value / 914400);
public static Emu ToEmu(this Cm cm)
return new Emu(cm.Value * 360000);
public static Cm ToCm(this Emu emu)
return new Cm(emu.Value / 360000);
public static Emu ToEmu(this Mm cm)
return new Emu(cm.Value * 36000);
public static Dxa ToDxa(this Emu emu)
return new Dxa(emu.Value / 635);
public static Emu ToEmu(this Dxa dxa)
return new Emu(dxa.Value * 635);
public static Mm ToMm(this Emu emu)
return new Mm(emu.Value / 36000);
public static Emu ToEmu(this Pixel px)
return new Emu(px.Value * 914400 / DefaultDpi);
public static Pixel ToPixel(this Emu emu)
return new Pixel(emu.Value / 914400 * DefaultDpi);
public static Emu ToEmu(this Pt pt)
return new Emu(pt.Value * 12700);
public static Pt ToPt(this Emu emu)
return new Pt(emu.Value / 12700);