X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxgluelength.C;h=fbea55bbd0354fa397088258e4eaed6a6ab2f0ed;hb=ba62665f966508db5a4de6864f4aa7374c5a5356;hp=0469b8e7357448e6b84f8d634bf25c7e0859dbb7;hpb=8283e978f8d621041c432b9b88a476bfd567385c;p=lyx.git diff --git a/src/lyxgluelength.C b/src/lyxgluelength.C index 0469b8e735..fbea55bbd0 100644 --- a/src/lyxgluelength.C +++ b/src/lyxgluelength.C @@ -1,23 +1,27 @@ -/* This file is part of - * ====================================================== +/** + * \file lyxgluelength.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author Lars Gullik Bjønnes + * \author Matthias Ettrich + * \author John Levon * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. - * - * ====================================================== */ + * Full author contact details are available in file CREDITS. + */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "lyxgluelength.h" #include "lengthcommon.h" -#include "Lsstream.h" +#include + + +namespace lyx { + +using std::ostringstream; +using std::string; LyXGlueLength::LyXGlueLength(LyXLength const & len) @@ -41,53 +45,49 @@ string const LyXGlueLength::asString() const { ostringstream buffer; - if (!plus_.zero()) - if (!minus_.zero()) - if (len_.unit() == plus_.unit() && len_.unit() == minus_.unit()) - if (plus_.value() == minus_.value()) - buffer << len_.value() << "+-" - << plus_.value() << unit_name[len_.unit()]; - else - buffer << len_.value() - << '+' << plus_.value() - << '-' << minus_.value() - << unit_name[len_.unit()]; - else - if (plus_.unit() == minus_.unit() - && plus_.value() == minus_.value()) - buffer << len_.value() << unit_name[len_.unit()] - << "+-" << plus_.value() - << unit_name[plus_.unit()]; - - else - buffer << len_.value() << unit_name[len_.unit()] - << '+' << plus_.value() - << unit_name[plus_.unit()] - << '-' << minus_.value() - << unit_name[minus_.unit()]; - else - if (len_.unit() == plus_.unit()) - buffer << len_.value() << '+' << plus_.value() - << unit_name[len_.unit()]; - else - buffer << len_.value() << unit_name[len_.unit()] - << '+' << plus_.value() - << unit_name[plus_.unit()]; - - else - if (!minus_.zero()) - if (len_.unit() == minus_.unit()) - buffer << len_.value() << '-' << minus_.value() - << unit_name[len_.unit()]; - - else - buffer << len_.value() << unit_name[len_.unit()] - << '-' << minus_.value() - << unit_name[minus_.unit()]; - else - buffer << len_.value() << unit_name[len_.unit()]; - - return buffer.str().c_str(); + buffer << len_.value(); + + if (plus_.zero() && minus_.zero()) { + buffer << unit_name[len_.unit()]; + return buffer.str(); + } + + // just len and plus + if (minus_.zero()) { + if (len_.unit() != plus_.unit()) + buffer << unit_name[len_.unit()]; + buffer << '+' << plus_.value(); + buffer << unit_name[plus_.unit()]; + return buffer.str(); + } + + // just len and minus + if (plus_.zero()) { + if (len_.unit() != minus_.unit()) + buffer << unit_name[len_.unit()]; + buffer << '-' << minus_.value(); + buffer << unit_name[minus_.unit()]; + return buffer.str(); + } + + // ok, len, plus AND minus + + // len+- + if (minus_ == plus_) { + if (len_.unit() != minus_.unit()) + buffer << unit_name[len_.unit()]; + buffer << "+-" << minus_.value(); + buffer << unit_name[minus_.unit()]; + return buffer.str(); + } + + // this is so rare a case, why bother minimising units ? + + buffer << unit_name[len_.unit()]; + buffer << '+' << plus_.value() << unit_name[plus_.unit()]; + buffer << '-' << minus_.value() << unit_name[minus_.unit()]; + + return buffer.str(); } @@ -95,26 +95,13 @@ string const LyXGlueLength::asLatexString() const { ostringstream buffer; + buffer << len_.value() << unit_name[len_.unit()]; + if (!plus_.zero()) - if (!minus_.zero()) - buffer << len_.value() << unit_name[len_.unit()] - << " plus " - << plus_.value() << unit_name[plus_.unit()] - << " minus " - << minus_.value() << unit_name[minus_.unit()]; - else - buffer << len_.value() << unit_name[len_.unit()] - << " plus " - << plus_.value() << unit_name[plus_.unit()]; - else - if (!minus_.zero()) - buffer << len_.value() << unit_name[len_.unit()] - << " minus " - << minus_.value() << unit_name[minus_.unit()]; - else - buffer << len_.value() << unit_name[len_.unit()]; - - return buffer.str().c_str(); + buffer << " plus " << plus_.value() << unit_name[plus_.unit()]; + if (!minus_.zero()) + buffer << " minus " << minus_.value() << unit_name[minus_.unit()]; + return buffer.str(); } @@ -148,3 +135,6 @@ bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2) { return !(l1 == l2); } + + +} // namespace lyx