*** empty log message ***
authorroot <root>
Wed, 25 Aug 2004 05:03:33 +0000 (05:03 +0000)
committerroot <root>
Wed, 25 Aug 2004 05:03:33 +0000 (05:03 +0000)
src/main.C
src/rxvtfont.h

index 2633db6..f67532d 100644 (file)
@@ -125,21 +125,6 @@ int rxvt_composite_vec::expand (unicode_t c, wchar_t *r)
 }
 #endif
 
-void *
-rxvt_term::operator new (size_t s)
-{
-  void *p = malloc (s);
-
-  memset (p, 0, s);
-  return p;
-}
-
-void
-rxvt_term::operator delete (void *p, size_t s)
-{
-  free (p);
-}
-
 rxvt_term::rxvt_term ()
     :
 #if TRANSPARENT
@@ -198,7 +183,12 @@ rxvt_term::~rxvt_term ()
   privileged_utmp (RESTORE);
 #endif
 
-  delete TermWin.fontset;
+#if ENABLE_STYLES
+  for (int i = RS_styleCount; --i; )
+    if (TermWin.fontset[i] != TermWin.fontset[0])
+      delete TermWin.fontset[i];
+#endif
+  delete TermWin.fontset[0];
 
   if (display)
     {
@@ -389,6 +379,8 @@ rxvt_term::init (int argc, const char *const *argv)
   XMapWindow (display->display, TermWin.vt);
   XMapWindow (display->display, TermWin.parent[0]);
 
+  set_colorfgbg ();
+
   init_command (cmd_argv);
 
   pty_ev.start (pty.pty, EVENT_READ);
@@ -795,7 +787,7 @@ rxvt_term::tt_winch ()
 }
 
 /*----------------------------------------------------------------------*/
-/* rxvt_change_font () - Switch to a new font */
+/* set_fonts () - load and set the various fonts
 /*
  * init = 1   - initialize
  *
@@ -803,49 +795,76 @@ rxvt_term::tt_winch ()
  * fontname == FONT_DN  - switch to smaller font
  */
 bool
-rxvt_term::change_font (const char *fontname)
+rxvt_term::set_fonts ()
 {
-  if (fontname == FONT_UP)
-    {
-      // TODO
-    }
-  else if (fontname == FONT_DN)
+  rxvt_fontset *fs = new rxvt_fontset (this);
+  rxvt_fontprop prop;
+
+  prop.width = prop.height = prop.weight = prop.slant
+    = rxvt_fontprop::unset;
+
+  if (!fs
+      || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed", prop)
+      || !fs->realize_font (1))
     {
-      // TODO
+      delete fs;
+      return false;
     }
-  else
+
+#if ENABLE_STYLES
+  for (int i = RS_styleCount; --i; )
+    if (TermWin.fontset[i] != TermWin.fontset[0])
+      delete TermWin.fontset[i];
+#endif
+
+  delete TermWin.fontset[0];
+  TermWin.fontset[0] = fs;
+
+  fs->prop = prop = (*fs)[1]->properties ();
+
+  TermWin.fwidth  = prop.width;
+  TermWin.fheight = prop.height;
+  TermWin.fweight = prop.weight;
+  TermWin.fslant  = prop.slant;
+  TermWin.fbase   = (*fs)[1]->ascent;
+
+  for (int style = 1; style < 4; style++)
     {
-      rxvt_fontset *fs = new rxvt_fontset (this);
+#if ENABLE_STYLES
+      const char *res = rs[Rs_font + style];
 
-      if (fs && fs->populate (fontname ? fontname : "fixed"))
+      if (res && !*res)
+        TermWin.fontset[style] = TermWin.fontset[0];
+      else
         {
-          delete TermWin.fontset;
-          TermWin.fontset = fs;
-          TermWin.fwidth  = fs->base_font ()->width;
-          TermWin.fheight = fs->base_font ()->height;
-          TermWin.fbase   = fs->base_font ()->ascent;
+          TermWin.fontset[style] = fs = new rxvt_fontset (this);
+          rxvt_fontprop prop2 = prop;
 
-          if (TermWin.parent[0])
+          if (res)
+            prop2.weight = prop2.slant = rxvt_fontprop::unset;
+          else
             {
-              resize_all_windows (0, 0, 0);
-              scr_remap_chars ();
-              scr_touch (true);
-            }   
+              res = TermWin.fontset[0]->fontdesc;
 
-          for (unicode_t ch = 0x20; ch <= 0x7f; ch++)
-            TermWin.ascii_map [ch - 0x20] = fs->find_font (ch);
+              if (SET_STYLE (0, style) & RS_Bold)   prop2.weight = rxvt_fontprop::bold;
+              if (SET_STYLE (0, style) & RS_Italic) prop2.slant  = rxvt_fontprop::italic;
+            }
 
-          return true;
+          fs->populate (res, prop2);
         }
+#else
+      TermWin.fontset[style] = TermWin.fontset[0];
+#endif
     }
 
-  return false;
-}
+  if (TermWin.parent[0])
+    {
+      resize_all_windows (0, 0, 0);
+      scr_remap_chars ();
+      scr_touch (true);
+    }   
 
-bool
-rxvt_term::font_up_down (int n, int direction)
-{
-  return false;
+  return true;
 }
 
 /*----------------------------------------------------------------------*/
@@ -949,16 +968,14 @@ rxvt_term::set_window_color (int idx, const char *color)
   /* Cursor cursor; */
 Done:
 #ifdef OFF_FOCUS_FADING
-  pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
+  if (rs[Rs_fade])
+    pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
 #endif
-  if (idx == Color_bg && ! (options & Opt_transparent))
-    XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
 
-  /* handle Color_BD, scrollbar background, etc. */
+  /*TODO: handle Color_BD, scrollbar background, etc. */
 
-  set_colorfgbg ();
   recolour_cursor ();
-  scr_touch (true);
+  scr_recolour ();
 }
 
 #else
@@ -970,8 +987,13 @@ rxvt_term::recolour_cursor ()
 {
   XColor xcol[2];
 
-  xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg];
-  xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg];
+  xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg)
+                     ? pix_colors_focused[Color_pointer_fg]
+                     : pix_colors_focused[Color_fg];
+  xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
+                     ? pix_colors_focused[Color_pointer_bg]
+                     : pix_colors_focused[Color_bg];
+
   XQueryColors (display->display, display->cmap, xcol, 2);
   XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
 }
@@ -983,12 +1005,11 @@ rxvt_term::recolour_cursor ()
 void
 rxvt_term::set_colorfgbg ()
 {
-  unsigned int    i;
-  const char     *xpmb = "\0";
-  char            fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
+  unsigned int i;
+  const char *xpmb = "\0";
+  char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
 
-  env_colorfgbg =
-    (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
+  env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
   strcpy (fstr, "default");
   strcpy (bstr, "default");
   for (i = Color_Black; i <= Color_White; i++)
@@ -997,6 +1018,7 @@ rxvt_term::set_colorfgbg ()
         sprintf (fstr, "%d", (i - Color_Black));
         break;
       }
+
   for (i = Color_Black; i <= Color_White; i++)
     if (pix_colors[Color_bg] == pix_colors[i])
       {
@@ -1008,17 +1030,6 @@ rxvt_term::set_colorfgbg ()
       }
 
   sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
-
-#ifndef NO_BRIGHTCOLOR
-  colorfgbg = DEFAULT_RSTYLE;
-  for (i = minCOLOR; i <= maxCOLOR; i++)
-    {
-      if (pix_colors[Color_fg] == pix_colors[i])
-        colorfgbg = SET_FGCOLOR (colorfgbg, i);
-      if (pix_colors[Color_bg] == pix_colors[i])
-        colorfgbg = SET_BGCOLOR (colorfgbg, i);
-    }
-#endif
 }
 
 /*----------------------------------------------------------------------*/
index 036a10a..e5c9862 100644 (file)
 
 #include <inttypes.h>
 
-#include "rxvtlib.h"
 #include "feature.h"
 #include "encoding.h"
 #include "rxvtutil.h"
+#include "rxvttoolkit.h"
+
+struct rxvt_term;
 
 struct rxvt_fontprop {
   enum {
+    unset  = -1,
     medium = 100, bold = 200,
     roman  = 0, italic = 100,
   };
@@ -59,37 +62,31 @@ struct rxvt_drawable {
 };
 
 struct rxvt_font {
-  struct rxvt_fontset *fs;
   // managed by the fontset
-  rxvt_t r;
-  void set_term (rxvt_t r) { this->r = r; }
+  rxvt_term *r;
+  void set_term (rxvt_term *r) { this->r = r; }
 
   char *name;
   codeset cs;
   bool loaded; // wether we tried loading it before (not wether it's loaded)
 
   // managed by the font object
-  bool slow; // wether this is a proportional font or has other funny characteristics
   int ascent, descent,
       width, height;
 
-  void set_name (char *name)
-  {
-    if (this->name) free (this->name); // let the compiler optimize
-    this->name = name;
-  }
+  void set_name (char *name);
 
   rxvt_font () { name = 0; }
-  ~rxvt_font () { free (name); };
-
-  void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color);
+  virtual ~rxvt_font () { free (name); };
 
   virtual void clear () { };
 
+  void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color);
+
   virtual rxvt_fontprop properties () = 0;
 
-  virtual bool load (const rxvt_fontprop &prop) = 0;
-  virtual bool has_codepoint (uint32_t unicode) = 0;
+  virtual bool load (const rxvt_fontprop &morph) = 0;
+  virtual bool has_char (uint32_t unicode, const rxvt_fontprop *prop, bool &careful) = 0;
 
   virtual void draw (rxvt_drawable &d,
                      int x, int y,
@@ -103,36 +100,32 @@ struct rxvt_fallback_font;
 
 struct rxvt_fontset {
   char *fontdesc;
+  rxvt_fontprop prop;
 
-  rxvt_fontset (rxvt_t r);
+  rxvt_fontset (rxvt_term *r);
   ~rxvt_fontset ();
 
   rxvt_font *new_font (const char *name, codeset cs);
 
-  bool populate (const char *desc);
-  int find_font (uint32_t unicode, bool bold = false);
+  bool populate (const char *desc, const rxvt_fontprop &prop);
+  int find_font (uint32_t unicode);
   int find_font (const char *name) const;
+  bool realize_font (int i);
 
-  // font-id's MUST fit into a signed 16 bit integer.
+  // font-id's MUST fit into a signed 16 bit integer, and within 0..255
   rxvt_font *operator [] (int id) const
   {
-    return fonts[id];
-  }
-
-  rxvt_font *base_font () const
-  {
-    return fonts[base_id];
+    return fonts[id & 0x7f];
   }
 
 private:
-  rxvt_t r;
+  rxvt_term *r;
   simplevec<rxvt_font *> fonts;
   const rxvt_fallback_font *fallback;
 
-  rxvt_fontprop base_prop;
-  int base_id;
+  typedef unsigned char pagemap[256];
+  vector<pagemap *> fmap;
 
-  bool realize_font (int i);
   void add_fonts (const char *desc);
   void clear ();
 };