Return-Path: Delivered-To: apmail-xmlgraphics-general-archive@www.apache.org Received: (qmail 46602 invoked from network); 11 Sep 2006 15:25:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Sep 2006 15:25:59 -0000 Received: (qmail 8597 invoked by uid 500); 11 Sep 2006 15:25:59 -0000 Mailing-List: contact general-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@xmlgraphics.apache.org Delivered-To: mailing list general@xmlgraphics.apache.org Delivered-To: moderator for general@xmlgraphics.apache.org Received: (qmail 889 invoked by uid 99); 11 Sep 2006 15:22:03 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of berger.max@gmail.com designates 64.233.166.180 as permitted sender) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-pgp-agent:x-mailer:sender; b=mur26d0Inf7+KRtFCFNImJNdpiUCQgYhRfjJ6tBqOOsSLLgNlVKH0p2Dr22aJrJvK3jUk0HqgfdlS58pVt0nbo+R7GoBTBaYI/pWNsmkY/Vhj9Nojoym/9OHwwAfzpPhkQLE/l9lHhWDMT6hKMB8684aibh4hEbfi2aMvrymfDo= Mime-Version: 1.0 (Apple Message framework v752.2) In-Reply-To: <20060910135639.BE24.DEV@jeremias-maerki.ch> References: <20060910135639.BE24.DEV@jeremias-maerki.ch> Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-3--707728658" Message-Id: Content-Transfer-Encoding: 7bit From: Max Berger Subject: Re: [PATCH] implementation of drawString(AttributedCharIterator,...) for AbstractGraphics2D Date: Mon, 11 Sep 2006 10:21:37 -0500 To: general@xmlgraphics.apache.org X-Pgp-Agent: GPGMail 1.1.2 (Tiger) X-Mailer: Apple Mail (2.752.2) Sender: Max Berger X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Apple-Mail-3--707728658 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Jeremias, developers, strange. My attachments must have been removed. I'll send it inline (at the very bottom of this mail) Max Berger e-mail: max@berger.name -- PGP/GnuPG ID: E81592BC Print: F489F8759D4132923EC4 BC7E072AB73AE81592BC For information about me or my projects please see http:// max.berger.name On Sep 10, 2006, at 6:59 AM, Jeremias Maerki wrote: > There's no Bugzilla for XML Graphics Commons, yet. So you were > right to > send the patch here in this case. However, I did not find any patches > attached to your post. > > On 09.09.2006 10:48:00 Max Berger wrote: >> Dear xml-commons developers, >> >> as I am unable to find an issues database for xml-commons I'll send >> the patch here, Is there an issues db for commons? If so, where is >> the link to it? >> >> This patch implements the drawString >> (AttributesCharacterIterator,float,float) in Abstract2DGraphics using >> TextLayout (shamelessly stolen this idea from batik 1.6). It removes >> the incomplete implementation in PSGraphics2D. -------------- drawStringAttributed.patch Index: src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java =================================================================== --- src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (revision 441726) +++ src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java (working copy) @@ -678,66 +678,6 @@ } /** - * Renders the text of the specified iterator, using the - * Graphics2D context's current Paint. The - * iterator must specify a font - * for each character. The baseline of the - * first character is at position (xy) in the - * User Space. - * The rendering attributes applied include the Clip, - * Transform, Paint, and - * Composite attributes. - * For characters in script systems such as Hebrew and Arabic, - * the glyphs can be rendered from right to left, in which case the - * coordinate supplied is the location of the leftmost character - * on the baseline. - * @param iterator the iterator whose text is to be rendered - * @param x the x-coordinate where the iterator's text is to be - * rendered - * @param y the y-coordinate where the iterator's text is to be - * rendered - * @see #setPaint - * @see java.awt.Graphics#setColor - * @see #setTransform - * @see #setComposite - * @see #setClip - */ - public void drawString(AttributedCharacterIterator iterator, float x, - float y) { - preparePainting(); - System.err.println("NYI: drawString (AttributedCharacterIterator)"); - /* - try { - gen.writeln("BT"); - Shape imclip = getClip(); - writeClip(imclip); - establishColor(getColor()); - - AffineTransform trans = getTransform(); - trans.translate(x, y); - double[] vals = new double[6]; - trans.getMatrix(vals); - - for (char ch = iterator.first(); ch != CharacterIterator.DONE; - ch = iterator.next()) { - //Map attr = iterator.getAttributes(); - - gen.writeln(gen.formatDouble(vals[0]) + " " - + gen.formatDouble(vals[1]) + " " - + gen.formatDouble(vals[2]) + " " - + gen.formatDouble(vals[3]) + " " - + gen.formatDouble(vals[4]) + " " - + gen.formatDouble(vals[5]) + " " - + gen.formatDouble(vals[6]) + " Tm [" + ch - + "]"); - } - gen.writeln("ET"); - } catch (IOException ioe) { - handleIOException(ioe); - }*/ - } - - /** * Fills the interior of a Shape using the settings of the * Graphics2D context. The rendering attributes applied * include the Clip, Transform, Index: src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java =================================================================== --- src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java (revision 441726) +++ src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java (working copy) @@ -32,6 +32,7 @@ import java.awt.Stroke; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; +import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; @@ -76,6 +77,11 @@ * Text handling strategy. */ protected boolean textAsShapes = false; + + /** + * Protection agains infinite recursion + */ + protected boolean inPossibleRecursion = false; /** * @param textAsShapes if true, all text is turned into shapes in the @@ -607,6 +613,31 @@ public void drawString(String str, int x, int y){ drawString(str, (float)x, (float)y); } + + /** + * Generic implementation for drawing attributed strings using TextLayout. + * + * @param iterator - + * the iterator whose text is to be rendered + * @param x + * the x coordinate where the iterator's text is to be rendered + * @param y + * the y coordinate where the iterator's text is to be rendered + * @see java.awt.Graphics2D#drawString (java.text.AttributedCharacterIterator, + * float, float) + */ + public void drawString(AttributedCharacterIterator iterator, float x, + float y) { + if (inPossibleRecursion) { + System.err + .println("Called itself: drawString (AttributedCharacterIterator)"); + } else { + inPossibleRecursion = true; + TextLayout layout = new TextLayout(iterator, getFontRenderContext()); + layout.draw(this, x, y); + inPossibleRecursion = false; + } + } /** -------------- PSTest.java package name.berger.max.test.xmlgraphics; import java.awt.font.TextAttribute; import java.io.FileOutputStream; import java.io.IOException; import java.text.AttributedString; import org.apache.xmlgraphics.java2d.GraphicContext; import org.apache.xmlgraphics.java2d.ps.PSDocumentGraphics2D; public class PSTest { /** * @param args */ public static void main(String[] args) { try { PSDocumentGraphics2D doc = new PSDocumentGraphics2D(false, new FileOutputStream("/tmp/test.ps"), 612, 792); doc.setGraphicContext(new GraphicContext()); doc.drawString("This is a regular text", 72, 72); AttributedString aString = new AttributedString( "This is a special Text"); aString.addAttribute(TextAttribute.FAMILY, "SansSerif"); aString.addAttribute(TextAttribute.FAMILY, "Serif", 10, 17); doc.drawString(aString.getIterator(), 72, 144); doc.finish(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } -------------- --Apple-Mail-3--707728658 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (Darwin) iD8DBQFFBX8BByq3OugVkrwRArujAJ46TCEi0x7QQaWDoKDDlxyyj6td+wCfapc0 Q/KCc7fNJ7PB6pVjzC4i6Ps= =GHIB -----END PGP SIGNATURE----- --Apple-Mail-3--707728658--