From: Jürgen Spitzmüller Date: Fri, 19 Sep 2003 07:25:36 +0000 (+0000) Subject: fix centering of float contents (bug 1290) X-Git-Tag: 1.6.10~16053 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e4eb667ea26d31091eaad349eeaf3ee9e00fdaff;p=features.git fix centering of float contents (bug 1290) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7796 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 6d176fa6dc..c3dcf3be69 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-09-19 Juergen Spitzmueller + + * paragraph.C: use appropriate alignment tags inside floats (bug 1290) + 2003-09-18 Angus Leeming * buffer.C: diff --git a/src/paragraph.C b/src/paragraph.C index 5091301972..e8a0827ba1 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -688,6 +688,47 @@ InsetBibitem * Paragraph::bibitem() const } +namespace { + +/* paragraphs inside floats need different alignment tags to avoid +unwanted space */ + +bool noTrivlistCentering(UpdatableInset const * inset) +{ + if (inset && inset->owner()) { + InsetOld::Code const code = inset->owner()->lyxCode(); + return code == InsetOld::FLOAT_CODE || + code == InsetOld::WRAP_CODE; + } + return false; +} + + +string correction(string const & orig) +{ + if (orig == "flushleft") + return "raggedright"; + if (orig == "flushright") + return "raggedleft"; + if (orig == "center") + return "centering"; + return orig; +} + + +string const corrected_env(string const & suffix, string const & env, + UpdatableInset const * inset) +{ + string output = suffix + "{"; + if (noTrivlistCentering(inset)) + output += correction(env); + else + output += env; + return output + "}"; +} + +} // namespace anon + // This could go to ParagraphParameters if we want to int Paragraph::startTeXParParams(BufferParams const & bparams, @@ -722,29 +763,34 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, case LYX_ALIGN_LAYOUT: case LYX_ALIGN_SPECIAL: break; - case LYX_ALIGN_LEFT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\begin{flushleft}"; - column += 17; - } else { - os << "\\begin{flushright}"; - column += 18; - } + case LYX_ALIGN_LEFT: { + string output; + UpdatableInset const * const inset = pimpl_->inset_owner; + if (getParLanguage(bparams)->babel() != "hebrew") + output = corrected_env("\\begin", "flushleft", inset); + else + output = corrected_env("\\begin", "flushright", inset); + os << output; + column += output.size(); break; - case LYX_ALIGN_RIGHT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\begin{flushright}"; - column += 18; - } else { - os << "\\begin{flushleft}"; - column += 17; - } + } case LYX_ALIGN_RIGHT: { + string output; + UpdatableInset const * const inset = pimpl_->inset_owner; + if (getParLanguage(bparams)->babel() != "hebrew") + output = corrected_env("\\begin", "flushright", inset); + else + output = corrected_env("\\begin", "flushleft", inset); + os << output; + column += output.size(); break; - case LYX_ALIGN_CENTER: - os << "\\begin{center}"; - column += 14; + } case LYX_ALIGN_CENTER: { + string output; + output = corrected_env("\\begin", "center", pimpl_->inset_owner); + os << output; + column += output.size(); break; } + } return column; } @@ -778,29 +824,35 @@ int Paragraph::endTeXParParams(BufferParams const & bparams, case LYX_ALIGN_LAYOUT: case LYX_ALIGN_SPECIAL: break; - case LYX_ALIGN_LEFT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\end{flushleft}"; - column = 15; - } else { - os << "\\end{flushright}"; - column = 16; - } + case LYX_ALIGN_LEFT: { + string output; + UpdatableInset const * const inset = pimpl_->inset_owner; + if (getParLanguage(bparams)->babel() != "hebrew") + output = corrected_env("\\par\\end", "flushleft", inset); + else + output = corrected_env("\\par\\end", "flushright", inset); + os << output; + column += output.size(); break; - case LYX_ALIGN_RIGHT: - if (getParLanguage(bparams)->babel() != "hebrew") { - os << "\\end{flushright}"; - column+= 16; - } else { - os << "\\end{flushleft}"; - column = 15; - } + } case LYX_ALIGN_RIGHT: { + string output; + UpdatableInset const * const inset = pimpl_->inset_owner; + if (getParLanguage(bparams)->babel() != "hebrew") + output = corrected_env("\\par\\end", "flushright", inset); + else + output = corrected_env("\\par\\end", "flushleft", inset); + os << output; + column += output.size(); break; - case LYX_ALIGN_CENTER: - os << "\\end{center}"; - column = 12; + } case LYX_ALIGN_CENTER: { + string output; + output = corrected_env("\\par\\end", "center", pimpl_->inset_owner); + os << output; + column += output.size(); break; } + } + return column; }