Compare commits

..

23 Commits

Author SHA1 Message Date
7f167d6cbf Merge branch hotfix/v6.3.1 into master 2021-06-28 08:14:12 +00:00
7f22ab1ba1 Merge pull request #637 from ONLYOFFICE/fix/buildLinux
Fix build on linux/macos
2021-06-09 13:58:21 +03:00
3472edc763 Fix build on linux/macos (#636) 2021-06-09 09:45:16 +03:00
4aa3a5cd36 Fix build on linux/macos 2021-06-09 09:09:24 +03:00
5422dcc85a Merge branch hotfix/v6.3.1 into master 2021-06-08 11:51:54 +00:00
686be7c5f0 Aes gcm mode (#634) 2021-06-08 11:32:54 +03:00
a977cfd2b9 Merge pull request #633 from ONLYOFFICE/fix/bug50706
Fix bug 50706
2021-06-03 11:39:36 +03:00
09c2d38b5c Fix bug 50706 2021-06-03 11:35:54 +03:00
2d97939946 Merge pull request #632 from ONLYOFFICE/fix/build
Fix build
2021-06-01 16:50:24 +03:00
9114aa1f90 Fix build 2021-06-01 16:49:12 +03:00
79a9292fe8 Merge pull request #631 from ONLYOFFICE/fix/build
Fix build
2021-06-01 14:44:39 +03:00
ed98692fa8 Fix build 2021-06-01 14:43:48 +03:00
4b8c111981 Merge pull request #630 from ONLYOFFICE/fix/build
Fix build
2021-06-01 12:14:39 +03:00
073d7b4d8b Fix build 2021-06-01 12:12:47 +03:00
c7c15ea254 Merge pull request #629 from ONLYOFFICE/fix/build
Fix build
2021-06-01 11:36:58 +03:00
4de3ced875 Fix build 2021-06-01 11:35:27 +03:00
2ddc8e68d3 Merge pull request #628 from ONLYOFFICE/fix/desktop6.3.0
Fix/desktop6.3.0
2021-05-31 18:11:20 +03:00
7840995442 Merge pull request #625 from ONLYOFFICE/fix/bug50608
Fix bug 50608
2021-05-28 21:17:25 +03:00
76925c03e0 Fix bug 50608 2021-05-28 21:16:26 +03:00
87e66482f2 Merge pull request #624 from ONLYOFFICE/fix/standartTesterSpreadsheets
Add all sheets to generations
2021-05-28 11:56:57 +03:00
9f6e34b975 Add all sheets to generations 2021-05-28 11:55:38 +03:00
a7aa7add19 Refactoring 2021-05-22 17:55:01 +03:00
d1094c0c0b Fix for desktop 6.3.0 2021-05-21 10:13:32 +03:00
21 changed files with 1628 additions and 1825 deletions

View File

@ -187,37 +187,37 @@ namespace DocWrapper {
else
*oFontSelectFormat.bFixedWidth = 0;
}
ULONG ulRange1 = 0;
ULONG ulRange2 = 0;
ULONG ulRange3 = 0;
ULONG ulRange4 = 0;
ULONG ulCodeRange1 = 0;
ULONG ulCodeRange2 = 0;
UINT ulRange1 = 0;
UINT ulRange2 = 0;
UINT ulRange3 = 0;
UINT ulRange4 = 0;
UINT ulCodeRange1 = 0;
UINT ulCodeRange2 = 0;
if (font.m_oUsb0.IsInit())
ulRange1 = font.m_oUsb0->GetValue();
ulRange1 = (UINT)font.m_oUsb0->GetValue();
if (font.m_oUsb1.IsInit())
ulRange2 = font.m_oUsb1->GetValue();
ulRange2 = (UINT)font.m_oUsb1->GetValue();
if (font.m_oUsb2.IsInit())
ulRange3 = font.m_oUsb2->GetValue();
ulRange3 = (UINT)font.m_oUsb2->GetValue();
if (font.m_oUsb3.IsInit())
ulRange4 = font.m_oUsb3->GetValue();
ulRange4 = (UINT)font.m_oUsb3->GetValue();
if (font.m_oCsb0.IsInit())
ulCodeRange1 = font.m_oCsb0->GetValue();
ulCodeRange1 = (UINT)font.m_oCsb0->GetValue();
if (font.m_oCsb1.IsInit())
ulCodeRange2 = font.m_oCsb1->GetValue();
ulCodeRange2 = (UINT)font.m_oCsb1->GetValue();
if ( !(0 == ulRange1 && 0 == ulRange2 && 0 == ulRange3 && 0 == ulRange4 && 0 == ulCodeRange1 && 0 == ulCodeRange2) )
{
oFontSelectFormat.ulRange1 = new ULONG;
oFontSelectFormat.ulRange1 = new UINT;
*oFontSelectFormat.ulRange1 = ulRange1;
oFontSelectFormat.ulRange2 = new ULONG;
oFontSelectFormat.ulRange2 = new UINT;
*oFontSelectFormat.ulRange2 = ulRange2;
oFontSelectFormat.ulRange3 = new ULONG;
oFontSelectFormat.ulRange3 = new UINT;
*oFontSelectFormat.ulRange3 = ulRange3;
oFontSelectFormat.ulRange4 = new ULONG;
oFontSelectFormat.ulRange4 = new UINT;
*oFontSelectFormat.ulRange4 = ulRange4;
oFontSelectFormat.ulCodeRange1 = new ULONG;
oFontSelectFormat.ulCodeRange1 = new UINT;
*oFontSelectFormat.ulCodeRange1 = ulCodeRange1;
oFontSelectFormat.ulCodeRange2 = new ULONG;
oFontSelectFormat.ulCodeRange2 = new UINT;
*oFontSelectFormat.ulCodeRange2 = ulCodeRange2;
}

View File

@ -37,6 +37,7 @@
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/aes.h>
#include <openssl/rand.h>
namespace NSOpenSSL
{
@ -483,4 +484,176 @@ namespace NSOpenSSL
}
return "";
}
// AES GCM for private rooms
#define GCM_IV_LENGTH 12
#define GCM_TAG_LENGHT 16
// для того, чтобы мы могли менять алгоритмы, в зависимости от версии
// на шифровке - дописываем хедер. сделано на этом уровне, чтобы лишний раз не выделять/копировать память
std::string g_aes_header = "VER2;";
unsigned char* PBKDF2_desktop_GCM(const std::string& pass, const std::string& salt)
{
unsigned char* key = NULL;
if (salt.empty())
{
unsigned int pass_salt_len = 0;
unsigned char* pass_salt = NSOpenSSL::GetHash((unsigned char*)pass.c_str(), (unsigned int)pass.length(), OPENSSL_HASH_ALG_SHA512, pass_salt_len);
key = PBKDF2(pass.c_str(), (int)pass.length(), pass_salt, pass_salt_len, OPENSSL_HASH_ALG_SHA256, 32);
openssl_free(pass_salt);
}
else
{
key = PBKDF2(pass.c_str(), (int)pass.length(), (const unsigned char*)salt.c_str(), (unsigned int)salt.length(), OPENSSL_HASH_ALG_SHA256, 32);
}
return key;
}
bool AES_Decrypt_desktop_GCM(const unsigned char* key, const std::string& input, std::string& output, const int header_offset)
{
unsigned char* input_ptr = NULL;
int input_ptr_len = 0;
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str() + header_offset, (int)input.length() - header_offset, input_ptr, input_ptr_len);
if (!bBase64)
return false;
unsigned char* iv_ptr = input_ptr;
unsigned char* tag_ptr = input_ptr + GCM_IV_LENGTH;
unsigned char* ciphertext_ptr = tag_ptr + GCM_TAG_LENGHT;
int ciphertext_len = input_ptr_len - (GCM_IV_LENGTH + GCM_TAG_LENGHT);
unsigned char* output_ptr = NULL;
int output_len = 0;
int final_len = 0;
bool bResult = false;
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
if (!ctx)
goto end;
if (!EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))
goto end;
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, GCM_IV_LENGTH, NULL))
goto end;
if (!EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv_ptr))
goto end;
output_ptr = openssl_alloc(ciphertext_len);
if (!EVP_DecryptUpdate(ctx, output_ptr, &output_len, ciphertext_ptr, ciphertext_len))
goto end;
if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, GCM_TAG_LENGHT, tag_ptr))
goto end;
if (EVP_DecryptFinal_ex(ctx, output_ptr + output_len, &final_len))
{
output_len += final_len;
bResult = true;
}
end:
RELEASEARRAYOBJECTS(input_ptr);
if (ctx)
EVP_CIPHER_CTX_free(ctx);
if (bResult)
{
output = std::string((char*)output_ptr, output_len);
}
if (output_ptr)
openssl_free(output_ptr);
return bResult;
}
bool AES_Encrypt_desktop_GCM(const unsigned char* key, const std::string& input, std::string& output)
{
const unsigned char* input_ptr = (const unsigned char*)input.c_str();
int input_len = (int)input.length();
int output_buffer_all_offset = GCM_IV_LENGTH + GCM_TAG_LENGHT;
int output_buffer_len = input_len + output_buffer_all_offset;
unsigned char* output_ptr = NULL;
unsigned char* iv_ptr = NULL;
unsigned char* tag_ptr = NULL;
unsigned char* ciphertext_ptr = NULL;
int ciphertext_len = 0;
int final_len = 0;
bool bResult = false;
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
if (!ctx)
goto end;
if (1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL))
goto end;
if (1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, GCM_IV_LENGTH, NULL))
goto end;
output_ptr = openssl_alloc(output_buffer_len);
iv_ptr = output_ptr;
tag_ptr = iv_ptr + GCM_IV_LENGTH;
ciphertext_ptr = tag_ptr + GCM_TAG_LENGHT;
if (1 != RAND_bytes(iv_ptr, GCM_IV_LENGTH))
goto end;
if (1 != EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv_ptr))
goto end;
if (1 != EVP_EncryptUpdate(ctx, ciphertext_ptr, &ciphertext_len, input_ptr, input_len))
goto end;
if (1 != EVP_EncryptFinal_ex(ctx, ciphertext_ptr + ciphertext_len, &final_len))
goto end;
ciphertext_len += final_len;
if (1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, GCM_TAG_LENGHT, tag_ptr))
goto end;
bResult = true;
end:
if (ctx)
EVP_CIPHER_CTX_free(ctx);
if (bResult)
{
// header + base64
char* pDataDst = NULL;
int nDataDst = 0;
NSFile::CBase64Converter::Encode(output_ptr, ciphertext_len + output_buffer_all_offset, pDataDst, nDataDst, NSBase64::B64_BASE64_FLAG_NOCRLF);
output = "";
output.reserve(g_aes_header.length() + (size_t)nDataDst + 1);
output.append(g_aes_header);
output.append((char*)pDataDst, nDataDst);
RELEASEARRAYOBJECTS(pDataDst);
}
if (output_ptr)
openssl_free(output_ptr);
return bResult;
}
bool AES_Encrypt_desktop_GCM(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
{
unsigned char* key = PBKDF2_desktop_GCM(pass, salt);
bool bRes = AES_Encrypt_desktop_GCM(key, input, output);
openssl_free(key);
return bRes;
}
bool AES_Decrypt_desktop_GCM(const std::string& pass, const std::string& input, std::string& output, const std::string& salt, const int header_offset)
{
unsigned char* key = PBKDF2_desktop_GCM(pass, salt);
bool bRes = AES_Decrypt_desktop_GCM(key, input, output, header_offset);
openssl_free(key);
return bRes;
}
}

View File

@ -89,6 +89,13 @@ namespace NSOpenSSL
// serialize
OPENSSL_DECL std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg);
// GCM
OPENSSL_DECL unsigned char* PBKDF2_desktop_GCM(const std::string& pass, const std::string& salt = "");
OPENSSL_DECL bool AES_Decrypt_desktop_GCM(const unsigned char* key, const std::string& input, std::string& output, const int header_offset = 0);
OPENSSL_DECL bool AES_Decrypt_desktop_GCM(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "", const int header_offset = 0);
OPENSSL_DECL bool AES_Encrypt_desktop_GCM(const unsigned char* key, const std::string& input, std::string& output);
OPENSSL_DECL bool AES_Encrypt_desktop_GCM(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
}
#endif // COMMON_OPENSSL_H

View File

@ -118,7 +118,7 @@ std::string CV8RealTimeWorker::GetGlobalVariable()
std::wstring CV8RealTimeWorker::GetJSVariable(std::wstring sParam)
{
std::string sParamA = U_TO_UTF8(sParam);
NSCommon::string_replaceA(sParamA, "\\\"", "\"");
NSStringUtils::string_replaceA(sParamA, "\\\"", "\"");
std::string commandA = "(function(){ return (" + sParamA + "); })()";
JSSmart<CJSContextScope> context_scope = m_context->CreateContextScope();
@ -152,8 +152,8 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
std::string sArg = m_sUtf8ArgumentJSON;
if (sArg.empty())
sArg = "{}";
NSCommon::string_replaceA(sArg, "\\", "\\\\");
NSCommon::string_replaceA(sArg, "\"", "\\\"");
NSStringUtils::string_replaceA(sArg, "\\", "\\\\");
NSStringUtils::string_replaceA(sArg, "\"", "\\\"");
std::string sArgument = "var Argument = JSON.parse(\"" + sArg + "\");";
m_context->runScript(sArgument, try_catch);
@ -166,8 +166,8 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
std::string sArg = m_sGlobalVariable;
if (sArg.empty())
sArg = "{}";
NSCommon::string_replaceA(sArg, "\\", "\\\\");
NSCommon::string_replaceA(sArg, "\"", "\\\"");
NSStringUtils::string_replaceA(sArg, "\\", "\\\\");
NSStringUtils::string_replaceA(sArg, "\"", "\\\"");
std::string sScriptVar = "var GlobalVariable = JSON.parse(\"" + sArg + "\");";
@ -231,7 +231,7 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
JSSmart<CJSValue> args_open[3];
args_open[0] = oWorkerLoader.GetDataFull()->toObject()->toValue();
args_open[1] = CJSContext::createInt(nVersion);
std::wstring sXlsx = NSCommon::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
std::wstring sXlsx = NSFile::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
args_open[2] = NSFile::CFileBinary::Exists(sXlsx) ? CJSContext::createString(sXlsx) : CJSContext::createUndefined();
global_js->call_func("NativeOpenFileData", 3, args_open);

View File

@ -312,7 +312,7 @@ namespace NSDoctRenderer
void CheckFonts(bool bIsCheckFonts)
{
std::wstring sDirectory = NSCommon::GetDirectoryName(m_strAllFonts);
std::wstring sDirectory = NSFile::GetDirectoryName(m_strAllFonts);
std::wstring strFontsSelectionBin = sDirectory + L"/font_selection.bin";
if (!bIsCheckFonts && NSFile::CFileBinary::Exists(strFontsSelectionBin))
@ -334,7 +334,7 @@ namespace NSDoctRenderer
if (NSFile::CFileBinary::Exists(m_sFileDir))
NSFile::CFileBinary::Remove(m_sFileDir);
NSCommon::string_replace(m_sFileDir, L"\\", L"/");
NSStringUtils::string_replace(m_sFileDir, L"\\", L"/");
std::wstring::size_type nPosPoint = m_sFileDir.rfind('.');
if (nPosPoint != std::wstring::npos && nPosPoint > m_sTmpFolder.length())
@ -472,7 +472,7 @@ namespace NSDoctRenderer
else
{
oBuilder.WriteString(L"<m_sFontDir>");
oBuilder.WriteEncodeXmlString(NSCommon::GetDirectoryName(m_strAllFonts));
oBuilder.WriteEncodeXmlString(NSFile::GetDirectoryName(m_strAllFonts));
oBuilder.WriteString(L"</m_sFontDir>");
oBuilder.WriteString(L"<m_sAllFontsPath>");
@ -604,7 +604,7 @@ namespace NSDoctRenderer
std::wstring GetFileCopyExt(const std::wstring& path)
{
std::wstring sExtCopy = NSCommon::GetFileExtention(path);
std::wstring sExtCopy = NSFile::GetFileExtention(path);
if (true)
{
@ -702,10 +702,10 @@ namespace NSDoctRenderer
wchar_t last = m_sFolderForSaveOnlyUseNames.c_str()[m_sFolderForSaveOnlyUseNames.length() - 1];
if (last != '/' && last != '\\')
_path += L"/";
_path += NSCommon::GetFileName(path);
_path += NSFile::GetFileName(path);
}
std::wstring sDstFileDir = NSCommon::GetDirectoryName(_path);
std::wstring sDstFileDir = NSFile::GetDirectoryName(_path);
if ((sDstFileDir != _path) && !NSDirectory::Exists(sDstFileDir))
NSDirectory::CreateDirectories(sDstFileDir);
@ -782,7 +782,7 @@ namespace NSDoctRenderer
else
{
oBuilder.WriteString(L"<m_sFontDir>");
oBuilder.WriteEncodeXmlString(NSCommon::GetDirectoryName(m_strAllFonts));
oBuilder.WriteEncodeXmlString(NSFile::GetDirectoryName(m_strAllFonts));
oBuilder.WriteString(L"</m_sFontDir>");
oBuilder.WriteString(L"<m_sAllFontsPath>");
@ -1030,7 +1030,7 @@ namespace NSDoctRenderer
if (0 < arSdkFiles->size())
{
return NSCommon::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache";
return NSFile::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache";
}
return L"";
}
@ -1066,7 +1066,7 @@ namespace NSDoctRenderer
{
std::wstring sValue(value);
std::string sValueA = U_TO_UTF8(sValue);
NSCommon::string_replaceA(sValueA, "%", "%%");
NSStringUtils::string_replaceA(sValueA, "%", "%%");
std::wstring _sFile(path);
std::wstring sFile = GetSaveFilePath(_sFile);

View File

@ -724,7 +724,7 @@ namespace NSDoctRenderer
JSSmart<CJSValue> args_open[4];
args_open[0] = oWorkerLoader.GetDataFull()->toValue();
args_open[1] = CJSContext::createInt(nVersion);
std::wstring sXlsx = NSCommon::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
std::wstring sXlsx = NSFile::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
args_open[2] = NSFile::CFileBinary::Exists(sXlsx) ? CJSContext::createString(sXlsx) : CJSContext::createUndefined();
JSSmart<CJSObject> globalParams = CJSContext::createObject();
if (0 < m_oParams.m_nLcid)

View File

@ -2,7 +2,6 @@
#include "./../docbuilder_p.h"
#include "../../common/Directory.h"
#include "../../fontengine/application_generate_fonts_common.h"
JSSmart<CJSValue> CBuilderEmbed::builder_OpenFile(JSSmart<CJSValue> sPath, JSSmart<CJSValue> sParams)
{
@ -66,7 +65,7 @@ JSSmart<CJSValue> CBuilderDocumentEmbed::builder_doc_GetImageMap()
for (std::vector<std::wstring>::iterator i = files.begin(); i != files.end(); i++)
{
std::wstring sFile = *i;
NSCommon::string_replace(sFile, L"\\", L"/");
NSStringUtils::string_replace(sFile, L"\\", L"/");
std::wstring sName = L"media/" + NSFile::GetFileName(sFile);
obj->set(U_TO_UTF8(sName).c_str(), CJSContext::createString(sFile));
@ -85,7 +84,7 @@ void CBuilderDocumentEmbed::OpenFile(const std::wstring& sFile, const std::wstri
if (NSFile::CFileBinary::Exists(m_sFolder))
NSFile::CFileBinary::Remove(m_sFolder);
NSCommon::string_replace(m_sFolder, L"\\", L"/");
NSStringUtils::string_replace(m_sFolder, L"\\", L"/");
std::wstring::size_type nPosPoint = m_sFolder.rfind('.');
if (nPosPoint != std::wstring::npos && nPosPoint > sTmpDir.length())

View File

@ -151,15 +151,15 @@ FUNCTION_WRAPPER_JS_2(_m, _m)
FUNCTION_WRAPPER_JS_2(_l, _l)
FUNCTION_WRAPPER_JS_6(_c, _c)
FUNCTION_WRAPPER_JS_4(_c2, _c2)
FUNCTION_WRAPPER_JS(_ds, ds)
FUNCTION_WRAPPER_JS(_df, df)
FUNCTION_WRAPPER_JS(ds, ds)
FUNCTION_WRAPPER_JS(df, df)
// canvas state
FUNCTION_WRAPPER_JS(_save, save)
FUNCTION_WRAPPER_JS(_restore, restore)
FUNCTION_WRAPPER_JS(_clip, clip)
FUNCTION_WRAPPER_JS(_reset, reset)
FUNCTION_WRAPPER_JS(_FreeFont, FreeFont)
FUNCTION_WRAPPER_JS(_ClearLastFont, ClearLastFont)
FUNCTION_WRAPPER_JS(save, save)
FUNCTION_WRAPPER_JS(restore, restore)
FUNCTION_WRAPPER_JS(clip, clip)
FUNCTION_WRAPPER_JS(reset, reset)
FUNCTION_WRAPPER_JS(FreeFont, FreeFont)
FUNCTION_WRAPPER_JS(ClearLastFont, ClearLastFont)
// images
FUNCTION_WRAPPER_JS_7(drawImage2, drawImage2)
FUNCTION_WRAPPER_JS_8(drawImage, drawImage)
@ -240,7 +240,7 @@ FUNCTION_WRAPPER_JS(get_LineJoin, get_LineJoin)
FUNCTION_WRAPPER_JS_4(put_TextureBounds, put_TextureBounds)
FUNCTION_WRAPPER_JS(GetlineWidth, GetlineWidth)
FUNCTION_WRAPPER_JS_1(DrawPath, DrawPath)
FUNCTION_WRAPPER_JS_2(_oordTransformOffset, CoordTransformOffset)
FUNCTION_WRAPPER_JS_2(CoordTransformOffset, CoordTransformOffset)
FUNCTION_WRAPPER_JS(GetTransform, GetTransform)
@end

View File

@ -59,7 +59,7 @@ std::wstring CImagesWorker::GetImage(const std::wstring& sUrl)
if (sUrlFile.find(L"localhost") == 0)
sUrlFile = sUrlFile.substr(9);
NSCommon::string_replace(sUrlFile, L"%20", L" ");
NSStringUtils::string_replace(sUrlFile, L"%20", L" ");
if (!NSFile::CFileBinary::Exists(sUrlFile))
sUrlFile = sUrlFile.substr(1);

View File

@ -39,10 +39,10 @@
#include "../graphics/Timer.h"
#include "../common/Directory.h"
#include "../common/Array.h"
#include "../common/StringBuilder.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "js_internal/js_base.h"
#include "../fontengine/application_generate_fonts_common.h"
#if defined(CreateDirectory)
#undef CreateDirectory
@ -182,7 +182,7 @@ private:
void url_correct2(std::wstring& url)
{
NSCommon::string_replace(url, L"/./", L"/");
NSStringUtils::string_replace(url, L"/./", L"/");
size_t posn = 0;
while (std::wstring::npos != (posn = url.find(L"/../")))
@ -195,9 +195,9 @@ private:
}
}
NSCommon::string_replace(url, L"\\\\", L"\\");
NSCommon::string_replace(url, L"//", L"/");
NSCommon::string_replace(url, L"\\", L"/");
NSStringUtils::string_replace(url, L"\\\\", L"\\");
NSStringUtils::string_replace(url, L"//", L"/");
NSStringUtils::string_replace(url, L"\\", L"/");
}
};
@ -346,7 +346,7 @@ public:
{
m_strFilePath = strPath;
m_oZipWorker.m_sWorkerFolder = NSCommon::GetDirectoryName(strPath);
m_oZipWorker.m_sWorkerFolder = NSFile::GetDirectoryName(strPath);
}
std::wstring GetFilePath()
{

View File

@ -266,12 +266,12 @@ namespace NSFonts
memcpy( (void *)pBuffer, (const void *)pInfo->m_aPanose, lLen );
pBuffer += lLen;
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulUnicodeRange1);
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulUnicodeRange2);
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulUnicodeRange3);
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulUnicodeRange4);
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulCodePageRange1);
NSBinarySerialize::Write<UINT>(pBuffer, (UINT)pInfo->m_ulCodePageRange2);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulUnicodeRange1);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulUnicodeRange2);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulUnicodeRange3);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulUnicodeRange4);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulCodePageRange1);
NSBinarySerialize::Write<UINT>(pBuffer, pInfo->m_ulCodePageRange2);
NSBinarySerialize::Write<USHORT>(pBuffer, pInfo->m_usWeigth);
NSBinarySerialize::Write<USHORT>(pBuffer, pInfo->m_usWidth);
@ -445,7 +445,7 @@ namespace NSCharsets
return 0;
}
static void GetCodePageByCharset(unsigned char unCharset, unsigned long *pulBit, unsigned int *punLongIndex)
static void GetCodePageByCharset(unsigned char unCharset, unsigned int *pulBit, unsigned int *punLongIndex)
{
// Данная функция возвращает параметры, которые нужно посылать на вход
// функции AVSFontManager::IsUnicodeRangeAvailable
@ -561,19 +561,19 @@ std::wstring CFontList::GetFontBySymbol(int symbol)
}
///////////////////////////////////////////////////////////////////////////////////
int CFontList::GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset)
int CFontList::GetCharsetPenalty(UINT ulCandRanges[6], unsigned char unReqCharset)
{
// Penalty = 65000 (это самый весомый параметр)
if ( UNKNOWN_CHARSET == unReqCharset )
return 0;
unsigned long ulBit = 0;
unsigned int ulBit = 0;
unsigned int unLongIndex = 0;
NSCharsets::GetCodePageByCharset( unReqCharset, &ulBit, &unLongIndex );
int nMult = 1;
for ( int nIndex = 0; nIndex < (int)ulBit; nIndex++ )
unsigned int nMult = 1;
for ( unsigned int nIndex = 0; nIndex < ulBit; nIndex++ )
nMult <<= 1;
if ( !(ulCandRanges[unLongIndex] & nMult) )
@ -581,56 +581,41 @@ int CFontList::GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqChars
return 0;
}
int CFontList::GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight, double dRangeWeightSuferflouous)
int CFontList::GetSigPenalty(UINT ulCandRanges[6], UINT ulReqRanges[6], double dRangeWeight, double dRangeWeightSuferflouous)
{
double dPenalty = 0;
// Для начала просматриваем сколько вообще различных пространств надо.
// Исходя из их общего количества, находим вес 1 пропущеного пространства.
unsigned char arrCandidate[192], arrRequest[192];
memset( arrCandidate, 0x00, 192 );
memset( arrRequest, 0x00, 192 );
bool isSuferflouous = (dRangeWeightSuferflouous < 1) ? false : true;
int nRangesCount = 0;
for ( int nIndex = 0; nIndex < 6; nIndex++ )
{
UINT nBit = 1;
UINT first = ulReqRanges[nIndex];
UINT second = ulReqRanges[nIndex];
for ( int bit = 0; bit < 32; ++bit, nBit <<= 1 )
{
if (first & nBit)
{
++nRangesCount;
if (!(second & nBit))
dPenalty += dRangeWeight;
}
int nRangesCount = 0; // Количество необходимых пространств
int nAddCount = 0; // количество дополнительных(ненужных) пространств у кандидата
if (isSuferflouous)
{
if (!(first & nBit) && (second & nBit))
dPenalty += dRangeWeightSuferflouous;
}
}
}
for ( int nIndex = 0; nIndex < 6; nIndex++ )
{
for ( unsigned long nBitCount = 0, nBit = 1; nBitCount < 32; nBitCount++, nBit *= 2 )
{
INT bReqAdd = FALSE;
if (!nRangesCount)
return 0;
if ( ulReqRanges[nIndex] & nBit )
{
arrRequest[ nIndex * 32 + nBitCount ] = 1;
nRangesCount++;
bReqAdd = TRUE;
}
if ( ulCandRanges[nIndex] & nBit )
{
arrCandidate[ nIndex * 32 + nBitCount ] = 1;
if ( !bReqAdd )
nAddCount++;
}
}
}
if ( 0 == nRangesCount )
return 0;
//double dRangeWeight = 1;//1000.0 / nRangesCount;
for ( int nIndex = 0; nIndex < 192; nIndex++ )
{
if ( 1 == arrRequest[nIndex] && 0 == arrCandidate[nIndex] )
dPenalty += dRangeWeight;
else if ( dRangeWeightSuferflouous != 0 && 0 == arrRequest[nIndex] && 1 == arrCandidate[nIndex] )
dPenalty += dRangeWeightSuferflouous;
}
return (int)dPenalty;
return (int)dPenalty;
}
int CFontList::GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed)
{
@ -658,10 +643,11 @@ int CFontList::GetFaceNamePenalty(const std::wstring& sCandName, const std::wstr
if ( sReqName == sCandName )
return 0;
if (CFontListNamePicker::IsEqualsFontsAdvanced(sCandName, sReqName))
bool bIsOneInAnother = false;
if (CFontListNamePicker::IsEqualsFontsAdvanced(sCandName, sReqName, &bIsOneInAnother))
return 100;
if ( std::wstring::npos != sReqName.find( sCandName ) || std::wstring::npos != sCandName.find( sReqName ) )
if (bIsOneInAnother)
{
if (m_oPicker.IsLikeFonts(sCandName, sReqName))
return 700;
@ -1019,7 +1005,7 @@ NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect,
nCurPenalty += GetPanosePenalty( pInfo->m_aPanose, oSelect.pPanose );
}
ULONG arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
UINT arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
if (true)
{
@ -1030,7 +1016,7 @@ NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect,
NULL != oSelect.ulCodeRange1 &&
NULL != oSelect.ulCodeRange2)
{
ULONG arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
UINT arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
nCurPenalty += GetSigPenalty( arrCandRanges, arrReqRanges, nCurPenalty >= 1000 ? 50 : 10, 10 );
}
}

View File

@ -155,32 +155,24 @@ public:
int lenName = (int)name.length();
int lenReq = (int)req.length();
const wchar_t* pName = name.c_str();
const wchar_t* pReq = req.c_str();
if (lenName == lenReq)
{
const wchar_t* name_str = name.c_str();
const wchar_t* req_str = req.c_str();
int i = 0;
wchar_t nameChar = 0;
wchar_t reqChar = 0;
while (i < lenName)
{
wchar_t mem1 = *pName++;
wchar_t mem2 = *pReq++;
if (mem1 == mem2)
{
++i;
continue;
}
if (mem1 >= 'A' && mem1 <= 'Z' && (mem1 + 'a' - 'A') == mem2)
{
++i;
continue;
}
if (mem2 >= 'A' && mem2 <= 'Z' && (mem2 + 'a' - 'A') == mem1)
{
++i;
continue;
}
break;
nameChar = *name_str++;
reqChar = *req_str++;
if (nameChar >= 'A' && nameChar <= 'Z')
nameChar += ('a' - 'A');
if (reqChar >= 'A' && reqChar <= 'Z')
reqChar += ('a' - 'A');
if (nameChar != reqChar)
break;
}
if (i == lenName)
return 1500;
@ -189,61 +181,56 @@ public:
return IsEqualsFontsAdvanced(name, req) ? 3000 : 10000;
}
static bool IsEqualsFontsAdvanced(const std::wstring& name, const std::wstring& req)
// не учитываем регистр (латиница) и знаки /-/ /,/
static bool IsEqualsFontsAdvanced(const std::wstring& name, const std::wstring& req, bool* bIsOneInAnother = NULL)
{
int lenName = (int)name.length();
int lenReq = (int)req.length();
const wchar_t* pName = name.c_str();
const wchar_t* pReq = req.c_str();
const wchar_t* name_str = name.c_str();
const wchar_t* req_str = req.c_str();
pName = name.c_str();
pReq = req.c_str();
int curName = 0;
int curReq = 0;
wchar_t* pNameD = new wchar_t[lenName]; int nLenName = 0;
wchar_t* pReqD = new wchar_t[lenReq]; int nLenReq = 0;
for (int i = 0; i < lenName; ++i)
wchar_t curNameChar = 0;
wchar_t curReqChar = 0;
while (true)
{
wchar_t mem = *pName++;
if (mem == '-' || mem == ' ' || mem == ',')
continue;
if (mem >= 'A' && mem <= 'Z')
mem += ('a' - 'A');
pNameD[nLenName++] = mem;
}
for (int i = 0; i < lenReq; ++i)
{
wchar_t mem = *pReq++;
if (mem == '-' || mem == ' ' || mem == ',')
continue;
if (mem >= 'A' && mem <= 'Z')
mem += ('a' - 'A');
pReqD[nLenReq++] = mem;
}
wchar_t* pNameDCur = pNameD;
wchar_t* pReqDCur = pReqD;
bool bIsEq = false;
if (nLenName == nLenReq)
{
int i = 0;
while (i < nLenName)
while (curName < lenName)
{
if (*pNameDCur++ != *pReqDCur++)
break;
++i;
curNameChar = *name_str++;
if (curNameChar == '-' || curNameChar == ' ' || curNameChar == ',')
++curName;
if (curNameChar >= 'A' && curNameChar <= 'Z')
curNameChar += ('a' - 'A');
break;
}
if (curName == lenName)
curNameChar = 0;
if (i == nLenName)
bIsEq = true;
while (curReq < lenReq)
{
curReqChar = *req_str++;
if (curReqChar == '-' || curReqChar == ' ' || curReqChar == ',')
++curReq;
if (curReqChar >= 'A' && curReqChar <= 'Z')
curReqChar += ('a' - 'A');
break;
}
if (curReq == lenReq)
curReqChar = 0;
if (curNameChar != curReqChar)
{
if (bIsOneInAnother)
*bIsOneInAnother = (0 == curNameChar || 0 == curReqChar) ? true : false;
return false;
}
}
delete [] pNameD;
delete [] pReqD;
return bIsEq;
return true;
}
};
@ -281,8 +268,8 @@ public:
virtual std::vector<NSFonts::CFontInfo*>* GetFonts() { return &m_pList; }
private:
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
int GetCharsetPenalty(UINT ulCandRanges[6], unsigned char unReqCharset);
int GetSigPenalty(UINT ulCandRanges[6], UINT ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed);
int GetFaceNamePenalty(const std::wstring& sCandName, const std::wstring& sReqName, bool bIsUseNamePicker = false);
int GetFaceNamePenalty2(NSFonts::CFontInfo* pInfo, const std::wstring& sReqName, bool bIsUseNamePicker = false);

File diff suppressed because it is too large Load Diff

View File

@ -36,21 +36,49 @@
#include <vector>
#include "../graphics/pro/Fonts.h"
class CApplicationFontsWorkerBreaker
{
public:
virtual bool IsFontsWorkerRunned() { return true; }
};
class CApplicationFontsWorker_private;
class CApplicationFontsWorker
{
public:
// использовать ли системные шрифты
bool m_bIsUseSystemFonts;
// дополнительные папки с шрифтами
std::vector<std::wstring> m_arAdditionalFolders;
// рабоча директория (сюда скидываем все артефакты)
std::wstring m_sDirectory;
bool m_bIsNeedThumbnails;
// поддерживать ли opentype шрифты
bool m_bIsUseOpenType;
// поддерживать ли все версии AllFonts.js
bool m_bIsUseAllVersions;
// нужны ли табнейлы
bool m_bIsNeedThumbnails;
// генерим табнейлы отдельно
bool m_bSeparateThumbnails;
// какие масштабы нудны для табнейлов
std::vector<double> m_arThumbnailsScales;
private:
CApplicationFontsWorker_private* m_pInternal;
public:
CApplicationFontsWorker();
~CApplicationFontsWorker();
NSFonts::IApplicationFonts* Check();
void CheckThumbnails();
void SetBreaker(CApplicationFontsWorkerBreaker* pChecker);
std::string GetAllFonts();
static std::vector<std::wstring> GetFontNames(NSFonts::IApplicationFonts* pFonts);

File diff suppressed because it is too large Load Diff

View File

@ -1,194 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef APPLICATION_GENERATE_FONTS_COMMON_H
#define APPLICATION_GENERATE_FONTS_COMMON_H
#include "../common/File.h"
#include "../common/Directory.h"
#include "../common/StringBuilder.h"
namespace NSCommon
{
static void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{
size_t posn = 0;
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
static void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
{
size_t posn = 0;
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
static void url_correct(std::wstring& url)
{
string_replace(url, L"/./", L"/");
size_t posn = 0;
while (std::wstring::npos != (posn = url.find(L"/../")))
{
std::wstring::size_type pos2 = url.rfind(L"/", posn - 1);
if (std::wstring::npos != pos2)
{
url.erase(pos2, posn - pos2 + 3);
}
}
// MAC
if (0 == url.find(L"file:/") && 0 != url.find(L"file://"))
{
url.replace(0, 6, L"file:///");
}
}
static void makeUpper(std::string& url)
{
int nLen = (int)url.length();
char* pStr = (char*)url.c_str();
for (int i = 0; i < nLen; ++i)
{
if (pStr[i] >= 'a' && pStr[i] <= 'z')
pStr[i] = pStr[i] + 'A' - 'a';
}
}
static void makeUpperW(std::wstring& url)
{
int nLen = (int)url.length();
wchar_t* pStr = (wchar_t*)url.c_str();
for (int i = 0; i < nLen; ++i)
{
if (pStr[i] >= 'a' && pStr[i] <= 'z')
pStr[i] = pStr[i] + 'A' - 'a';
}
}
static void makeLower(std::string& url)
{
int nLen = (int)url.length();
char* pStr = (char*)url.c_str();
for (int i = 0; i < nLen; ++i)
{
if (pStr[i] >= 'A' && pStr[i] <= 'Z')
pStr[i] = pStr[i] + 'a' - 'A';
}
}
static void makeLowerW(std::wstring& url)
{
int nLen = (int)url.length();
wchar_t* pStr = (wchar_t*)url.c_str();
for (int i = 0; i < nLen; ++i)
{
if (pStr[i] >= 'A' && pStr[i] <= 'Z')
pStr[i] = pStr[i] + 'a' - 'A';
}
}
static void WriteLog(const std::string& sLogFile, const std::wstring& sData)
{
FILE* f = fopen(sLogFile.c_str(), "a+");
std::string sDataA = U_TO_UTF8(sData);
fprintf(f, sDataA.c_str());
fprintf(f, "\n");
fclose(f);
}
}
namespace NSCommon
{
static std::wstring GetFileExtention(const std::wstring& sPath)
{
std::wstring::size_type nPos = sPath.rfind('.');
if (nPos != std::wstring::npos)
return sPath.substr(nPos + 1);
return sPath;
}
static std::wstring GetFileName(const std::wstring& sPath)
{
#ifdef _WIN32
std::wstring::size_type nPos1 = sPath.rfind('\\');
#else
std::wstring::size_type nPos1 = std::wstring::npos;
#endif
std::wstring::size_type nPos2 = sPath.rfind('/');
std::wstring::size_type nPos = std::wstring::npos;
if (nPos1 != std::wstring::npos)
{
nPos = nPos1;
if (nPos2 != std::wstring::npos && nPos2 > nPos)
nPos = nPos2;
}
else
nPos = nPos2;
if (nPos == std::wstring::npos)
return sPath;
return sPath.substr(nPos + 1);
}
static std::wstring GetDirectoryName(const std::wstring& sPath)
{
#ifdef _WIN32
std::wstring::size_type nPos1 = sPath.rfind('\\');
#else
std::wstring::size_type nPos1 = std::wstring::npos;
#endif
std::wstring::size_type nPos2 = sPath.rfind('/');
std::wstring::size_type nPos = std::wstring::npos;
if (nPos1 != std::wstring::npos)
{
nPos = nPos1;
if (nPos2 != std::wstring::npos && nPos2 > nPos)
nPos = nPos2;
}
else
nPos = nPos2;
if (nPos == std::wstring::npos)
return sPath;
return sPath.substr(0, nPos);
}
}
#endif // APPLICATION_GENERATE_FONTS_COMMON_H

View File

@ -281,12 +281,12 @@ namespace NSFontDictionary
memcpy(oFormat.pPanose, pFont->m_aPanose, 10);
// ranges
oFormat.ulRange1 = new ULONG(pFont->m_ulUnicodeRange1);
oFormat.ulRange2 = new ULONG(pFont->m_ulUnicodeRange2);
oFormat.ulRange3 = new ULONG(pFont->m_ulUnicodeRange3);
oFormat.ulRange4 = new ULONG(pFont->m_ulUnicodeRange4);
oFormat.ulCodeRange1 = new ULONG(pFont->m_ulCodePageRange1);
oFormat.ulCodeRange2 = new ULONG(pFont->m_ulCodePageRange2);
oFormat.ulRange1 = new UINT(pFont->m_ulUnicodeRange1);
oFormat.ulRange2 = new UINT(pFont->m_ulUnicodeRange2);
oFormat.ulRange3 = new UINT(pFont->m_ulUnicodeRange3);
oFormat.ulRange4 = new UINT(pFont->m_ulUnicodeRange4);
oFormat.ulCodeRange1 = new UINT(pFont->m_ulCodePageRange1);
oFormat.ulCodeRange2 = new UINT(pFont->m_ulCodePageRange2);
oFormat.usWeight = new USHORT(pFont->m_usWeigth);
oFormat.usWidth = new USHORT(pFont->m_usWidth);

View File

@ -99,12 +99,12 @@ namespace NSFonts
BYTE* pPanose;
ULONG* ulRange1;
ULONG* ulRange2;
ULONG* ulRange3;
ULONG* ulRange4;
ULONG* ulCodeRange1;
ULONG* ulCodeRange2;
UINT* ulRange1;
UINT* ulRange2;
UINT* ulRange3;
UINT* ulRange4;
UINT* ulCodeRange1;
UINT* ulCodeRange2;
USHORT* usWeight;
USHORT* usWidth;
@ -190,17 +190,17 @@ namespace NSFonts
}
if (NULL != ulRange1)
oFormat.ulRange1 = new ULONG(*ulRange1);
oFormat.ulRange1 = new UINT(*ulRange1);
if (NULL != ulRange2)
oFormat.ulRange2 = new ULONG(*ulRange2);
oFormat.ulRange2 = new UINT(*ulRange2);
if (NULL != ulRange3)
oFormat.ulRange3 = new ULONG(*ulRange3);
oFormat.ulRange3 = new UINT(*ulRange3);
if (NULL != ulRange4)
oFormat.ulRange4 = new ULONG(*ulRange4);
oFormat.ulRange4 = new UINT(*ulRange4);
if (NULL != ulCodeRange1)
oFormat.ulCodeRange1 = new ULONG(*ulCodeRange1);
oFormat.ulCodeRange1 = new UINT(*ulCodeRange1);
if (NULL != ulCodeRange2)
oFormat.ulCodeRange2 = new ULONG(*ulCodeRange2);
oFormat.ulCodeRange2 = new UINT(*ulCodeRange2);
if (NULL != usWeight)
oFormat.usWeight = new USHORT(*usWeight);
@ -277,12 +277,12 @@ namespace NSFonts
INT bItalic,
INT bFixedWidth,
BYTE *pPanose,
ULONG ulRange1,
ULONG ulRange2,
ULONG ulRange3,
ULONG ulRange4,
ULONG ulCodeRange1,
ULONG ulCodeRange2,
UINT ulRange1,
UINT ulRange2,
UINT ulRange3,
UINT ulRange4,
UINT ulCodeRange1,
UINT ulCodeRange2,
USHORT usWeigth,
USHORT usWidth,
SHORT sFamilyClass,
@ -353,14 +353,14 @@ namespace NSFonts
INT m_bItalic; // Italic text
INT m_bIsFixed; // Моноширинный шрифт?
BYTE m_aPanose[10];
ULONG m_ulUnicodeRange1; // Bits 0-31
ULONG m_ulUnicodeRange2; // Bits 32-63
ULONG m_ulUnicodeRange3; // Bits 64-95
ULONG m_ulUnicodeRange4; // Bits 96-127
BYTE m_aPanose[10];
UINT m_ulUnicodeRange1; // Bits 0-31
UINT m_ulUnicodeRange2; // Bits 32-63
UINT m_ulUnicodeRange3; // Bits 64-95
UINT m_ulUnicodeRange4; // Bits 96-127
ULONG m_ulCodePageRange1; // Bits 0-31
ULONG m_ulCodePageRange2; // Bits 32-63
UINT m_ulCodePageRange1; // Bits 0-31
UINT m_ulCodePageRange2; // Bits 32-63
USHORT m_usWeigth;
USHORT m_usWidth;

View File

@ -53,7 +53,7 @@ namespace NSHtmlRenderer
std::wstring m_strFamilyName;
BYTE m_strPANOSE[10];
LONG m_lStyle;
std::vector<DWORD> m_arSignature;
std::vector<UINT> m_arSignature;
bool m_bIsFixedWidth;
LONG m_lAvgWidth;
@ -456,7 +456,7 @@ namespace NSHtmlRenderer
for ( unsigned int i = 0; i < 6; i++ )
{
DWORD value = 0;
UINT value = 0;
for ( unsigned long bit = 0; bit < 32; bit++ )
{
@ -476,7 +476,7 @@ namespace NSHtmlRenderer
std::wstring sExt;
std::wstring sEncodingPath;
int nFindExt = m_oFont.m_oFont.Path.find_last_of((wchar_t)'.');
std::wstring::size_type nFindExt = m_oFont.m_oFont.Path.find_last_of((wchar_t)'.');
if (nFindExt == std::wstring::npos)
{
sEncodingPath = m_oFont.m_oFont.Path + L".enc";
@ -1435,7 +1435,7 @@ namespace NSHtmlRenderer
}
}
}
inline void CheckRanges(DWORD& lRange1, DWORD& lRange2, DWORD& lRange3, DWORD& lRange4, BYTE& lRangeNum, BYTE& lRange)
inline void CheckRanges(UINT& lRange1, UINT& lRange2, UINT& lRange3, UINT& lRange4, BYTE& lRangeNum, BYTE& lRange)
{
if (0 == lRangeNum)
lRange1 |= 1 << lRange;
@ -1524,16 +1524,16 @@ namespace NSHtmlRenderer
oPick.m_lPickStyle = m_oFont.m_oProperties.m_lStyle;
LONG lCountSigs = (LONG)m_oFont.m_oProperties.m_arSignature.size();
DWORD dwR1 = 0;
UINT dwR1 = 0;
if (0 < lCountSigs)
dwR1 = m_oFont.m_oProperties.m_arSignature[0];
DWORD dwR2 = 0;
UINT dwR2 = 0;
if (1 < lCountSigs)
dwR2 = m_oFont.m_oProperties.m_arSignature[1];
DWORD dwR3 = 0;
UINT dwR3 = 0;
if (2 < lCountSigs)
dwR3 = m_oFont.m_oProperties.m_arSignature[2];
DWORD dwR4 = 0;
UINT dwR4 = 0;
if (3 < lCountSigs)
dwR4 = m_oFont.m_oProperties.m_arSignature[3];
@ -1566,17 +1566,17 @@ namespace NSHtmlRenderer
oFormat.bFixedWidth = new INT(m_oFont.m_oProperties.m_bIsFixedWidth ? 1 : 0);
if (0 != dwR1)
oFormat.ulRange1 = new ULONG(dwR1);
oFormat.ulRange1 = new UINT(dwR1);
if (0 != dwR2)
oFormat.ulRange2 = new ULONG(dwR2);
oFormat.ulRange2 = new UINT(dwR2);
if (0 != dwR3)
oFormat.ulRange3 = new ULONG(dwR3);
oFormat.ulRange3 = new UINT(dwR3);
if (0 != dwR4)
oFormat.ulRange4 = new ULONG(dwR4);
oFormat.ulRange4 = new UINT(dwR4);
if (0 != dwCodePage1)
oFormat.ulCodeRange1 = new ULONG(dwCodePage1);
oFormat.ulCodeRange1 = new UINT(dwCodePage1);
if (0 != dwCodePage2)
oFormat.ulCodeRange2 = new ULONG(dwCodePage2);
oFormat.ulCodeRange2 = new UINT(dwCodePage2);
NSFonts::CFontInfo* pInfo = m_pManager->GetFontInfoByParams(oFormat);
oPick.m_strPickFont = pInfo->m_wsFontName;

View File

@ -8,17 +8,19 @@
#include "../../../DesktopEditor/common/File.h"
#include "../../../DesktopEditor/common/Directory.h"
#include "../../../DesktopEditor/common/StringBuilder.h"
#include "../../../DesktopEditor/raster/BgraFrame.h"
#include "../../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include "../../../DesktopEditor/fontengine/application_generate_fonts.h"
#ifdef LINUX
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
#endif
#include <map>
class CConverter;
class CInternalWorker
{
@ -111,7 +113,7 @@ namespace NSX2T
std::wstring sConverterExe = sConverterPath;
#ifdef WIN32
NSCommon::string_replace(sConverterExe, L"/", L"\\");
NSStringUtils::string_replace(sConverterExe, L"/", L"\\");
sConverterExe += L".exe";
std::wstring sApp = L"x2t ";
@ -289,14 +291,14 @@ public:
std::wstring sProcess = NSFile::GetProcessDirectory();
NSCommon::string_replace(sProcess, L"\\", L"/");
NSCommon::string_replace(m_file, L"\\", L"/");
NSStringUtils::string_replace(sProcess, L"\\", L"/");
NSStringUtils::string_replace(m_file, L"\\", L"/");
std::wstring sDirectoryDst = m_folder_dst;
NSCommon::string_replace(sDirectoryDst, L"\\", L"/");
NSStringUtils::string_replace(sDirectoryDst, L"\\", L"/");
#ifdef WIN32
NSCommon::string_replace(m_file, L"//", L"\\\\");
NSStringUtils::string_replace(m_file, L"//", L"\\\\");
#endif
NSDirectory::CreateDirectory(sDirectoryDst);
@ -321,6 +323,7 @@ public:
oBuilder.WriteString(L"</m_sFontDir>");
oBuilder.WriteString(L"<m_oThumbnail><format>4</format><aspect>2</aspect><first>false</first><width>1000</width><height>1000</height></m_oThumbnail>");
oBuilder.WriteString(L"<m_sJsonParams>{&quot;spreadsheetLayout&quot;:{&quot;gridLines&quot;:true,&quot;headings&quot;:true,&quot;fitToHeight&quot;:1,&quot;fitToWidth&quot;:1,&quot;orientation&quot;:&quot;landscape&quot;}}</m_sJsonParams>");
oBuilder.WriteString(L"</TaskQueueDataConvert>");
@ -644,133 +647,22 @@ void CInternalWorker::Cancel()
m_nCount = m_nCurrent;
}
#define ONLYOFFICE_FONTS_VERSION_ 1
void CheckFonts(const bool& bIsUseSystemFonts, std::vector<std::wstring>& arDirs)
{
std::vector<std::string> strFonts;
std::wstring strDirectory = NSFile::GetProcessDirectory() + L"/fonts";
CApplicationFontsWorker oWorker;
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts";
if (!NSDirectory::Exists(oWorker.m_sDirectory))
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
if (!NSDirectory::Exists(strDirectory))
NSDirectory::CreateDirectory(strDirectory);
std::wstring strAllFontsJSPath = strDirectory + L"/AllFonts.js";
std::wstring strThumbnailsFolder = strDirectory;
std::wstring strFontsSelectionBin = strDirectory + L"/font_selection.bin";
if (true)
{
NSFile::CFileBinary oFile;
if (oFile.OpenFile(strDirectory + L"/fonts.log"))
{
int nSize = oFile.GetFileSize();
char* pBuffer = new char[nSize];
DWORD dwReaden = 0;
oFile.ReadFile((BYTE*)pBuffer, nSize, dwReaden);
oFile.CloseFile();
int nStart = 0;
int nCur = nStart;
for (; nCur < nSize; ++nCur)
{
if (pBuffer[nCur] == '\n')
{
int nEnd = nCur - 1;
if (nEnd > nStart)
{
std::string s(pBuffer + nStart, nEnd - nStart + 1);
strFonts.push_back(s);
}
nStart = nCur + 1;
}
}
delete[] pBuffer;
}
if (0 != strFonts.size())
{
// check version!!!
std::string sOO_Version = strFonts[0];
if (0 != sOO_Version.find("ONLYOFFICE_FONTS_VERSION_"))
{
strFonts.clear();
}
else
{
std::string sVersion = sOO_Version.substr(25);
int nVersion = std::stoi(sVersion);
if (nVersion != ONLYOFFICE_FONTS_VERSION_)
strFonts.clear();
else
strFonts.erase(strFonts.begin());
}
}
}
NSFonts::IApplicationFonts* oApplicationF = NSFonts::NSApplication::Create();
std::vector<std::wstring> strFontsW_Cur;
if (bIsUseSystemFonts)
strFontsW_Cur = oApplicationF->GetSetupFontFiles();
oWorker.m_bIsUseSystemFonts = bIsUseSystemFonts;
for (std::vector<std::wstring>::iterator i = arDirs.begin(); i != arDirs.end(); i++)
{
NSDirectory::GetFiles2(*i, strFontsW_Cur, true);
}
oWorker.m_arAdditionalFolders.push_back(*i);
bool bIsEqual = true;
if (strFonts.size() != strFontsW_Cur.size())
bIsEqual = false;
if (bIsEqual)
{
int nCount = (int)strFonts.size();
for (int i = 0; i < nCount; ++i)
{
if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
{
bIsEqual = false;
break;
}
}
}
if (bIsEqual)
{
if (!NSFile::CFileBinary::Exists(strFontsSelectionBin))
bIsEqual = false;
}
if (!bIsEqual)
{
if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
NSFile::CFileBinary::Remove(strAllFontsJSPath);
if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
NSFile::CFileBinary::Remove(strFontsSelectionBin);
if (strFonts.size() != 0)
NSFile::CFileBinary::Remove(strDirectory + L"/fonts.log");
NSFile::CFileBinary oFile;
oFile.CreateFileW(strDirectory + L"/fonts.log");
oFile.WriteStringUTF8(L"ONLYOFFICE_FONTS_VERSION_");
oFile.WriteStringUTF8(std::to_wstring(ONLYOFFICE_FONTS_VERSION_));
oFile.WriteFile((BYTE*)"\n", 1);
int nCount = (int)strFontsW_Cur.size();
for (int i = 0; i < nCount; ++i)
{
oFile.WriteStringUTF8(strFontsW_Cur[i]);
oFile.WriteFile((BYTE*)"\n", 1);
}
oFile.CloseFile();
int nFlag = 3;
oApplicationF->InitializeFromArrayFiles(strFontsW_Cur, nFlag);
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, strThumbnailsFolder, strFontsSelectionBin);
}
oApplicationF->Release();
oWorker.m_bIsNeedThumbnails = false;
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
if (pFonts)
pFonts->Release();
}
std::wstring CorrectDir(const std::wstring& sDir)

View File

@ -8,7 +8,8 @@ TARGET = standardtester
SOURCES += \
$$PWD/../../../../core/Common/OfficeFileFormatChecker2.cpp \
$$PWD/../../../../core/Common/3dParty/pole/pole.cpp \
$$PWD/../../../../core/Common/DocxFormat/Source/Base/unicode_util.cpp
$$PWD/../../../../core/Common/DocxFormat/Source/Base/unicode_util.cpp \
$$PWD/../../../../core/DesktopEditor/fontengine/ApplicationFontsWorker.cpp
SOURCES += main.cpp