Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better approach for issue 5420.

Now multiple fonts can be marked as used when an element uses different
fonts for the texts in it.
  • Loading branch information...
commit e8ab8cb95aa0325410ebef5084ed7fd56fe43f42 1 parent 1ae347f
Sebastian Zartner authored April 27, 2012
88  extension/content/firebug/css/cssElementPanel.js
@@ -79,11 +79,22 @@ CSSElementPanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
79 79
 
80 80
         CSSFontPropValueTag:
81 81
             SPAN({"class": "cssFontPropValue"},
82  
-                SPAN("$otherValues"),
83  
-                SPAN({"class": "cssFontPropBefore"}, "$before"),
84  
-                SPAN({"class": "cssFontUsed"}, "$used"),
85  
-                SPAN({"class": "cssFontPropAfter"}, "$after")
86  
-            )
  82
+                FOR("part", "$propValueParts",
  83
+                    SPAN({"class": "$part.class"}, "$part.value"),
  84
+                    SPAN({"class": "cssFontPropSeparator"}, "$part|getSeparator")
  85
+                )
  86
+            ),
  87
+
  88
+        getSeparator: function(part)
  89
+        {
  90
+            if (part.type == "otherProps")
  91
+                return " ";
  92
+
  93
+            if (part.last)
  94
+                return "";
  95
+
  96
+            return ",";
  97
+        }
87 98
     }),
88 99
 
89 100
     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -126,11 +137,12 @@ CSSElementPanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
126 137
                 {
127 138
                     var propValueElem = prop.getElementsByClassName("cssPropValue").item(0);
128 139
                     var propValue = propValueElem.textContent;
129  
-                    var fontParts = getFontParts(element, propValue);
  140
+                    var fontPropValueParts = getFontPropValueParts(element, propValue);
130 141
 
131  
-                    // xxxsz: Web fonts are not covered by this.
132  
-                    // For that to work we need to react to when the fonts are loaded.
133  
-                    this.template.CSSFontPropValueTag.replace(fontParts, propValueElem);
  142
+                    // xxxsz: Web fonts not being loaded at display time
  143
+                    // won't be marked as used. See issue 5420.
  144
+                    this.template.CSSFontPropValueTag.replace({propValueParts: fontPropValueParts},
  145
+                        propValueElem);
134 146
                 }
135 147
             }
136 148
 
@@ -652,16 +664,19 @@ function safeGetContentState(selection)
652 664
     }
653 665
 }
654 666
 
655  
-function getFontForGenericFontFamily(genericFontFamily)
  667
+function getFontPropValueParts(element, value)
656 668
 {
657  
-    var fontsDomain = "font.name."+genericFontFamily;
  669
+    function isFontInDefinition(fonts, font)
  670
+    {
  671
+        for (var i = 0; i < fonts.length; ++i)
  672
+        {
  673
+            if (font == fonts[i].replace(/^"(.*)"$/, "$1").toLowerCase())
  674
+                return true;
  675
+        }
658 676
 
659  
-    // xxxsz: Is there a possibility to find out the language group used for a specific page?
660  
-    return Options.getPref(fontsDomain, "x-western");
661  
-}
  677
+        return false;
  678
+    }
662 679
 
663  
-function getFontParts(element, value)
664  
-{
665 680
     const genericFontFamilies =
666 681
     {
667 682
         "serif": 1,
@@ -671,9 +686,9 @@ function getFontParts(element, value)
671 686
         "monospace": 1,
672 687
     };
673 688
     const reFontFamilies = new RegExp("^(.*(\\d+(\\.\\d+)?(em|ex|ch|rem|cm|mm|in|pt|pc|px|%)|"+
674  
-        "x{0,2}-(small|large)|medium|larger|smaller) )(.*)$|.*");
  689
+        "x{0,2}-(small|large)|medium|larger|smaller)) (.*)$|.*");
675 690
     var matches = reFontFamilies.exec(value);
676  
-    var fontParts = {otherValues: "", before: "", used: "", after: ""};
  691
+    var parts = [];
677 692
     var i = 0;
678 693
 
679 694
     if (!matches)
@@ -682,7 +697,7 @@ function getFontParts(element, value)
682 697
     var fonts;
683 698
     if (matches[6])
684 699
     {
685  
-        fontParts.otherValues = matches[1];
  700
+        parts.push({type: "otherProps", value: matches[1]});
686 701
         fonts = matches[6].split(",");
687 702
     }
688 703
     else
@@ -691,39 +706,36 @@ function getFontParts(element, value)
691 706
     }
692 707
 
693 708
     var usedFonts = Fonts.getFonts(element);
  709
+    var genericFontUsed = false;
694 710
     for (; i < fonts.length; ++i)
695 711
     {
696 712
         var font = fonts[i].replace(/^"(.*)"$/, "$1").toLowerCase();
697  
-        if (genericFontFamilies.hasOwnProperty(font))
698  
-            font = getFontForGenericFontFamily(font).toLowerCase();
699  
-
  713
+        var isUsedFont = false;
700 714
         for (var j = 0; j < usedFonts.length; ++j)
701 715
         {
702  
-            if (font == usedFonts[j].CSSFamilyName.toLowerCase())
  716
+            var usedFont = usedFonts[j].CSSFamilyName.toLowerCase();
  717
+            if (font == usedFont || (genericFontFamilies.hasOwnProperty(font) &&
  718
+                !genericFontUsed && !isFontInDefinition(fonts, usedFont)))
703 719
             {
704  
-                fontParts.used = fonts[i];
  720
+                parts.push({type: "used", value: fonts[i]});
  721
+
  722
+                isUsedFont = true;
  723
+                if (genericFontFamilies.hasOwnProperty(font))
  724
+                    genericFontUsed = true;
705 725
                 break;
706 726
             }
707 727
         }
708 728
 
709  
-        if (fontParts.used != "")
710  
-            break;
  729
+        if (!isUsedFont)
  730
+            parts.push({type: "unused", class: "cssPropValueUnused", value: fonts[i]});
711 731
 
712  
-        fontParts.before += fonts[i];
713  
-        if (i < fonts.length-1)
714  
-            fontParts.before += ",";
715 732
     }
716 733
 
717  
-    if (i < fonts.length-1)
718  
-        fontParts.after = ",";
719  
-    for (++i; i < fonts.length; ++i)
720  
-    {
721  
-        fontParts.after += fonts[i];
722  
-        if (i < fonts.length-1)
723  
-            fontParts.after += ",";
724  
-    }
  734
+    // xxxsz: Domplate doesn't allow to check for the last element in an array yet,
  735
+    // so use this as hack
  736
+    parts[parts.length-1].last = true;
725 737
 
726  
-    return fontParts;
  738
+    return parts;
727 739
 }
728 740
 
729 741
 // ********************************************************************************************* //
2  extension/skin/classic/css.css
@@ -44,7 +44,7 @@
44 44
     color: darkblue;
45 45
 }
46 46
 
47  
-.cssFontPropBefore, .cssFontPropAfter {
  47
+.cssPropValueUnused, .cssFontPropSeparator {
48 48
     color: #787878;
49 49
 }
50 50
 

0 notes on commit e8ab8cb

Please sign in to comment.
Something went wrong with that request. Please try again.