** add support for protected horizontal fill. FILE FORMAT CHANGE. **

* src/Buffer.cpp:
	- increment file format to 320.

* src/insets(InsetSpace.{cpp, h}:
	- add HFILL_PROTECTED, a protected horizontal fill
	  (LaTeX: \hspace*{\fill})

* src/factory.cpp:
* src/frontends/qt4/GuiHSpace.{cpp, h}:
	- handle the new space type.

* lib/lyx2lyx/LyX.py:
* lib/lyx2lyx/lyx_1_6.py:
	- reversion routine for protected hfill.

* development/FORMAT:
	- document file format change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23805 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-03-18 12:11:28 +00:00
parent aad4651830
commit 18101eea7b
9 changed files with 74 additions and 13 deletions

View File

@ -1,8 +1,12 @@
LyX file-format changes
-----------------------
2008-03-18 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 320: support for protected horizontal fill
(\hspace*{\fill})
2008-03-10 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 319: hspace and extended hfill support.
* Format incremented to 319: hspace and extended hfill support
2008-03-09 Bo Peng <ben.bob@gmail.com>
* Format incremented to 318: add \extra_embedded_files to buffer params

View File

@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 2)),
("1_6", range(277,320), minor_versions("1.6" , 0))]
("1_6", range(277,321), minor_versions("1.6" , 0))]
def formats_list():

View File

@ -1458,6 +1458,24 @@ def revert_hspace(document):
'hspace{' + length + '}\n\\end_layout\n\n\\end_inset\n\n')
def revert_protected_hfill(document):
' Revert \\begin_inset Space \\hspace*{\\fill} to ERT '
i = 0
while True:
i = find_token(document.body, '\\begin_inset Space \\hspace*{\\fill}', i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: Could not find end of space inset.")
continue
del document.body[j]
document.body[i] = document.body[i].replace('\\begin_inset Space \\hspace*{\\fill}', \
'\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Standard\n\n\n\\backslash\n' \
'hspace*{\n\\backslash\nfill}\n\\end_layout\n\n\\end_inset\n\n')
##
# Conversion hub
#
@ -1505,10 +1523,12 @@ convert = [[277, [fix_wrong_tables]],
[316, [convert_subfig]],
[317, []],
[318, []],
[319, [convert_spaceinset, convert_hfill]]
[319, [convert_spaceinset, convert_hfill]],
[320, []]
]
revert = [[318, [revert_spaceinset, revert_hfills, revert_hspace]],
revert = [[319, [revert_protected_hfill]],
[318, [revert_spaceinset, revert_hfills, revert_hspace]],
[317, [remove_extra_embedded_files]],
[316, [revert_wrapplacement]],
[315, [revert_subfig]],

View File

@ -116,7 +116,7 @@ namespace os = support::os;
namespace {
int const LYX_FORMAT = 319;
int const LYX_FORMAT = 320;
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -348,6 +348,8 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
isp.kind = InsetSpaceParams::NEGTHIN;
else if (name == "hfill")
isp.kind = InsetSpaceParams::HFILL;
else if (name == "hfill*")
isp.kind = InsetSpaceParams::HFILL_PROTECTED;
else if (name == "dotfill")
isp.kind = InsetSpaceParams::DOTFILL;
else if (name == "hrulefill")

View File

@ -54,7 +54,7 @@ GuiHSpace::GuiHSpace(GuiView & lv)
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(fillPatternCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
this, SLOT(patternChanged()));
valueLE->setValidator(unsignedLengthValidator(valueLE));
@ -90,13 +90,22 @@ void GuiHSpace::enableWidgets(int selection)
valueLE->setEnabled(selection == 7);
unitCO->setEnabled(selection == 7);
fillPatternCO->setEnabled(selection == 6);
int pattern = fillPatternCO->currentIndex();
bool const enable_keep =
selection == 0 || selection == 3 || selection == 7;
selection == 0 || selection == 3 ||
(selection == 6 && pattern == 0) || selection == 7;
keepCB->setEnabled(enable_keep);
changed();
}
void GuiHSpace::patternChanged()
{
enableWidgets(spacingCO->currentIndex());
changed();
}
static void setWidgetsFromHSpace(InsetSpaceParams const & params,
QComboBox * spacing,
QLineEdit * value,
@ -137,6 +146,10 @@ static void setWidgetsFromHSpace(InsetSpaceParams const & params,
case InsetSpaceParams::HFILL:
item = 6;
break;
case InsetSpaceParams::HFILL_PROTECTED:
item = 6;
protect = true;
break;
case InsetSpaceParams::DOTFILL:
item = 6;
pattern = 1;
@ -200,6 +213,8 @@ static InsetSpaceParams setHSpaceFromWidgets(int spacing,
params.kind = InsetSpaceParams::DOTFILL;
else if (fill == 2)
params.kind = InsetSpaceParams::HRULEFILL;
else if (keep)
params.kind = InsetSpaceParams::HFILL_PROTECTED;
else
params.kind = InsetSpaceParams::HFILL;
break;

View File

@ -31,6 +31,8 @@ private Q_SLOTS:
void change_adaptor();
///
void enableWidgets(int);
///
void patternChanged();
private:
/// Apply from dialog

View File

@ -96,6 +96,9 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const
case InsetSpaceParams::HFILL:
message = _("Horizontal Fill");
break;
case InsetSpaceParams::HFILL_PROTECTED:
message = _("Protected Horizontal Fill");
break;
case InsetSpaceParams::DOTFILL:
message = _("Horizontal Fill (Dots)");
break;
@ -141,9 +144,7 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (params_.kind == InsetSpaceParams::HFILL ||
params_.kind == InsetSpaceParams::DOTFILL ||
params_.kind == InsetSpaceParams::HRULEFILL) {
if (isStretchableSpace()) {
// The metrics for this kinds are calculated externally in
// \c TextMetrics::computeRowMetrics. Those are dummy value:
dim = Dimension(10, 10, 10);
@ -178,6 +179,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = params_.length.inBP();
break;
case InsetSpaceParams::HFILL:
case InsetSpaceParams::HFILL_PROTECTED:
case InsetSpaceParams::DOTFILL:
case InsetSpaceParams::HRULEFILL:
// shut up compiler
@ -192,9 +194,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
{
Dimension const dim = dimension(*pi.base.bv);
if (params_.kind == InsetSpaceParams::HFILL ||
params_.kind == InsetSpaceParams::DOTFILL ||
params_.kind == InsetSpaceParams::HRULEFILL) {
if (isStretchableSpace()) {
int const asc = theFontMetrics(pi.base.font).ascent('M');
int const desc = theFontMetrics(pi.base.font).descent('M');
int const x0 = x + 1;
@ -208,6 +208,11 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
pi.pain.line(x0, y2 , x1, y2, Color_added_space,
frontend::Painter::line_onoffdash);
pi.pain.line(x1, y1, x1, y0, Color_added_space);
} else if (params_.kind == InsetSpaceParams::HFILL_PROTECTED) {
pi.pain.line(x0, y1, x0, y0, Color_latex);
pi.pain.line(x0, y2 , x1, y2, Color_latex,
frontend::Painter::line_onoffdash);
pi.pain.line(x1, y1, x1, y0, Color_latex);
} else if (params_.kind == InsetSpaceParams::DOTFILL) {
pi.pain.line(x0, y1, x0, y0, Color_special);
pi.pain.line(x0, y, x1, y, Color_special,
@ -279,6 +284,9 @@ void InsetSpaceParams::write(ostream & os) const
case InsetSpaceParams::HFILL:
os << "\\hfill{}";
break;
case InsetSpaceParams::HFILL_PROTECTED:
os << "\\hspace*{\\fill}";
break;
case InsetSpaceParams::DOTFILL:
os << "\\dotfill{}";
break;
@ -321,6 +329,8 @@ void InsetSpaceParams::read(Lexer & lex)
kind = InsetSpaceParams::NEGTHIN;
else if (command == "\\hfill{}")
kind = InsetSpaceParams::HFILL;
else if (command == "\\hspace*{\\fill}")
kind = InsetSpaceParams::HFILL_PROTECTED;
else if (command == "\\dotfill{}")
kind = InsetSpaceParams::DOTFILL;
else if (command == "\\hrulefill{}")
@ -393,6 +403,9 @@ int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
case InsetSpaceParams::HFILL:
os << (runparams.free_spacing ? " " : "\\hfill{}");
break;
case InsetSpaceParams::HFILL_PROTECTED:
os << (runparams.free_spacing ? " " : "\\hspace*{\\fill}");
break;
case InsetSpaceParams::DOTFILL:
os << (runparams.free_spacing ? " " : "\\dotfill{}");
break;
@ -420,6 +433,7 @@ int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
{
switch (params_.kind) {
case InsetSpaceParams::HFILL:
case InsetSpaceParams::HFILL_PROTECTED:
os << " ";
return 5;
case InsetSpaceParams::DOTFILL:
@ -451,6 +465,7 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
os << "&nbsp;";
break;
case InsetSpaceParams::HFILL:
case InsetSpaceParams::HFILL_PROTECTED:
os << '\n';
case InsetSpaceParams::DOTFILL:
// FIXME
@ -476,6 +491,7 @@ void InsetSpace::textString(odocstream & os) const
bool InsetSpace::isStretchableSpace() const
{
return (params_.kind == InsetSpaceParams::HFILL ||
params_.kind == InsetSpaceParams::HFILL_PROTECTED ||
params_.kind == InsetSpaceParams::DOTFILL ||
params_.kind == InsetSpaceParams::HRULEFILL);
}

View File

@ -47,6 +47,8 @@ public:
NEGTHIN,
/// rubber length
HFILL,
/// \hspace*{\fill}
HFILL_PROTECTED,
/// rubber length, filled with dots
DOTFILL,
/// rubber length, filled with a rule