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.

PDFGradientFactory.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. package org.apache.fop.render.shading;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.fop.pdf.PDFDeviceColorSpace;
  21. import org.apache.fop.pdf.PDFFunction;
  22. import org.apache.fop.pdf.PDFPattern;
  23. import org.apache.fop.pdf.PDFShading;
  24. import org.apache.fop.svg.PDFGraphics2D;
  25. public class PDFGradientFactory extends GradientFactory<PDFPattern> {
  26. private final PDFGraphics2D graphics2D;
  27. public PDFGradientFactory(PDFGraphics2D pdfGraphics2D) {
  28. this.graphics2D = pdfGraphics2D;
  29. }
  30. @Override
  31. public Function makeFunction(int functionType, List<Double> theDomain,
  32. List<Double> theRange, List<Function> theFunctions,
  33. List<Double> theBounds, List<Double> theEncode) {
  34. return new Function(functionType, theDomain, theRange, theFunctions, theBounds, theEncode);
  35. }
  36. public Function makeFunction(int functionType, List<Double> theDomain,
  37. List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
  38. double theInterpolationExponentN) {
  39. Function newFunction = new Function(functionType, theDomain, theRange, theCZero,
  40. theCOne, theInterpolationExponentN);
  41. return newFunction;
  42. }
  43. @Override
  44. public Shading makeShading(int theShadingType,
  45. PDFDeviceColorSpace theColorSpace, List<Double> theBackground, List<Double> theBBox,
  46. boolean theAntiAlias, List<Double> theCoords, List<Double> theDomain,
  47. Function theFunction, List<Integer> theExtend) {
  48. List<PDFFunction> pdfFunctions = new ArrayList<PDFFunction>(theFunction.getFunctions().size());
  49. for (Function f : theFunction.getFunctions()) {
  50. pdfFunctions.add(graphics2D.registerFunction(new PDFFunction(f)));
  51. }
  52. PDFFunction pdfFunction = graphics2D.registerFunction(new PDFFunction(theFunction, pdfFunctions));
  53. PDFShading newShading = new PDFShading(theShadingType, theColorSpace, theBackground,
  54. theBBox, theAntiAlias, theCoords, theDomain, pdfFunction, theExtend);
  55. newShading = graphics2D.registerShading(newShading);
  56. return newShading;
  57. }
  58. @Override
  59. public PDFPattern makePattern(int thePatternType, Shading theShading, List theXUID,
  60. StringBuffer theExtGState, List<Double> theMatrix) {
  61. PDFPattern newPattern = new PDFPattern(thePatternType, theShading, theXUID, theExtGState,
  62. theMatrix);
  63. newPattern = graphics2D.registerPattern(newPattern);
  64. return newPattern;
  65. }
  66. }