From ff9b02aabae2253d4176bfd0f2d668ab97d7f908 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 2 Dec 2001 23:47:06 +0000 Subject: [PATCH] split vspace into smaller files. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3136 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Makefile.am | 6 + src/figureForm.C | 14 +- src/lengthcommon.C | 20 +++ src/lengthcommon.h | 16 +++ src/lyxgluelength.C | 162 +++++++++++++++++++++++ src/lyxgluelength.h | 81 ++++++++++++ src/lyxlength.C | 126 ++++++++++++++++++ src/lyxlength.h | 107 +++++++++++++++ src/vspace.C | 311 ++++++-------------------------------------- src/vspace.h | 155 +--------------------- 10 files changed, 567 insertions(+), 431 deletions(-) create mode 100644 src/lengthcommon.C create mode 100644 src/lengthcommon.h create mode 100644 src/lyxgluelength.C create mode 100644 src/lyxgluelength.h create mode 100644 src/lyxlength.C create mode 100644 src/lyxlength.h diff --git a/src/Makefile.am b/src/Makefile.am index 089dad773f..6662a8a5bf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -133,6 +133,8 @@ lyx_SOURCES = \ lastfiles.h \ layout.C \ layout.h \ + lengthcommon.C \ + lengthcommon.h \ lyx_cb.C \ lyx_cb.h \ lyx_gui.C \ @@ -151,6 +153,10 @@ lyx_SOURCES = \ lyxfind.h \ lyxfunc.C \ lyxfunc.h \ + lyxgluelength.C \ + lyxgluelength.h \ + lyxlength.C \ + lexlength.h \ lyxlex.C \ lyxlex.h \ lyxlex_pimpl.C \ diff --git a/src/figureForm.C b/src/figureForm.C index b160d0eedc..6361915fb0 100644 --- a/src/figureForm.C +++ b/src/figureForm.C @@ -81,16 +81,10 @@ void FigureApplyCB(FL_OBJECT *, long) // The standard layout should always be numer 0; current_view->text->setLayout(current_view, 0); - current_view->text-> - setParagraph(current_view, 0, 0, - 0, 0, - VSpace (0.3 * buffer->params.spacing.getValue(), - LyXLength::CM), - VSpace (0.3 * - buffer->params.spacing.getValue(), - LyXLength::CM), - Spacing(), - LYX_ALIGN_CENTER, string(), 0); + LyXLength len(0.3 * buffer->params.spacing.getValue(), LyXLength::CM); + current_view->text->setParagraph(current_view, 0, 0, 0, 0, + VSpace(len), VSpace(len), Spacing(), + LYX_ALIGN_CENTER, string(), 0); current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); diff --git a/src/lengthcommon.C b/src/lengthcommon.C new file mode 100644 index 0000000000..6e90ceff3a --- /dev/null +++ b/src/lengthcommon.C @@ -0,0 +1,20 @@ +#include + +#include "lengthcommon.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%" }; + + +LyXLength::UNIT unitFromString(string const & data) +{ + int i = 0; + while (i < num_units && data != unit_name[i]) + ++i; + return static_cast(i); +} diff --git a/src/lengthcommon.h b/src/lengthcommon.h new file mode 100644 index 0000000000..7991f2c573 --- /dev/null +++ b/src/lengthcommon.h @@ -0,0 +1,16 @@ +// -*- C++ -*- + +#ifndef LENGHT_COMMON_H +#define LENGHT_COMMON_H + +#include "LString.h" +#include "lyxlength.h" + +extern int const num_units; + +// I am not sure if "mu" should be possible to select (Lgb) +extern char const *unit_name[]; + +LyXLength::UNIT unitFromString(string const & data); + +#endif diff --git a/src/lyxgluelength.C b/src/lyxgluelength.C new file mode 100644 index 0000000000..d876e7d347 --- /dev/null +++ b/src/lyxgluelength.C @@ -0,0 +1,162 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "lyxgluelength.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) +{} + + +LyXGlueLength::LyXGlueLength(LyXLength const & len, LyXLength const & plus, + LyXLength const & minus) + : len_(len), plus_(plus), minus_(minus) +{} + + +LyXGlueLength::LyXGlueLength(string const & data) +{ + isValidGlueLength(data, this); +} + + +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(); +} + + +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(); +} + + +LyXLength const & LyXGlueLength::len() const +{ + return len_; +} + + +LyXLength const & LyXGlueLength::plus() const +{ + return plus_; +} + + +LyXLength const & LyXGlueLength::minus() const +{ + return minus_; +} + + +bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2) +{ + return l1.len() == l2.len() + && l1.plus() == l2.plus() + && l1.minus() == l2.minus(); +} + + +bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2) +{ + return !(l1 == l2); +} diff --git a/src/lyxgluelength.h b/src/lyxgluelength.h new file mode 100644 index 0000000000..e07b0fa664 --- /dev/null +++ b/src/lyxgluelength.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#ifndef LYX_GLUE_LENGTH_H +#define LYX_GLUE_LENGTH_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "lyxlength.h" + +#include "LString.h" + +class BufferParams; +class BufferView; + + +class LyXGlueLength { +public: + /// + LyXGlueLength() {} + /// + explicit LyXGlueLength(LyXLength const & len); + /// + LyXGlueLength(LyXLength const & len, + LyXLength const & plus, + LyXLength const & minus); + + /** "data" must be a decimal number, followed by a unit, and + optional "glue" indicated by "+" and "-". You may abbreviate + reasonably. Examples: + 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm + The traditional Latex format is also accepted, like + 4cm plus 10pt minus 10pt */ + explicit LyXGlueLength(string const & data); + + /// + LyXLength const & len() const; + /// + LyXLength const & plus() const; + /// + LyXLength const & minus() const; + + + /// conversion + string const asString() const; + /// + string const asLatexString() const; + + + /** If "data" is valid, the length represented by it is + stored into "result", if that is not 0. */ + friend bool isValidGlueLength(string const & data, + LyXGlueLength* result = 0); + +private: + /// the normal vlaue + LyXLength len_; + /// extra stretch + LyXLength plus_; + /// extra shrink + LyXLength minus_; +}; + +/// +bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2); +/// +bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2); +/// +bool isValidGlueLength(string const & data, LyXGlueLength * result); + +#endif diff --git a/src/lyxlength.C b/src/lyxlength.C new file mode 100644 index 0000000000..8f782873bc --- /dev/null +++ b/src/lyxlength.C @@ -0,0 +1,126 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "lyxlength.h" + +#include "Lsstream.h" + +namespace { +// this is now here and in lyxgluelength.C + +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%" }; + + +LyXLength::UNIT unitFromString(string const & data) +{ + int i = 0; + while (i < num_units && data != unit_name[i]) + ++i; + return static_cast(i); +} + +} + + +LyXLength::LyXLength() + : val_(0), unit_(LyXLength::PT) +{} + + +LyXLength::LyXLength(double v, LyXLength::UNIT u) + : val_(v), unit_(u) +{} + + +LyXLength::LyXLength(string const & data) +{ + LyXLength tmp; + + if (!isValidLength (data, &tmp)) + return; // should raise an exception + + val_ = tmp.val_; + unit_ = tmp.unit_; +} + + +string const LyXLength::asString() const +{ + ostringstream buffer; + buffer << val_ << unit_name[unit_]; // setw? + return buffer.str().c_str(); +} + + +string const LyXLength::asLatexString() const +{ + ostringstream buffer; + switch(unit_) { + case PW: + case PE: + buffer << abs(static_cast(val_/100)) << "." + << abs(static_cast(val_)%100) << "\\columnwidth"; + break; + case PP: + buffer << abs(static_cast(val_/100)) << "." + << abs(static_cast(val_)%100) << "\\pagewidth"; + break; + case PL: + buffer << abs(static_cast(val_/100)) << "." + << abs(static_cast(val_)%100) << "\\linewidth"; + break; + default: + buffer << val_ << unit_name[unit_]; // setw? + break; + } + return buffer.str().c_str(); +} + + +double LyXLength::value() const +{ + return val_; +} + + +LyXLength::UNIT LyXLength::unit() const +{ + return unit_; +} + + +void LyXLength::value(double v) +{ + val_ = v; +} + + +void LyXLength::unit(LyXLength::UNIT u) +{ + unit_ = u; +} + + +bool operator==(LyXLength const & l1, LyXLength const & l2) +{ + return l1.value() == l2.value() && l1.unit() == l2.unit(); +} diff --git a/src/lyxlength.h b/src/lyxlength.h new file mode 100644 index 0000000000..df31f95349 --- /dev/null +++ b/src/lyxlength.h @@ -0,0 +1,107 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#ifndef LYX_LENGTH_H +#define LYX_LENGTH_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "LString.h" + +// +/// LyXLength Class +// +class LyXLength { +public: + /// length units + enum UNIT { + /// Scaled point (65536sp = 1pt) TeX's smallest unit. + SP, + /// Point = 1/72.27in = 0.351mm + PT, + /// Big point (72bp = 1in), also PostScript point + BP, + /// Didot point = 1/72 of a French inch, = 0.376mm + DD, + /// Millimeter = 2.845pt + MM, + /// Pica = 12pt = 4.218mm + PC, + /// Cicero = 12dd = 4.531mm + CC, + /// Centimeter = 10mm = 2.371pc + CM, + /// Inch = 25.4mm = 72.27pt = 6.022pc + IN, + /// Height of a small "x" for the current font. + EX, + /// Width of capital "M" in current font. + EM, + /// Math unit (18mu = 1em) for positioning in math mode + MU, + /// Percent of columnwidth both "%" or "%c" + PW, + /// + PE, + /// Percent of pagewidth + PP, + /// Percent of linewidth + PL, + /// no unit + UNIT_NONE + }; + + /// + LyXLength(); + /// + LyXLength(double v, LyXLength::UNIT u); + + /// "data" must be a decimal number, followed by a unit + explicit LyXLength(string const & data); + + /// + double value() const; + /// + LyXLength::UNIT unit() const; + /// + void value(double); + /// + void unit(LyXLength::UNIT unit); + + /// real length in SP + //void lenght(); + + /// conversion + string const asString() const; + /// + string const asLatexString() const; + + /** If "data" is valid, the length represented by it is + stored into "result", if that is not 0. */ + friend bool isValidLength(string const & data, LyXLength * result = 0); + +private: + /// + double val_; + /// + LyXLength::UNIT unit_; +}; + +/// +bool operator==(LyXLength const & l1, LyXLength const & l2); +/// +bool isValidLength(string const & data, LyXLength * result); +/// +char const * stringFromUnit(int unit); + +#endif diff --git a/src/vspace.C b/src/vspace.C index 247bb6d3e4..ed2a81600e 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -11,10 +11,11 @@ #include #ifdef __GNUG__ -#pragma implementation "vspace.h" +#pragma implementation #endif #include "vspace.h" +#include "lengthcommon.h" #include "lyx_main.h" #include "buffer.h" #include "lyxrc.h" @@ -28,6 +29,7 @@ namespace { +#if 0 /* length units */ @@ -51,6 +53,23 @@ LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE, int number_index; int unit_index; +LyXLength::UNIT unitFromString(string const & data) +{ + int i = 0; + while (i < num_units && data != unit_name[i]) + ++i; + return static_cast(i); +} + +#endif +double number[4] = { 0, 0, 0, 0 }; +LyXLength::UNIT unit[4] = { LyXLength::UNIT_NONE, + LyXLength::UNIT_NONE, + LyXLength::UNIT_NONE, + LyXLength::UNIT_NONE }; + +int number_index; +int unit_index; inline void lyx_advance(string & data, string::size_type n) @@ -165,6 +184,7 @@ LaTeXLength table[] = { { "", 0, 0, 0, 0 } // sentinel, must be empty }; + } // namespace anon const char * stringFromUnit(int unit) @@ -242,12 +262,12 @@ bool isValidGlueLength(string const & data, LyXGlueLength * result) // is zero, the corresponding array value is zero or UNIT_NONE, // so we needn't check this. if (result) { - result->val_ = number[1] * val_sign; - result->unit_ = unit[1]; - result->plus_val_ = number[table[table_index].plus_val_index]; - result->minus_val_ = number[table[table_index].minus_val_index]; - result->plus_unit_ = unit [table[table_index].plus_uni_index]; - result->minus_unit_ = unit [table[table_index].minus_uni_index]; + result->len_.value (number[1] * val_sign); + result->len_.unit (unit[1]); + result->plus_.value (number[table[table_index].plus_val_index]); + result->plus_.unit (unit [table[table_index].plus_uni_index]); + result->minus_.value(number[table[table_index].minus_val_index]); + result->minus_.unit (unit [table[table_index].minus_uni_index]); } return true; } @@ -309,276 +329,32 @@ bool isValidLength(string const & data, LyXLength * result) } - - -// -// LyXLength -// - -LyXLength::LyXLength() - : val_(0), unit_(LyXLength::PT) -{} - - -LyXLength::LyXLength(double v, LyXLength::UNIT u) - : val_(v), unit_(u) -{} - - -LyXLength::LyXLength(string const & data) -{ - LyXLength tmp; - - if (!isValidLength (data, &tmp)) - return; // should raise an exception - - val_ = tmp.val_; - unit_ = tmp.unit_; -} - - -string const LyXLength::asString() const -{ - ostringstream buffer; - buffer << val_ << unit_name[unit_]; // setw? - return buffer.str().c_str(); -} - - -string const LyXLength::asLatexString() const -{ - ostringstream buffer; - switch(unit_) { - case PW: - case PE: - buffer << abs(static_cast(val_/100)) << "." - << abs(static_cast(val_)%100) << "\\columnwidth"; - break; - case PP: - buffer << abs(static_cast(val_/100)) << "." - << abs(static_cast(val_)%100) << "\\pagewidth"; - break; - case PL: - buffer << abs(static_cast(val_/100)) << "." - << abs(static_cast(val_)%100) << "\\linewidth"; - break; - default: - buffer << val_ << unit_name[unit_]; // setw? - break; - } - return buffer.str().c_str(); -} - - -double LyXLength::value() const -{ - return val_; -} - - -LyXLength::UNIT LyXLength::unit() const -{ - return unit_; -} - - -bool operator==(LyXLength const & l1, LyXLength const & l2) -{ - return l1.value() == l2.value() && l1.unit() == l2.unit(); -} - - -LyXLength::UNIT unitFromString (string const & data) -{ - int i = 0; - while (i < num_units && data != unit_name[i]) - ++i; - return static_cast(i); -} - - - -// -// LyXGlueLength -// - - -LyXGlueLength::LyXGlueLength( - double v, LyXLength::UNIT u, - double pv, LyXLength::UNIT pu, - double mv, LyXLength::UNIT mu) - : LyXLength(v, u), - plus_val_(pv), minus_val_(mv), - plus_unit_(pu), minus_unit_(mu) -{} - - -LyXGlueLength::LyXGlueLength(string const & data) -{ - LyXGlueLength tmp(0.0, PT); - - // we should really raise exception here - if (!isValidGlueLength(data, &tmp)) - ; - - val_ = tmp.val_; - unit_ = tmp.unit_; - plus_val_ = tmp.plus_val_; - plus_unit_ = tmp.plus_unit_; - minus_val_ = tmp.minus_val_; - minus_unit_ = tmp.minus_unit_; -} - - -string const LyXGlueLength::asString() const -{ - ostringstream buffer; - - if (plus_val_ != 0.0) - if (minus_val_ != 0.0) - if (unit_ == plus_unit_ && unit_ == minus_unit_) - if (plus_val_ == minus_val_) - buffer << val_ << "+-" - << plus_val_ << unit_name[unit_]; - else - buffer << val_ - << '+' << plus_val_ - << '-' << minus_val_ - << unit_name[unit_]; - else - if (plus_unit_ == minus_unit_ - && plus_val_ == minus_val_) - buffer << val_ << unit_name[unit_] - << "+-" << plus_val_ - << unit_name[plus_unit_]; - - else - buffer << val_ << unit_name[unit_] - << '+' << plus_val_ - << unit_name[plus_unit_] - << '-' << minus_val_ - << unit_name[minus_unit_]; - else - if (unit_ == plus_unit_) - buffer << val_ << '+' << plus_val_ - << unit_name[unit_]; - else - buffer << val_ << unit_name[unit_] - << '+' << plus_val_ - << unit_name[plus_unit_]; - - else - if (minus_val_ != 0.0) - if (unit_ == minus_unit_) - buffer << val_ << '-' << minus_val_ - << unit_name[unit_]; - - else - buffer << val_ << unit_name[unit_] - << '-' << minus_val_ - << unit_name[minus_unit_]; - else - buffer << val_ << unit_name[unit_]; - - return buffer.str().c_str(); -} - - -string const LyXGlueLength::asLatexString() const -{ - ostringstream buffer; - - if (plus_val_ != 0.0) - if (minus_val_ != 0.0) - buffer << val_ << unit_name[unit_] - << " plus " - << plus_val_ << unit_name[plus_unit_] - << " minus " - << minus_val_ << unit_name[minus_unit_]; - else - buffer << val_ << unit_name[unit_] - << " plus " - << plus_val_ << unit_name[plus_unit_]; - else - if (minus_val_ != 0.0) - buffer << val_ << unit_name[unit_] - << " minus " - << minus_val_ << unit_name[minus_unit_]; - else - buffer << val_ << unit_name[unit_]; - - return buffer.str().c_str(); -} - - -double LyXGlueLength::plusValue() const -{ - return plus_val_; -} - - -LyXLength::UNIT LyXGlueLength::plusUnit() const -{ - return plus_unit_; -} - - -double LyXGlueLength::minusValue() const -{ - return minus_val_; -} - - -LyXLength::UNIT LyXGlueLength::minusUnit() const -{ - return minus_unit_; -} - - -bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2) -{ - return l1.value() == l2.value() - && l1.unit() == l2.unit() - && l1.plusValue() == l2.plusValue() - && l1.plusUnit() == l2.plusUnit() - && l1.minusValue() == l2.minusValue() - && l1.minusUnit() == l2.minusUnit(); -} - - -bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2) -{ - return !(l1 == l2); -} - - - // // VSpace class // VSpace::VSpace() - : kind_(NONE), len_(0.0, LyXLength::PT), keep_(false) + : kind_(NONE), len_(), keep_(false) {} VSpace::VSpace(vspace_kind k) - : kind_(k), len_(0.0, LyXLength::PT), keep_(false) + : kind_(k), len_(), keep_(false) {} -VSpace::VSpace(LyXGlueLength l) +VSpace::VSpace(LyXLength const & l) : kind_(LENGTH), len_(l), keep_(false) {} -VSpace::VSpace(double v, LyXLength::UNIT u) - : kind_(LENGTH), len_(v, u), keep_(false) +VSpace::VSpace(LyXGlueLength const & l) + : kind_(LENGTH), len_(l), keep_(false) {} VSpace::VSpace(string const & data) - : kind_(NONE), len_(0.0, LyXLength::PT), keep_(false) + : kind_(NONE), len_(), keep_(false) { if (data.empty()) return; @@ -603,7 +379,7 @@ VSpace::VSpace(string const & data) // without units in added_space_top/bottom. // Let unit default to centimeters here. kind_ = LENGTH; - len_ = LyXGlueLength(value, LyXLength::CM); + len_ = LyXGlueLength(LyXLength(value, LyXLength::CM)); } } @@ -689,20 +465,13 @@ string const VSpace::asLatexCommand(BufferParams const & params) const int VSpace::inPixels(BufferView * bv) const { // Height of a normal line in pixels (zoom factor considered) - int height = bv->text->defaultHeight(); // [pixels] - int skip = 0; - int width = bv->workWidth(); + int default_height = bv->text->defaultHeight(); // [pixels] + int default_skip = 0; + int default_width = bv->workWidth(); if (kind_ == DEFSKIP) - skip = bv->buffer()->params.getDefSkip().inPixels(bv); + default_skip = bv->buffer()->params.getDefSkip().inPixels(bv); - return inPixels(height, skip, width); -} - - -int VSpace::inPixels(int default_height, int default_skip, int default_width) - const -{ // Height of a normal line in pixels (zoom factor considered) int height = default_height; // [pixels] @@ -739,10 +508,10 @@ int VSpace::inPixels(int default_height, int default_skip, int default_width) // we don't care about sign of value, we // display negative space with text too result = 0.0; - value = len_.value(); + value = len_.len().value(); int val_sign = value < 0.0 ? -1 : 1; - switch (len_.unit()) { + switch (len_.len().unit()) { case LyXLength::SP: // Scaled point: sp = 1/65536 pt result = zoom * dpi * value diff --git a/src/vspace.h b/src/vspace.h index 9d783909f6..266e04196d 100644 --- a/src/vspace.h +++ b/src/vspace.h @@ -16,158 +16,15 @@ #pragma interface #endif +#include "lyxgluelength.h" + #include "LString.h" class BufferParams; class BufferView; -// -/// LyXLength Class -// -class LyXLength { -public: - /// length units - enum UNIT { - /// Scaled point (65536sp = 1pt) TeX's smallest unit. - SP, - /// Point = 1/72.27in = 0.351mm - PT, - /// Big point (72bp = 1in), also PostScript point - BP, - /// Didot point = 1/72 of a French inch, = 0.376mm - DD, - /// Millimeter = 2.845pt - MM, - /// Pica = 12pt = 4.218mm - PC, - /// Cicero = 12dd = 4.531mm - CC, - /// Centimeter = 10mm = 2.371pc - CM, - /// Inch = 25.4mm = 72.27pt = 6.022pc - IN, - /// Height of a small "x" for the current font. - EX, - /// Width of capital "M" in current font. - EM, - /// Math unit (18mu = 1em) for positioning in math mode - MU, - /// Percent of columnwidth both "%" or "%c" - PW, - /// - PE, - /// Percent of pagewidth - PP, - /// Percent of linewidth - PL, - /// no unit - UNIT_NONE - }; - - /// - LyXLength(); - /// - LyXLength(double v, LyXLength::UNIT u); - - /// "data" must be a decimal number, followed by a unit - explicit LyXLength(string const & data); - - /// - double value() const; - /// - LyXLength::UNIT unit() const; - - /// conversion - virtual string const asString() const; - /// - virtual string const asLatexString() const; - - /** If "data" is valid, the length represented by it is - stored into "result", if that is not 0. */ - friend bool isValidLength(string const & data, LyXLength * result = 0); - -protected: - /// - double val_; - /// - LyXLength::UNIT unit_; -}; - -/// -bool operator==(LyXLength const & l1, LyXLength const & l2); -/// -LyXLength::UNIT unitFromString (string const & data); -/// -bool isValidLength(string const & data, LyXLength * result); -/// -const char * stringFromUnit(int unit); - - - -// -/// LyXGlueLength class -// -class LyXGlueLength : public LyXLength { -public: - /// - LyXGlueLength(double v, - LyXLength::UNIT u, - double pv = 0.0, - LyXLength::UNIT pu = LyXLength::UNIT_NONE, - double mv = 0.0, - LyXLength::UNIT mu = LyXLength::UNIT_NONE); - - /** "data" must be a decimal number, followed by a unit, and - optional "glue" indicated by "+" and "-". You may abbreviate - reasonably. Examples: - 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm - The traditional Latex format is also accepted, like - 4cm plus 10pt minus 10pt */ - explicit LyXGlueLength(string const & data); - - /// - double plusValue() const; - /// - LyXLength::UNIT plusUnit() const; - /// - double minusValue() const; - /// - LyXLength::UNIT minusUnit() const; - - /// conversion - virtual string const asString() const; - /// - virtual string const asLatexString() const; - - - /** If "data" is valid, the length represented by it is - stored into "result", if that is not 0. */ - friend bool isValidGlueLength(string const & data, - LyXGlueLength* result = 0); - -protected: - /// - double plus_val_; - /// - double minus_val_; - /// - LyXLength::UNIT plus_unit_; - /// - LyXLength::UNIT minus_unit_; -}; - -/// -bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2); -/// -bool operator!=(LyXGlueLength const & l1, LyXGlueLength const & l2); /// -bool isValidGlueLength(string const & data, LyXGlueLength * result); - - -// -/// VSpace class -// class VSpace { public: /// The different kinds of spaces. @@ -192,9 +49,9 @@ public: /// Constructor explicit VSpace(vspace_kind k); /// Constructor - explicit VSpace(LyXGlueLength l); + explicit VSpace(LyXLength const & l); /// Constructor - explicit VSpace(double v, LyXLength::UNIT u); + explicit VSpace(LyXGlueLength const & l); /// Constructor for reading from a .lyx file explicit VSpace(string const & data); @@ -202,7 +59,7 @@ public: /// access functions vspace_kind kind() const; /// - LyXGlueLength length() const; + LyXGlueLength length() const; // a flag that switches between \vspace and \vspace* bool keep() const; @@ -218,8 +75,6 @@ public: string const asLatexCommand(BufferParams const & params) const; /// int inPixels(BufferView * bv) const; - /// - int inPixels(int default_height, int default_skip, int default_width=0) const; private: /// This VSpace kind vspace_kind kind_; -- 2.39.2