You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XDGFPage.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xdgf.usermodel;
  16. import java.awt.geom.Point2D;
  17. import java.awt.geom.Rectangle2D;
  18. import com.microsoft.schemas.office.visio.x2012.main.PageType;
  19. import org.apache.poi.ooxml.POIXMLException;
  20. import org.apache.poi.util.Internal;
  21. import org.apache.poi.xdgf.geom.Dimension2dDouble;
  22. /**
  23. * Provides the API to work with an underlying page
  24. */
  25. public class XDGFPage {
  26. private PageType _page;
  27. protected XDGFPageContents _content;
  28. protected XDGFPages _pages;
  29. protected XDGFSheet _pageSheet;
  30. public XDGFPage(PageType page, XDGFPageContents content,
  31. XDGFDocument document, XDGFPages pages) {
  32. _page = page;
  33. _content = content;
  34. _pages = pages;
  35. content.setPage(this);
  36. if (page.isSetPageSheet())
  37. _pageSheet = new XDGFPageSheet(page.getPageSheet(), document);
  38. }
  39. @Internal
  40. protected PageType getXmlObject() {
  41. return _page;
  42. }
  43. public long getID() {
  44. return _page.getID();
  45. }
  46. public String getName() {
  47. return _page.getName();
  48. }
  49. public XDGFPageContents getContent() {
  50. return _content;
  51. }
  52. public XDGFSheet getPageSheet() {
  53. return _pageSheet;
  54. }
  55. public long getPageNumber() {
  56. return _pages.getPageList().indexOf(this) + 1L;
  57. }
  58. /**
  59. * @return width/height of page
  60. */
  61. public Dimension2dDouble getPageSize() {
  62. XDGFCell w = _pageSheet.getCell("PageWidth");
  63. XDGFCell h = _pageSheet.getCell("PageHeight");
  64. if (w == null || h == null)
  65. throw new POIXMLException("Cannot determine page size");
  66. return new Dimension2dDouble(Double.parseDouble(w.getValue()),
  67. Double.parseDouble(h.getValue()));
  68. }
  69. /**
  70. * @return origin of coordinate system
  71. */
  72. public Point2D.Double getPageOffset() {
  73. XDGFCell xoffcell = _pageSheet.getCell("XRulerOrigin");
  74. XDGFCell yoffcell = _pageSheet.getCell("YRulerOrigin");
  75. double xoffset = 0;
  76. double yoffset = 0;
  77. if (xoffcell != null)
  78. xoffset = Double.parseDouble(xoffcell.getValue());
  79. if (yoffcell != null)
  80. yoffset = Double.parseDouble(yoffcell.getValue());
  81. return new Point2D.Double(xoffset, yoffset);
  82. }
  83. /**
  84. * @return bounding box of page
  85. */
  86. public Rectangle2D getBoundingBox() {
  87. Dimension2dDouble sz = getPageSize();
  88. Point2D.Double offset = getPageOffset();
  89. return new Rectangle2D.Double(-offset.getX(), -offset.getY(),
  90. sz.getWidth(), sz.getHeight());
  91. }
  92. }