Roxen.git/
server/
font_handlers/
old.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2008-11-13
2008-11-13 07:32:14 by Jonas Wallden <jonasw@roxen.com>
631e743f1aabdf8fd605683920602a6f28f71759 (
56
lines) (+
40
/-
16
)
[
Show
|
Annotate
]
Branch:
5.2
Reduce number of font directory accesses.
Rev: server/font_handlers/old.pike:1.13
2:
// Copyright © 1996 - 2004, Roxen IS. #include <config.h>
-
constant cvs_version = "$Id: old.pike,v 1.
12
2004
/
06
/
30
16
:
58
:
49
mast
Exp $";
+
constant cvs_version = "$Id: old.pike,v 1.
13
2008
/
11
/
13
07
:
32
:
14
jonasw
Exp $";
constant name = "Compatibility bitmap fonts"; constant doc =
12:
inherit FontHandler;
-
array
available
_
fonts
()
+
Thread.Mutex
lock = Thread.Mutex();
+
+
protected mapping font
_
cache;
+
+
protected void build_font_cache
()
{
-
array
res = (
{}
);
+
mapping
res = (
[ ]
);
foreach(roxen->query("font_dirs"), string dir) { dir+="32/";
31:
string style) if(has_value(d, style)) {
-
res
|=
({
replace(f,"_", " ")
})
;
-
break;
+
res
["32/"
+ f + "/" + style]
= replace(f,
"_", " ");
} } } } }
-
return
res;
+
font_cache
=
res;
}
-
+
array available_fonts(int(0..1)|void force_reload)
+
{
+
Thread.MutexKey key = lock->lock();
+
if (!font_cache || force_reload)
+
build_font_cache();
+
return Array.uniq(values(font_cache));
+
}
+
array(mapping) font_information( string fnt ) { string ofnt = fnt;
87:
array available, fallback_available; if( String.width( name ) > 8 ) return 0;
-
foreach(roxen
->
query
(
"font_dirs"
)
,
string
dir
)
-
{
-
base
_
dir
=
dir+size+
"/"
+fix
_name(name);
-
if
(
available
=
r
_
get_dir
(
base_dir
))
-
break
;
-
if (!
fallback_available
) {
-
base_
dir=
dir+
"/
32/
"
+fix
_name(name);
-
fallback
_available = r_get_dir(base_dir);
+
+
Thread.MutexKey key = lock
->
lock
()
;
+
if (!font_cache
)
+
build_font_cache();
+
+
string
match
_
prefix
=
size +
"/"
+ fix
_name(name)
+ "/"
;
+
array
matches
=
filter
(
indices(font_cache),
has_prefix,
match
_
prefix);
+
if
(
sizeof(matches
))
+
return
map(matches,
`[], sizeof(match_prefix), 99999)
;
+
+
if (
size
!
= 32) {
+
foreach(roxen->query("font
_
dirs"
)
,
string dir)
{
+
string key
=
size +
"/"
+ fix
_name(name);
+
base
_
dir = dir + key;
+
if (
available = r_get_dir(base_dir)
) {
+
foreach(available - ({ "CVS" }), string style)
+
font_cache[key + "/" + style] = name
;
+
return available;
} }
-
if(!available
&&
!fallback_available)
return
0;
-
return
(available
?
available : fallback
_
available) -
(
{
"CVS" }
);
+
key
=
0;
+
return
has
_
font
(
name,
32
);
}
-
+
return 0;
+
}
class MyFont { inherit Image.Font;