* Calculates the scale of the map taking into account the paper size.
*
* @return the scale of the map on the current paper type.
*/
private double calculateScale() {
IViewportModel viewportModel = getMapBoxPrinter().getMap().getViewportModel();
// get page size in pixels and in mm
Page page = getMapBoxPrinter().getBox().getPage();
org.eclipse.draw2d.geometry.Dimension pageSize = page.getSize();
org.eclipse.draw2d.geometry.Dimension paperSize = page.getPaperSize();
// map box size in pixels
org.eclipse.draw2d.geometry.Dimension mapSize = owner.getBoxPrinter().getBox().getSize();
// map box size in points and then in meters on paper
float mapPaperWidthPoints = (float) paperSize.width * (float) mapSize.width
/ (float) pageSize.width;
float mapPaperWidthMeters = AbstractBoxPrinter.point2cm(mapPaperWidthPoints) / 100f;
// map bounds in meters
ReferencedEnvelope mapEnvelope = (ReferencedEnvelope) viewportModel.getBounds();
double mapWorldWidthMeters = mapEnvelope.getWidth();
double thescale = mapWorldWidthMeters / mapPaperWidthMeters;
return thescale;
}