]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Add alignment to default CSS.
[lyx.git] / src / Layout.cpp
index a9a5487b989e624d10203f0bccb20b34d666efd3..daf298f509d33dd959d5d64e464222b96575f2f3 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;
 }
 
 
@@ -995,22 +1004,55 @@ 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(double d) {
+               ostringstream os;
+               os << d << "ex";
+               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();
+       
+       // top and bottom margins
+       string tmp;
+       if (topsep > 0)
+               tmp += "margin-top: " + makeMarginValue(topsep) + ";\n";
+       if (bottomsep > 0)
+               tmp += "margin-bottom: " + makeMarginValue(bottomsep) + ";\n";
+       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");
+                       htmldefaultstyle_ + from_ascii("\n}\n");
+       
        if (labelfont == font || htmllabeltag() == "NONE")
                return;
+       
+       // label font
        docstring const labelfontCSS = labelfont.asCSS();
        if (!labelfontCSS.empty())
                htmldefaultstyle_ +=