X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxgluelength.C;h=c7c90432293f931ee3363c06b256f65244ee42bb;hb=fe390e9da1538e20eabbc98977d845295f8e563d;hp=d876e7d3477dd61281963236a97d0802873f33d0;hpb=ff9b02aabae2253d4176bfd0f2d668ab97d7f908;p=lyx.git diff --git a/src/lyxgluelength.C b/src/lyxgluelength.C index d876e7d347..c7c9043229 100644 --- a/src/lyxgluelength.C +++ b/src/lyxgluelength.C @@ -2,7 +2,7 @@ * ====================================================== * * LyX, The Document Processor - * + * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team. * @@ -10,27 +10,11 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "lyxgluelength.h" +#include "lengthcommon.h" #include "Lsstream.h" -namespace { -// this is now here and in lyxlenght.h - -int const num_units = LyXLength::UNIT_NONE; - -// I am not sure if "mu" should be possible to select (Lgb) -char const * unit_name[num_units] = { "sp", "pt", "bp", "dd", - "mm", "pc", "cc", "cm", - "in", "ex", "em", "mu", - "%", "c%", "p%", "l%" }; - -} - LyXGlueLength::LyXGlueLength(LyXLength const & len) : len_(len) @@ -53,53 +37,49 @@ string const LyXGlueLength::asString() const { ostringstream buffer; - if (plus_.value() != 0.0) - if (minus_.value() != 0.0) - 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_.value() != 0.0) - 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 STRCONV(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 STRCONV(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 STRCONV(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 STRCONV(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 STRCONV(buffer.str()); } @@ -107,26 +87,13 @@ string const LyXGlueLength::asLatexString() const { ostringstream buffer; - if (plus_.value() != 0.0) - if (minus_.value() != 0.0) - 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_.value() != 0.0) - 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 << len_.value() << unit_name[len_.unit()]; + + if (!plus_.zero()) + buffer << " plus " << plus_.value() << unit_name[plus_.unit()]; + if (!minus_.zero()) + buffer << " minus " << minus_.value() << unit_name[minus_.unit()]; + return STRCONV(buffer.str()); } @@ -151,8 +118,8 @@ LyXLength const & LyXGlueLength::minus() const bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2) { return l1.len() == l2.len() - && l1.plus() == l2.plus() - && l1.minus() == l2.minus(); + && l1.plus() == l2.plus() + && l1.minus() == l2.minus(); }