font picker: improve the font picker (closes #3451)

Preparatory work for introducing colibris skin
This commit is contained in:
Sebastian Castro 2018-11-08 21:56:10 +01:00
parent c5a07e6827
commit 63ec2d8cc2
3 changed files with 45 additions and 84 deletions

View file

@ -314,7 +314,7 @@ function handshake()
// If the Monospacefont value is set to true then change it to monospace.
if (settings.useMonospaceFontGlobal == true)
{
pad.changeViewOption('useMonospaceFont', true);
pad.changeViewOption('padFontFamily', 'monospace');
}
// if the globalUserName value is set we need to tell the server and the client about the new authorname
if (settings.globalUserName !== false)
@ -560,19 +560,7 @@ var pad = {
if(padcookie.getPref("rtlIsTrue") == true){
pad.changeViewOption('rtlIsTrue', true);
}
var fonts = ['useMonospaceFont', 'useMontserratFont', 'useOpenDyslexicFont', 'useComicSansFont', 'useCourierNewFont',
'useGeorgiaFont', 'useImpactFont', 'useLucidaFont', 'useLucidaSansFont', 'usePalatinoFont', 'useRobotoMonoFont',
'useTahomaFont', 'useTimesNewRomanFont', 'useTrebuchetFont', 'useVerdanaFont', 'useSymbolFont', 'useWebdingsFont',
'useWingDingsFont', 'useSansSerifFont', 'useSerifFont'];
$.each(fonts, function(i, font){
if(padcookie.getPref(font) == true){
pad.changeViewOption(font, true);
}
})
pad.changeViewOption('padFontFamily', padcookie.getPref("padFontFamily"));
hooks.aCallAll("postAceInit", {ace: padeditor.ace, pad: pad});
}

View file

@ -29,14 +29,6 @@ var padeditor = (function()
var pad = undefined;
var settings = undefined;
// Array of available fonts
var fonts = ['useMonospaceFont', 'useMontserratFont', 'useOpenDyslexicFont', 'useComicSansFont', 'useCourierNewFont',
'useGeorgiaFont', 'useImpactFont', 'useLucidaFont', 'useLucidaSansFont', 'usePalatinoFont', 'useRobotoMonoFont',
'useTahomaFont', 'useTimesNewRomanFont', 'useTrebuchetFont', 'useVerdanaFont', 'useSymbolFont', 'useWebdingsFont',
'useWingDingsFont', 'useSansSerifFont', 'useSerifFont'];
var self = {
ace: null,
// this is accessed directly from other files
@ -97,12 +89,7 @@ var padeditor = (function()
// font family change
$("#viewfontmenu").change(function()
{
$.each(fonts, function(i, font){
var sfont = font.replace("use","");
sfont = sfont.replace("Font","");
sfont = sfont.toLowerCase();
pad.changeViewOption(font, $("#viewfontmenu").val() == sfont);
});
pad.changeViewOption('padFontFamily', $("#viewfontmenu").val());
});
// Language
@ -154,45 +141,29 @@ var padeditor = (function()
self.ace.setProperty("showsauthorcolors", !settings.noColors);
}
var normalFont = true;
// Go through each font and see if the option is set..
$.each(fonts, function(i, font){
var isEnabled = getOption(font, false);
if(isEnabled){
font = font.replace("use","");
font = font.replace("Font","");
font = font.toLowerCase();
if(font === "monospace") self.ace.setProperty("textface", "monospace");
if(font === "montserrat") self.ace.setProperty("textface", "Montserrat");
if(font === "opendyslexic") self.ace.setProperty("textface", "OpenDyslexic");
if(font === "comicsans") self.ace.setProperty("textface", "'Comic Sans MS','Comic Sans',cursive");
if(font === "georgia") self.ace.setProperty("textface", "Georgia,'Bitstream Charter',serif");
if(font === "impact") self.ace.setProperty("textface", "Impact,Haettenschweiler,'Arial Black',sans-serif");
if(font === "lucida") self.ace.setProperty("textface", "Lucida,'Lucida Serif','Lucida Bright',serif");
if(font === "lucidasans") self.ace.setProperty("textface", "'Lucida Sans','Lucida Grande','Lucida Sans Unicode','Luxi Sans',sans-serif");
if(font === "palatino") self.ace.setProperty("textface", "Palatino,'Palatino Linotype','URW Palladio L',Georgia,serif");
if(font === "robotomono") self.ace.setProperty("textface", "RobotoMono");
if(font === "tahoma") self.ace.setProperty("textface", "Tahoma,sans-serif");
if(font === "timesnewroman") self.ace.setProperty("textface", "'Times New Roman',Times,serif");
if(font === "trebuchet") self.ace.setProperty("textface", "'Trebuchet MS',sans-serif");
if(font === "verdana") self.ace.setProperty("textface", "Verdana,'DejaVu Sans',sans-serif");
if(font === "symbol") self.ace.setProperty("textface", "Symbol");
if(font === "webdings") self.ace.setProperty("textface", "Webdings");
if(font === "wingdings") self.ace.setProperty("textface", "Wingdings");
if(font === "sansserif") self.ace.setProperty("textface", "sans-serif");
if(font === "serif") self.ace.setProperty("textface", "serif");
// $("#viewfontmenu").val(font);
normalFont = false;
}
});
// No font has been previously selected so use the Normal font
if(normalFont){
self.ace.setProperty("textface", "'Helvetica Neue',Arial, sans-serif");
// $("#viewfontmenu").val("normal");
var fontFamily = newOptions['padFontFamily'];
switch (fontFamily) {
case "monospace": self.ace.setProperty("textface", "monospace"); break;
case "montserrat": self.ace.setProperty("textface", "Montserrat"); break;
case "opendyslexic": self.ace.setProperty("textface", "OpenDyslexic"); break;
case "comicsans": self.ace.setProperty("textface", "'Comic Sans MS','Comic Sans',cursive"); break;
case "georgia": self.ace.setProperty("textface", "Georgia,'Bitstream Charter',serif"); break;
case "impact": self.ace.setProperty("textface", "Impact,Haettenschweiler,'Arial Black',sans-serif"); break;
case "lucida": self.ace.setProperty("textface", "Lucida,'Lucida Serif','Lucida Bright',serif"); break;
case "lucidasans": self.ace.setProperty("textface", "'Lucida Sans','Lucida Grande','Lucida Sans Unicode','Luxi Sans',sans-serif"); break;
case "palatino": self.ace.setProperty("textface", "Palatino,'Palatino Linotype','URW Palladio L',Georgia,serif"); break;
case "robotomono": self.ace.setProperty("textface", "RobotoMono"); break;
case "tahoma": self.ace.setProperty("textface", "Tahoma,sans-serif"); break;
case "timesnewroman": self.ace.setProperty("textface", "'Times New Roman',Times,serif"); break;
case "trebuchet": self.ace.setProperty("textface", "'Trebuchet MS',sans-serif"); break;
case "verdana": self.ace.setProperty("textface", "Verdana,'DejaVu Sans',sans-serif"); break;
case "symbol": self.ace.setProperty("textface", "Symbol"); break;
case "webdings": self.ace.setProperty("textface", "Webdings"); break;
case "wingdings": self.ace.setProperty("textface", "Wingdings"); break;
case "sansserif": self.ace.setProperty("textface", "sans-serif"); break;
case "serif": self.ace.setProperty("textface", "serif"); break;
default: self.ace.setProperty("textface", ""); break;
}
},
dispose: function()
{

View file

@ -166,25 +166,27 @@ function handleClientVars(message)
// font family change
$("#viewfontmenu").change(function(){
var font = $("#viewfontmenu").val();
if(font === "monospace") setFont("Courier new");
if(font === "opendyslexic") setFont("OpenDyslexic");
if(font === "comicsans") setFont("Comic Sans MS");
if(font === "georgia") setFont("Georgia");
if(font === "impact") setFont("Impact");
if(font === "lucida") setFont("Lucida");
if(font === "lucidasans") setFont("Lucida Sans Unicode");
if(font === "palatino") setFont("Palatino Linotype");
if(font === "tahoma") setFont("Tahoma");
if(font === "timesnewroman") setFont("Times New Roman");
if(font === "trebuchet") setFont("Trebuchet MS");
if(font === "verdana") setFont("Verdana");
if(font === "symbol") setFont("Symbol");
if(font === "webdings") setFont("Webdings");
if(font === "wingdings") setFont("Wingdings");
if(font === "sansserif") setFont("MS Sans Serif");
if(font === "serif") setFont("MS Serif");
switch (font) {
case "monospace": setFont("Courier new");break;
case "opendyslexic": setFont("OpenDyslexic");break;
case "comicsans": setFont("Comic Sans MS");break;
case "georgia": setFont("Georgia");break;
case "impact": setFont("Impact");break;
case "lucida": setFont("Lucida");break;
case "lucidasans": setFont("Lucida Sans Unicode");break;
case "palatino": setFont("Palatino Linotype");break;
case "tahoma": setFont("Tahoma");break;
case "timesnewroman": setFont("Times New Roman");break;
case "trebuchet": setFont("Trebuchet MS");break;
case "verdana": setFont("Verdana");break;
case "symbol": setFont("Symbol");break;
case "webdings": setFont("Webdings");break;
case "wingdings": setFont("Wingdings");break;
case "sansserif": setFont("MS Sans Serif");break;
case "serif": setFont("MS Serif");break;
default: setFont("");break;
}
});
}
function setFont(font){