From bd5cccbb3446ac61ffd78a98f34b188a4be4307b Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 12 Jun 2009 14:42:33 +0000 Subject: [PATCH] Lengths for HTML. Use them for InsetBox. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30074 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Length.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ src/Length.h | 2 ++ src/insets/InsetBox.cpp | 17 ++++++++++++----- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/Length.cpp b/src/Length.cpp index e248d7c4f4..af61d0fe76 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -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_; diff --git a/src/Length.h b/src/Length.h index 11b591dcb8..c6e32c3431 100644 --- a/src/Length.h +++ b/src/Length.h @@ -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. diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 9948e94e91..1ca0aa718b 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -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("\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("\n"; + InsetText::xhtml(os, runparams); os << "\n"; - return ret; + return 0; } -- 2.39.5