mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 00:10:59 +00:00
Rewrite mathindent without HSpace class
Use Length instead of HSpace for math_indentation and rename it to mathindent. Get rid of the string version. Rename (g|s)etMathIndentation() to (g|s)etMathIndent(). Remove the HSpace class altogether. Some cleanups to parindent support to look like mathindent.
This commit is contained in:
parent
d86954eb81
commit
df6b2f4470
@ -916,7 +916,6 @@ int Buffer::readHeader(Lexer & lex)
|
||||
params().headheight.erase();
|
||||
params().headsep.erase();
|
||||
params().footskip.erase();
|
||||
params().math_indentation.erase();
|
||||
params().columnsep.erase();
|
||||
params().fonts_cjk.erase();
|
||||
params().listings_params.clear();
|
||||
|
@ -28,11 +28,11 @@
|
||||
#include "ColorSet.h"
|
||||
#include "Converter.h"
|
||||
#include "Encoding.h"
|
||||
#include "HSpace.h"
|
||||
#include "IndicesList.h"
|
||||
#include "Language.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "LaTeXFonts.h"
|
||||
#include "Length.h"
|
||||
#include "ModuleList.h"
|
||||
#include "Font.h"
|
||||
#include "Lexer.h"
|
||||
@ -338,11 +338,11 @@ public:
|
||||
IndicesList indiceslist;
|
||||
Spacing spacing;
|
||||
Length parindent;
|
||||
Length mathindent;
|
||||
/** This is the amount of space used for paragraph_separation "skip",
|
||||
* and for detached paragraphs in "indented" documents.
|
||||
*/
|
||||
VSpace defskip;
|
||||
HSpace math_indentation;
|
||||
PDFOptions pdfoptions;
|
||||
LayoutFileIndex baseClass_;
|
||||
FormatList exportableFormatList;
|
||||
@ -385,7 +385,6 @@ BufferParams::BufferParams()
|
||||
makeDocumentClass();
|
||||
paragraph_separation = ParagraphIndentSeparation;
|
||||
is_math_indent = false;
|
||||
math_indentation = "default";
|
||||
quotes_style = InsetQuotesParams::EnglishQuotes;
|
||||
dynamic_quotes = false;
|
||||
fontsize = "default";
|
||||
@ -629,15 +628,15 @@ PDFOptions const & BufferParams::pdfoptions() const
|
||||
}
|
||||
|
||||
|
||||
HSpace const & BufferParams::getMathIndentation() const
|
||||
Length const & BufferParams::getMathIndent() const
|
||||
{
|
||||
return pimpl_->math_indentation;
|
||||
return pimpl_->mathindent;
|
||||
}
|
||||
|
||||
|
||||
void BufferParams::setMathIndentation(HSpace const & indent)
|
||||
void BufferParams::setMathIndent(Length const & indent)
|
||||
{
|
||||
pimpl_->math_indentation = indent;
|
||||
pimpl_->mathindent = indent;
|
||||
}
|
||||
|
||||
|
||||
@ -852,8 +851,7 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
lex >> is_math_indent;
|
||||
} else if (token == "\\math_indentation") {
|
||||
lex.next();
|
||||
string math_indentation = lex.getString();
|
||||
pimpl_->math_indentation = HSpace(math_indentation);
|
||||
pimpl_->mathindent = Length(lex.getString());
|
||||
} else if (token == "\\quotes_style") {
|
||||
string qstyle;
|
||||
lex >> qstyle;
|
||||
@ -1348,12 +1346,12 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
|
||||
<< string_paragraph_separation[paragraph_separation];
|
||||
if (!paragraph_separation)
|
||||
os << "\n\\paragraph_indentation "
|
||||
<< (pimpl_->parindent.empty() ? "default" : pimpl_->parindent.asString());
|
||||
<< (getParIndent().empty() ? "default" : getParIndent().asString());
|
||||
else
|
||||
os << "\n\\defskip " << getDefSkip().asLyXCommand();
|
||||
os << "\n\\is_math_indent " << is_math_indent;
|
||||
if (is_math_indent && getMathIndentation().asLyXCommand() != "default")
|
||||
os << "\n\\math_indentation " << getMathIndentation().asLyXCommand();
|
||||
if (is_math_indent && !getMathIndent().empty())
|
||||
os << "\n\\math_indentation " << getMathIndent().asString();
|
||||
os << "\n\\quotes_style "
|
||||
<< string_quotes_style[quotes_style]
|
||||
<< "\n\\dynamic_quotes " << dynamic_quotes
|
||||
@ -1965,9 +1963,9 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
|
||||
if (is_math_indent) {
|
||||
// when formula indentation
|
||||
// only output something when it is not the default
|
||||
if (getMathIndentation().asLyXCommand() != "default") {
|
||||
if (!getMathIndent().empty()) {
|
||||
os << "\\setlength{\\mathindent}{"
|
||||
<< from_utf8(getMathIndentation().asLatexCommand())
|
||||
<< from_utf8(getMathIndent().asString())
|
||||
<< "}\n";
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ class Bullet;
|
||||
class DocumentClass;
|
||||
class Encoding;
|
||||
class Font;
|
||||
class HSpace;
|
||||
class IndicesList;
|
||||
class Language;
|
||||
class LayoutFile;
|
||||
@ -103,16 +102,13 @@ public:
|
||||
void setDefSkip(VSpace const & vs);
|
||||
|
||||
///
|
||||
HSpace const & getMathIndentation() const;
|
||||
Length const & getMathIndent() const;
|
||||
///
|
||||
void setMathIndentation(HSpace const & indent);
|
||||
void setMathIndent(Length const & indent);
|
||||
|
||||
/// Whether formulas are indented
|
||||
bool is_math_indent;
|
||||
|
||||
/// the indentation of formulas
|
||||
std::string math_indentation;
|
||||
|
||||
/** Whether paragraphs are separated by using a indent like in
|
||||
* articles or by using a little skip like in letters.
|
||||
*/
|
||||
|
159
src/HSpace.cpp
159
src/HSpace.cpp
@ -1,159 +0,0 @@
|
||||
/**
|
||||
* \file HSpace.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Jürgen Spitzmüller
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "HSpace.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "support/gettext.h"
|
||||
#include "Length.h"
|
||||
#include "Text.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include "support/lassert.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
HSpace::HSpace()
|
||||
: kind_(DEFAULT), len_()
|
||||
{}
|
||||
|
||||
|
||||
HSpace::HSpace(HSpaceKind k)
|
||||
: kind_(k), len_()
|
||||
{}
|
||||
|
||||
|
||||
HSpace::HSpace(Length const & l)
|
||||
: kind_(LENGTH), len_(l)
|
||||
{}
|
||||
|
||||
|
||||
HSpace::HSpace(GlueLength const & l)
|
||||
: kind_(LENGTH), len_(l)
|
||||
{}
|
||||
|
||||
|
||||
HSpace::HSpace(string const & data)
|
||||
: kind_(DEFAULT), len_()
|
||||
{
|
||||
if (data.empty())
|
||||
return;
|
||||
|
||||
string input = rtrim(data);
|
||||
|
||||
if (prefixIs(input, "default"))
|
||||
kind_ = DEFAULT;
|
||||
else if (isValidGlueLength(input, &len_))
|
||||
kind_ = LENGTH;
|
||||
}
|
||||
|
||||
|
||||
bool HSpace::operator==(HSpace const & other) const
|
||||
{
|
||||
if (kind_ != other.kind_)
|
||||
return false;
|
||||
if (len_ != other.len_)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string const HSpace::asLyXCommand() const
|
||||
{
|
||||
string result;
|
||||
switch (kind_) {
|
||||
case DEFAULT:
|
||||
result = "default";
|
||||
break;
|
||||
case LENGTH:
|
||||
result = len_.asString();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string const HSpace::asLatexCommand() const
|
||||
{
|
||||
switch (kind_) {
|
||||
case DEFAULT:
|
||||
return string();
|
||||
case LENGTH:
|
||||
return len_.asLatexString();
|
||||
default:
|
||||
LATTEST(false);
|
||||
// fall through in release mode
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
|
||||
docstring const HSpace::asGUIName() const
|
||||
{
|
||||
docstring result;
|
||||
switch (kind_) {
|
||||
case DEFAULT:
|
||||
result = _("Default");
|
||||
break;
|
||||
case LENGTH:
|
||||
result = from_ascii(len_.asString());
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string HSpace::asHTMLLength() const
|
||||
{
|
||||
string result;
|
||||
switch (kind_) {
|
||||
case DEFAULT:
|
||||
// 30pt are LaTeX's default
|
||||
result = "30pt";
|
||||
break;
|
||||
case LENGTH: {
|
||||
Length tmp = len_.len();
|
||||
if (tmp.value() > 0)
|
||||
result = tmp.asHTMLString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int HSpace::inPixels(BufferView const & bv) const
|
||||
{
|
||||
switch (kind_) {
|
||||
case DEFAULT:
|
||||
// FIXME: replace by correct length
|
||||
return bv.buffer().params().getParIndent().inPixels(bv.workWidth());
|
||||
case LENGTH:
|
||||
return len_.len().inPixels(bv.workWidth());
|
||||
default:
|
||||
LATTEST(false);
|
||||
// fall through in release mode
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
78
src/HSpace.h
78
src/HSpace.h
@ -1,78 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file HSpace.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Jürgen Spitzmüller
|
||||
* \author Uwe Stöhr
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef HSPACE_H
|
||||
#define HSPACE_H
|
||||
|
||||
#include "Length.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
class BufferParams;
|
||||
class BufferView;
|
||||
|
||||
|
||||
/// A class representing latex horizontal spacing
|
||||
class HSpace {
|
||||
public:
|
||||
/// The different kinds of spaces.
|
||||
enum HSpaceKind {
|
||||
DEFAULT,
|
||||
LENGTH ///< user-defined length
|
||||
};
|
||||
|
||||
///
|
||||
HSpace();
|
||||
///
|
||||
explicit HSpace(HSpaceKind k);
|
||||
///
|
||||
explicit HSpace(Length const & l);
|
||||
///
|
||||
explicit HSpace(GlueLength const & l);
|
||||
|
||||
/// Constructor for reading from a .lyx file
|
||||
explicit HSpace(std::string const & data);
|
||||
|
||||
/// return the type of vertical space
|
||||
HSpaceKind kind() const { return kind_; }
|
||||
/// return the length of this space
|
||||
GlueLength const & length() const { return len_; }
|
||||
|
||||
///
|
||||
bool operator==(HSpace const &) const;
|
||||
|
||||
// conversion
|
||||
|
||||
/// how it goes into the LyX file
|
||||
std::string const asLyXCommand() const;
|
||||
/// the latex representation
|
||||
std::string const asLatexCommand() const;
|
||||
///
|
||||
std::string asHTMLLength() const;
|
||||
/// how it is seen in the LyX window
|
||||
docstring const asGUIName() const;
|
||||
/// the size of the space on-screen
|
||||
int inPixels(BufferView const & bv) const;
|
||||
|
||||
private:
|
||||
/// This HSpace kind
|
||||
HSpaceKind kind_;
|
||||
/// the specified length
|
||||
GlueLength len_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif // HSPACE_H
|
@ -134,7 +134,6 @@ SOURCEFILESCORE = \
|
||||
FuncRequest.cpp \
|
||||
FuncStatus.cpp \
|
||||
Graph.cpp \
|
||||
HSpace.cpp \
|
||||
IndicesList.cpp \
|
||||
InsetIterator.cpp \
|
||||
InsetList.cpp \
|
||||
@ -237,7 +236,6 @@ HEADERFILESCORE = \
|
||||
FuncRequest.h \
|
||||
FuncStatus.h \
|
||||
Graph.h \
|
||||
HSpace.h \
|
||||
IndicesList.h \
|
||||
InsetIterator.h \
|
||||
InsetList.h \
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "CoordCache.h"
|
||||
#include "Cursor.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "HSpace.h"
|
||||
#include "InsetList.h"
|
||||
#include "Language.h"
|
||||
#include "Layout.h"
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include "FloatPlacement.h"
|
||||
#include "Format.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "HSpace.h"
|
||||
#include "IndicesList.h"
|
||||
#include "Language.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
@ -2903,13 +2902,10 @@ void GuiDocument::applyView()
|
||||
bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked();
|
||||
// if math is indented
|
||||
if (bp_.is_math_indent) {
|
||||
HSpace MathIndentation = HSpace(
|
||||
widgetsToLength(textLayoutModule->MathIndentLE,
|
||||
textLayoutModule->MathIndentLengthCO)
|
||||
);
|
||||
bp_.setMathIndentation(MathIndentation);
|
||||
Length mathindent(widgetsToLength(textLayoutModule->MathIndentLE,
|
||||
textLayoutModule->MathIndentLengthCO));
|
||||
bp_.setMathIndent(mathindent);
|
||||
}
|
||||
|
||||
// Page Layout
|
||||
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
|
||||
bp_.pagestyle = "default";
|
||||
@ -2955,14 +2951,12 @@ void GuiDocument::applyView()
|
||||
case 0:
|
||||
bp_.setParIndent(Length());
|
||||
break;
|
||||
case 1: {
|
||||
Length indent(
|
||||
widgetsToLength(textLayoutModule->indentLE,
|
||||
textLayoutModule->indentLengthCO)
|
||||
);
|
||||
bp_.setParIndent(indent);
|
||||
case 1: {
|
||||
Length parindent(widgetsToLength(textLayoutModule->indentLE,
|
||||
textLayoutModule->indentLengthCO));
|
||||
bp_.setParIndent(parindent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
// this should never happen
|
||||
bp_.setParIndent(Length());
|
||||
@ -3001,19 +2995,17 @@ void GuiDocument::applyView()
|
||||
// if formulas are indented
|
||||
switch (textLayoutModule->MathIndentCO->currentIndex()) {
|
||||
case 0:
|
||||
bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
|
||||
bp_.setMathIndent(Length());
|
||||
break;
|
||||
case 1: {
|
||||
HSpace MathIndent = HSpace(
|
||||
widgetsToLength(textLayoutModule->MathIndentLE,
|
||||
textLayoutModule->MathIndentLengthCO)
|
||||
);
|
||||
bp_.setMathIndentation(MathIndent);
|
||||
case 1: {
|
||||
Length mathindent(widgetsToLength(textLayoutModule->MathIndentLE,
|
||||
textLayoutModule->MathIndentLengthCO));
|
||||
bp_.setMathIndent(mathindent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
// this should never happen
|
||||
bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
|
||||
bp_.setMathIndent(Length());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3384,16 +3376,16 @@ void GuiDocument::paramsToDialog()
|
||||
// math
|
||||
if (bp_.is_math_indent) {
|
||||
textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent);
|
||||
string MathIndentation = bp_.getMathIndentation().asLyXCommand();
|
||||
int MathIndent = 0;
|
||||
if (MathIndentation != "default") {
|
||||
Length const mathindent = bp_.getMathIndent();
|
||||
int indent = 0;
|
||||
if (!mathindent.empty()) {
|
||||
lengthToWidgets(textLayoutModule->MathIndentLE,
|
||||
textLayoutModule->MathIndentLengthCO,
|
||||
MathIndentation, default_unit);
|
||||
MathIndent = 1;
|
||||
textLayoutModule->MathIndentLengthCO,
|
||||
mathindent, default_unit);
|
||||
indent = 1;
|
||||
}
|
||||
textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent);
|
||||
setMathIndent(MathIndent);
|
||||
textLayoutModule->MathIndentCO->setCurrentIndex(indent);
|
||||
setMathIndent(indent);
|
||||
}
|
||||
|
||||
map<string, string> const & packages = BufferParams::auto_packages();
|
||||
|
Loading…
Reference in New Issue
Block a user