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.

HyphContext.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.layoutmgr.inline;
  19. /**
  20. * This class is used to pass information to the getNextBreakPoss()
  21. * method concerning hyphenation. A reference to an instance of the
  22. * class is contained in the LayoutContext object passed to each
  23. * LayoutManager. It contains information concerning the hyphenation
  24. * points in a word and the how many of those have previously been
  25. * processed by a Layout Manager to generate size information.
  26. */
  27. public class HyphContext {
  28. private int[] hyphPoints;
  29. private int currentOffset;
  30. private int currentIndex;
  31. /**
  32. * @param hyphPoints number of hyphenation points
  33. */
  34. public HyphContext(int[] hyphPoints) {
  35. this.hyphPoints = hyphPoints;
  36. }
  37. /** @return next hyphenation point */
  38. public int getNextHyphPoint() {
  39. for (; currentIndex < hyphPoints.length; currentIndex++) {
  40. if (hyphPoints[currentIndex] > currentOffset) {
  41. return (hyphPoints[currentIndex] - currentOffset);
  42. }
  43. }
  44. return -1; // AT END!
  45. }
  46. /** @return true if more hyphenation points */
  47. public boolean hasMoreHyphPoints() {
  48. for (; currentIndex < hyphPoints.length; currentIndex++) {
  49. if (hyphPoints[currentIndex] > currentOffset) {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. /** @param iCharsProcessed amount to extend offset */
  56. public void updateOffset(int iCharsProcessed) {
  57. currentOffset += iCharsProcessed;
  58. }
  59. }