package com.radaee.view;

import android.content.Context;
import android.graphics.Bitmap;

import com.radaee.pdf.Global;

public class PDFViewLandscape extends PDFViewVert {

    private int m_lock = 0;
    private int m_align = 1;

    public PDFViewLandscape(Context context) {
        super(context);
    }

    public void vResize(int w, int h)
    {
        if ((w == 0) || (h == 0) || (this.m_lock == 4)) return;
        if (this.m_bmp != null) this.m_bmp.recycle();
        this.m_bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        this.m_w = w;
        this.m_h = h;
        vLayout();
        if (this.m_listener != null)
        {
            this.m_listener.OnPDFInvalidate(false);
        }
    }

    public void vSetPageAlign(int align)
    {
        // Do nothing
    }

    protected void vLayout()
    {
        if ((this.m_doc == null) || (this.m_w <= this.m_page_gap) || (this.m_h <= this.m_page_gap)) return;
        int cur = 0;
        int cnt = this.m_doc.GetPageCount();
        float maxw = 0.0F;
        float maxh = 0.0F;
        while (cur < cnt)
        {
            float w = this.m_doc.GetPageWidth(cur);
            float h = this.m_doc.GetPageHeight(cur);
            if (maxw < w) maxw = w;
            if (maxh < h) maxh = h;
            cur++;
        }
        this.m_scale_min = this.m_h / maxh;
        this.m_scale_max = (this.m_scale_min * Global.zoomLevel);
        if (this.m_scale < this.m_scale_min) this.m_scale = this.m_scale_min;
        if (this.m_scale > this.m_scale_max) this.m_scale = this.m_scale_max;

        if (this.m_pages == null) this.m_pages = new PDFVPage[cnt];
        int left;
        int top = this.m_page_gap / 2;
        this.m_docw = ((int)(this.m_scale * maxw) + this.m_page_gap);
        this.m_doch = 0;

        cur = 0;
        while (cur < cnt)
        {
            if (this.m_pages[cur] == null) this.m_pages[cur] = new PDFVPage(this.m_doc, cur);
            left = (this.m_w - (int)(this.m_doc.GetPageWidth(cur) * this.m_scale)) / 2;
            this.m_pages[cur].SetRect(left, top, this.m_scale);
            top += this.m_pages[cur].GetHeight() + this.m_page_gap;
            cur++;
        }
        this.m_doch = top;
    }
}
