// Path: src/main/java/org/fit/cssbox/misc/Coords.java
// public class Coords
// {
//     /** A difference threshold to consider two coordinates to be equal */ 
//     public static final float COORDS_THRESHOLD = 0.0001f; 
// 
//     /**
//      * Comapres two coordinate values and returns true when they should be considered equal.
//      * @param v1
//      * @param v2
//      * @return
//      */
//     public static boolean eq(float v1, float v2)
//     {
//         return (Math.abs(v1 - v2) < COORDS_THRESHOLD);
//     }
//     
// }


import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import org.fit.cssbox.misc.Coords;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.vutbr.web.css.CSSProperty;
/*
 * CSSStroke.java
 * Copyright (c) 2005-2010 Radek Burget
 *
 * CSSBox is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * CSSBox is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public License
 * along with CSSBox. If not, see <http://www.gnu.org/licenses/>.
 *
 * Created on 9.11.2010, 17:31:58 by burgetr
 */
package org.fit.cssbox.awt;




/**
 * Stroke for drawing the CSS borders.
 * 
 * @author burgetr
 */
public class CSSStroke implements Stroke
{
    private static Logger log = LoggerFactory.getLogger(CSSStroke.class);

    private float width;
    private CSSProperty.BorderStyle style;
    private boolean reverse;
    
    /**
     * Creates a new CSS stroke.
     * @param width Border width
     * @param style Border css style
     * @param reverse Should be true for right and bottom border - used for reversing the shape of 'double' style border.
     */
    public CSSStroke(float width, CSSProperty.BorderStyle style, boolean reverse)
    {
    	this.width = width;
    	this.style = style;
    	this.reverse = reverse;
    }
    
    public Shape createStrokedShape(Shape s)
    {
    	if (s instanceof Line2D.Float)
    	{
    		Line2D.Float l = (Line2D.Float) s;
    		float x1 = l.x1;
    		float y1 = l.y1;
    		float x2 = l.x2;
    		float y2 = l.y2;
// Path: src/main/java/org/fit/cssbox/misc/Coords.java
// public class Coords
// {
//     /** A difference threshold to consider two coordinates to be equal */ 
//     public static final float COORDS_THRESHOLD = 0.0001f; 
// 
//     /**
//      * Comapres two coordinate values and returns true when they should be considered equal.
//      * @param v1
//      * @param v2
//      * @return
//      */
//     public static boolean eq(float v1, float v2)
//     {
//         return (Math.abs(v1 - v2) < COORDS_THRESHOLD);
//     }
//     
// }


// Path: src/main/java/org/fit/cssbox/awt/CSSStroke.java
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import org.fit.cssbox.misc.Coords;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.vutbr.web.css.CSSProperty;

/*
 * CSSStroke.java
 * Copyright (c) 2005-2010 Radek Burget
 *
 * CSSBox is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * CSSBox is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *  
 * You should have received a copy of the GNU Lesser General Public License
 * along with CSSBox. If not, see <http://www.gnu.org/licenses/>.
 *
 * Created on 9.11.2010, 17:31:58 by burgetr
 */
package org.fit.cssbox.awt;




/**
 * Stroke for drawing the CSS borders.
 * 
 * @author burgetr
 */
public class CSSStroke implements Stroke
{
    private static Logger log = LoggerFactory.getLogger(CSSStroke.class);

    private float width;
    private CSSProperty.BorderStyle style;
    private boolean reverse;
    
    /**
     * Creates a new CSS stroke.
     * @param width Border width
     * @param style Border css style
     * @param reverse Should be true for right and bottom border - used for reversing the shape of 'double' style border.
     */
    public CSSStroke(float width, CSSProperty.BorderStyle style, boolean reverse)
    {
    	this.width = width;
    	this.style = style;
    	this.reverse = reverse;
    }
    
    public Shape createStrokedShape(Shape s)
    {
    	if (s instanceof Line2D.Float)
    	{
    		Line2D.Float l = (Line2D.Float) s;
    		float x1 = l.x1;
    		float y1 = l.y1;
    		float x2 = l.x2;
    		float y2 = l.y2;
    		if (Coords.eq(y1, y2) && x2 > x1)