1 /*
  2  *Copyright (c) 2009, TellurianRing.com
  3  *All rights reserved.
  4  *
  5  *Redistribution and use in source and binary forms, with or without modification,
  6  *are permitted provided that the following conditions are met:
  7  *
  8  *   Redistributions of source code must retain the above copyright notice, this
  9  *   list of conditions and the following disclaimer.
 10  *   Redistributions in binary form must reproduce the above copyright notice,
 11  *   this list of conditions and the following disclaimer in the documentation
 12  *   and/or other materials provided with the distribution.
 13  *   Neither the name of the Organization (TellurianRing.com) nor the names of
 14  *   its contributors may be used to endorse or promote products derived from
 15  *   this software without specific prior written permission.
 16  *
 17  *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 18  *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19  *WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20  *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 21  *ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22  *(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23  *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 24  *ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25  *(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 26  *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27  */
 28 
 29 /**
 30  * @class Represents a CSS Font.
 31  * @author <a href="mailto:elberry@tellurianring.com">Eric Berry</a>
 32  * @example
 33  * // Creates a new Font object
 34  * var myFont = Font({style: "bold", size: "12px", family: "Tahoma"});
 35  * @example
 36  * // Creates a new Font with multiple families.
 37  * var myFont = Font({style: "bold", size: "12px", family: ["Tahoma", "Arial"]});
 38  * @example
 39  * // Creates a new Font using convienence method.
 40  * var myFont = font("Tahoma", "12px", "bold");
 41  * @param _details An JSON object containing the following properties:
 42  * <table cellpadding="0" cellspacing="1" border="0" class="constructor_details">
 43  *    <tr><th>Property</th> <th>Required</th> <th>Default</th></tr>
 44  *    <tr><td>family</td>   <td>no</td>       <td>Tahoma</td></tr>
 45  *    <tr><td>size</td>     <td>no</td>       <td>12px</td></tr>
 46  *    <tr><td>style</td>    <td>no</td>       <td>Font.Styles.normal</td></tr>
 47  *    <tr><td>variant</td>  <td>no</td>       <td>normal</td></tr>
 48  *    <tr><td>weight</td>   <td>no</td>       <td>Font.Weights.normal</td></tr>
 49  * </table>
 50  * @see <a href="http://www.blooberry.com/indexdot/css/properties/font/font.htm">
 51  *      Font</a> for more details on the CSS font property.
 52  */
 53 function Font(_details) { // {{{
 54    /** @constructs */
 55    function _Font(_details) { // {{{
 56       this.family = check(_details.family, "Tahoma");
 57       this.size = check(_details.size, "12px");
 58       this.style = check(_details.style, "normal");
 59       this.variant = check(_details.variant, "normal");
 60       this.weight = check(_details.weight, "normal");
 61 
 62       // toCss Creates a CSS font string from the given details.
 63       /**
 64        * Creates a CSS string from this Font object.
 65        * @function
 66        * @return A String in the format of: "[style] [variant] [weight] [size] [family(ies)]"
 67        */
 68       this.toCss = function() {
 69          var cssFont = this.style + " " + this.variant + " " + this.weight + " " + this.size
 70          if(typeof(this.family) == 'array') {
 71             for(var fi in this.family) {
 72                cssFont += " " + this.family[fi];
 73             }
 74          } else {
 75             cssFont += " " + this.family;
 76          }
 77          return cssFont;
 78       }
 79    } // }}} _Font
 80    var theFont = new _Font(_details);
 81    return theFont;
 82 } // }}} Font
 83 
 84 /**
 85  *@namespace Some Font style constants
 86  */
 87 Font.Styles = {
 88    /** @property */
 89    italic: "italic",
 90    /** @property */
 91    normal: "normal",
 92    /** @property */
 93    oblique: "oblique"
 94 };
 95 
 96 /**
 97  *@namespace Some Font weight constants
 98  */
 99 Font.Weights = {
100    /** @property */
101    bold: "bold",
102    /** @property */
103    bolder: "bolder",
104    /** @property */
105    lighter: "lighter",
106    /** @property */
107    normal: "normal"
108 };
109 // These properties are for jEdit - Programmer's Text Editor.
110 // Load this file in jEdit to see what they do.
111 // ::folding=explicit:mode=javascript:noTabs=true:collapseFolds=4::
112