summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsf-exg <sf-exg>2016-06-21 12:03:56 +0000
committersf-exg <sf-exg>2016-06-21 12:03:56 +0000
commit7ccd280a30a8620e7e9ee33d4fbb1e9e3809ea15 (patch)
tree4691f03aaf20e38d9313be60f897eb058fa36c0d /src
parenta13900490c816a2570522c42cb807615cc943cdd (diff)
24-bit direct color support (patch by Fengguang Wu)
Support directly setting RGB fg/bg colors via ISO-8613-3 24-bit ANSI color escapes: ESC[38;2;<r>;<g>;<b>m Select RGB foreground color ESC[48;2;<r>;<g>;<b>m Select RGB background color The killer applications for me are vim in tmux. It'll not only modernize their look and feeling, but also bring more eye friendly color schemes. Very helpful for long time programmers. To avoid memory overheads and keep the patch non-intrusive, it takes the approach to adapt the nearest color in an hidden 6x6x4 (88-color mode) or 7x7x5 (256-color mode) color cube to the new 24-bit RGB color. The pros/cons are: +) least memory footprint (close to 0) comparing to konsole, gnome-terminal etc. real 24-bit arrays +) exact colors and excellent user feelings comparing to xterm, mlterm, etc. approximating to 256 palette +) usable in both the existing 88/256-color modes Most vim GUI color schemes show up the same as gvim in rxvt-unicode's 88-color mode, not to mention the 256-color mode. Typical applications only use one or two dozens of colors at the same time. -) may not be able to show 2+ close 24-bit colors RGB colors close to each other will likely fall into the same slot in the 6x6x4 or 7x7x5 color cube. If necessary, it could be improved effectively by implementing some collision avoidance logic, trying to find empty/eldest slot in the +1/-1 r/g/b indices (ie. 3-8 neighbors). The CPU overheads of map_rgb24_color() look ignorable: I feel no perceptible slow down when doing vim operations in 24-bit color mode. A micro benchmark running a test script from [1]: % time (for i in {1..100}; do 24-bit-color.sh; done) vanilla rxvt-unicode ==================== 2.42s user 1.88s system 31% cpu 13.555 total 2.59s user 1.74s system 31% cpu 13.615 total 2.46s user 1.85s system 31% cpu 13.631 total THIS PATCH (adapt hidden color cube to 24-bit) ============================================== 2.33s user 1.97s system 31% cpu 13.598 total 2.46s user 1.89s system 31% cpu 13.613 total 2.51s user 1.82s system 31% cpu 13.556 total https://github.com/spudowiar/rxvt-unicode (real 24-bit array) ============================================================= 2.61s user 1.75s system 31% cpu 13.721 total 2.48s user 1.82s system 31% cpu 13.566 total 2.60s user 1.76s system 31% cpu 13.631 total USE_256_COLORS is defined in all the above rxvt-unicode builds. References: [1] True Colour (16 million colours) support in various terminal applications and terminals https://gist.github.com/XVilka/8346728 [2] https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
Diffstat (limited to 'src')
-rw-r--r--src/rxvtfont.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/rxvtfont.h b/src/rxvtfont.h
new file mode 100644
index 0000000..efb1509
--- /dev/null
+++ b/src/rxvtfont.h
@@ -0,0 +1,133 @@
+#ifndef DEFAULTFONT_H_
+#define DEFAULTFONT_H_
+
+#include <X11/Xlib.h>
+#if XFT
+# include <X11/Xft/Xft.h>
+#endif
+
+#include <inttypes.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,
+ };
+ int width, height, ascent;
+ int weight, slant;
+};
+
+struct rxvt_font
+{
+ // managed by the fontset
+ rxvt_term *term;
+ void set_term (rxvt_term *term) { this->term = term; }
+
+ char *name;
+ codeset cs;
+ bool loaded; // whether we tried loading it before (not whether it's loaded)
+
+ // managed by the font object
+ int ascent, descent,
+ width, height;
+
+ void set_name (char *name_);
+
+ rxvt_font ();
+ virtual ~rxvt_font () { free (name); };
+
+ virtual void clear () { };
+
+ void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color) const;
+
+ virtual rxvt_fontprop properties () = 0;
+
+ virtual bool load (const rxvt_fontprop &morph, bool force_prop) = 0;
+ virtual bool has_char (uint32_t unicode, const rxvt_fontprop *prop, bool &careful) const = 0;
+
+ virtual void draw (rxvt_drawable &d,
+ int x, int y,
+ const text_t *text, int len,
+ int fg, int bg) = 0;
+
+ void unref ()
+ {
+ clear ();
+ delete this;
+ }
+};
+
+struct rxvt_fallback_font;
+
+struct rxvt_fontset
+{
+ char *fontdesc;
+
+ // must be power-of-two - 1, also has to match RS_fontMask in rxvt.h
+#if USE_256_COLORS
+ enum { fontCount = 7 }; // 2 extra colors bits, 2 fewer fontcount bits
+#else
+ enum { fontCount = 31 };
+#endif
+
+ // index of first font in set
+ enum { firstFont = 2 };
+
+ rxvt_fontset (rxvt_term *term);
+ ~rxvt_fontset ();
+
+ bool populate (const char *desc);
+ void set_prop (const rxvt_fontprop &prop, bool force_prop) { this->prop = prop; this->force_prop = force_prop; }
+ int find_font_idx (uint32_t unicode);
+ int find_font (const char *name) const;
+ bool realize_font (int i);
+
+ rxvt_font *operator [] (int id) const
+ {
+ return fonts[id >> 1];
+ }
+
+ int
+ find_font (unicode_t unicode)
+ {
+ return min<int> ((fontCount << 1) | 1, find_font_idx (unicode));
+ }
+
+private:
+ rxvt_term *term;
+ rxvt_fontprop prop;
+ bool force_prop;
+ simplevec<rxvt_font *> fonts;
+ const rxvt_fallback_font *fallback;
+
+ // this once was a "typedef xxx pagemap[256]
+ // but c++ arrays are not normal types, and cannot be
+ // put into containers, new doesn't work for them etc. etc.
+ // so we wrap out array into an object that acts like one. doh.
+ // example: C++ has no separate new and new [] forms,
+ // and if pagemap is char[256], new incorrectly assumes we want to
+ // allocate an array of chars instead of a single pagemap.
+ struct pagemap
+ {
+ unsigned char cppsucks[256];
+ unsigned char &operator [](int i) { return cppsucks [i]; };
+ };
+ vector<pagemap *> fmap;
+
+ void clear ();
+ rxvt_font *new_font (const char *name, codeset cs);
+ void prepare_font (rxvt_font *font, codeset cs);
+ void add_fonts (const char *desc);
+ void push_font (rxvt_font *font);
+};
+
+#endif /* _DEFAULTFONT_H_ */
+