]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfont.h
Angus insetindex patch + protect patch from Dekel
[lyx.git] / src / lyxfont.h
index bd32445f7e6584f62251f26081551fa9d1919046..62e5da13f22ad8c3c589acdfa23533cc17cd60f0 100644 (file)
 #pragma interface
 #endif
 
-#include FORMS_H_LOCATION
+#include <iosfwd>
+
 #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,9 +35,8 @@
 #undef OFF
 #endif
 
-#define USE_OSTREAM_ONLY 1
-
 class LyXLex;
+class BufferParams;
 
 ///
 class LyXFont {
@@ -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 {
                ///
@@ -173,11 +159,20 @@ public:
        LyXFont(LyXFont const & x);
  
        /// Shortcut initialization
+       explicit
        LyXFont(LyXFont::FONT_INIT1);
        /// Shortcut initialization
+       explicit
        LyXFont(LyXFont::FONT_INIT2);
        /// Shortcut initialization
+       explicit
        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 +211,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 +238,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 +274,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 */
@@ -292,132 +292,77 @@ public:
        LyXFont & lyxRead(LyXLex &);
  
        /// Writes the changes from this font to orgfont in .lyx format in file
-       void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
+       void lyxWriteChanges(LyXFont const & orgfont, std::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
            font state active now.
        */
-       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,
+       int latexWriteStartChanges(std::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(string &, LyXFont const & base,
+       int latexWriteEndChanges(std::ostream &, LyXFont const & base,
                                 LyXFont const & next) const;
-#endif 
-       /// Build GUI description of font state
-       string stateText() const;
-
-       ///
-       int maxAscent() const; 
-
-       ///
-       int maxDescent() const;
-
-       ///
-       int ascent(char c) const;
 
-       ///
-       int descent(char c) const;
-
-       ///
-       int width(char c) const;
-
-       ///
-       int lbearing(char c) const;
-
-       ///
-       int rbearing(char c) const;
-       
-       ///
-       int textWidth(char const *s, int n) const;
-
-       ///
-       int stringWidth(string const & s) const;
-
-       ///
-       int signedStringWidth(string const & s) const;
-
-       /// Draws text and returns width of text
-       int drawText(char const *, int n, Pixmap, int baseline, int x) const;
-
-       ///
-       int drawString(string const &, Pixmap pm, int baseline, int x) const;
+       /// Build GUI description of font state
+       string stateText(BufferParams * params) const;
 
        ///
        LColor::color realColor() const;
 
        ///
-       XID getFontID() const {
-               return getXFontstruct()->fid;
-       }
-       
-       ///
-       friend inline
+       friend
        bool operator==(LyXFont const & font1, LyXFont const & font2) {
-               return font1.bits == font2.bits;
+               return font1.bits == font2.bits &&
+                       font1.lang == font2.lang;
        }
 
        ///
-       friend inline
+       friend 
        bool operator!=(LyXFont const & font1, LyXFont const & font2) {
-               return font1.bits != font2.bits;
+               return !(font1 == font2);
        }
 
        /// compares two fonts, ignoring the setting of the Latex part.
        bool equalExceptLatex(LyXFont const &) const;
 
+       /// Converts logical attributes to concrete shape attribute
+       LyXFont::FONT_SHAPE realShape() const;
 private:
        ///
        struct FontBits {
-               bool operator==(FontBits const & fb1) const {
-                       return fb1.family == family &&
-                               fb1.series == series &&
-                               fb1.shape == shape &&
-                               fb1.size == size &&
-                               fb1.color == color &&
-                               fb1.emph == emph &&
-                               fb1.underbar == underbar &&
-                               fb1.noun == noun &&
-                               fb1.latex == latex &&
-                               fb1.direction == direction;
-               }
-               bool operator!=(FontBits const & fb1) const {
-                       return !(fb1 == *this);
-               }
-               
+               ///
+               bool operator==(FontBits const & fb1) const;
+               ///
+               bool operator!=(FontBits const & fb1) const;
+               ///
                FONT_FAMILY family;
+               ///
                FONT_SERIES series;
+               ///
                FONT_SHAPE shape;
+               ///
                FONT_SIZE size;
+               ///
                LColor::color color;
+               ///
                FONT_MISC_STATE emph;
+               ///
                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;
@@ -431,49 +376,79 @@ private:
        /// Updates a misc setting according to request
        LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
                                         LyXFont::FONT_MISC_STATE org);
+};
 
-       /// Converts logical attributes to concrete shape attribute
-       LyXFont::FONT_SHAPE realShape() const;
 
-       ///
-       XFontStruct * getXFontstruct() const;
-};
+std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
 
-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)
+{
+       bits = inherit;
+       lang = default_language;
+}
+
+
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT2)
+{
+       bits = ignore;
+       lang = ignore_language;
 }
 
 
-inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
+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(LyXFont::FONT_INIT2)
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
 {
        bits = ignore;
+       lang = l;
 }
 
 
-inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
+inline
+LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
 {
        bits = sane;
+       lang = l;
 }
 
 
-inline LyXFont & LyXFont::operator=(LyXFont const & x) 
+inline
+LyXFont & LyXFont::operator=(LyXFont const & x) 
 {
        bits = x.bits;
+       lang = x.lang;
        return *this;
 }
 
@@ -542,11 +517,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 +609,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;
 }