KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > expr > ICCColorFunction


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
18 /* $Id$ */
19  
20 package org.apache.fop.fo.expr;
21 import org.apache.fop.apps.FOUserAgent;
22 import org.apache.fop.fo.pagination.ColorProfile;
23 import org.apache.fop.fo.pagination.Declarations;
24 import org.apache.fop.fo.properties.ColorProperty;
25 import org.apache.fop.fo.properties.Property;
26
27 /**
28  * Implements the rgb-icc() function.
29  */

30 class ICCColorFunction extends FunctionBase {
31     
32     /**
33      * rgb-icc takes a variable number of arguments.
34      * At least 4 should be passed - returns -4
35      * @see org.apache.fop.fo.expr.Function#nbArgs()
36      */

37     public int nbArgs() {
38         return -4;
39     }
40     
41     /** @see org.apache.fop.fo.expr.Function */
42     public Property eval(Property[] args,
43                          PropertyInfo pInfo) throws PropertyException {
44         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
45
46         // Map color profile NCNAME to src from declarations/color-profile element
47
String JavaDoc colorProfileName = args[3].getString();
48         Declarations decls = pInfo.getFO().getRoot().getDeclarations();
49         ColorProfile cp = decls.getColorProfile(colorProfileName);
50         if (cp == null) {
51             PropertyException pe = new PropertyException("The " + colorProfileName
52                     + " color profile was not declared");
53             pe.setPropertyInfo(pInfo);
54             throw pe;
55         }
56         String JavaDoc src = cp.getSrc();
57         
58         // rgb-icc is replaced with fop-rgb-icc which has an extra fifth argument containing the
59
// color profile src attribute as it is defined in the color-profile declarations element.
60
sb.append("fop-rgb-icc(" + args[0]);
61         for (int ix = 1; ix < args.length; ix++) {
62             if (ix == 3) {
63                 sb.append("," + colorProfileName);
64                 sb.append(",\"" + src + "\"");
65             } else {
66                 sb.append("," + args[ix]);
67             }
68         }
69         sb.append(")");
70         FOUserAgent ua = (pInfo == null
71                 ? null
72                 : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent()));
73         return new ColorProperty(ua, sb.toString());
74     }
75
76
77 }
78
Popular Tags