]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfont.h
Added html export for LinuxDoc and DocBook. LinuxDoc import now available in file...
[lyx.git] / src / lyxfont.h
index bd32445f7e6584f62251f26081551fa9d1919046..13a0f703a522721bb534b6393f0ff8b193adaa85 100644 (file)
@@ -19,7 +19,7 @@
 #include FORMS_H_LOCATION
 #include "LString.h"
 #include "debug.h"
-#include "direction.h"
+#include "language.h"
 #include "LColor.h"
 
 // It might happen that locale.h defines ON and OFF. This is not good
@@ -35,7 +35,6 @@
 #undef OFF
 #endif
 
-#define USE_OSTREAM_ONLY 1
 
 class LyXLex;
 
@@ -123,19 +122,6 @@ public:
                IGNORE_SIZE
        };
  
-       enum FONT_DIRECTION {
-               ///
-               LTR_DIR,
-               ///
-               RTL_DIR,
-               ///
-               TOGGLE_DIR,
-               ///
-               INHERIT_DIR,
-               ///
-               IGNORE_DIR
-       };
-
        /// Used for emph, underbar, noun and latex toggles
        enum FONT_MISC_STATE {
                ///
@@ -178,6 +164,12 @@ public:
        LyXFont(LyXFont::FONT_INIT2);
        /// Shortcut initialization
        LyXFont(LyXFont::FONT_INIT3);
+       /// Shortcut initialization
+       LyXFont(LyXFont::FONT_INIT1, Language const * l);
+       /// Shortcut initialization
+       LyXFont(LyXFont::FONT_INIT2, Language const * l);
+       /// Shortcut initialization
+       LyXFont(LyXFont::FONT_INIT3, Language const * l);
 
        /// LyXFont x, y; x = y;
        LyXFont & operator=(LyXFont const & x);
@@ -216,10 +208,13 @@ public:
        LColor::color color() const;
 
        ///
-       FONT_DIRECTION direction() const;
+       Language const * language() const;
+
+       ///
+       bool isRightToLeft() const;
 
        ///
-       LyXDirection getFontDirection() const;
+       bool isVisibleRightToLeft() const;
        
        ///
        LyXFont & setFamily(LyXFont::FONT_FAMILY f);
@@ -240,7 +235,7 @@ public:
        ///
        LyXFont & setColor(LColor::color c);
        ///
-       LyXFont & setDirection(LyXFont::FONT_DIRECTION d);
+       LyXFont & setLanguage(Language const * l);
 
        /// Set family after LyX text format
        LyXFont & setLyXFamily(string const &);
@@ -276,7 +271,9 @@ public:
         * a INHERIT_FAMILY was asked for.  This is necessary for the
         * toggle-user-defined-style button on the toolbar.
         */
-       void update(LyXFont const & newfont, bool toggleall = false);
+       void update(LyXFont const & newfont, 
+                   Language const * default_lang,
+                   bool toggleall = false);
  
        /** Reduce font to fall back to template where possible.
            Equal fields are reduced to INHERIT */
@@ -294,8 +291,6 @@ public:
        /// Writes the changes from this font to orgfont in .lyx format in file
        void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
 
-
-#ifdef USE_OSTREAM_ONLY
        /** Writes the head of the LaTeX needed to change to this font.
            Writes to string, the head of the LaTeX needed to change
            to this font. Returns number of chars written. Base is the
@@ -303,27 +298,14 @@ public:
        */
        int latexWriteStartChanges(ostream &, LyXFont const & base,
                                   LyXFont const & prev) const;
+
        /** Writes tha tail of the LaTeX needed to chagne to this font.
            Returns number of chars written. Base is the font state we want
            to achieve.
        */
        int latexWriteEndChanges(ostream &, LyXFont const & base,
                                 LyXFont const & next) const;
-#else
-       /** Writes the head of the LaTeX needed to change to this font.
-           Writes to string, the head of the LaTeX needed to change
-           to this font. Returns number of chars written. Base is the
-           font state active now.
-       */
-       int latexWriteStartChanges(string &, LyXFont const & base,
-                                  LyXFont const & prev) const;
-       /** Writes tha tail of the LaTeX needed to chagne to this font.
-           Returns number of chars written. Base is the font state we want
-           to achieve.
-       */
-       int latexWriteEndChanges(string &, LyXFont const & base,
-                                LyXFont const & next) const;
-#endif 
+
        /// Build GUI description of font state
        string stateText() const;
 
@@ -374,13 +356,15 @@ public:
        ///
        friend inline
        bool operator==(LyXFont const & font1, LyXFont const & font2) {
-               return font1.bits == font2.bits;
+               return font1.bits == font2.bits &&
+                       font1.lang == font2.lang;
        }
 
        ///
        friend inline
        bool operator!=(LyXFont const & font1, LyXFont const & font2) {
-               return font1.bits != font2.bits;
+               return font1.bits != font2.bits ||
+                       font1.lang != font2.lang;
        }
 
        /// compares two fonts, ignoring the setting of the Latex part.
@@ -398,8 +382,7 @@ private:
                                fb1.emph == emph &&
                                fb1.underbar == underbar &&
                                fb1.noun == noun &&
-                               fb1.latex == latex &&
-                               fb1.direction == direction;
+                               fb1.latex == latex;
                }
                bool operator!=(FontBits const & fb1) const {
                        return !(fb1 == *this);
@@ -414,10 +397,10 @@ private:
                FONT_MISC_STATE underbar;
                FONT_MISC_STATE noun;
                FONT_MISC_STATE latex;
-               FONT_DIRECTION direction;
        };
 
        FontBits bits;
+       Language const * lang;
        
        /// Sane font
        static FontBits sane;
@@ -441,39 +424,72 @@ private:
 
 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
 
-inline LyXFont::LyXFont()
+inline
+LyXFont::LyXFont()
 {
        bits = sane;
+       lang = default_language;
 }
 
 
-inline LyXFont::LyXFont(LyXFont const & x)
+inline
+LyXFont::LyXFont(LyXFont const & x)
 {
        bits = x.bits;
+       lang = x.lang;
 }
 
 
-inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT1)
 {
        bits = inherit;
+       lang = default_language;
 }
 
 
-inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT2)
 {
        bits = ignore;
+       lang = ignore_language;
 }
 
 
-inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT3)
 {
        bits = sane;
+       lang = default_language;
+}
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
+{
+       bits = inherit;
+       lang = l;
 }
 
 
-inline LyXFont & LyXFont::operator=(LyXFont const & x) 
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
+{
+       bits = ignore;
+       lang = l;
+}
+
+
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
+{
+       bits = sane;
+       lang = l;
+}
+
+inline
+LyXFont & LyXFont::operator=(LyXFont const & x) 
 {
        bits = x.bits;
+       lang = x.lang;
        return *this;
 }
 
@@ -542,11 +558,26 @@ LColor::color LyXFont::color() const
 
 
 inline
-LyXFont::FONT_DIRECTION LyXFont::direction() const 
+Language const * LyXFont::language() const 
+{
+       return lang;
+}
+
+
+inline
+bool LyXFont::isRightToLeft() const 
 {
-       return bits.direction;
+       return lang->RightToLeft;
 }
 
+
+inline
+bool LyXFont::isVisibleRightToLeft() const 
+{
+       return (lang->RightToLeft && latex() != ON);
+}
+
+
 inline
 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
 {
@@ -619,9 +650,9 @@ LyXFont & LyXFont::setColor(LColor::color c)
 
 
 inline
-LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)
+LyXFont & LyXFont::setLanguage(Language const * l)
 {
-       bits.direction = d;
+       lang = l;
        return *this;
 }