File: render.pike

package info (click to toggle)
caudium 2%3A1.2.35.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 12,956 kB
  • ctags: 1,470
  • sloc: ansic: 9,557; sh: 2,298; cpp: 1,365; makefile: 772; perl: 389; xml: 1
file content (75 lines) | stat: -rw-r--r-- 2,120 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
array colors = ({
  "black",
  "brown",
  "cyan",
  "darkblue",
  "darkred",
  "green",
  "orange",
  "pink",
  "red",
  "white",
});


array (string) list_fonts()
{
  return caudium->available_fonts(1);
}

string make_select(array (string) from, string selected)
{
  array res = ({});
  string s;
  if(!selected) selected="";
  foreach(from, s)
  {
    if((s-" ")==(selected-" "))
      res += ({ "<option value='"+s+"' selected>"+s });
    else
      res += ({ "<option value='"+s+"'>"+s });
  }
  return res*"";
}

array trim(array in)
{
  return Array.map(in,lambda(string s){
    if(sscanf(s, "%*s%*d")==2) return 0;return s;
  })-({0});
}

string parse(object id)
{
  string args ="";
  if(id->variables->weight=="bold") args += " bold";
  if(id->variables->weight=="light") args += " light";
  if(id->variables->weight=="black") args += " black";
  if(id->variables->italic == "italic") args += " italic";

  if(!id->variables->txt) id->variables->txt="Enter text here";
  
  if(!id->variables->color) id->variables->color="white";
  if(!id->variables->bg) id->variables->bg="black";

  return ("<body bgcolor="+id->variables->bg+" text="+id->variables->color+"> "
	  "<form><table><tr><td>Text to render: (\\n is newline)<br><input size=60,1 name=txt value=\""+
	  id->variables->txt+"\">\n"
	  "<table><tr><td>Text</td><td>Background</td><td"
	  " rowspan=2><input type=submit value=Go></td><tr>"
	  "<td><select name=color>"+
	  make_select(colors,id->variables->color)+"</select></td><td>"
	  "<select name=bg>"+
	  make_select(colors,id->variables->bg)+"</select><br></td></table>"
	  "</tr><tr><td>Font:<br><select name=font>"+
	  make_select(sort(list_fonts()), id->variables->font)+
	  "</select>"+"<select name=weight>"+
	  make_select(({"normal","bold","black","light"}),
		      id->variables->weight)+
	  "</select><select name=italic>"+
	  make_select(({"italic","plain"}), id->variables->italic)+
	  "</select></form></table><br>"
	  "<gtext nocache "+args+" nfont=\""+id->variables->font+"\">"+
	  replace(id->variables->txt,({"\\n","<",">","&"}),({"\n","&lt;","&gt;","&amp;"}))+
	  "</gtext>");
}