Units.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libpagemaker project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef LIBPAGEMAKER_UNITS_H
11 #define LIBPAGEMAKER_UNITS_H
12 
13 #include <string>
14 
15 namespace libpagemaker
16 {
17 const unsigned PAGE_UNITS_PER_INCH = 720;
18 const unsigned SHAPE_UNITS_PER_INCH = 1440;
19 
20 template <unsigned PER_INCH> class LengthUnit
21 {
23 public:
24  int m_value;
25 
26  LengthUnit(int value) : m_value(value) { }
27 
28  double toInches() const
29  {
30  return m_value / ((double)PER_INCH);
31  }
32 };
33 
34 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
36 {
37  return LengthUnit<PER_INCH>(left.m_value + right.m_value);
38 }
39 
40 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
42 {
43  return LengthUnit<PER_INCH>(left.m_value * right);
44 }
45 
46 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
48 {
49  return right * left;
50 }
51 
52 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
54 {
55  return LengthUnit<PER_INCH>(left.m_value - right.m_value);
56 }
57 
60 
61 }
62 
63 #endif /* LIBPAGEMAKER_UNITS_H */
64 
65 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
const unsigned SHAPE_UNITS_PER_INCH
Definition: Units.h:18
LengthUnit(int value)
Definition: Units.h:26
LengthUnit< SHAPE_UNITS_PER_INCH > PMDShapeUnit
Definition: Units.h:59
const LengthUnit< PER_INCH > operator*(LengthUnit< PER_INCH > left, int right)
Definition: Units.h:41
const unsigned PAGE_UNITS_PER_INCH
Definition: Units.h:17
double toInches() const
Definition: Units.h:28
LengthUnit< PER_INCH > T
Definition: Units.h:22
int m_value
Definition: Units.h:24
const LengthUnit< PER_INCH > operator-(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:53
Definition: Units.h:20
LengthUnit< PAGE_UNITS_PER_INCH > PMDPageUnit
Definition: Units.h:58
Definition: geometry.h:20
const LengthUnit< PER_INCH > operator+(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:35

Generated for libpagemaker by doxygen 1.8.10