PageRenderTime 65ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/pptx/src/org/apache/poi/xslf/usermodel/XSLFBackground.java

https://github.com/minstrelsy/POI-Android
Java | 108 lines | 61 code | 16 blank | 31 comment | 6 complexity | f259ec227f81c8d728d9e1a1d81f293e MD5 | raw file
  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.xslf.usermodel;
  16. import net.pbdavey.awt.Graphics2D;
  17. import org.apache.xmlbeans.XmlObject;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
  19. //import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
  20. import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
  21. import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
  22. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  23. import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
  24. import and.awt.Color;
  25. import and.awt.Dimension;
  26. import and.awt.Paint;
  27. import and.awt.geom.Rectangle2D;
  28. /**
  29. * Background shape
  30. *
  31. * @author Yegor Kozlov
  32. */
  33. public class XSLFBackground extends XSLFSimpleShape {
  34. /* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
  35. super(shape, sheet);
  36. }
  37. @Override
  38. public Rectangle2D getAnchor(){
  39. Dimension pg = getSheet().getSlideShow().getPageSize();
  40. return new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
  41. }
  42. public void draw(Graphics2D graphics) {
  43. Rectangle2D anchor = getAnchor();
  44. Paint fill = getPaint(graphics);
  45. if(fill != null) {
  46. graphics.setPaint(fill);
  47. graphics.fill(anchor);
  48. }
  49. }
  50. /**
  51. * @return the Paint object to fill
  52. */
  53. Paint getPaint(Graphics2D graphics){
  54. RenderableShape rShape = new RenderableShape(this);
  55. Paint fill = null;
  56. CTBackground bg = (CTBackground)getXmlObject();
  57. if(bg.isSetBgPr()){
  58. XmlObject spPr = bg.getBgPr();
  59. fill = rShape.getPaint(graphics, spPr, null);
  60. } else if (bg.isSetBgRef()){
  61. CTStyleMatrixReference bgRef= bg.getBgRef();
  62. CTSchemeColor phClr = bgRef.getSchemeClr();
  63. int idx = (int)bgRef.getIdx() - 1001;
  64. XSLFTheme theme = getSheet().getTheme();
  65. CTBackgroundFillStyleList bgStyles =
  66. theme.getXmlObject().getThemeElements().getFmtScheme().getBgFillStyleLst();
  67. XmlObject bgStyle = bgStyles.selectPath("*")[idx];
  68. fill = rShape.selectPaint(graphics, bgStyle, phClr, theme.getPackagePart());
  69. }
  70. return fill;
  71. }
  72. @Override
  73. public Color getFillColor(){
  74. Paint p = getPaint(null);
  75. if(p instanceof Color){
  76. return (Color)p;
  77. }
  78. return null;
  79. }
  80. /**
  81. * background does not have a associated transform.
  82. * we return a dummy transform object to prevent exceptions in inherited methods.
  83. *
  84. * @return dummy CTTransform2D bean
  85. */
  86. @Override
  87. CTTransform2D getXfrm() {
  88. return CTTransform2D.Factory.newInstance();
  89. }
  90. }