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.

PSFunction.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.ps.svg;
  19. import java.io.UnsupportedEncodingException;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import org.apache.fop.render.shading.Function;
  23. import org.apache.fop.render.shading.FunctionPattern;
  24. public class PSFunction extends Function {
  25. /**
  26. * Creates a Postscript function dictionary
  27. * @param theFunctionType The function type (0 = Sampled, 2 = Exponential
  28. * Interpolation, 3 = Stitching)
  29. * @param theDomain The function domain
  30. * @param theRange Range used for clipping
  31. * @param theFunctions An array of sub-functions such as determining the
  32. * colour values used in a gradient.
  33. * @param theBounds Bounds determines where each boundary exists for whatever
  34. * the function is mean't. In a gradient case, it would be the point between
  35. * colours.
  36. * @param theEncode The function encoding
  37. */
  38. public PSFunction(int theFunctionType, List<Double> theDomain,
  39. List<Double> theRange, List<Function> theFunctions,
  40. List<Double> theBounds, List<Double> theEncode) {
  41. super(theFunctionType, theDomain, theRange, theFunctions, theBounds, theEncode);
  42. }
  43. /**
  44. * Creates a Postscript function dictionary
  45. * @param theFunctionType The function type (0 = Sampled, 2 = Exponential
  46. * Interpolation, 3 = Stitching)
  47. * @param theDomain The function domain
  48. * @param theRange Range used for clipping
  49. * @param theCZero In a gradient, this would be the first colour
  50. * @param theCOne In a gradient, this would be the second colour
  51. * @param theInterpolationExponentN Determines the number of values
  52. * the function returns.
  53. */
  54. public PSFunction(int theFunctionType, List<Double> theDomain,
  55. List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
  56. double theInterpolationExponentN) {
  57. super(theFunctionType, theDomain, theRange, theCZero, theCOne, theInterpolationExponentN);
  58. }
  59. /**
  60. * Outputs the function to a byte array
  61. */
  62. public byte[] toByteString() {
  63. FunctionPattern pattern = new FunctionPattern(this);
  64. try {
  65. List<String> functionsStrings = new ArrayList<String>(getFunctions().size());
  66. for (Function f : getFunctions()) {
  67. functionsStrings.add(new String(((PSFunction) f).toByteString(), "UTF-8"));
  68. }
  69. return pattern.toWriteableString(functionsStrings).getBytes("UTF-8");
  70. } catch (UnsupportedEncodingException ex) {
  71. //This should have been made an enum type to avoid throwing exceptions.
  72. return new byte[0];
  73. }
  74. }
  75. }