The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit b383d04e078f23553cefcd82851b037f54a7d1c8
Author: Richard Heck <rgh...@lyx.org>
Date:   Fri May 10 16:58:38 2013 -0400

    XHTML support for font shapes.

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index a95163e..d3dc2d8 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -2832,14 +2832,15 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
 
 namespace {
-void doFontSwitch(XHTMLStream & xs, bool startrange,
-       bool & flag, FontState curstate, html::FontTypes type)
+void doFontSwitch(vector<html::FontTag> & tagsToOpen,
+                  vector<html::EndFontTag> & tagsToClose,
+                  bool & flag, FontState curstate, html::FontTypes type)
 {
        if (curstate == FONT_ON) {
-               xs << html::FontTag(type);
+               tagsToOpen.push_back(html::FontTag(type));
                flag = true;
-       } else if (flag && !startrange) {
-               xs << html::EndFontTag(type);
+       } else if (flag) {
+               tagsToClose.push_back(html::EndFontTag(type));
                flag = false;
        }
 }
@@ -2854,6 +2855,7 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & 
buf,
 {
        docstring retval;
 
+       // track whether we have opened these tags
        bool emph_flag = false;
        bool bold_flag = false;
        bool noun_flag = false;
@@ -2861,6 +2863,8 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & 
buf,
        bool dbar_flag = false;
        bool sout_flag = false;
        bool wave_flag = false;
+       // shape tags
+       bool shap_flag = false;
 
        Layout const & style = *d->layout_;
 
@@ -2869,6 +2873,11 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & 
buf,
        FontInfo font_old =
                style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
 
+       FontShape curr_fs = INHERIT_SHAPE;
+
+       vector<html::FontTag> tagsToOpen;
+       vector<html::EndFontTag> tagsToClose;
+       
        // parsing main loop
        for (pos_type i = initial; i < size(); ++i) {
                // let's not show deleted material in the output
@@ -2876,47 +2885,104 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const 
& buf,
                        continue;
 
                Font const font = getFont(buf.masterBuffer()->params(), i, 
outerfont);
-               bool const at_start = (i == initial);
 
                // emphasis
                FontState curstate = font.fontInfo().emph();
                if (font_old.emph() != curstate)
-                       doFontSwitch(xs, at_start, emph_flag, curstate, 
html::FT_EMPH);
+                       doFontSwitch(tagsToOpen, tagsToClose, emph_flag, 
curstate, html::FT_EMPH);
 
                // noun
                curstate = font.fontInfo().noun();
                if (font_old.noun() != curstate)
-                       doFontSwitch(xs, at_start, noun_flag, curstate, 
html::FT_NOUN);
+                       doFontSwitch(tagsToOpen, tagsToClose, noun_flag, 
curstate, html::FT_NOUN);
 
                // underbar
                curstate = font.fontInfo().underbar();
                if (font_old.underbar() != curstate)
-                       doFontSwitch(xs, at_start, ubar_flag, curstate, 
html::FT_UBAR);
+                       doFontSwitch(tagsToOpen, tagsToClose, ubar_flag, 
curstate, html::FT_UBAR);
        
                // strikeout
                curstate = font.fontInfo().strikeout();
                if (font_old.strikeout() != curstate)
-                       doFontSwitch(xs, at_start, sout_flag, curstate, 
html::FT_SOUT);
+                       doFontSwitch(tagsToOpen, tagsToClose, sout_flag, 
curstate, html::FT_SOUT);
 
                // double underbar
                curstate = font.fontInfo().uuline();
                if (font_old.uuline() != curstate)
-                       doFontSwitch(xs, at_start, dbar_flag, curstate, 
html::FT_DBAR);
+                       doFontSwitch(tagsToOpen, tagsToClose, dbar_flag, 
curstate, html::FT_DBAR);
 
                // wavy line
                curstate = font.fontInfo().uwave();
                if (font_old.uwave() != curstate)
-                       doFontSwitch(xs, at_start, wave_flag, curstate, 
html::FT_WAVE);
+                       doFontSwitch(tagsToOpen, tagsToClose, wave_flag, 
curstate, html::FT_WAVE);
 
                // bold
                // a little hackish, but allows us to reuse what we have.
                curstate = (font.fontInfo().series() == BOLD_SERIES ? FONT_ON : 
FONT_OFF);
                if (font_old.series() != font.fontInfo().series())
-                       doFontSwitch(xs, at_start, bold_flag, curstate, 
html::FT_BOLD);
+                       doFontSwitch(tagsToOpen, tagsToClose, bold_flag, 
curstate, html::FT_BOLD);
+
+               curr_fs = font.fontInfo().shape();
+               FontShape old_fs = font_old.shape();
+               if (old_fs != curr_fs) {
+                       if (shap_flag) {
+                               switch (old_fs) {
+                               case ITALIC_SHAPE:
+                                       
tagsToClose.push_back(html::EndFontTag(html::FT_ITALIC));
+                                       break;
+                               case SLANTED_SHAPE:
+                                       
tagsToClose.push_back(html::EndFontTag(html::FT_SLANTED));
+                                       break;
+                               case SMALLCAPS_SHAPE:
+                                       
tagsToClose.push_back(html::EndFontTag(html::FT_SMALLCAPS));
+                                       break;
+                               case UP_SHAPE:
+                               case INHERIT_SHAPE:
+                                       break;
+                               default:
+                                       // the other tags are for internal use
+                                       LATTEST(false);
+                                       break;
+                               }
+                               shap_flag = false;
+                       }
+                       switch (curr_fs) {
+                       case ITALIC_SHAPE:
+                               
tagsToOpen.push_back(html::FontTag(html::FT_ITALIC));
+                               break;
+                       case SLANTED_SHAPE:
+                               
tagsToOpen.push_back(html::FontTag(html::FT_SLANTED));
+                               break;
+                       case SMALLCAPS_SHAPE:
+                               
tagsToOpen.push_back(html::FontTag(html::FT_SMALLCAPS));
+                               break;
+                       case UP_SHAPE:
+                       case INHERIT_SHAPE:
+                               break;
+                       default:
+                               // the other tags are for internal use
+                               LATTEST(false);
+                               break;
+                       }
+                       shap_flag = true;
+               }
 
                // FIXME XHTML
                // Other such tags? What about the other text ranges?
 
+               vector<html::EndFontTag>::const_iterator cit = 
tagsToClose.begin();
+               vector<html::EndFontTag>::const_iterator cen = 
tagsToClose.end();
+               for (; cit != cen; ++cit)
+                       xs << *cit;
+
+               vector<html::FontTag>::const_iterator sit = tagsToOpen.begin();
+               vector<html::FontTag>::const_iterator sen = tagsToOpen.end();
+               for (; sit != sen; ++sit)
+                       xs << *sit;
+
+               tagsToClose.clear();
+               tagsToOpen.clear();
+
                Inset const * inset = getInset(i);
                if (inset) {
                        if (!runparams.for_toc || inset->isInToc()) {
diff --git a/src/Text2.cpp b/src/Text2.cpp
index 05dad80..8dfcd4a 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -318,7 +318,7 @@ void Text::setFont(Cursor & cur, Font const & font, bool 
toggleall)
                        newfi.setSeries(INHERIT_SERIES);
        
                FontShape newshp = newfi.shape();
-               if (newshp !=   INHERIT_SHAPE && newshp != IGNORE_SHAPE &&
+               if (newshp != INHERIT_SHAPE && newshp != IGNORE_SHAPE &&
                                newshp == oldfi.shape())
                        newfi.setShape(INHERIT_SHAPE);
 
diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp
index 7212bb2..82fe373 100644
--- a/src/output_xhtml.cpp
+++ b/src/output_xhtml.cpp
@@ -221,11 +221,12 @@ string fontToTag(html::FontTypes type)
                return "del";
        case FT_ITALIC:
                return "i";
+       case FT_UPRIGHT:
        case FT_SLANTED:
        case FT_SMALLCAPS:
        case FT_ROMAN:
        case FT_SANS:
-       case FT_TYPER:
+       case FT_TYPE:
                return "span";
        }
        // kill warning
@@ -252,6 +253,8 @@ StartTag fontToStartTag(html::FontTypes type)
                return html::StartTag(tag, "class='wline'");
        case FT_ITALIC:
                return html::StartTag(tag);
+       case FT_UPRIGHT:
+               return html::StartTag(tag, "style='font-style:normal;'");
        case FT_SLANTED:
                return html::StartTag(tag, "style='font-style:oblique;'");
        case FT_SMALLCAPS:
@@ -260,7 +263,7 @@ StartTag fontToStartTag(html::FontTypes type)
                return html::StartTag(tag, "style='font-family:serif;'");
        case FT_SANS:
                return html::StartTag(tag, "style='font-family:sans-serif;'");
-       case FT_TYPER:
+       case FT_TYPE:
                return html::StartTag(tag, "style='font-family:monospace;'");
        }
        // kill warning
diff --git a/src/output_xhtml.h b/src/output_xhtml.h
index c825a4d..d5fabf9 100644
--- a/src/output_xhtml.h
+++ b/src/output_xhtml.h
@@ -129,19 +129,24 @@ struct ParTag : public StartTag
 
 ///
 enum FontTypes {
+       // ranges
        FT_EMPH,
-       FT_BOLD,
        FT_NOUN,
        FT_UBAR,
        FT_DBAR,
-       FT_SOUT,
        FT_WAVE,
+       FT_SOUT,
+       // bold
+       FT_BOLD,
+       // shapes
+       FT_UPRIGHT,
        FT_ITALIC,
        FT_SLANTED,
        FT_SMALLCAPS,
+       // families
        FT_ROMAN,
        FT_SANS,
-       FT_TYPER
+       FT_TYPE
        // SIZES?
 };
 

-----------------------------------------------------------------------

Summary of changes:
 src/Paragraph.cpp    |   92 +++++++++++++++++++++++++++++++++++++++++++-------
 src/Text2.cpp        |    2 +-
 src/output_xhtml.cpp |    7 +++-
 src/output_xhtml.h   |   11 ++++--
 4 files changed, 93 insertions(+), 19 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to