OK. I think my implementation problems are taken care of. Here is a design/architecture question:
What is a good way to implement multiple gradients in the PdfGraphics2D? Options include: 1. Using reflection to identify the relevant properties. This requires knowledge of the classes I intend to support (notably Java 1.6's "LinearGradientPaint" and Vincent Hardy's "GradientPaintExt".) This is hack-ish, but doesn't bloat anything too much. 2. Creating a "setGradient()" method in the Graphics2D, similar to setColor() or setPaint(). This delegates the responsibility of interacting with complex paints to the agents *using* iText. This is the "not my problem" approach. 3. Creating a LinearGradientInfo class, and a clever interface for developers to plug into a Graphics2D. This clever interfaces takes an arbitrary Paint object that iText may not be able to recognize and returns a LinearGradientInfo object that iText can recognize. This is the the most bloat (as far as new classes and public methods are concerned), but most flexible. I'm leaning towards option #1, simply because I don't think many developers have their own flavor of gradient paints to support. If they use multiple-color gradients, it's probably the built-in variety in Java 1.6. Or if nobody else is interested in this change: it may not matter. :) This email is assuming I'm crafting something that other developers may have an interest in working with in the future. Regards, - Jeremy On May 29, 2009, at 9:19 AM, Leonard Rosenthol wrote: > My recommendation is to use a program, such as Adobe Illustrator, > that can create PDFs with multi-colored gradients and then look at > the output. That way you can control the values you want and see > the results. > > Yes, it's all about the functions! > > Leonard > > -----Original Message----- > From: Jeremy Wood [mailto:[email protected]] > Sent: Friday, May 29, 2009 10:46 AM > To: [email protected] > Subject: Re: [iText-questions] Gradients with Multiple Colors > > >> Of course - you can have as many colors as you want (provided they >> are all in the same colorspace). > > Just making sure. :) > >> You will definitely need to read the PDF Reference/ISO 32000-1 in >> order to understand how to encode such things, since it is more >> complex than a simple gradiants. > > Thanks for the reference. I started by exploring section 8.7.4.5.3: > "Type 2 (Axial) Shadings". > > However I couldn't find a way to support more than 2 colors. When two > colors are used, you use "C0" and "C1" to define the color at t=0 and > t=1, but I couldn't figure out how to to introduce n-many colors with > a type 2 function. (I tried using floating points, and also > increasing my domain by a factor of 10 so my dictionary included "C0", > "C5", and "C10" (for example). > > I gave up on this approach, and then turned to section 7.10.4: "Type 3 > (Stitching) Functions". (I'm trying to use a type 2 shading with a > type 3 function.) > > My current new PdfShading method is included below. > > When I fill a rectangle with this shading... the resulting PDF appears > blank. (Based on previous results, I assume this basically means > there is an error parsing it?) > > Soooo... at this point I'm feeling pretty stuck. I don't suppose > anyone has any pointers on what I'm doing wrong? I tried to be > concise in this email, but I could discuss in more detail exactly what > I'm doing if anything is too vague. > > Regards, > - Jeremy > > The following method I added to PdfShading.java to complement the > "simpleAxial" methods: > > public static PdfShading complexAxial(PdfWriter writer, float x0, > float y0, float x1, float y1, Color[] colors,float[] times, boolean > extendStart, boolean extendEnd) { > if(colors.length!=times.length) { > System.err.println("colors.length = "+colors.length); > System.err.println("times.length = "+times.length); > throw new IllegalArgumentException("colors.length must equal > times.length"); > } > for(int a = 1; a<colors.length; a++) { > checkCompatibleColors(colors[0], colors[a]); > } > float[][] colorArrays = new float[colors.length][]; > for(int a = 0; a<colors.length; a++) { > colorArrays[a] = getColorArray(colors[a]); > } > normalize(times); > > PdfFunction[] functions = new PdfFunction[times.length-1]; > float[] encode = new float[functions.length*2]; > for(int a = 0; a<functions.length; a++) { > functions[a] = PdfFunction.type2(writer, > new float[] {0,1}, > null, > colorArrays[a], > colorArrays[a+1], > 1); > encode[2*a+0] = 0; > encode[2*a+1] = 1; > } > float[] bounds = new float[functions.length-1]; > for(int a = 0; a<bounds.length; a++) { > bounds[a] = times[a+1]; > } > > PdfFunction function = PdfFunction.type3(writer, > new float[] {0,1}, > null, > functions, > bounds, > encode); > > return type2(writer, colors[0], new float[]{x0, y0, x1, y1}, > null, function, new boolean[]{extendStart, extendEnd}); > } > > > ------------------------------------------------------------------------------ > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > is a gathering of tech-side developers & brand creativity > professionals. Meet > the minds behind Google Creative Lab, Visual Complexity, Processing, & > iPhoneDevCamp as they present alongside digital heavyweights like > Barbarian > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.1t3xt.com/docs/book.php > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ > > ------------------------------------------------------------------------------ > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > is a gathering of tech-side developers & brand creativity > professionals. Meet > the minds behind Google Creative Lab, Visual Complexity, Processing, & > iPhoneDevCamp as they present alongside digital heavyweights like > Barbarian > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.1t3xt.com/docs/book.php > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ > ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
