Java Pixel Convert To pixel2WidthUnits(int pxs)

Here you can find the source of pixel2WidthUnits(int pxs)

Description

Converts pixel units to Excel width units (one Excel width unit is 1/256th of a character width)

License

Open Source License

Parameter

Parameter Description
pxs Pixel value to convert

Return

Value in Excel width units

Declaration

static short pixel2WidthUnits(int pxs) 

Method Source Code

//package com.java2s;
/*/*from   www.j  av a  2 s . c  o m*/
 * #%L
 * Vaadin Spreadsheet
 * %%
 * Copyright (C) 2013 - 2015 Vaadin Ltd
 * %%
 * This program is available under Commercial Vaadin Add-On License 3.0
 * (CVALv3).
 * 
 * See the file license.html distributed with this software for more
 * information about licensing.
 * 
 * You should have received a copy of the CVALv3 along with this program.
 * If not, see <http://vaadin.com/license/cval-3>.
 * #L%
 */

public class Main {
    private static final short EXCEL_COLUMN_WIDTH_FACTOR = 256;
    private static final int UNIT_OFFSET_LENGTH = 7;
    private static final int[] UNIT_OFFSET_MAP = new int[] { 0, 36, 73, 109, 146, 182, 219 };

    /**
     * Converts pixel units to Excel width units (one Excel width unit is
     * 1/256th of a character width)
     * 
     * @param pxs
     *            Pixel value to convert
     * @return Value in Excel width units
     */
    static short pixel2WidthUnits(int pxs) {
        short widthUnits = (short) (EXCEL_COLUMN_WIDTH_FACTOR * (pxs / UNIT_OFFSET_LENGTH));

        widthUnits += UNIT_OFFSET_MAP[(pxs % UNIT_OFFSET_LENGTH)];

        return widthUnits;
    }
}

Related

  1. pixel2logical_size(float l, float zoom)
  2. pixels2angle(double pixels)
  3. pixels2Molecules(float[] pixels, int width, int height)
  4. pixelsToCm(float pixels)
  5. pixelsToInches(int sizeInPixels, int dpi)