package com.printer.demo.utils;


import android.graphics.Paint;
import android.text.TextPaint;

import com.printer.sdk.PrinterConstants;

/**
 * 列宽计算器
 * 58 mm ≈ 384 px
 * 80 mm ≈ 576 px
 * 1 mm ≈ 6.7 px（取整 6.5）
 */
public class ColWidthUtil {
    private static final float PX_PER_MM = 6.5f;

    /* ---------- 1. 毫米 → 像素 ---------- */
    public static int[] mm(int... mm) {
        int[] px = new int[mm.length];
        for (int i = 0; i < mm.length; i++) px[i] = (int) (mm[i] * PX_PER_MM);
        return px;
    }

    /* ---------- 2. 权重 → 像素（总宽=纸宽-左右边距） ---------- */
    public static int[] weight(int paperWidthPx, int marginPx, int... weights) {
        int usable = paperWidthPx - marginPx * 2;
        int total = 0;
        for (int w : weights) total += w;
        int[] px = new int[weights.length];
        for (int i = 0; i < weights.length; i++)
            px[i] = usable * weights[i] / total;
        return px;
    }
}