You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by cj...@apache.org on 2001/04/03 10:07:56 UTC

cvs commit: xml-batik/sources/org/apache/batik/svggen SVGFont.java SVGGraphics2D.java SVGGraphics2DIOException.java

cjolif      01/04/03 01:07:56

  Modified:    sources/org/apache/batik/svggen SVGFont.java
                        SVGGraphics2D.java SVGGraphics2DIOException.java
  Log:
  small improvment in catching of exception in SVGGraphics2D
  give access to some SVGFont static method from the outside.
  
  Revision  Changes    Path
  1.10      +20 -13    xml-batik/sources/org/apache/batik/svggen/SVGFont.java
  
  Index: SVGFont.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGFont.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SVGFont.java	2001/04/01 18:05:11	1.9
  +++ SVGFont.java	2001/04/03 08:07:55	1.10
  @@ -21,7 +21,7 @@
    * font attributes
    *
    * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: SVGFont.java,v 1.9 2001/04/01 18:05:11 hillion Exp $
  + * @version $Id: SVGFont.java,v 1.10 2001/04/03 08:07:55 cjolif Exp $
    */
   public class SVGFont extends AbstractSVGConverter {
       public static final float EXTRA_LIGHT =
  @@ -142,27 +142,34 @@
           String fontSize = "" + font.getSize();
           String fontWeight = weightToSVG(font);
           String fontStyle = styleToSVG(font);
  -        String fontFamilyStr = font.getFamily();
  -        StringBuffer fontFamily = new StringBuffer("'");
  -        fontFamily.append(fontFamilyStr);
  -        fontFamily.append("'");
  -
  -        fontFamilyStr = fontFamily.toString();
  +        String fontFamilyStr = familtyToSVG(font);
  +        return new SVGFontDescriptor(fontSize, fontWeight,
  +                                     fontStyle, fontFamilyStr);
  +    }
   
  +    /**
  +     * @param font whose family should be converted to an SVG string
  +     *   value.
  +     */
  +    public static String familyToSVG(Font font) {
  +        String fontFamilyStr = font.getFamily();
           String logicalFontFamily =
               (String)logicalFontMap.get(font.getName().toLowerCase());
  -        if(logicalFontFamily != null)
  +        if (logicalFontFamily() != null)
               fontFamilyStr = logicalFontFamily;
  -
  -        return new SVGFontDescriptor(fontSize, fontWeight,
  -                                     fontStyle, fontFamilyStr);
  +        else {
  +            StringBuffer fontFamily = new StringBuffer("'");
  +            fontFamily.append(fontFamilyStr);
  +            fontFamily.append("'");
  +            fontFamilyStr = fontFamily.toString();
  +        }
       }
   
       /**
        * @param font whose style should be converted to an SVG string
        *        value.
        */
  -    private static String styleToSVG(Font font) {
  +    public static String styleToSVG(Font font) {
           Map attrMap = font.getAttributes();
           Float styleValue = (Float)attrMap.get(TextAttribute.POSTURE);
   
  @@ -189,7 +196,7 @@
        *        value. Note that there is loss of precision for
        *        semibold and extrabold.
        */
  -    private static String weightToSVG(Font font) {
  +    public static String weightToSVG(Font font) {
           Map attrMap = font.getAttributes();
           Float weightValue = (Float)attrMap.get(TextAttribute.WEIGHT);
           if(weightValue==null){
  
  
  
  1.14      +13 -5     xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java
  
  Index: SVGGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SVGGraphics2D.java	2001/04/02 23:29:16	1.13
  +++ SVGGraphics2D.java	2001/04/03 08:07:55	1.14
  @@ -44,7 +44,7 @@
    *
    *
    * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: SVGGraphics2D.java,v 1.13 2001/04/02 23:29:16 vhardy Exp $
  + * @version $Id: SVGGraphics2D.java,v 1.14 2001/04/03 08:07:55 cjolif Exp $
    * @see                org.apache.batik.ext.awt.g2d.GraphicContext
    * @see                org.apache.batik.svggen.DOMTreeManager
    * @see                org.apache.batik.svggen.DOMGroupManager
  @@ -275,6 +275,10 @@
               stream(writer, useCss);
               writer.flush();
               writer.close();
  +        } catch (SVGGraphics2DIOException io) {
  +            // this one as already been handled in stream(Writer, boolean)
  +            // method => rethrow it in all cases
  +            throw io;
           } catch (IOException e) {
               generatorCtx.errorHandler.
                   handleError(new SVGGraphics2DIOException(e));
  @@ -336,13 +340,17 @@
   
               XmlWriter.writeXml(svgDocument, writer);
               writer.flush();
  +        } catch (SVGGraphics2DIOException e) {
  +            // this catch prevents from catching an SVGGraphics2DIOException
  +            // and wrapping it again in another SVGGraphics2DIOException
  +            // as would do the second catch (XmlWriter throws SVGGraphics2DIO
  +            // Exception but flush throws IOException)
  +            generatorCtx.errorHandler.
  +                handleError(e);
           } catch (IOException io) {
               generatorCtx.errorHandler.
                   handleError(new SVGGraphics2DIOException(io));
  -        } /*catch (SVGGraphics2DIOException e) {
  -            generatorCtx.errorHandler.
  -                handleError(e);
  -                }*/
  +        }
       }
   
       /**
  
  
  
  1.3       +2 -3      xml-batik/sources/org/apache/batik/svggen/SVGGraphics2DIOException.java
  
  Index: SVGGraphics2DIOException.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2DIOException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SVGGraphics2DIOException.java	2001/04/02 22:23:29	1.2
  +++ SVGGraphics2DIOException.java	2001/04/03 08:07:55	1.3
  @@ -14,7 +14,7 @@
    * Thrown when an SVG Generator method receives an illegal argument in parameter.
    *
    * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
  - * @version $Id: SVGGraphics2DIOException.java,v 1.2 2001/04/02 22:23:29 vhardy Exp $
  + * @version $Id: SVGGraphics2DIOException.java,v 1.3 2001/04/03 08:07:55 cjolif Exp $
    */
   public class SVGGraphics2DIOException extends IOException {
       /** The enclosed exception. */
  @@ -44,8 +44,7 @@
        * @param s the detail message of this exception
        * @param ex the original exception
        */
  -    public SVGGraphics2DIOException(String s,
  -                                                 IOException ex) {
  +    public SVGGraphics2DIOException(String s, IOException ex) {
           super(s);
           embedded = ex;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org