Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.Property;
  9. import org.apache.fop.fo.expr.Numeric;
  10. /**
  11. * a length quantity in XSL
  12. */
  13. public class FixedLength extends Length {
  14. /**
  15. * Set the length given a number of relative units and the current
  16. * font size in base units.
  17. */
  18. public FixedLength(double numRelUnits, int iCurFontSize) {
  19. setComputedValue((int)(numRelUnits * (double)iCurFontSize));
  20. }
  21. /**
  22. * Set the length given a number of units and a unit name.
  23. */
  24. public FixedLength(double numUnits, String units) {
  25. convert(numUnits, units);
  26. }
  27. /**
  28. * set the length as a number of base units
  29. */
  30. public FixedLength(int baseUnits) {
  31. setComputedValue(baseUnits);
  32. }
  33. /**
  34. * Convert the given length to a dimensionless integer representing
  35. * a whole number of base units (milli-points).
  36. */
  37. protected void convert(double dvalue, String unit) {
  38. int assumed_resolution = 1; // points/pixel
  39. if (unit.equals("in")) {
  40. dvalue = dvalue * 72;
  41. } else if (unit.equals("cm")) {
  42. dvalue = dvalue * 28.3464567;
  43. } else if (unit.equals("mm")) {
  44. dvalue = dvalue * 2.83464567;
  45. } else if (unit.equals("pt")) {
  46. dvalue = dvalue;
  47. } else if (unit.equals("pc")) {
  48. dvalue = dvalue * 12;
  49. /*
  50. * } else if (unit.equals("em")) {
  51. * dvalue = dvalue * fontsize;
  52. */
  53. } else if (unit.equals("px")) {
  54. dvalue = dvalue * assumed_resolution;
  55. } else {
  56. dvalue = 0;
  57. //log.error("unknown length unit '" + unit
  58. // + "'");
  59. }
  60. setComputedValue((int)(dvalue * 1000));
  61. }
  62. public Numeric asNumeric() {
  63. return new Numeric(this);
  64. }
  65. }