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.

SlideMaster.java 5.2KB

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