From 95f141d7374fe99d3bf6f96299f5c5109ea058a4 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 15 Jun 2015 12:37:18 +0300 Subject: [PATCH] Move realization to cpp. --HG-- branch : feature --- src/libs/ifc/ifcdef.cpp | 109 +++++++++++++++++++++++++++++++++++++++ src/libs/ifc/ifcdef.h | 110 ++-------------------------------------- 2 files changed, 112 insertions(+), 107 deletions(-) diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 5ed716df4..8bfc8d93c 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -59,3 +59,112 @@ qreal WidthHairLine(Unit patternUnit) { return WidthMainLine(patternUnit)/3.0; } + +//--------------------------------------------------------------------------------------------------------------------- +double ToPixel(double val, const Unit &unit) +{ + switch (unit) + { + case Unit::Mm: + return (val / 25.4) * PrintDPI; + case Unit::Cm: + return ((val * 10.0) / 25.4) * PrintDPI; + case Unit::Inch: + return val * PrintDPI; + case Unit::Px: + return val; + default: + break; + } + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +double FromPixel(double pix, const Unit &unit) +{ + switch (unit) + { + case Unit::Mm: + return (pix / PrintDPI) * 25.4; + case Unit::Cm: + return ((pix / PrintDPI) * 25.4) / 10.0; + case Unit::Inch: + return pix / PrintDPI; + case Unit::Px: + return pix; + default: + break; + } + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) +{ + switch (from) + { + case Unit::Mm: + switch (to) + { + case Unit::Mm: + return value; + case Unit::Cm: + return value / 10.0; + case Unit::Inch: + return value / 25.4; + case Unit::Px: + return (value / 25.4) * PrintDPI; + default: + break; + } + break; + case Unit::Cm: + switch (to) + { + case Unit::Mm: + return value * 10.0; + case Unit::Cm: + return value; + case Unit::Inch: + return value / 2.54; + case Unit::Px: + return ((value * 10.0) / 25.4) * PrintDPI; + default: + break; + } + break; + case Unit::Inch: + switch (to) + { + case Unit::Mm: + return value * 25.4; + case Unit::Cm: + return value * 2.54; + case Unit::Inch: + return value; + case Unit::Px: + return value * PrintDPI; + default: + break; + } + break; + case Unit::Px: + switch (to) + { + case Unit::Mm: + return (value / PrintDPI) * 25.4; + case Unit::Cm: + return ((value / PrintDPI) * 25.4) / 10.0; + case Unit::Inch: + return value / PrintDPI; + case Unit::Px: + return value; + default: + break; + } + break; + default: + break; + } + return 0; +} diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index adac8e6d2..e61a27a06 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -64,113 +64,9 @@ extern const qreal PrintDPI; qreal WidthMainLine(Unit patternUnit); qreal WidthHairLine(Unit patternUnit); -//--------------------------------------------------------------------------------------------------------------------- -inline double ToPixel(double val, const Unit &unit) -{ - switch (unit) - { - case Unit::Mm: - return (val / 25.4) * PrintDPI; - case Unit::Cm: - return ((val * 10.0) / 25.4) * PrintDPI; - case Unit::Inch: - return val * PrintDPI; - case Unit::Px: - return val; - default: - break; - } - return 0; -} +double ToPixel(double val, const Unit &unit); +double FromPixel(double pix, const Unit &unit); -//--------------------------------------------------------------------------------------------------------------------- -inline double FromPixel(double pix, const Unit &unit) -{ - switch (unit) - { - case Unit::Mm: - return (pix / PrintDPI) * 25.4; - case Unit::Cm: - return ((pix / PrintDPI) * 25.4) / 10.0; - case Unit::Inch: - return pix / PrintDPI; - case Unit::Px: - return pix; - default: - break; - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) -{ - switch (from) - { - case Unit::Mm: - switch (to) - { - case Unit::Mm: - return value; - case Unit::Cm: - return value / 10.0; - case Unit::Inch: - return value / 25.4; - case Unit::Px: - return (value / 25.4) * PrintDPI; - default: - break; - } - break; - case Unit::Cm: - switch (to) - { - case Unit::Mm: - return value * 10.0; - case Unit::Cm: - return value; - case Unit::Inch: - return value / 2.54; - case Unit::Px: - return ((value * 10.0) / 25.4) * PrintDPI; - default: - break; - } - break; - case Unit::Inch: - switch (to) - { - case Unit::Mm: - return value * 25.4; - case Unit::Cm: - return value * 2.54; - case Unit::Inch: - return value; - case Unit::Px: - return value * PrintDPI; - default: - break; - } - break; - case Unit::Px: - switch (to) - { - case Unit::Mm: - return (value / PrintDPI) * 25.4; - case Unit::Cm: - return ((value / PrintDPI) * 25.4) / 10.0; - case Unit::Inch: - return value / PrintDPI; - case Unit::Px: - return value; - default: - break; - } - break; - default: - break; - } - return 0; -} +qreal UnitConvertor(qreal value, const Unit &from, const Unit &to); #endif // IFCDEF_H