/** * Created by guopeng on 16/8/12. * * 纸张类, 给report提供宽, 高 * */ import * as React from "react"; import {RectF, RectUnit, Unit, SizeF, SizeUnit, PointF} from "../drawing/Unit"; import {DesignerHost} from "../design/DesignerHost"; import {ReportItemBase} from "../items/ReportItemBase"; import {ReportItem} from "../items/ReportItem" import {PageBand} from "../items/band/PageBand" import {Report} from "../items/Report"; import {hasPaper, saveCustomPaper, papaers} from "../configs/papers"; import {observable} from "mobx"; // import {PaperTypeEnum} from "../configs/enums"; // interface Props { // // } // // export interface IPaper { // name: string; // width: number; // height: number; // } // export default class Paper { // // @observable // private _width:Unit; // // @observable // private _height:Unit; // // // 纸张名称 // private _paperType:string; // // private _report:Report; // // static findMatchPaper(width: number, height: number): IPaper { // return papaers.find((paper) => paper.width === width && paper.height === height); // } // // /** // * 构造函数重载 // * 1. 接收宽、高 // * 2. 接收 纸张类型 `configs/papers.ts` 中定义的类型 // * // * @param widthOrPaper // * @param height // */ // constructor(widthOrPaper:any, height?:number) { // if (height) { // // 传入的是宽高 // this._width = Unit.mm(widthOrPaper); // this._height = Unit.mm(height); // this.setPaperType(widthOrPaper, height); // 设置纸张类型 // } else { // // 传入的是纸张 // this._width = Unit.mm(widthOrPaper.width); // this._height = Unit.mm(widthOrPaper.height); // this._paperType = widthOrPaper.name; // } // // } // // get width():Unit { // return this._width; // } // // get height():Unit { // return this._height; // } // // get paperType():string { // return this._paperType; // } // // get report() { // if (!this._report) { // this._report = DesignerHost.instance().designReport.report; // } // // return this._report; // } // // /** // * 判断papers中是否有此纸张的定义, 没有的话加入, 并设置当前类型 // * @param width // * @param height // */ // setPaperType(width:number, height:number) { // const paper = hasPaper(width, height); // if (!paper) { // const customPaper = saveCustomPaper(width, height); // this._paperType = customPaper.name; // } else { // this._paperType = paper.name; // } // } // // /////////////////////////// 纸张超高判断 ////////////////////////////// // // /** // * 已占用的高度, 上下边距加上所有bands高度 // * @returns {number} // */ // used():number { // const report = this.report; // const items = report.items; // let h = 0; // items.forEach(function (_band) { // const band = _band as ReportItem; // h += band.height.pixels; // }) // // h += report.topMargin.pixels; // h += report.bottomMargin.pixels; // // return h; // } // // /** // * 是否占满paper高度 // * > 0 为还有空间 // * @returns {number} // */ // isFull():number { // const report = this.report; // return report.height.pixels - this.used(); // } // // // canMove(item:ReportItem, bandBound:RectF, mousePoint:PointF, offset:SizeF) { // // const bandEndPosY = bandBound.y + bandBound.height; // const itemEndPosY = mousePoint.y - offset.height + item.height.pixels; // if (itemEndPosY < bandEndPosY) { // return true; // } else { // // if(this.used() + itemEndPosY - bandEndPosY - report.height ) // if (itemEndPosY - bandEndPosY - this.isFull() < 0) { // return true; // } // } // return false; // } // // // }