Beispiel #1
0
  /**
   * support body auto resize, remove invalid header and footer
   *
   * @param page
   */
  protected void updateBodySize() {
    if (header != null && header.getHeight() >= root.getHeight()) {
      removeHeader();
      header = null;
    }
    if (footer != null && footer.getHeight() >= root.getHeight()) {
      removeFooter();
      footer = null;
    }
    if (header != null
        && footer != null
        && footer.getHeight() + header.getHeight() >= root.getHeight()) {
      removeHeader();
    }

    body.setHeight(
        root.getContentHeight()
            - (header == null ? 0 : header.getHeight())
            - (footer == null ? 0 : footer.getHeight()));
    body.setPosition(
        body.getX(),
        (header == null ? 0 : header.getHeight()) + root.getBoxStyle().getTopBorderWidth());
    if (footer != null) {
      footer.setPosition(
          footer.getX(),
          (header == null ? 0 : header.getHeight())
              + root.getBoxStyle().getTopBorderWidth()
              + (body == null ? 0 : body.getHeight()));
    }
  }
Beispiel #2
0
 /** layout page footer area */
 protected void layoutFooter() {
   IContent footerContent = pageContent.getPageFooter();
   if (footerContent != null) {
     DimensionType h = pageContent.getFooterHeight();
     if (h == null) {
       h = new DimensionType(0.5f, DimensionType.UNITS_IN);
     }
     footerContent.setHeight(h);
     footer.content = footerContent;
     boolean autoPageBreak = context.isAutoPageBreak();
     context.setAutoPageBreak(false);
     RegionLayoutEngine rle = new RegionLayoutEngine(footer, context);
     try {
       rle.layout(footerContent);
     } catch (BirtException e) {
       logger.log(Level.WARNING, e.getMessage(), e);
     }
     context.setAutoPageBreak(autoPageBreak);
   }
 }
Beispiel #3
0
  protected void createRoot() {
    int overFlowType = context.getPageOverflow();

    if (overFlowType == IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES) {
      // page.setExtendToMultiplePages( true );
    }

    pageContentWidth =
        getDimensionValue(pageContent, pageContent.getPageWidth())
            - boxStyle.getLeftBorderWidth()
            - boxStyle.getRightBorderWidth();
    pageContentHeight =
        getDimensionValue(pageContent, pageContent.getPageHeight())
            - boxStyle.getTopBorderWidth()
            - boxStyle.getBottomBorderWidth();

    // validate page width
    if (pageContentWidth <= 0) {
      pageContentWidth = DEFAULT_PAGE_WIDTH;
    }

    // validate page height
    if (pageContentHeight <= 0) {
      pageContentHeight = DEFAULT_PAGE_HEIGHT;
    }

    setWidth(pageContentWidth);
    setHeight(pageContentHeight);

    /** set position and dimension for root */
    ContainerArea pageRoot = new BlockContainerArea();
    BoxStyle boxStyle = buildRootStyle();
    if (boxStyle != BoxStyle.DEFAULT) {
      pageRoot.hasStyle = true;
    }
    pageRoot.setBoxStyle(boxStyle);
    rootLeft = getDimensionValue(pageContent, pageContent.getMarginLeft(), pageContentWidth);
    rootTop = getDimensionValue(pageContent, pageContent.getMarginTop(), pageContentWidth);
    rootLeft = Math.max(0, rootLeft);
    rootLeft = Math.min(pageContentWidth, rootLeft);
    rootTop = Math.max(0, rootTop);
    rootTop = Math.min(pageContentHeight, rootTop);
    pageRoot.setPosition(rootLeft, rootTop);
    int rootRight = getDimensionValue(pageContent, pageContent.getMarginRight(), pageContentWidth);
    int rootBottom =
        getDimensionValue(pageContent, pageContent.getMarginBottom(), pageContentWidth);
    rootRight = Math.max(0, rootRight);
    rootBottom = Math.max(0, rootBottom);
    if (rootLeft + rootRight > pageContentWidth) {
      rootRight = 0;
    }
    if (rootTop + rootBottom > pageContentHeight) {
      rootBottom = 0;
    }

    rootWidth = pageContentWidth - rootLeft - rootRight;
    rootHeight = pageContentHeight - rootTop - rootBottom;
    pageRoot.setWidth(rootWidth);
    pageRoot.setHeight(rootHeight);
    setRoot(pageRoot);
    pageRoot.setParent(this);

    /** set position and dimension for header */
    int headerHeight =
        getDimensionValue(pageContent, pageContent.getHeaderHeight(), pageRoot.getHeight());
    int headerWidth =
        pageRoot.getWidth() - boxStyle.getLeftBorderWidth() - boxStyle.getRightBorderWidth();
    headerHeight = Math.max(0, headerHeight);
    headerHeight = Math.min(pageRoot.getHeight(), headerHeight);
    RegionArea header = new RegionArea();
    header.setHeight(headerHeight);
    header.setWidth(headerWidth);
    header.context = context;
    header.needClip = true;
    header.setPosition(boxStyle.getLeftBorderWidth(), boxStyle.getTopBorderWidth());
    pageRoot.addChild(header);
    setHeader(header);
    header.setParent(pageRoot);

    /** set position and dimension for footer */
    int footerHeight =
        getDimensionValue(pageContent, pageContent.getFooterHeight(), pageRoot.getHeight());
    int footerWidth =
        pageRoot.getWidth() - boxStyle.getLeftBorderWidth() - boxStyle.getRightBorderWidth();
    footerHeight = Math.max(0, footerHeight);
    footerHeight = Math.min(pageRoot.getHeight() - headerHeight, footerHeight);
    RegionArea footer = new RegionArea();
    footer.setHeight(footerHeight);
    footer.setWidth(footerWidth);
    footer.context = context;
    footer.needClip = true;
    footer.setPosition(
        boxStyle.getLeftBorderWidth(),
        pageRoot.getHeight() - boxStyle.getBottomBorderWidth() - footerHeight);
    pageRoot.addChild(footer);
    setFooter(footer);
    footer.setParent(pageRoot);

    /** set position and dimension for body */
    ContainerArea body = new BlockContainerArea();
    int bodyLeft = getDimensionValue(pageContent, pageContent.getLeftWidth(), pageRoot.getWidth());
    bodyLeft = Math.max(0, bodyLeft);
    bodyLeft = Math.min(pageRoot.getWidth(), bodyLeft);
    body.setPosition(
        boxStyle.getLeftBorderWidth() + bodyLeft, headerHeight + boxStyle.getRightBorderWidth());
    int bodyRight =
        getDimensionValue(pageContent, pageContent.getRightWidth(), pageRoot.getWidth());
    bodyRight = Math.max(0, bodyRight);
    bodyRight = Math.min(pageRoot.getWidth() - bodyLeft, bodyRight);

    body.setWidth(
        pageRoot.getWidth()
            - bodyLeft
            - bodyRight
            - boxStyle.getLeftBorderWidth()
            - boxStyle.getRightBorderWidth());
    body.setHeight(
        pageRoot.getHeight()
            - headerHeight
            - footerHeight
            - boxStyle.getTopBorderWidth()
            - boxStyle.getBottomBorderWidth());
    setBody(body);
    if (overFlowType == IPDFRenderOption.CLIP_CONTENT
        || overFlowType == IPDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES) {
      pageRoot.setNeedClip(true);
      body.setNeedClip(true);
    } else {
      pageRoot.setNeedClip(false);
    }
    // TODO add left area and right area;
  }