Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

HSLFSlideMaster.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.hslf.usermodel;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import org.apache.poi.hslf.model.textproperties.TextProp;
  19. import org.apache.poi.hslf.model.textproperties.TextPropCollection;
  20. import org.apache.poi.hslf.record.*;
  21. /**
  22. * SlideMaster determines the graphics, layout, and formatting for all the slides in a given presentation.
  23. * It stores information about default font styles, placeholder sizes and positions,
  24. * background design, and color schemes.
  25. *
  26. * @author Yegor Kozlov
  27. */
  28. public final class HSLFSlideMaster extends HSLFMasterSheet {
  29. private final List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>();
  30. /**
  31. * all TxMasterStyleAtoms available in this master
  32. */
  33. private TxMasterStyleAtom[] _txmaster;
  34. /**
  35. * Constructs a SlideMaster from the MainMaster record,
  36. *
  37. */
  38. public HSLFSlideMaster(MainMaster record, int sheetNo) {
  39. super(record, sheetNo);
  40. for (List<HSLFTextParagraph> l : HSLFTextParagraph.findTextParagraphs(getPPDrawing(), this)) {
  41. if (!_paragraphs.contains(l)) _paragraphs.add(l);
  42. }
  43. for (List<HSLFTextParagraph> p : _paragraphs) {
  44. for (HSLFTextParagraph htp : p) {
  45. htp.supplySheet(this);
  46. }
  47. }
  48. }
  49. /**
  50. * Returns an array of all the TextRuns found
  51. */
  52. public List<List<HSLFTextParagraph>> getTextParagraphs() {
  53. return _paragraphs;
  54. }
  55. /**
  56. * Returns <code>null</code> since SlideMasters doen't have master sheet.
  57. */
  58. public HSLFMasterSheet getMasterSheet() {
  59. return null;
  60. }
  61. /**
  62. * Pickup a style attribute from the master.
  63. * This is the "workhorse" which returns the default style attrubutes.
  64. */
  65. public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
  66. TextProp prop = null;
  67. for (int i = level; i >= 0; i--) {
  68. List<TextPropCollection> styles =
  69. isCharacter ? _txmaster[txtype].getCharacterStyles() : _txmaster[txtype].getParagraphStyles();
  70. if (i < styles.size()) prop = styles.get(i).findByName(name);
  71. if (prop != null) break;
  72. }
  73. if (prop == null) {
  74. if(isCharacter) {
  75. switch (txtype) {
  76. case TextHeaderAtom.CENTRE_BODY_TYPE:
  77. case TextHeaderAtom.HALF_BODY_TYPE:
  78. case TextHeaderAtom.QUARTER_BODY_TYPE:
  79. txtype = TextHeaderAtom.BODY_TYPE;
  80. break;
  81. case TextHeaderAtom.CENTER_TITLE_TYPE:
  82. txtype = TextHeaderAtom.TITLE_TYPE;
  83. break;
  84. default:
  85. return null;
  86. }
  87. } else {
  88. switch (txtype) {
  89. case TextHeaderAtom.CENTRE_BODY_TYPE:
  90. case TextHeaderAtom.HALF_BODY_TYPE:
  91. case TextHeaderAtom.QUARTER_BODY_TYPE:
  92. txtype = TextHeaderAtom.BODY_TYPE;
  93. break;
  94. case TextHeaderAtom.CENTER_TITLE_TYPE:
  95. txtype = TextHeaderAtom.TITLE_TYPE;
  96. break;
  97. default:
  98. return null;
  99. }
  100. }
  101. prop = getStyleAttribute(txtype, level, name, isCharacter);
  102. }
  103. return prop;
  104. }
  105. /**
  106. * Assign SlideShow for this slide master.
  107. * (Used interanlly)
  108. */
  109. public void setSlideShow(HSLFSlideShow ss) {
  110. super.setSlideShow(ss);
  111. //after the slide show is assigned collect all available style records
  112. if (_txmaster == null) {
  113. _txmaster = new TxMasterStyleAtom[9];
  114. TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom();
  115. _txmaster[txdoc.getTextType()] = txdoc;
  116. TxMasterStyleAtom[] txrec = ((MainMaster)getSheetContainer()).getTxMasterStyleAtoms();
  117. for (int i = 0; i < txrec.length; i++) {
  118. int txType = txrec[i].getTextType();
  119. if(_txmaster[txType] == null) _txmaster[txType] = txrec[i];
  120. }
  121. }
  122. }
  123. protected void onAddTextShape(HSLFTextShape shape) {
  124. List<HSLFTextParagraph> runs = shape.getTextParagraphs();
  125. _paragraphs.add(runs);
  126. }
  127. public TxMasterStyleAtom[] getTxMasterStyleAtoms(){
  128. return _txmaster;
  129. }
  130. }