string userAgent = project.Profile.UserAgent;
string osType = "Unknown";
var systemFontsList = new List<string>();
var rnd = new Random();
// Выбор базовых шрифтов для ОС
if (userAgent.Contains("Windows NT"))
{
osType = "Windows";
systemFontsList = new List<string>
{
"Arial", "Arial Black", "Bahnschrift", "Calibri", "Cambria",
"Cambria Math", "Candara", "Comic Sans MS", "Consolas", "Constantia",
"Corbel", "Courier New", "Ebrima", "Franklin Gothic Medium", "Gabriola",
"Gadugi", "Georgia", "Impact", "Javanese Text", "Leelawadee UI",
"Lucida Console", "Lucida Sans Unicode", "Malgun Gothic", "Marlett",
"Microsoft Himalaya", "Microsoft JhengHei", "Microsoft New Tai Lue",
"Microsoft PhagsPa", "Microsoft Sans Serif", "Microsoft Tai Le",
"Microsoft YaHei", "Microsoft Yi Baiti", "MingLiU-ExtB", "Mongolian Baiti",
"MS Gothic", "MV Boli", "Myanmar Text", "Nirmala UI", "Palatino Linotype",
"Segoe MDL2 Assets", "Segoe Print", "Segoe Script", "Segoe UI",
"Segoe UI Historic", "Segoe UI Emoji", "Segoe UI Symbol", "SimSun",
"Sitka", "Sylfaen", "Symbol", "Tahoma", "Times New Roman",
"Trebuchet MS", "Verdana", "Webdings", "Wingdings", "Yu Gothic"
};
}
else if (userAgent.Contains("Macintosh"))
{
osType = "Macintosh";
systemFontsList = new List<string>
{
"San Francisco", "Helvetica Neue", "Times New Roman", "Arial",
"Arial Narrow", "Arial Rounded MT Bold", "Baskerville", "Big Caslon",
"Brush Script MT", "Chalkboard", "Chalkduster", "Courier New",
"Futura", "Geneva", "Georgia", "Gill Sans", "Herculanum", "Hoefler Text",
"Impact", "Lucida Grande", "Marker Felt", "Menlo", "Monaco",
"Noteworthy", "Optima", "Palatino", "Papyrus", "Phosphate",
"Skia", "Tahoma", "Trebuchet MS", "Verdana", "Zapf Dingbats",
"Zapfino"
};
}
var allFonts = instance.GetFonts().ToList();
// Фильтрация доступных системных шрифтов
var systemFonts = allFonts
.Where(f => systemFontsList.Contains(f))
.ToList();
if (!systemFonts.Any())
{
foreach (var font in allFonts) instance.ShowFont(font);
return osType;
}
var nonSystemFonts = allFonts.Except(systemFonts).ToList();
// Настройки количества дополнительных шрифтов
int minExtra = osType == "Windows" ? 3 : 20; // Основное изменение
int maxExtra = Math.Max(minExtra + 1, nonSystemFonts.Count);
// Защита от недостатка шрифтов
int actualTake = Math.Min(
rnd.Next(minExtra, maxExtra),
nonSystemFonts.Count
);
var additionalFonts = nonSystemFonts
.OrderBy(f => rnd.Next())
.Take(actualTake)
.ToList();
foreach (var font in allFonts) instance.HideFont(font);
foreach (var font in systemFonts.Concat(additionalFonts)) instance.ShowFont(font);
return osType;