package com.neptune.modules;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.neptune.base.NeptuneAppMgmt;
import com.pax.gl.page.IPage;
import com.pax.gl.page.PaxGLPage;


import java.io.IOException;
import java.io.InputStream;

public class GLPrinter {
    private static GLPrinter glPrinter;
    private PaxGLPage iPaxGLPage;

    private GLPrinter() {
        iPaxGLPage = NeptuneAppMgmt.getIPaxGLPage();
    }

    public static GLPrinter getInstance() {
        if (glPrinter == null) {
            glPrinter = new GLPrinter();
        }
        return glPrinter;
    }

    public IPage createPage(){
        IPage page = iPaxGLPage.createPage();
        return page;
    }



    public Bitmap pageToBitmap(IPage page, int width){
        return iPaxGLPage.pageToBitmap(page, width);
    }

    public Bitmap getImageFromAssetsFile(String fileName) {
        Bitmap image = null;
        AssetManager am = NeptuneAppMgmt.getAppContext().getResources().getAssets();
        try {
            InputStream is = am.open(fileName);
            image = BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return image;

    }

}
