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.

PercentLength.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 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.datatypes;
  8. import org.apache.fop.fo.expr.Numeric;
  9. /**
  10. * a percent specified length quantity in XSL
  11. */
  12. public class PercentLength extends Length {
  13. private double factor;
  14. private PercentBase lbase = null;
  15. /**
  16. * construct an object based on a factor (the percent, as a
  17. * a factor) and an object which has a method to return the
  18. * Length which provides the "base" for this calculation.
  19. */
  20. public PercentLength(double factor) {
  21. this(factor, null);
  22. }
  23. public PercentLength(double factor, PercentBase lbase) {
  24. this.factor = factor;
  25. this.lbase = lbase;
  26. }
  27. public void setBaseLength(PercentBase lbase) {
  28. this.lbase = lbase;
  29. }
  30. public PercentBase getBaseLength() {
  31. return this.lbase;
  32. }
  33. /**
  34. * Return the computed value in millipoints. This assumes that the
  35. * base length has been resolved to an absolute length value.
  36. */
  37. protected void computeValue() {
  38. setComputedValue((int)(factor * (double)lbase.getBaseLength()));
  39. }
  40. public double value() {
  41. return factor;
  42. }
  43. public String toString() {
  44. // return the factor as a percent
  45. // What about the base value?
  46. return (new Double(factor * 100.0).toString()) + "%";
  47. }
  48. public Numeric asNumeric() {
  49. return new Numeric(this);
  50. }
  51. }