Package org.apache.batik.ext.awt.g2d

Examples of org.apache.batik.ext.awt.g2d.GraphicContext


     * Sets an non null <code>SVGGeneratorContext</code>.
     */
    private void setGeneratorContext(SVGGeneratorContext generatorCtx) {
        this.generatorCtx = generatorCtx;

        this.gc = new GraphicContext(new AffineTransform());

        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
            generatorCtx.getGraphicContextDefaults();

        if(gcDefaults != null){
View Full Code Here


     * Sets an non null <code>SVGGeneratorContext</code>.
     */
    private void setGeneratorContext(SVGGeneratorContext generatorCtx) {
        this.generatorCtx = generatorCtx;

        this.gc = new GraphicContext(new AffineTransform());

        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
            generatorCtx.getGraphicContextDefaults();

        if(gcDefaults != null){
View Full Code Here

     * Sets an non null <code>SVGGeneratorContext</code>.
     */
    protected void setGeneratorContext(SVGGeneratorContext generatorCtx) {
        this.generatorCtx = generatorCtx;

        this.gc = new GraphicContext(new AffineTransform());

        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
            generatorCtx.getGraphicContextDefaults();

        if(gcDefaults != null){
View Full Code Here

    }

    public void testDOMTreeManager() throws Exception {
        Document domFactory = getDocumentPrototype();

        GraphicContext gc = new GraphicContext(new AffineTransform());
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
        DOMTreeManager domTreeManager
            = new DOMTreeManager(gc,
                                 ctx,
                                 2);

        DOMGroupManager domGroupManager
            = new DOMGroupManager(gc, domTreeManager);

        //
        // Do the following:
        // + Add one rect element
        // + Modify the Paint (modif 1)
        // + Add one ellipse element. Should be under the same group
        // + Modify the Composite (modif 2, ignored, as it does not apply to a group)
        // + Add one circle element. Should be under the same group
        // + Modify the Clip (modif 2bis)
        // + Modify the Transform (modif 3, over limit)
        // + Add one path element: Should be under a new group.
        // + Set the transform to a new transform (new group trigger)
        // + Add a polygon: should be under a new group
        //

        Element rect = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                  SVG_RECT_TAG);
        Element ellipse = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                     SVG_ELLIPSE_TAG);
        Element circle = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                    SVG_CIRCLE_TAG);
        Element path = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                  SVG_PATH_TAG);
        Element polygon = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                     SVG_POLYGON_TAG);

        rect.setAttributeNS(null, SVG_FILL_ATTRIBUTE, SVG_NONE_VALUE);
        polygon.setAttributeNS(null, SVG_STROKE_ATTRIBUTE, SVG_NONE_VALUE);

        domGroupManager.addElement(rect);

        // Modif 1
        gc.setPaint(Color.red);

        // Ellipse element
        domGroupManager.addElement(ellipse);

        // Modif 2
        gc.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, .5f));

        // Circle element
        domGroupManager.addElement(circle);

        // Modif 2bis
        gc.setClip(new Rectangle(30, 30, 60, 60));

        // Modif 3
        gc.translate(45, 45);

        GraphicContext gc2 = (GraphicContext)gc.clone();
        DOMGroupManager domGroupManager2
            = new DOMGroupManager(gc2, domTreeManager);

        // Path element (should be in a new group)
        domGroupManager2.addElement(path);

        // Modify transform
        gc2.setTransform(AffineTransform.getScaleInstance(45, 50));

        // Polygon element (should be in a new group as well).
        domGroupManager2.addElement(polygon);

        //
View Full Code Here

    private void traceFonts(Font fonts[])
        throws Exception {
        Document domFactory = getDocumentPrototype();
        Element group = domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
        SVGFont converter = new SVGFont(getContext(domFactory));
        GraphicContext gc = new GraphicContext(new AffineTransform());

        for(int i=0; i<fonts.length; i++){
            Font font = fonts[i];
            Map attrMap = converter.toSVG(font, gc.getFontRenderContext()).getAttributeMap(null);
            Element textElement = domFactory.createElementNS(SVG_NAMESPACE_URI, SVG_TEXT_TAG);
            Iterator iter = attrMap.keySet().iterator();
            while(iter.hasNext()){
                String attrName = (String)iter.next();
                String attrValue = (String)attrMap.get(attrName);
View Full Code Here

        // b. Modify the value of each of the context attributes
        // c. Dump new list of SVG attributes
        // d. Dump list of defs
        //

        GraphicContext gc = new GraphicContext(new AffineTransform());
        SVGGraphicContextConverter converter =
            new SVGGraphicContextConverter(getContext(domFactory));
        SVGGraphicContext defaultSVGGC = converter.toSVG(gc);
        traceSVGGC(defaultSVGGC, converter);

        // Transform
        gc.translate(40, 40);

        // Paint
        gc.setPaint(new GradientPaint(0, 0, Color.yellow, 200, 200, Color.red));

        // Stroke
        gc.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND,
                                     BasicStroke.JOIN_BEVEL, 40, new float[]{ 4, 5, 6, 7 }, 3));

        // Composite
        gc.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, .25f));

        // Clip
        gc.setClip(new Ellipse2D.Double(20, 30, 40, 50));

        // Hints
        gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // Font
        gc.setFont(new Font("French Script MT", Font.BOLD, 45));

        SVGGraphicContext modifiedSVGGC = converter.toSVG(gc);

        traceSVGGC(modifiedSVGGC, converter);
View Full Code Here

        trace(group, System.out);
    }

    public void testSVGTransform() throws Exception {
        GraphicContext gc = new GraphicContext();
        gc.translate(20, 20);
        gc.rotate(Math.PI/4);
        gc.shear(.5, .5);
        gc.scale(20, 20);

        AffineTransform txf = new AffineTransform();
        txf.translate(60, 60);
        gc.transform(txf);

        String svgTransform = SVGTransform.toSVGTransform(gc);
        System.out.println("SVG Transform: " + svgTransform);

        gc.setTransform(new AffineTransform());
        gc.translate(45, 45);

        svgTransform = SVGTransform.toSVGTransform(gc);
        System.out.println("SVG Transform: " + svgTransform);

        gc.setTransform(new AffineTransform());
        gc.translate(10, 10);
        gc.translate(30, 30);
        gc.scale(2, 3);
        gc.scale(3, 2);
        gc.rotate(Math.PI/2);
        gc.rotate(Math.PI/2);
        gc.translate(100, 100);
        gc.translate(-100, -100);
        gc.scale(2, 2);
        gc.scale(.5, .5);
        gc.rotate(Math.PI/2);
        gc.rotate(-Math.PI/2);

        svgTransform = SVGTransform.toSVGTransform(gc);
        System.out.println("SVG Transform: " + svgTransform);
    }
View Full Code Here

     * Sets an non null <code>SVGGeneratorContext</code>.
     */
    private void setGeneratorContext(SVGGeneratorContext generatorCtx) {
        this.generatorCtx = generatorCtx;

        this.gc = new GraphicContext(new AffineTransform());

        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
            generatorCtx.getGraphicContextDefaults();

        if(gcDefaults != null){
View Full Code Here

     * Sets an non null <code>SVGGeneratorContext</code>.
     */
    protected void setGeneratorContext(SVGGeneratorContext generatorCtx) {
        this.generatorCtx = generatorCtx;

        this.gc = new GraphicContext(new AffineTransform());

        SVGGeneratorContext.GraphicContextDefaults gcDefaults =
            generatorCtx.getGraphicContextDefaults();

        if(gcDefaults != null){
View Full Code Here

    }

    public void testDOMTreeManager() throws Exception {
        Document domFactory = getDocumentPrototype();

        GraphicContext gc = new GraphicContext(new AffineTransform());
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
        DOMTreeManager domTreeManager
            = new DOMTreeManager(gc,
                                 ctx,
                                 2);

        DOMGroupManager domGroupManager
            = new DOMGroupManager(gc, domTreeManager);

        //
        // Do the following:
        // + Add one rect element
        // + Modify the Paint (modif 1)
        // + Add one ellipse element. Should be under the same group
        // + Modify the Composite (modif 2, ignored, as it does not apply to a group)
        // + Add one circle element. Should be under the same group
        // + Modify the Clip (modif 2bis)
        // + Modify the Transform (modif 3, over limit)
        // + Add one path element: Should be under a new group.
        // + Set the transform to a new transform (new group trigger)
        // + Add a polygon: should be under a new group
        //

        Element rect = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                  SVG_RECT_TAG);
        Element ellipse = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                     SVG_ELLIPSE_TAG);
        Element circle = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                    SVG_CIRCLE_TAG);
        Element path = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                  SVG_PATH_TAG);
        Element polygon = domFactory.createElementNS(SVG_NAMESPACE_URI,
                                                     SVG_POLYGON_TAG);

        rect.setAttributeNS(null, SVG_FILL_ATTRIBUTE, SVG_NONE_VALUE);
        polygon.setAttributeNS(null, SVG_STROKE_ATTRIBUTE, SVG_NONE_VALUE);

        domGroupManager.addElement(rect);

        // Modif 1
        gc.setPaint(Color.red);

        // Ellipse element
        domGroupManager.addElement(ellipse);

        // Modif 2
        gc.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, .5f));

        // Circle element
        domGroupManager.addElement(circle);

        // Modif 2bis
        gc.setClip(new Rectangle(30, 30, 60, 60));

        // Modif 3
        gc.translate(45, 45);

        GraphicContext gc2 = (GraphicContext)gc.clone();
        DOMGroupManager domGroupManager2
            = new DOMGroupManager(gc2, domTreeManager);

        // Path element (should be in a new group)
        domGroupManager2.addElement(path);

        // Modify transform
        gc2.setTransform(AffineTransform.getScaleInstance(45, 50));

        // Polygon element (should be in a new group as well).
        domGroupManager2.addElement(polygon);

        //
View Full Code Here

TOP

Related Classes of org.apache.batik.ext.awt.g2d.GraphicContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.