Fixed the function responsible for returning a list of fonts available

This commit is contained in:
Mark Nelson 2013-04-11 19:06:18 +08:00
parent 7c4e8def0c
commit 3e446120d2

19
lib.php
View file

@ -397,6 +397,9 @@ function customcert_get_fonts() {
// Set the name of the font to null, the include next should then set this // Set the name of the font to null, the include next should then set this
// value, if it is not set then the file does not include the necessary data. // value, if it is not set then the file does not include the necessary data.
$name = null; $name = null;
// Some files include a display name, the include next should then set this
// value if it is present, if not then $name is used to create the display name.
$displayname = null;
// Some of the TCPDF files include files that are not present, so we have to // Some of the TCPDF files include files that are not present, so we have to
// suppress warnings, this is the TCPDF libraries fault, grrr. // suppress warnings, this is the TCPDF libraries fault, grrr.
@include("$fontdir/$font"); @include("$fontdir/$font");
@ -404,13 +407,17 @@ function customcert_get_fonts() {
if (is_null($name)) { if (is_null($name)) {
continue; continue;
} }
// Format the font name, so "FontName-Style" becomes "Font Name - Style". // Remove the extension of the ".php" file that contains the font information.
$formatname = preg_replace("/([a-z])([A-Z])/", "$1 $2", $name); $filename = basename($font, ".php");
$formatname = preg_replace("/([a-zA-Z])-([a-zA-Z])/", "$1 - $2", $formatname); // Check if there is no display name to use.
$options[$name] = $formatname; if (is_null($displayname)) {
ksort($options); // Format the font name, so "FontName-Style" becomes "Font Name - Style".
$displayname = preg_replace("/([a-z])([A-Z])/", "$1 $2", $name);
$displayname = preg_replace("/([a-zA-Z])-([a-zA-Z])/", "$1 - $2", $displayname);
}
$options[$filename] = $displayname;
} }
ksort($options);
} }
return $options; return $options;