Package org.plutext.jaxb.xslfo

Examples of org.plutext.jaxb.xslfo.SimplePageMaster


      boolean needBefore, boolean needAfter) {
   
    // This method uses dummy large extents
    // A later step fixes them.
   
    SimplePageMaster spm = getFactory().createSimplePageMaster();
    spm.setMasterName(masterName);
   
    // dimensions. 
    //   <w:pgSz w:w="12240" w:h="15840"/>
        //   <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>

    spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getPgSz().getH().intValue() ));
    spm.setPageWidthUnitsOfMeasurement.twipToBest(page.getPgSz().getW().intValue() ));
   
    spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.getPgMar().getLeft().intValue() ) );
    spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.getPgMar().getRight().intValue()) );
   
    /*
     * Region before & after live in region body margins:
     *
     * Per http://www.w3.org/TR/xsl/#fo_region-body
     *
     * The body region should be sized and positioned within the fo:simple-page-master
     * so that there is room for the areas returned by the flow that is assigned to the
     * fo:region-body and for any desired side regions, that is, fo:region-before,
     * fo:region-after, fo:region-start and fo:region-end's that are to be placed on the same page.
     *
     * These side regions are positioned within the content-rectangle of the page-reference-area.
     * The margins on the fo:region-body are used to position the region-viewport-area for the
     * fo:region-body and to leave space for the other regions that surround the fo:region-body.
     *                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     *                   
     * The spacing between the last four regions and the fo:region-body is determined by subtracting
     * the relevant extent trait on the side regions from the trait that corresponds to the "margin-x"
     * property on the fo:region-body.
     */
    RegionBody rb = getFactory().createRegionBody();   
    rb.setMarginLeft("0mm");
    rb.setMarginRight("0mm");
   
    float halfPageHeight = page.getPgSz().getH().intValue()/40; // convert from twips, then * 0.5
    String halfPageHeightPts = halfPageHeight + "pt"
   
    spm.setRegionBody(rb);
   
    if (needBefore) {
      //Header
      RegionBefore rBefore = getFactory().createRegionBefore();
      rBefore.setRegionName("xsl-region-before-"+appendRegionName);
      spm.setRegionBefore(rBefore);
     
      // Margin top on SPM is space between the page edge and the start of the header     
      int marginTopTwips
        =  page.getHeaderMargin();
      spm.setMarginTop( UnitsOfMeasurement.twipToBest(marginTopTwips ) );
     
      // Size header manually
      rBefore.setExtent( halfPageHeightPts); // A4 portrait is 297mm high
     
     
      // Leave room for this region in body margin
      rb.setMarginTop(halfPageHeightPts);
     
     
    } else {
      // No header
      spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.getPgMar().getTop().intValue() ) );
    }

    if (needAfter) {
      // Footer
      RegionAfter rAfter = getFactory().createRegionAfter();
      rAfter.setRegionName("xsl-region-after-"+appendRegionName);
      spm.setRegionAfter(rAfter);
     
      int marginBottomTwips= page.getFooterMargin();
      spm.setMarginBottom( UnitsOfMeasurement.twipToBest(marginBottomTwips) );
     
      // Size footer manually
      rAfter.setExtent( halfPageHeightPts); // A4 portrait is 297mm high
         
      // Leave room for this region in body margin
      rb.setMarginBottom(halfPageHeightPts );
     
    } else {
      // No footer
      spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.getPgMar().getBottom().intValue()) );
    }
   
    return spm;
  }
View Full Code Here


                <region-before extent="1435mm" region-name="xsl-region-before-default"/>
                <region-after extent="145mm" region-name="xsl-region-after-default"/>
              </simple-page-master>
           */
         
          SimplePageMaster spm =((SimplePageMaster)o);
         
          String simplePageMasterName = spm.getMasterName()// eg s1-first page
         
          // We'll need the corresponding ConversionSectionWrapper
          int index = -1 + Integer.parseInt(
              simplePageMasterName.substring(1, simplePageMasterName.indexOf("-")));
          PageDimensions page = null;
          if (sections.get(index)==null) {
            log.error("Couldn't find section " + index + " from " + simplePageMasterName);
          } else {
            page = sections.get(index).getPageDimensions();
          }
         
          // Region before
          if (spm.getRegionBefore()!=null) {
            Integer hBpdaMilliPts = headerBpda.get(simplePageMasterName);
            if (hBpdaMilliPts==null) {
              // No headerBpda for s1-default
              log.error("No headerBpda for " + simplePageMasterName);
              // You need to debug to find out why
             
            } else {
                float hBpdaPts = hBpdaMilliPts/1000;
              spm.getRegionBefore().setExtent(hBpdaPts+"pt");
              spm.getRegionBody().setMarginTop(hBpdaPts+"pt");
             
              // If the top margin in Word > what we have, then pad with margin top
              float totalHeight = (page.getHeaderMargin()/20 ) // twips to points
                        + hBpdaPts;
             
              float extraMargin = (page.getPgMar().getTop().intValue()/20) - totalHeight; 
             
              if (extraMargin>0) {
                float required = (page.getPgMar().getTop().intValue()-page.getHeaderMargin())/20;
                spm.getRegionBody().setMarginTop(required+"pt");             
              } // otherwise, we've expanded to the extent of the header already
            }
          }
         
          // Region after
          if (spm.getRegionAfter()!=null) {
            Integer fBpdaMilliPts = footerBpda.get(simplePageMasterName);
            if (fBpdaMilliPts==null) {
              log.error("No footerBpda for " + simplePageMasterName);
             
            } else {           
              float fBpdaPts = fBpdaMilliPts/1000;
              spm.getRegionAfter().setExtent(fBpdaPts+"pt");
              spm.getRegionBody().setMarginBottom(fBpdaPts+"pt");
             
              // If the bottom margin in Word > what we have, then pad with margin bottom
              float totalHeight = (page.getFooterMargin()/20 ) // twips to points
                        + fBpdaPts;
             
              float extraMargin = (page.getPgMar().getBottom().intValue()/20) - totalHeight; 
             
              if (extraMargin>0) {
                float required = (page.getPgMar().getBottom().intValue()-page.getFooterMargin())/20;
                spm.getRegionBody().setMarginBottom(required+"pt");             
              } // otherwise, we've expanded to the extent of the footer already
           
            }
          }         
         
View Full Code Here

TOP

Related Classes of org.plutext.jaxb.xslfo.SimplePageMaster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.