ed12fd2000-02-08Henrik Grubbström (Grubba) /*
dcf3ff2011-12-28Martin Stjernholm  * $Id: listfonts.pike,v 1.23 2011/12/28 18:24:08 mast Exp $
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);
23414a2000-07-21Andreas Lange  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)
2617162001-02-05Per Hedbor  res += ({ //"<input type='hidden' name='"+(font+"/"+t)+"'/>"+
8b09a92000-03-14Martin Stjernholm  Roxen.html_encode_string(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 ), " ", "_" ); if( mapping m = info[ fn ] ) {
80cd682003-11-17Anders Johansson  string res = "<p><font><b>"+
1e6b542000-09-04Per Hedbor  (Roxen.html_encode_string(map(replace(font,"_"," ")/" ", capitalize)*" ")+ "</b></font> <font size='-1'>"+versions(font)+"</font><br />" "<table cellspacing=0 cellpadding=0"); foreach( sort( indices( m ) - ({"name","versions"}) ), string i ) res += "<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>"+i+":&nbsp;</font></td><td><font size=-1>"+ Roxen.html_encode_string(m[i])+"</font></td></tr>\n"; res += "</table>"; return res; }
80cd682003-11-17Anders Johansson  return "<p><font><b>"+
1e6b542000-09-04Per Hedbor  (Roxen.html_encode_string(map(replace(font,"_"," ")/" ",capitalize)*" ")+ "</b></font> <font size='-1'>"+versions(font)+"</font><br />");
89b41a2000-02-04Per Hedbor }
8c3d912000-09-04Per Hedbor string font_loaders( ) { string res ="<dl>";
2617162001-02-05Per Hedbor  foreach( roxen.fonts.font_handlers, FontHandler fl )
8c3d912000-09-04Per Hedbor  { int nf = sizeof( fl->available_fonts() );
80cd682003-11-17Anders Johansson  res += "<b><dt><font>"+fl->name+" ("+nf
8c3d912000-09-04Per Hedbor  +" font"+(nf==1?"":"s")+")</font></b></dt>" "<dd>"+fl->doc+"</dd><p />"; } return res+"</dl>"; }
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"
8c3d912000-09-04Per Hedbor  "<font size='+1'><b>" +
c708e52000-09-08Andreas Lange  LOCALE(58,"Available font loaders") + "</b></font><p>"+
8c3d912000-09-04Per Hedbor  font_loaders()+"<font size='+1'><b>" +
80cd682003-11-17Anders Johansson  "<br />" + LOCALE("dI","All available fonts") + "</b></font><p>");
dcf3ff2011-12-28Martin Stjernholm  foreach(sort(fonts), string font)
8b09a92000-03-14Martin Stjernholm  res+=list_font(font);
80cd682003-11-17Anders Johansson  res += ("</p><p>" + LOCALE(236,"Example text") + " "
23414a2000-07-21Andreas Lange  "<font size=-1><input name=text size=46 value='" + LOCALE(237,"Jackdaws love my big sphinx of quartz.") +
bebbad2000-08-16Andreas Lange  "'></p><p><table width='70%'><tr><td align='left'>"
028f2d2002-04-18Anders Johansson  "<cf-cancel href='?class=status'/></td><td align='right'>"
bebbad2000-08-16Andreas Lange  "<cf-next/></td></tr></table></p>");
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 }