home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / mozapps / preferences / fontbuilder.js < prev    next >
Encoding:
JavaScript  |  2008-03-18  |  3.1 KB  |  86 lines

  1. //@line 37 "/build/buildd/xulrunner-1.9-1.9.0.14+build2+nobinonly/mozilla/toolkit/mozapps/preferences/fontbuilder.js"
  2.  
  3. var FontBuilder = {
  4.   _enumerator: null,
  5.   get enumerator ()
  6.   {
  7.     if (!this._enumerator) {
  8.       this._enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
  9.                                    .createInstance(Components.interfaces.nsIFontEnumerator);
  10.     }
  11.     return this._enumerator;
  12.   },
  13.  
  14.   _allFonts: null,
  15.   buildFontList: function (aLanguage, aFontType, aMenuList) 
  16.   {
  17.     // Reset the list
  18.     while (aMenuList.hasChildNodes())
  19.       aMenuList.removeChild(aMenuList.firstChild);
  20.     
  21.     var defaultFont = null;
  22.     // Load Font Lists
  23.     var fonts = this.enumerator.EnumerateFonts(aLanguage, aFontType, { } );
  24.     if (fonts.length > 0)
  25.       defaultFont = this.enumerator.getDefaultFont(aLanguage, aFontType);
  26.     else {
  27.       fonts = this.enumerator.EnumerateFonts(aLanguage, "", { });
  28.       if (fonts.length > 0)
  29.         defaultFont = this.enumerator.getDefaultFont(aLanguage, "");
  30.     }
  31.     
  32.     if (!this._allFonts)
  33.       this._allFonts = this.enumerator.EnumerateAllFonts({});
  34.     
  35.     // Build the UI for the Default Font and Fonts for this CSS type.
  36.     var popup = document.createElement("menupopup");
  37.     var separator;
  38.     if (fonts.length > 0) {
  39.       if (defaultFont) {
  40.         var bundlePreferences = document.getElementById("bundlePreferences");
  41.         var label = bundlePreferences.getFormattedString("labelDefaultFont", [defaultFont]);
  42.         var menuitem = document.createElement("menuitem");
  43.         menuitem.setAttribute("label", label);
  44.         menuitem.setAttribute("value", ""); // Default Font has a blank value
  45.         popup.appendChild(menuitem);
  46.         
  47.         separator = document.createElement("menuseparator");
  48.         popup.appendChild(separator);
  49.       }
  50.       
  51.       for (var i = 0; i < fonts.length; ++i) {
  52.         menuitem = document.createElement("menuitem");
  53.         menuitem.setAttribute("value", fonts[i]);
  54.         menuitem.setAttribute("label", fonts[i]);
  55.         popup.appendChild(menuitem);
  56.       }
  57.     }
  58.     
  59.     // Build the UI for the remaining fonts. 
  60.     if (this._allFonts.length > fonts.length) {
  61.       // Both lists are sorted, and the Fonts-By-Type list is a subset of the
  62.       // All-Fonts list, so walk both lists side-by-side, skipping values we've
  63.       // already created menu items for. 
  64.       var builtItem = separator ? separator.nextSibling : popup.firstChild;
  65.       var builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
  66.  
  67.       separator = document.createElement("menuseparator");
  68.       popup.appendChild(separator);
  69.       
  70.       for (i = 0; i < this._allFonts.length; ++i) {
  71.         if (this._allFonts[i] != builtItemValue) {
  72.           menuitem = document.createElement("menuitem");
  73.           menuitem.setAttribute("value", this._allFonts[i]);
  74.           menuitem.setAttribute("label", this._allFonts[i]);
  75.           popup.appendChild(menuitem);
  76.         }
  77.         else {
  78.           builtItem = builtItem.nextSibling;
  79.           builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
  80.         }
  81.       }
  82.     }
  83.     aMenuList.appendChild(popup);    
  84.   }
  85. };
  86.