ed12fd2000-02-08Henrik Grubbström (Grubba) /*
0917d32013-03-04Anders Johansson  * $Id$
ed12fd2000-02-08Henrik Grubbström (Grubba)  */
23414a2000-07-21Andreas Lange #include <roxen.h>
bebbad2000-08-16Andreas Lange //<locale-token project="admin_tasks"> LOCALE </locale-token> #define LOCALE(X,Y) _STR_LOCALE("admin_tasks",X,Y)
23414a2000-07-21Andreas Lange 
48ad1f2000-09-19Per Hedbor constant action = "status";
bebbad2000-08-16Andreas Lange  string name= LOCALE(10, "List fonts"); string doc = LOCALE(11, "List all available fonts");
09348f2000-02-04Per Hedbor 
23414a2000-07-21Andreas Lange 
89b41a2000-02-04Per Hedbor string versions(string font) { array res=({ }); array b = available_font_versions(font,32);
fc8ffc2017-05-23Pontus Östlund  if (!b || !sizeof(b)) return "<b>"+LOCALE("dH","Not available.")+"</b>";
09348f2000-02-04Per Hedbor  array a = map(b,describe_font_type);
89b41a2000-02-04Per Hedbor  mapping m = mkmapping(b,a); foreach(sort(indices(m)), string t)
fc8ffc2017-05-23Pontus Östlund  res += ({ m[t] });
89b41a2000-02-04Per Hedbor  return String.implode_nicely(res); }
2617162001-02-05Per Hedbor 
1e6b542000-09-04Per Hedbor mapping info;
89b41a2000-02-04Per Hedbor string list_font(string font) {
1e6b542000-09-04Per Hedbor  string fn = replace(lower_case( font ), " ", "_" );
fc8ffc2017-05-23Pontus Östlund  string tmpl = #" {{ #name }} <h3 class='section{{^do_info}} no-margin-bottom{{/do_info}}'>{{ name }} <small>&ndash; {{ versions }}</small></h3> {{ /name }} {{ #do_info }} <table class='auto indent extra'> {{ #info }} <tr> <th>{{ key }}:</th> <td>{{ value }} </tr> {{ /info }} </table> {{ /do_info }}"; mapping data = ([ "name" : map(replace(font,"_"," ")/" ", capitalize)*" ", "versions" : versions(font), "info" : ({}) ]); if (mapping m = info[fn]) { data->do_info = true; foreach( sort( indices( m ) - ({"name","versions"}) ), string i ) { if (intp(m[i]) || (stringp(m[i]) && sizeof(m[i]))) { data->info += ({ ([ "key" : i, "value" : (string)m[i] ]) }); } }
1e6b542000-09-04Per Hedbor  }
fc8ffc2017-05-23Pontus Östlund  Mustache m = Mustache(); string res = m->render(tmpl, data); destruct(m); return res;
89b41a2000-02-04Per Hedbor }
8c3d912000-09-04Per Hedbor string font_loaders( ) {
fc8ffc2017-05-23Pontus Östlund  string res ="";
2617162001-02-05Per Hedbor  foreach( roxen.fonts.font_handlers, FontHandler fl )
8c3d912000-09-04Per Hedbor  { int nf = sizeof( fl->available_fonts() );
fc8ffc2017-05-23Pontus Östlund  res += "<dl><dt>"+fl->name+" ("+nf +" font"+(nf==1?"":"s")+")</dt>" "<dd>"+fl->doc+"</dd></dl>";
8c3d912000-09-04Per Hedbor  }
fc8ffc2017-05-23Pontus Östlund  return res;
8c3d912000-09-04Per Hedbor }
bebbad2000-08-16Andreas Lange string page_0(RequestID id)
89b41a2000-02-04Per Hedbor {
dcf3ff2011-12-28Martin Stjernholm  array fonts = roxen.fonts.available_fonts(1);
2617162001-02-05Per Hedbor  array q = roxen.fonts.get_font_information();
1e6b542000-09-04Per Hedbor  info = mkmapping( q->name, q );
bebbad2000-08-16Andreas Lange  string res=("<input type='hidden' name='action' value='listfonts.pike'/>" "<input type='hidden' name='doit' value='indeed'/>\n"
fc8ffc2017-05-23Pontus Östlund  "<h2 class='no-margin-top'>" + LOCALE(58,"Available font loaders") + "</h2><p>"+ font_loaders()+"<h3 class='section'>" + LOCALE("dI","All available fonts") + "</h3><p>"); foreach(sort(fonts), string font) { res += list_font(font); } res += ("</p><hr class='section'><p>" + LOCALE(236,"Example text") + ": " "<input name=text size=46 value='" + LOCALE(237,"Jackdaws love my big sphinx of quartz.") + "'></p><hr class='section'>" "<table><tr><td>" "<cf-cancel href='?class=status&amp;&usr.set-wiz-id;'/></td>" "<td class='text-right'>" "<cf-next/></td></tr></table>");
89b41a2000-02-04Per Hedbor  return res; }
bebbad2000-08-16Andreas Lange string page_1(RequestID id)
89b41a2000-02-04Per Hedbor { string res="";
2617162001-02-05Per Hedbor  mapping v = id->real_variables;
f671c22001-08-27Per Hedbor  string txt = v->text && v->text[0];
2617162001-02-05Per Hedbor  foreach(roxen.fonts.available_fonts(), string fn) res += Roxen.html_encode_string( fn )+":<br />\n"
f671c22001-08-27Per Hedbor  "<gtext fontsize=16 align='top' font='"+fn+"'>"+Roxen.html_encode_string(txt)+"</gtext><br>" "<gtext fontsize=32 align='top' font='"+fn+"'>"+Roxen.html_encode_string(lower_case(txt))+"</gtext><br>" "<gtext fontsize=48 align='top' font='"+fn+"'>"+Roxen.html_encode_string(upper_case(txt))+"</gtext><p>";
bebbad2000-08-16Andreas Lange  return res+"<br /></p><p>\n<cf-ok/></p>";
89b41a2000-02-04Per Hedbor }
23414a2000-07-21Andreas Lange mixed parse( RequestID id )
89b41a2000-02-04Per Hedbor {
4f27572000-02-04Per Hedbor  if( id->variables->doit ) return page_1( id ); return page_0( id );
89b41a2000-02-04Per Hedbor }