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.

AbstractData.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package org.apache.fop;
  2. import java.awt.Color;
  3. import java.awt.geom.AffineTransform;
  4. import java.io.Serializable;
  5. /**
  6. * A base state data holding object
  7. */
  8. public abstract class AbstractData implements Cloneable, Serializable {
  9. private static final long serialVersionUID = 5208418041189828624L;
  10. /** The current color */
  11. protected Color color = null;
  12. /** The current background color */
  13. protected Color backColor = null;
  14. /** The current font name */
  15. protected String fontName = null;
  16. /** The current font size */
  17. protected int fontSize = 0;
  18. /** The current line width */
  19. protected float lineWidth = 0;
  20. /** The dash array for the current basic stroke (line type) */
  21. protected float[] dashArray = null;
  22. /** The current transform */
  23. protected AffineTransform transform = null;
  24. /**
  25. * Returns a newly create data object
  26. *
  27. * @return a new data object
  28. */
  29. protected abstract AbstractData instantiate();
  30. /**
  31. * Concatenate the given AffineTransform with the current thus creating
  32. * a new viewport. Note that all concatenation operations are logged
  33. * so they can be replayed if necessary (ex. for block-containers with
  34. * "fixed" positioning.
  35. *
  36. * @param at Transformation to perform
  37. */
  38. public void concatenate(AffineTransform at) {
  39. getTransform().concatenate(at);
  40. }
  41. /**
  42. * Get the current AffineTransform.
  43. *
  44. * @return the current transform
  45. */
  46. public AffineTransform getTransform() {
  47. if (transform == null) {
  48. transform = new AffineTransform();
  49. }
  50. return transform;
  51. }
  52. /**
  53. * Sets the current AffineTransform.
  54. */
  55. public void setTransform(AffineTransform baseTransform) {
  56. this.transform = baseTransform;
  57. }
  58. /**
  59. * Resets the current AffineTransform.
  60. */
  61. public void clearTransform() {
  62. transform = new AffineTransform();
  63. }
  64. /**
  65. * Returns the derived rotation from the current transform
  66. *
  67. * @return the derived rotation from the current transform
  68. */
  69. public int getDerivedRotation() {
  70. AffineTransform at = getTransform();
  71. double sx = at.getScaleX();
  72. double sy = at.getScaleY();
  73. double shx = at.getShearX();
  74. double shy = at.getShearY();
  75. int rotation = 0;
  76. if (sx == 0 && sy == 0 && shx > 0 && shy < 0) {
  77. rotation = 270;
  78. } else if (sx < 0 && sy < 0 && shx == 0 && shy == 0) {
  79. rotation = 180;
  80. } else if (sx == 0 && sy == 0 && shx < 0 && shy > 0) {
  81. rotation = 90;
  82. } else {
  83. rotation = 0;
  84. }
  85. return rotation;
  86. }
  87. /** {@inheritDoc} */
  88. public Object clone() {
  89. AbstractData data = instantiate();
  90. data.color = this.color;
  91. data.backColor = this.backColor;
  92. data.fontName = this.fontName;
  93. data.fontSize = this.fontSize;
  94. data.lineWidth = this.lineWidth;
  95. data.dashArray = this.dashArray;
  96. data.transform = new AffineTransform(this.transform);
  97. return data;
  98. }
  99. /** {@inheritDoc} */
  100. public String toString() {
  101. return "color=" + color
  102. + ", backColor=" + backColor
  103. + ", fontName=" + fontName
  104. + ", fontSize=" + fontSize
  105. + ", lineWidth=" + lineWidth
  106. + ", dashArray=" + dashArray
  107. + ", transform=" + transform;
  108. }
  109. }