1 51 package org.apache.fop.fo.expr; 52 53 import org.apache.fop.fo.Property; 54 import org.apache.fop.fo.ColorTypeProperty; 55 import org.apache.fop.datatypes.ColorType; 56 import org.apache.fop.datatypes.PercentBase; 57 58 class RGBColorFunction extends FunctionBase { 59 public int nbArgs() { 60 return 3; 61 } 62 63 68 public PercentBase getPercentBase() { 69 return new RGBPercentBase(); 70 } 71 72 public Property eval(Property[] args, 73 PropertyInfo pInfo) throws PropertyException { 74 float[] cfvals = new float[3]; for (int i = 0; i < 3; i++) { 79 Number cval = args[i].getNumber(); 80 if (cval == null) { 81 throw new PropertyException("Argument to rgb() must be a Number"); 82 } 83 float colorVal = cval.floatValue() / 255f; 84 if (colorVal < 0.0 || colorVal > 255.0) { 85 throw new PropertyException("Arguments to rgb() must normalize to the range 0 to 1"); 86 } 87 cfvals[i] = colorVal; 88 } 89 return new ColorTypeProperty(new ColorType(cfvals[0], cfvals[1], 90 cfvals[2])); 91 92 } 93 94 static class RGBPercentBase implements PercentBase { 95 public int getDimension() { 96 return 0; 97 } 98 99 public double getBaseValue() { 100 return 255f; 101 } 102 103 public int getBaseLength() { 104 return 0; 105 } 106 107 } 108 } 109 | Popular Tags |