1 17 18 19 20 package org.apache.fop.render.rtf; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.impl.SimpleLog; 24 import org.apache.fop.datatypes.Length; 25 import org.apache.fop.fo.Constants; 26 import org.apache.fop.fo.expr.NumericOp; 27 import org.apache.fop.fo.pagination.RegionBA; 28 import org.apache.fop.fo.pagination.RegionBody; 29 import org.apache.fop.fo.pagination.SimplePageMaster; 30 import org.apache.fop.fo.properties.CommonMarginBlock; 31 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; 32 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage; 33 34 35 39 40 final class PageAttributesConverter { 41 42 private static Log log = new SimpleLog("FOP/RTF"); 43 44 47 private PageAttributesConverter() { 48 } 49 50 51 static RtfAttributes convertPageAttributes(SimplePageMaster pagemaster) { 52 FOPRtfAttributes attrib = new FOPRtfAttributes(); 53 54 try { 55 RegionBA before = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_BEFORE); 56 RegionBody body = (RegionBody) pagemaster.getRegion(Constants.FO_REGION_BODY); 57 RegionBA after = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_AFTER); 58 59 attrib.setTwips(RtfPage.PAGE_WIDTH, pagemaster.getPageWidth()); 60 attrib.setTwips(RtfPage.PAGE_HEIGHT, pagemaster.getPageHeight()); 61 62 Object widthRaw = attrib.getValue(RtfPage.PAGE_WIDTH); 63 Object heightRaw = attrib.getValue(RtfPage.PAGE_HEIGHT); 64 if ((widthRaw instanceof Integer ) && (heightRaw instanceof Integer ) 65 && ((Integer ) widthRaw).intValue() > ((Integer ) heightRaw).intValue()) { 66 attrib.set(RtfPage.LANDSCAPE); 67 } 68 69 Length pageTop = pagemaster.getCommonMarginBlock().marginTop; 70 Length pageBottom = pagemaster.getCommonMarginBlock().marginBottom; 71 Length pageLeft = pagemaster.getCommonMarginBlock().marginLeft; 72 Length pageRight = pagemaster.getCommonMarginBlock().marginRight; 73 74 Length bodyTop = pageTop; 75 Length bodyBottom = pageBottom; 76 Length bodyLeft = pageLeft; 77 Length bodyRight = pageRight; 78 79 if (body != null) { 80 CommonMarginBlock bodyMargin = body.getCommonMarginBlock(); 82 bodyTop = (Length) NumericOp.addition(pageTop, bodyMargin.marginTop); 83 bodyBottom = (Length) NumericOp.addition(pageBottom, bodyMargin.marginBottom); 84 bodyLeft = (Length) NumericOp.addition(pageLeft, bodyMargin.marginLeft); 85 bodyRight = (Length) NumericOp.addition(pageRight, bodyMargin.marginRight); 86 } 87 88 attrib.setTwips(RtfPage.MARGIN_TOP, bodyTop); 89 attrib.setTwips(RtfPage.MARGIN_BOTTOM, bodyBottom); 90 attrib.setTwips(RtfPage.MARGIN_LEFT, bodyLeft); 91 attrib.setTwips(RtfPage.MARGIN_RIGHT, bodyRight); 92 93 Length beforeTop = pageTop; 95 if (before != null) { 96 beforeTop = (Length) NumericOp.addition(pageTop, before.getExtent()); 97 } 98 attrib.setTwips(RtfPage.HEADERY, beforeTop); 99 100 Length afterBottom = pageBottom; 102 if (after != null) { 103 afterBottom = (Length) NumericOp.addition(pageBottom, after.getExtent()); 104 } 105 attrib.setTwips(RtfPage.FOOTERY, beforeTop); 106 } catch (Exception e) { 107 log.error("Exception in convertPageAttributes: " 108 + e.getMessage() + "- page attributes ignored"); 109 attrib = new FOPRtfAttributes(); 110 } 111 112 return attrib; 113 } 114 } 115 | Popular Tags |