aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcms <cms@beatworm.co.uk>2016-10-12 14:20:29 (GMT)
committercms <cms@beatworm.co.uk>2016-10-12 14:20:29 (GMT)
commit5364e79ca462aa781e1b6aa8a91b9e12ad73cd95 (patch)
treea563c8a36d5a88122906e40e36ba62a009110763
parentfa947622f4252559f737040e8fa3b3351ec1b34f (diff)
downloadhydra-5364e79ca462aa781e1b6aa8a91b9e12ad73cd95.zip
hydra-5364e79ca462aa781e1b6aa8a91b9e12ad73cd95.tar.gz
hydra-5364e79ca462aa781e1b6aa8a91b9e12ad73cd95.tar.bz2
more unit conversions
-rw-r--r--src/HydraRootHandler.cpp15
-rw-r--r--src/HydraUnit.cpp20
-rw-r--r--src/HydraUnit.h9
3 files changed, 35 insertions, 9 deletions
diff --git a/src/HydraRootHandler.cpp b/src/HydraRootHandler.cpp
index 6ba7571..b3f46ed 100644
--- a/src/HydraRootHandler.cpp
+++ b/src/HydraRootHandler.cpp
@@ -2,6 +2,7 @@
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "HydraApplication.h"
+#include "HydraUnit.h"
#include "fpdfview.h"
#include <iostream>
@@ -16,11 +17,11 @@ namespace Hydra {
return false;
return true;
}
-
+
static void WritePpm(std::ostream& out, const void* buffer_void,
int stride, int width, int height) {
const char* buffer = reinterpret_cast<const char*>(buffer_void);
-
+
if (!CheckDimensions(stride, width, height))
return;
@@ -66,16 +67,18 @@ namespace Hydra {
if (!page) {
std::cerr << "An error occurred loading page 0" << std::endl;
}
- std::cerr << "Height is " << FPDF_GetPageHeight(page);
- std::cerr << "OK GOT A PAGE" << std::endl;
+
+ Unit height(FPDF_GetPageHeight(page),72);
+ Unit width(FPDF_GetPageWidth(page),72);
+
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);
-
+
response.setContentType("image/x-portable-pixmap");
response.setChunkedTransferEncoding(true);
-
+
std::ostream& s = response.send();
const char* buffer =
reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bmp));
diff --git a/src/HydraUnit.cpp b/src/HydraUnit.cpp
index 6c487f1..7386cae 100644
--- a/src/HydraUnit.cpp
+++ b/src/HydraUnit.cpp
@@ -1,14 +1,20 @@
#include "HydraUnit.h"
namespace Hydra {
- const double POINTS_PER_MM = 0.352777778 ;
-
+ 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){}
void Unit::mm(double mm_val) { _base_points = mm_to_points(mm_val); }
double Unit::mm() { return points_to_mm(_base_points); }
+ void Unit::pixels(long px_val)
+ { _base_points = points_to_pixels(px_val, _dpi); }
+ long Unit::pixels()
+ { return points_to_pixels(_base_points,_dpi); }
+
+
double Unit::mm_to_points(double mm_val)
{
return mm_val * POINTS_PER_MM;
@@ -18,4 +24,14 @@ namespace Hydra {
{
return points_val / POINTS_PER_MM;
}
+
+ double Unit::pixels_to_points(long pixels_val, int dpi_val)
+ {
+ return ((pixels_val / dpi_val) / INCHES_PER_MM) * POINTS_PER_MM;
+ }
+
+ long Unit::points_to_pixels(double points_val, int dpi_val)
+ {
+ return ((points_val / POINTS_PER_MM) * INCHES_PER_MM) / dpi_val;
+ }
}
diff --git a/src/HydraUnit.h b/src/HydraUnit.h
index 25b73be..6b3e36a 100644
--- a/src/HydraUnit.h
+++ b/src/HydraUnit.h
@@ -2,18 +2,25 @@
namespace Hydra {
class Unit {
+ public:
Unit(double points);
Unit(double points, int dpi);
+
double mm();
void mm(double);
- int points();
+ double points();
void points(double);
+ long pixels();
+ void pixels(long);
private:
double mm_to_points(double val);
double points_to_mm(double val);
+ long points_to_pixels(double val,int dpi);
+ double pixels_to_points(long val, int dpi);
+
double _base_points;
long _dpi ;
};