vhardy 2002/09/09 06:02:08 Modified: resources/org/apache/batik/apps/rasterizer/resources Messages.properties test-sources/org/apache/batik/apps/rasterizer MainTest.java SVGConverterTest.java sources/org/apache/batik/apps/rasterizer Main.java SVGConverter.java sources/org/apache/batik/apps/svgbrowser Application.java JSVGViewerFrame.java Main.java PreferenceDialog.java sources/org/apache/batik/transcoder SVGAbstractTranscoder.java test-resources/org/apache/batik/transcoder/image unitTesting.xml Added: test-references/samples/tests/spec/styling defaultFontFamilyArial.png defaultFontFamilyTimes.png samples/tests/spec/styling defaultFontFamily.svg test-sources/org/apache/batik/transcoder/image DefaultFontFamilyTest.java Log: Adding support for default font-family option in applications (rasterizer and viewer). In the rasterizer, there is now a font-family command line option which lets the user define the default value for the font-family CSS property. In the Squiggle browser, the default font-family value is an option read from the preference file (the key is preference.key.default.font.family). There is no user interface for modifying this value at this time. That default font-family value is used when there is no specified font-family property for text content. Revision Changes Path 1.1 xml-batik/test-references/samples/tests/spec/styling/defaultFontFamilyArial.png <<Binary file>> 1.1 xml-batik/test-references/samples/tests/spec/styling/defaultFontFamilyTimes.png <<Binary file>> 1.1 xml-batik/samples/tests/spec/styling/defaultFontFamily.svg Index: defaultFontFamily.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" viewBox="0 0 450 500"> <text x="50%" y="50%" font-size="30" text-anchor="middle">Default font-family</text> </svg> 1.10 +9 -0 xml-batik/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties Index: Messages.properties =================================================================== RCS file: /home/cvs/xml-batik/resources/org/apache/batik/apps/rasterizer/resources/Messages.properties,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Messages.properties 4 Sep 2002 19:20:21 -0000 1.9 +++ Messages.properties 9 Sep 2002 13:02:06 -0000 1.10 @@ -86,6 +86,9 @@ -cssUser <userStylesheet> \n \ \tCSS user stylesheet URI to apply to converted SVG documents \n \ \tin addition to any other referened or embeded stylesheets. \n \ + -font-family <defaultFontFamily> \n \ +\tValue used as a default when no font-family value \n \ +\tis specified. \n \ -lang <userLanguage> \n \ \tUser language to use when converting SVG documents.\n \ -q <quality> \n \ @@ -159,6 +162,12 @@ converted.\n \ Example: -cssMedia projection \n \ Default: none (which means that the "screen" media will be used. + +Main.cl.option.default.font.family.description = \ +-font-family <defaultValue> Value used as a default when no font-family value \n \ + is specified.\n \ +Example: -font-family "Times, Comic Sans MS" +Default: "Arial, Helvetica, sans-serif" Main.cl.option.cssAlternate.description = \ -cssAlternate <alternate> CSS alternate stylesheet to use when converting the source \n \ 1.8 +29 -1 xml-batik/test-sources/org/apache/batik/apps/rasterizer/MainTest.java Index: MainTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/apps/rasterizer/MainTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MainTest.java 5 Sep 2002 15:58:34 -0000 1.7 +++ MainTest.java 9 Sep 2002 13:02:06 -0000 1.8 @@ -248,6 +248,30 @@ addTest(t); t.setId("MainConfigTest.cssMedia"); + + t = new MainConfigTest("-font-family Arial, Comic Sans MS"){ + public TestReport validate(SVGConverter c){ + String fontFamily = c.getDefaultFontFamily(); + String eFontFamily = "Arial, Comic Sans MS"; + if(eFontFamily.equals(fontFamily)){ + return reportSuccess(); + } else { + return reportError("-font-family", eFontFamily, fontFamily); + } + } + + String[] makeArgsArray(String args) { + return new String[] {"-font-family", + "Arial, Comic Sans MS"}; + } + }; + + addTest(t); + t.setId("MainConfigTest.fontFamily"); + + + + t = new MainConfigTest("-cssAlternate myAlternateStylesheet"){ public TestReport validate(SVGConverter c){ String alternate = c.getAlternateStylesheet(); @@ -415,6 +439,10 @@ t = new MainConfigErrorTest("-cssMedia", "hello.svg -cssMedia"); addTest(t); t.setId("MainConfigErrorTest.mediaType"); + + t = new MainConfigErrorTest("-font-family", "hello.svg -font-family"); + addTest(t); + t.setId("MainConfigErrorTest.font-family"); t = new MainConfigErrorTest("-cssAlternate", "hello.svg -cssAlternate"); addTest(t); 1.15 +11 -1 xml-batik/test-sources/org/apache/batik/apps/rasterizer/SVGConverterTest.java Index: SVGConverterTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/apps/rasterizer/SVGConverterTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- SVGConverterTest.java 5 Sep 2002 15:58:34 -0000 1.14 +++ SVGConverterTest.java 9 Sep 2002 13:02:06 -0000 1.15 @@ -125,6 +125,16 @@ t.setId("HintsConfigTest.KEY_MEDIA"); t = new HintsConfigTest(new Object[][]{ + {ImageTranscoder.KEY_DEFAULT_FONT_FAMILY, "Times"}}){ + protected void deltaConfigure(SVGConverter c){ + c.setDefaultFontFamily("Times"); + } + }; + + addTest(t); + t.setId("HintsConfigTest.KEY_DEFAULT_FONT_FAMILY"); + + t = new HintsConfigTest(new Object[][]{ {ImageTranscoder.KEY_ALTERNATE_STYLESHEET, "myStyleSheet"}}){ protected void deltaConfigure(SVGConverter c){ c.setAlternateStylesheet("myStyleSheet"); 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/DefaultFontFamilyTest.java Index: DefaultFontFamilyTest.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.Map; import java.util.HashMap; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; /** * Test the ImageTranscoder with the KEY_DEFAULT_FONT_FAMILY transcoding hint. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> * @version $Id: DefaultFontFamilyTest.java,v 1.1 2002/09/09 13:02:07 vhardy Exp $ */ public class DefaultFontFamilyTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** The default font-family to use. */ protected String defaultFontFamily; /** * Constructs a new <tt>DefaultFontFamilyTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image * @param defaultFontFamily the default font-family to use */ public DefaultFontFamilyTest(String inputURI, String refImageURI, String defaultFontFamily) { this.inputURI = inputURI; this.refImageURI = refImageURI; this.defaultFontFamily = defaultFontFamily; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { return new TranscoderInput(resolveURL(inputURI).toString()); } /** * Creates a Map that contains additional transcoding hints. */ protected Map createTranscodingHints() { Map hints = new HashMap(3); hints.put(ImageTranscoder.KEY_DEFAULT_FONT_FAMILY, defaultFontFamily); return hints; } /** * Returns the reference image for this test. */ protected byte [] getReferenceImageData() { return createBufferedImageData(resolveURL(refImageURI)); } } 1.24 +23 -1 xml-batik/sources/org/apache/batik/apps/rasterizer/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/rasterizer/Main.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Main.java 4 Sep 2002 19:20:21 -0000 1.23 +++ Main.java 9 Sep 2002 13:02:07 -0000 1.24 @@ -353,6 +353,16 @@ = Messages.get("Main.cl.option.media.type.description", "No description"); /** + * Option to specify the default value for the font-family + * CSS property when converting the SVG image + */ + public static String CL_OPTION_DEFAULT_FONT_FAMILY + = Messages.get("Main.cl.option.default.font.family", "-font-family"); + + public static String CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION + = Messages.get("Main.cl.option.default.font.family.description", "No description"); + + /** * Option to specify the CSS alternate stylesheet when * converting the SVG images */ @@ -578,6 +588,18 @@ return CL_OPTION_MEDIA_TYPE_DESCRIPTION; } }); + + optionMap.put(CL_OPTION_DEFAULT_FONT_FAMILY, + new SingleValueOptionHandler() { + public void handleOption(String optionValue, + SVGConverter c){ + c.setDefaultFontFamily(optionValue); + } + + public String getOptionDescription(){ + return CL_OPTION_DEFAULT_FONT_FAMILY_DESCRIPTION; + } + }); optionMap.put(CL_OPTION_ALTERNATE_STYLESHEET, new SingleValueOptionHandler(){ 1.17 +22 -1 xml-batik/sources/org/apache/batik/apps/rasterizer/SVGConverter.java Index: SVGConverter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/rasterizer/SVGConverter.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- SVGConverter.java 4 Sep 2002 19:20:21 -0000 1.16 +++ SVGConverter.java 9 Sep 2002 13:02:07 -0000 1.17 @@ -253,6 +253,9 @@ /** Media type for which the SVG image should be rendered */ protected String mediaType = null; + /** Default value for the font-family when it is unspecified */ + protected String defaultFontFamily = null; + /** Alternate stylesheet for which should be applied to the SVG */ protected String alternateStylesheet = null; @@ -481,6 +484,19 @@ } /** + * Sets the <tt>defaultFontFamily</tt> value. This value controls + * the default value for the font-family CSS property when that + * property is unspecified. + */ + public void setDefaultFontFamily(String defaultFontFamily) { + this.defaultFontFamily = defaultFontFamily; + } + + public String getDefaultFontFamily() { + return defaultFontFamily; + } + + /** * Sets the <tt>alternateStyleSheet</tt> value. This value * controls the CSS alternate stylesheet to select in the * rendered SVG file(s). It may be null, in which case no alternate @@ -781,6 +797,11 @@ // Set CSS Media if (mediaType != null){ map.put(ImageTranscoder.KEY_MEDIA, mediaType); + } + + // Set default font-family + if (defaultFontFamily != null) { + map.put(ImageTranscoder.KEY_DEFAULT_FONT_FAMILY, defaultFontFamily); } // Set alternateStylesheet 1.10 +7 -1 xml-batik/sources/org/apache/batik/apps/svgbrowser/Application.java Index: Application.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/Application.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Application.java 18 Jun 2002 12:27:11 -0000 1.9 +++ Application.java 9 Sep 2002 13:02:07 -0000 1.10 @@ -66,6 +66,12 @@ String getUserStyleSheetURI(); /** + * Returns the default value for the CSS + * "font-family" property + */ + String getDefaultFontFamily(); + + /** * Returns the CSS media to use. * @return empty string if no CSS media was specified. */ 1.87 +2 -2 xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Index: JSVGViewerFrame.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v retrieving revision 1.86 retrieving revision 1.87 diff -u -r1.86 -r1.87 --- JSVGViewerFrame.java 5 Sep 2002 12:58:18 -0000 1.86 +++ JSVGViewerFrame.java 9 Sep 2002 13:02:07 -0000 1.87 @@ -2242,7 +2242,7 @@ * Returns the default font family. */ public String getDefaultFontFamily() { - return "Arial, Helvetica, sans-serif"; + return application.getDefaultFontFamily(); } /** 1.43 +18 -1 xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- Main.java 2 Aug 2002 20:26:05 -0000 1.42 +++ Main.java 9 Sep 2002 13:02:07 -0000 1.43 @@ -135,6 +135,12 @@ public static final String URI_SEPARATOR = " "; /** + * Default font-family value. + */ + public static final String DEFAULT_DEFAULT_FONT_FAMILY + = "Arial, Helvetica, sans-serif"; + + /** * SVG initialization file, used to trigger loading of most of * the Batik classes */ @@ -272,6 +278,8 @@ ""); defaults.put(PreferenceDialog.PREFERENCE_KEY_CSS_MEDIA, "screen"); + defaults.put(PreferenceDialog.PREFERENCE_KEY_DEFAULT_FONT_FAMILY, + DEFAULT_DEFAULT_FONT_FAMILY); defaults.put(PreferenceDialog.PREFERENCE_KEY_IS_XML_PARSER_VALIDATING, Boolean.FALSE); defaults.put(PreferenceDialog.PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING, @@ -711,6 +719,15 @@ public String getUserStyleSheetURI() { return preferenceManager.getString (PreferenceDialog.PREFERENCE_KEY_USER_STYLESHEET); + } + + /** + * Returns the default value for the CSS + * "font-family" property + */ + public String getDefaultFontFamily() { + return preferenceManager.getString + (PreferenceDialog.PREFERENCE_KEY_DEFAULT_FONT_FAMILY); } /** 1.18 +4 -1 xml-batik/sources/org/apache/batik/apps/svgbrowser/PreferenceDialog.java Index: PreferenceDialog.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/PreferenceDialog.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- PreferenceDialog.java 2 Aug 2002 00:51:40 -0000 1.17 +++ PreferenceDialog.java 9 Sep 2002 13:02:07 -0000 1.18 @@ -242,6 +242,9 @@ public static final String PREFERENCE_KEY_CSS_MEDIA = "preference.key.cssmedia"; + public static final String PREFERENCE_KEY_DEFAULT_FONT_FAMILY + = "preference.key.default.font.family"; + public static final String PREFERENCE_KEY_PROXY_PORT = "preference.key.proxy.port"; 1.2 +46 -1 xml-batik/sources/org/apache/batik/transcoder/SVGAbstractTranscoder.java Index: SVGAbstractTranscoder.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/transcoder/SVGAbstractTranscoder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SVGAbstractTranscoder.java 5 Jun 2002 21:14:48 -0000 1.1 +++ SVGAbstractTranscoder.java 9 Sep 2002 13:02:07 -0000 1.2 @@ -74,6 +74,12 @@ * @version $Id$ */ public abstract class SVGAbstractTranscoder extends XMLAbstractTranscoder { /** + * Value used as a default for the default font-family hint + */ + public static final String DEFAULT_DEFAULT_FONT_FAMILY + = "Arial, Helvetica, sans-serif"; + + /** * Current area of interest. */ protected Rectangle2D curAOI; @@ -105,6 +111,8 @@ ExtensibleSVGDOMImplementation.getDOMImplementation()); hints.put(KEY_MEDIA, "screen"); + hints.put(KEY_DEFAULT_FONT_FAMILY, + DEFAULT_DEFAULT_FONT_FAMILY); hints.put(KEY_EXECUTE_ONLOAD, Boolean.FALSE); hints.put(KEY_ALLOWED_SCRIPT_TYPES, @@ -365,6 +373,33 @@ = new StringKey(); /** + * The default font-family key. + * + * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1"> + * <TR> + * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH> + * <TD VALIGN="TOP">KEY_DEFAULT_FONT_FAMILY</TD></TR> + * <TR> + * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH> + * <TD VALIGN="TOP">String</TD></TR> + * <TR> + * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH> + * <TD VALIGN="TOP">"Arial, Helvetica, sans-serif"</TD></TR> + * <TR> + * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH> + * <TD VALIGN="TOP">No</TD></TR> + * <TR> + * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH> + * <TD VALIGN="TOP">Controls the default + * value used by the CSS engine for the font-family property + * when that property is unspecified.Specify the media to use with CSS. + * </TD></TR> + * </TABLE> + */ + public static final TranscodingHints.Key KEY_DEFAULT_FONT_FAMILY + = new StringKey(); + + /** * The alternate stylesheet key. * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1"> * <TR> @@ -642,6 +677,16 @@ if (s != null) return s; return super.getMedia(); + } + + /** + * Returns the default font family. + */ + public String getDefaultFontFamily() { + String s = (String)hints.get(KEY_DEFAULT_FONT_FAMILY); + if (s != null) return s; + + return super.getDefaultFontFamily(); } /** 1.2 +27 -1 xml-batik/test-resources/org/apache/batik/transcoder/image/unitTesting.xml Index: unitTesting.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/transcoder/image/unitTesting.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- unitTesting.xml 30 Oct 2001 14:25:56 -0000 1.1 +++ unitTesting.xml 9 Sep 2002 13:02:07 -0000 1.2 @@ -409,6 +409,32 @@ </testGroup> <!-- ================================================================== --> +<!-- KEY_DEFAULT_FONT_FAMILY --> +<!-- ================================================================== --> + +<testGroup id="transcoder.image.hints.fontFamily" class="org.apache.batik.transcoder.image.DefaultFontFamilyTest"> + +<test id="transcoder.image.hints.defaultFontFamily.Arial"> + <arg class="java.lang.String" value="samples/tests/spec/styling/defaultFontFamily.svg" /> + <arg class="java.lang.String" value="test-references/samples/tests/spec/styling/defaultFontFamilyArial.png" /> + <arg class="java.lang.String" value="Arial" /> +</test> + +<test id="transcoder.image.hints.defaultFontFamily.Times"> + <arg class="java.lang.String" value="samples/tests/spec/styling/defaultFontFamily.svg" /> + <arg class="java.lang.String" value="test-references/samples/tests/spec/styling/defaultFontFamilyTimes.png" /> + <arg class="java.lang.String" value="Times" /> +</test> + +<test id="trancoder.image.hints.defaultFontFamily.TotoTimes"> + <arg class="java.lang.String" value="samples/tests/spec/styling/defaultFontFamily.svg" /> + <arg class="java.lang.String" value="test-references/samples/tests/spec/styling/defaultFontFamilyTimes.png" /> + <arg class="java.lang.String" value="toto, Times" /> +</test> + +</testGroup> + +<!-- ================================================================== --> <!-- KEY_ALTERNATE_STYLESHEET --> <!-- ================================================================== -->
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]