PDFCMapUtils.java 1.05 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.internal.pdftoolkit.pdf.graphics.font.impl;

public class PDFCMapUtils {
    public static final String ADOBE_TOUNICODEMAP = "UCS2";
    private static final int ONE_BYTE_LIMIT = 255;
    private static final int TWO_BYTE_LIMIT = 65535;

    public static long getCharCode(byte[] bytes) {
        long charCode = 0;
        if (bytes.length > 1) {
            for (int i = 0; i < bytes.length; ++i) {
                charCode |= (long)(bytes[i] & 255);
                if (i >= bytes.length - 1) continue;
                charCode <<= 8;
            }
        } else {
            charCode = bytes[0] & 255;
        }
        return charCode;
    }

    public static byte[] numToByteArray(long value, int minBytesNeeded) {
        byte[] b = minBytesNeeded == 1 && value <= 255 ? new byte[1] : (value <= 65535 ? new byte[2] : new byte[4]);
        for (int i = 0; i < b.length; ++i) {
            int offset = (b.length - 1 - i) * 8;
            b[i] = (byte)(value >>> offset & 255);
        }
        return b;
    }
}