1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.rtfdoc; 21 22 26 public class RtfSpaceSplitter { 27 28 29 private RtfAttributes commonAttributes; 30 31 32 private int spaceBefore; 33 34 35 private int spaceAfter; 36 37 38 private boolean updatingSpaceBefore; 39 40 41 private RtfAttributes spaceBeforeCandidate; 42 43 44 private RtfAttributes spaceAfterCandidate; 45 46 52 public RtfSpaceSplitter(RtfAttributes attrs, int previousSpace) { 53 commonAttributes = attrs; 54 updatingSpaceBefore = true; 55 spaceBeforeCandidate = null; 56 spaceAfterCandidate = null; 57 58 spaceBefore = split(RtfText.SPACE_BEFORE) + previousSpace; 59 spaceAfter = split(RtfText.SPACE_AFTER); 60 } 61 62 69 public int split(String key) { 70 Integer i = (Integer ) commonAttributes.getValue(key); 71 if (i == null) { 72 i = new Integer (0); 73 } 74 75 commonAttributes.unset(key); 76 return i.intValue(); 77 } 78 79 80 public RtfAttributes getCommonAttributes() { 81 return commonAttributes; 82 } 83 84 85 public int getSpaceBefore() { 86 return spaceBefore; 87 } 88 89 95 public void setSpaceBeforeCandidate(RtfAttributes candidate) { 96 if (updatingSpaceBefore) { 97 this.spaceBeforeCandidate = candidate; 98 } 99 } 100 101 107 public void setSpaceAfterCandidate(RtfAttributes candidate) { 108 this.spaceAfterCandidate = candidate; 109 } 110 111 112 public boolean isBeforeCadidateSet() { 113 return spaceBeforeCandidate != null; 114 } 115 116 117 public boolean isAfterCadidateSet() { 118 return spaceAfterCandidate != null; 119 } 120 121 124 public void stopUpdatingSpaceBefore() { 125 updatingSpaceBefore = false; 126 } 127 128 135 public int flush() { 136 int accumulatingSpace = 0; 137 if (!isBeforeCadidateSet()) { 138 accumulatingSpace += spaceBefore; 139 } else { 140 spaceBeforeCandidate.addIntegerValue(spaceBefore, 141 RtfText.SPACE_BEFORE); 142 } 143 144 if (!isAfterCadidateSet()) { 145 accumulatingSpace += spaceAfter; 146 } else { 147 spaceAfterCandidate.addIntegerValue(spaceAfter, 148 RtfText.SPACE_AFTER); 149 } 150 151 return accumulatingSpace; 152 } 153 } 154 | Popular Tags |