fonts.js
Go to the documentation of this file.
1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Original Code is the Firefox Preferences System.
16 #
17 # The Initial Developer of the Original Code is
18 # Ben Goodger.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
21 #
22 # Contributor(s):
23 # Ben Goodger <ben@mozilla.org>
24 # Asaf Romano <mozilla.mano@sent.com>
25 #
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
37 #
38 # ***** END LICENSE BLOCK *****
39 
40 # browser.display.languageList LOCK ALL when LOCKED
41 
42 const kDefaultFontType = "font.default.%LANG%";
43 const kFontNameFmtSerif = "font.name.serif.%LANG%";
44 const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%";
45 const kFontNameFmtMonospace = "font.name.monospace.%LANG%";
46 const kFontNameListFmtSerif = "font.name-list.serif.%LANG%";
47 const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
48 const kFontNameListFmtMonospace = "font.name-list.monospace.%LANG%";
49 const kFontSizeFmtVariable = "font.size.variable.%LANG%";
50 const kFontSizeFmtFixed = "font.size.fixed.%LANG%";
51 const kFontMinSizeFmt = "font.minimum-size.%LANG%";
52 
53 var gFontsDialog = {
54  _selectLanguageGroup: function (aLanguageGroup)
55  {
56  var prefs = [{ format: kDefaultFontType, type: "string", element: "defaultFontType", fonttype: null},
57  { format: kFontNameFmtSerif, type: "fontname", element: "serif", fonttype: "serif" },
58  { format: kFontNameFmtSansSerif, type: "fontname", element: "sans-serif", fonttype: "sans-serif" },
59  { format: kFontNameFmtMonospace, type: "fontname", element: "monospace", fonttype: "monospace" },
60  { format: kFontNameListFmtSerif, type: "unichar", element: null, fonttype: "serif" },
61  { format: kFontNameListFmtSansSerif, type: "unichar", element: null, fonttype: "sans-serif" },
62  { format: kFontNameListFmtMonospace, type: "unichar", element: null, fonttype: "monospace" },
63  { format: kFontSizeFmtVariable, type: "int", element: "sizeVar", fonttype: null },
64  { format: kFontSizeFmtFixed, type: "int", element: "sizeMono", fonttype: null },
65  { format: kFontMinSizeFmt, type: "int", element: "minSize", fonttype: null }];
66  var preferences = document.getElementById("fontPreferences");
67  for (var i = 0; i < prefs.length; ++i) {
68  var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
69  if (!preference) {
70  preference = document.createElement("preference");
71  var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup);
72  preference.id = name;
73  preference.setAttribute("name", name);
74  preference.setAttribute("type", prefs[i].type);
75  preferences.appendChild(preference);
76  }
77 
78  if (!prefs[i].element)
79  continue;
80 
81  var element = document.getElementById(prefs[i].element);
82  if (element) {
83  element.setAttribute("preference", preference.id);
84 
85  if (prefs[i].fonttype)
86  FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element);
87 
88  preference.setElementValue(element);
89  }
90  }
91  },
92 
93  readFontLanguageGroup: function ()
94  {
95  var languagePref = document.getElementById("font.language.group");
96  this._selectLanguageGroup(languagePref.value);
97  return undefined;
98  },
99 
100  readFontSelection: function (aElement)
101  {
102  // Determine the appropriate value to select, for the following cases:
103  // - there is no setting
104  // - the font selected by the user is no longer present (e.g. deleted from
105  // fonts folder)
106  var preference = document.getElementById(aElement.getAttribute("preference"));
107  if (preference.value) {
108  var fontItems = aElement.getElementsByAttribute("value", preference.value);
109 
110  // There is a setting that actually is in the list. Respect it.
111  if (fontItems.length > 0)
112  return undefined;
113  }
114 
115  var defaultValue = aElement.firstChild.firstChild.getAttribute("value");
116  var languagePref = document.getElementById("font.language.group");
117  preference = document.getElementById("font.name-list." + aElement.id + "." + languagePref.value);
118  if (!preference || !preference.hasUserValue)
119  return defaultValue;
120 
121  var fontNames = preference.value.split(",");
122  var stripWhitespace = /^\s*(.*)\s*$/;
123 
124  for (var i = 0; i < fontNames.length; ++i) {
125  var fontName = fontNames[i].replace(stripWhitespace, "$1");
126  fontItems = aElement.getElementsByAttribute("value", fontName);
127  if (fontItems.length)
128  break;
129  }
130  if (fontItems.length)
131  return fontItems[0].getAttribute("value");
132  return defaultValue;
133  },
134 
135  _charsetMenuInitialized: false,
136  readDefaultCharset: function ()
137  {
138  if (!this._charsetMenuInitialized) {
139  var os = Components.classes["@mozilla.org/observer-service;1"]
140  .getService(Components.interfaces.nsIObserverService);
141  os.notifyObservers(null, "charsetmenu-selected", "other");
142  this._charsetMenuInitialized = true;
143  }
144  return undefined;
145  },
146 
147  readUseDocumentFonts: function ()
148  {
149  var preference = document.getElementById("browser.display.use_document_fonts");
150  return preference.value == 1;
151  },
152 
153  writeUseDocumentFonts: function ()
154  {
155  var useDocumentFonts = document.getElementById("useDocumentFonts");
156  return useDocumentFonts.checked ? 1 : 0;
157  }
158 };
159 
const kFontSizeFmtVariable
Definition: fonts.js:49
playlistfolders preferences
Definition: preferences.js:13
var gFontsDialog
Definition: fonts.js:53
const kDefaultFontType
Definition: fonts.js:42
const kFontNameFmtSansSerif
Definition: fonts.js:44
const kFontNameFmtSerif
Definition: fonts.js:43
const kFontNameListFmtSerif
Definition: fonts.js:46
return null
Definition: FeedWriter.js:1143
const kFontMinSizeFmt
Definition: fonts.js:51
var os
var prefs
Definition: FeedWriter.js:1169
const kFontNameFmtMonospace
Definition: fonts.js:45
const kFontNameListFmtMonospace
Definition: fonts.js:48
const kFontNameListFmtSansSerif
Definition: fonts.js:47
_getSelectedPageStyle s i
const kFontSizeFmtFixed
Definition: fonts.js:50