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.

PageScaleAttributes.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.extensions.prepress;
  19. import java.awt.geom.Point2D;
  20. import java.text.MessageFormat;
  21. import org.apache.xmlgraphics.util.QName;
  22. import org.apache.fop.fo.extensions.ExtensionElementMapping;
  23. /**
  24. * This class contains definition of 'scale' FOF's extension attribute for XSL-FO, and provides
  25. * utility method to parse the possible values of this attibute
  26. */
  27. public final class PageScaleAttributes {
  28. /**
  29. * The extension 'scale' attribute for simple-page-master element
  30. */
  31. public static final QName EXT_PAGE_SCALE
  32. = new QName(ExtensionElementMapping.URI, null, "scale");
  33. /**
  34. * Utility classes should not have a public or default constructor
  35. */
  36. private PageScaleAttributes() {
  37. }
  38. /**
  39. * Compute scale parameters from given fox:scale attribute which has format: scaleX [scaleY]
  40. * If scaleY is not defined, it equals scaleX
  41. * @param scale scale attribute, input format: scaleX [scaleY]
  42. * @return the pair of (sx, sy) values
  43. */
  44. public static Point2D.Double getScaleAttributes(String scale) {
  45. final String err = "Extension 'scale' attribute has incorrect value(s): {0}";
  46. if (scale == null) {
  47. return null;
  48. }
  49. Point2D.Double result = null;
  50. try {
  51. String[] scales = scale.split(" ");
  52. if (scales.length > 0) {
  53. result = new Point2D.Double(Double.parseDouble(scales[0]),
  54. Double.parseDouble(scales[0]));
  55. }
  56. if (scales.length > 1) {
  57. result.y = Double.parseDouble(scales[1]);
  58. }
  59. if (result.x <= 0 || result.y <= 0) {
  60. throw new IllegalArgumentException(MessageFormat.format(err, new Object[]{scale}));
  61. }
  62. } catch (NumberFormatException nfe) {
  63. throw new IllegalArgumentException(MessageFormat.format(err, new Object[]{scale}));
  64. }
  65. return result;
  66. }
  67. }