Class UnitUtil


  • public class UnitUtil
    extends Object
    Various unit conversion methods.
    Since:
    3.5.0
    Author:
    Hawk
    • Constructor Detail

      • UnitUtil

        public UnitUtil()
    • Method Detail

      • pxToPoint

        public static int pxToPoint​(int px)
        convert pixel to point
      • pointToPx

        public static int pointToPx​(int point)
        convert point to pixel
      • pxToEmu

        public static int pxToEmu​(int px)
        convert pixel to EMU
      • emuToPx

        public static int emuToPx​(int emu)
        convert EMU to pixel, 1 twip == 635 emu
      • twipToPx

        public static int twipToPx​(int twip)
        convert twip (1/20 point) to pixel
      • pxToTwip

        public static int pxToTwip​(int px)
        convert pixel to twip (1/20 point)
      • fileChar256ToPx

        public static int fileChar256ToPx​(int char256,
                                          int charWidth)
        convert file 1/256 character width to pixel
      • pxToFileChar256

        public static int pxToFileChar256​(int px,
                                          int charWidth)
        convert pixel to file 1/256 character width
      • defaultColumnWidthToPx

        public static int defaultColumnWidthToPx​(int columnWidth,
                                                 int charWidth)
        Convert default columns width (in character) to pixel. 5 pixels are margin padding.(There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.) Description of how column widths are determined in Excel (http://support.microsoft.com/kb/214123)
        Parameters:
        columnWidth - number of character
        charWidth - Using the Calibri font, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi).
        Returns:
        width in pixel Rounds this number up to the nearest multiple of 8 pixels.
      • pxToDefaultColumnWidth

        public static int pxToDefaultColumnWidth​(int px,
                                                 int charWidth)
        Convert default column width in pixel to number of character by reverse defaultColumnWidthToPx() and ignore the mod(%) operation.
        Parameters:
        px - default column width in pixel
        charWidth - one character width in pixel of normal style's font
        Returns:
        default column width in character
      • incheToPx

        public static int incheToPx​(double inches)
      • pxToInche

        public static double pxToInche​(int px)
      • pxToCTChar

        public static double pxToCTChar​(int px,
                                        int charWidth)
      • cmToInche

        public static double cmToInche​(double cm)
      • incheToCm

        public static double incheToCm​(double inches)
      • cmToPx

        public static int cmToPx​(double cm)
      • pxToCm

        public static double pxToCm​(int px)
      • xssfDefaultColumnWidthToPx

        public static int xssfDefaultColumnWidthToPx​(double xssfDefaultColumnWidth,
                                                     int charWidth)
        Convert XSSF default columns width (in character) to pixel. In XSSF the value is a double value / charWidth and includes the 5 pixels margin padding. 5 pixels are margin padding.(There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.) Description of how column widths are determined in Excel (http://support.microsoft.com/kb/214123)
        Parameters:
        columnWidth - number of character
        charWidth - Using the Calibri font, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi).
        Returns:
        width in pixel
      • hexToArgbColor

        public static byte[] hexToArgbColor​(String color)