mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
For bug 65437. Add param --use-system-user-fonts to allfontsgen
This commit is contained in:
@ -32,10 +32,10 @@
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
#include "../fontengine/ApplicationFontsWorker.h"
|
||||
#include "../common/Directory.h"
|
||||
#include "../fontengine/ApplicationFontsWorker.h"
|
||||
|
||||
//#define _GENERATE_FONT_MAP_
|
||||
// #define _GENERATE_FONT_MAP_
|
||||
|
||||
#ifdef _GENERATE_FONT_MAP_
|
||||
#include "../freetype_names/FontMaps/FontDictionary.h"
|
||||
@ -43,37 +43,37 @@
|
||||
|
||||
std::wstring CorrectDir(const std::wstring& sDir)
|
||||
{
|
||||
if (sDir.empty())
|
||||
return L"";
|
||||
if (sDir.empty())
|
||||
return L"";
|
||||
|
||||
const wchar_t* data = sDir.c_str();
|
||||
const wchar_t* data = sDir.c_str();
|
||||
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = sDir.length();
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = sDir.length();
|
||||
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
|
||||
if (pos2 > 0 && ((data[pos2 - 1] == '\\') || (data[pos2 - 1] == '/')))
|
||||
--pos2;
|
||||
if (pos2 > 0 && ((data[pos2 - 1] == '\\') || (data[pos2 - 1] == '/')))
|
||||
--pos2;
|
||||
|
||||
return sDir.substr(pos1, pos2 - pos1);
|
||||
return sDir.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
std::wstring CorrectValue(const std::wstring& value)
|
||||
{
|
||||
if (value.empty())
|
||||
return L"";
|
||||
if (value.empty())
|
||||
return L"";
|
||||
|
||||
const wchar_t* data = value.c_str();
|
||||
const wchar_t* data = value.c_str();
|
||||
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = value.length();
|
||||
std::wstring::size_type pos1 = (data[0] == '\"') ? 1 : 0;
|
||||
std::wstring::size_type pos2 = value.length();
|
||||
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
if (data[pos2 - 1] == '\"')
|
||||
--pos2;
|
||||
|
||||
return value.substr(pos1, pos2 - pos1);
|
||||
return value.substr(pos1, pos2 - pos1);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
@ -82,149 +82,157 @@ int wmain(int argc, wchar_t** argv)
|
||||
int main(int argc, char** argv)
|
||||
#endif
|
||||
{
|
||||
std::vector<std::wstring> arFontsDirs;
|
||||
bool bIsUseSystemFonts = false;
|
||||
std::wstring strAllFontsWebPath = L"";
|
||||
std::wstring strAllFontsPath = L"";
|
||||
std::wstring strThumbnailsFolder = L"";
|
||||
std::wstring strFontsSelectionBin = L"";
|
||||
std::wstring strOutputDir = L"";
|
||||
int nFontFlag = 3;
|
||||
std::vector<std::wstring> arFontsDirs;
|
||||
bool bIsUseSystemFonts = false;
|
||||
bool bIsUseSystemUserFonts = true;
|
||||
std::wstring strAllFontsWebPath = L"";
|
||||
std::wstring strAllFontsPath = L"";
|
||||
std::wstring strThumbnailsFolder = L"";
|
||||
std::wstring strFontsSelectionBin = L"";
|
||||
std::wstring strOutputDir = L"";
|
||||
int nFontFlag = 3;
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring sParam(argv[i]);
|
||||
std::wstring sParam(argv[i]);
|
||||
#else
|
||||
std::string sParamA(argv[i]);
|
||||
std::wstring sParam = UTF8_TO_U(sParamA);
|
||||
std::string sParamA(argv[i]);
|
||||
std::wstring sParam = UTF8_TO_U(sParamA);
|
||||
#endif
|
||||
|
||||
if (sParam.find(L"--") == 0)
|
||||
{
|
||||
std::wstring sKey = L"";
|
||||
std::wstring sValue = L"";
|
||||
if (sParam.find(L"--") == 0)
|
||||
{
|
||||
std::wstring sKey = L"";
|
||||
std::wstring sValue = L"";
|
||||
|
||||
std::wstring::size_type _pos = sParam.find('=');
|
||||
if (std::wstring::npos == _pos)
|
||||
{
|
||||
sKey = sParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
sKey = sParam.substr(0, _pos);
|
||||
sValue = sParam.substr(_pos + 1);
|
||||
}
|
||||
std::wstring::size_type _pos = sParam.find('=');
|
||||
if (std::wstring::npos == _pos)
|
||||
{
|
||||
sKey = sParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
sKey = sParam.substr(0, _pos);
|
||||
sValue = sParam.substr(_pos + 1);
|
||||
}
|
||||
|
||||
if (sKey == L"--use-system")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
if (sValue == L"1" || sValue == L"true")
|
||||
bIsUseSystemFonts = true;
|
||||
}
|
||||
else if (sKey == L"--allfonts-web")
|
||||
{
|
||||
strAllFontsWebPath = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--allfonts")
|
||||
{
|
||||
strAllFontsPath = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--images")
|
||||
{
|
||||
strThumbnailsFolder = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--selection")
|
||||
{
|
||||
strFontsSelectionBin = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--input")
|
||||
{
|
||||
const wchar_t* src = sValue.c_str();
|
||||
const wchar_t* limit = src + sValue.length();
|
||||
if (sKey == L"--use-system")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
if (sValue == L"1" || sValue == L"true")
|
||||
bIsUseSystemFonts = true;
|
||||
}
|
||||
else if (sKey == L"--use-system-user-fonts")
|
||||
{
|
||||
sValue = CorrectValue(sValue);
|
||||
if (sValue == L"0" || sValue == L"false")
|
||||
bIsUseSystemUserFonts = false;
|
||||
}
|
||||
else if (sKey == L"--allfonts-web")
|
||||
{
|
||||
strAllFontsWebPath = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--allfonts")
|
||||
{
|
||||
strAllFontsPath = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--images")
|
||||
{
|
||||
strThumbnailsFolder = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--selection")
|
||||
{
|
||||
strFontsSelectionBin = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--input")
|
||||
{
|
||||
const wchar_t* src = sValue.c_str();
|
||||
const wchar_t* limit = src + sValue.length();
|
||||
|
||||
const wchar_t* srcPrev = src;
|
||||
while (src < limit)
|
||||
{
|
||||
if (*src == ';')
|
||||
{
|
||||
if (srcPrev != src)
|
||||
{
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
src++;
|
||||
srcPrev = src;
|
||||
}
|
||||
else
|
||||
src++;
|
||||
}
|
||||
const wchar_t* srcPrev = src;
|
||||
while (src < limit)
|
||||
{
|
||||
if (*src == ';')
|
||||
{
|
||||
if (srcPrev != src)
|
||||
{
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
src++;
|
||||
srcPrev = src;
|
||||
}
|
||||
else
|
||||
src++;
|
||||
}
|
||||
|
||||
if (src > srcPrev)
|
||||
{
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
}
|
||||
else if (sKey == L"--output-web")
|
||||
{
|
||||
strOutputDir = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--font-format")
|
||||
{
|
||||
// first byte => isSupportCFF
|
||||
// second byte => isUnsupport DFont (mac)
|
||||
if (src > srcPrev)
|
||||
{
|
||||
arFontsDirs.push_back(CorrectDir(std::wstring(srcPrev, src - srcPrev)));
|
||||
}
|
||||
}
|
||||
else if (sKey == L"--output-web")
|
||||
{
|
||||
strOutputDir = CorrectDir(sValue);
|
||||
}
|
||||
else if (sKey == L"--font-format")
|
||||
{
|
||||
// first byte => isSupportCFF
|
||||
// second byte => isUnsupport DFont (mac)
|
||||
|
||||
int nFlag = std::stoi(sValue);
|
||||
if (nFlag > 0)
|
||||
nFontFlag = nFlag;
|
||||
}
|
||||
}
|
||||
}
|
||||
int nFlag = std::stoi(sValue);
|
||||
if (nFlag > 0)
|
||||
nFontFlag = nFlag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
--input="./fontsInput" --allfonts="./fonts/AllFonts.js" --allfonts-web="./fonts/AllFonts2.js" --images="./fonts" --selection="./fonts/font_selection.bin" --output-web="./fonts" --use-system="false"
|
||||
*/
|
||||
/*
|
||||
--input="./fontsInput" --allfonts="./fonts/AllFonts.js" --allfonts-web="./fonts/AllFonts2.js" --images="./fonts" --selection="./fonts/font_selection.bin" --output-web="./fonts"
|
||||
--use-system="false"
|
||||
*/
|
||||
|
||||
CApplicationFontsWorker oWorker;
|
||||
// это не рабочая папка, где только шрифты
|
||||
oWorker.m_bIsCleanDirectory = false;
|
||||
oWorker.m_bIsRemoveOldThumbnails = true;
|
||||
CApplicationFontsWorker oWorker;
|
||||
// это не рабочая папка, где только шрифты
|
||||
oWorker.m_bIsCleanDirectory = false;
|
||||
oWorker.m_bIsRemoveOldThumbnails = true;
|
||||
|
||||
// input fonts
|
||||
oWorker.m_bIsUseSystemFonts = bIsUseSystemFonts;
|
||||
oWorker.m_arAdditionalFolders = arFontsDirs;
|
||||
// input fonts
|
||||
oWorker.m_bIsUseSystemFonts = bIsUseSystemFonts;
|
||||
if (bIsUseSystemFonts)
|
||||
oWorker.m_bIsUseSystemUserFonts = bIsUseSystemUserFonts;
|
||||
oWorker.m_arAdditionalFolders = arFontsDirs;
|
||||
|
||||
// font_selection.bin
|
||||
// fonts.log
|
||||
oWorker.m_sDirectory = NSFile::GetDirectoryName(strFontsSelectionBin);
|
||||
// font_selection.bin
|
||||
// fonts.log
|
||||
oWorker.m_sDirectory = NSFile::GetDirectoryName(strFontsSelectionBin);
|
||||
|
||||
// thumbnails
|
||||
oWorker.m_sThumbnailsDirectory = strThumbnailsFolder;
|
||||
oWorker.m_bIsNeedThumbnails = !oWorker.m_sThumbnailsDirectory.empty();
|
||||
oWorker.m_bSeparateThumbnails = true;
|
||||
// thumbnails
|
||||
oWorker.m_sThumbnailsDirectory = strThumbnailsFolder;
|
||||
oWorker.m_bIsNeedThumbnails = !oWorker.m_sThumbnailsDirectory.empty();
|
||||
oWorker.m_bSeparateThumbnails = true;
|
||||
|
||||
// allfonts
|
||||
oWorker.m_sAllFontsJSPath = strAllFontsPath;
|
||||
oWorker.m_sWebAllFontsJSPath = strAllFontsWebPath;
|
||||
// allfonts
|
||||
oWorker.m_sAllFontsJSPath = strAllFontsPath;
|
||||
oWorker.m_sWebAllFontsJSPath = strAllFontsWebPath;
|
||||
|
||||
// webfonts
|
||||
oWorker.m_sWebFontsDirectory = strOutputDir;
|
||||
// webfonts
|
||||
oWorker.m_sWebFontsDirectory = strOutputDir;
|
||||
|
||||
// opentype
|
||||
oWorker.m_bIsUseOpenType = (0x01 == (0x01 & nFontFlag));
|
||||
// opentype
|
||||
oWorker.m_bIsUseOpenType = (0x01 == (0x01 & nFontFlag));
|
||||
|
||||
NSFonts::IApplicationFonts* pApplicationFonts = oWorker.Check();
|
||||
if (oWorker.m_bIsNeedThumbnails)
|
||||
oWorker.CheckThumbnails();
|
||||
|
||||
RELEASEINTERFACE(pApplicationFonts);
|
||||
NSFonts::IApplicationFonts* pApplicationFonts = oWorker.Check();
|
||||
if (oWorker.m_bIsNeedThumbnails)
|
||||
oWorker.CheckThumbnails();
|
||||
|
||||
RELEASEINTERFACE(pApplicationFonts);
|
||||
|
||||
#ifdef _GENERATE_FONT_MAP_
|
||||
|
||||
NSCommon::DumpFontsDictionary(L"./fonts_dictionary.txt");
|
||||
NSCommon::DumpFontsDictionary(L"./fonts_dictionary.txt");
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1707,7 +1707,7 @@ static long GetNextNameValue(HKEY key, const std::wstring& sSubkey, std::wstring
|
||||
|
||||
#endif
|
||||
|
||||
std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles()
|
||||
std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles(const bool& bIsUseUserFonts)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
// Ищем директорию с фонтами (обычно это C:\Windows\Fonts)
|
||||
@ -1778,13 +1778,16 @@ std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles()
|
||||
{
|
||||
std::vector<std::wstring> oArray2 = NSDirectory::GetFiles(L"C:\\Windows\\Fonts", true);
|
||||
|
||||
wchar_t sUserName[1000];
|
||||
DWORD nUserNameLen = 1000 + 1;
|
||||
GetUserNameW(sUserName, &nUserNameLen);
|
||||
std::wstring strUserName(sUserName, nUserNameLen - 1);
|
||||
if (bIsUseUserFonts)
|
||||
{
|
||||
wchar_t sUserName[1000];
|
||||
DWORD nUserNameLen = 1000 + 1;
|
||||
GetUserNameW(sUserName, &nUserNameLen);
|
||||
std::wstring strUserName(sUserName, nUserNameLen - 1);
|
||||
|
||||
NSDirectory::GetFiles2(L"C:\\Users\\" + strUserName + L"\\AppData\\Local\\Microsoft\\Windows\\Fonts", oArray2, false);
|
||||
NSDirectory::GetFiles2(L"C:\\Users\\" + strUserName + L"\\AppData\\Local\\Microsoft\\FontCache\\4\\CloudFonts", oArray2, true);
|
||||
NSDirectory::GetFiles2(L"C:\\Users\\" + strUserName + L"\\AppData\\Local\\Microsoft\\Windows\\Fonts", oArray2, false);
|
||||
NSDirectory::GetFiles2(L"C:\\Users\\" + strUserName + L"\\AppData\\Local\\Microsoft\\FontCache\\4\\CloudFonts", oArray2, true);
|
||||
}
|
||||
|
||||
for (std::vector<std::wstring>::iterator i = oArray2.begin(); i != oArray2.end(); i++)
|
||||
{
|
||||
@ -1800,9 +1803,11 @@ std::vector<std::wstring> CApplicationFonts::GetSetupFontFiles()
|
||||
std::vector<std::wstring> _array = NSDirectory::GetFiles(L"/usr/share/fonts", true);
|
||||
NSDirectory::GetFiles2(L"/usr/share/X11/fonts", _array, true);
|
||||
NSDirectory::GetFiles2(L"/usr/X11R6/lib/X11/fonts", _array, true);
|
||||
NSDirectory::GetFiles2(L"/usr/local/share/fonts", _array, true);
|
||||
NSDirectory::GetFiles2(L"/run/host/fonts", _array, true);
|
||||
|
||||
if (bIsUseUserFonts)
|
||||
NSDirectory::GetFiles2(L"/usr/local/share/fonts", _array, true);
|
||||
|
||||
#ifndef BUILDING_WASM_MODULE
|
||||
std::wstring custom_fonts_path = NSSystemUtils::GetEnvVariable(L"CUSTOM_FONTS_PATH");
|
||||
if (!custom_fonts_path.empty())
|
||||
|
||||
@ -345,7 +345,7 @@ public:
|
||||
void InitializeFromBin(BYTE* pData, unsigned int nLen);
|
||||
void InitializeRanges(unsigned char* data);
|
||||
|
||||
std::vector<std::wstring> GetSetupFontFiles();
|
||||
std::vector<std::wstring> GetSetupFontFiles(const bool& bIsUseUserFonts = true);
|
||||
void InitializeFromArrayFiles(std::vector<std::wstring>& files, int nFlag = 0);
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
|
||||
@ -1566,6 +1566,7 @@ public:
|
||||
CApplicationFontsWorker::CApplicationFontsWorker()
|
||||
{
|
||||
m_bIsUseSystemFonts = true;
|
||||
m_bIsUseSystemUserFonts = true;
|
||||
m_bIsNeedThumbnails = true;
|
||||
m_bIsUseOpenType = true;
|
||||
m_bIsUseAllVersions = false;
|
||||
@ -1658,7 +1659,7 @@ NSFonts::IApplicationFonts* CApplicationFontsWorker::Check()
|
||||
std::vector<std::wstring> strFontsW_Cur;
|
||||
|
||||
if (m_bIsUseSystemFonts)
|
||||
strFontsW_CurSrc = pApplicationF->GetSetupFontFiles();
|
||||
strFontsW_CurSrc = pApplicationF->GetSetupFontFiles(m_bIsUseSystemUserFonts);
|
||||
|
||||
for (std::vector<std::wstring>::iterator i = m_arAdditionalFolders.begin(); i != m_arAdditionalFolders.end(); i++)
|
||||
{
|
||||
|
||||
@ -51,6 +51,8 @@ class GRAPHICS_DECL CApplicationFontsWorker
|
||||
public:
|
||||
// использовать ли системные шрифты
|
||||
bool m_bIsUseSystemFonts;
|
||||
bool m_bIsUseSystemUserFonts;
|
||||
|
||||
// дополнительные папки с шрифтами
|
||||
std::vector<std::wstring> m_arAdditionalFolders;
|
||||
|
||||
|
||||
@ -784,7 +784,7 @@ namespace NSFonts
|
||||
virtual void InitializeFromBin(BYTE* pData, unsigned int nLen) = 0;
|
||||
virtual void InitializeRanges(unsigned char* data) = 0;
|
||||
|
||||
virtual std::vector<std::wstring> GetSetupFontFiles() = 0;
|
||||
virtual std::vector<std::wstring> GetSetupFontFiles(const bool& bIsUseUserFonts = true) = 0;
|
||||
virtual void InitializeFromArrayFiles(std::vector<std::wstring>& files, int nFlag = 0) = 0;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
Reference in New Issue
Block a user