X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FSpacing.h;h=7311f792b5a3b5ae7ec98e90430db607a30ac52c;hb=a4d9315bc49445e4419b3b59fd238a13c5f7be31;hp=3bbc85282b84600c632ff51caa9ba602b44f4f9e;hpb=35584afc1162dec2cf9fff79305e95cb3b75aefb;p=lyx.git diff --git a/src/Spacing.h b/src/Spacing.h index 3bbc85282b..7311f792b5 100644 --- a/src/Spacing.h +++ b/src/Spacing.h @@ -1,18 +1,22 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-1999 The LyX Team. +/** + * \file src/Spacing.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * ======================================================*/ + * \author Lars Gullik Bjønnes + * + * Full author contact details are available in file CREDITS. + */ #ifndef SPACING_H #define SPACING_H -#include +#include "support/strfwd.h" + +#include + +namespace lyx { /// class Spacing { @@ -26,64 +30,68 @@ public: /// Double, /// - Other + Other, + /// + Default }; /// - Spacing() - { - space = Single; - value = getValue(); - } + Spacing() : space(Default), value("1.0") {} + /// + Spacing(Spacing::Space sp, double val = 1.0) { set(sp, val); } + /// + Spacing(Spacing::Space sp, std::string const & val) { set(sp, val); } + /// + bool isDefault() const { return space == Default; } /// - float getValue() const - { - switch(space) { - case Single: return 1.0; - case Onehalf: return 1.25; - case Double: return 1.667; - case Other: return value; - } - return 1.0; - } + std::string const getValueAsString() const; /// - Spacing::Space getSpace() const - { - return space; - } + double getValue() const; /// - void set(Spacing::Space sp, float val= 1.0) - { - space = sp; - if (sp == Other) { - switch(int(val*1000 + 0.5)) { - case 1000: space = Single; break; - case 1250: space = Onehalf; break; - case 1667: space = Double; break; - default: value = val; break; - } - } - } + Spacing::Space getSpace() const { return space; } /// - void set(Spacing::Space sp, char const* val) - { - float fval; - sscanf(val,"%f",&fval); - set(sp,fval); - } + void set(Spacing::Space sp, double val = 1.0); /// - void writeFile(FILE *file); + void set(Spacing::Space sp, std::string const & val); /// - friend bool operator!=(Spacing const &a, Spacing const &b) - { - if (a.space == b.space && a.getValue() == b.getValue()) - return false; - return true; - } + void writeFile(std::ostream &, bool para = false) const; + /// useSetSpace is true when using the variant supported by + /// the memoir class. + std::string const writeEnvirBegin(bool useSetSpace) const; + /// useSetSpace is true when using the variant supported by + /// the memoir class. + std::string const writeEnvirEnd(bool useSetSpace) const; + /// useSetSpace is true when using the variant supported by + /// the memoir class. + std::string const writeCmd(bool useSetSpace) const; + /// useSetSpace is true when using the variant supported by + /// the memoir class. + std::string const writePreamble(bool useSetSpace) const; + private: /// Space space; /// - float value; + std::string value; + /// names of line spacing + static std::string const spacing_string[]; }; -#endif + +/// +inline +bool operator==(Spacing const & a, Spacing const & b) +{ + return a.getSpace() == b.getSpace() + && a.getValueAsString() == b.getValueAsString(); +} + +/// +inline +bool operator!=(Spacing const & a, Spacing const & b) +{ + return !(a == b); +} + +} // namespace lyx + +#endif // SPACING_H