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.

BidiOverride.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.fo.flow;
  19. import java.util.Iterator;
  20. import java.util.Stack;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.complexscripts.bidi.DelimitedTextRange;
  23. import org.apache.fop.fo.Constants;
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.properties.Property;
  27. import org.apache.fop.util.CharUtilities;
  28. /**
  29. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_bidi-override">
  30. * <code>fo:bidi-override</code></a> object.
  31. */
  32. public class BidiOverride extends Inline {
  33. // The value of FO traits (refined properties) that apply to fo:bidi-override
  34. // (that are not implemented by InlineLevel).
  35. private Property letterSpacing;
  36. private Property wordSpacing;
  37. private int direction;
  38. private int unicodeBidi;
  39. // private int scoreSpaces;
  40. // End of trait values
  41. /**
  42. * Base constructor
  43. *
  44. * @param parent FONode that is the parent of this object
  45. */
  46. public BidiOverride(FONode parent) {
  47. super(parent);
  48. }
  49. /** {@inheritDoc} */
  50. public void bind(PropertyList pList) throws FOPException {
  51. super.bind(pList);
  52. letterSpacing = pList.get(PR_LETTER_SPACING);
  53. wordSpacing = pList.get(PR_WORD_SPACING);
  54. direction = pList.get(PR_DIRECTION).getEnum();
  55. unicodeBidi = pList.get(PR_UNICODE_BIDI).getEnum();
  56. }
  57. /** @return the "letter-spacing" trait */
  58. public Property getLetterSpacing() {
  59. return letterSpacing;
  60. }
  61. /** @return the "word-spacing" trait */
  62. public Property getWordSpacing() {
  63. return wordSpacing;
  64. }
  65. /** @return the "direction" trait */
  66. public int getDirection() {
  67. return direction;
  68. }
  69. /** @return the "unicodeBidi" trait */
  70. public int getUnicodeBidi() {
  71. return unicodeBidi;
  72. }
  73. /** {@inheritDoc} */
  74. public String getLocalName() {
  75. return "bidi-override";
  76. }
  77. /**
  78. * {@inheritDoc}
  79. * @return {@link org.apache.fop.fo.Constants#FO_BIDI_OVERRIDE}
  80. */
  81. public int getNameId() {
  82. return FO_BIDI_OVERRIDE;
  83. }
  84. @Override
  85. protected Stack<DelimitedTextRange> collectDelimitedTextRanges(Stack<DelimitedTextRange> ranges,
  86. DelimitedTextRange currentRange) {
  87. char pfx = 0;
  88. char sfx = 0;
  89. int unicodeBidi = getUnicodeBidi();
  90. int direction = getDirection();
  91. if (unicodeBidi == Constants.EN_BIDI_OVERRIDE) {
  92. pfx = (direction == Constants.EN_RTL) ? CharUtilities.RLO : CharUtilities.LRO;
  93. sfx = CharUtilities.PDF;
  94. } else if (unicodeBidi == Constants.EN_EMBED) {
  95. pfx = (direction == Constants.EN_RTL) ? CharUtilities.RLE : CharUtilities.LRE;
  96. sfx = CharUtilities.PDF;
  97. }
  98. if (currentRange != null) {
  99. if (pfx != 0) {
  100. currentRange.append(pfx, this);
  101. }
  102. for (Iterator it = getChildNodes(); (it != null) && it.hasNext();) {
  103. ranges = ((FONode) it.next()).collectDelimitedTextRanges(ranges);
  104. }
  105. if (sfx != 0) {
  106. currentRange.append(sfx, this);
  107. }
  108. }
  109. return ranges;
  110. }
  111. }