aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcms <cms@beatworm.co.uk>2016-10-12 14:54:25 (GMT)
committercms <cms@beatworm.co.uk>2016-10-12 14:54:25 (GMT)
commita327f22858d08562587a6e69ac406d2cad934a6f (patch)
tree4b2a49e1e6a33e754540a1f6003e22c2cf41cc0b
parent5364e79ca462aa781e1b6aa8a91b9e12ad73cd95 (diff)
downloadhydra-a327f22858d08562587a6e69ac406d2cad934a6f.zip
hydra-a327f22858d08562587a6e69ac406d2cad934a6f.tar.gz
hydra-a327f22858d08562587a6e69ac406d2cad934a6f.tar.bz2
fixed dpi / ppi ppp calculations
probably not for the first time. Astonished at quite how bad I am at basic arithmetic these days. I even had to turn the radio off to concentrate better. the trick is, I think computing pixels per inch ("dpi") and using that againts points per inch ( 72 ) to calculate pixels per point
-rw-r--r--src/HydraRootHandler.cpp3
-rw-r--r--src/HydraUnit.cpp10
2 files changed, 10 insertions, 3 deletions
diff --git a/src/HydraRootHandler.cpp b/src/HydraRootHandler.cpp
index b3f46ed..56027e4 100644
--- a/src/HydraRootHandler.cpp
+++ b/src/HydraRootHandler.cpp
@@ -70,7 +70,8 @@ namespace Hydra {
Unit height(FPDF_GetPageHeight(page),72);
Unit width(FPDF_GetPageWidth(page),72);
-
+ std::cerr << "page width of " << width.points() << "pts " <<
+ " which is " << width.pixels() << "px at 72dpi";
FPDF_BITMAP bmp = FPDFBitmap_Create(600,600,1);
FPDFBitmap_FillRect(bmp, 0, 0, 600, 600, 0xccccccff);
FPDF_RenderPageBitmap(bmp,page,0,0,600,600,0,0);
diff --git a/src/HydraUnit.cpp b/src/HydraUnit.cpp
index 7386cae..549bd00 100644
--- a/src/HydraUnit.cpp
+++ b/src/HydraUnit.cpp
@@ -1,8 +1,11 @@
#include "HydraUnit.h"
namespace Hydra {
+
+ const int POINTS_PER_INCH = 72;
const double POINTS_PER_MM = 0.352777778;
const double INCHES_PER_MM = 0.039;
+
Unit::Unit(double points) : _base_points(points), _dpi(72) {}
Unit::Unit(double points, int dpi) : _base_points(points), _dpi(dpi){}
@@ -13,6 +16,9 @@ namespace Hydra {
{ _base_points = points_to_pixels(px_val, _dpi); }
long Unit::pixels()
{ return points_to_pixels(_base_points,_dpi); }
+
+ double Unit::points() { return _base_points; }
+ void Unit::points(double pts_val) { _base_points = pts_val; }
double Unit::mm_to_points(double mm_val)
@@ -27,11 +33,11 @@ namespace Hydra {
double Unit::pixels_to_points(long pixels_val, int dpi_val)
{
- return ((pixels_val / dpi_val) / INCHES_PER_MM) * POINTS_PER_MM;
+ return ( dpi_val / POINTS_PER_INCH ) / pixels_val ;
}
long Unit::points_to_pixels(double points_val, int dpi_val)
{
- return ((points_val / POINTS_PER_MM) * INCHES_PER_MM) / dpi_val;
+ return (dpi_val / POINTS_PER_INCH) * points_val;
}
}