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.

Leader.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 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.flow;
  8. // FOP
  9. import org.apache.fop.fo.*;
  10. import org.apache.fop.fo.properties.*;
  11. import org.apache.fop.datatypes.*;
  12. import org.apache.fop.area.inline.InlineArea;
  13. import org.apache.fop.layout.*;
  14. import org.apache.fop.layout.FontState;
  15. import org.apache.fop.apps.FOPException;
  16. import org.apache.fop.layoutmgr.LayoutManager;
  17. import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
  18. import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
  19. import org.apache.fop.layoutmgr.ContentLayoutManager;
  20. import org.apache.fop.layoutmgr.LayoutContext;
  21. import org.apache.fop.layoutmgr.LMiter;
  22. import org.apache.fop.area.MinOptMax;
  23. import org.apache.fop.area.inline.Space;
  24. import org.apache.fop.area.inline.Word;
  25. import org.apache.fop.area.inline.Stretch;
  26. import org.apache.fop.area.inline.InlineParent;
  27. import org.apache.fop.area.inline.FilledArea;
  28. import org.apache.fop.util.CharUtilities;
  29. import org.apache.fop.apps.StructureHandler;
  30. import org.apache.fop.area.Trait;
  31. import java.util.List;
  32. import java.util.ArrayList;
  33. /**
  34. * Implements fo:leader; main property of leader leader-pattern.
  35. * The following patterns are treated: rule, space, dots.
  36. * The pattern use-content is ignored, i.e. it still must be implemented.
  37. */
  38. public class Leader extends FObjMixed {
  39. int ruleStyle;
  40. int ruleThickness;
  41. int leaderPattern;
  42. int patternWidth;
  43. protected FontInfo fontInfo = null;
  44. protected FontState fontState;
  45. protected InlineArea leaderArea = null;
  46. public Leader(FONode parent) {
  47. super(parent);
  48. }
  49. public void addLayoutManager(List list) {
  50. LeafNodeLayoutManager lm = new LeafNodeLayoutManager(this) {
  51. public InlineArea get(LayoutContext context) {
  52. return getInlineArea();
  53. }
  54. protected MinOptMax getAllocationIPD(int refIPD) {
  55. return getAllocIPD(refIPD);
  56. }
  57. };
  58. lm.setAlignment(properties.get("leader-alignment").getEnum());
  59. list.add(lm);
  60. }
  61. protected InlineArea getInlineArea() {
  62. if(leaderArea == null) {
  63. createLeaderArea();
  64. }
  65. return leaderArea;
  66. }
  67. protected void createLeaderArea() {
  68. setup();
  69. if(leaderPattern == LeaderPattern.RULE) {
  70. org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
  71. leader.setRuleStyle(ruleStyle);
  72. leader.setRuleThickness(ruleThickness);
  73. leaderArea = leader;
  74. } else if (leaderPattern == LeaderPattern.SPACE) {
  75. leaderArea = new Space();
  76. } else if(leaderPattern == LeaderPattern.DOTS) {
  77. Word w = new Word();
  78. char dot = '.'; // userAgent.getLeaderDotChar();
  79. w.setWord("" + dot);
  80. w.addTrait(Trait.FONT_NAME, fontState.getFontName());
  81. w.addTrait(Trait.FONT_SIZE,
  82. new Integer(fontState.getFontSize()));
  83. // set offset of dot within inline parent
  84. w.setOffset(fontState.getAscender());
  85. int width = CharUtilities.getCharWidth(dot, fontState);
  86. Space spacer = null;
  87. if(patternWidth > width) {
  88. spacer = new Space();
  89. spacer.setWidth(patternWidth - width);
  90. width = patternWidth;
  91. }
  92. FilledArea fa = new FilledArea();
  93. fa.setUnitWidth(width);
  94. fa.addChild(w);
  95. if(spacer != null) {
  96. fa.addChild(spacer);
  97. }
  98. leaderArea = fa;
  99. } else if(leaderPattern == LeaderPattern.USECONTENT) {
  100. InlineStackingLayoutManager lm;
  101. lm = new InlineStackingLayoutManager(this,
  102. new LMiter(children.listIterator()));
  103. lm.init();
  104. // get breaks then add areas to FilledArea
  105. FilledArea fa = new FilledArea();
  106. ContentLayoutManager clm = new ContentLayoutManager(fa);
  107. lm.setParentLM(clm);
  108. clm.fillArea(lm);
  109. int width = clm.getStackingSize();
  110. Space spacer = null;
  111. if(patternWidth > width) {
  112. spacer = new Space();
  113. spacer.setWidth(patternWidth - width);
  114. width = patternWidth;
  115. }
  116. fa.setUnitWidth(width);
  117. if(spacer != null) {
  118. fa.addChild(spacer);
  119. }
  120. leaderArea = fa;
  121. }
  122. }
  123. public void setStructHandler(StructureHandler st) {
  124. super.setStructHandler(st);
  125. fontInfo = st.getFontInfo();
  126. }
  127. public void setup() {
  128. // Common Accessibility Properties
  129. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  130. // Common Aural Properties
  131. AuralProps mAurProps = propMgr.getAuralProps();
  132. // Common Border, Padding, and Background Properties
  133. BorderAndPadding bap = propMgr.getBorderAndPadding();
  134. BackgroundProps bProps = propMgr.getBackgroundProps();
  135. // Common Font Properties
  136. this.fontState = propMgr.getFontState(fontInfo);
  137. // Common Margin Properties-Inline
  138. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  139. // Common Relative Position Properties
  140. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  141. // this.properties.get("alignment-adjust");
  142. // this.properties.get("alignment-baseline");
  143. // this.properties.get("baseline-shift");
  144. // this.properties.get("color");
  145. // this.properties.get("dominant-baseline");
  146. // this.properties.get("text-depth");
  147. // this.properties.get("text-altitude");
  148. setupID();
  149. // this.properties.get("leader-alignment");
  150. // this.properties.get("leader-length");
  151. // this.properties.get("leader-pattern");
  152. // this.properties.get("leader-pattern-width");
  153. // this.properties.get("rule-style");
  154. // this.properties.get("rule-thickness");
  155. // this.properties.get("letter-spacing");
  156. // this.properties.get("line-height");
  157. // this.properties.get("line-height-shift-adjustment");
  158. // this.properties.get("text-shadow");
  159. // this.properties.get("visibility");
  160. // this.properties.get("word-spacing");
  161. // this.properties.get("z-index");
  162. // color properties
  163. ColorType c = this.properties.get("color").getColorType();
  164. float red = c.red();
  165. float green = c.green();
  166. float blue = c.blue();
  167. // fo:leader specific properties
  168. // determines the pattern of leader; allowed values: space, rule,dots, use-content
  169. leaderPattern = this.properties.get("leader-pattern").getEnum();
  170. switch(leaderPattern) {
  171. case LeaderPattern.SPACE:
  172. // use Space
  173. break;
  174. case LeaderPattern.RULE:
  175. // the following properties only apply
  176. // for leader-pattern = "rule"
  177. ruleThickness =
  178. properties.get("rule-thickness").getLength().mvalue();
  179. ruleStyle = properties.get("rule-style").getEnum();
  180. break;
  181. case LeaderPattern.DOTS:
  182. break;
  183. case LeaderPattern.USECONTENT:
  184. // use inline layout manager to create inline areas
  185. // add the inline parent multiple times until leader full
  186. break;
  187. }
  188. // if leaderPatternWidth = 0 = default = use-font-metric
  189. patternWidth =
  190. this.properties.get("leader-pattern-width").getLength().mvalue();
  191. }
  192. protected MinOptMax getAllocIPD(int ipd) {
  193. // length of the leader
  194. int opt = getLength("leader-length.optimum", ipd);
  195. int min = getLength("leader-length.minimum", ipd);
  196. int max = getLength("leader-length.maximum", ipd);
  197. return new MinOptMax(min, opt, max);
  198. }
  199. protected int getLength(String prop, int dim) {
  200. int length;
  201. Length maxlength = properties.get(prop).getLength();
  202. if(maxlength instanceof PercentLength) {
  203. length = (int)(((PercentLength)maxlength).value()
  204. * dim);
  205. } else {
  206. length = maxlength.mvalue();
  207. }
  208. return length;
  209. }
  210. }