From 6fba73ee1df2edbca073dd528c2ef06e95088567 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 9 Oct 2012 15:02:20 +0200 Subject: [PATCH] Add built-in font sizes (8, 12, 16) to terminal --- gems/run/terminal_echo.run | 9 +- gems/src/server/terminal/main.cc | 148 ++++++++++++------ gems/src/server/terminal/notix-8.tff | Bin 0 -> 13576 bytes gems/src/server/terminal/target.mk | 2 +- gems/src/server/terminal/terminus-12.tff | Bin 0 -> 23560 bytes .../terminal/{mono.tff => terminus-16.tff} | Bin 34824 -> 34824 bytes ports/run/noux_bash.run | 1 + 7 files changed, 105 insertions(+), 55 deletions(-) create mode 100644 gems/src/server/terminal/notix-8.tff create mode 100644 gems/src/server/terminal/terminus-12.tff rename gems/src/server/terminal/{mono.tff => terminus-16.tff} (84%) diff --git a/gems/run/terminal_echo.run b/gems/run/terminal_echo.run index 099e333c5b..add3b59af1 100644 --- a/gems/run/terminal_echo.run +++ b/gems/run/terminal_echo.run @@ -1,8 +1,3 @@ -if {[have_spec linux]} { - puts "\nLinux not supported because of missing UART driver\n" - exit 0 -} - build { core init drivers/timer server/terminal test/terminal_echo @@ -72,6 +67,10 @@ append config { + + + + diff --git a/gems/src/server/terminal/main.cc b/gems/src/server/terminal/main.cc index c57f7e8c73..ea7a5cfd94 100644 --- a/gems/src/server/terminal/main.cc +++ b/gems/src/server/terminal/main.cc @@ -97,22 +97,34 @@ inline Pixel_rgb565 mix(Pixel_rgb565 p1, Pixel_rgb565 p2, int alpha) return res; } -/* - * Font initialization - */ -extern char _binary_mono_tff_start; - -static Font mono_font (&_binary_mono_tff_start); - -static Font *fonts[4] = { &mono_font, &mono_font, - &mono_font, &mono_font }; - -enum Font_face { FONT_REGULAR, FONT_ITALIC, FONT_BOLD, FONT_BOLD_ITALIC }; - - static Color color_palette[2*8]; +class Font_family +{ + private: + + Font const &_regular; + + public: + + enum Face { REGULAR, ITALIC, BOLD, BOLD_ITALIC }; + + Font_family(Font const ®ular /* ...to be extended */ ) + : _regular(regular) { } + + /** + * Return font for specified face + * + * For now, we do not support font faces other than regular. + */ + Font const *font(Face) const { return &_regular; } + + unsigned cell_width() const { return _regular.str_w("m"); } + unsigned cell_height() const { return _regular.str_h("m"); } +}; + + struct Char_cell { unsigned char attr; @@ -125,7 +137,8 @@ struct Char_cell Char_cell() : attr(0), ascii(0) { } - Char_cell(unsigned char c, Font_face f, int colidx, bool inv, bool highlight) + Char_cell(unsigned char c, Font_family::Face f, + int colidx, bool inv, bool highlight) : attr(f | (colidx & ATTR_COLIDX_MASK) | (inv ? ATTR_INVERSE : 0) @@ -133,11 +146,11 @@ struct Char_cell ascii(c) { } - Font_face font_face() const { return (Font_face)(attr & 0x3); } + Font_family::Face font_face() const { return (Font_family::Face)(attr & 0x3); } - int colidx() const { return attr & ATTR_COLIDX_MASK; } - bool inverse() const { return attr & ATTR_INVERSE; } - bool highlight() const { return attr & ATTR_HIGHLIGHT; } + int colidx() const { return attr & ATTR_COLIDX_MASK; } + bool inverse() const { return attr & ATTR_INVERSE; } + bool highlight() const { return attr & ATTR_HIGHLIGHT; } Color fg_color() const { @@ -380,7 +393,7 @@ class Char_cell_array_character_screen : public Terminal::Character_screen if (c.ascii() > 0x10) { Cursor_guard guard(*this); _char_cell_array.set_cell(_cursor_pos.x, _cursor_pos.y, - Char_cell(c.ascii(), FONT_REGULAR, + Char_cell(c.ascii(), Font_family::REGULAR, _color_index, _inverse, _highlight)); _cursor_pos.x++; } @@ -502,7 +515,7 @@ class Char_cell_array_character_screen : public Terminal::Character_screen for (int i = 0; i < v; i++, _cursor_pos.x++) _char_cell_array.set_cell(_cursor_pos.x, _cursor_pos.y, - Char_cell(' ', FONT_REGULAR, + Char_cell(' ', Font_family::REGULAR, _color_index, _inverse, _highlight)); } @@ -725,13 +738,15 @@ inline void draw_glyph(Color fg_color, template -static void convert_char_array_to_pixels(Char_cell_array *cell_array, - PT *fb_base, - unsigned fb_width, - unsigned fb_height) +static void convert_char_array_to_pixels(Char_cell_array *cell_array, + PT *fb_base, + unsigned fb_width, + unsigned fb_height, + Font_family const &font_family) { - unsigned glyph_height = mono_font.img_h, - glyph_step_x = mono_font.wtab['m']; + Font const ®ular_font = *font_family.font(Font_family::REGULAR); + unsigned glyph_height = regular_font.img_h, + glyph_step_x = regular_font.wtab['m']; unsigned y = 0; for (unsigned line = 0; line < cell_array->num_lines(); line++) { @@ -745,15 +760,15 @@ static void convert_char_array_to_pixels(Char_cell_array *cell_array, for (unsigned column = 0; column < cell_array->num_cols(); column++) { Char_cell cell = cell_array->get_cell(column, line); - Font *font = fonts[cell.font_face()]; + Font const *font = font_family.font(cell.font_face()); unsigned char ascii = cell.ascii; if (ascii == 0) ascii = ' '; - unsigned char *glyph_base = font->img + font->otab[ascii]; + unsigned char const *glyph_base = font->img + font->otab[ascii]; - unsigned glyph_width = mono_font.wtab[ascii]; + unsigned glyph_width = regular_font.wtab[ascii]; if (x + glyph_width >= fb_width) break; @@ -845,7 +860,9 @@ namespace Terminal { Char_cell_array_character_screen _char_cell_array_character_screen; Terminal::Decoder _decoder; - Terminal::Position _last_cursor_pos; + Terminal::Position _last_cursor_pos; + + Font_family const *_font_family; /** * Initialize framebuffer-related attributes @@ -868,7 +885,8 @@ namespace Terminal { Session_component(Read_buffer *read_buffer, Framebuffer::Session *framebuffer, Genode::size_t io_buffer_size, - Flush_callback_registry &flush_callback_registry) + Flush_callback_registry &flush_callback_registry, + Font_family const &font_family) : _read_buffer(read_buffer), _framebuffer(framebuffer), _flush_callback_registry(flush_callback_registry), @@ -877,8 +895,8 @@ namespace Terminal { _fb_ds_cap(_init_fb()), /* take size of space character as character cell size */ - _char_width(mono_font.str_w("m")), - _char_height(mono_font.str_h("m")), + _char_width(font_family.cell_width()), + _char_height(font_family.cell_height()), /* compute number of characters fitting on the framebuffer */ _columns(_fb_mode.width()/_char_width), @@ -887,7 +905,9 @@ namespace Terminal { _fb_addr(Genode::env()->rm_session()->attach(_fb_ds_cap)), _char_cell_array(_columns, _lines, Genode::env()->heap()), _char_cell_array_character_screen(_char_cell_array), - _decoder(_char_cell_array_character_screen) + _decoder(_char_cell_array_character_screen), + + _font_family(&font_family) { using namespace Genode; @@ -913,7 +933,8 @@ namespace Terminal { convert_char_array_to_pixels(&_char_cell_array, (Pixel_rgb565 *)_fb_addr, _fb_mode.width(), - _fb_mode.height()); + _fb_mode.height(), + *_font_family); int first_dirty_line = 10000, @@ -1003,6 +1024,7 @@ namespace Terminal { Read_buffer *_read_buffer; Framebuffer::Session *_framebuffer; Flush_callback_registry &_flush_callback_registry; + Font_family const &_font_family; protected: @@ -1019,7 +1041,8 @@ namespace Terminal { new (md_alloc()) Session_component(_read_buffer, _framebuffer, io_buffer_size, - _flush_callback_registry); + _flush_callback_registry, + _font_family); return session; } @@ -1032,11 +1055,13 @@ namespace Terminal { Genode::Allocator *md_alloc, Read_buffer *read_buffer, Framebuffer::Session *framebuffer, - Flush_callback_registry &flush_callback_registry) + Flush_callback_registry &flush_callback_registry, + Font_family const &font_family) : Genode::Root_component(ep, md_alloc), _read_buffer(read_buffer), _framebuffer(framebuffer), - _flush_callback_registry(flush_callback_registry) + _flush_callback_registry(flush_callback_registry), + _font_family(font_family) { } }; } @@ -1354,14 +1379,14 @@ int main(int, char **) static Read_buffer read_buffer; /* initialize color palette */ - color_palette[0] = Color( 0, 0, 0); /* black */ - color_palette[1] = Color(255, 0, 0); /* red */ - color_palette[2] = Color( 0, 255, 0); /* green */ - color_palette[3] = Color(255, 255, 0); /* yellow */ - color_palette[4] = Color( 0, 0, 255); /* blue */ - color_palette[5] = Color(255, 0, 255); /* magenta */ - color_palette[6] = Color( 0, 255, 255); /* cyan */ - color_palette[7] = Color(255, 255, 255); /* white */ + color_palette[0] = Color( 0, 0, 0); /* black */ + color_palette[1] = Color(255, 0, 0); /* red */ + color_palette[2] = Color( 0, 255, 0); /* green */ + color_palette[3] = Color(255, 255, 0); /* yellow */ + color_palette[4] = Color( 0, 0, 255); /* blue */ + color_palette[5] = Color(255, 0, 255); /* magenta */ + color_palette[6] = Color( 0, 255, 255); /* cyan */ + color_palette[7] = Color(255, 255, 255); /* white */ /* the upper portion of the palette contains highlight colors */ for (int i = 0; i < 8; i++) { @@ -1370,12 +1395,39 @@ int main(int, char **) color_palette[i + 8] = col; } + /* built-in fonts */ + extern char _binary_notix_8_tff_start; + extern char _binary_terminus_12_tff_start; + extern char _binary_terminus_16_tff_start; + + /* pick font according to config file */ + char const *font_data = &_binary_terminus_16_tff_start; + try { + size_t font_size = 16; + config()->xml_node().sub_node("font") + .attribute("size").value(&font_size); + + switch (font_size) { + case 8: font_data = &_binary_notix_8_tff_start; break; + case 12: font_data = &_binary_terminus_12_tff_start; break; + case 16: font_data = &_binary_terminus_16_tff_start; break; + default: break; + } + } catch (...) { } + + static Font font(font_data); + static Font_family font_family(font); + + printf("cell size is %dx%d\n", (int)font_family.cell_width(), + (int)font_family.cell_height()); + static Terminal::Flush_callback_registry flush_callback_registry; /* create root interface for service */ static Terminal::Root_component root(&ep, &sliced_heap, &read_buffer, &framebuffer, - flush_callback_registry); + flush_callback_registry, + font_family); /* announce service at our parent */ env()->parent()->announce(ep.manage(&root)); @@ -1393,8 +1445,6 @@ int main(int, char **) * Read keyboard layout from config file */ try { - using namespace Genode; - if (config()->xml_node().sub_node("keyboard") .attribute("layout").has_value("de")) { diff --git a/gems/src/server/terminal/notix-8.tff b/gems/src/server/terminal/notix-8.tff new file mode 100644 index 0000000000000000000000000000000000000000..c4bf3c6a7fccc0ec924a71b93a926638891f088d GIT binary patch literal 13576 zcmeH~1=K9n5rh|s5QDe}LfqYrKoa8a?(XgaNgz(#-QC^Y-QC^Y^YT@7_q{W-v%fsZ z3GeU^TRkn+)qU^o&pB_gSS*eNjs|uI#{(w@rvRq{rw3;N=LF{i7X}vxmjagqR|eMr z*9A8MHwU)?cLa9>_XZCD2Y`dXqrv0BQ@}I9^T3P2E5K{Po50(_d%y?5$H1q-7rrRWsZs1tpxZp(K8MrmL1Gp==7q~xo2zWSn6gUJt89W0#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126WgLaI2Fl%YKa z9bKgu$?Ju&XB~0vbnC9=7pAwrf6p$e_~XN zYIqK3jq9PUdTildRdfr@sJPzag*wR#+E}}tET#s}L+zI5x98>=CaNNbR4^Tlnq!($ zmG*!%&RZb2az2mh9vIo2ooGSZN=0YZ^@nH>(ywgZ zZc3?GOWKWut7X*T@x>(!m1wPL(GN9lUSYL$f$piCoZ^}8VB{$iVzsK{9mT{U!|KdB zb)4L}LFj@^o;Xjq6j~)kEae_a53fl<4zgkh%fic|ybPTi8+TYFyJEy-PHK6Y21&!6 zbH=sR6z|d&8jSPI8N&=8NORj^f)@*^T;AM5lboolkKlzEV~$@nJX5uXFTiW4u+9^L zja2$1a)cc1*~8|x891WozsPlRDObU~)QnniBcD|b96k!OG+>w%%Z;m92o(oiFv1WY z_7=@KPs@=M;uA0XCYRS$#N;B9u6O!Q6X6=pF?rckTi44@$;(aTv=H#u zmK|1iI#;Y>?bmsd$}PinyrUSeti$+9;$9pM5@d%b8~W=Uv(znLef5ss(O2M9POBb5 zU-rakB`eLD6%{GhFKi$$p$hTM8s@Ufa`yBZboAb_XOerCjT9_1FdGofwoo2VD@6;J zcC8syf5|f9I;ABx`J}!StXEng>0GR0-DIyZqcgNoX_kC6iqm-$;a>F7yidqP3pUQ| z(ClW0QZCn=;9~vBQz4VW@}f7qEO=0Ln3ARnI>)%fI+?3!diO!$MvdO-<6h^}XujN} zwhc5}pC~0`5?b836wxbO%MAo9Ukv6PP7v#vHg#il%S@TroCEXJG5t8`>|4Sz>+%%H$C#u^lp0C zVbs87Z)oi)ZOyJytoNF`PLb%7 literal 0 HcmV?d00001 diff --git a/gems/src/server/terminal/target.mk b/gems/src/server/terminal/target.mk index 17761a610b..23920849a5 100644 --- a/gems/src/server/terminal/target.mk +++ b/gems/src/server/terminal/target.mk @@ -1,4 +1,4 @@ TARGET = terminal LIBS = cxx env server signal SRC_CC = main.cc -SRC_BIN = mono.tff +SRC_BIN = $(notdir $(wildcard $(PRG_DIR)/*.tff)) diff --git a/gems/src/server/terminal/terminus-12.tff b/gems/src/server/terminal/terminus-12.tff new file mode 100644 index 0000000000000000000000000000000000000000..93abd6687675101503dc27a35be2a337648b5501 GIT binary patch literal 23560 zcmeHI4XAC?7T&J=UayyKk|arzBuSDaNs=T1#i1AhTKcPtkF1r7!d1C9ia0geYw0!{_a0L})^11wp`9TY%evyMTLv2Y`ox$ABk+XMpE{mw;D+ zH-NW+_ka(9Pk_&XuYhlXAAp~M-+(`X9XoOVz%JlW;0WMo;5gt!;1u9=;4I)=-~!-c z;4%d#UyTAv)$G~U6m%ul`_rOoUufQJw|L@P3XE1*Q|IBZI z|M_>}cfkD26PPD3Phg(FJb`%v^91Gz%oCU=Fi&8fz&wHVCa`-w+RWM}6WG0IZftjB z_xjsC8C|qGz1(m#3a+HJ@m3W_l&2P>&t8M+sC+ZW{MiZH?Q`IgKO=dN-0K~SeHlsS z{N6qjh;L@Bq50~@CbLz4JIU5wUnjHjy?*9iV4~>%rS4v6eNQCxdw1#o$m%(?3@iBe zckAzWr6`tUMNVwf%RJj!^EWv+t=*9y;g9J!H%>j0yEGG~j4;FBY3Og=479da>)~GX z!$0=G#;rLF-Is?IBMXmithr5JtsR*>`UZ_7!Q(}CcxTd6e7a#3={ zR~4QQ|8%-dU-R_sH0mhx+&+8EfGIkAUT12QcSN=K$KViTT*vDmKbZZBp@vuXXO6FA z)e0`U(t=n2)*S7xN>bOU(C36FJ13D{POj08smx@G7iY%YVZvMl@Re#lx*tDF*ha4l|;HtW0mqnZrov zQ_Y`_JgG7C8{0Y2UgTTFSsl%yMz8*{Qg}<1jwie7N0(?>u5$`zFFiOHYHH;RQE!T! z9=myFJxXJ@0r3l`qv?|smzm0Q_Q0A#E~Qna%6@uEn-KM(V%1FYguVsuI2%}cg=tqI zaa0)wG0hP6?c~~hQ?`+g3=0%_7mbzPEWo$3C)bkUy#AVs%MtFOjMt=o8wEMCdcB!e zqB4BOy|8LJl#KC95;k0MIliK?Rb4x|bl9G&+ScryZbjC%}d?wOOwMJ9D zGdHXFi^>XmD`Za8G1*mIxT)wPEU&5G)@n6de^gOd(U|n9F|N~|wC%s6tn{oKqH2{s zKJ9y=mYA*b_Ox}RIF)BtKM;4E3?7^wK0deYx@n_nn?p^e=Ng&Pi>gvhfA^hJrZ;r; z;$o~=RaYss1#C+@3PoI{tIdwLqhCs_J^K=x;3XJh+D^w}fEndQp2XJ}usVT9e$>7;5? zcv8w9oXa)i)mF_oN7M*fbIz!acwxE`XVj)rA>KL;m-M^7wqZs~b;s)Uk#tm%H|!{x zy0rp5eDL-GqIT^f6vU}ExAnyKBb73K(d@vxTonQ%IaN7(+boZc(m73>P!q{nndKAG z4l8brC+5Qx4j2E@<$z$rHq=$S)LM}q`Tcrkx^jr>wz8M#BHFN8ySi$t0$YTdnOfPoyYQO6 zQj5ohz1reZtK$ci zlL)@Y5<&Y-l3f-WiLPaD#@ct6Csl^yv6=kjdS6x;wA(fBF*8UgKfz26bK`(|%Ql%g zeSna;HCoE2!PMSUYo$W#scIRuhce*V8U1k6<}TYVZEve~bVV?ysp?EDp^Qv;I(+AL*Y1u= zS%HNnl%u^hdI*(LNxJJPo5jpAeo-x*XV+6%ty(C+HD0CVhYd1+_$O@>SB)#~I_x-p ze3+a#&z3}wso7?rb;-7agP{Ue&&M{i?8>NxBkHWEYN3cnVtG+iJkLMXEWlvtT`o1F zR>b5YRA#D0&xn$s{%K^cdy_vk_zr!)DO&hq1z(!&BBtqe0yUSa^cQ`addR8DjCVOz z)BcdLUfHC+lq9HHk&MbLpE;`QRA`E`xoaFIPsds6L><4Q9)klNPJ}bX5_Jcwt64+v zD>?6m5zV<$u#d^dm2=0uSd<}OqtvR(u6%Xwe%jS){Z*AhxgYI#+;b$T*}k1h?mCX* zv#hh`(K~hfReB!JXGK=dZ)I1IuNKw14HNc A1ONa4 literal 0 HcmV?d00001 diff --git a/gems/src/server/terminal/mono.tff b/gems/src/server/terminal/terminus-16.tff similarity index 84% rename from gems/src/server/terminal/mono.tff rename to gems/src/server/terminal/terminus-16.tff index dcf78949b4c334048588a07b300709b8140f5076..e066b6965cd1bcf419e0005ce9daa05e577b6814 100644 GIT binary patch delta 708 zcmeB}z|=8;X@j7~WWg|v$qE`5Cu@}oZkE=3#sn332ow;Sd_R(7a*rzSKKYIs*JfSYCroIHEGDlElLkBE zl_k(5M?5BZ6>@EscKwFigjKRY6Fl!RO|oH|%x|ZKW)s9Y$IbXQ%lm#JU`QYyXB;;Z zn4GW0u~{?p1=Hkn_Lx?|!WHPD$-9AJs1tb=cksYXiv^m79DN`*ENK4A2~GBv1)7vd sj7h0@Oacc{CSKnG!zULQK8QpKN`vg1l?#EoAc7AkR|Nu7YUx`c0E#jl=Kufz delta 961 zcmeB}z|=8;X@j7~W+4qG#>syJxi`ycK4#j?q$9*QIaXJ2a*rzSTT_rQDOxC$dex8_Yg=tuE*0Ak+O!lk;Oau-b^~5`oG7)%=qM zq`5aMTi#=u?2{=#geHl}^Q(k`er2D0M~!QD@5qlEs +