]> git.lyx.org Git - lyx.git/commitdiff
Lengths for HTML. Use them for InsetBox.
authorRichard Heck <rgheck@comcast.net>
Fri, 12 Jun 2009 14:42:33 +0000 (14:42 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 12 Jun 2009 14:42:33 +0000 (14:42 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30074 a592a061-630c-0410-9148-cb99ea01b6c8

src/Length.cpp
src/Length.h
src/insets/InsetBox.cpp

index e248d7c4f4e2e918065e4f8801ebae1b6cbd0361..af61d0fe7681a4f5dbf698e0eca5063be40ac206 100644 (file)
@@ -110,6 +110,48 @@ string const Length::asLatexString() const
 }
 
 
+string const Length::asHTMLString() const
+{
+       ostringstream os;
+       switch (unit_) {
+       case PT:
+       case BP:
+       case DD:
+               // close enough
+               os << val_ << "pt";
+               break;
+       case MM:
+       case CM:
+       case PC:
+       case IN:
+       case EX:
+       case EM:
+               os << val_ << unit_name[unit_];
+               break;
+       case CC:
+               os << val_/12.0 << "pt";
+               break;
+       case MU:
+               os << val_/18.0 << "em";
+               break;
+       case PTW:
+       case PPW:
+       case PLW:
+       case PCW:
+       case PTH:
+       case PPH:
+               // what it's a percentage of probably won't make sense for HTML,
+               // so we'll assume people have chosen these appropriately
+               os << val_ << '%';
+               break;
+       case SP:
+       case UNIT_NONE:
+               break;
+       }
+       return os.str();
+}
+
+
 double Length::value() const
 {
        return val_;
index 11b591dcb8e69be8df6b5a225ea9ef1bc31eecee..c6e32c3431e94b570681bf4bd38ba711213881a4 100644 (file)
@@ -87,6 +87,8 @@ public:
        docstring const asDocstring() const;
        /// return string representation for LaTeX
        std::string const asLatexString() const;
+       /// return string representation for HTML
+       std::string const asHTMLString() const;
        /// return the on-screen size of this length
        int inPixels(int text_width, int em_width = 0) const;
        /// return the value in Big Postscript points.
index 9948e94e91804aa80fbe7b40acd943a4eb450e96..1ca0aa718b3040eee2f6e722b8af4bed27be5299 100644 (file)
@@ -486,12 +486,19 @@ int InsetBox::docbook(odocstream & os, OutputParams const & runparams) const
 
 int InsetBox::xhtml(odocstream & os, OutputParams const & runparams) const
 {
-       // FIXME We also want to do something with the length info, etc,
-       // presumably as "style='...'".
-       os << from_ascii("<span class='" + params_.type + "'>\n");
-       int ret = InsetText::xhtml(os, runparams);
+       string style;
+       if (!params_.width.empty())
+               style += ("width: " + params_.width.asHTMLString() + ";");
+       if (!params_.height.empty())
+               style += ("height: " + params_.height.asHTMLString() + ";");
+       
+       os << from_ascii("<span class='" + params_.type + "'");
+       if (!style.empty())
+               os << from_ascii(" style='" + style + "'");
+       os << ">\n";
+       InsetText::xhtml(os, runparams);
        os << "</span>\n";
-       return ret;
+       return 0;
 }