Changeset 1567
- Timestamp:
- 06/25/11 11:45:55 (11 months ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j
- Files:
-
- 7 edited
-
convert/out/pdf/viaXSLFO/LayoutMasterSetBuilder.java (modified) (5 diffs)
-
model/structure/DocumentModel.java (modified) (3 diffs)
-
model/structure/PageDimensions.java (modified) (7 diffs)
-
model/structure/SectionWrapper.java (modified) (2 diffs)
-
model/table/TableModel.java (modified) (2 diffs)
-
openpackaging/packages/WordprocessingMLPackage.java (modified) (1 diff)
-
openpackaging/parts/DrawingML/CreateDocxWithSmartArt.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/LayoutMasterSetBuilder.java
r1182 r1567 187 187 // <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/> 188 188 189 spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getP ageHeight()));190 spm.setPageWidth( UnitsOfMeasurement.twipToBest(page.getP ageWidth()));191 192 spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.get MarginLeft()) );193 spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.get MarginRight()) );189 spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getPgSz().getH().intValue() )); 190 spm.setPageWidth( UnitsOfMeasurement.twipToBest(page.getPgSz().getW().intValue() )); 191 192 spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.getPgMar().getLeft().intValue() ) ); 193 spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.getPgMar().getRight().intValue()) ); 194 194 195 195 /* … … 227 227 // Make margin smaller, because header takes up space it would otherwise occupy 228 228 int marginTopTwips 229 = page.get MarginTop()230 - (HEADER_PADDING_TWIP + page.getHeaderExtent() + page.get MarginHeader());229 = page.getPgMar().getTop().intValue() 230 - (HEADER_PADDING_TWIP + page.getHeaderExtent() + page.getPgMar().getHeader().intValue()); 231 231 if (marginTopTwips<MIN_PAGE_MARGIN) marginTopTwips=MIN_PAGE_MARGIN; 232 232 spm.setMarginTop( UnitsOfMeasurement.twipToBest(marginTopTwips ) ); … … 240 240 } else { 241 241 // No header 242 spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.get MarginTop() ) );242 spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.getPgMar().getTop().intValue() ) ); 243 243 } 244 244 … … 251 251 // Make margin smaller, because footer takes up space it would otherwise occupy 252 252 int marginBottomTwips 253 = page.get MarginBottom()254 - (FOOTER_PADDING_TWIP + page.getFooterExtent() + page.get MarginFooter() );253 = page.getPgMar().getBottom().intValue() 254 - (FOOTER_PADDING_TWIP + page.getFooterExtent() + page.getPgMar().getFooter().intValue() ); 255 255 if (marginBottomTwips<MIN_PAGE_MARGIN) marginBottomTwips=MIN_PAGE_MARGIN; 256 256 log.debug("marginBottomTwips: " + marginBottomTwips ); … … 265 265 } else { 266 266 // No footer 267 spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.get MarginBottom()) );267 spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.getPgMar().getBottom().intValue()) ); 268 268 } 269 269 -
trunk/docx4j/src/main/java/org/docx4j/model/structure/DocumentModel.java
r1352 r1567 54 54 protected static Logger log = Logger.getLogger(DocumentModel.class); 55 55 56 private List<SectionWrapper> sections = new ArrayList<SectionWrapper>(); 57 58 // Consider whether this class should store a reference to the 59 // org.docx4j.wml.Document? Not until there is a demonstrable 60 // need. 56 private List<SectionWrapper> sections; 57 private WordprocessingMLPackage wordMLPackage; 61 58 62 59 // At present, objects (eg w:p, w:tbl) don't know which … … 69 66 public DocumentModel(WordprocessingMLPackage wordMLPackage) { 70 67 68 this.wordMLPackage = wordMLPackage; 69 refresh(); 70 } 71 72 /** 73 * If you have added/deleted sections from your WordprocessingMLPackage, 74 * you'll need to call this method in order for the changes to be 75 * reflected in the DocumentModel. 76 */ 77 public void refresh() { 78 71 79 RelationshipsPart rels = wordMLPackage.getMainDocumentPart().getRelationshipsPart(); 72 80 … … 75 83 HeaderFooterPolicy previousHF = null; 76 84 77 for (Object o : doc.getBody().getEGBlockLevelElts() ) { 85 sections = new ArrayList<SectionWrapper>(); 86 for (Object o : doc.getBody().getContent() ) { 78 87 if (o instanceof org.docx4j.wml.P) { 79 88 if (((org.docx4j.wml.P)o).getPPr() != null ) { -
trunk/docx4j/src/main/java/org/docx4j/model/structure/PageDimensions.java
r1537 r1567 25 25 import org.docx4j.jaxb.Context; 26 26 import org.docx4j.wml.STPageOrientation; 27 import org.docx4j.wml.SectPr; 27 28 import org.docx4j.wml.SectPr.PgMar; 28 29 import org.docx4j.wml.SectPr.PgSz; 29 30 31 /** 32 * Wraps PgSz (Page size) and PgMar (margin settings). 33 * - gives you an easy way to set these; 34 * - performs a few useful calculations 35 * 36 * Used in SectionWrapper, to store the dimensions 37 * of a page for a section; can also be used to 38 * store a set of page dimensions which aren't 39 * associated with any section. 40 * 41 * @author jharrop 42 * 43 */ 30 44 public class PageDimensions { 31 45 32 // Defaults - if values aren't defined in sectPr 33 // TODO - defaults page size and margins in a .properties file 34 35 public static int DEFAULT_PAGE_WIDTH_TWIPS = 12240; // Letter; A4 would be 11907 36 public static int DEFAULT_LEFT_MARGIN_TWIPS = 1440; // 1 inch 37 public static int DEFAULT_RIGHT_MARGIN_TWIPS = 1440; 38 // TODO - defaults for the other fields 39 40 int pageWidth = DEFAULT_PAGE_WIDTH_TWIPS; 41 int pageHeight = 15840; // Letter 42 43 int marginTop = 1440; 44 int marginBottom = 1440; 45 int marginLeft = DEFAULT_LEFT_MARGIN_TWIPS; 46 int marginRight = DEFAULT_RIGHT_MARGIN_TWIPS; 47 48 int marginHeader = 708; 49 int marginFooter = 708; 50 int marginGutter = 0; 51 52 // @Deprecated 53 // public void setA4Defaults() { 54 // /* Mimic 55 // <w:pgSz w:w="12240" w:h="15840"/>^M 56 // <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" 57 // w:header="708" w:footer="708" w:gutter="0"/> 58 // */ 59 // pageWidth = DEFAULT_PAGE_WIDTH_TWIPS; 60 // pageHeight = 15840; 61 // 62 // marginTop = 1440; 63 // marginBottom = 1440; 64 // marginLeft = DEFAULT_LEFT_MARGIN_TWIPS; 65 // marginRight = DEFAULT_RIGHT_MARGIN_TWIPS; 66 // 67 // marginHeader = 708; 68 // marginFooter = 708; 69 // marginGutter = 0; 70 // } 71 46 // TODO - defaults page size and margins in a .properties file? 47 48 public PageDimensions() { 49 pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 50 setPgSize(PageSizePaper.A4, false ); 51 52 pgMar = Context.getWmlObjectFactory().createSectPrPgMar(); 53 setMargins(MarginsWellKnown.NORMAL); 54 } 55 56 /** 57 * @since 2.7 58 */ 59 public PageDimensions(PgSz pgSz, PgMar pgMar) { 60 init(pgSz, pgMar); 61 } 62 63 /** 64 * @since 2.7 65 */ 66 public PageDimensions(SectPr sectPr) { 67 if (sectPr==null) { 68 init(null, null); 69 } else { 70 init(sectPr.getPgSz(), sectPr.getPgMar()); 71 } 72 } 73 74 private void init(PgSz pgSz, PgMar pgMar) { 75 76 if (pgSz == null) { 77 pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 78 } else { 79 this.pgSz = pgSz; 80 } 81 82 if (pgMar ==null) { 83 pgMar = Context.getWmlObjectFactory().createSectPrPgMar(); 84 } else { 85 this.pgMar = pgMar; 86 } 87 } 88 89 private PgSz pgSz; 90 /** 91 * @since 2.7 92 */ 93 public PgSz getPgSz() { 94 return pgSz; 95 } 96 /** 97 * @since 2.7 98 */ 99 public void setPgSz(PgSz pgSz) { 100 this.pgSz = pgSz; 101 } 102 103 private PgMar pgMar; 104 /** 105 * @since 2.7 106 */ 107 public PgMar getPgMar() { 108 return pgMar; 109 } 110 /** 111 * @since 2.7 112 */ 113 public void setPgMar(PgMar pgMar) { 114 this.pgMar = pgMar; 115 } 116 117 72 118 /** 73 119 * @since 2.7 … … 77 123 // NORMAL("normal"), // <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/> 78 124 if (m.equals(MarginsWellKnown.NORMAL)) { 79 marginTop = 1440;80 marginBottom = 1440;81 marginLeft = 1440;82 marginRight = 1440;125 pgMar.setTop( BigInteger.valueOf(1440)); 126 pgMar.setBottom( BigInteger.valueOf(1440)); 127 pgMar.setLeft( BigInteger.valueOf(1440)); 128 pgMar.setRight( BigInteger.valueOf(1440)); 83 129 return; 84 130 } … … 86 132 // NARROW("narrow"), // <w:pgMar w:top="720" w:right="720" w:bottom="720" w:left="720" w:header="708" w:footer="708" w:gutter="0"/> 87 133 if (m.equals(MarginsWellKnown.NARROW)) { 88 marginTop = 720;89 marginBottom = 720;90 marginLeft = 720;91 marginRight = 720;134 pgMar.setTop( BigInteger.valueOf(720)); 135 pgMar.setBottom( BigInteger.valueOf(720)); 136 pgMar.setLeft( BigInteger.valueOf(720)); 137 pgMar.setRight( BigInteger.valueOf(720)); 92 138 return; 93 139 } … … 95 141 // MODERATE("moderate"), // <w:pgMar w:top="1440" w:right="1080" w:bottom="1440" w:left="1080" w:header="708" w:footer="708" w:gutter="0"/> 96 142 if (m.equals(MarginsWellKnown.MODERATE)) { 97 marginTop = 1440;98 marginBottom = 1440;99 marginLeft = 1080;100 marginRight = 1080;143 pgMar.setTop( BigInteger.valueOf(1440)); 144 pgMar.setBottom( BigInteger.valueOf(1440)); 145 pgMar.setLeft( BigInteger.valueOf(1080)); 146 pgMar.setRight( BigInteger.valueOf(1080)); 101 147 return; 102 148 } … … 104 150 // WIDE("wide"); // <w:pgMar w:top="1440" w:right="2880" w:bottom="1440" w:left="2880" w:header="708" w:footer="708" w:gutter="0"/> 105 151 if (m.equals(MarginsWellKnown.WIDE)) { 106 marginTop = 1440; 107 marginBottom = 1440; 108 marginLeft = 2880; 109 marginRight = 2880; 110 return; 111 } 112 113 } 114 115 public void setPageSize(PgSz pgSz ) { 116 117 if (pgSz!=null) { 118 if (pgSz.getW()!=null) { 119 pageWidth = pgSz.getW().intValue(); 120 } 121 if (pgSz.getH()!=null) { 122 pageHeight = pgSz.getH().intValue(); 123 } 124 } 125 } 126 127 /** 128 * @since 2.7 129 */ 130 public static PgSz createPgSize(PageSizePaper sz, boolean landscape ) { 131 132 PgSz pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 133 152 pgMar.setTop( BigInteger.valueOf(1440)); 153 pgMar.setBottom( BigInteger.valueOf(1440)); 154 pgMar.setLeft( BigInteger.valueOf(2880)); 155 pgMar.setRight( BigInteger.valueOf(2880)); 156 return; 157 } 158 159 } 160 161 /** 162 * @since 2.7 163 */ 164 public void setPgSize(PageSizePaper sz, boolean landscape ) { 165 134 166 if (sz.equals(PageSizePaper.LETTER)) { 135 167 pgSz.setCode(BigInteger.valueOf(1)); … … 196 228 } 197 229 } 198 return pgSz;199 230 } 200 201 public PgSz createPgSize() { 202 203 PgSz pgSz = Context.getWmlObjectFactory().createSectPrPgSz(); 204 205 pgSz.setW( BigInteger.valueOf(pageWidth) ); 206 pgSz.setH( BigInteger.valueOf(pageHeight) ); 207 208 209 return pgSz; 210 } 211 212 public void setMargins(PgMar pgMar) { 213 214 if (pgMar!=null) { 215 if (pgMar.getTop()!=null) { 216 marginTop = pgMar.getTop().intValue(); 217 } 218 219 if (pgMar.getBottom()!=null) { 220 marginBottom = pgMar.getBottom().intValue(); 221 } 222 if (pgMar.getLeft()!=null) { 223 marginLeft = pgMar.getLeft().intValue(); 224 } 225 if (pgMar.getRight()!=null) { 226 marginRight = pgMar.getRight().intValue(); 227 } 228 229 if (pgMar.getHeader()!=null) { 230 marginHeader = pgMar.getHeader().intValue(); 231 } 232 if (pgMar.getFooter()!=null) { 233 marginFooter = pgMar.getFooter().intValue(); 234 } 235 if (pgMar.getGutter()!=null) { 236 marginGutter = pgMar.getGutter().intValue(); 237 } 238 } 239 } 240 241 public PgMar createPgMar() { 242 243 PgMar pgMar = Context.getWmlObjectFactory().createSectPrPgMar(); 244 245 pgMar.setTop( BigInteger.valueOf(marginTop) ); 246 pgMar.setBottom( BigInteger.valueOf(marginBottom) ); 247 pgMar.setLeft( BigInteger.valueOf(marginLeft) ); 248 pgMar.setRight( BigInteger.valueOf(marginRight) ); 249 250 pgMar.setHeader( BigInteger.valueOf(marginHeader) ); 251 pgMar.setFooter( BigInteger.valueOf(marginFooter) ); 252 pgMar.setGutter( BigInteger.valueOf(marginGutter) ); 253 254 return pgMar; 255 } 256 257 258 /** 259 * @return the pageWidth 260 */ 261 public int getPageWidth() { 262 return pageWidth; 263 } 264 265 /** 266 * @param pageWidth the pageWidth to set 267 */ 268 public void setPageWidth(int pageWidth) { 269 this.pageWidth = pageWidth; 270 } 271 272 public int getWritableWidthTwips() { 273 return pageWidth - (marginLeft + marginRight); 274 } 275 276 /** 277 * @return the pageHeight 278 */ 279 public int getPageHeight() { 280 return pageHeight; 281 } 282 283 /** 284 * @param pageHeight the pageHeight to set 285 */ 286 public void setPageHeight(int pageHeight) { 287 this.pageHeight = pageHeight; 288 } 289 290 /** 291 * @return the marginTop 292 */ 293 public int getMarginTop() { 294 return marginTop; 295 } 296 297 /** 298 * @param marginTop the marginTop to set 299 */ 300 public void setMarginTop(int marginTop) { 301 this.marginTop = marginTop; 302 } 303 304 /** 305 * @return the marginBottom 306 */ 307 public int getMarginBottom() { 308 return marginBottom; 309 } 310 311 /** 312 * @param marginBottom the marginBottom to set 313 */ 314 public void setMarginBottom(int marginBottom) { 315 this.marginBottom = marginBottom; 316 } 317 318 /** 319 * @return the marginLeft 320 */ 321 public int getMarginLeft() { 322 return marginLeft; 323 } 324 325 /** 326 * @param marginLeft the marginLeft to set 327 */ 328 public void setMarginLeft(int marginLeft) { 329 this.marginLeft = marginLeft; 330 } 331 332 /** 333 * @return the marginRight 334 */ 335 public int getMarginRight() { 336 return marginRight; 337 } 338 339 /** 340 * @param marginRight the marginRight to set 341 */ 342 public void setMarginRight(int marginRight) { 343 this.marginRight = marginRight; 344 } 345 346 /** 347 * @return the marginHeader 348 */ 349 public int getMarginHeader() { 350 return marginHeader; 351 } 352 353 /** 354 * @param marginHeader the marginHeader to set 355 */ 356 public void setMarginHeader(int marginHeader) { 357 this.marginHeader = marginHeader; 358 } 359 360 /** 361 * @return the marginFooter 362 */ 363 public int getMarginFooter() { 364 return marginFooter; 365 } 366 367 /** 368 * @param marginFooter the marginFooter to set 369 */ 370 public void setMarginFooter(int marginFooter) { 371 this.marginFooter = marginFooter; 372 } 373 374 /** 375 * @return the marginGutter 376 */ 377 public int getMarginGutter() { 378 return marginGutter; 379 } 380 381 /** 382 * @param marginGutter the marginGutter to set 383 */ 384 public void setMarginGutter(int marginGutter) { 385 this.marginGutter = marginGutter; 231 232 public int getWritableWidthTwips() { 233 return pgSz.getW().intValue() - (pgMar.getLeft().intValue() + pgMar.getRight().intValue()); 386 234 } 387 235 … … 401 249 * 402 250 * Instead, this class allows headerExtent and footerExtent to be 403 * set as required (in TWIPS). In due course (when we have an algori rthm for amount of251 * set as required (in TWIPS). In due course (when we have an algorithm for amount of 404 252 * space occupied), it may be possible to do this automatically. 405 253 * 406 254 */ 407 255 408 private int headerExtent = 708;409 256 public int getHeaderExtent() { 410 return headerExtent; 411 } 412 public void setHeaderExtent(int headerExtent) { 413 this.headerExtent = headerExtent; 414 } 415 416 private int footerExtent = 1440; //708; 257 if (pgMar.getHeader()==null 258 || pgMar.getHeader().intValue() ==0 ) { 259 return 708; 260 } else { 261 return pgMar.getHeader().intValue(); 262 } 263 } 264 417 265 public int getFooterExtent() { 418 return footerExtent; 419 } 420 public void setFooterExtent(int footerExtent) { 421 this.footerExtent = footerExtent; 422 } 423 266 if (pgMar.getFooter()==null 267 || pgMar.getFooter().intValue() ==0 ) { 268 return 1440; 269 } else { 270 return pgMar.getFooter().intValue(); 271 } 272 } 424 273 425 274 } -
trunk/docx4j/src/main/java/org/docx4j/model/structure/SectionWrapper.java
r1352 r1567 20 20 package org.docx4j.model.structure; 21 21 22 import java.util.ArrayList;23 import java.util.List;24 22 25 23 import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; … … 33 31 this.headerFooterPolicy = new HeaderFooterPolicy(sectPr, previousHF, rels); 34 32 35 page = new PageDimensions(); 36 if (sectPr!=null) { 37 if (sectPr.getPgSz()!=null) { 38 page.setPageSize(sectPr.getPgSz()); 39 } 40 if (sectPr.getPgMar()!=null) { 41 page.setMargins(sectPr.getPgMar()); 42 } 43 } 33 page = new PageDimensions(sectPr); 44 34 45 35 } -
trunk/docx4j/src/main/java/org/docx4j/model/table/TableModel.java
r1475 r1567 94 94 cells = new Vector<List<Cell>>(); 95 95 } 96 97 // TODO, retire this 98 private final static int DEFAULT_PAGE_WIDTH_TWIPS = 12240; // LETTER; A4 would be 11907 96 99 97 100 /** … … 427 430 // Default to page width 428 431 TblWidth tblWidth = factory.createTblWidth(); 429 tblWidth.setW(BigInteger.valueOf(PageDimensions.DEFAULT_PAGE_WIDTH_TWIPS)); 432 tblWidth.setW(BigInteger.valueOf(DEFAULT_PAGE_WIDTH_TWIPS)); 433 // TODO: shouldn't hard code that. Pass it in? 430 434 tblWidth.setType("dxa"); // twips 431 435 tblPr.setTblW(tblWidth); -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
r1536 r1567 408 408 // Create a basic sectPr using our Page model 409 409 PageDimensions page = new PageDimensions(); 410 page.setPgSize(sz, landscape); 411 410 412 SectPr sectPr = factory.createSectPr(); 411 413 body.setSectPr(sectPr); 412 sectPr.setPgSz( PageDimensions.createPgSize(sz, landscape) );413 sectPr.setPgMar( page.createPgMar());414 sectPr.setPgSz( page.getPgSz() ); 415 sectPr.setPgMar( page.getPgMar() ); 414 416 415 417 // Put the content in the part -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/DrawingML/CreateDocxWithSmartArt.java
r1544 r1567 67 67 MarginsWellKnown margins, 68 68 Document xml) throws Exception { 69 70 // TODO: pass in page size and orientation, 71 // and scale the SmartArt to fill the page. 72 69 73 70 // Make a basic docx 74 71 WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(sz, landscape); … … 97 94 98 95 // Occupy entire page, less margins 99 PgSz pgSz = PageDimensions.createPgSize(sz, landscape );100 96 PageDimensions pd = new PageDimensions(); 97 pd.setPgSize(sz, landscape ); 98 PgSz pgSz = pd.getPgSz(); 101 99 pd.setMargins(margins); 102 String cx = ""+UnitsOfMeasurement.twipToEMU(pgSz.getW().intValue() - (pd.getMarginLeft()+pd.getMarginRight() ) ); //"5486400"; 103 String cy = ""+UnitsOfMeasurement.twipToEMU(pgSz.getH().intValue() - (pd.getMarginTop()+pd.getMarginBottom() )); //"3200400"; 100 String cx = ""+UnitsOfMeasurement.twipToEMU(pgSz.getW().intValue() 101 - (pd.getPgMar().getLeft().intValue()+pd.getPgMar().getRight().intValue() ) ); //"5486400"; 102 String cy = ""+UnitsOfMeasurement.twipToEMU(pgSz.getH().intValue() 103 - (pd.getPgMar().getTop().intValue()+pd.getPgMar().getBottom().intValue() )); //"3200400"; 104 104 105 105 // Now use it in the docx
Note: See TracChangeset
for help on using the changeset viewer.
