flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [07/36] git commit: [flex-asjs] [refs/heads/develop] - CSS Font loading
Date Tue, 28 Jul 2015 18:40:33 GMT
CSS Font loading


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c28c2fe8
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c28c2fe8
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c28c2fe8

Branch: refs/heads/develop
Commit: c28c2fe8474c49d1a986cedd57a61ad1daa8891f
Parents: a348641
Author: Alex Harui <aharui@apache.org>
Authored: Mon Jul 13 21:56:32 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Jul 13 21:56:32 2015 -0700

----------------------------------------------------------------------
 .../src/org/apache/flex/core/CSSFontFaceBead.as | 140 +++++++++++++++++++
 frameworks/projects/Core/basic-manifest.xml     |   1 +
 .../src/org/apache/flex/core/CSSFontFaceBead.js |  54 +++++++
 3 files changed, 195 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c28c2fe8/frameworks/projects/Core/as/src/org/apache/flex/core/CSSFontFaceBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/CSSFontFaceBead.as b/frameworks/projects/Core/as/src/org/apache/flex/core/CSSFontFaceBead.as
new file mode 100644
index 0000000..f17f33b
--- /dev/null
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/CSSFontFaceBead.as
@@ -0,0 +1,140 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.core
+{
+    import flash.display.Loader;
+    import flash.system.LoaderContext;
+    import flash.events.Event;
+    import flash.events.IOErrorEvent;
+    import flash.events.SecurityErrorEvent;
+    import flash.net.URLRequest;
+    import flash.system.ApplicationDomain;
+    import flash.utils.getQualifiedClassName;
+    
+    import org.apache.flex.events.Event;
+    import org.apache.flex.events.IEventDispatcher;
+    import org.apache.flex.events.ValueEvent;
+    
+    /**
+     *  The CSSFontFaceBead class is the class that loads swfs
+     *  of converted fonts so they can be used in Flash.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class CSSFontFaceBead implements IBead
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function CSSFontFaceBead()
+		{
+		}
+		
+        private var _strand:IStrand;
+        
+        /**
+         *  @copy org.apache.flex.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function set strand(value:IStrand):void
+        {
+            _strand = value;
+            IEventDispatcher(ValuesManager.valuesImpl).addEventListener("init", initHandler);
+            IEventDispatcher(_strand).addEventListener("preinitialize", preinitHandler);
+            var mainClassName:String = getQualifiedClassName(value);
+            var styleClassName:String = "_" + mainClassName + "_Styles";
+            var c:Class = ApplicationDomain.currentDomain.getDefinition(styleClassName) as
Class;
+            requestFonts(c["fontFaces"]);
+        }
+            
+        private var loaders:Array;
+        
+        private function initHandler(event:ValueEvent):void
+        {
+            var fontFaces:Array = event.value as Array;
+            if (fontFaces)
+                requestFonts(fontFaces);
+        }
+        
+        private function requestFonts(fontFaces:Array):void
+        {
+            if (!loaders)
+                loaders = [];
+            
+            for each (var url:String in fontFaces)
+            {
+                // swap swf in suffix
+                var c:int = url.lastIndexOf(".");
+                url = url.substr(0, c) + ".swf";
+                var foo:Loader = new Loader();
+                var bar:URLRequest = new URLRequest(url);
+                var ctx:LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain);
+                foo.load(bar, ctx);
+                foo.name = url;
+                foo.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, completeHandler);
+                foo.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
+                foo.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
errorHandler);
+                loaders.push(foo.contentLoaderInfo);
+            }
+        }
+        
+        private function completeHandler(event:flash.events.Event):void
+        {
+            removeTarget(event.target);
+        }
+        
+        private function errorHandler(event:flash.events.Event):void
+        {
+            trace("error loading font from: ", event.target.name);
+            removeTarget(event.target);
+        }
+        
+        private function removeTarget(target:Object):void
+        {
+            var n:int = loaders.length;
+            for (var i:int = 0; i < n; i++)
+            {
+                if (loaders[i] === target)
+                {
+                    loaders.splice(i, 1);
+                    if (loaders.length == 0)
+                        IEventDispatcher(_strand).removeEventListener("preinitialize", preinitHandler);
                       
+                    break;
+                }
+            }
+        }
+                
+        private function preinitHandler(event:org.apache.flex.events.Event):void
+        {
+            event.preventDefault();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c28c2fe8/frameworks/projects/Core/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/basic-manifest.xml b/frameworks/projects/Core/basic-manifest.xml
index ac43d5e..995157d 100644
--- a/frameworks/projects/Core/basic-manifest.xml
+++ b/frameworks/projects/Core/basic-manifest.xml
@@ -27,6 +27,7 @@
     <component id="ViewBase" class="org.apache.flex.core.ViewBase"/>
     <component id="MXMLDragInitiator" class="org.apache.flex.core.MXMLDragInitiator" />
     <component id="CallLaterBead" class="org.apache.flex.core.CallLaterBead" />
+    <component id="CSSFontFaceBead" class="org.apache.flex.core.CSSFontFaceBead" />
 
     <component id="BindableCSSStyles" class="org.apache.flex.core.BindableCSSStyles"/>
     <component id="SimpleCSSStyles" class="org.apache.flex.core.SimpleCSSStyles"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c28c2fe8/frameworks/projects/Core/js/src/org/apache/flex/core/CSSFontFaceBead.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/js/src/org/apache/flex/core/CSSFontFaceBead.js b/frameworks/projects/Core/js/src/org/apache/flex/core/CSSFontFaceBead.js
new file mode 100644
index 0000000..8d72363
--- /dev/null
+++ b/frameworks/projects/Core/js/src/org/apache/flex/core/CSSFontFaceBead.js
@@ -0,0 +1,54 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the 'License');
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an 'AS IS' BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+goog.provide('org_apache_flex_core_CSSFontFaceBead');
+
+
+
+/**
+ * @constructor
+ * This is just a stub.
+ */
+org_apache_flex_core_CSSFontFaceBead = function() {
+
+  /**
+   * @private
+   * @type {Object}
+   */
+  this.strand_ = null;
+
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org_apache_flex_core_CSSFontFaceBead.prototype.FLEXJS_CLASS_INFO =
+    { names: [{ name: 'CSSFontFaceBead.js',
+                qName: 'org_apache_flex_core_CSSFontFaceBead'}] };
+
+
+Object.defineProperties(org_apache_flex_core_CSSFontFaceBead.prototype, {
+    /** @export */
+    strand: {
+        /** @this {org_apache_flex_binding_GenericBinding} */
+        set: function(value) {
+            if (this.strand_ !== value) {
+              this.strand_ = value;
+            }
+        }
+    }
+});


Mime
View raw message