Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BidiOverride.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 org.xml.sax.Locator;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.fo.FONode;
  22. import org.apache.fop.fo.FObjMixed;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. import org.apache.fop.fo.properties.SpaceProperty;
  26. /**
  27. * Class modelling the fo:bidi-override object.
  28. */
  29. public class BidiOverride extends FObjMixed {
  30. // used for FO validation
  31. private boolean blockOrInlineItemFound = false;
  32. private boolean canHaveBlockLevelChildren = true;
  33. // The value of properties relevant for fo:bidi-override.
  34. // private ToBeImplementedProperty prDirection;
  35. // private ToBeImplementedProperty prLetterSpacing;
  36. private SpaceProperty lineHeight;
  37. // private ToBeImplementedProperty prScoreSpaces;
  38. // private ToBeImplementedProperty prUnicodeBidi;
  39. // Unused but valid items, commented out for performance:
  40. // private CommonAural commonAural;
  41. // private CommonFont commonFont;
  42. // private CommonRelativePosition commonRelativePosition;
  43. // private Color prColor;
  44. // private SpaceProperty prWordSpacing;
  45. // End of property values
  46. /**
  47. * @param parent FONode that is the parent of this object
  48. */
  49. public BidiOverride(FONode parent) {
  50. super(parent);
  51. /* Check to see if this node can have block-level children.
  52. * See validateChildNode() below.
  53. */
  54. int lvlLeader = findAncestor(FO_LEADER);
  55. int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
  56. int lvlInline = findAncestor(FO_INLINE);
  57. int lvlFootnote = findAncestor(FO_FOOTNOTE);
  58. if (lvlLeader > 0) {
  59. if (lvlInCntr < 0 || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
  60. canHaveBlockLevelChildren = false;
  61. }
  62. } else if (lvlInline > 0 && lvlFootnote == (lvlInline + 1)) {
  63. if (lvlInCntr < 0 || (lvlInCntr > 0 && lvlInCntr > lvlInline)) {
  64. canHaveBlockLevelChildren = false;
  65. }
  66. }
  67. }
  68. /**
  69. * {@inheritDoc}
  70. */
  71. public void bind(PropertyList pList) throws FOPException {
  72. // prDirection = pList.get(PR_DIRECTION);
  73. // prLetterSpacing = pList.get(PR_LETTER_SPACING);
  74. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  75. // prScoreSpaces = pList.get(PR_SCORE_SPACES);
  76. // prUnicodeBidi = pList.get(PR_UNICODE_BIDI);
  77. }
  78. /**
  79. * {@inheritDoc}
  80. * XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
  81. * Additionally: "An fo:bidi-override that is a descendant of an fo:leader
  82. * or of the fo:inline child of an fo:footnote may not have block-level
  83. * children, unless it has a nearer ancestor that is an
  84. * fo:inline-container."
  85. */
  86. protected void validateChildNode(Locator loc, String nsURI, String localName)
  87. throws ValidationException {
  88. if (FO_URI.equals(nsURI)) {
  89. if (localName.equals("marker")) {
  90. if (blockOrInlineItemFound) {
  91. nodesOutOfOrderError(loc, "fo:marker",
  92. "(#PCDATA|%inline;|%block;)");
  93. }
  94. } else if (!isBlockOrInlineItem(nsURI, localName)) {
  95. invalidChildError(loc, nsURI, localName);
  96. } else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
  97. invalidChildError(loc, getParent().getName(), nsURI, getName(),
  98. "rule.bidiOverrideContent");
  99. } else {
  100. blockOrInlineItemFound = true;
  101. }
  102. }
  103. }
  104. /**
  105. * @return the "line-height" property.
  106. */
  107. public SpaceProperty getLineHeight() {
  108. return lineHeight;
  109. }
  110. /** {@inheritDoc} */
  111. public String getLocalName() {
  112. return "bidi-override";
  113. }
  114. /**
  115. * {@inheritDoc}
  116. */
  117. public int getNameId() {
  118. return FO_BIDI_OVERRIDE;
  119. }
  120. }