/*
 * ThemeFonts.java
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.core.client.theme;

import com.google.gwt.core.client.GWT;
import org.rstudio.core.client.BrowseCap;


public class ThemeFonts
{
   private static final ThemeFontLoader fontLoader =
         GWT.create(ThemeFontLoader.class);
   
   public static String getProportionalFont()
   {
      return fontLoader.getProportionalFont();
   }

   public static String getFixedWidthFont()
   {
      return fontLoader.getFixedWidthFont();
   }

   static interface ThemeFontLoader
   {
      String getProportionalFont();
      String getFixedWidthFont();
   }

   static class DesktopThemeFontLoader implements ThemeFontLoader
   {
      public native final String getProportionalFont() /*-{
         return $wnd.desktopInfo.proportionalFont;
      }-*/;

      public native final String getFixedWidthFont() /*-{
         return $wnd.desktopInfo.fixedWidthFont;
      }-*/;
   }

   static class WebThemeFontLoader implements ThemeFontLoader
   {
      public String getProportionalFont()
      {
         String font = BrowseCap.hasUbuntuFonts() ? "Ubuntu, " : "";
         return font + "\"Lucida Sans\", \"DejaVu Sans\", \"Lucida Grande\", \"Segoe UI\", Verdana, Helvetica, sans-serif"; 
      }

      public String getFixedWidthFont()
      {
         if (BrowseCap.isMacintosh())
            return "Monaco, monospace";
         else if (BrowseCap.isLinux())
            return "\"Ubuntu Mono\", \"Droid Sans Mono\", \"DejaVu Sans Mono\", monospace";
         else
            return "Consolas, \"Lucida Console\", monospace";
      }
   }
}

@@ -653,16 +653,59 @@
 nt.GWT;%0A
+import com.google.gwt.user.client.Window;%0A%0A
 import o
@@ -738,16 +738,16 @@
 wseCap;%0A
-
 %0A%0Apublic
@@ -1264,39 +1264,32 @@
  %7B%0A      public 
-native 
 final String get
@@ -1302,28 +1302,31 @@
 tionalFont()
- /*-
+%0A      
 %7B%0A         r
@@ -1323,38 +1323,36 @@
          return 
-$wnd.d
+getD
 esktopInfo.propo
@@ -1345,17 +1345,18 @@
 ktopInfo
-.
+(%22
 proporti
@@ -1359,24 +1359,26 @@
 ortionalFont
+%22)
 ;%0A      %7D-*/
@@ -1374,21 +1374,23 @@
 %0A      %7D
--*/;%0A
+%0A      
 %0A      p
@@ -1399,15 +1399,8 @@
 lic 
-native 
 fina
@@ -1431,62 +1431,738 @@
 nt()
- /*-%7B%0A         return $wnd.desktopInfo.fixedWidthFont;
+%0A      %7B%0A         return getDesktopInfo(%22fixedWidthFont%22);%0A      %7D%0A      %0A      private static final native String getDesktopInfo(String property)%0A      /*-%7B%0A         %0A         // NOTE: because this is called very early during the startup process%0A         // (GWT needs to generate CSS based on the value of these entries),%0A         // it's possible (for satellite windows) that the 'desktopInfo' object%0A         // will not yet be initialized -- so attempt to read it from an opener%0A         // directly.%0A         var window = $wnd;%0A         while (window) %7B%0A            if (window.desktopInfo)%0A               break;%0A            window = window.opener;%0A         %7D%0A         %0A         return window.desktopInfo%5Bproperty%5D;%0A         
 %0A   

fix error in satellite initialization