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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo;
  8. import org.apache.fop.layout.BorderAndPadding;
  9. import org.apache.fop.util.CharUtilities;
  10. import java.util.Iterator;
  11. import java.util.ListIterator;
  12. import java.util.NoSuchElementException;
  13. public class InlineCharIterator extends RecursiveCharIterator {
  14. private boolean bStartBoundary = false;
  15. private boolean bEndBoundary = false;
  16. public InlineCharIterator(FObj fobj, BorderAndPadding bap) {
  17. super(fobj);
  18. checkBoundaries(bap);
  19. }
  20. private void checkBoundaries(BorderAndPadding bap) {
  21. // TODO! use start and end in BAP!!
  22. bStartBoundary = (bap.getBorderLeftWidth(false) > 0 ||
  23. bap.getPaddingLeft(false) > 0);
  24. bEndBoundary = (bap.getBorderRightWidth(false) > 0 ||
  25. bap.getPaddingRight(false) > 0);
  26. }
  27. public boolean hasNext() {
  28. if (bStartBoundary)
  29. return true;
  30. return (super.hasNext() || bEndBoundary);
  31. /* If super.hasNext() returns false,
  32. * we return true if we are going to return a "boundary" signal
  33. * else false.
  34. */
  35. }
  36. public char nextChar() throws NoSuchElementException {
  37. if (bStartBoundary) {
  38. bStartBoundary = false;
  39. return CharUtilities.CODE_EOT;
  40. }
  41. try {
  42. return super.nextChar();
  43. } catch (NoSuchElementException e) {
  44. // Underlying has nothing more to return
  45. // Check end boundary char
  46. if (bEndBoundary) {
  47. bEndBoundary = false;
  48. return CharUtilities.CODE_EOT;
  49. } else
  50. throw e;
  51. }
  52. }
  53. }