<?php

require 'browserhawk.php';

  // This file is provided under the terms of the BrowserHawk4J license
  // agreement.  Copyright (c) 2004-2010 cyScape, Inc. All rights reserved.

  // First we make sure the system executing this example has an
  // Enterprise Edition license as required for this test.
  // Note: This is NOT needed in your pages, only for this generic sample.
  if (strpos($BrowserHawk->getVersion(), "Ent") === false) {
    echo "Enterprise License Required.  ";
    echo "You are using " . $BrowserHawk->getVersion() . ".  ";
    echo "See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.";
    return;
  }

  $fonts = "Arial,Courier,Helvetica,Palatino Linotype,Times,Trebuchet MS";
  $userFonts = "";
  if (isset($_GET["fonts"])) {
    $userFonts = $_GET["fonts"];
    $fonts = $userFonts . "," .
             str_replace(array("<", ">", "\"", "'"), " ", $fonts);
  }

  $options->addProperty("FontsInstalled");

  $checkingAll = false;
  if (isset($_GET["checkAll"])) {
    $fonts = "all";
    $checkingAll = true;
  }

  $options->setFontsToCheck($fonts);
  $options->setPageMessage("Now checking fonts...");

  $einfo = bhextended($options);

?>

<html>
<head><title>Font Test Page</title></head>

<body bgcolor=white>
<font face="helvetica">

<h2>Font Test Page</h2>

<?php
// The PHP Java bridge doesn't let you compare complex Java objects for
// identity equality, so we'll see if their toString() forms match.
if ($einfo->toString() === $UNSUPPORTED->toString()) { ?>
  <big>No extended information is available.  Only Netscape,
  Mozilla, Firefox, Chrome, IE, Opera, Safari, and AOL Explorer browsers are
  supported.</big>
<?php } else if ($einfo->getJavaScriptEnabled() === false) { ?>
  <big>No extended information is available.  This client has
  JavaScript disabled.</big>
<?php } else if (!($info->getBrowser() == "IE") || !($info->getVersion() > 5)) { ?>
  <big>No font detection is available.  Your browser has to be IE on Windows or
  Mac version 5 or later.</big>
<?php } else { ?>


<?php
  if ($checkingAll === false) {
?>
    This example tests which fonts your browser has installed.<br>
    First we check a few standard fonts.  Then you can try a few of your own.<p>
<?php
} else {
?>
    The following is a list of all fonts installed on your computer.<p>
<?php
  }
?>


<table border=1 cellspacing=2 cellpadding=5>
<tr><th align="left">Font Name</th><th>Installed</th><th>Sample output</th></tr>

<?php
  if ($checkingAll) {
     // Since we are checking for all fonts, set our fonts var to list of fonts
     // that BrowserHawk detected as installed.  This way it will enumerate
     // through the list of installed fonts.  If we're not checking for ALL
     // fonts then the fonts variable will remain set equal to the list of
     // default fonts that we tested for so those will be enumerated.
     $fonts = $einfo->getFontsInstalled();
  }

  $components = split(",", $fonts);
  foreach ($components as $font) {
?>
    <tr><td width="150"><?php echo $font ?></font></td>
        <td><?php boolprint($einfo->getFontInstalled($font)) ?></td>
        <td><font face="<?php echo $font ?>">Detect fonts with BrowserHawk!</font></td>
    </tr>
<?php
  }
?>

</table>

<br>
Want to check for your own fonts?  Enter a comma-separated list below.
<br>
Or <a href="fontcheck_adv.php?checkAll=1">click here</a> to obtain a list of
<b>all installed fonts.</b>
<form>
Fonts: <input type="text" name="fonts" size="50"
         value="<?php echo $userFonts ?>">
<input type="submit" value="Test">
</form>

<?php } ?>

<P>
<b><a href="fontcheck_adv.php">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other PHP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font>
</body>
</html>
