/*
* author:MaoFangyun
* createTime:2015-01-15
* description:打印
* notice:需引用lodop,LodopFuncs.js
*/

/*
*   打印页面设置(A4纵向参考值890px,横向参考值1450px) 
*
*   @pageName   页面名称 e.g. "A4","CreateCustomPage"(自定义页面大小)
*   @pageSize   页面大小[width,height]，自定义页面时需设置此值，参考值[2410,1400]、[2150,1350]
*   @model      打印模式1:纵向打印 2:横向打印
*   @point      页面左上角的坐标[top,left]
*   
*   备注：pt=1/72(英寸), px=1/dpi(英寸)
*   因此 pt=px*72/dpi
*   以Windows下的96dpi来计算，pt=px*72/96=px*3/4 1450px=1087.5pt 890px=667.5pt
*/
function PrintPage(config) {
    this.pageName = (config && config.pageName) ? config.pageName : "A4";
    this.pageSize = (config && config.pageSize) ? config.pageSize : [0, 0];
    this.model = (config && config.model) ? config.model : 1;
    this.point = (config && config.point) ? config.point : ["10mm", "0mm"];
}
function Print(config) {
    this.lodop = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
    this.printPage = new PrintPage(config);
}
Print.prototype = {
    print: function(data, isPrint) {
        if (data.length == 0) {
            alert("没有可打印的数据");
            return;
        }
        data = data.split('$==$');
        var html = [];
        html.push("<table style='border:none;' >");
        for (var i = 0, k = data.length; i < k; i++) {
            html.push("<tr><td>");
            html.push(data[i]);
            html.push("</td></tr>");
        }
        html.push("</table>");
        this.lodop.PRINT_INIT("");
        this.lodop.SET_PRINT_PAGESIZE(this.printPage.model, this.printPage.pageSize[0], this.printPage.pageSize[1], this.printPage.pageName);
        if (this.printPage.model == 2) {//横向打印时，让预览旋转90度(正向显示)
            this.lodop.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1);
        }
        this.lodop.ADD_PRINT_TABLE(this.printPage.point[0], this.printPage.point[1], '100%', 1, html.join(""));
        if (isPrint) {
            this.lodop.PRINT();
        } else {
            this.lodop.PREVIEW();
        }
    }
}