Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XSLFBackground.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 org.apache.xmlbeans.XmlObject;
  17. import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
  19. import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
  20. import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
  21. import java.awt.Color;
  22. import java.awt.Dimension;
  23. import java.awt.Graphics2D;
  24. import java.awt.Paint;
  25. import java.awt.geom.Rectangle2D;
  26. /**
  27. * Background shape
  28. *
  29. * @author Yegor Kozlov
  30. */
  31. public class XSLFBackground extends XSLFSimpleShape {
  32. /* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
  33. super(shape, sheet);
  34. }
  35. @Override
  36. public Rectangle2D getAnchor(){
  37. Dimension pg = getSheet().getSlideShow().getPageSize();
  38. return new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
  39. }
  40. public void draw(Graphics2D graphics) {
  41. Rectangle2D anchor = getAnchor();
  42. Paint fill = getPaint(graphics);
  43. if(fill != null) {
  44. graphics.setPaint(fill);
  45. graphics.fill(anchor);
  46. }
  47. }
  48. /**
  49. * @return the Paint object to fill
  50. */
  51. Paint getPaint(Graphics2D graphics){
  52. RenderableShape rShape = new RenderableShape(this);
  53. Paint fill = null;
  54. CTBackground bg = (CTBackground)getXmlObject();
  55. if(bg.isSetBgPr()){
  56. XmlObject spPr = bg.getBgPr();
  57. fill = rShape.getPaint(graphics, spPr, null);
  58. } else if (bg.isSetBgRef()){
  59. CTStyleMatrixReference bgRef= bg.getBgRef();
  60. CTSchemeColor phClr = bgRef.getSchemeClr();
  61. int idx = (int)bgRef.getIdx() - 1001;
  62. XSLFTheme theme = getSheet().getTheme();
  63. CTBackgroundFillStyleList bgStyles =
  64. theme.getXmlObject().getThemeElements().getFmtScheme().getBgFillStyleLst();
  65. XmlObject bgStyle = bgStyles.selectPath("*")[idx];
  66. fill = rShape.selectPaint(graphics, bgStyle, phClr, theme.getPackagePart());
  67. }
  68. return fill;
  69. }
  70. @Override
  71. public Color getFillColor(){
  72. Paint p = getPaint(null);
  73. if(p instanceof Color){
  74. return (Color)p;
  75. }
  76. return null;
  77. }
  78. }