]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Fix bug #6997
[lyx.git] / src / Layout.cpp
index a9a5487b989e624d10203f0bccb20b34d666efd3..fd4709e35659bf8927e4974b014f3efc588b5a14 100644 (file)
 #include <config.h>
 
 #include "Layout.h"
+#include "FontInfo.h"
 #include "Language.h"
-#include "TextClass.h"
 #include "Lexer.h"
-#include "FontInfo.h"
+#include "output_xhtml.h"
+#include "TextClass.h"
 
-#include "support/Messages.h"
 #include "support/debug.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/Messages.h"
 
 #include "support/regex.h"
 
@@ -55,6 +56,7 @@ enum LayoutTags {
        LT_FONT,
        LT_FREE_SPACING,
        LT_PASS_THRU,
+       LT_PARBREAK_IS_NEWLINE,
        //LT_HEADINGS,
        LT_ITEMSEP,
        LT_KEEPEMPTY,
@@ -143,6 +145,7 @@ Layout::Layout()
        newline_allowed = true;
        free_spacing = false;
        pass_thru = false;
+       parbreak_is_newline = false;
        toclevel = NOT_IN_TOC;
        commanddepth = 0;
        htmllabelfirst_ = false;
@@ -210,6 +213,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                { "nextnoindent",   LT_NEXTNOINDENT },
                { "obsoletedby",    LT_OBSOLETEDBY },
                { "optionalargs",   LT_OPTARGS },
+               { "parbreakisnewline", LT_PARBREAK_IS_NEWLINE },
                { "parindent",      LT_PARINDENT },
                { "parsep",         LT_PARSEP },
                { "parskip",        LT_PARSKIP },
@@ -495,6 +499,10 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                        lex >> pass_thru;
                        break;
 
+               case LT_PARBREAK_IS_NEWLINE:
+                       lex >> parbreak_is_newline;
+                       break;
+
                case LT_SPACING: // setspace.sty
                        readSpacing(lex);
                        break;
@@ -551,6 +559,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
 
                case LT_HTMLFORCECSS:
                        lex >> htmlforcecss_;
+                       break;
 
                case LT_HTMLPREAMBLE:
                        htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
@@ -573,7 +582,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                inpreamble = false;
        }
 
-       return !error;
+       return finished && !error;
 }
 
 
@@ -948,8 +957,13 @@ string const & Layout::htmlitemattr() const
 
 string const & Layout::htmllabeltag() const 
 { 
-       if (htmllabeltag_.empty())
-               htmllabeltag_ = "span";
+       if (htmllabeltag_.empty()) {
+               if (labeltype != LABEL_TOP_ENVIRONMENT &&
+                   labeltype != LABEL_CENTERED_TOP_ENVIRONMENT)
+                       htmllabeltag_ = "span";
+               else
+                       htmllabeltag_ = "div";
+       }
        return htmllabeltag_; 
 }
 
@@ -995,27 +1009,77 @@ string Layout::defaultCSSClass() const
 }
 
 
-// NOTE There is a whole ton of stuff that could go into this.
-// Things like bottomsep, topsep, and parsep could become various
-// sorts of margins or padding, for example. But for now we are
-// going to keep it simple.
+namespace {
+       string makeMarginValue(char const * side, double d) {
+               ostringstream os;
+               os << "margin-" << side << ": " << d << "ex;\n";
+               return os.str();
+       }
+}
+
+
 void Layout::makeDefaultCSS() const {
        // this never needs to be redone, since reloading layouts will
        // wipe out what we did before.
        if (!htmldefaultstyle_.empty()) 
                return;
-       docstring const mainfontCSS = font.asCSS();
-       if (!mainfontCSS.empty())
+       
+       // main font
+       htmldefaultstyle_ = font.asCSS();
+       
+       // bottom margins
+       string tmp;
+       if (topsep > 0)
+               tmp += makeMarginValue("top", topsep);
+       if (bottomsep > 0)
+               tmp += makeMarginValue("bottom", bottomsep);
+       if (!leftmargin.empty()) {
+               // we can't really do what LyX does with the margin, so 
+               // we'll just figure out how many characters it is
+               int const len = leftmargin.length();
+               tmp += makeMarginValue("left", len);
+       }
+       if (!rightmargin.empty()) {
+               int const len = rightmargin.length();
+               tmp += makeMarginValue("right", len);
+       }
+               
+       if (!tmp.empty()) {
+               if (!htmldefaultstyle_.empty())
+                       htmldefaultstyle_ += from_ascii("\n");
+               htmldefaultstyle_ += from_ascii(tmp);
+       }
+
+// tex2lyx does not see output_xhtml.cpp
+#ifndef TEX2LYX
+       // alignment
+       string where = alignmentToCSS(align);
+       if (!where.empty()) {
+               htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
+       }
+#endif
+       
+       // wrap up what we have, if anything
+       if (!htmldefaultstyle_.empty())
                htmldefaultstyle_ = 
                        from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
-                       mainfontCSS + from_ascii("\n}\n");
-       if (labelfont == font || htmllabeltag() == "NONE")
+                       htmldefaultstyle_ + from_ascii("\n}\n");
+       
+       if (labeltype == LABEL_NO_LABEL || htmllabeltag() == "NONE")
                return;
-       docstring const labelfontCSS = labelfont.asCSS();
-       if (!labelfontCSS.empty())
+       
+       docstring labelCSS;
+       
+       // label font
+       if (labelfont != font)
+               labelCSS = labelfont.asCSS() + from_ascii("\n");
+       if (labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
+               labelCSS += from_ascii("text-align: center;\n");
+       
+       if (!labelCSS.empty())
                htmldefaultstyle_ +=
                        from_ascii(htmllabeltag() + "." + defaultCSSLabelClass() + " {\n") +
-                       labelfontCSS + from_ascii("\n}\n");
+                       labelCSS + from_ascii("\n}\n");
 }