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.

SVGUtil.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.svg;
  19. import java.awt.geom.AffineTransform;
  20. import org.apache.fop.render.intermediate.IFUtil;
  21. /**
  22. * This class provides utility methods for generating SVG.
  23. */
  24. public final class SVGUtil {
  25. private SVGUtil() {
  26. }
  27. /**
  28. * Formats a length in millipoints as a point value.
  29. * @param mpt the length in millipoints
  30. * @return the formatted value in points
  31. */
  32. public static String formatMptToPt(int mpt) {
  33. return Float.toString(mpt / 1000f);
  34. }
  35. /**
  36. * Formats an array of lengths in millipoints as point values.
  37. * @param lengths the lengths in millipoints
  38. * @return the formatted array in points
  39. */
  40. public static String formatMptArrayToPt(int[] lengths) {
  41. return IFUtil.toString(lengths);
  42. }
  43. /**
  44. * Formats a transformation matrix in millipoints with values as points.
  45. * @param transform the transformation matrix in millipoints
  46. * @return the formatted matrix in points
  47. */
  48. public static String formatAffineTransformMptToPt(AffineTransform transform) {
  49. AffineTransform scaled = new AffineTransform(transform);
  50. scaled.setToTranslation(
  51. transform.getTranslateX() / 1000,
  52. transform.getTranslateY() / 1000);
  53. return IFUtil.toString(scaled);
  54. }
  55. /**
  56. * Formats an array of transformation matrices in millipoints with values as points.
  57. * @param transforms the transformation matrices in millipoints
  58. * @return the formatted matrices in points
  59. */
  60. public static String formatAffineTransformsMptToPt(AffineTransform[] transforms) {
  61. StringBuffer sb = new StringBuffer();
  62. for (int i = 0, c = transforms.length; i < c; i++) {
  63. if (i > 0) {
  64. sb.append(' ');
  65. }
  66. sb.append(formatAffineTransformMptToPt(transforms[i]));
  67. }
  68. return sb.toString();
  69. }
  70. }