Blame |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2014 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 or
* version 2 as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
package test.svg;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
* Copyright (C) 2014 steve
* <p/>
* Created by steve on 09/11/14.
*/
public abstract class SvgDoc
{
private static final String SODIPODI =
"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
private Document doc
; // The whole document
private Element defs
; // Definitions, eg markers.
// Offsets to translate the whole diagram by, so that it is all on the page.
private int topOffset
;
private int leftOffset
;
/**
* Create the document outline. Various elements are saved and added to by the
* rest of the program.
*/
public void createDoc
() {
doc = DocumentHelper.
createDocument();
Element svg = doc.
addElement("svg",
"http://www.w3.org/2000/svg")
.
addAttribute("xmlns",
"http://www.w3.org/2000/svg")
.
addAttribute("xmlns:inkscape",
"http://www.inkscape.org/namespaces/inkscape")
.
addAttribute("xmlns:sodipodi", SODIPODI
)
.
addAttribute("version",
"1.1")
.
addAttribute("id",
"svg2");
// Definitions for the whole document
defs = svg.
addElement("defs").
addAttribute("id",
"defs1");
addMarkers
();
// Information for inkscape.
svg.
addElement("sodipodi:namedview", SODIPODI
)
.
addAttribute("id",
"base")
.
addAttribute("pagecolor",
"#ffffff")
.
addAttribute("inkscape:window-width",
"1060")
.
addAttribute("inkscape:window-height",
"700")
;
// Add the document layers.
addLayers
(svg
);
}
protected abstract void addLayers
(Element svg
);
private void addMarkers
() {
defs.
addElement("marker")
.
addAttribute("inkscape:stockid",
"Arrow2Send")
.
addAttribute("orient",
"auto")
.
addAttribute("refX",
"0.0")
.
addAttribute("refY",
"0.0")
.
addAttribute("id",
"Arrow2Send")
.
addAttribute("style",
"overflow:visible;")
.
addElement("path")
.
addAttribute("style",
"fill-rule:evenodd;stroke-width:0.62500000;stroke-linejoin:round;")
.
addAttribute("d",
"M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z ")
.
addAttribute("transform",
"scale(0.3) rotate(180) translate(-2.3,0)")
;
defs.
addElement("marker")
.
addAttribute("inkscape:stockid",
"DiamondSend")
.
addAttribute("orient",
"auto")
.
addAttribute("refX",
"0.0")
.
addAttribute("refY",
"0.0")
.
addAttribute("id",
"DiamondSend")
.
addAttribute("style",
"overflow:visible;")
.
addElement("path")
.
addAttribute("style",
"fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt")
.
addAttribute("d",
"M 0,-7.0710768 L -7.0710894,0 L 0,7.0710589 L 7.0710462,0 L 0,-7.0710768 z")
.
addAttribute("transform",
"scale(0.2) translate(-6,0)")
;
defs.
addElement("marker")
.
addAttribute("inkscape:stockid",
"DotM")
.
addAttribute("orient",
"auto")
.
addAttribute("refX",
"0.0")
.
addAttribute("refY",
"0.0")
.
addAttribute("id",
"DotM")
.
addAttribute("style",
"overflow:visible;")
.
addElement("path")
.
addAttribute("style",
"fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt")
.
addAttribute("d",
"M -2.5,-1.0 C -2.5,1.7600000 -4.7400000,4.0 -7.5,4.0 C -10.260000,4.0 -12.5,1.7600000 " +
"-12.5,-1.0 C -12.5,-3.7600000 -10.260000,-6.0 -7.5,-6.0 C -4.7400000,-6.0 -2.5,-3.7600000 -2.5,-1.0 z")
.
addAttribute("transform",
"scale(0.4) translate(7.4, 1)")
;
}
public Document getDoc
() {
return doc
;
}
public abstract void setTransform
(int leftOffset,
int topOffset
);
public int getLeftOffset
() {
return leftOffset
;
}
public int getTopOffset
() {
return topOffset
;
}
public XY coord
(int lat,
int lon
) {
XY co =
new XY
(lat, lon
);
if (co.
getXi() < leftOffset
)
leftOffset = co.
getXi();
if (co.
getYi() < topOffset
)
topOffset = co.
getYi();
return co
;
}
}