[jboss-user] [JBoss Seam] - Submit: rgb color values for PDF
dustismo
do-not-reply at jboss.com
Tue Apr 10 13:39:46 EDT 2007
Hi,
Not sure what the best method to submit is, but since the code needed is extremely small I thought I would just post it here.
The following will add support for color in the form
| rgb(255,0,0)
| or
| rgb(100%, 0%, 0%)
|
I noticed that hex values seem to work fine, though they are not documented.
here is the code for ITextUtils.java:
| /**
| * return a color value from a string specification.
| */
| public static Color colorValue(String colorName) {
| String clr = colorName.trim().toLowerCase();
| if (clr.startsWith("rgb"))
| return rgbStringToColor(clr);
|
| Color color = colorMap.get(clr);
| if (color == null) {
| color = Color.decode(clr);
| }
| return color;
| }
|
| /*
| * Returns color of the form rgb(r,g,b) or rgb(r,g,b,a)
| * r,g,b,a values can be 0-255 or float values with a '%' sign
| */
| public static Color rgbStringToColor(String rgbString) {
| String rgb[] = rgbString.split(",");
| int r = parseSingleChanel(rgb[0]);
| int g = parseSingleChanel(rgb[1]);
| int b = parseSingleChanel(rgb[2]);
| if (rgb.length != 4)
| return new Color(r,g,b);
| int a = parseSingleChanel(rgb[3]);
| return new Color(r,g,b,a);
| }
|
| public static int parseSingleChanel(String chanel) {
| if (chanel.contains("%")) {
| float percent = Float.parseFloat(chanel.replaceAll("[^0-9\\.]",""));
| return (int)(255 * (percent / 100));
| }
| return Integer.parseInt(chanel.replaceAll("[^0-9]", ""));
| }
|
Hope this is useful,
Dustin
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036068#4036068
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036068
More information about the jboss-user
mailing list