Source for file FontFamilySC.class.php

Documentation is available at FontFamilySC.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."GUIManager/StyleComponent.class.php");
  4.  
  5. /**
  6. * The FontFamilySC represents CSS "font-family" values. The allowed
  7. * values are:
  8. * <ul style="font-family: monospace;">
  9. * <li> serif </li>
  10. * <li> sans-serif </li>
  11. * <li> cursive </li>
  12. * <li> fantasy </li>
  13. * <li> monospace </li>
  14. * <li> [specific-font-family] - for example: Arial, "Courier New" (if there is white space
  15. * in the name of the font, then it must be quoted)</li>
  16. * </ul>
  17. * <br /><br />
  18. * One or more values (comma separated) are allowed. Example: you can set the
  19. * value to "Arial" or "Courier, 'Courier New', monospace".
  20. * <br /><br />
  21. * The <code>StyleComponent</code> (SC) is the most basic of the three building pieces
  22. * of CSS styles. It combines a CSS property value with a ValidatorRule to ensure that
  23. * the value follows a certain format.<br /><br />
  24. *
  25. * @package harmoni.gui.scs
  26. *
  27. * @copyright Copyright &copy; 2005, Middlebury College
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  29. *
  30. * @version $Id: FontFamilySC.class.php,v 1.11 2007/09/04 20:25:22 adamfranco Exp $
  31. */
  32. class FontFamilySC extends StyleComponent {
  33.  
  34. /**
  35. * The constructor.
  36. * @param string value The value to assign to this SC.
  37. * @access public
  38. ***/
  39. function FontFamilySC($value=null) {
  40. $options = array("serif","sans-serif","cursive","fantasy","monospace");
  41.  
  42. $errDescription = "Could not validate the font-family StyleComponent value \"%s\".
  43. Allowed values are: ".implode(", ", $options)."
  44. or a specific font-family name (names with white space must be quoted).
  45. Also, you can specify one or many comma-separated values.";
  46. $rule = CSSFontFamilyValidatorRule::getRule();
  47. $displayName = "Font Family";
  48. $description = "Specifies the font to use. Allowed values are: ".implode(", ", $options)."
  49. or a specific font-family name (names with white space must be quoted).
  50. Also, you can specify one or many comma-separated values.";
  51. $this->StyleComponent($value, $rule, $options, false, $errDescription, $displayName, $description);
  52. }
  53. }
  54.  
  55.  
  56.  
  57. class CSSFontFamilyValidatorRule extends RegexValidatorRule {
  58. //@todo not tested
  59. function CSSFontFamilyValidatorRule(){
  60. $singleQuote = "'[- A-Za-z0-9]+'";
  61. $doubleQuote = "\"[- A-Za-z0-9]+\"";
  62. $noQuote = "[-A-Za-z0-9]+";
  63. $fontName = "(".$singleQuote."|".$doubleQuote."|".$noQuote.")";
  64. $re = "^(serif|sans-serif|cursive|fantasy|monospace|".$fontName."(, *".$fontName.")?)$";
  65. $this->_regex=$re;
  66. }
  67. /*
  68. function check($val) {
  69. $regs = array();
  70. $fonts = explode(",", $val);
  71. foreach ($fonts as $font)
  72. // no quotes, no white space
  73. if (ereg("^ *([a-z|A-Z])+ *$", $font))
  74. continue;
  75. // single quotes with optional white space
  76. else if (ereg("^ *'([a-z|A-Z] *)+' *$", $font))
  77. continue;
  78. // double quotes with optional white space
  79. else if (ereg("^ *\"([a-z|A-Z] *)+\" *$", $font))
  80. continue;
  81. else
  82. return false;
  83.  
  84. return true;
  85. }
  86. */
  87. /**
  88. * This is a static method to return an already-created instance of a validator
  89. * rule. There are at most about a hundred unique rule objects in use durring
  90. * any given execution cycle, but rule objects are instantiated hundreds of
  91. * thousands of times.
  92. *
  93. * This method follows a modified Singleton pattern
  94. *
  95. * @return object ValidatorRule
  96. * @access public
  97. * @static
  98. * @since 3/28/05
  99. */
  100. function getRule () {
  101. // Because there is no way in PHP to get the class name of the descendent
  102. // class on which this method is called, this method must be implemented
  103. // in each descendent class.
  104.  
  105. if (!is_array($GLOBALS['validator_rules']))
  106. $GLOBALS['validator_rules'] = array();
  107. $class = __CLASS__;
  108. if (!isset($GLOBALS['validator_rules'][$class]))
  109. $GLOBALS['validator_rules'][$class] = new $class;
  110. return $GLOBALS['validator_rules'][$class];
  111. }
  112. }
  113.  
  114.  
  115. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:18 -0400 by phpDocumentor 1.3.0RC3