browser/components/preferences/fonts.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // browser.display.languageList LOCK ALL when LOCKED
michael@0 7
michael@0 8 const kDefaultFontType = "font.default.%LANG%";
michael@0 9 const kFontNameFmtSerif = "font.name.serif.%LANG%";
michael@0 10 const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%";
michael@0 11 const kFontNameFmtMonospace = "font.name.monospace.%LANG%";
michael@0 12 const kFontNameListFmtSerif = "font.name-list.serif.%LANG%";
michael@0 13 const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
michael@0 14 const kFontNameListFmtMonospace = "font.name-list.monospace.%LANG%";
michael@0 15 const kFontSizeFmtVariable = "font.size.variable.%LANG%";
michael@0 16 const kFontSizeFmtFixed = "font.size.fixed.%LANG%";
michael@0 17 const kFontMinSizeFmt = "font.minimum-size.%LANG%";
michael@0 18
michael@0 19 var gFontsDialog = {
michael@0 20 _selectLanguageGroup: function (aLanguageGroup)
michael@0 21 {
michael@0 22 var prefs = [{ format: kDefaultFontType, type: "string", element: "defaultFontType", fonttype: null},
michael@0 23 { format: kFontNameFmtSerif, type: "fontname", element: "serif", fonttype: "serif" },
michael@0 24 { format: kFontNameFmtSansSerif, type: "fontname", element: "sans-serif", fonttype: "sans-serif" },
michael@0 25 { format: kFontNameFmtMonospace, type: "fontname", element: "monospace", fonttype: "monospace" },
michael@0 26 { format: kFontNameListFmtSerif, type: "unichar", element: null, fonttype: "serif" },
michael@0 27 { format: kFontNameListFmtSansSerif, type: "unichar", element: null, fonttype: "sans-serif" },
michael@0 28 { format: kFontNameListFmtMonospace, type: "unichar", element: null, fonttype: "monospace" },
michael@0 29 { format: kFontSizeFmtVariable, type: "int", element: "sizeVar", fonttype: null },
michael@0 30 { format: kFontSizeFmtFixed, type: "int", element: "sizeMono", fonttype: null },
michael@0 31 { format: kFontMinSizeFmt, type: "int", element: "minSize", fonttype: null }];
michael@0 32 var preferences = document.getElementById("fontPreferences");
michael@0 33 for (var i = 0; i < prefs.length; ++i) {
michael@0 34 var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
michael@0 35 if (!preference) {
michael@0 36 preference = document.createElement("preference");
michael@0 37 var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup);
michael@0 38 preference.id = name;
michael@0 39 preference.setAttribute("name", name);
michael@0 40 preference.setAttribute("type", prefs[i].type);
michael@0 41 preferences.appendChild(preference);
michael@0 42 }
michael@0 43
michael@0 44 if (!prefs[i].element)
michael@0 45 continue;
michael@0 46
michael@0 47 var element = document.getElementById(prefs[i].element);
michael@0 48 if (element) {
michael@0 49 element.setAttribute("preference", preference.id);
michael@0 50
michael@0 51 if (prefs[i].fonttype)
michael@0 52 FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element);
michael@0 53
michael@0 54 preference.setElementValue(element);
michael@0 55 }
michael@0 56 }
michael@0 57 },
michael@0 58
michael@0 59 readFontLanguageGroup: function ()
michael@0 60 {
michael@0 61 var languagePref = document.getElementById("font.language.group");
michael@0 62 this._selectLanguageGroup(languagePref.value);
michael@0 63 return undefined;
michael@0 64 },
michael@0 65
michael@0 66 readFontSelection: function (aElement)
michael@0 67 {
michael@0 68 // Determine the appropriate value to select, for the following cases:
michael@0 69 // - there is no setting
michael@0 70 // - the font selected by the user is no longer present (e.g. deleted from
michael@0 71 // fonts folder)
michael@0 72 var preference = document.getElementById(aElement.getAttribute("preference"));
michael@0 73 if (preference.value) {
michael@0 74 var fontItems = aElement.getElementsByAttribute("value", preference.value);
michael@0 75
michael@0 76 // There is a setting that actually is in the list. Respect it.
michael@0 77 if (fontItems.length > 0)
michael@0 78 return undefined;
michael@0 79 }
michael@0 80
michael@0 81 var defaultValue = aElement.firstChild.firstChild.getAttribute("value");
michael@0 82 var languagePref = document.getElementById("font.language.group");
michael@0 83 preference = document.getElementById("font.name-list." + aElement.id + "." + languagePref.value);
michael@0 84 if (!preference || !preference.hasUserValue)
michael@0 85 return defaultValue;
michael@0 86
michael@0 87 var fontNames = preference.value.split(",");
michael@0 88 var stripWhitespace = /^\s*(.*)\s*$/;
michael@0 89
michael@0 90 for (var i = 0; i < fontNames.length; ++i) {
michael@0 91 var fontName = fontNames[i].replace(stripWhitespace, "$1");
michael@0 92 fontItems = aElement.getElementsByAttribute("value", fontName);
michael@0 93 if (fontItems.length)
michael@0 94 break;
michael@0 95 }
michael@0 96 if (fontItems.length)
michael@0 97 return fontItems[0].getAttribute("value");
michael@0 98 return defaultValue;
michael@0 99 },
michael@0 100
michael@0 101 readUseDocumentFonts: function ()
michael@0 102 {
michael@0 103 var preference = document.getElementById("browser.display.use_document_fonts");
michael@0 104 return preference.value == 1;
michael@0 105 },
michael@0 106
michael@0 107 writeUseDocumentFonts: function ()
michael@0 108 {
michael@0 109 var useDocumentFonts = document.getElementById("useDocumentFonts");
michael@0 110 return useDocumentFonts.checked ? 1 : 0;
michael@0 111 }
michael@0 112 };
michael@0 113

mercurial