xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r446632 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java status.xml
Date Fri, 15 Sep 2006 15:28:11 GMT
Author: jeremias
Date: Fri Sep 15 08:28:11 2006
New Revision: 446632

URL: http://svn.apache.org/viewvc?view=rev&rev=446632
Log:
Default implementation for AbstractGraphics2D.drawText(ACI, float, float) so PSGraphics2D
supports painting text using the AttributedCharacterIterator.
Submitted by: Max Berger <max.at.berger.name>

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java?view=diff&rev=446632&r1=446631&r2=446632
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/AbstractGraphics2D.java
Fri Sep 15 08:28:11 2006
@@ -1,21 +1,22 @@
 /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
+/* $Id$ */
 
- */
 package org.apache.xmlgraphics.java2d;
 
 import java.awt.AlphaComposite;
@@ -32,6 +33,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;
@@ -78,6 +80,11 @@
     protected boolean textAsShapes = false;
 
     /**
+     * Protection agains infinite recursion
+     */
+    protected boolean inPossibleRecursion = false;
+
+    /**
      * @param textAsShapes if true, all text is turned into shapes in the
      *        convertion. No text is output.
      *
@@ -608,6 +615,25 @@
         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;
+        }
+    }
 
     /**
      * Draws the text given by the specified iterator, using this

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java?view=diff&rev=446632&r1=446631&r2=446632
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
Fri Sep 15 08:28:11 2006
@@ -20,7 +20,6 @@
 package org.apache.xmlgraphics.java2d.ps;
 
 //Java
-import java.text.AttributedCharacterIterator;
 import java.awt.AlphaComposite;
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -675,66 +674,6 @@
         } catch (IOException ioe) {
             handleIOException(ioe);
         }
-    }
-
-    /**
-     * Renders the text of the specified iterator, using the
-     * <code>Graphics2D</code> context's current <code>Paint</code>.
The
-     * iterator must specify a font
-     * for each character. The baseline of the
-     * first character is at position (<i>x</i>,&nbsp;<i>y</i>)
in the
-     * User Space.
-     * The rendering attributes applied include the <code>Clip</code>,
-     * <code>Transform</code>, <code>Paint</code>, and
-     * <code>Composite</code> 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);
-        }*/
     }
 
     /**

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?view=diff&rev=446632&r1=446631&r2=446632
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Fri Sep 15 08:28:11 2006
@@ -28,6 +28,10 @@
 
   <changes>
     <release version="Trunk" date="n/a">
+      <action context="Code" dev="JM" type="add" due-to="Max Berger">
+        Default implementation for AbstractGraphics2D.drawText(ACI, float, float) so
+        PSGraphics2D supports painting text using the AttributedCharacterIterator.
+      </action>
       <action context="Code" dev="JM" type="fix">
         Bugfix: The generation of the PostScript setdash command was assuming that
         only integer values can be used but that isn't the case.



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message