aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcms <cms@beatworm.co.uk>2016-10-12 12:37:24 (GMT)
committercms <cms@beatworm.co.uk>2016-10-12 12:37:24 (GMT)
commit5838ec137b7641f5c682cd6a9a54ec600ad2f532 (patch)
treefcd9a8d0a70408aec095a5c9444fe3760d20ca08
parentd3b7ad2fb2334f27f6cf5adb2fa47929cd511be0 (diff)
downloadhydra-5838ec137b7641f5c682cd6a9a54ec600ad2f532.zip
hydra-5838ec137b7641f5c682cd6a9a54ec600ad2f532.tar.gz
hydra-5838ec137b7641f5c682cd6a9a54ec600ad2f532.tar.bz2
put points/mm/pixels converesions in a unit class
keeps things tidier - probably could do this with templated classes even better, but at that point it's probably better looking for a library that someone else already wrote
-rw-r--r--Makefile4
-rw-r--r--src/HydraRootHandler.cpp4
-rw-r--r--src/HydraUnit.cpp18
-rw-r--r--src/HydraUnit.h18
4 files changed, 41 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index c667cfc..26bf2c7 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,9 @@ LDLIBS+=$(PDF_LIBS) $(PDF_LIBS)
VPATH=src
OBJDIR=obj
-SRCS=main.cpp HydraRequestHandlerFactory.cpp HydraRootHandler.cpp HydraApplication.cpp
+SRCS=main.cpp HydraRequestHandlerFactory.cpp HydraRootHandler.cpp \
+ HydraApplication.cpp HydraUnit.cpp
+
OBJS=$(patsubst %,$(OBJDIR)/%, $(subst .cpp,.o,$(SRCS)))
EXE=hydra
diff --git a/src/HydraRootHandler.cpp b/src/HydraRootHandler.cpp
index 48ba447..6ba7571 100644
--- a/src/HydraRootHandler.cpp
+++ b/src/HydraRootHandler.cpp
@@ -48,8 +48,8 @@ namespace Hydra {
out.write(result.data(), out_len);
}
- void RootHandler::handleRequest(Poco::Net::HTTPServerRequest &request,
- Poco::Net::HTTPServerResponse &response)
+ void RootHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
+ Poco::Net::HTTPServerResponse& response)
{
FPDF_LIBRARY_CONFIG config;
diff --git a/src/HydraUnit.cpp b/src/HydraUnit.cpp
new file mode 100644
index 0000000..8978038
--- /dev/null
+++ b/src/HydraUnit.cpp
@@ -0,0 +1,18 @@
+#include "HydraUnit.h"
+
+namespace Hydra {
+ const double POINTS_PER_MM = 0.352777778 ;
+
+ void Unit::mm(double mm_val) { _base = mm_to_points(mm_val); }
+ double Unit::mm() { return points_to_mm(_base); }
+
+ double Unit::mm_to_points(double mm_val)
+ {
+ return mm_val * POINTS_PER_MM;
+ }
+
+ double Unit::points_to_mm(double points_val)
+ {
+ return points_val / POINTS_PER_MM;
+ }
+}
diff --git a/src/HydraUnit.h b/src/HydraUnit.h
new file mode 100644
index 0000000..659f98b
--- /dev/null
+++ b/src/HydraUnit.h
@@ -0,0 +1,18 @@
+#pragma once
+
+namespace Hydra {
+ class Unit {
+ double mm();
+ void mm(double);
+
+ int points();
+ void points(double);
+
+
+ private:
+ double mm_to_points(double val);
+ double points_to_mm(double val);
+ double _base;
+ long _dpi ;
+ };
+};