move font related stuff from bufferview_funcs to Font

delete bufferview_funcs, since it's now empty


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20579 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-09-29 11:00:18 +00:00
parent 122f32ea29
commit 5aaf4dce20
14 changed files with 204 additions and 336 deletions

View File

@ -20,7 +20,6 @@
#include "buffer_funcs.h"
#include "BufferList.h"
#include "BufferParams.h"
#include "bufferview_funcs.h"
#include "callback.h" // added for Dispatch functions
#include "CoordCache.h"
#include "CutAndPaste.h"

View File

@ -15,7 +15,6 @@
#include "Bidi.h"
#include "BufferView.h"
#include "bufferview_funcs.h"
#include "Buffer.h"
#include "Cursor.h"
#include "CoordCache.h"

View File

@ -27,11 +27,14 @@
#include "output_latex.h"
#include "OutputParams.h"
#include "support/convert.h"
#include "support/lstrings.h"
using std::endl;
using std::string;
using std::ostream;
using std::ostringstream;
using std::istringstream;
using std::pair;
#ifndef CXX_GLOBAL_CSTD
@ -974,6 +977,99 @@ Color_color Font::realColor() const
}
std::string Font::toString(bool const toggle) const
{
string lang = "ignore";
if (language())
lang = language()->lang();
ostringstream os;
os << "family " << family() << '\n'
<< "series " << series() << '\n'
<< "shape " << shape() << '\n'
<< "size " << size() << '\n'
<< "emph " << emph() << '\n'
<< "underbar " << underbar() << '\n'
<< "noun " << noun() << '\n'
<< "number " << number() << '\n'
<< "color " << color() << '\n'
<< "language " << lang << '\n'
<< "toggleall " << convert<string>(toggle);
return os.str();
}
bool Font::fromString(string const & data, bool & toggle)
{
istringstream is(data);
Lexer lex(0,0);
lex.setStream(is);
int nset = 0;
while (lex.isOK()) {
string token;
if (lex.next())
token = lex.getString();
if (token.empty() || !lex.next())
break;
if (token == "family") {
int const next = lex.getInteger();
setFamily(FONT_FAMILY(next));
} else if (token == "series") {
int const next = lex.getInteger();
setSeries(FONT_SERIES(next));
} else if (token == "shape") {
int const next = lex.getInteger();
setShape(FONT_SHAPE(next));
} else if (token == "size") {
int const next = lex.getInteger();
setSize(FONT_SIZE(next));
} else if (token == "emph" || token == "underbar" ||
token == "noun" || token == "number") {
int const next = lex.getInteger();
FONT_MISC_STATE const misc = FONT_MISC_STATE(next);
if (token == "emph")
setEmph(misc);
else if (token == "underbar")
setUnderbar(misc);
else if (token == "noun")
setNoun(misc);
else if (token == "number")
setNumber(misc);
} else if (token == "color") {
int const next = lex.getInteger();
setColor(Color::color(next));
} else if (token == "language") {
string const next = lex.getString();
if (next == "ignore")
setLanguage(ignore_language);
else
setLanguage(languages.getLanguage(next));
} else if (token == "toggleall") {
toggle = lex.getBool();
} else {
// Unrecognised token
break;
}
++nset;
}
return (nset > 0);
}
ostream & operator<<(ostream & os, Font::FONT_MISC_STATE fms)
{
return os << int(fms);

View File

@ -25,13 +25,11 @@
namespace lyx {
class Lexer;
class BufferParams;
class Language;
class OutputParams;
///
class Font {
public:
@ -340,6 +338,11 @@ public:
return bits.shape;
}
/// Set \param data using \param font and \param toggle.
std::string toString(bool toggle) const;
/// Set \param font and \param toggle using \param data. Return success.
bool fromString(std::string const & data, bool & toggle);
/** Compaq cxx 6.5 requires that the definition be public so that
it can compile operator==()
@ -423,6 +426,11 @@ bool operator!=(Font const & font1, Font const & font2)
return !(font1 == font2);
}
/** Returns the current freefont, encoded as a std::string to be passed to the
* frontends.
*/
std::string const freefont2string();
} // namespace lyx

View File

@ -27,7 +27,6 @@
#include "Buffer.h"
#include "BufferList.h"
#include "BufferParams.h"
#include "bufferview_funcs.h"
#include "BufferView.h"
#include "callback.h"
#include "Color.h"
@ -116,8 +115,6 @@ namespace fs = boost::filesystem;
namespace lyx {
using bv_funcs::freefont2string;
using frontend::LyXView;
using support::absolutePath;
@ -151,8 +148,7 @@ namespace Alert = frontend::Alert;
namespace {
bool getLocalStatus(Cursor cursor,
FuncRequest const & cmd, FuncStatus & status)
bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
{
// Try to fix cursor in case it is broken.
cursor.fixIfBroken();

View File

@ -94,8 +94,6 @@ liblyxcore_la_SOURCES = \
BufferParams.cpp \
BufferParams.h \
BufferView.cpp \
bufferview_funcs.cpp \
bufferview_funcs.h \
BufferView.h \
Bullet.cpp \
Bullet.h \

View File

@ -25,7 +25,6 @@
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "bufferview_funcs.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "debug.h"
@ -90,15 +89,13 @@ namespace frontend {
extern docstring current_layout;
}
namespace {
// globals...
static Font freefont(Font::ALL_IGNORE);
static bool toggleall = false;
// globals...
Font freefont(Font::ALL_IGNORE);
bool toggleall = false;
void toggleAndShow(Cursor & cur, Text * text,
static void toggleAndShow(Cursor & cur, Text * text,
Font const & font, bool toggleall = true)
{
{
text->toggleFree(cur, font, toggleall);
if (font.language() != ignore_language ||
@ -109,25 +106,25 @@ namespace {
text->setCursor(cur, cur.pit(), cur.pos(),
false, !cur.boundary());
}
}
}
void moveCursor(Cursor & cur, bool selecting)
{
static void moveCursor(Cursor & cur, bool selecting)
{
if (selecting || cur.mark())
cur.setSelection();
}
}
void finishChange(Cursor & cur, bool selecting)
{
static void finishChange(Cursor & cur, bool selecting)
{
finishUndo();
moveCursor(cur, selecting);
}
}
void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
{
static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
{
recordUndo(cur);
docstring sel = cur.selectionAsString(false);
@ -174,28 +171,10 @@ namespace {
}
}
cur.message(from_utf8(N_("Math editor mode")));
}
} // namespace anon
namespace bv_funcs {
string const freefont2string()
{
string data;
if (font2string(freefont, toggleall, data))
return data;
return string();
}
}
namespace {
void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
{
recordUndo(cur);
cap::replaceSelection(cur);
@ -204,7 +183,7 @@ void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
}
bool doInsertInset(Cursor & cur, Text * text,
static bool doInsertInset(Cursor & cur, Text * text,
FuncRequest const & cmd, bool edit, bool pastesel)
{
Inset * inset = createInset(&cur.bv(), cmd);
@ -235,7 +214,10 @@ bool doInsertInset(Cursor & cur, Text * text,
}
} // anon namespace
string const freefont2string()
{
return freefont.toString(toggleall);
}
void Text::number(Cursor & cur)
@ -1364,7 +1346,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_FONT_FREE_UPDATE: {
Font font;
bool toggle;
if (bv_funcs::string2font(to_utf8(cmd.argument()), font, toggle)) {
if (font.fromString(to_utf8(cmd.argument()), toggle)) {
freefont = font;
toggleall = toggle;
toggleAndShow(cur, this, freefont, toggleall);

View File

@ -24,7 +24,6 @@
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "bufferview_funcs.h"
#include "Color.h"
#include "CutAndPaste.h"
#include "debug.h"

View File

@ -1,153 +0,0 @@
/**
* \file bufferview_funcs.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author John Levon
* \author Angus Leeming
* \author Juergen Vigna
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "bufferview_funcs.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Cursor.h"
#include "CoordCache.h"
#include "gettext.h"
#include "Language.h"
#include "Color.h"
#include "Lexer.h"
#include "frontends/alert.h"
#include "insets/InsetCommand.h"
#include "insets/InsetText.h"
#include "support/convert.h"
#include <sstream>
using std::istringstream;
using std::ostringstream;
using std::string;
using std::vector;
using std::find;
namespace lyx {
using support::bformat;
namespace bv_funcs {
// Set data using font and toggle
// If successful, returns true
bool font2string(Font const & font, bool const toggle, string & data)
{
string lang = "ignore";
if (font.language())
lang = font.language()->lang();
ostringstream os;
os << "family " << font.family() << '\n'
<< "series " << font.series() << '\n'
<< "shape " << font.shape() << '\n'
<< "size " << font.size() << '\n'
<< "emph " << font.emph() << '\n'
<< "underbar " << font.underbar() << '\n'
<< "noun " << font.noun() << '\n'
<< "number " << font.number() << '\n'
<< "color " << font.color() << '\n'
<< "language " << lang << '\n'
<< "toggleall " << convert<string>(toggle);
data = os.str();
return true;
}
// Set font and toggle using data
// If successful, returns true
bool string2font(string const & data, Font & font, bool & toggle)
{
istringstream is(data);
Lexer lex(0,0);
lex.setStream(is);
int nset = 0;
while (lex.isOK()) {
string token;
if (lex.next())
token = lex.getString();
if (token.empty() || !lex.next())
break;
if (token == "family") {
int const next = lex.getInteger();
font.setFamily(Font::FONT_FAMILY(next));
} else if (token == "series") {
int const next = lex.getInteger();
font.setSeries(Font::FONT_SERIES(next));
} else if (token == "shape") {
int const next = lex.getInteger();
font.setShape(Font::FONT_SHAPE(next));
} else if (token == "size") {
int const next = lex.getInteger();
font.setSize(Font::FONT_SIZE(next));
} else if (token == "emph" || token == "underbar" ||
token == "noun" || token == "number") {
int const next = lex.getInteger();
Font::FONT_MISC_STATE const misc =
Font::FONT_MISC_STATE(next);
if (token == "emph")
font.setEmph(misc);
else if (token == "underbar")
font.setUnderbar(misc);
else if (token == "noun")
font.setNoun(misc);
else if (token == "number")
font.setNumber(misc);
} else if (token == "color") {
int const next = lex.getInteger();
font.setColor(Color::color(next));
} else if (token == "language") {
string const next = lex.getString();
if (next == "ignore")
font.setLanguage(ignore_language);
else
font.setLanguage(languages.getLanguage(next));
} else if (token == "toggleall") {
toggle = lex.getBool();
} else {
// Unrecognised token
break;
}
++nset;
}
return (nset > 0);
}
} // namespace bv_funcs
} // namespace lyx

View File

@ -1,41 +0,0 @@
// -*- C++ -*-
/**
* \file bufferview_funcs.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#ifndef BUFFERVIEW_FUNCS_H
#define BUFFERVIEW_FUNCS_H
#include <string>
namespace lyx {
class Font;
namespace bv_funcs {
/// Set \param data using \param font and \param toggle. Return success.
bool font2string(Font const & font, bool toggle, std::string & data);
/// Set \param font and \param toggle using \param data. Return success.
bool string2font(std::string const & data, Font & font, bool & toggle);
/** Returns the current freefont, encoded as a std::string to be passed to the
* frontends.
*/
std::string const freefont2string();
} // namespace bv_funcs
} // namespace lyx
#endif

View File

@ -23,7 +23,6 @@
#include "BufferList.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "bufferview_funcs.h"
#include "Cursor.h"
#include "debug.h"
#include "ErrorList.h"

View File

@ -14,12 +14,10 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "bufferview_funcs.h"
#include "FuncRequest.h"
#include "Language.h"
#include "Color.h"
using lyx::bv_funcs::font2string;
using std::string;
namespace lyx {
@ -62,17 +60,14 @@ void ControlCharacter::dispatchParams()
if (!font_)
return;
string data;
if (font2string(*font_, toggleall_, data))
string data = font_->toString(toggleall_);
dispatch(FuncRequest(getLfun(), data));
}
Font::FONT_FAMILY ControlCharacter::getFamily() const
{
if (!font_)
return Font::IGNORE_FAMILY;
return font_->family();
return font_ ? font_->family() : Font::IGNORE_FAMILY;
}
@ -84,9 +79,7 @@ void ControlCharacter::setFamily(Font::FONT_FAMILY val)
Font::FONT_SERIES ControlCharacter::getSeries() const
{
if (!font_)
return Font::IGNORE_SERIES;
return font_->series();
return font_ ? font_->series() : Font::IGNORE_SERIES;
}
@ -98,9 +91,7 @@ void ControlCharacter::setSeries(Font::FONT_SERIES val)
Font::FONT_SHAPE ControlCharacter::getShape() const
{
if (!font_)
return Font::IGNORE_SHAPE;
return font_->shape();
return font_ ? font_->shape() : Font::IGNORE_SHAPE;
}
@ -112,9 +103,7 @@ void ControlCharacter::setShape(Font::FONT_SHAPE val)
Font::FONT_SIZE ControlCharacter::getSize() const
{
if (!font_)
return Font::IGNORE_SIZE;
return font_->size();
return font_ ? font_->size() : Font::IGNORE_SIZE;
}
@ -138,9 +127,9 @@ FONT_STATE ControlCharacter::getBar() const
if (font_->noun() == Font::TOGGLE)
return NOUN_TOGGLE;
if (font_->emph() == Font::IGNORE &&
font_->underbar() == Font::IGNORE &&
font_->noun() == Font::IGNORE)
if (font_->emph() == Font::IGNORE
&& font_->underbar() == Font::IGNORE
&& font_->noun() == Font::IGNORE)
return IGNORE;
return INHERIT;

View File

@ -25,9 +25,6 @@
#include "MathSupport.h"
#include "InsetMathRef.h"
#include "bufferview_funcs.h"
#include "Text.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "BufferView.h"
@ -43,6 +40,7 @@
#include "LyXRC.h"
#include "OutputParams.h"
#include "sgml.h"
#include "Text.h"
#include "TextPainter.h"
#include "Undo.h"
@ -1304,7 +1302,7 @@ void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
recordUndo(cur);
Font font;
bool b;
bv_funcs::string2font(to_utf8(arg), font, b);
font.fromString(to_utf8(arg), b);
if (font.color() != Color::inherit) {
MathAtom at = MathAtom(new InsetMathColor(true, font.color()));
cur.handleNest(at, 0);

View File

@ -34,7 +34,6 @@
#include "MathSupport.h"
#include "Bidi.h"
#include "bufferview_funcs.h"
#include "BufferView.h"
#include "Color.h"
#include "CoordCache.h"
@ -432,7 +431,7 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
recordUndo(cur, Undo::ATOMIC);
Font font;
bool b;
bv_funcs::string2font(to_utf8(arg), font, b);
font.fromString(to_utf8(arg), b);
if (font.color() != Color::inherit) {
MathAtom at = MathAtom(new InsetMathColor(true, font.color()));
cur.handleNest(at, 0);