You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InlineCharIterator.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fo;
  18. import org.apache.fop.fo.properties.CommonBorderAndPadding;
  19. import org.apache.fop.util.CharUtilities;
  20. import java.util.NoSuchElementException;
  21. public class InlineCharIterator extends RecursiveCharIterator {
  22. private boolean bStartBoundary = false;
  23. private boolean bEndBoundary = false;
  24. /**
  25. * @param fobj the object for whose character contents and for whose
  26. * descendant's character contents should be iterated
  27. * @param bap the CommonBorderAndPadding properties to be applied
  28. */
  29. public InlineCharIterator(FObj fobj, CommonBorderAndPadding bap) {
  30. super(fobj);
  31. checkBoundaries(bap);
  32. }
  33. private void checkBoundaries(CommonBorderAndPadding bap) {
  34. bStartBoundary = (bap.getBorderStartWidth(false) > 0
  35. || bap.getPaddingStart(false) > 0);
  36. bEndBoundary = (bap.getBorderEndWidth(false) > 0
  37. || bap.getPaddingEnd(false) > 0);
  38. }
  39. /**
  40. * @return true if there are more characters
  41. */
  42. public boolean hasNext() {
  43. if (bStartBoundary) {
  44. return true;
  45. }
  46. return (super.hasNext() || bEndBoundary);
  47. /* If super.hasNext() returns false,
  48. * we return true if we are going to return a "boundary" signal
  49. * else false.
  50. */
  51. }
  52. /**
  53. * @return the next character
  54. * @throws NoSuchElementException if there are no more characters
  55. */
  56. public char nextChar() throws NoSuchElementException {
  57. if (bStartBoundary) {
  58. bStartBoundary = false;
  59. return CharUtilities.CODE_EOT;
  60. }
  61. try {
  62. return super.nextChar();
  63. } catch (NoSuchElementException e) {
  64. // Underlying has nothing more to return
  65. // Check end boundary char
  66. if (bEndBoundary) {
  67. bEndBoundary = false;
  68. return CharUtilities.CODE_EOT;
  69. } else {
  70. throw e;
  71. }
  72. }
  73. }
  74. }