Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_g_context_v_m_l_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_g_context_v_m_l_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:42 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: AppKit/CoreGraphics/CGContextVML.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/CoreGraphics/CGContextVML.j</h1><a href="_c_g_context_v_m_l_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"> * CGContextVML.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><a class="code" href="_c_g_context_v_m_l_8j.html#a649e09418b0f2481e0496ca66325eb1f">00023</a> var <a class="code" href="_c_g_context_v_m_l_8j.html#a649e09418b0f2481e0496ca66325eb1f">VML_TRUTH_TABLE</a>     = [ <span class="stringliteral">&quot;f&quot;</span>, <span class="stringliteral">&quot;t&quot;</span>],
<a name="l00024"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a195443622f0fd6298b3bd8e2e7d47fc0">00024</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#a195443622f0fd6298b3bd8e2e7d47fc0">VML_LINECAP_TABLE</a>   = [ <span class="stringliteral">&quot;flat&quot;</span>, <span class="stringliteral">&quot;round&quot;</span>, <span class="stringliteral">&quot;square&quot;</span> ],
<a name="l00025"></a><a class="code" href="_c_g_context_v_m_l_8j.html#adf717a005fbc8ce11e9cebe46a5fa2f9">00025</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#adf717a005fbc8ce11e9cebe46a5fa2f9">VML_LINEJOIN_TABLE</a>  = [ <span class="stringliteral">&quot;miter&quot;</span>, <span class="stringliteral">&quot;round&quot;</span>, <span class="stringliteral">&quot;bevel&quot;</span> ],
<a name="l00026"></a><a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">00026</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>   = [ <span class="stringliteral">&quot; m &quot;</span>, <span class="stringliteral">&quot; l &quot;</span>, <span class="stringliteral">&quot;qb&quot;</span>, <span class="stringliteral">&quot; c &quot;</span>, <span class="stringliteral">&quot; x &quot;</span>, [<span class="stringliteral">&quot; at &quot;</span>, <span class="stringliteral">&quot; wa &quot;</span>]];
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 var _CGBitmapGraphicsContextCreate = <a class="code" href="group__coregraphics.html#ga792b63f505ae560e354bdd49de62307c">CGBitmapGraphicsContextCreate</a>;
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a792b63f505ae560e354bdd49de62307c">00030</a> function <a class="code" href="group__coregraphics.html#ga792b63f505ae560e354bdd49de62307c">CGBitmapGraphicsContextCreate</a>()
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032     <span class="comment">// The first time around, we have to set up our environment to support vml.</span>
<a name="l00033"></a>00033     document.namespaces.add(<span class="stringliteral">&quot;cg_vml_&quot;</span>, <span class="stringliteral">&quot;urn:schemas-microsoft-com:vml&quot;</span>);
<a name="l00034"></a>00034     document.createStyleSheet().cssText = <span class="stringliteral">&quot;cg_vml_\\:*{behavior:url(#default#VML)}&quot;</span>;
<a name="l00035"></a>00035     
<a name="l00036"></a>00036     <a class="code" href="group__coregraphics.html#ga792b63f505ae560e354bdd49de62307c">CGBitmapGraphicsContextCreate</a> = _CGBitmapGraphicsContextCreate;
<a name="l00037"></a>00037     
<a name="l00038"></a>00038     <span class="keywordflow">return</span> _CGBitmapGraphicsContextCreate();
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">// FIXME: aRect is ignored.</span>
<a name="l00042"></a><a class="code" href="_c_g_context_v_m_l_8j.html#ad26b22aa810370acebe12a0656b26f8d">00042</a> function <a class="code" href="_c_g_context_canvas_8j.html#ad26b22aa810370acebe12a0656b26f8d">CGContextClearRect</a>(aContext, aRect)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044     <span class="keywordflow">if</span> (aContext.buffer != nil)
<a name="l00045"></a>00045         aContext.buffer = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00046"></a>00046     <span class="keywordflow">else</span>
<a name="l00047"></a>00047         aContext.DOMElement.innerHTML = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00048"></a>00048     
<a name="l00049"></a>00049     aContext.path = NULL;
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a0b02f09bf5aa8ca34f72487f7d0e6e63">00052</a> var <a class="code" href="_c_g_context_v_m_l_8j.html#a0b02f09bf5aa8ca34f72487f7d0e6e63">W</a> = 10.0,
<a name="l00053"></a><a class="code" href="_c_g_context_v_m_l_8j.html#abd057520df7a5dc64fe29b4edd3166a3">00053</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#abd057520df7a5dc64fe29b4edd3166a3">H</a> = 10.0,
<a name="l00054"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a0e13cb15ff3d6fbe4b9cd26ef446070e">00054</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#a0e13cb15ff3d6fbe4b9cd26ef446070e">Z</a> = 10.0,
<a name="l00055"></a><a class="code" href="_c_g_context_v_m_l_8j.html#ab0fb30b480470ba9d6cb61edf4336e85">00055</a>     <a class="code" href="_c_g_context_v_m_l_8j.html#ab0fb30b480470ba9d6cb61edf4336e85">Z_2</a> = <a class="code" href="_c_g_context_v_m_l_8j.html#a0e13cb15ff3d6fbe4b9cd26ef446070e">Z</a> / 2.0;
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">00057</a> <span class="preprocessor">#define COORD(aCoordinate) (ROUND(Z * (aCoordinate) - Z_2))</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span>
<a name="l00059"></a><a class="code" href="_c_g_context_v_m_l_8j.html#aa73a703617b790a33f95044f29cd3193">00059</a> function <a class="code" href="_c_g_context_v_m_l_8j.html#aa73a703617b790a33f95044f29cd3193">CGContextDrawImage</a>(aContext, aRect, anImage)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061     var <span class="keywordtype">string</span> = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00062"></a>00062     
<a name="l00063"></a>00063     <span class="keywordflow">if</span> (anImage.buffer != nil)
<a name="l00064"></a>00064         <span class="keywordtype">string</span> = anImage.buffer;
<a name="l00065"></a>00065     <span class="keywordflow">else</span>
<a name="l00066"></a>00066     {
<a name="l00067"></a>00067         var ctm = aContext.gState.CTM,
<a name="l00068"></a>00068             origin = <a class="code" href="_c_g_affine_transform_8j.html#ab2e1fbd101ea6fc5c3d4cff1f59d7e36">CGPointApplyAffineTransform</a>(aRect.origin, ctm),
<a name="l00069"></a>00069             similarity = ctm.a == ctm.d &amp;&amp; ctm.b == -ctm.c,
<a name="l00070"></a>00070             vml = [<span class="stringliteral">&quot;&lt;cg_vml_:group coordsize=\&quot;1,1\&quot; coordorigin=\&quot;0,0\&quot; style=\&quot;width:1;height:1;position:absolute&quot;</span>];
<a name="l00071"></a>00071           
<a name="l00072"></a>00072         <span class="comment">/*if (similarity)</span>
<a name="l00073"></a>00073 <span class="comment">        {</span>
<a name="l00074"></a>00074 <span class="comment">            var angle = CGPointMake(1.0, 0.0);</span>
<a name="l00075"></a>00075 <span class="comment">            </span>
<a name="l00076"></a>00076 <span class="comment">            angle = _CGPointApplyAffineTransform(angle, ctm);</span>
<a name="l00077"></a>00077 <span class="comment">            </span>
<a name="l00078"></a>00078 <span class="comment">            vml.push(&quot;;rotation:&quot;, ATAN2(angle.y - ctm.ty, angle.x - ctm.tx) * 180 / PI);</span>
<a name="l00079"></a>00079 <span class="comment">        }*/</span>
<a name="l00080"></a>00080     
<a name="l00081"></a>00081         <span class="comment">// Only create a filter if absolutely necessary.  This actually </span>
<a name="l00082"></a>00082         <span class="comment">// turns out to only be the case if our transform matrix is not </span>
<a name="l00083"></a>00083         <span class="comment">// a similarity matrix, that is to say, the transform actually </span>
<a name="l00084"></a>00084         <span class="comment">// morphs the shape beyond scaling and rotation.</span>
<a name="l00085"></a>00085         <span class="comment">//if (!similarity &amp;&amp; (ctm.a != 1.0 || ctm.b || ctm.c || ctm.d != 1.0))</span>
<a name="l00086"></a>00086         {
<a name="l00087"></a>00087             var transformedRect = <a class="code" href="_c_g_affine_transform_8j.html#aa2cac55239f169c578848a871f67fcb2">CGRectApplyAffineTransform</a>(aRect, ctm);
<a name="l00088"></a>00088     
<a name="l00089"></a>00089             vml.push(   <span class="stringliteral">&quot;;padding:0 &quot;</span>, ROUND(_CGRectGetMaxX(transformedRect)), <span class="stringliteral">&quot;px &quot;</span>, ROUND(_CGRectGetMaxY(transformedRect)),
<a name="l00090"></a>00090                         <span class="stringliteral">&quot;px 0;filter:progid:DXImageTransform.Microsoft.Matrix(&quot;</span>,
<a name="l00091"></a>00091                         <span class="stringliteral">&quot;M11=&apos;&quot;</span>, ctm.a, <span class="stringliteral">&quot;&apos;,M12=&apos;&quot;</span>, ctm.c, <span class="stringliteral">&quot;&apos;,M21=&apos;&quot;</span>, ctm.b, <span class="stringliteral">&quot;&apos;,M22=&apos;&quot;</span>, ctm.d, <span class="stringliteral">&quot;&apos;,&quot;</span>,
<a name="l00092"></a>00092                         <span class="stringliteral">&quot;Dx=&apos;&quot;</span>, ROUND(origin.x), <span class="stringliteral">&quot;&apos;, Dy=&apos;&quot;</span>, ROUND(origin.y), <span class="stringliteral">&quot;&apos;, sizingmethod=&apos;clip&apos;);&quot;</span>);
<a name="l00093"></a>00093         }
<a name="l00094"></a>00094         <span class="comment">//else</span>
<a name="l00095"></a>00095         <span class="comment">//    vml.push(&quot;;top:&quot;, ROUND(origin.y - 0.5), &quot;px;left:&quot;, ROUND(origin.x - 0.5), &quot;px;&quot;);</span>
<a name="l00096"></a>00096             
<a name="l00097"></a>00097         vml.push(   <span class="stringliteral">&quot;\&quot;&gt;&lt;cg_vml_:image src=\&quot;&quot;</span>, anImage._image.src, 
<a name="l00098"></a>00098                     <span class="stringliteral">&quot;\&quot; style=\&quot;width:&quot;</span>, _CGRectGetWidth(aRect), <span class="stringliteral">&quot;px;height:&quot;</span>, _CGRectGetHeight(aRect), 
<a name="l00099"></a>00099                     <span class="stringliteral">&quot;px;\&quot;/&gt;&lt;/g_vml_:group&gt;&quot;</span>);
<a name="l00100"></a>00100         
<a name="l00101"></a>00101         <span class="keywordtype">string</span> = vml.join(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103     
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (aContext.buffer != nil)
<a name="l00105"></a>00105         aContext.buffer += string;
<a name="l00106"></a>00106     <span class="keywordflow">else</span>
<a name="l00107"></a>00107         aContext.DOMElement.insertAdjacentHTML(<span class="stringliteral">&quot;BeforeEnd&quot;</span>, <span class="keywordtype">string</span>);
<a name="l00108"></a>00108 }
<a name="l00109"></a>00109 
<a name="l00110"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a50a84bacbbad420fe66e560fd51a9e53">00110</a> function <a class="code" href="_c_g_context_canvas_8j.html#a50a84bacbbad420fe66e560fd51a9e53">CGContextDrawPath</a>(aContext, aMode)
<a name="l00111"></a>00111 {
<a name="l00112"></a>00112     <span class="keywordflow">if</span> (!aContext || <a class="code" href="group__coregraphics.html#ga75236063f073e7f232d97c103185f170">CGPathIsEmpty</a>(aContext.path))
<a name="l00113"></a>00113         <span class="keywordflow">return</span>;
<a name="l00114"></a>00114     
<a name="l00115"></a>00115     var elements = aContext.path.elements,
<a name="l00116"></a>00116         
<a name="l00117"></a>00117         i = 0,
<a name="l00118"></a>00118         count = aContext.path.count,
<a name="l00119"></a>00119         
<a name="l00120"></a>00120         gState = aContext.gState,
<a name="l00121"></a>00121         fill = (aMode == <a class="code" href="_c_g_context_8j.html#aac8571f0496bc11265484d681934efaf">kCGPathFill</a> || aMode == <a class="code" href="_c_g_context_8j.html#ad7123ac2c8b7a7b1a22ea0037ff42d97">kCGPathFillStroke</a>) ? 1 : 0,
<a name="l00122"></a>00122         stroke = (aMode == <a class="code" href="_c_g_context_8j.html#a8a5478dd8a6263acdc0d712c7da25c57">kCGPathStroke</a> || aMode == <a class="code" href="_c_g_context_8j.html#ad7123ac2c8b7a7b1a22ea0037ff42d97">kCGPathFillStroke</a>) ? 1 : 0,
<a name="l00123"></a>00123         opacity = gState.alpha,
<a name="l00124"></a>00124         vml = [ <span class="stringliteral">&quot;&lt;cg_vml_:shape&quot;</span>, 
<a name="l00125"></a>00125                 <span class="stringliteral">&quot; fillcolor=\&quot;&quot;</span>, gState.fillStyle, 
<a name="l00126"></a>00126                 <span class="stringliteral">&quot;\&quot; filled=\&quot;&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a649e09418b0f2481e0496ca66325eb1f">VML_TRUTH_TABLE</a>[fill], 
<a name="l00127"></a>00127                 <span class="stringliteral">&quot;\&quot; style=\&quot;position:absolute;width:&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a0b02f09bf5aa8ca34f72487f7d0e6e63">W</a>, <span class="stringliteral">&quot;;height:&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#abd057520df7a5dc64fe29b4edd3166a3">H</a>, 
<a name="l00128"></a>00128                 <span class="stringliteral">&quot;;\&quot; coordorigin=\&quot;0 0\&quot; coordsize=\&quot;&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a0e13cb15ff3d6fbe4b9cd26ef446070e">Z</a> * W, <span class="stringliteral">&quot; &quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a0e13cb15ff3d6fbe4b9cd26ef446070e">Z</a> * H, 
<a name="l00129"></a>00129                 <span class="stringliteral">&quot;\&quot; stroked=\&quot;&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a649e09418b0f2481e0496ca66325eb1f">VML_TRUTH_TABLE</a>[stroke], 
<a name="l00130"></a>00130                 <span class="stringliteral">&quot;\&quot; strokeweight=\&quot;&quot;</span>, gState.lineWidth, 
<a name="l00131"></a>00131                 <span class="stringliteral">&quot;\&quot; strokecolor=\&quot;&quot;</span>, gState.strokeStyle, 
<a name="l00132"></a>00132                 <span class="stringliteral">&quot;\&quot; path=\&quot;&quot;</span>];
<a name="l00133"></a>00133     
<a name="l00134"></a>00134     <span class="keywordflow">for</span> (; i &lt; count; ++i)
<a name="l00135"></a>00135     {
<a name="l00136"></a>00136         var element = elements[i],
<a name="l00137"></a>00137             type = element.type;
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <span class="keywordflow">switch</span>(type)
<a name="l00140"></a>00140         {
<a name="l00141"></a>00141             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#afde27cddf02b40ea4c4a369736f4ddf4">kCGPathElementMoveToPoint</a>: 
<a name="l00142"></a>00142             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#affb51bdb84af3fe68af46b6748807536">kCGPathElementAddLineToPoint</a>:      vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[type], <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.y));
<a name="l00143"></a>00143                                                     <span class="keywordflow">break</span>;
<a name="l00144"></a>00144                                                     
<a name="l00145"></a>00145             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#a1e5ece1061fac8a78fa62f5f96958e3b">kCGPathElementAddQuadCurveToPoint</a>: vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[type], 
<a name="l00146"></a>00146                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cpx), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cpy), <span class="charliteral">&apos;,&apos;</span>,
<a name="l00147"></a>00147                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.y));
<a name="l00148"></a>00148                                                     <span class="keywordflow">break</span>;
<a name="l00149"></a>00149                                                     
<a name="l00150"></a>00150             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#a17aac2a8e9d2d2b6182d1a23e7bf41eb">kCGPathElementAddCurveToPoint</a>:     vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[type], 
<a name="l00151"></a>00151                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cp1x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cp1y), <span class="charliteral">&apos;,&apos;</span>,
<a name="l00152"></a>00152                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cp2x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.cp2y), <span class="charliteral">&apos;,&apos;</span>,
<a name="l00153"></a>00153                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(element.y));
<a name="l00154"></a>00154                                                     <span class="keywordflow">break</span>;
<a name="l00155"></a>00155                                                            
<a name="l00156"></a>00156             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#afd9cd245b331cd15188c7b3e319c4b86">kCGPathElementCloseSubpath</a>:        vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[type]);
<a name="l00157"></a>00157                                                     <span class="keywordflow">break</span>;
<a name="l00158"></a>00158             
<a name="l00159"></a>00159             <span class="keywordflow">case</span> <a class="code" href="_c_g_path_8j.html#ac1c2ae20f02a2d793033cead62938432">kCGPathElementAddArc</a>:              var x = element.x,
<a name="l00160"></a>00160                                                         y = element.y,
<a name="l00161"></a>00161                                                         radius = element.radius,
<a name="l00162"></a>00162                                                         clockwise = element.clockwise ? 1 : 0,
<a name="l00163"></a>00163                                                         endAngle = element.endAngle,
<a name="l00164"></a>00164                                                         startAngle = element.startAngle,
<a name="l00165"></a>00165                                                         
<a name="l00166"></a>00166                                                         start = _CGPointMake(x + radius * COS(startAngle), y + radius * SIN(startAngle));
<a name="l00167"></a>00167                                                     
<a name="l00168"></a>00168                                                     <span class="comment">// If the angle&apos;s are equal, then we won&apos;t actually draw an arc, but instead </span>
<a name="l00169"></a>00169                                                     <span class="comment">// simply move to its start/end to get the proper fill.</span>
<a name="l00170"></a>00170                                                     <span class="comment">// We only need this special case for anti-clockwise because start == end is </span>
<a name="l00171"></a>00171                                                     <span class="comment">// interpreted as a full circle with anti-clockwise, but empty for clockwise.</span>
<a name="l00172"></a>00172                                                     <span class="keywordflow">if</span> (startAngle == endAngle &amp;&amp; !clockwise)
<a name="l00173"></a>00173                                                     {
<a name="l00174"></a>00174                                                         vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[<a class="code" href="_c_g_path_8j.html#afde27cddf02b40ea4c4a369736f4ddf4">kCGPathElementMoveToPoint</a>], <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(start.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(start.y));
<a name="l00175"></a>00175                                                         
<a name="l00176"></a>00176                                                         <span class="keywordflow">continue</span>;
<a name="l00177"></a>00177                                                     }
<a name="l00178"></a>00178                                                     
<a name="l00179"></a>00179                                                     var end = _CGPointMake(x + radius * COS(endAngle), y + radius * SIN(endAngle));
<a name="l00180"></a>00180                                                     
<a name="l00181"></a>00181                                                     <span class="comment">// Only do the start correction if the angles aren&apos;t equal.  If they are, then </span>
<a name="l00182"></a>00182                                                     <span class="comment">// let the circle be empty.</span>
<a name="l00183"></a>00183                                                     <span class="comment">// FIXME: Should this be |star.x - end.x| &lt; 0.125 ?</span>
<a name="l00184"></a>00184                                                     <span class="keywordflow">if</span> (clockwise &amp;&amp; startAngle != endAngle &amp;&amp; _CGPointEqualToPoint(start, end))
<a name="l00185"></a>00185                                                         <span class="keywordflow">if</span> (start.x &gt;= x)
<a name="l00186"></a>00186                                                         {
<a name="l00187"></a>00187                                                             <span class="keywordflow">if</span> (start.y &lt; y)
<a name="l00188"></a>00188                                                                 start.x += 0.125;
<a name="l00189"></a>00189                                                             <span class="keywordflow">else</span>
<a name="l00190"></a>00190                                                                 start.y += 0.125;
<a name="l00191"></a>00191                                                         }
<a name="l00192"></a>00192                                                         <span class="keywordflow">else</span>
<a name="l00193"></a>00193                                                         {
<a name="l00194"></a>00194                                                             <span class="keywordflow">if</span> (end.y &lt;= y)
<a name="l00195"></a>00195                                                                 end.x += 0.125;
<a name="l00196"></a>00196                                                             <span class="keywordflow">else</span>
<a name="l00197"></a>00197                                                                 end.y += 0.125;
<a name="l00198"></a>00198                                                         }
<a name="l00199"></a>00199                                                     
<a name="l00200"></a>00200                                                     vml.push(<a class="code" href="_c_g_context_v_m_l_8j.html#af25fc1e5e2f7b8fcd5d65dd7651fe535">VML_ELEMENT_TABLE</a>[type][clockwise], 
<a name="l00201"></a>00201                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(x - radius), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(y - radius), <span class="stringliteral">&quot; &quot;</span>, 
<a name="l00202"></a>00202                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(x + radius), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(y + radius), <span class="stringliteral">&quot; &quot;</span>, 
<a name="l00203"></a>00203                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(start.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(start.y), <span class="stringliteral">&quot; &quot;</span>,
<a name="l00204"></a>00204                                                         <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(end.x), <span class="charliteral">&apos;,&apos;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#af1fd2c3a46bdf75fe468baa0e54727d0">COORD</a>(end.y));
<a name="l00205"></a>00205                                                     <span class="keywordflow">break</span>;
<a name="l00206"></a>00206             <span class="keywordflow">case</span> kCGPathElementAddArcTo:            <span class="keywordflow">break</span>;
<a name="l00207"></a>00207         }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209       <span class="comment">// TODO: Following is broken for curves due to</span>
<a name="l00210"></a>00210       <span class="comment">//       move to proper paths.</span>
<a name="l00211"></a>00211 
<a name="l00212"></a>00212       <span class="comment">// Figure out dimensions so we can do gradient fills</span>
<a name="l00213"></a>00213       <span class="comment">// properly</span>
<a name="l00214"></a>00214       <span class="comment">/*if(c) {</span>
<a name="l00215"></a>00215 <span class="comment">        if (min.x == null || c.x &lt; min.x) {</span>
<a name="l00216"></a>00216 <span class="comment">          min.x = c.x;</span>
<a name="l00217"></a>00217 <span class="comment">        }</span>
<a name="l00218"></a>00218 <span class="comment">        if (max.x == null || c.x &gt; max.x) {</span>
<a name="l00219"></a>00219 <span class="comment">          max.x = c.x;</span>
<a name="l00220"></a>00220 <span class="comment">        }</span>
<a name="l00221"></a>00221 <span class="comment">        if (min.y == null || c.y &lt; min.y) {</span>
<a name="l00222"></a>00222 <span class="comment">          min.y = c.y;</span>
<a name="l00223"></a>00223 <span class="comment">        }</span>
<a name="l00224"></a>00224 <span class="comment">        if (max.y == null || c.y &gt; max.y) {</span>
<a name="l00225"></a>00225 <span class="comment">          max.y = c.y;</span>
<a name="l00226"></a>00226 <span class="comment">        }</span>
<a name="l00227"></a>00227 <span class="comment">      }*/</span>
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     vml.push(<span class="stringliteral">&quot;\&quot;&gt;&quot;</span>);
<a name="l00231"></a>00231     
<a name="l00232"></a>00232     <span class="keywordflow">if</span> (gState.gradient)
<a name="l00233"></a>00233         vml.push(gState.gradient)
<a name="l00234"></a>00234     
<a name="l00235"></a>00235     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fill)
<a name="l00236"></a>00236         vml.push(<span class="stringliteral">&quot;&lt;cg_vml_:fill color=\&quot;&quot;</span>, gState.fillStyle, <span class="stringliteral">&quot;\&quot; opacity=\&quot;&quot;</span>, opacity, <span class="stringliteral">&quot;\&quot; /&gt;&quot;</span>);
<a name="l00237"></a>00237     
<a name="l00238"></a>00238     <span class="keywordflow">if</span> (stroke)
<a name="l00239"></a>00239         vml.push(   <span class="stringliteral">&quot;&lt;cg_vml_:stroke opacity=\&quot;&quot;</span>, opacity, 
<a name="l00240"></a>00240                     <span class="stringliteral">&quot;\&quot; joinstyle=\&quot;&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#adf717a005fbc8ce11e9cebe46a5fa2f9">VML_LINEJOIN_TABLE</a>[gState.lineJoin], 
<a name="l00241"></a>00241                     <span class="stringliteral">&quot;\&quot; miterlimit=\&quot;&quot;</span>, gState.miterLimit, 
<a name="l00242"></a>00242                     <span class="stringliteral">&quot;\&quot; endcap=\&quot;&quot;</span>, <a class="code" href="_c_g_context_v_m_l_8j.html#a195443622f0fd6298b3bd8e2e7d47fc0">VML_LINECAP_TABLE</a>[gState.lineCap],        
<a name="l00243"></a>00243                     <span class="stringliteral">&quot;\&quot; weight=\&quot;&quot;</span>, gState.lineWidth, <span class="stringliteral">&quot;&quot;</span>,
<a name="l00244"></a>00244                     <span class="stringliteral">&quot;px\&quot; color=\&quot;&quot;</span>, gState.strokeStyle,<span class="stringliteral">&quot;\&quot; /&gt;&quot;</span>);
<a name="l00245"></a>00245      
<a name="l00246"></a>00246     var shadowColor = gState.shadowColor;
<a name="l00247"></a>00247     <span class="comment">//\&quot;&quot;, [shadowColor cssString], &quot;\&quot;</span>
<a name="l00248"></a>00248     <span class="keywordflow">if</span> (shadowColor)
<a name="l00249"></a>00249     {
<a name="l00250"></a>00250         var shadowOffset = gState.shadowOffset;
<a name="l00251"></a>00251         
<a name="l00252"></a>00252         vml.push(<span class="stringliteral">&quot;&lt;cg_vml_:shadow on=\&quot;t\&quot; offset=\&quot;&quot;</span>, 
<a name="l00253"></a>00253             shadowOffset.width, <span class="stringliteral">&quot;pt &quot;</span>, shadowOffset.height, <span class="stringliteral">&quot;pt\&quot; opacity=\&quot;&quot;</span>, [shadowColor alphaComponent], <span class="stringliteral">&quot;\&quot; color=black /&gt;&quot;</span>);
<a name="l00254"></a>00254     }
<a name="l00255"></a>00255     
<a name="l00256"></a>00256     vml.push(<span class="stringliteral">&quot;&lt;/cg_vml_:shape&gt;&quot;</span>);
<a name="l00257"></a>00257 
<a name="l00258"></a>00258     aContext.path = NULL;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260     <span class="keywordflow">if</span> (aContext.buffer != nil)
<a name="l00261"></a>00261         aContext.buffer += vml.join(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00262"></a>00262     <span class="keywordflow">else</span>
<a name="l00263"></a>00263         aContext.DOMElement.insertAdjacentHTML(<span class="stringliteral">&quot;BeforeEnd&quot;</span>, vml.join(<span class="stringliteral">&quot;&quot;</span>));
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265 
<a name="l00266"></a><a class="code" href="_c_g_context_v_m_l_8j.html#a44b5b8680504ac1d5cd6e28b3f899441">00266</a> function <a class="code" href="_c_g_context_v_m_l_8j.html#a44b5b8680504ac1d5cd6e28b3f899441">to_string</a>(aColor)
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268     <span class="keywordflow">return</span> <span class="stringliteral">&quot;rgb(&quot;</span> + ROUND(aColor.components[0] * 255) + <span class="stringliteral">&quot;, &quot;</span> + ROUND(aColor.components[1] * 255) + <span class="stringliteral">&quot;, &quot;</span> + ROUND(255 * aColor.components[2]) + <span class="stringliteral">&quot;)&quot;</span>;
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 
<a name="l00271"></a><a class="code" href="_c_g_context_v_m_l_8j.html#ad5aab9a4c77342b828db694cea80e128">00271</a> function <a class="code" href="_c_g_context_v_m_l_8j.html#ad5aab9a4c77342b828db694cea80e128">CGContextDrawLinearGradient</a>(aContext, aGradient, aStartPoint, anEndPoint, options)
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     <span class="keywordflow">if</span> (!aContext || !aGradient)
<a name="l00274"></a>00274         <span class="keywordflow">return</span>;
<a name="l00275"></a>00275     
<a name="l00276"></a>00276     var vml = nil;
<a name="l00277"></a>00277     
<a name="l00278"></a>00278     <span class="keywordflow">if</span> (aGradient.vml_gradient)
<a name="l00279"></a>00279     {
<a name="l00280"></a>00280         var stops = [[aGradient.vml_gradient stops] sortedArrayUsingSelector:<span class="keyword">@selector</span>(comparePosition:)],
<a name="l00281"></a>00281             count = [stops count];
<a name="l00282"></a>00282         
<a name="l00283"></a>00283         vml = [<span class="stringliteral">&quot;&lt;cg_vml_:fill type=\&quot;gradient\&quot; method=\&quot;linear sigma\&quot; &quot;</span>];
<a name="l00284"></a>00284         vml.push(<span class="stringliteral">&quot;angle=\&quot;&quot;</span> + ([aGradient.vml_gradient angle] + 90) +<span class="stringliteral">&quot;\&quot; &quot;</span>);
<a name="l00285"></a>00285         
<a name="l00286"></a>00286         vml.push(<span class="stringliteral">&quot;colors=\&quot;&quot;</span>);
<a name="l00287"></a>00287 
<a name="l00288"></a>00288         <span class="keywordflow">for</span> (var i = 0; i &lt; count; i++)
<a name="l00289"></a>00289         {
<a name="l00290"></a>00290             vml.push(([stops[i] position]*100).toFixed(0)+<span class="stringliteral">&quot;% &quot;</span>);
<a name="l00291"></a>00291             vml.push([[[stops[i] color] colorForSlideBase:nil] cssString]);
<a name="l00292"></a>00292             
<a name="l00293"></a>00293             <span class="keywordflow">if</span> (i &lt; count-1)
<a name="l00294"></a>00294                 vml.push(<span class="stringliteral">&quot;,&quot;</span>);
<a name="l00295"></a>00295         }
<a name="l00296"></a>00296 
<a name="l00297"></a>00297         vml.push(<span class="stringliteral">&quot;\&quot; /&gt;&quot;</span>);
<a name="l00298"></a>00298     }
<a name="l00299"></a>00299     <span class="keywordflow">else</span>
<a name="l00300"></a>00300     {
<a name="l00301"></a>00301         var colors = aGradient.colors,
<a name="l00302"></a>00302             count = colors.length;
<a name="l00303"></a>00303 
<a name="l00304"></a>00304         vml = [<span class="stringliteral">&quot;&lt;cg_vml_:fill type=\&quot;gradient\&quot; &quot;</span>];
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         vml.push(<span class="stringliteral">&quot;colors=\&quot;&quot;</span>);
<a name="l00307"></a>00307 
<a name="l00308"></a>00308         <span class="keywordflow">for</span> (var i = 0; i &lt; count; i++)
<a name="l00309"></a>00309             vml.push((aGradient.locations[i]*100).toFixed(0)+<span class="stringliteral">&quot;% &quot;</span>+<a class="code" href="_c_g_context_v_m_l_8j.html#a44b5b8680504ac1d5cd6e28b3f899441">to_string</a>(colors[i])+(i&lt;count-1 ? <span class="stringliteral">&quot;,&quot;</span> : <span class="stringliteral">&quot;&quot;</span>));
<a name="l00310"></a>00310 
<a name="l00311"></a>00311         vml.push(<span class="stringliteral">&quot;\&quot; /&gt;&quot;</span>);
<a name="l00312"></a>00312     }
<a name="l00313"></a>00313     
<a name="l00314"></a>00314     aContext.gState.gradient = vml.join(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00315"></a>00315     
<a name="l00316"></a>00316     <span class="comment">// if (aContext.buffer != nil)</span>
<a name="l00317"></a>00317     <span class="comment">//     aContext.buffer += vml.join(&quot;&quot;);</span>
<a name="l00318"></a>00318     <span class="comment">// else</span>
<a name="l00319"></a>00319     <span class="comment">//     aContext.DOMElement.innerHTML = vml.join(&quot;&quot;);</span>
<a name="l00320"></a>00320 }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:54 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_g_context_v_m_l_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:42 GMT -->
</html>