summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp98
1 files changed, 45 insertions, 53 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
index 8ab8120daab..7b8b84814fd 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Length.cpp
@@ -2,7 +2,7 @@
** Length.cpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2017 Martin Gieseking <martin.gieseking@uos.de> **
** **
** This program is free software; you can redistribute it and/or **
** modify it under the terms of the GNU General Public License as **
@@ -19,21 +19,11 @@
*************************************************************************/
#include <sstream>
-#include "InputReader.h"
-#include "Length.h"
+#include "InputReader.hpp"
+#include "Length.hpp"
using namespace std;
-const double Length::pt2in = 1.0/72.27;
-const double Length::pt2bp = pt2in*72;
-const double Length::pt2cm = pt2in*2.54;
-const double Length::pt2mm = pt2cm*10;
-const double Length::pt2pc = 1.0/12;
-const double Length::pt2dd = 1157.0/1238;
-const double Length::pt2cc = pt2dd/12;
-const double Length::pt2sp = 65536.0;
-
-
void Length::set (const string &lenstr) {
switch (lenstr.length()) {
case 0:
@@ -59,19 +49,19 @@ void Length::set (const string &lenstr) {
void Length::set (double val, Unit unit) {
switch (unit) {
- case PT: _pt = val; break;
- case BP: _pt = val/pt2bp; break;
- case IN: _pt = val/pt2in; break;
- case CM: _pt = val/pt2cm; break;
- case MM: _pt = val/pt2mm; break;
- case PC: _pt = val/pt2pc; break;
- case DD: _pt = val/pt2dd; break;
- case CC: _pt = val/pt2cc; break;
- case SP: _pt = val/pt2sp; break;
+ case Unit::PT: _pt = val; break;
+ case Unit::BP: _pt = val/pt2bp; break;
+ case Unit::IN: _pt = val/pt2in; break;
+ case Unit::CM: _pt = val/pt2cm; break;
+ case Unit::MM: _pt = val/pt2mm; break;
+ case Unit::PC: _pt = val/pt2pc; break;
+ case Unit::DD: _pt = val/pt2dd; break;
+ case Unit::CC: _pt = val/pt2cc; break;
+ case Unit::SP: _pt = val/pt2sp; break;
default:
// this isn't supposed to happen
ostringstream oss;
- oss << "invalid length unit: (" << unit << ")";
+ oss << "invalid length unit: (" << static_cast<int>(unit) << ")";
throw UnitException(oss.str());
}
}
@@ -79,19 +69,19 @@ void Length::set (double val, Unit unit) {
double Length::get (Unit unit) const {
switch (unit) {
- case PT: return pt();
- case BP: return bp();
- case IN: return in();
- case CM: return cm();
- case MM: return mm();
- case PC: return pc();
- case DD: return dd();
- case CC: return cc();
- case SP: return sp();
+ case Unit::PT: return pt();
+ case Unit::BP: return bp();
+ case Unit::IN: return in();
+ case Unit::CM: return cm();
+ case Unit::MM: return mm();
+ case Unit::PC: return pc();
+ case Unit::DD: return dd();
+ case Unit::CC: return cc();
+ case Unit::SP: return sp();
}
// this isn't supposed to happen
ostringstream oss;
- oss << "invalid length unit: (" << unit << ")";
+ oss << "invalid length unit: (" << static_cast<int>(unit) << ")";
throw UnitException(oss.str());
}
@@ -103,20 +93,22 @@ string Length::toString (Unit unit) const {
}
-#define UNIT(c1, c2) ((c1 << 8)|c2)
+static constexpr int unit_id (int c1, int c2) {
+ return (c1 << 8) | c2;
+}
Length::Unit Length::stringToUnit (const std::string &unitstr) {
if (unitstr.length() == 2) {
- switch (UNIT(unitstr[0], unitstr[1])) {
- case UNIT('p','t'): return PT;
- case UNIT('b','p'): return BP;
- case UNIT('i','n'): return IN;
- case UNIT('c','m'): return CM;
- case UNIT('m','m'): return MM;
- case UNIT('p','c'): return PC;
- case UNIT('d','d'): return DD;
- case UNIT('c','c'): return CC;
- case UNIT('s','p'): return SP;
+ switch (unit_id(unitstr[0], unitstr[1])) {
+ case unit_id('p','t'): return Unit::PT;
+ case unit_id('b','p'): return Unit::BP;
+ case unit_id('i','n'): return Unit::IN;
+ case unit_id('c','m'): return Unit::CM;
+ case unit_id('m','m'): return Unit::MM;
+ case unit_id('p','c'): return Unit::PC;
+ case unit_id('d','d'): return Unit::DD;
+ case unit_id('c','c'): return Unit::CC;
+ case unit_id('s','p'): return Unit::SP;
}
}
throw UnitException(string("invalid length unit: ")+unitstr);
@@ -125,15 +117,15 @@ Length::Unit Length::stringToUnit (const std::string &unitstr) {
string Length::unitToString (Unit unit) {
switch (unit) {
- case PT: return "pt";
- case BP: return "bp";
- case IN: return "in";
- case CM: return "cm";
- case MM: return "mm";
- case PC: return "pc";
- case DD: return "dd";
- case CC: return "cc";
- case SP: return "sp";
+ case Unit::PT: return "pt";
+ case Unit::BP: return "bp";
+ case Unit::IN: return "in";
+ case Unit::CM: return "cm";
+ case Unit::MM: return "mm";
+ case Unit::PC: return "pc";
+ case Unit::DD: return "dd";
+ case Unit::CC: return "cc";
+ case Unit::SP: return "sp";
}
// this isn't supposed to happen
return "??";