You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2015/07/15 02:55:02 UTC

[4/5] git commit: [flex-falcon] [refs/heads/develop] - handle more complex font-face

handle more complex font-face


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

Branch: refs/heads/develop
Commit: 1f8f602c2ac8442cd6d5cc55168d64a0c7278ffc
Parents: 350daad
Author: Alex Harui <ah...@apache.org>
Authored: Tue Jul 14 17:52:18 2015 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Jul 14 17:54:54 2015 -0700

----------------------------------------------------------------------
 .../js/flexjs/JSCSSCompilationSession.java      | 31 ++++++++++
 .../flex/compiler/internal/css/CSSFontFace.java |  8 +++
 .../flex/compiler/internal/css/CSSProperty.java | 16 ++++-
 .../apache/flex/compiler/internal/css/CSSTree.g |  2 +-
 .../css/CSSURLAndFormatPropertyValue.java       | 65 ++++++++++++++++++++
 .../css/codegen/CSSCompilationSession.java      |  4 +-
 6 files changed, 123 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
index 0499610..3a7ff6c 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
@@ -33,6 +33,7 @@ import org.apache.flex.compiler.css.ICSSSelectorCondition;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.css.CSSArrayPropertyValue;
 import org.apache.flex.compiler.internal.css.CSSColorPropertyValue;
+import org.apache.flex.compiler.internal.css.CSSFontFace;
 import org.apache.flex.compiler.internal.css.CSSFunctionCallPropertyValue;
 import org.apache.flex.compiler.internal.css.CSSKeywordPropertyValue;
 import org.apache.flex.compiler.internal.css.CSSNumberPropertyValue;
@@ -72,6 +73,30 @@ public class JSCSSCompilationSession extends CSSCompilationSession
         return sb.toString();
     }
     
+    private String fontFaceToString(CSSFontFace fontFace)
+    {
+        final StringBuilder result = new StringBuilder();
+        result.append("@font-face {\n");
+        result.append("    ");
+        result.append("font-family: ");
+        result.append(fontFace.getFontFamily() + ";\n");
+        result.append("    ");
+        result.append("font-style: ");
+        result.append(fontFace.getFontStyle() + ";\n");
+        result.append("    ");
+        result.append("font-weight: ");
+        result.append(fontFace.getFontStyle() + ";\n");
+        result.append("    ");
+        ArrayList<ICSSPropertyValue> sources = fontFace.getSources();
+        for (ICSSPropertyValue src : sources)
+        {
+        	result.append("src: ");
+        	result.append(src.toString() + ";\n");
+        }
+       	result.append("}\n");
+        return result.toString();
+    }
+    
     private String cssRuleToString(ICSSRule rule)
     {
         final StringBuilder result = new StringBuilder();
@@ -140,6 +165,12 @@ public class JSCSSCompilationSession extends CSSCompilationSession
     
     private void walkCSS(ICSSDocument css, StringBuilder sb)
     {
+    	for (CSSFontFace fontFace : fontFaces)
+    	{
+    		sb.append(fontFaceToString(fontFace));
+    	}
+    	if (fontFaces.size() > 0)
+    		sb.append("\n\n");
         ImmutableList<ICSSRule> rules = css.getRules();
         for (ICSSRule rule : rules)
         {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler/src/org/apache/flex/compiler/internal/css/CSSFontFace.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/CSSFontFace.java b/compiler/src/org/apache/flex/compiler/internal/css/CSSFontFace.java
index 3a679cc..2bcf249 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/CSSFontFace.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/CSSFontFace.java
@@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.css;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.antlr.runtime.TokenStream;
@@ -66,6 +67,7 @@ public class CSSFontFace extends CSSNodeBase implements ICSSFontFace
             final ICSSPropertyValue value = property.getValue();
             if (name.equals("src"))
             {
+                sources.add(value);
                 srcValue = value;
             }
             else if (name.equals("fontFamily"))
@@ -113,12 +115,18 @@ public class CSSFontFace extends CSSNodeBase implements ICSSFontFace
     }
 
     private final CSSFunctionCallPropertyValue source;
+    private final ArrayList<ICSSPropertyValue> sources = new ArrayList<ICSSPropertyValue>();
     private final String fontFamily;
     private final String fontStyle;
     private final String fontWeight;
     private final boolean isEmbedAsCFF;
     private final boolean isAdvancedAntiAliasing;
 
+    public ArrayList<ICSSPropertyValue> getSources()
+    {
+        return sources;
+    }
+    
     @Override
     public FontFaceSourceType getSourceType()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java b/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
index 4dd0b4d..f5947ac 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
@@ -74,12 +74,16 @@ public class CSSProperty extends CSSNodeBase implements ICSSProperty
         }
         if (cssName.equals("content"))
         {
-            return String.format("%s : \"%s\" ;", cssName, ((CSSStringPropertyValue)value).getValue());            
+            return String.format("%s : \"%s\" ;", cssName, escape(((CSSStringPropertyValue)value).getValue()));            
         }
         if (value instanceof CSSStringPropertyValue)
         {
             return String.format("%s : %s ;", cssName, ((CSSStringPropertyValue)value).getValue());
         }
+        if (value instanceof CSSFunctionCallPropertyValue)
+        {
+            return String.format("%s : %s ;", cssName, ((CSSFunctionCallPropertyValue)value).toString());
+        }
         if (cssName.equalsIgnoreCase("border"))
         {
             if (value instanceof CSSArrayPropertyValue) {
@@ -137,4 +141,14 @@ public class CSSProperty extends CSSNodeBase implements ICSSProperty
         return result.toString();
     }
 
+    private String escape(String content)
+    {
+        if (content.length() == 1 && content.codePointAt(0) > 255)
+        {
+            int code = content.codePointAt(0);
+            content = Integer.toHexString(code);
+            return "\\" + content;
+        }
+        return content;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler/src/org/apache/flex/compiler/internal/css/CSSTree.g
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/CSSTree.g b/compiler/src/org/apache/flex/compiler/internal/css/CSSTree.g
index c1ba3db..83d9f80 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/CSSTree.g
+++ b/compiler/src/org/apache/flex/compiler/internal/css/CSSTree.g
@@ -404,7 +404,7 @@ singleValue returns [CSSPropertyValue propertyValue]
     |   ^(EMBED es=ARGUMENTS)
         { $propertyValue = new CSSFunctionCallPropertyValue($EMBED.text, $es.text, $start, tokenStream); }
     |   ^(URL url=ARGUMENTS format=formatOption*)
-        { $propertyValue = new CSSFunctionCallPropertyValue($URL.text, $url.text, $start, tokenStream); }
+        { $propertyValue = new CSSURLAndFormatPropertyValue($URL.text, $url.text, $format.text, $start, tokenStream); }
     |   ^(LOCAL l=ARGUMENTS)
         { $propertyValue = new CSSFunctionCallPropertyValue($LOCAL.text, $l.text, $start, tokenStream); }
     |   s=STRING   

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler/src/org/apache/flex/compiler/internal/css/CSSURLAndFormatPropertyValue.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/CSSURLAndFormatPropertyValue.java b/compiler/src/org/apache/flex/compiler/internal/css/CSSURLAndFormatPropertyValue.java
new file mode 100644
index 0000000..e7dbede
--- /dev/null
+++ b/compiler/src/org/apache/flex/compiler/internal/css/CSSURLAndFormatPropertyValue.java
@@ -0,0 +1,65 @@
+/*
+ *
+ *  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.compiler.internal.css;
+
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.tree.CommonTree;
+import org.apache.flex.compiler.css.ICSSDocument;
+
+/**
+ * @author aharui
+ *
+ */
+public class CSSURLAndFormatPropertyValue extends CSSFunctionCallPropertyValue
+{
+    /**
+     * Initialize a {@link CSSURLAndFormatPropertyValue}.
+     * 
+     * @param name Function name.
+     * @param rawArguments Raw argument string with parentheses and quotes.
+     * @param tree AST.
+     * @param tokenStream Token stream.
+     */
+    public CSSURLAndFormatPropertyValue(final String name,
+                                        final String rawArguments,
+                                        final String format,
+                                        final CommonTree tree,
+                                        final TokenStream tokenStream)
+    {
+        super(name, rawArguments, tree, tokenStream);
+        this.format = format;
+    }
+
+    private String format;
+    
+    /**
+     * Generate CSS code fragment for this model object. This is used by
+     * recursively generating a CSS document from a {@link ICSSDocument} for
+     * debugging and testing purposes.
+     */
+    @Override
+    public String toString()
+    {
+        if (format == null)
+            return super.toString();
+        return super.toString() + " " + format;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1f8f602c/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSCompilationSession.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSCompilationSession.java b/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSCompilationSession.java
index 8cb40d0..ae98028 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSCompilationSession.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSCompilationSession.java
@@ -128,7 +128,7 @@ public class CSSCompilationSession
     /**
      * A set of font faces that will be included in the code generation.
      */
-    public final ArrayList<CSSFontFace> fontFaces;
+    public ArrayList<CSSFontFace> fontFaces;
 
     /**
      * A list of CSS models to be included in the code generation. The CSS
@@ -185,6 +185,8 @@ public class CSSCompilationSession
      */
     protected ICSSDocument synthesisNormalizedCSS()
     {
+        fontFaces = new ArrayList<CSSFontFace>();
+        
         for (final ICSSDocument cssDocument : cssDocuments)
         {
             for (final ICSSRule newRule : cssDocument.getRules())