Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_font_8j_source.html

Full commit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_font_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:30 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: AppKit/CPFont.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>AppKit/CPFont.j</h1><a href="_c_p_font_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPFont.j</span>
<a name="l00003"></a>00003 <span class="comment"> * AppKit</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 var _CPFonts                = {},
<a name="l00024"></a>00024     _CPFontSystemFontFace   = <span class="stringliteral">@&quot;Arial, sans-serif&quot;</span>,
<a name="l00025"></a>00025     _CPWrapRegExp           = <span class="keyword">new</span> RegExp(<span class="stringliteral">&quot;\\s*,\\s*&quot;</span>, <span class="stringliteral">&quot;g&quot;</span>);
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#define _CPCreateCSSString(aName, aSize, isBold) (isBold ? </span><span class="stringliteral">@&quot;bold &quot;</span> : <span class="stringliteral">@&quot;&quot;</span>) + ROUND(aSize) + <span class="stringliteral">@&quot;px &quot;</span> + ((aName === _CPFontSystemFontFace) ? aName : (<span class="stringliteral">@&quot;\&quot;&quot; + aName.replace(_CPWrapRegExp, &apos;&quot;</span>, &quot;&apos;) + <span class="stringliteral">@&quot;\&quot;</span>, &quot; + _CPFontSystemFontFace))
<a name="l00029"></a>00029 <span class="preprocessor">#define _CPCachedFont(aName, aSize, isBold) _CPFonts[_CPCreateCSSString(aName, aSize, isBold)]</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00037"></a><a class="code" href="class_c_p_font.html">00037</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_font.html">CPFont</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039     <a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>    _name;
<a name="l00040"></a>00040     <span class="keywordtype">float</span>       _size;
<a name="l00041"></a>00041     BOOL        _isBold;
<a name="l00042"></a>00042     
<a name="l00043"></a>00043     <a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>    _cssString;
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00052"></a><a class="code" href="class_c_p_font.html#a7743052c1b5925a47efb49080b4864b6">00052</a> + (<a class="code" href="class_c_p_font.html">CPFont</a>)fontWithName:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aName size:(<span class="keywordtype">float</span>)aSize
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054     <span class="keywordflow">return</span> _CPCachedFont(aName, aSize, NO) || [[<a class="code" href="class_c_p_font.html">CPFont</a> alloc] _initWithName:aName size:aSize bold:NO];
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00063"></a><a class="code" href="class_c_p_font.html#ad07cba707ca28895d8483750bc1fd022">00063</a> + (<a class="code" href="class_c_p_font.html">CPFont</a>)boldFontWithName:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aName size:(<span class="keywordtype">float</span>)aSize
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065     <span class="keywordflow">return</span> _CPCachedFont(aName, aSize, YES) || [[<a class="code" href="class_c_p_font.html">CPFont</a> alloc] _initWithName:aName size:aSize bold:YES];
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00073"></a><a class="code" href="class_c_p_font.html#acc46c8f9ff7da14a2cf974d048ce80bd">00073</a> + (<a class="code" href="class_c_p_font.html">CPFont</a>)systemFontOfSize:(CPSize)aSize
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     <span class="keywordflow">return</span> _CPCachedFont(_CPFontSystemFontFace, aSize, NO) || [[<a class="code" href="class_c_p_font.html">CPFont</a> alloc] _initWithName:_CPFontSystemFontFace size:aSize bold:NO];
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 
<a name="l00083"></a><a class="code" href="class_c_p_font.html#ad01b27fa98100994a257ecc5f2c51a47">00083</a> + (<a class="code" href="class_c_p_font.html">CPFont</a>)boldSystemFontOfSize:(CPSize)aSize
<a name="l00084"></a>00084 {
<a name="l00085"></a>00085     <span class="keywordflow">return</span> _CPCachedFont(_CPFontSystemFontFace, aSize, YES) || [[<a class="code" href="class_c_p_font.html">CPFont</a> alloc] _initWithName:_CPFontSystemFontFace size:aSize bold:YES];
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="comment">/*  FIXME Font Descriptor</span>
<a name="l00089"></a>00089 <span class="comment">    @ignore</span>
<a name="l00090"></a>00090 <span class="comment">*/</span>
<a name="l00091"></a>00091 - (id)_initWithName:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aName size:(<span class="keywordtype">float</span>)aSize bold:(BOOL)isBold
<a name="l00092"></a>00092 {   
<a name="l00093"></a>00093     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00094"></a>00094     
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097         _name = aName;
<a name="l00098"></a>00098         _size = aSize;
<a name="l00099"></a>00099         _isBold = isBold;
<a name="l00100"></a>00100         
<a name="l00101"></a>00101         _cssString = _CPCreateCSSString(_name, _size, _isBold);
<a name="l00102"></a>00102         
<a name="l00103"></a>00103         _CPFonts[_cssString] = <span class="keyword">self</span>;
<a name="l00104"></a>00104     }
<a name="l00105"></a>00105     
<a name="l00106"></a>00106     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00112"></a><a class="code" href="class_c_p_font.html#addb96d570fa4dd30bf610fb71f739c6e">00112</a> - (float)<a class="code" href="_c_p_screen_8j.html#ad241596b0d0f8cbdd1529d94ea71337b">size</a>
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114     <span class="keywordflow">return</span> _size;
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116 
<a name="l00120"></a><a class="code" href="class_c_p_font.html#ade1d8ffe91cab2427fdd35472a58795d">00120</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)cssString
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122     <span class="keywordflow">return</span> _cssString;
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 
<a name="l00128"></a><a class="code" href="class_c_p_font.html#ab35d92321459af4cbde82104599ac195">00128</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)familyName
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     <span class="keywordflow">return</span> _name;
<a name="l00131"></a>00131 }
<a name="l00132"></a>00132 
<a name="l00133"></a><a class="code" href="class_c_p_font.html#a4e694cf449c3547366382cd8585c1199">00133</a> - (BOOL)isEqual:(<span class="keywordtype">id</span>)anObject
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135     <span class="keywordflow">return</span> [anObject isKindOfClass:[<a class="code" href="class_c_p_font.html">CPFont</a> class]] &amp;&amp; [anObject cssString] === [<span class="keyword">self</span> <a class="code" href="class_c_p_font.html#ade1d8ffe91cab2427fdd35472a58795d">cssString</a>];
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00138"></a><a class="code" href="class_c_p_font.html#a5cb7be6944eb5a89ac7fecc145b0bad1">00138</a> - (<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)description
<a name="l00139"></a>00139 {
<a name="l00140"></a>00140     <span class="keywordflow">return</span> [<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a> <a class="code" href="class_c_p_string.html#a7d9e7b4329b51daf0c3b43d6183d4eec">stringWithFormat</a>:@&quot;%@ %@ %f pt.&quot;, [<span class="keyword">super</span> description], [<span class="keyword">self</span> <a class="code" href="class_c_p_font.html#ab35d92321459af4cbde82104599ac195">familyName</a>], [<span class="keyword">self</span> <a class="code" href="class_c_p_font.html#addb96d570fa4dd30bf610fb71f739c6e">size</a>]];
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 <span class="keyword">@end</span>
<a name="l00144"></a>00144 
<a name="l00145"></a><a class="code" href="_c_p_font_8j.html#a6d3482a0bfd99907a244c04972987620">00145</a> var <a class="code" href="_c_p_font_8j.html#a6d3482a0bfd99907a244c04972987620">CPFontNameKey</a>   = <span class="stringliteral">@&quot;CPFontNameKey&quot;</span>,
<a name="l00146"></a><a class="code" href="_c_p_font_8j.html#af83ea92896a8b10e11dfebefe07a49b7">00146</a>     <a class="code" href="_c_p_font_8j.html#af83ea92896a8b10e11dfebefe07a49b7">CPFontSizeKey</a>   = <span class="stringliteral">@&quot;CPFontSizeKey&quot;</span>,
<a name="l00147"></a><a class="code" href="_c_p_font_8j.html#aacd5e5f20b81d2f280f47fd86d70adf7">00147</a>     <a class="code" href="_c_p_font_8j.html#aacd5e5f20b81d2f280f47fd86d70adf7">CPFontIsBoldKey</a> = <span class="stringliteral">@&quot;CPFontIsBoldKey&quot;</span>;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149 <span class="keyword">@implementation </span><a class="code" href="class_c_p_font.html">CPFont</a> (CPCoding)
<a name="l00150"></a>00150 
<a name="l00156"></a><a class="code" href="class_c_p_font.html#af5036102257203dc7f5a4755f845eb86">00156</a> - (id)initWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00157"></a>00157 {
<a name="l00158"></a>00158     <span class="keywordflow">return</span> [<span class="keyword">self</span> _initWithName:[aCoder decodeObjectForKey:CPFontNameKey]
<a name="l00159"></a>00159         size:[aCoder decodeFloatForKey:CPFontSizeKey]
<a name="l00160"></a>00160         bold:[aCoder decodeBoolForKey:CPFontIsBoldKey]];
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 
<a name="l00167"></a><a class="code" href="class_c_p_font.html#a5086fd104fb94f80d746233cb9b612ae">00167</a> - (void)encodeWithCoder:(<a class="code" href="class_c_p_coder.html" title="Defines methods for use when archiving &amp;amp; restoring (enc/decoding).">CPCoder</a>)aCoder
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169     [aCoder encodeObject:_name forKey:CPFontNameKey];
<a name="l00170"></a>00170     [aCoder encodeFloat:_size forKey:CPFontSizeKey];
<a name="l00171"></a>00171     [aCoder encodeBool:_isBold forKey:CPFontIsBoldKey];
<a name="l00172"></a>00172 }
<a name="l00173"></a>00173 
<a name="l00174"></a>00174 <span class="keyword">@end</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:55 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_font_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:30 GMT -->
</html>