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.

Character.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.ColorType;
  12. import org.apache.fop.layout.BlockArea;
  13. import org.apache.fop.layout.*;
  14. import org.apache.fop.layout.inline.InlineArea;
  15. import org.apache.fop.fo.FObj;
  16. import org.apache.fop.layout.FontState;
  17. import org.apache.fop.layout.LineArea;
  18. import org.apache.fop.apps.FOPException;
  19. /**
  20. * this class represents the flow object 'fo:character'. Its use is defined by
  21. * the spec: "The fo:character flow object represents a character that is mapped to
  22. * a glyph for presentation. It is an atomic unit to the formatter.
  23. * When the result tree is interpreted as a tree of formatting objects,
  24. * a character in the result tree is treated as if it were an empty
  25. * element of type fo:character with a character attribute
  26. * equal to the Unicode representation of the character.
  27. * The semantics of an "auto" value for character properties, which is
  28. * typically their initial value, are based on the Unicode codepoint.
  29. * Overrides may be specified in an implementation-specific manner." (6.6.3)
  30. *
  31. */
  32. public class Character extends FObj {
  33. public final static int OK = 0;
  34. public final static int DOESNOT_FIT = 1;
  35. private char characterValue;
  36. public Character(FONode parent) {
  37. super(parent);
  38. }
  39. public Status layout(Area area) throws FOPException {
  40. BlockArea blockArea;
  41. if (!(area instanceof BlockArea)) {
  42. log.warn("currently Character can only be in a BlockArea");
  43. return new Status(Status.OK);
  44. }
  45. blockArea = (BlockArea)area;
  46. boolean textDecoration;
  47. // Common Aural Properties
  48. AuralProps mAurProps = propMgr.getAuralProps();
  49. // Common Border, Padding, and Background Properties
  50. BorderAndPadding bap = propMgr.getBorderAndPadding();
  51. BackgroundProps bProps = propMgr.getBackgroundProps();
  52. // Common Font Properties
  53. //this.fontState = propMgr.getFontState(area.getFontInfo());
  54. // Common Hyphenation Properties
  55. HyphenationProps mHyphProps = propMgr.getHyphenationProps();
  56. // Common Margin Properties-Inline
  57. MarginInlineProps mProps = propMgr.getMarginInlineProps();
  58. // Common Relative Position Properties
  59. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  60. // this.properties.get("alignment-adjust");
  61. // this.properties.get("treat-as-word-space");
  62. // this.properties.get("alignment-baseline");
  63. // this.properties.get("baseline-shift");
  64. // this.properties.get("character");
  65. // this.properties.get("color");
  66. // this.properties.get("dominant-baseline");
  67. // this.properties.get("text-depth");
  68. // this.properties.get("text-altitude");
  69. // this.properties.get("glyph-orientation-horizontal");
  70. // this.properties.get("glyph-orientation-vertical");
  71. // this.properties.get("id");
  72. // this.properties.get("keep-with-next");
  73. // this.properties.get("keep-with-previous");
  74. // this.properties.get("letter-spacing");
  75. // this.properties.get("line-height");
  76. // this.properties.get("line-height-shift-adjustment");
  77. // this.properties.get("score-spaces");
  78. // this.properties.get("suppress-at-line-break");
  79. // this.properties.get("text-decoration");
  80. // this.properties.get("text-shadow");
  81. // this.properties.get("text-transform");
  82. // this.properties.get("word-spacing");
  83. // color properties
  84. ColorType c = this.properties.get("color").getColorType();
  85. float red = c.red();
  86. float green = c.green();
  87. float blue = c.blue();
  88. int whiteSpaceCollapse =
  89. this.properties.get("white-space-collapse").getEnum();
  90. int wrapOption = ((FObj)this.parent).properties.get("wrap-option").getEnum();
  91. int tmp = this.properties.get("text-decoration").getEnum();
  92. if (tmp == org.apache.fop.fo.properties.TextDecoration.UNDERLINE) {
  93. textDecoration = true;
  94. } else {
  95. textDecoration = false;
  96. }
  97. // Character specific properties
  98. characterValue = this.properties.get("character").getCharacter();
  99. // initialize id
  100. String id = this.properties.get("id").getString();
  101. blockArea.getIDReferences().initializeID(id, blockArea);
  102. LineArea la = blockArea.getCurrentLineArea();
  103. if (la == null) {
  104. return new Status(Status.AREA_FULL_NONE);
  105. }
  106. la.changeFont(propMgr.getFontState(area.getFontInfo()));
  107. la.changeColor(red, green, blue);
  108. la.changeWrapOption(wrapOption);
  109. la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
  110. blockArea.setupLinkSet(this.getLinkSet());
  111. int result = la.addCharacter(characterValue, this.getLinkSet(),
  112. textDecoration);
  113. if (result == Character.DOESNOT_FIT) {
  114. la = blockArea.createNextLineArea();
  115. if (la == null) {
  116. return new Status(Status.AREA_FULL_NONE);
  117. }
  118. la.changeFont(propMgr.getFontState(area.getFontInfo()));
  119. la.changeColor(red, green, blue);
  120. la.changeWrapOption(wrapOption);
  121. la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
  122. blockArea.setupLinkSet(this.getLinkSet());
  123. la.addCharacter(characterValue, this.getLinkSet(),
  124. textDecoration);
  125. }
  126. return new Status(Status.OK);
  127. }
  128. public CharIterator charIterator() {
  129. return new OneCharIterator(characterValue);
  130. // But what it the character is ignored due to white space handling?
  131. }
  132. }