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.

Hyphen.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.hyphenation;
  19. import java.io.Serializable;
  20. /**
  21. * This class represents a hyphen. A 'full' hyphen is made of 3 parts:
  22. * the pre-break text, post-break text and no-break. If no line-break
  23. * is generated at this position, the no-break text is used, otherwise,
  24. * pre-break and post-break are used. Typically, pre-break is equal to
  25. * the hyphen character and the others are empty. However, this general
  26. * scheme allows support for cases in some languages where words change
  27. * spelling if they're split across lines, like german's 'backen' which
  28. * hyphenates 'bak-ken'. BTW, this comes from TeX.
  29. *
  30. * @author Carlos Villegas <cav@uniscope.co.jp>
  31. */
  32. /**
  33. * Represents a hyphen.
  34. */
  35. public class Hyphen implements Serializable {
  36. private static final long serialVersionUID = 8989909741110279085L;
  37. /** pre break string */
  38. public String preBreak; // CSOK: VisibilityModifier
  39. /** no break string */
  40. public String noBreak; // CSOK: VisibilityModifier
  41. /** post break string */
  42. public String postBreak; // CSOK: VisibilityModifier
  43. /**
  44. * Construct a hyphen.
  45. * @param pre break string
  46. * @param no break string
  47. * @param post break string
  48. */
  49. Hyphen(String pre, String no, String post) {
  50. preBreak = pre;
  51. noBreak = no;
  52. postBreak = post;
  53. }
  54. /**
  55. * Construct a hyphen.
  56. * @param pre break string
  57. */
  58. Hyphen(String pre) {
  59. preBreak = pre;
  60. noBreak = null;
  61. postBreak = null;
  62. }
  63. /** {@inheritDoc} */
  64. public String toString() {
  65. if (noBreak == null
  66. && postBreak == null
  67. && preBreak != null
  68. && preBreak.equals("-")) {
  69. return "-";
  70. }
  71. StringBuffer res = new StringBuffer("{");
  72. res.append(preBreak);
  73. res.append("}{");
  74. res.append(postBreak);
  75. res.append("}{");
  76. res.append(noBreak);
  77. res.append('}');
  78. return res.toString();
  79. }
  80. }