Rev 434 |
Blame |
Compare with Previous |
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.subdiv;
import uk.me.parabola.imgfmt.app.trergn.Subdivision;
import org.dom4j.Element;
import test.svg.SvgDoc;
import test.svg.XY;
/**
* Build a SVG document to display subdivisions.
*/
public class SvgDivDoc
extends SvgDoc
{
private Element divs
;
private Element labels
;
protected void addLayers
(Element svg
) {
divs = svg.
addElement("g")
.
addAttribute("inkscape:label",
"subdivisions")
.
addAttribute("inkscape:groupmode",
"layer");
labels = svg.
addElement("g")
.
addAttribute("inkscape:label",
"labels")
.
addAttribute("style",
"display:none")
.
addAttribute("inkscape:groupmode",
"layer")
;
}
public XY addDiv
(Subdivision div,
int width,
int height
) {
// Uncomment to not show empty divs
//if (!div.hasIndPoints() && !div.hasPoints() && !div.hasPolylines() && !div.hasPolygons())
// return null;
XY blc = coord
(div.
getLatitude() - height /
2, div.
getLongitude() - width /
2);
XY trc = coord
(div.
getLatitude() + height /
2, div.
getLongitude() + width /
2);
divs.
addElement("rect")
.
addAttribute("width",
String.
valueOf(trc.
getXi() - blc.
getXi()))
.
addAttribute("height",
String.
valueOf(blc.
getYi() - trc.
getYi()))
.
addAttribute("x", blc.
getX())
.
addAttribute("y", trc.
getY())
.
addAttribute("stroke",
"black")
.
addAttribute("stroke-width",
"3")
.
addAttribute("fill-opacity",
"0.2")
.
addAttribute("fill",
"#faa")
;
return blc
;
}
public void addLabel
(Subdivision div, XY blc,
int npoints,
int nlines,
int nshapes
) {
//System.out.printf("Div:%d P:%d L:%d S:%d\n", div.getNumber(), npoints, nlines, nshapes);
Element g = labels.
addElement("g")
.
addAttribute("transform",
String.
format("translate(%s,%s) scale(4)", blc.
getX(), blc.
getY()));
g.
addElement("rect")
.
addAttribute("width",
"50")
.
addAttribute("height",
"10")
.
addAttribute("fill",
"white")
.
addAttribute("stroke-width",
"0.1")
.
addAttribute("stroke",
"red");
Element text = g.
addElement("text")
.
addAttribute("y",
"5")
.
addAttribute("x",
"1")
.
addAttribute("font-size",
"3px");
// Add the division number and (lat,lon)
text.
addElement("tspan")
.
addAttribute("sodipodi:role",
"line")
.
setText(String.
format("%d: %s", div.
getNumber(), div.
getCenter().
toString()));
// Add the numbers of points, lines and shapes (polygons).
text.
addElement("tspan")
.
addAttribute("sodipodi:role",
"line")
.
setText(String.
format("P:%d, L:%d S:%d", npoints, nlines, nshapes
));
}
public void setTransform
(int leftOffset,
int topOffset
) {
int MARGIN =
0;
String translate =
String.
format("translate(%d,%d)", MARGIN - leftOffset, MARGIN - topOffset
);
divs.
addAttribute("transform", translate
);
labels.
addAttribute("transform", translate
);
}
}