Compare commits

..

19 Commits

Author SHA1 Message Date
48d4b72d4b Merge pull request #39 from ONLYOFFICE/release/v5.0.0
xhtml bug
2017-09-18 10:35:39 +03:00
85de7ec7a6 xhtml bug 2017-09-15 19:07:14 +03:00
9e6d4950c2 Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop
* 'develop' of https://github.com/ONLYOFFICE/core:
  store Editor.xlsx without m_bSaveXFile flag
  .
  font names project (full work)
  .
  fix open html file with incorrect extension
  .
  .
  .
  pivot table build on server
  XlsFormat pivots - fix after testing
  build error (not windows)
  first version zip reader (doctrenderer)
2017-09-14 17:08:28 +03:00
cb4befa078 up 2017-09-14 17:08:19 +03:00
ac1292a17a Merge remote-tracking branch 'origin/release/v5.0.0' into develop 2017-09-14 13:35:25 +03:00
007a984c36 store Editor.xlsx without m_bSaveXFile flag 2017-09-13 19:35:56 +03:00
d3d3180402 . 2017-09-13 19:06:32 +03:00
fa9c096f3c font names project (full work) 2017-09-13 17:20:50 +03:00
e1ec9d942e . 2017-09-13 13:14:32 +03:00
4acaa75b06 Merge branch 'release/v5.0.0' of https://github.com/ONLYOFFICE/core into release/v5.0.0 2017-09-12 18:17:02 +03:00
431115ef48 fix open html file with incorrect extension 2017-09-12 18:16:26 +03:00
2d66d9902e . 2017-09-12 18:15:26 +03:00
206dd12a47 . 2017-09-12 16:14:08 +03:00
e8d3059fe8 . 2017-09-12 16:07:20 +03:00
f624f731de fix for build 2017-09-12 15:23:45 +03:00
ed373b7e2d pivot table build on server 2017-09-12 14:11:57 +03:00
a67eb5644d XlsFormat pivots - fix after testing 2017-09-12 13:11:41 +03:00
5040220d82 build error (not windows) 2017-09-12 10:42:54 +03:00
4f0b889f04 first version zip reader (doctrenderer) 2017-09-11 18:44:52 +03:00
37 changed files with 1781 additions and 5477 deletions

View File

@ -229,7 +229,7 @@ const std::wstring int2wstr(const int val, const int radix)
const std::wstring double2str(const double val)
{
return std::to_wstring(val);
return boost::lexical_cast<std::wstring>(val);// std::to_wstring(val); - округление (
}

View File

@ -62,6 +62,7 @@ void DXFNum::load(CFRecord& record)
int DXFNum::serialize(std::wostream & stream)
{
if (!parent) return 0;
if (fmt_id.ifmt == 0) return 0;
CP_XML_WRITER(stream)
{

View File

@ -227,7 +227,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB)
Formula->serialize_attr(CP_GET_XML_NODE());
}
if (!m_arSRCSXOPER.empty() && (bDBB || (!bDBB && bSql)) )
if (!m_arSRCSXOPER.empty() && (bDBB || (!bDBB && bSql) || !m_arGRPSXOPER.empty()) )
{
CP_XML_NODE(L"sharedItems")
{
@ -266,7 +266,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB)
else if (!bEmpty && !bString && !bBool)
{
CP_XML_ATTR(L"containsSemiMixedTypes", 0);
if (bDate)
if (bDate && (bNumber || bInteger))
{
CP_XML_ATTR(L"containsMixedTypes", 1);
}
@ -320,7 +320,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB)
}
}
if (m_arGRPSXOPER.empty() == false)
if (!m_arGRPSXOPER.empty())
{
CP_XML_NODE(L"fieldGroup")
{

View File

@ -209,21 +209,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
XLS::BinReaderProcessor proc(pivot_cache_reader , pivot_cache.get() , true);
proc.mandatory(*pivot_cache.get());
int index = -1;
try
{
index = boost::lexical_cast<int>(it->c_str());
}
catch(...)
{
}
if (index < 0)
{
//может быть шестнадцатеричное
index = XmlUtils::GetHex(*it);
}
if (index < 0)
index = last_index + 1;
int index = XmlUtils::GetHex(*it);
xls_global_info->mapPivotCacheStream.insert(std::make_pair(index, pivot_cache));

View File

@ -49,43 +49,45 @@ namespace OOX
public:
CExtensionTable()
{
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("bmp"), _T("image/bmp")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("gif"), _T("image/gif")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("png"), _T("image/png")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("tif"), _T("image/tiff")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("tiff"), _T("image/tiff")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpeg"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpg"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpe"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jfif"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("rels"), _T("application/vnd.openxmlformats-package.relationships+xml")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("bin"), _T("application/vnd.openxmlformats-officedocument.oleObject")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xml"), _T("application/xml")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("emf"), _T("image/x-emf")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("emz"), _T("image/x-emz")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wmf"), _T("image/x-wmf")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("svm"), _T("image/svm")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wav"), _T("audio/wav")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wma"), _T("audio/x-wma")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("m4a"), _T("audio/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mp3"), _T("audio/mpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mp4"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mov"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("avi"), _T("video/avi")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wmv"), _T("video/x-wmv")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xls"), _T("application/vnd.ms-excel")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsm"), _T("application/vnd.ms-excel.sheet.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsb"), _T("application/vnd.ms-excel.sheet.binary.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsx"), _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("ppt"), _T("application/vnd.ms-powerpoint")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("pptm"), _T("application/vnd.ms-powerpoint.presentation.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("pptx"), _T("application/vnd.openxmlformats-officedocument.presentationml.presentation")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("sldm"), _T("application/vnd.ms-powerpoint.slide.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("sldx"), _T("application/vnd.openxmlformats-officedocument.presentationml.slide")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("doc"), _T("application/msword")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("docm"), _T("aapplication/vnd.ms-word.document.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("docx"), _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("vml"), _T("application/vnd.openxmlformats-officedocument.vmlDrawing")));
m_mTable.insert( std::make_pair( _T("bmp"), _T("image/bmp")));
m_mTable.insert( std::make_pair( _T("gif"), _T("image/gif")));
m_mTable.insert( std::make_pair( _T("png"), _T("image/png")));
m_mTable.insert( std::make_pair( _T("tif"), _T("image/tiff")));
m_mTable.insert( std::make_pair( _T("tiff"), _T("image/tiff")));
m_mTable.insert( std::make_pair( _T("jpeg"), _T("image/jpeg")));
m_mTable.insert( std::make_pair( _T("jpg"), _T("image/jpeg")));
m_mTable.insert( std::make_pair( _T("jpe"), _T("image/jpeg")));
m_mTable.insert( std::make_pair( _T("jfif"), _T("image/jpeg")));
m_mTable.insert( std::make_pair( _T("rels"), _T("application/vnd.openxmlformats-package.relationships+xml")));
m_mTable.insert( std::make_pair( _T("bin"), _T("application/vnd.openxmlformats-officedocument.oleObject")));
m_mTable.insert( std::make_pair( _T("xml"), _T("application/xml")));
m_mTable.insert( std::make_pair( _T("emf"), _T("image/x-emf")));
m_mTable.insert( std::make_pair( _T("emz"), _T("image/x-emz")));
m_mTable.insert( std::make_pair( _T("wmf"), _T("image/x-wmf")));
m_mTable.insert( std::make_pair( _T("svm"), _T("image/svm")));
m_mTable.insert( std::make_pair( _T("wav"), _T("audio/wav")));
m_mTable.insert( std::make_pair( _T("wma"), _T("audio/x-wma")));
m_mTable.insert( std::make_pair( _T("m4a"), _T("audio/unknown")));
m_mTable.insert( std::make_pair( _T("mp3"), _T("audio/mpeg")));
m_mTable.insert( std::make_pair( _T("mp4"), _T("video/unknown")));
m_mTable.insert( std::make_pair( _T("mov"), _T("video/unknown")));
m_mTable.insert( std::make_pair( _T("m4v"), _T("video/unknown")));
m_mTable.insert( std::make_pair( _T("mkv"), _T("video/unknown")));
m_mTable.insert( std::make_pair( _T("avi"), _T("video/avi")));
m_mTable.insert( std::make_pair( _T("wmv"), _T("video/x-wmv")));
m_mTable.insert( std::make_pair( _T("xls"), _T("application/vnd.ms-excel")));
m_mTable.insert( std::make_pair( _T("xlsm"), _T("application/vnd.ms-excel.sheet.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("xlsb"), _T("application/vnd.ms-excel.sheet.binary.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("xlsx"), _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")));
m_mTable.insert( std::make_pair( _T("ppt"), _T("application/vnd.ms-powerpoint")));
m_mTable.insert( std::make_pair( _T("pptm"), _T("application/vnd.ms-powerpoint.presentation.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("pptx"), _T("application/vnd.openxmlformats-officedocument.presentationml.presentation")));
m_mTable.insert( std::make_pair( _T("sldm"), _T("application/vnd.ms-powerpoint.slide.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("sldx"), _T("application/vnd.openxmlformats-officedocument.presentationml.slide")));
m_mTable.insert( std::make_pair( _T("doc"), _T("application/msword")));
m_mTable.insert( std::make_pair( _T("docm"), _T("aapplication/vnd.ms-word.document.macroEnabled.12")));
m_mTable.insert( std::make_pair( _T("docx"), _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document")));
m_mTable.insert( std::make_pair( _T("vml"), _T("application/vnd.openxmlformats-officedocument.vmlDrawing")));
}
const std::wstring operator[] (const std::wstring& sExtension) const
{

View File

@ -387,11 +387,22 @@ public:
CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
v8::Handle<v8::Value> args_open[2];
v8::Handle<v8::Value> args_open[3];
args_open[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(m_isolate, nVersion);
func_open->Call(global_js, 2, args_open);
std::wstring sXlsx = NSCommon::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
if (NSFile::CFileBinary::Exists(sXlsx))
{
std::string sXlsxA = U_TO_UTF8(sXlsx);
args_open[2] = v8::String::NewFromUtf8(m_isolate, (char*)(sXlsxA.c_str()));
}
else
{
args_open[2] = v8::Undefined(m_isolate);
}
func_open->Call(global_js, 3, args_open);
if (try_catch.HasCaught())
{

View File

@ -364,18 +364,18 @@ namespace NSDoctRenderer
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{
#if 0
if (m_sErrorsLogFile.empty())
return;
#if 0
if (m_sErrorsLogFile.empty())
return;
FILE* f = NSFile::CFileBinary::OpenFileNative(m_sErrorsLogFile, L"a+");
FILE* f = NSFile::CFileBinary::OpenFileNative(m_sErrorsLogFile, L"a+");
std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
fprintf(f, sT.c_str());
fprintf(f, sT.c_str());
fprintf(f, ": ");
fprintf(f, sE.c_str());
fprintf(f, sE.c_str());
fprintf(f, "\n");
fclose(f);
#endif
@ -730,11 +730,22 @@ namespace NSDoctRenderer
CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
v8::Handle<v8::Value> args_open[2];
v8::Handle<v8::Value> args_open[3];
args_open[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(isolate, nVersion);
func_open->Call(global_js, 2, args_open);
std::wstring sXlsx = NSCommon::GetDirectoryName(pNative->GetFilePath()) + L"/Editor.xlsx";
if (NSFile::CFileBinary::Exists(sXlsx))
{
std::string sXlsxA = U_TO_UTF8(sXlsx);
args_open[2] = v8::String::NewFromUtf8(isolate, (char*)(sXlsxA.c_str()));
}
else
{
args_open[2] = v8::Undefined(isolate);
}
func_open->Call(global_js, 3, args_open);
if (try_catch.HasCaught())
{

View File

@ -305,6 +305,112 @@ void _SaveChanges(const v8::FunctionCallbackInfo<v8::Value>& args)
pNative->DumpChanges(to_cstringA(args[0]), args[1]->Int32Value(), args[2]->Int32Value());
}
/// ZIP -----
void _zipOpenFile(const v8::FunctionCallbackInfo<v8::Value>& args)
{
if (args.Length() < 1)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
CNativeControl* pNative = unwrap_nativeobject(args.This());
bool bIsOpen = pNative->m_oZipWorker.Open(to_cstring(args[0]));
if (!bIsOpen)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
v8::Local<v8::Object> obj = v8::Object::New(v8::Isolate::GetCurrent());
for (std::vector<std::wstring>::iterator i = pNative->m_oZipWorker.m_arFiles.begin(); i != pNative->m_oZipWorker.m_arFiles.end(); i++)
{
std::string sFile = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(*i);
v8::Local<v8::String> _k = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1);
v8::Local<v8::String> _v = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1);
obj->Set(_k, _v);
}
args.GetReturnValue().Set(obj);
}
void _zipOpenFileBase64(const v8::FunctionCallbackInfo<v8::Value>& args)
{
if (args.Length() < 1)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
CNativeControl* pNative = unwrap_nativeobject(args.This());
bool bIsOpen = pNative->m_oZipWorker.OpenBase64(to_cstringA(args[0]));
if (!bIsOpen)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
v8::Local<v8::Object> obj = v8::Object::New(v8::Isolate::GetCurrent());
for (std::vector<std::wstring>::iterator i = pNative->m_oZipWorker.m_arFiles.begin(); i != pNative->m_oZipWorker.m_arFiles.end(); i++)
{
std::string sFile = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(*i);
v8::Local<v8::String> _k = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1);
v8::Local<v8::String> _v = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sFile.c_str(), v8::String::kNormalString, -1);
obj->Set(_k, _v);
}
args.GetReturnValue().Set(obj);
}
void _zipGetFileAsString(const v8::FunctionCallbackInfo<v8::Value>& args)
{
if (args.Length() < 1)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
CNativeControl* pNative = unwrap_nativeobject(args.This());
BYTE* pData = NULL;
DWORD len = 0;
pNative->m_oZipWorker.GetFileData(to_cstring(args[0]), pData, len);
args.GetReturnValue().Set(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), (char*)pData, v8::String::kNormalString, len));
}
void _zipGetFileAsBinary(const v8::FunctionCallbackInfo<v8::Value>& args)
{
if (args.Length() < 1)
{
args.GetReturnValue().Set(v8::Null(v8::Isolate::GetCurrent()));
return;
}
CNativeControl* pNative = unwrap_nativeobject(args.This());
BYTE* pData = NULL;
DWORD len = 0;
pNative->m_oZipWorker.GetFileData(to_cstring(args[0]), pData, len);
v8::Local<v8::ArrayBuffer> _buffer = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), (void*)pData, (size_t)len);
v8::Local<v8::Uint8Array> _array = v8::Uint8Array::New(_buffer, 0, (size_t)len);
args.GetReturnValue().Set(_array);
}
void _zipCloseFile(const v8::FunctionCallbackInfo<v8::Value>& args)
{
CNativeControl* pNative = unwrap_nativeobject(args.This());
args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent()));
pNative->m_oZipWorker.Close();
}
/// ---------
void _AddImageInChanges(const v8::FunctionCallbackInfo<v8::Value>& args)
{
args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent()));
@ -355,6 +461,12 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate)
result->Set(v8::String::NewFromUtf8(current, "ConsoleLog"), v8::FunctionTemplate::New(current, _ConsoleLog));
result->Set(v8::String::NewFromUtf8(current, "ZipOpen"), v8::FunctionTemplate::New(current, _zipOpenFile));
result->Set(v8::String::NewFromUtf8(current, "ZipOpenBase64"), v8::FunctionTemplate::New(current, _zipOpenFileBase64));
result->Set(v8::String::NewFromUtf8(current, "ZipFileAsString"), v8::FunctionTemplate::New(current, _zipGetFileAsString));
result->Set(v8::String::NewFromUtf8(current, "ZipFileAsBinary"), v8::FunctionTemplate::New(current, _zipGetFileAsBinary));
result->Set(v8::String::NewFromUtf8(current, "ZipClose"), v8::FunctionTemplate::New(current, _zipCloseFile));
// возвращаем временный хэндл хитрым образом, который переносит наш хэндл в предыдущий HandleScope и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope
@ -397,6 +509,12 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplateBuilder(v8::Isolate* i
result->Set(v8::String::NewFromUtf8(current, "SaveChanges"), v8::FunctionTemplate::New(current, _SaveChanges));
result->Set(v8::String::NewFromUtf8(current, "ZipOpen"), v8::FunctionTemplate::New(current, _zipOpenFile));
result->Set(v8::String::NewFromUtf8(current, "ZipOpenBase64"), v8::FunctionTemplate::New(current, _zipOpenFileBase64));
result->Set(v8::String::NewFromUtf8(current, "ZipFileAsString"), v8::FunctionTemplate::New(current, _zipGetFileAsString));
result->Set(v8::String::NewFromUtf8(current, "ZipFileAsBinary"), v8::FunctionTemplate::New(current, _zipGetFileAsBinary));
result->Set(v8::String::NewFromUtf8(current, "ZipClose"), v8::FunctionTemplate::New(current, _zipCloseFile));
// возвращаем временный хэндл хитрым образом, который переносит наш хэндл в предыдущий HandleScope и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope

View File

@ -37,6 +37,132 @@
#include "../fontengine/ApplicationFonts.h"
#include <iostream>
#include "../../graphics/Timer.h"
#include "../../common/Directory.h"
#include "../../../../OfficeUtils/src/OfficeUtils.h"
#include "../../fontengine/application_generate_fonts_common.h"
class CZipWorker
{
public:
std::wstring m_sTmpFolder;
std::vector<std::wstring> m_arFiles;
std::wstring m_sWorkerFolder;
public:
CZipWorker()
{
m_sWorkerFolder = L"";
}
~CZipWorker()
{
Close();
}
void Close()
{
if (!m_sTmpFolder.empty())
NSDirectory::DeleteDirectory(m_sTmpFolder);
m_sTmpFolder = L"";
m_arFiles.clear();
}
bool Open(const std::wstring& sFile)
{
m_sTmpFolder = m_sWorkerFolder + L"/nativeZip";
COfficeUtils oUtils;
NSDirectory::CreateDirectory(m_sTmpFolder);
if (S_OK != oUtils.ExtractToDirectory(sFile, m_sTmpFolder, NULL, 0))
return false;
CheckDirectory();
return true;
}
bool OpenBase64(const std::string& sData)
{
BYTE* pRawData = NULL;
int nRawSize = 0;
if (true != NSFile::CBase64Converter::Decode(sData.c_str(), (int)sData.length(), pRawData, nRawSize))
return false;
std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSDirectory::GetTempPath(), L"ZIP");
if (NSFile::CFileBinary::Exists(sTmpFile))
NSFile::CFileBinary::Remove(sTmpFile);
NSFile::CFileBinary oFile;
oFile.CreateFileW(sTmpFile);
oFile.WriteFile(pRawData, (DWORD)nRawSize);
oFile.CloseFile();
m_sTmpFolder = m_sWorkerFolder + L"/nativeZip";
COfficeUtils oUtils;
NSDirectory::CreateDirectory(m_sTmpFolder);
if (S_OK != oUtils.ExtractToDirectory(sTmpFile, m_sTmpFolder, NULL, 0))
{
NSFile::CFileBinary::Remove(sTmpFile);
return false;
}
NSFile::CFileBinary::Remove(sTmpFile);
CheckDirectory();
return true;
}
void CheckDirectory()
{
std::vector<std::wstring> arFiles = NSDirectory::GetFiles(m_sTmpFolder, true);
url_correct2(m_sTmpFolder);
int nStart = m_sTmpFolder.length();
for (std::vector<std::wstring>::iterator i = arFiles.begin(); i != arFiles.end(); i++)
{
std::wstring sTmp = *i;
url_correct2(sTmp);
m_arFiles.push_back(sTmp.substr(nStart + 1));
}
}
void GetFileData(const std::wstring& strFile, BYTE*& pData, DWORD& dwLen)
{
NSFile::CFileBinary oFile;
oFile.OpenFile(m_sTmpFolder + L"/" + strFile);
dwLen = (DWORD)oFile.GetFileSize();
pData = (BYTE*)malloc((size_t)dwLen);
DWORD dwSizeRead = 0;
oFile.ReadFile(pData, dwLen, dwSizeRead);
oFile.CloseFile();
}
private:
void url_correct2(std::wstring& url)
{
NSCommon::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);
}
}
NSCommon::string_replace(url, L"\\\\", L"\\");
NSCommon::string_replace(url, L"//", L"/");
NSCommon::string_replace(url, L"\\", L"/");
}
};
// string convert
std::wstring to_cstring(v8::Local<v8::Value> v);
@ -76,6 +202,8 @@ public:
std::wstring m_sChangesBuilderPath;
int m_nCurrentChangesBuilderIndex;
CZipWorker m_oZipWorker;
public:
CMemoryStream* m_pStream;
@ -152,6 +280,8 @@ public:
void SetFilePath(const std::wstring& strPath)
{
m_strFilePath = strPath;
m_oZipWorker.m_sWorkerFolder = NSCommon::GetDirectoryName(strPath);
}
std::wstring GetFilePath()
{
@ -324,6 +454,14 @@ void _ConsoleLog(const v8::FunctionCallbackInfo<v8::Value>& args);
void _SaveChanges(const v8::FunctionCallbackInfo<v8::Value>& args);
/// ZIP -----
void _zipOpenFile(const v8::FunctionCallbackInfo<v8::Value>& args);
void _zipOpenFileBase64(const v8::FunctionCallbackInfo<v8::Value>& args);
void _zipGetFileAsString(const v8::FunctionCallbackInfo<v8::Value>& args);
void _zipGetFileAsBinary(const v8::FunctionCallbackInfo<v8::Value>& args);
void _zipCloseFile(const v8::FunctionCallbackInfo<v8::Value>& args);
/// ---------
void _AddImageInChanges(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate);

View File

@ -42,15 +42,15 @@ int main(int argc, char *argv[])
#if 1
std::wstring strXml = L"<Settings>\
<SrcFileType>0</SrcFileType>\
<DstFileType>3</DstFileType>\
<SrcFilePath>D:\\DE_CAD4</SrcFilePath>\
<DstFilePath>D:\\DE_CAD4\\EditorWithChanges.bin</DstFilePath>\
<SrcFileType>1</SrcFileType>\
<DstFileType>1</DstFileType>\
<SrcFilePath>D:\\source</SrcFilePath>\
<DstFilePath>D:\\source\\EditorWithChanges.bin</DstFilePath>\
<FontsDirectory>D:\\activex\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\DesktopEditor\\ChromiumBasedEditors2\\app\\test\\src\\build\\win64\\Debug\\Local\\converter\\fonts\\</FontsDirectory>\
<ImagesDirectory>D:\\DE_CAD4\\media</ImagesDirectory>\
<ImagesDirectory>D:\\source\\media</ImagesDirectory>\
<ThemesDirectory>D:\\activex\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\Test\\Applications\\TestAVSOfficeDocxFile2\\TestAVSOfficeDocxFile2\\bin\\x86\\presentationthemes</ThemesDirectory>\
<Changes TopItem=\"-1\">\
<Change>D:\\DE_CAD4\\changes\\changes0.json</Change>\
<Change>D:\\source\\changes\\changes0.json</Change>\
</Changes>\
</Settings>";

View File

@ -709,6 +709,44 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory, bool bIsOnly
pBuffer += sizeof(SHORT);
}
#ifdef BUILD_FONT_NAMES_DICTIONARY
#include "ftsnames.h"
#include "tttables.h"
#include "ftxf86.h"
#include "internal/internal.h"
#include "internal/tttypes.h"
void CFontInfo::ReadNames(FT_Face pFace)
{
TT_Face pTT_Face = (TT_Face)(pFace);
names.clear();
if (NULL != pTT_Face)
{
for (int i = 0; i < pTT_Face->utf16_len; ++i)
{
std::wstring s(pTT_Face->utf16_names[i]);
if (s == m_wsFontName)
continue;
bool bIsPresent = false;
for (std::vector<std::wstring>::iterator i = names.begin(); i != names.end(); i++)
{
if (*i == s)
{
bIsPresent = true;
break;
}
}
if (!bIsPresent)
names.push_back(s);
}
}
}
#endif
///////////////////////////////////////////////////////////////////////////////////
namespace NSCharsets
{
@ -1583,6 +1621,10 @@ void CFontList::LoadFromArrayFiles(std::vector<std::wstring>& oArray, int nFlag)
shXHeight,
shCapHeight );
#ifdef BUILD_FONT_NAMES_DICTIONARY
pFontInfo->ReadNames(pFace);
#endif
Add(pFontInfo);
FT_Done_Face( pFace );
@ -1642,6 +1684,7 @@ void CFontList::Add(CFontInfo* pInfo)
return;
}
}
m_pList.Add(pInfo);
}

View File

@ -159,6 +159,12 @@ public:
SHORT m_shLineGap; // Межсимвольный интервал
SHORT m_shXHeight; // Высота буквы 'x' (в нижнем регистре)
SHORT m_shCapHeight; // Высота буквы 'H' (в верхнем регистре)
#ifdef BUILD_FONT_NAMES_DICTIONARY
std::vector<std::wstring> names;
void ReadNames(FT_Face pFace);
#endif
};
namespace NSCharsets

View File

@ -44,70 +44,7 @@
#include "../graphics/GraphicsRenderer.h"
#endif
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 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);
}
}
#include "./application_generate_fonts_common.h"
///////////////////////////////////////////////////////
//#define _GENERATE_FONT_MAP_
@ -116,55 +53,6 @@ namespace NSCommon
#include "../../freetype_names/FontMaps/FontDictionary.h"
#endif
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)
{
std::wstring::size_type nPos1 = sPath.rfind('\\');
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)
{
std::wstring::size_type nPos1 = sPath.rfind('\\');
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);
}
}
namespace NSCommon
{
class CFontInfoJS

View File

@ -0,0 +1,164 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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 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)
{
std::wstring::size_type nPos1 = sPath.rfind('\\');
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)
{
std::wstring::size_type nPos1 = sPath.rfind('\\');
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

@ -1,278 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
*
*/
#pragma once
#include "windows.h"
class CFile
{
public:
CFile()
{
m_hFileHandle = NULL;
m_lFileSize = 0;
m_lFilePosition = 0;
}
virtual ~CFile()
{
CloseFile();
}
virtual HRESULT OpenFile(CString FileName)
{
CloseFile();
HRESULT hRes = S_OK;
DWORD AccessMode = GENERIC_READ;
DWORD ShareMode = FILE_SHARE_READ;
DWORD Disposition = OPEN_EXISTING;
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
hRes = S_FALSE;
else
{
ULARGE_INTEGER nTempSize;
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
m_lFileSize = nTempSize.QuadPart;
SetPosition(0);
}
return hRes;
}
virtual HRESULT OpenFileRW(CString FileName)
{
CloseFile();
HRESULT hRes = S_OK;
DWORD AccessMode = GENERIC_READ | GENERIC_WRITE;
DWORD ShareMode = FILE_SHARE_READ;
DWORD Disposition = OPEN_EXISTING;
m_hFileHandle = ::CreateFile(FileName, AccessMode, ShareMode, NULL, Disposition, 0, 0);
if (NULL == m_hFileHandle || INVALID_HANDLE_VALUE == m_hFileHandle)
{
hRes = S_FALSE;
}
else
{
ULARGE_INTEGER nTempSize;
nTempSize.LowPart = ::GetFileSize(m_hFileHandle, &nTempSize.HighPart);
m_lFileSize = nTempSize.QuadPart;
SetPosition(0);
}
return hRes;
}
HRESULT ReadFile(BYTE* pData, DWORD nBytesToRead)
{
DWORD nBytesRead = 0;
if(NULL == pData)
return S_FALSE;
if(m_hFileHandle && (pData))
{
SetPosition(m_lFilePosition);
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
m_lFilePosition += nBytesRead;
}
return S_OK;
}
HRESULT ReadFile2(BYTE* pData, DWORD nBytesToRead)
{
DWORD nBytesRead = 0;
if(NULL == pData)
return S_FALSE;
if(m_hFileHandle && (pData))
{
SetPosition(m_lFilePosition);
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
m_lFilePosition += nBytesRead;
for (size_t index = 0; index < nBytesToRead / 2; ++index)
{
BYTE temp = pData[index];
pData[index] = pData[nBytesToRead - index - 1];
pData[nBytesToRead - index - 1] = temp;
}
}
return S_OK;
}
HRESULT ReadFile3(void* pData, DWORD nBytesToRead)
{
DWORD nBytesRead = 0;
if(NULL == pData)
return S_FALSE;
if(m_hFileHandle && (pData))
{
SetPosition(m_lFilePosition);
::ReadFile(m_hFileHandle, pData, nBytesToRead, &nBytesRead, NULL);
m_lFilePosition += nBytesRead;
}
return S_OK;
}
HRESULT WriteFile(void* pData, DWORD nBytesToWrite)
{
if(m_hFileHandle)
{
DWORD dwWritten = 0;
::WriteFile(m_hFileHandle, pData, nBytesToWrite, &dwWritten, NULL);
m_lFilePosition += nBytesToWrite;
}
return S_OK;
}
HRESULT WriteFile2(void* pData, DWORD nBytesToWrite)
{
if(m_hFileHandle)
{
BYTE* mem = new BYTE[nBytesToWrite];
memcpy(mem, pData, nBytesToWrite);
for (size_t index = 0; index < nBytesToWrite / 2; ++index)
{
BYTE temp = mem[index];
mem[index] = mem[nBytesToWrite - index - 1];
mem[nBytesToWrite - index - 1] = temp;
}
DWORD dwWritten = 0;
::WriteFile(m_hFileHandle, (void*)mem, nBytesToWrite, &dwWritten, NULL);
m_lFilePosition += nBytesToWrite;
delete[] mem;
}
return S_OK;
}
HRESULT CreateFile(CString strFileName)
{
CloseFile();
DWORD AccessMode = GENERIC_WRITE;
DWORD ShareMode = FILE_SHARE_WRITE;
DWORD Disposition = CREATE_ALWAYS;
m_hFileHandle = ::CreateFile(strFileName, AccessMode, ShareMode, NULL, Disposition, FILE_ATTRIBUTE_NORMAL, NULL);
return SetPosition(0);
}
HRESULT SetPosition( ULONG64 nPos )
{
if (m_hFileHandle && nPos < (ULONG)m_lFileSize)
{
LARGE_INTEGER nTempPos;
nTempPos.QuadPart = nPos;
::SetFilePointer(m_hFileHandle, nTempPos.LowPart, &nTempPos.HighPart, FILE_BEGIN);
m_lFilePosition = nPos;
return S_OK;
}
else
{
return (INVALID_HANDLE_VALUE == m_hFileHandle) ? S_FALSE : S_OK;
}
}
LONG64 GetPosition()
{
return m_lFilePosition;
}
HRESULT SkipBytes(ULONG64 nCount)
{
return SetPosition(m_lFilePosition + nCount);
}
HRESULT CloseFile()
{
m_lFileSize = 0;
m_lFilePosition = 0;
CloseHandle(m_hFileHandle);
m_hFileHandle = NULL;
return S_OK;
}
ULONG64 GetFileSize()
{
return m_lFileSize;
}
void WriteStringUTF8(CString& strXml)
{
int nLength = strXml.GetLength();
CStringA saStr;
#ifdef UNICODE
// Encoding Unicode to UTF-8
WideCharToMultiByte(CP_UTF8, 0, strXml.GetBuffer(), nLength + 1, saStr.GetBuffer(nLength*3 + 1), nLength*3, NULL, NULL);
saStr.ReleaseBuffer();
#else
wchar_t* pWStr = new wchar_t[nLength + 1];
if (!pWStr)
return;
// set end string
pWStr[nLength] = 0;
// Encoding ASCII to Unicode
MultiByteToWideChar(CP_ACP, 0, strXml, nLength, pWStr, nLength);
int nLengthW = (int)wcslen(pWStr);
// Encoding Unicode to UTF-8
WideCharToMultiByte(CP_UTF8, 0, pWStr, nLengthW + 1, saStr.GetBuffer(nLengthW*3 + 1), nLengthW*3, NULL, NULL);
saStr.ReleaseBuffer();
delete[] pWStr;
#endif
WriteFile((void*)saStr.GetBuffer(), saStr.GetLength());
}
LONG GetProgress()
{
if (0 >= m_lFileSize)
return -1;
double dVal = (double)(100 * m_lFilePosition);
LONG lProgress = (LONG)(dVal / m_lFileSize);
return lProgress;
}
protected:
HANDLE m_hFileHandle;
LONG64 m_lFileSize;
LONG64 m_lFilePosition;
};

View File

@ -32,34 +32,35 @@
// FontMaps.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "WinFont.h"
#include "File.h"
#include "../../common/File.h"
#include <algorithm>
#include "../../fontengine/ApplicationFonts.h"
#include "../../common/StringBuilder.h"
class CFontInfoJS
{
public:
CString m_sName;
std::wstring m_sName;
LONG m_lIndexR;
LONG m_lFaceIndexR;
CAtlArray<CString> namesR;
std::vector<std::wstring> namesR;
LONG m_lIndexI;
LONG m_lFaceIndexI;
CAtlArray<CString> namesI;
std::vector<std::wstring> namesI;
LONG m_lIndexB;
LONG m_lFaceIndexB;
CAtlArray<CString> namesB;
std::vector<std::wstring> namesB;
LONG m_lIndexBI;
LONG m_lFaceIndexBI;
CAtlArray<CString> namesBI;
std::vector<std::wstring> namesBI;
CFontInfoJS()
{
m_sName = _T("");
m_sName = L"";
m_lIndexR = -1;
m_lFaceIndexR = -1;
@ -90,119 +91,105 @@ public:
m_lFaceIndexB = oSrc.m_lFaceIndexB;
m_lFaceIndexBI = oSrc.m_lFaceIndexBI;
namesR.RemoveAll();
namesR.Copy(oSrc.namesR);
namesR.clear();
namesR = oSrc.namesR;
namesI.RemoveAll();
namesI.Copy(oSrc.namesI);
namesI.clear();
namesI = oSrc.namesI;
namesB.RemoveAll();
namesB.Copy(oSrc.namesB);
namesB.clear();
namesB = oSrc.namesB;
namesBI.RemoveAll();
namesBI.Copy(oSrc.namesBI);
namesBI.clear();
namesBI = oSrc.namesBI;
return *this;
}
};
int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char* argv[])
{
FT_Library pLibrary = NULL;
//CString strFolder = _T("\\\\mediaserver\\Exchange\\Korshul\\Fonts");
CString strFolder = _T("X:\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\DesktopEditor\\freetype_names\\FontsDictionaryFiles");
CWinFontList* m_pList = NULL;
CApplicationFonts oFonts;
oFonts.InitializeFromFolder(L"D:\\onlyoffice_trunk\\fonts\\all");
//oFonts.Initialize();
if (!FT_Init_FreeType( &pLibrary ))
{
if (_T("") == strFolder)
m_pList = new CWinFontList(pLibrary);
else
m_pList = new CWinFontList(pLibrary, strFolder);
std::wstring strFontDictionaryPath = L"D:\\GIT\\core\\DesktopEditor\\freetype_names\\FontMaps\\FontDictionary.h";
FT_Done_FreeType( pLibrary );
}
CString strFontDictionaryPath = _T("X:\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\DesktopEditor\\freetype_names\\FontMaps\\FontDictionary.h");
int nCount = m_pList->GetFonts()->GetLength();
int nCount = oFonts.GetList()->GetFonts()->GetCount();
// теперь строим массив всех шрифтов по имени
CAtlMap<CString, CFontInfoJS> mapFonts;
CAtlMap<CString, CFontInfoJS> mapFontsUnicodes;
CAtlArray<CString> arrFonts;
CAtlArray<CString> arrFontsUnicodes;
std::map<std::wstring, CFontInfoJS> mapFonts;
std::map<std::wstring, CFontInfoJS> mapFontsUnicodes;
std::vector<std::wstring> arrFonts;
std::vector<std::wstring> arrFontsUnicodes;
int nError = 0;
CAtlMap<CString, BOOL> mapMainAscii;
std::map<std::wstring, bool> mapMainAscii;
for (int i = 0; i < nCount; ++i)
{
CWinFontInfo* pInfo = (CWinFontInfo*)m_pList->GetByIndex(i);
CString strPath = (CString)pInfo->m_wsFontPath;
CString strName = (CString)pInfo->m_wsFontName;
CFontInfo* pInfo = oFonts.GetList()->GetFonts()->operator [](i);
std::wstring strPath = pInfo->m_wsFontPath;
std::wstring strName = pInfo->m_wsFontName;
LONG lFontIndex = 0;
LONG lFaceIndex = 0;
//CAtlMap<CString, LONG>::CPair* pPairFontFiles = mapFontFiles.Lookup(strPath);
//lFontIndex = pPairFontFiles->m_value;
lFontIndex = (LONG)i;
if (pInfo->m_lIndex >= 0)
lFaceIndex = pInfo->m_lIndex;
mapMainAscii.SetAt(pInfo->m_wsFontName, TRUE);
mapMainAscii.insert(std::pair<std::wstring, bool>(pInfo->m_wsFontName, true));
CAtlMap<CString, CFontInfoJS>::CPair* pPair = mapFonts.Lookup(pInfo->m_wsFontName);
if (NULL != pPair)
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(pInfo->m_wsFontName);
if (mapFonts.end() != pPair)
{
pPair->m_value.m_sName = pInfo->m_wsFontName;
pPair->second.m_sName = pInfo->m_wsFontName;
if (pInfo->m_bBold && pInfo->m_bItalic)
{
if (-1 != pPair->m_value.m_lIndexBI)
if (-1 != pPair->second.m_lIndexBI)
nError++;
pPair->m_value.m_lIndexBI = lFontIndex;
pPair->m_value.m_lFaceIndexBI = lFaceIndex;
pPair->second.m_lIndexBI = lFontIndex;
pPair->second.m_lFaceIndexBI = lFaceIndex;
pPair->m_value.namesBI.RemoveAll();
pPair->m_value.namesBI.Copy(pInfo->names);
pPair->second.namesBI.clear();
pPair->second.namesBI = pInfo->names;
}
else if (pInfo->m_bBold)
{
if (-1 != pPair->m_value.m_lIndexB)
if (-1 != pPair->second.m_lIndexB)
nError++;
pPair->m_value.m_lIndexB = lFontIndex;
pPair->m_value.m_lFaceIndexB = lFaceIndex;
pPair->second.m_lIndexB = lFontIndex;
pPair->second.m_lFaceIndexB = lFaceIndex;
pPair->m_value.namesB.RemoveAll();
pPair->m_value.namesB.Copy(pInfo->names);
pPair->second.namesB.clear();
pPair->second.namesB = pInfo->names;
}
else if (pInfo->m_bItalic)
{
if (-1 != pPair->m_value.m_lIndexI)
if (-1 != pPair->second.m_lIndexI)
nError++;
pPair->m_value.m_lIndexI = lFontIndex;
pPair->m_value.m_lFaceIndexI = lFaceIndex;
pPair->second.m_lIndexI = lFontIndex;
pPair->second.m_lFaceIndexI = lFaceIndex;
pPair->m_value.namesI.RemoveAll();
pPair->m_value.namesI.Copy(pInfo->names);
pPair->second.namesI.clear();
pPair->second.namesI = pInfo->names;
}
else
{
if (-1 != pPair->m_value.m_lIndexR)
if (-1 != pPair->second.m_lIndexR)
nError++;
pPair->m_value.m_lIndexR = lFontIndex;
pPair->m_value.m_lFaceIndexR = lFaceIndex;
pPair->second.m_lIndexR = lFontIndex;
pPair->second.m_lFaceIndexR = lFaceIndex;
pPair->m_value.namesR.RemoveAll();
pPair->m_value.namesR.Copy(pInfo->names);
pPair->second.namesR.clear();
pPair->second.namesR = pInfo->names;
}
}
else
@ -216,70 +203,68 @@ int _tmain(int argc, _TCHAR* argv[])
fontInfo.m_lIndexBI = lFontIndex;
fontInfo.m_lFaceIndexBI = lFaceIndex;
fontInfo.namesBI.RemoveAll();
fontInfo.namesBI.Copy(pInfo->names);
fontInfo.namesBI.clear();
fontInfo.namesBI = pInfo->names;
}
else if (pInfo->m_bBold)
{
fontInfo.m_lIndexB = lFontIndex;
fontInfo.m_lFaceIndexB = lFaceIndex;
fontInfo.namesB.RemoveAll();
fontInfo.namesB.Copy(pInfo->names);
fontInfo.namesB.clear();
fontInfo.namesB = pInfo->names;
}
else if (pInfo->m_bItalic)
{
fontInfo.m_lIndexI = lFontIndex;
fontInfo.m_lFaceIndexI = lFaceIndex;
fontInfo.namesI.RemoveAll();
fontInfo.namesI.Copy(pInfo->names);
fontInfo.namesI.clear();
fontInfo.namesI = pInfo->names;
}
else
{
fontInfo.m_lIndexR = lFontIndex;
fontInfo.m_lFaceIndexR = lFaceIndex;
fontInfo.namesR.RemoveAll();
fontInfo.namesR.Copy(pInfo->names);
fontInfo.namesR.clear();
fontInfo.namesR = pInfo->names;
}
mapFonts.SetAt(fontInfo.m_sName, fontInfo);
arrFonts.Add(fontInfo.m_sName);
mapFonts.insert(std::pair<std::wstring, CFontInfoJS>(fontInfo.m_sName, fontInfo));
arrFonts.push_back(fontInfo.m_sName);
}
}
// additional names
for (int i = 0; i < nCount; ++i)
{
CWinFontInfo* pInfo = (CWinFontInfo*)m_pList->GetByIndex(i);
CString strPath = (CString)pInfo->m_wsFontPath;
CString strName = (CString)pInfo->m_wsFontName;
CFontInfo* pInfo = oFonts.GetList()->GetFonts()->operator [](i);
std::wstring strPath = pInfo->m_wsFontPath;
std::wstring strName = pInfo->m_wsFontName;
LONG lFontIndex = 0;
LONG lFaceIndex = 0;
//CAtlMap<CString, LONG>::CPair* pPairFontFiles = mapFontFiles.Lookup(strPath);
//lFontIndex = pPairFontFiles->m_value;
lFontIndex = (LONG)i;
if (pInfo->m_lIndex >= 0)
lFaceIndex = pInfo->m_lIndex;
int nNamesAdditional = pInfo->names.GetCount();
int nNamesAdditional = pInfo->names.size();
for (int j = 0; j < nNamesAdditional; ++j)
{
CString strNameA = pInfo->names[j];
std::wstring strNameA = pInfo->names[j];
CAtlMap<CString, BOOL>::CPair* pPairMain = mapMainAscii.Lookup(strNameA);
if (NULL != pPairMain)
std::map<std::wstring, bool>::iterator pPairMain = mapMainAscii.find(strNameA);
if (mapMainAscii.end() != pPairMain)
continue;
WCHAR* pBufferA = strNameA.GetBuffer();
int len = strNameA.GetLength();
const wchar_t* pBufferA = strNameA.c_str();
int len = strNameA.length();
CAtlMap<CString, CFontInfoJS>* pMap = &mapFonts;
CAtlArray<CString>* pArrFonts = &arrFonts;
std::map<std::wstring, CFontInfoJS>* pMap = &mapFonts;
std::vector<std::wstring>* pArrFonts = &arrFonts;
for (int k = 0; k < len; ++k)
{
@ -291,54 +276,54 @@ int _tmain(int argc, _TCHAR* argv[])
}
}
CAtlMap<CString, CFontInfoJS>::CPair* pPair = pMap->Lookup(strNameA);
if (NULL != pPair)
std::map<std::wstring, CFontInfoJS>::iterator pPair = pMap->find(strNameA);
if (pMap->end() != pPair)
{
pPair->m_value.m_sName = strNameA;
pPair->second.m_sName = strNameA;
if (pInfo->m_bBold && pInfo->m_bItalic)
{
if (-1 != pPair->m_value.m_lIndexBI)
if (-1 != pPair->second.m_lIndexBI)
nError++;
pPair->m_value.m_lIndexBI = lFontIndex;
pPair->m_value.m_lFaceIndexBI = lFaceIndex;
pPair->second.m_lIndexBI = lFontIndex;
pPair->second.m_lFaceIndexBI = lFaceIndex;
pPair->m_value.namesBI.RemoveAll();
pPair->m_value.namesBI.Copy(pInfo->names);
pPair->second.namesBI.clear();
pPair->second.namesBI = pInfo->names;
}
else if (pInfo->m_bBold)
{
if (-1 != pPair->m_value.m_lIndexB)
if (-1 != pPair->second.m_lIndexB)
nError++;
pPair->m_value.m_lIndexB = lFontIndex;
pPair->m_value.m_lFaceIndexB = lFaceIndex;
pPair->second.m_lIndexB = lFontIndex;
pPair->second.m_lFaceIndexB = lFaceIndex;
pPair->m_value.namesB.RemoveAll();
pPair->m_value.namesB.Copy(pInfo->names);
pPair->second.namesB.clear();
pPair->second.namesB = pInfo->names;
}
else if (pInfo->m_bItalic)
{
if (-1 != pPair->m_value.m_lIndexI)
if (-1 != pPair->second.m_lIndexI)
nError++;
pPair->m_value.m_lIndexI = lFontIndex;
pPair->m_value.m_lFaceIndexI = lFaceIndex;
pPair->second.m_lIndexI = lFontIndex;
pPair->second.m_lFaceIndexI = lFaceIndex;
pPair->m_value.namesI.RemoveAll();
pPair->m_value.namesI.Copy(pInfo->names);
pPair->second.namesI.clear();
pPair->second.namesI = pInfo->names;
}
else
{
if (-1 != pPair->m_value.m_lIndexR)
if (-1 != pPair->second.m_lIndexR)
nError++;
pPair->m_value.m_lIndexR = lFontIndex;
pPair->m_value.m_lFaceIndexR = lFaceIndex;
pPair->second.m_lIndexR = lFontIndex;
pPair->second.m_lFaceIndexR = lFaceIndex;
pPair->m_value.namesR.RemoveAll();
pPair->m_value.namesR.Copy(pInfo->names);
pPair->second.namesR.clear();
pPair->second.namesR = pInfo->names;
}
}
else
@ -352,137 +337,93 @@ int _tmain(int argc, _TCHAR* argv[])
fontInfo.m_lIndexBI = lFontIndex;
fontInfo.m_lFaceIndexBI = lFaceIndex;
fontInfo.namesBI.RemoveAll();
fontInfo.namesBI.Copy(pInfo->names);
fontInfo.namesBI.clear();
fontInfo.namesBI = pInfo->names;
}
else if (pInfo->m_bBold)
{
fontInfo.m_lIndexB = lFontIndex;
fontInfo.m_lFaceIndexB = lFaceIndex;
fontInfo.namesB.RemoveAll();
fontInfo.namesB.Copy(pInfo->names);
fontInfo.namesB.clear();
fontInfo.namesB = pInfo->names;
}
else if (pInfo->m_bItalic)
{
fontInfo.m_lIndexI = lFontIndex;
fontInfo.m_lFaceIndexI = lFaceIndex;
fontInfo.namesI.RemoveAll();
fontInfo.namesI.Copy(pInfo->names);
fontInfo.namesI.clear();
fontInfo.namesI = pInfo->names;
}
else
{
fontInfo.m_lIndexR = lFontIndex;
fontInfo.m_lFaceIndexR = lFaceIndex;
fontInfo.namesR.RemoveAll();
fontInfo.namesR.Copy(pInfo->names);
fontInfo.namesR.clear();
fontInfo.namesR = pInfo->names;
}
pMap->SetAt(fontInfo.m_sName, fontInfo);
pArrFonts->Add(fontInfo.m_sName);
pMap->insert(std::pair<std::wstring, CFontInfoJS>(fontInfo.m_sName, fontInfo));
pArrFonts->push_back(fontInfo.m_sName);
}
}
}
// -------------------------------------------
// теперь сортируем шрифты по имени ----------
size_t nCountFonts = arrFonts.GetCount();
for (size_t i = 0; i < nCountFonts; ++i)
{
for (size_t j = i + 1; j < nCountFonts; ++j)
{
if (arrFonts[i] > arrFonts[j])
{
CString temp = arrFonts[i];
arrFonts[i] = arrFonts[j];
arrFonts[j] = temp;
}
}
}
size_t nCountFonts = arrFonts.size();
std::sort(arrFonts.begin(), arrFonts.end());
size_t nCountFontsU = arrFontsUnicodes.GetCount();
for (size_t i = 0; i < nCountFontsU; ++i)
{
for (size_t j = i + 1; j < nCountFontsU; ++j)
{
if (arrFontsUnicodes[i] > arrFontsUnicodes[j])
{
CString temp = arrFontsUnicodes[i];
arrFontsUnicodes[i] = arrFontsUnicodes[j];
arrFontsUnicodes[j] = temp;
}
}
}
size_t nCountFontsU = arrFontsUnicodes.size();
std::sort(arrFontsUnicodes.begin(), arrFontsUnicodes.end());
#if 0
CFile oFile;
oFile.CreateFile(_T("c:\\fonts.txt"));
BYTE bom[3];
bom[0] = 0xEF;
bom[1] = 0xBB;
bom[2] = 0xBF;
oFile.WriteFile((void*)&bom, 3);
CString strInfos = _T("");
for (int index = 0; index < nCountFonts; ++index)
{
const CAtlMap<CString, CFontInfoJS>::CPair* pPair = mapFonts.Lookup(arrFonts[index]);
CString strFontInfo = pPair->m_value.m_sName + _T(": [");
for (size_t i = 0; i < pPair->m_value.namesR.GetCount(); ++i)
{
strFontInfo += pPair->m_value.namesR[i];
strFontInfo += _T(",");
}
strFontInfo += _T(";");
for (size_t i = 0; i < pPair->m_value.namesI.GetCount(); ++i)
{
strFontInfo += pPair->m_value.namesI[i];
strFontInfo += _T(",");
}
strFontInfo += _T(";");
for (size_t i = 0; i < pPair->m_value.namesB.GetCount(); ++i)
{
strFontInfo += pPair->m_value.namesB[i];
strFontInfo += _T(",");
}
strFontInfo += _T(";");
for (size_t i = 0; i < pPair->m_value.namesBI.GetCount(); ++i)
{
strFontInfo += pPair->m_value.namesBI[i];
strFontInfo += _T(",");
}
strFontInfo += _T("]\n");
strInfos += strFontInfo;
}
oFile.WriteStringUTF8(strInfos);
oFile.CloseFile();
#endif
CFile oFileW;
NSFile::CFileBinary oFileW;
oFileW.CreateFile(strFontDictionaryPath);
BYTE bom[3];
bom[0] = 0xEF;
bom[1] = 0xBB;
bom[2] = 0xBF;
oFileW.WriteFile((void*)&bom, 3);
oFileW.WriteFile(bom, 3);
CString strAll = _T("");
NSStringUtils::CStringBuilder oBuilder;
CString strConstant1 = _T("#ifndef _FONT_DICTIONARY_H\n\n\
oBuilder.WriteString(L"\
/*\n\
* (c) Copyright Ascensio System SIA 2010-2017\n\
*\n\
* This program is a free software product. You can redistribute it and/or\n\
* modify it under the terms of the GNU Affero General Public License (AGPL)\n\
* version 3 as published by the Free Software Foundation. In accordance with\n\
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect\n\
* that Ascensio System SIA expressly excludes the warranty of non-infringement\n\
* of any third-party rights.\n\
*\n\
* This program is distributed WITHOUT ANY WARRANTY; without even the implied\n\
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For\n\
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html\n\
*\n\
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,\n\
* EU, LV-1021.\n\
*\n\
* The interactive user interfaces in modified source and object code versions\n\
* of the Program must display Appropriate Legal Notices, as required under\n\
* Section 5 of the GNU AGPL version 3.\n\
*\n\
* Pursuant to Section 7(b) of the License you must retain the original Product\n\
* logo when distributing the program. Pursuant to Section 7(e) we decline to\n\
* grant you any rights under trademark law for use of our trademarks.\n\
*\n\
* All the Product's GUI elements, including illustrations and icon sets, as\n\
* well as technical writing content are licensed under the terms of the\n\
* Creative Commons Attribution-ShareAlike 4.0 International. See the License\n\
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode\n\
*\n\
*/\n");
oBuilder.WriteString(L"#ifndef _FONT_DICTIONARY_H\n\n\
typedef struct FD_FontMapRec_\n\
{\n\
const char* m_name;\n\
@ -502,40 +443,45 @@ typedef struct FD_FontMapRecW_\n\
int m_index_bi;\n\
} FD_FontMapRecW;\n\n");
strAll += strConstant1;
int nAsciiNamesCount = (int)arrFonts.GetCount();
CString sAsciiNames = _T("");
sAsciiNames.Format(_T("#define FONTS_DICT_ASCII_NAMES_COUNT %d\n"), nAsciiNamesCount);
sAsciiNames += _T("static const FD_FontMapRec FD_Ascii_Names[FONTS_DICT_ASCII_NAMES_COUNT] = \n{\n");
int nAsciiNamesCount = (int)arrFonts.size();
oBuilder.WriteString(L"#define FONTS_DICT_ASCII_NAMES_COUNT ");
oBuilder.AddInt(nAsciiNamesCount);
oBuilder.WriteString(L"\n");
oBuilder.WriteString(L"static const FD_FontMapRec FD_Ascii_Names[FONTS_DICT_ASCII_NAMES_COUNT] = \n{\n");
for (int k = 0; k < nAsciiNamesCount; ++k)
{
CAtlMap<CString, CFontInfoJS>::CPair* pPair = mapFonts.Lookup(arrFonts[k]);
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[k]);
sAsciiNames += _T("\t{ \"");
sAsciiNames += pPair->m_value.m_sName;
sAsciiNames += _T("\", ");
CString strP = _T("");
oBuilder.WriteString(L"\t{ \"");
oBuilder.WriteString(pPair->second.m_sName);
oBuilder.WriteString(L"\", ");
if (k != (nAsciiNamesCount - 1))
{
strP.Format(_T("%d, %d, %d, %d },\n"), pPair->m_value.m_lIndexR,
pPair->m_value.m_lIndexI, pPair->m_value.m_lIndexB, pPair->m_value.m_lIndexBI);
oBuilder.AddInt(pPair->second.m_lIndexR);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexI);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexB);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexBI);
oBuilder.WriteString(L" },\n");
}
else
{
strP.Format(_T("%d, %d, %d, %d }\n"), pPair->m_value.m_lIndexR,
pPair->m_value.m_lIndexI, pPair->m_value.m_lIndexB, pPair->m_value.m_lIndexBI);
oBuilder.AddInt(pPair->second.m_lIndexR);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexI);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexB);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexBI);
oBuilder.WriteString(L" }\n");
}
sAsciiNames += strP;
}
sAsciiNames += _T("};\n\n");
strAll += sAsciiNames;
oBuilder.WriteString(L"};\n\n");
int _offsets[256];
for (int t = 0; t < 256; ++t)
@ -544,7 +490,7 @@ typedef struct FD_FontMapRecW_\n\
int nCurChar = -1;
for (int k = 0; k < nAsciiNamesCount; ++k)
{
int nChar = (int)arrFonts[k].GetAt(0);
int nChar = (int)arrFonts[k].c_str()[0];
nChar = max(0, min(nChar, 255));
if (nChar != nCurChar)
@ -554,66 +500,70 @@ typedef struct FD_FontMapRecW_\n\
nCurChar = nChar;
}
CString strAsciiOffsets = _T("static const int FD_Ascii_Names_Offsets[256] =\n{\n");
oBuilder.WriteString(L"static const int FD_Ascii_Names_Offsets[256] =\n{\n");
for (int k = 0; k < 256; ++k)
{
CString sMem = _T("");
sMem.Format(_T("%d"), _offsets[k]);
std::wstring sMem = std::to_wstring(_offsets[k]);
while (sMem.GetLength() < 4)
sMem = (_T(" ") + sMem);
while (sMem.length() < 4)
sMem = (L" " + sMem);
if (0 == k % 32)
sMem = _T("\t") + sMem;
sMem = L"\t" + sMem;
if (k != 255)
sMem += _T(",");
sMem += L",";
if (0 == (k + 1) % 32)
sMem += _T("\n");
sMem += L"\n";
strAsciiOffsets += sMem;
oBuilder.WriteString(sMem);
}
strAsciiOffsets += _T("};\n\n");
oBuilder.WriteString(L"};\n\n");
strAll += strAsciiOffsets;
int nUnicodeNamesCount = (int)arrFontsUnicodes.GetCount();
CString sUnicodeNames = _T("");
sUnicodeNames.Format(_T("#define FONTS_DICT_UNICODE_NAMES_COUNT %d\n"), nUnicodeNamesCount);
sUnicodeNames += _T("static const FD_FontMapRecW FD_Unicode_Names[FONTS_DICT_UNICODE_NAMES_COUNT] = \n{\n");
int nUnicodeNamesCount = (int)arrFontsUnicodes.size();
oBuilder.WriteString(L"#define FONTS_DICT_UNICODE_NAMES_COUNT ");
oBuilder.AddInt(nUnicodeNamesCount);
oBuilder.WriteString(L"\n");
oBuilder.WriteString(L"static const FD_FontMapRecW FD_Unicode_Names[FONTS_DICT_UNICODE_NAMES_COUNT] = \n{\n");
for (int k = 0; k < nUnicodeNamesCount; ++k)
{
CAtlMap<CString, CFontInfoJS>::CPair* pPair = mapFontsUnicodes.Lookup(arrFontsUnicodes[k]);
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFontsUnicodes.find(arrFontsUnicodes[k]);
sUnicodeNames += _T("\t{ L\"");
sUnicodeNames += pPair->m_value.m_sName;
sUnicodeNames += _T("\", ");
CString strP = _T("");
oBuilder.WriteString(L"\t{ L\"");
oBuilder.WriteString(pPair->second.m_sName);
oBuilder.WriteString(L"\", ");
if (k != (nAsciiNamesCount - 1))
{
strP.Format(_T("%d, %d, %d, %d },\n"), pPair->m_value.m_lIndexR,
pPair->m_value.m_lIndexI, pPair->m_value.m_lIndexB, pPair->m_value.m_lIndexBI);
oBuilder.AddInt(pPair->second.m_lIndexR);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexI);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexB);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexBI);
oBuilder.WriteString(L" },\n");
}
else
{
strP.Format(_T("%d, %d, %d, %d }\n"), pPair->m_value.m_lIndexR,
pPair->m_value.m_lIndexI, pPair->m_value.m_lIndexB, pPair->m_value.m_lIndexBI);
oBuilder.AddInt(pPair->second.m_lIndexR);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexI);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexB);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pPair->second.m_lIndexBI);
oBuilder.WriteString(L" }\n");
}
sUnicodeNames += strP;
}
sUnicodeNames += _T("};\n\n");
oBuilder.WriteString(L"};\n\n");
strAll += sUnicodeNames;
CString strConstant2 = _T("typedef struct FD_Font_Rec\n\
oBuilder.WriteString(L"typedef struct FD_Font_Rec\n\
{\n\
const char* m_name;\n\
\n\
@ -646,81 +596,107 @@ typedef struct FD_FontMapRecW_\n\
short m_shCapHeight;\n\
} FD_Font;\n\n");
strAll += strConstant2;
int nAllFontsCount = (int)nCount;
CString sAllFontsNames = _T("");
sAllFontsNames.Format(_T("#define FONTS_DICT_ASCII_FONTS_COUNT %d\n"), nCount);
sAllFontsNames += _T("static const FD_Font FD_Ascii_Files[FONTS_DICT_ASCII_FONTS_COUNT] = \n{\n");
oBuilder.WriteString(L"#define FONTS_DICT_ASCII_FONTS_COUNT ");
oBuilder.AddInt(nCount);
oBuilder.WriteString(L"\n");
oBuilder.WriteString(L"static const FD_Font FD_Ascii_Files[FONTS_DICT_ASCII_FONTS_COUNT] = \n{\n");
for (int k = 0; k < nCount; ++k)
{
CWinFontInfo* pInfo = (CWinFontInfo*)m_pList->GetByIndex(k);
CFontInfo* pInfo = oFonts.GetList()->GetFonts()->operator [](k);
#if 1
// CORRECT!!!
if (pInfo->m_wsFontName == _T("Monotype Sorts"))
if (pInfo->m_wsFontName == L"Monotype Sorts")
pInfo->m_aPanose[0] = 5;
#endif
CString sMem = _T("");
sMem.Format(_T("\", %d, %d, %d, %d, { %d, %d, %d, %d, %d, %d, %d, %d, %d, %d }, %u, %u, %u, %u, %u, %u, %u, %u, %d, %d, %d, %d, %d, %d, %d, %d }"),
pInfo->m_lIndex,
pInfo->m_bBold,
pInfo->m_bItalic,
pInfo->m_bIsFixed,
pInfo->m_aPanose[0],
pInfo->m_aPanose[1],
pInfo->m_aPanose[2],
pInfo->m_aPanose[3],
pInfo->m_aPanose[4],
pInfo->m_aPanose[5],
pInfo->m_aPanose[6],
pInfo->m_aPanose[7],
pInfo->m_aPanose[8],
pInfo->m_aPanose[9],
pInfo->m_ulUnicodeRange1,
pInfo->m_ulUnicodeRange2,
pInfo->m_ulUnicodeRange3,
pInfo->m_ulUnicodeRange4,
pInfo->m_ulCodePageRange1,
pInfo->m_ulCodePageRange2,
pInfo->m_usWeigth,
pInfo->m_usWidth,
pInfo->m_sFamilyClass,
pInfo->m_eFontFormat,
pInfo->m_shAvgCharWidth,
pInfo->m_shAscent,
pInfo->m_shDescent,
pInfo->m_shLineGap,
pInfo->m_shXHeight,
pInfo->m_shCapHeight);
sAllFontsNames += _T("\t{\"");
sAllFontsNames += pInfo->m_wsFontName;
sAllFontsNames += sMem;
oBuilder.WriteString(L"\t{\"");
oBuilder.WriteString(pInfo->m_wsFontName);
oBuilder.WriteString(L"\", ");
oBuilder.AddInt(pInfo->m_lIndex);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_bBold);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_bItalic);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_bIsFixed);
oBuilder.WriteString(L", { ");
oBuilder.AddInt(pInfo->m_aPanose[0]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[1]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[2]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[3]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[4]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[5]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[6]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[7]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[8]);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_aPanose[9]);
oBuilder.WriteString(L" }, ");
oBuilder.AddInt64((__int64)pInfo->m_ulUnicodeRange1);
oBuilder.WriteString(L", ");
oBuilder.AddInt64((__int64)pInfo->m_ulUnicodeRange2);
oBuilder.WriteString(L", ");
oBuilder.AddInt64((__int64)pInfo->m_ulUnicodeRange3);
oBuilder.WriteString(L", ");
oBuilder.AddInt64((__int64)pInfo->m_ulUnicodeRange4);
oBuilder.WriteString(L", ");
oBuilder.AddInt64((__int64)pInfo->m_ulCodePageRange1);
oBuilder.WriteString(L", ");
oBuilder.AddInt64((__int64)pInfo->m_ulCodePageRange2);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_usWeigth);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_usWidth);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_sFamilyClass);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_eFontFormat);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shAvgCharWidth);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shAscent);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shDescent);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shLineGap);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shXHeight);
oBuilder.WriteString(L", ");
oBuilder.AddInt(pInfo->m_shCapHeight);
oBuilder.WriteString(L" }");
if (k != (nCount - 1))
sAllFontsNames += _T(",\n");
oBuilder.WriteString(L",\n");
else
sAllFontsNames += _T("\n");
oBuilder.WriteString(L"\n");
}
sAllFontsNames += _T("};\n\n");
oBuilder.WriteString(L"};\n\n");
strAll += sAllFontsNames;
oBuilder.WriteString(L"// error : ");
oBuilder.AddInt(nError);
oBuilder.WriteString(L"\n\n");
oBuilder.WriteString(L"#endif /* _FONT_DICTIONARY_H */");
CString strError = _T("");
strError.Format(_T("// error : %d\n\n"), nError);
strAll += strError;
strAll += _T("#endif /* _FONT_DICTIONARY_H */");
oFileW.WriteStringUTF8(strAll);
oFileW.WriteStringUTF8(oBuilder.GetData());
oFileW.CloseFile();
if (NULL != m_pList)
delete m_pList;
return 0;
return 0;
}

View File

@ -1,20 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual C++ Express 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FontMaps", "FontMaps.vcproj", "{841E1A33-234B-4C2B-97EB-1D6785A26DA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{841E1A33-234B-4C2B-97EB-1D6785A26DA9}.Debug|Win32.ActiveCfg = Debug|Win32
{841E1A33-234B-4C2B-97EB-1D6785A26DA9}.Debug|Win32.Build.0 = Debug|Win32
{841E1A33-234B-4C2B-97EB-1D6785A26DA9}.Release|Win32.ActiveCfg = Release|Win32
{841E1A33-234B-4C2B-97EB-1D6785A26DA9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -1,262 +0,0 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="FontMaps"
ProjectGUID="{841E1A33-234B-4C2B-97EB-1D6785A26DA9}"
RootNamespace="FontMaps"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
UseOfATL="1"
ATLMinimizesCRunTimeLibraryUsage="true"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../freetype-2.5.3/include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib $(NoInherit)"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib $(NoInherit)"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\FontMaps.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\File.h"
>
</File>
<File
RelativePath=".\FontDictionary.h"
>
</File>
<File
RelativePath=".\FontDictionaryWorker.h"
>
</File>
<File
RelativePath=".\FontUtils.h"
>
</File>
<File
RelativePath=".\List.h"
>
</File>
<File
RelativePath=".\ShareMemArray.h"
>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\WinFont.h"
>
</File>
<File
RelativePath=".\WinFontStorage.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,258 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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 _FONT_UTILS_H
#define _FONT_UTILS_H
#include FT_SFNT_NAMES_H
#define fabs(X) ( X >= 0 ? X : -X )
namespace FontConstants
{
enum FontStyle
{
FontStyleRegular = 0,
FontStyleBold = 1,
FontStyleItalic = 2,
FontStyleBoldItalic = 3,
FontStyleUnderline = 4,
FontStyleStrikeout = 8
};
}
#define UNKNOWN_CHARSET 3 // для случаев, когда задано значение DEFAULT_CHARSET, но
// на самом деле charset не учитывается
//---------------------------------------------------------------------------------------------------
#define MAX_FONT_CACHE_SIZE 16
#define MAX_FONT_NAME_LEN 50
#define MAX_FONT_STYLE_LEN 40
static long GetNextNameValue(HKEY key, LPCTSTR pszSubkey, LPTSTR pszName, LPTSTR pszData)
{
static HKEY hkey = NULL; // registry handle, kept open between calls
static DWORD dwIndex = 0; // count of values returned
LONG retval;
// if all parameters are NULL then close key
if (pszSubkey == NULL && pszName == NULL && pszData == NULL)
{
if (hkey)
RegCloseKey(hkey);
hkey = NULL;
return ERROR_SUCCESS;
}
// if subkey is specified then open key (first time)
if (pszSubkey && pszSubkey[0] != 0)
{
retval = RegOpenKeyEx(key, pszSubkey, 0, KEY_READ, &hkey);
if (retval != ERROR_SUCCESS)
{
return retval;
}
dwIndex = 0;
}
else
{
dwIndex++;
}
_ASSERTE(pszName != NULL && pszData != NULL);
*pszName = 0;
*pszData = 0;
TCHAR szValueName[MAX_PATH];
DWORD dwValueNameSize = sizeof(szValueName)-1;
BYTE szValueData[MAX_PATH];
DWORD dwValueDataSize = sizeof(szValueData)-1;
DWORD dwType = 0;
retval = RegEnumValue(hkey, dwIndex, szValueName, &dwValueNameSize, NULL,
&dwType, szValueData, &dwValueDataSize);
if (retval == ERROR_SUCCESS)
{
lstrcpy(pszName, (LPTSTR)szValueName);
lstrcpy(pszData, (LPTSTR)szValueData);
}
return retval;
}
static FT_Error FT_New_FaceW(FT_Library pLibrary, wchar_t *wsFilePath, FT_Long lIndex, FT_Face *pFace)
{
USES_CONVERSION;
FT_Open_Args oOpenArgs;
oOpenArgs.flags = FT_OPEN_PATHNAME;
oOpenArgs.pathname = W2A( wsFilePath );
FT_Parameter *pParams = (FT_Parameter *)::malloc( sizeof(FT_Parameter) * 4 );
pParams[0].tag = FT_MAKE_TAG( 'i', 'g', 'p', 'f' );
pParams[0].data = NULL;
pParams[1].tag = FT_MAKE_TAG( 'i', 'g', 'p', 's' );
pParams[1].data = NULL;
pParams[2].tag = FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY;
pParams[2].data = NULL;
pParams[3].tag = FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY;
pParams[3].data = NULL;
oOpenArgs.num_params = 4;
oOpenArgs.params = pParams;
int nError = FT_Open_Face( pLibrary, &oOpenArgs, lIndex, pFace );
::free( pParams );
return nError;
}
static int GetDefaultCharset(BOOL bUseDefCharset = TRUE)
{
if ( !bUseDefCharset )
return UNKNOWN_CHARSET;
LOCALESIGNATURE LocSig;
GetLocaleInfo( GetSystemDefaultLCID(), LOCALE_FONTSIGNATURE, (LPWSTR)&LocSig, sizeof(LocSig) / sizeof(TCHAR) );
if ( LocSig.lsCsbDefault[0] & 1 )
return 0;
else if ( LocSig.lsCsbDefault[0] & 2 )
return 238;
else if ( LocSig.lsCsbDefault[0] & 4 )
return 204;
else if ( LocSig.lsCsbDefault[0] & 8 )
return 161;
else if ( LocSig.lsCsbDefault[0] & 16 )
return 162;
else if ( LocSig.lsCsbDefault[0] & 32 )
return 177;
else if ( LocSig.lsCsbDefault[0] & 64 )
return 178;
else if ( LocSig.lsCsbDefault[0] & 128 )
return 186;
else if ( LocSig.lsCsbDefault[0] & 256 )
return 163;
else if ( LocSig.lsCsbDefault[0] & 0x10000 )
return 222;
else if ( LocSig.lsCsbDefault[0] & 0x20000 )
return 128;
else if ( LocSig.lsCsbDefault[0] & 0x40000 )
return 134;
else if ( LocSig.lsCsbDefault[0] & 0x80000 )
return 129;
else if ( LocSig.lsCsbDefault[0] & 0x100000 )
return 136;
else if ( LocSig.lsCsbDefault[0] & 0x200000 )
return 130;
else if ( LocSig.lsCsbDefault[0] & 0x20000000 )
return 77;
else if ( LocSig.lsCsbDefault[0] & 0x40000000 )
return 255;
else if ( LocSig.lsCsbDefault[0] & 0x80000000 )
return 2;
return 0;
}
static void GetCodePageByCharset(unsigned char unCharset, unsigned long *pulBit, unsigned int *punLongIndex)
{
// Данная функция возвращает параметры, которые нужно посылать на вход
// функции AVSFontManager::IsUnicodeRangeAvailable
// Соответствие Charset -> Codepage: http://support.microsoft.com/kb/165478
// http://msdn.microsoft.com/en-us/library/cc194829.aspx
// Charset Name Charset Value(hex) Codepage number
// ------------------------------------------------------
//
// DEFAULT_CHARSET 1 (x01)
// SYMBOL_CHARSET 2 (x02)
// OEM_CHARSET 255 (xFF)
// ANSI_CHARSET 0 (x00) 1252
// RUSSIAN_CHARSET 204 (xCC) 1251
// EASTEUROPE_CHARSET 238 (xEE) 1250
// GREEK_CHARSET 161 (xA1) 1253
// TURKISH_CHARSET 162 (xA2) 1254
// BALTIC_CHARSET 186 (xBA) 1257
// HEBREW_CHARSET 177 (xB1) 1255
// ARABIC _CHARSET 178 (xB2) 1256
// SHIFTJIS_CHARSET 128 (x80) 932
// HANGEUL_CHARSET 129 (x81) 949
// GB2313_CHARSET 134 (x86) 936
// CHINESEBIG5_CHARSET 136 (x88) 950
// THAI_CHARSET 222 (xDE) 874
// JOHAB_CHARSET 130 (x82) 1361
// VIETNAMESE_CHARSET 163 (xA3) 1258
// MAC_CHARSET 77 (x4D)
// Соответсвие CodePage -> ulCodePageRange1 : http://www.microsoft.com/Typography/otspec/os2.htm#cpr
if ( punLongIndex )
*punLongIndex = 4;
if ( unCharset == DEFAULT_CHARSET )
unCharset = GetDefaultCharset();
if ( pulBit )
{
switch( unCharset )
{
case 0x00: *pulBit = 0; break;
case 0xEE: *pulBit = 1; break;
case 0xCC: *pulBit = 2; break;
case 0xA1: *pulBit = 3; break;
case 0xA2: *pulBit = 4; break;
case 0xB1: *pulBit = 5; break;
case 0xB2: *pulBit = 6; break;
case 0xBA: *pulBit = 7; break;
case 0xA3: *pulBit = 8; break;
case 0xDE: *pulBit = 16; break;
case 0x80: *pulBit = 17; break;
case 0x86: *pulBit = 18; break;
case 0x81: *pulBit = 19; break;
case 0x88: *pulBit = 20; break;
case 0x82: *pulBit = 21; break;
case 0x4D: *pulBit = 29; break;
case 0x02: *pulBit = 31; break;
case 0xFF: *pulBit = 30; break;
default: *pulBit = 0; break;
}
}
}
#endif /* _FONT_UTILS_H */

View File

@ -1,180 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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 _LIST_H
#define _LIST_H
//------------------------------------------------------------------------
// CList
//------------------------------------------------------------------------
class CList
{
public:
// Создаем пустой список.
CList()
{
m_nItemSize = 8;
m_ppData = (void **)::malloc( m_nItemSize * sizeof(void*) );
m_nCount = 0;
m_nIncreament = 0;
}
// Создаем пустой список с с выделенной памятью под <nSize> элементов.
CList(int nSize)
{
m_nItemSize = nSize;
m_ppData = (void **)::malloc( m_nItemSize * sizeof(void*) );
m_nCount = 0;
m_nIncreament = 0;
}
// Деструктор.
~CList()
{
if ( m_ppData )
::free( m_ppData );
}
int GetLength()
{
return m_nCount;
}
// Возвращает <nIndex>Ый элемент.
// Если 0 <= nIndex < m_nCount, возвращает NULL.
void *GetByIndex(int nIndex)
{
if ( nIndex < 0 || nIndex >= m_nCount )
return NULL;
return m_ppData[ nIndex ];
}
// Добавляем элемент в окнец списка.
void Append(void *pItem)
{
if ( m_nCount >= m_nItemSize )
Expand();
m_ppData[m_nCount++] = pItem;
}
// Добавляем другой список в конец данного.
void Append(CList *pList)
{
while ( m_nCount + pList->m_nCount > m_nItemSize )
Expand();
for (int nIndex = 0; nIndex < pList->m_nCount; ++nIndex )
m_ppData[m_nCount++] = pList->m_ppData[ nIndex ];
}
// Вставляем элемент на место <nIndex>.
// Если !(0 <= nIndex <= m_nCount), ничего не делаем.
void Insert(int nIndex, void *pItem)
{
if ( 0 > nIndex || nIndex > m_nCount )
return;
if ( m_nCount >= m_nItemSize )
Expand();
if ( nIndex < m_nCount )
memmove( m_ppData + nIndex + 1, m_ppData + nIndex, ( m_nCount - nIndex ) * sizeof(void *));
m_ppData[ nIndex ] = pItem;
++m_nCount;
}
// Удаляем из списка и возвращаем ссылку на элемент.
// Если !(0 <= nIndex <= m_nCount), ничего не делаем.
void *Delete(int nIndex)
{
void *pItem = m_ppData[ nIndex ];
if ( nIndex < m_nCount - 1 )
memmove( m_ppData + nIndex, m_ppData + nIndex + 1, (m_nCount - nIndex - 1) * sizeof(void *));
--m_nCount;
if ( m_nItemSize - m_nCount >= ((m_nIncreament > 0) ? m_nIncreament : m_nItemSize / 2 ) )
Shrink();
return pItem;
}
// Сортируем список, в соответствии с данной функцией
// сранвения.
void Sort(int (*CompareFunc)(const void *pItem1, const void *pItem2 ) )
{
qsort( m_ppData, m_nCount, sizeof(void *), CompareFunc);
}
// Если m_nIncreament > 0, тогда при расширении списка ровно
// m_nIncreament элементов будет добавляться. Если m_nIncreament <= 0,
// тогда список будем удваивать при расширении.
void SetAllocationIncreament(int nIncreament)
{
m_nIncreament = nIncreament;
}
private:
void Expand()
{
m_nItemSize += ( m_nIncreament > 0 ) ? m_nIncreament : m_nItemSize;
m_ppData = (void **)::realloc( m_ppData, m_nItemSize * sizeof(void*) );
}
void Shrink()
{
m_nItemSize -= ( m_nIncreament > 0 ) ? m_nIncreament : m_nItemSize / 2;
m_ppData = (void **)::realloc( m_ppData, m_nItemSize * sizeof(void*) );
}
private:
void **m_ppData; // список элементов
int m_nItemSize; // размер данных в массиве
int m_nCount; // количестов элементов в списке
int m_nIncreament; // на сколько будем увеличивать список
};
#define DeleteCList(list, T) \
do { \
CList *_list = (list); \
{ \
int _i; \
for (_i = 0; _i < _list->GetLength(); ++_i) { \
delete (T*)_list->GetByIndex(_i); \
} \
delete _list; \
} \
} while (0)
#endif /* _LIST_H */

View File

@ -1,33 +0,0 @@
========================================================================
CONSOLE APPLICATION : FontMaps Project Overview
========================================================================
AppWizard has created this FontMaps application for you.
This file contains a summary of what you will find in each of the files that
make up your FontMaps application.
FontMaps.vcproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
FontMaps.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named FontMaps.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

View File

@ -1,345 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
*
*/
/***************************************************************
CShareMemArray
шаблон класса для работы с именованной
Shared-памятью. Реализаваны загрузка массива
из памяти и сохранение в память.
***************************************************************/
#pragma once
#pragma warning( disable : 4996 4244) // No CRT-secure warning
#include <atlcoll.h>
#include "../../../Common/ASCUtils.h" // CSyncAccess class definition
#define AVS_USER_NAME_LEN 1024
// Статус хранилища (ошибка, уже создано, новое)
enum TSMAStatus {SMAS_ERROR, SMAS_ALREADYEXISTS, SMAS_NEW};
// Хранилище
template <typename STOR_TYPE>
class CShareMemArray
{
protected:
HANDLE m_hAccessMutex; // Мьютекс для безопасного доступа к Shared-Memory
HANDLE m_hMapFile; // Хендл на map таблицы
STOR_TYPE *m_pArray; // Указатель на массив
LONG64 m_nSize; // Размер таблицы
CString m_sMutexName; // Имя мьютекса
CString m_sMapName; // Имя маппа
TSMAStatus m_sStatus;
protected:
// Читаем из памяти
bool ReadFromSharedMem(LONG64 nIndex, STOR_TYPE &nValue)
{
if (NULL == m_pArray)
{
m_sStatus = SMAS_ERROR;
return false;
}
__try
{
STOR_TYPE *pTable = (STOR_TYPE *) (((BYTE *) m_pArray) + sizeof(LONG64)); // sizeof(LONG64) - размер таблицы
nValue = pTable[nIndex];
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
ATLTRACE2("CIndexerStorage::ReadFromSharedMem()\n");
return false;
}
return true;
}
// Пишем в память
bool WriteToSharedMem(LONG64 nIndex, STOR_TYPE aValue)
{
if (NULL == m_pArray)
{
m_sStatus = SMAS_ERROR;
return false;
}
__try
{
STOR_TYPE *pTable = (STOR_TYPE *) (((BYTE *) m_pArray) + sizeof(LONG64)); // sizeof(LONG64) - размер таблицы
pTable[nIndex] = aValue;
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
ATLTRACE2("Error CIndexerStorage::WriteToSharedMem(#i)\n", nIndex);
return false;
}
return true;
}
// Загрузка таблицы индексов из SharedMemory
bool SaveTable_unsync(CAtlArray<STOR_TYPE> &aTable)
{
if ((NULL == m_pArray) || (NULL == m_hMapFile))
{
m_sStatus = SMAS_ERROR;
return false; // Защита от дурака
}
bool bRes = true;
// Защита от дурака
LONG64 nCopyCount = (m_nSize <= (LONG64) aTable.GetCount()) ? m_nSize : aTable.GetCount();
// Сохраняем размер таблицы
Size_unsync(m_nSize);
// копируем из памяти в массив (safe)
for (LONG64 nIndex = 0; nIndex < nCopyCount; nIndex++)
{
bRes &= WriteToSharedMem (nIndex, aTable[nIndex]);
}
return bRes;
}
// Сохранение таблицы индексов из SharedMemory
bool LoadTable_unsync(CAtlArray<STOR_TYPE> &aTable)
{
if ((NULL == m_pArray) || (NULL == m_hMapFile))
{
m_sStatus = SMAS_ERROR;
return false; // Защита от дурака
}
aTable.RemoveAll();
// Определяем размер
m_nSize = Size_unsync();
STOR_TYPE nValue;
// копируем из памяти в массив
for (DWORD nIndex = 0; nIndex < m_nSize; nIndex++)
{
if (ReadFromSharedMem(nIndex, nValue))
{
// Добавляем в таблицу
aTable.Add(nValue);
}
}
return true;
}
// Размер
LONG64 Size_unsync()
{
LONG64 nValue = -1;
if (NULL == m_pArray)
{
m_sStatus = SMAS_ERROR;
return nValue;
}
__try
{
LONG64 *pSize = (LONG64 *) m_pArray;
nValue = *pSize;
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
ATLTRACE2("CIndexerStorage::Size_unsync()\n");
return -1;
}
return nValue;
}
void Size_unsync(LONG64 aSize)
{
if (NULL == m_pArray)
{
m_sStatus = SMAS_ERROR;
return;
}
__try
{
LONG64 *pSize = (LONG64*) m_pArray; // sizeof(LONG64) - размер таблицы
*pSize = aSize;
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
ATLTRACE2("Error CIndexerStorage::Size_unsync(LONG64 aSize)\n");
}
}
public:
// aSize - размер таблицы индексации (кол-во полусекунд),
// Id - дополнительный идектификатор, чтоб можно было создавать много сторейджей для одного файла
CShareMemArray(CString &aFileName, LONG64 aSize, DWORD aId = ISID_DEFAULT):
m_hMapFile(NULL), m_nSize(aSize), m_pArray(NULL), m_sStatus(SMAS_ERROR)
{
// "Вытаскиваем" имя файла
TCHAR aDrive[_MAX_DRIVE];
TCHAR aDir[_MAX_DIR];
TCHAR aFName[_MAX_FNAME];
TCHAR aExt[_MAX_EXT];
_tsplitpath (aFileName.GetBuffer(), aDrive, aDir, aFName, aExt);
//_wsplitpath_s (aFileName.GetBuffer(), aDrive, _MAX_DRIVE, aDir, _MAX_DIR, aFName, _MAX_FNAME, aExt, _MAX_EXT);
// Дополнительно формируем уникальные символы для этого пути, чтобы включить в имя файла
DWORD dwPathID = 0;
TCHAR tcPathIDItem = 0;
// Подсчитываем контрольную сумму для пути
for (int i = 0; i < (int) _tcslen(aDir); i++)
{
tcPathIDItem ^= aDir[i];
dwPathID ^= dwPathID << 1;
dwPathID += (DWORD) tcPathIDItem;
}
// Подсчитываем контрольную сумму для расширения
DWORD dwExtID = 0;
TCHAR tcExtIDItem = 0;
for (int i = 0; i < (int) _tcslen(aExt); i++)
{
tcExtIDItem ^= aExt[i];
dwExtID ^= dwExtID << 1;
dwExtID += (DWORD) tcExtIDItem;
}
// Формируем имя мутекса и мапа
// Этот код не работает если зашло два пользователя и каждый запускает свою копию приложения.
// Фича в именовании мьютекса.
// В начале имени мьютекса должно стоять "Global\"
// ШульгаИван: "Global\" не проходит на Win7, если прога запущена не под админом
m_sMutexName.Format(_T("Local\\avs_mutex%u_%s_%06x_%06I64x_%06x"), aId, aFName, dwPathID, aSize, dwExtID);
m_sMapName.Format(_T("Local\\avs_storage%u_%s_%06x_%06I64x_%06x"), aId, aFName, dwPathID, aSize, dwExtID);
// добавляем имя юзера
TCHAR pBufferUserName[AVS_USER_NAME_LEN];
DWORD dwBufferUserNameLen = AVS_USER_NAME_LEN;
GetUserName(pBufferUserName, &dwBufferUserNameLen);
CString strUserName(pBufferUserName, dwBufferUserNameLen);
m_sMutexName += strUserName;
m_sMapName += strUserName;
// Создаем мьютекс
m_hAccessMutex = CreateMutex(NULL, FALSE, m_sMutexName.GetBuffer());
// Далее все делаем "под мутексом" :)
CSynchAccess oAccess = m_hAccessMutex;
// Создаем мап
ATLTRACE2("CShareMemArray()::CShareMemArray(): m_nSize = %d\n", m_nSize);
ULARGE_INTEGER nMappingSize;
nMappingSize.QuadPart = m_nSize * sizeof(STOR_TYPE) + sizeof(LONG64);
m_hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, nMappingSize.HighPart, nMappingSize.LowPart, m_sMapName.GetBuffer());
if (NULL == m_hMapFile)
{
// Ошибка
ATLTRACE2("CShareMemArray::CShareMemArray():CreateFileMapping() FAILS (0x%x)!\n", GetLastError());
m_sStatus = SMAS_ERROR;
}
else
{
// Все ок!
m_sStatus = (GetLastError() == ERROR_ALREADY_EXISTS) ? SMAS_ALREADYEXISTS : SMAS_NEW;
ATLTRACE2 (SMAS_ALREADYEXISTS == m_sStatus ? "CShareMemArray: open existing!\n" : "CShareMemArray: create new!\n");
// создаем View of file
m_pArray = (STOR_TYPE *) MapViewOfFile(m_hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, (SIZE_T) nMappingSize.QuadPart);
if (NULL == m_pArray)
{
// Ошибка
ATLTRACE2("CShareMemArray::CShareMemArray():MapViewOfFile() FAILS (0x%x)!\n", GetLastError());
m_sStatus = SMAS_ERROR;
}
}
}
virtual ~CShareMemArray()
{
if (m_pArray) UnmapViewOfFile(m_pArray); // удаляем view
if (NULL != m_hMapFile) CloseHandle(m_hMapFile); // удаляем мап
if (NULL != m_hAccessMutex) CloseHandle(m_hAccessMutex); // Удаляем мьютекс
}
public:
// Сохранить таблицу в шаред-мемори
bool Save(CAtlArray<STOR_TYPE> &aTable)
{
CSynchAccess oAccess = m_hAccessMutex;
return SaveTable_unsync(aTable);
}
// Загрузить таблицу
bool Load(CAtlArray<STOR_TYPE> &aTable)
{
CSynchAccess oAccess = m_hAccessMutex;
return LoadTable_unsync(aTable);
}
// Размер получение
LONG64 Size()
{
CSynchAccess oAccess = m_hAccessMutex;
return Size_unsync();
}
/*void Size(LONG64 aSize)
{
CSynchAccess oAccess = m_hAccessMutex;
Size_unsync(aSize);
}*/
// Получение статуса
TSMAStatus Status(void) const
{
CSynchAccess oAccess = m_hAccessMutex;
return m_sStatus;
}
};

File diff suppressed because it is too large Load Diff

View File

@ -1,408 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
*
*/
#pragma once
#include "../../../Common/ShareMemArray.h"
// Идентификаторы хранилищ
#define ISID_DEFAULT 0x0000 // По умолчанию
#define ISID_WIN_FONT_STATUS_STORAGE 0x0001 // Таблица для статуса
#define ISID_WIN_FONT_INFO_STORAGE 0x0002 // Таблица для Информации
// Макс. длина имени таблицы
#define STORAGE_TABLE_NAME_LEN 1024
#define STATUS_STORAGE_NAME CString( _T("AVS_LOADED_WIN_FONTS") )
namespace NSStrings
{
static CString ConvertCStringWToCString(CStringW& strW)
{
BSTR bstr = strW.AllocSysString();
CString str(bstr);
SysFreeString(bstr);
return str;
}
static CStringW GetCStringWFromUTF8( BYTE* pBuffer, LONG64 lCount )
{
LONG64 lLenght = 0;
CStringW strRes = L"";
for (LONG lIndex = 0; lIndex < lCount; ++lIndex)
{
if (0x00 == (0x80 & pBuffer[lIndex]))
{
strRes += (WCHAR)pBuffer[lIndex];
continue;
}
else if (0x00 == (0x20 & pBuffer[lIndex]))
{
WCHAR mem = (WCHAR)(((pBuffer[lIndex] & 0x1F) << 6) + (pBuffer[lIndex + 1] & 0x3F));
strRes += mem;
lIndex += 1;
}
else if (0x00 == (0x10 & pBuffer[lIndex]))
{
WCHAR mem = (WCHAR)(((pBuffer[lIndex] & 0x0F) << 12) + ((pBuffer[lIndex + 1] & 0x3F) << 6) + (pBuffer[lIndex + 2] & 0x3F));
strRes += mem;
lIndex += 2;
}
}
return strRes;
}
static CString GetCStringFromUTF8( BYTE* pBuffer, LONG64 lCount )
{
CStringW strRes = GetCStringWFromUTF8(pBuffer, lCount);
return ConvertCStringWToCString(strRes);
}
};
// статус таблицы установленных шрифтов
enum WinFontsTableStatus {STIF_ERROR, STIF_AVAILABLE, STIF_CREATING, STIF_BROKEN};
enum StringCoding
{
scASCII = 0,
scUNICODE = 1,
scUTF8 = 2
};
// Структура для определения статуса таблицы хранилища
struct WinFontsStatusStorage
{
// Общие данные
WinFontsTableStatus m_sStatus; // Статус
LONG64 m_lLength; // Размер таблицы
WinFontsStatusStorage()
{
Reset();
}
void Reset()
{
// Общие данные
m_sStatus = STIF_ERROR; // Статус
m_lLength = 0;
}
};
// Структура для определения информации
struct WinFontsInfoStorage
{
LONG m_lCount;
CStringA m_strXml;
BYTE* m_pBuffer;
LONG m_lCountData;
WinFontsInfoStorage()
{
Reset();
}
~WinFontsInfoStorage()
{
}
void Reset()
{
m_lCount = 0;
m_strXml = "";
m_pBuffer = NULL;
}
void GenerateInfo(BSTR bstrXML)
{
m_strXml = CStringA(bstrXML);
m_pBuffer = NULL;
m_lCountData = 0;
}
void GenerateInfo(BYTE* pBuffer, LONG lCountData)
{
m_pBuffer = pBuffer;
m_lCountData = lCountData;
}
void Save(BYTE* pBuffer)
{
if (NULL == pBuffer)
return;
if (0 == m_lCountData)
{
memcpy(pBuffer, (BYTE*)m_strXml.GetBuffer(), m_strXml.GetLength());
}
else
{
memcpy(pBuffer, m_pBuffer, m_lCountData);
}
}
LONG64 GetLength()
{
if (0 == m_lCountData)
{
return m_strXml.GetLength();
}
return m_lCountData;
}
void Load(BYTE* pBuffer, LONG64 lLength)
{
//m_pBuffer = pBuffer;
m_lCountData = (LONG)lLength;
m_pBuffer = new BYTE[m_lCountData];
memcpy(m_pBuffer, pBuffer, m_lCountData);
}
};
// Класс хранилища таблицы статуса
class CWinFontsStatusStorage: public CShareMemArray<BYTE>
{
protected:
bool ReadStruct_unsync(WinFontsStatusStorage *aData) // Прочитать структуру unsync
{
__try
{
WinFontsStatusStorage *pTable = (WinFontsStatusStorage *) ( (BYTE *)m_pArray + sizeof(LONG64)); // sizeof(LONG64) - размер таблицы
memcpy(aData, pTable, sizeof(WinFontsStatusStorage));
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
//ATLTRACE2("CStatusStorage::ReadStruct_unsync() fails!\n");
return false;
}
return true;
}
bool WriteStruct_unsync(WinFontsStatusStorage *aData) // Записать структуру unsync
{
__try
{
WinFontsStatusStorage *pTable = (WinFontsStatusStorage *) ( (BYTE *)m_pArray + sizeof(LONG64)); // sizeof(LONG64) - размер таблицы
memcpy(pTable, aData, sizeof(WinFontsStatusStorage));
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
//ATLTRACE2("CStatusStorage::ReadStruct_unsync() fails!\n");
return false;
}
return true;
}
public:
bool ReadStruct(WinFontsStatusStorage *aData)
{
CSynchAccess oAccess = m_hAccessMutex;
return ReadStruct_unsync(aData);
}
bool WriteStruct(WinFontsStatusStorage *aData)
{
CSynchAccess oAccess = m_hAccessMutex;
return WriteStruct_unsync(aData);
}
public:
// Получить статус индексатора (bForceControl - Попытаться стать мастером, если получится)
// возвращаем *bForceControl == true - вызывающий объект стал мастером
bool GetStatus(bool *bForceControl, WinFontsStatusStorage* aIS)
{
bool bTryToForceControl = bForceControl && (*bForceControl);
if (NULL == aIS) return false;
if (bForceControl) *bForceControl = false; // Пока мы не можем стать мастером
// Делаем все под мутексом :)
CSynchAccess oAccess = m_hAccessMutex;
if (!ReadStruct_unsync(aIS)) return false; // Не получилось прочитать статус
if ((STIF_BROKEN == aIS->m_sStatus) || (STIF_ERROR == aIS->m_sStatus))
{
// Таблица нарушена - говорим, что можно стать мастером (если нужно было)
if (bTryToForceControl)
{
// Сбрасываем таблицу
aIS->Reset();
aIS->m_sStatus = STIF_CREATING;
*bForceControl = WriteStruct_unsync(aIS); // пишем в память и говорим, что стали мастером
}
}
return true;
}
// Установить статус, как нарушенное хранилище. Мастерство может перехватываться другими объектами
bool SetBroken()
{
CSynchAccess oAccess = m_hAccessMutex;
WinFontsStatusStorage sStor;
sStor.m_sStatus = STIF_BROKEN;
// Пишем в ш-память
return WriteStruct_unsync(&sStor);
}
private:
// Скрываем методы работы с массивами
bool Save(CAtlArray<BYTE> &aTable)
{
return false;
}
bool Load(CAtlArray<BYTE> &aTable)
{
return false;
}
public:
CWinFontsStatusStorage(CString &aName): CShareMemArray(aName, sizeof(WinFontsStatusStorage), ISID_WIN_FONT_STATUS_STORAGE)
{
// Параметр aName должен быть AVS_LOAD_WIN_FONTS
//ATLTRACE2("CStatusStorage created;\n");
};
~CWinFontsStatusStorage()
{
//ATLTRACE2("CStatusStorage destroyed;\n");
};
};
// Класс хранилища таблицы информации
class CWinFontsInfoStorage: public CShareMemArray<BYTE>
{
protected:
bool ReadStruct_unsync(WinFontsInfoStorage *aData) // Прочитать структуру unsync
{
__try
{
LONG64 lLength = Size();
aData->Load((BYTE*)m_pArray + sizeof(LONG64), lLength); // sizeof(LONG64) - размер таблицы
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
//ATLTRACE2("CStatusStorage::ReadStruct_unsync() fails!\n");
return false;
}
return true;
}
bool WriteStruct_unsync(WinFontsInfoStorage *aData) // Записать структуру unsync
{
__try
{
LONG64 *pSize = (LONG64*)m_pArray;
*pSize = m_nSize;
aData->Save((BYTE*)m_pArray + sizeof(LONG64)); // sizeof(LONG64) - размер таблицы
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
//ATLTRACE2("CStatusStorage::ReadStruct_unsync() fails!\n");
return false;
}
return true;
}
public:
bool ReadStruct(WinFontsInfoStorage *aData)
{
//CSynchAccess oAccess = m_hAccessMutex;
return ReadStruct_unsync(aData);
}
bool WriteStruct(WinFontsInfoStorage *aData)
{
CSynchAccess oAccess = m_hAccessMutex;
return WriteStruct_unsync(aData);
}
bool WriteCount(WinFontsInfoStorage *aData)
{
__try
{
BYTE* pData = (BYTE*)m_pArray + sizeof(LONG64);
*((LONG*)pData) = aData->m_lCount;
}
__except(EXCEPTION_IN_PAGE_ERROR == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
// Failed to read from the view.
//ATLTRACE2("CWinFontsInfoStorage::ReadStruct_unsync() fails!\n");
return false;
}
return true;
}
private:
// Скрываем методы работы с массивами
bool Save(CAtlArray<BYTE> &aTable)
{
return false;
}
bool Load(CAtlArray<BYTE> &aTable)
{
return false;
}
public:
CWinFontsInfoStorage(CString &aFileName, LONG64 lSize): CShareMemArray(aFileName, lSize, ISID_WIN_FONT_INFO_STORAGE)
{
//ATLTRACE2("CWinFontsInfoStorage created;\n");
};
~CWinFontsInfoStorage()
{
//ATLTRACE2("CWinFontsInfoStorage destroyed;\n");
};
};

View File

@ -1,316 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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 _FONT_DICTIONARY_WORKER_H
#include "FontDictionary.h"
namespace NSFontDictionary
{
static bool CorrectParamsFromDictionary(CString& wsFamily, BOOL& bBold, BOOL& bItalic, BOOL& bFixedWidth, BYTE* pPanose,
ULONG& ulRange1, ULONG& ulRange2, ULONG& ulRange3, ULONG& ulRange4, ULONG& ulCodeRange1, ULONG& ulCodeRange2,
USHORT& usWeight, USHORT& usWidth, SHORT& sFamilyClass,
SHORT& shAvgCharWidth, SHORT& shAscent, SHORT& shDescent, SHORT& shLineGap, SHORT& shXHeight, SHORT& shCapHeight,
BOOL& bIsStyle, BOOL& bIsFixed, BOOL& bIsPanose, BOOL& bIsRanges,
BOOL& bIsWeight, BOOL& bIsWidth, BOOL& bIsFamilyClass,
BOOL& bIsAvgWidth, BOOL& bIsAscent, BOOL& bIsDescent, BOOL& bIsLineGap, BOOL& bIsXHeight, BOOL& bIsCapHeight)
{
int nNameLen = wsFamily.GetLength();
if (nNameLen == 0)
return false;
bool bIsAscii = true;
wchar_t* pName = wsFamily.GetBuffer();
for (int i = 0; i < nNameLen; ++i)
{
if (pName[i] > 255 || pName[i] < 0)
{
bIsAscii = false;
break;
}
}
const FD_Font* pFont = NULL;
if (bIsAscii)
{
int nStartIndex = FD_Ascii_Names_Offsets[pName[0]];
if (-1 != nStartIndex)
{
int nIndex = -1;
for (int i = nStartIndex; i < FONTS_DICT_ASCII_NAMES_COUNT; ++i)
{
const char* _name = FD_Ascii_Names[i].m_name;
if (pName[0] != (wchar_t)_name[0])
break;
bool bIsEqual = true;
for (int j = 1; j < nNameLen; ++j)
{
if ('\0' == _name[j] && j != (nNameLen - 1))
{
bIsEqual = false;
break;
}
if (pName[j] != (wchar_t)_name[j])
{
bIsEqual = false;
break;
}
}
if (bIsEqual)
{
nIndex = i;
break;
}
}
if (nIndex != -1)
{
const FD_FontMapRec* pRec = &FD_Ascii_Names[nIndex];
int nFontIndex = -1;
int nStyle = 0;
if (bIsStyle && bItalic)
nStyle |= 1;
if (bIsStyle && bBold)
nStyle |= 2;
switch (nStyle)
{
case 1:
{
if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else
nFontIndex = pRec->m_index_b;
break;
}
case 2:
{
if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else
nFontIndex = pRec->m_index_i;
break;
}
case 3:
{
if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else
nFontIndex = pRec->m_index_r;
break;
}
case 0:
default:
{
if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else
nFontIndex = pRec->m_index_bi;
break;
}
}
if (nFontIndex != -1)
pFont = &FD_Ascii_Files[nFontIndex];
}
}
}
else
{
int nIndex = -1;
for (int i = 0; i < FONTS_DICT_UNICODE_NAMES_COUNT; ++i)
{
const wchar_t* _name = FD_Unicode_Names[i].m_name;
if (pName[0] != _name[0])
continue;
bool bIsEqual = true;
for (int j = 1; j < nNameLen; ++j)
{
if (((wchar_t)'\0') == _name[j] && j != (nNameLen - 1))
{
bIsEqual = false;
break;
}
if (pName[j] != _name[j])
{
bIsEqual = false;
break;
}
}
if (bIsEqual)
{
nIndex = i;
break;
}
}
if (nIndex != -1)
{
const FD_FontMapRecW* pRec = &FD_Unicode_Names[nIndex];
int nFontIndex = -1;
int nStyle = 0;
if (bIsStyle && bItalic)
nStyle |= 1;
if (bIsStyle && bBold)
nStyle |= 2;
switch (nStyle)
{
case 1:
{
if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else
nFontIndex = pRec->m_index_b;
break;
}
case 2:
{
if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else
nFontIndex = pRec->m_index_i;
break;
}
case 3:
{
if (pRec->m_index_bi != -1)
nFontIndex = pRec->m_index_bi;
else if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else
nFontIndex = pRec->m_index_r;
break;
}
case 0:
default:
{
if (pRec->m_index_r != -1)
nFontIndex = pRec->m_index_r;
else if (pRec->m_index_i != -1)
nFontIndex = pRec->m_index_i;
else if (pRec->m_index_b != -1)
nFontIndex = pRec->m_index_b;
else
nFontIndex = pRec->m_index_bi;
break;
}
}
if (nFontIndex != -1)
pFont = &FD_Ascii_Files[nFontIndex];
}
}
if (NULL == pFont)
return false;
// name - делаем ascii, чтобы сработал подбор
wsFamily = (CString(pFont->m_name));
// fixed
bIsFixed = TRUE;
bFixedWidth = pFont->m_bIsFixed == 1 ? TRUE : FALSE;
// panose
bIsPanose = TRUE;
memcpy(pPanose, pFont->m_aPanose, 10);
// ranges
bIsRanges = TRUE;
ulRange1 = pFont->m_ulUnicodeRange1;
ulRange2 = pFont->m_ulUnicodeRange2;
ulRange3 = pFont->m_ulUnicodeRange3;
ulRange4 = pFont->m_ulUnicodeRange4;
ulCodeRange1 = pFont->m_ulCodePageRange1;
ulCodeRange2 = pFont->m_ulCodePageRange2;
bIsWeight = TRUE;
bIsWeight = pFont->m_usWeigth;
bIsWidth = TRUE;
usWidth = pFont->m_usWidth;
bIsAvgWidth = TRUE;
shAvgCharWidth = pFont->m_shAvgCharWidth;
bIsAscent = TRUE;
shAscent = pFont->m_shAscent;
bIsDescent = TRUE;
shDescent = pFont->m_shDescent;
bIsXHeight = TRUE;
shXHeight = pFont->m_shXHeight;
bIsCapHeight = TRUE;
shCapHeight = pFont->m_shCapHeight;
return true;
}
}
#endif /* _FONT_DICTIONARY_WORKER_H */

View File

@ -0,0 +1,60 @@
QT -= core gui
TARGET = freetype
TEMPLATE = lib
CONFIG += staticlib
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include(../../../../Common/base.pri)
FREETYPE_LIB_PATH=$$PWD/../../freetype-2.5.3
INCLUDEPATH += \
$$FREETYPE_LIB_PATH/include
DEFINES += \
FT2_BUILD_LIBRARY
DESTDIR=$$PWD/../build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX
SOURCES += \
$$FREETYPE_LIB_PATH/src/base/ftbbox.c \
$$FREETYPE_LIB_PATH/src/base/ftgxval.c \
$$FREETYPE_LIB_PATH/src/base/ftlcdfil.c \
$$FREETYPE_LIB_PATH/src/base/ftmm.c \
$$FREETYPE_LIB_PATH/src/base/ftotval.c \
$$FREETYPE_LIB_PATH/src/base/ftpatent.c \
$$FREETYPE_LIB_PATH/src/base/ftpfr.c \
$$FREETYPE_LIB_PATH/src/base/ftsynth.c \
$$FREETYPE_LIB_PATH/src/base/fttype1.c \
$$FREETYPE_LIB_PATH/src/base/ftwinfnt.c \
$$FREETYPE_LIB_PATH/src/base/ftxf86.c \
$$FREETYPE_LIB_PATH/src/pcf/pcf.c \
$$FREETYPE_LIB_PATH/src/pfr/pfr.c \
$$FREETYPE_LIB_PATH/src/psaux/psaux.c \
$$FREETYPE_LIB_PATH/src/pshinter/pshinter.c \
$$FREETYPE_LIB_PATH/src/psnames/psmodule.c \
$$FREETYPE_LIB_PATH/src/raster/raster.c \
$$FREETYPE_LIB_PATH/src/sfnt/sfnt.c \
$$FREETYPE_LIB_PATH/src/truetype/truetype.c \
$$FREETYPE_LIB_PATH/src/type1/type1.c \
$$FREETYPE_LIB_PATH/src/cid/type1cid.c \
$$FREETYPE_LIB_PATH/src/type42/type42.c \
$$FREETYPE_LIB_PATH/src/winfonts/winfnt.c \
\
$$FREETYPE_LIB_PATH/src/autofit/autofit.c \
$$FREETYPE_LIB_PATH/src/bdf/bdf.c \
$$FREETYPE_LIB_PATH/src/cff/cff.c \
$$FREETYPE_LIB_PATH/src/base/ftbase.c \
$$FREETYPE_LIB_PATH/src/base/ftbitmap.c \
$$FREETYPE_LIB_PATH/src/cache/ftcache.c \
$$FREETYPE_LIB_PATH/src/base/ftfstype.c \
$$FREETYPE_LIB_PATH/src/base/ftgasp.c \
$$FREETYPE_LIB_PATH/src/base/ftglyph.c \
$$FREETYPE_LIB_PATH/src/gzip/ftgzip.c \
$$FREETYPE_LIB_PATH/src/base/ftinit.c \
$$FREETYPE_LIB_PATH/src/lzw/ftlzw.c \
$$FREETYPE_LIB_PATH/src/base/ftstroke.c \
$$FREETYPE_LIB_PATH/src/base/ftsystem.c \
$$FREETYPE_LIB_PATH/src/smooth/smooth.c

View File

@ -0,0 +1,44 @@
QT -= core gui
TARGET = names
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEFINES += \
BUILD_FONT_NAMES_DICTIONARY
CORE_ROOT_DIR = $$PWD/../../..
PWD_ROOT_DIR = $$PWD
include(../../../Common/base.pri)
FREETYPE_LIB_PATH=$$PWD/../freetype-2.5.3
INCLUDEPATH += \
$$FREETYPE_LIB_PATH/include
LIBS += -L$$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX -lfreetype
DESTDIR=$$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX
SOURCES += \
FontMaps.cpp
#HEADERS += FontDictionary.h
HEADERS += \
$$PWD/../../fontengine/ApplicationFonts.h
SOURCES += \
$$PWD/../../fontengine/ApplicationFonts.cpp \
$$PWD/../../fontengine/FontFile.cpp \
$$PWD/../../fontengine/FontManager.cpp \
$$PWD/../../fontengine/GlyphString.cpp \
$$PWD/../../fontengine/FontPath.cpp
win32 {
LIBS += -ladvapi32 \
-luser32 \
-lshell32
}

View File

@ -1,39 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
*
*/
// stdafx.cpp : source file that includes just the standard includes
// FontMaps.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@ -1,87 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
*
*/
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#ifndef STRICT
#define STRICT
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _CRT_SECURE_NO_DEPRECATE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off ATL's hiding of some common and often safely ignored warning messages
#define _ATL_ALL_WARNINGS
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <atlstr.h>
using namespace ATL;

View File

@ -35,6 +35,7 @@
#include "../DesktopEditor/common/StringBuilder.h"
#include "../DesktopEditor/common/String.h"
#include "../DesktopEditor/xml/include/xmlutils.h"
#include "../DesktopEditor/fontengine/application_generate_fonts_common.h"
#include <vector>
#include <map>
@ -242,10 +243,30 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
oBuilder.WriteString(L"</destination>");
std::vector<std::wstring> arTmpFiles;
for (std::vector<std::wstring>::const_iterator iter = arFiles.begin(); iter != arFiles.end(); iter++)
{
oBuilder.WriteString(L"<file>");
oBuilder.WriteEncodeXmlString(CorrectHtmlPath(*iter));
std::wstring sFilePath = *iter;
std::wstring sExt = NSCommon::GetFileExtention(sFilePath);
NSCommon::makeUpperW(sExt);
if (sExt == L"HTML" || sExt == L"HTM" || sExt == L"XHTML")
oBuilder.WriteEncodeXmlString(CorrectHtmlPath(sFilePath));
else
{
std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSDirectory::GetTempPath(), L"HTM");
if (NSFile::CFileBinary::Exists(sTmpFile))
NSFile::CFileBinary::Remove(sTmpFile);
sTmpFile = sTmpFile + L".html";
NSFile::CFileBinary::Copy(sFilePath, sTmpFile);
oBuilder.WriteEncodeXmlString(CorrectHtmlPath(sTmpFile));
arTmpFiles.push_back(sTmpFile);
}
oBuilder.WriteString(L"</file>");
}
@ -411,6 +432,12 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
}
#endif
for (std::vector<std::wstring>::iterator i = arTmpFiles.begin(); i != arTmpFiles.end(); i++)
{
NSFile::CFileBinary::Remove(*i);
}
arTmpFiles.clear();
NSFile::CFileBinary::Remove(sTempFileForParams);
return nReturnCode;
}

View File

@ -108,7 +108,10 @@ int main(int argc, char *argv[])
#if 1
CHtmlFile oFile;
std::wstring sMetaInfo;
int nResult = oFile.ConvertEpub(L"D:/1", sMetaInfo, L"D:/test/Document");
//int nResult = oFile.ConvertEpub(L"D:/1", sMetaInfo, L"D:/test/Document");
std::vector<std::wstring> arFiles;
arFiles.push_back(L"Note.html");
int nResult = oFile.Convert(arFiles, L"D:\\test\\Document");
return 0;
#else

View File

@ -487,10 +487,22 @@ namespace NExtractTools
}
else return AVS_FILEUTILS_ERROR_CONVERT; }
return xlsx_dir2xlst_bin(sTempUnpackedXLSX, sTo, params, true);
return xlsx_dir2xlst_bin(sTempUnpackedXLSX, sTo, params, true, sFrom);
}
int xlsx_dir2xlst_bin (const std::wstring &sXlsxDir, const std::wstring &sTo, InputParams& params, bool bXmlOptions)
int xlsx_dir2xlst_bin (const std::wstring &sXlsxDir, const std::wstring &sTo, InputParams& params, bool bXmlOptions, const std::wstring &sXlsxFile)
{
//save Editor.xlsx for pivot
std::wstring sToDir = NSDirectory::GetFolderPath(sTo);
std::wstring sEditorXLSX = sToDir + FILE_SEPARATOR_STR + _T("Editor.xlsx");
if(sXlsxFile.empty())
{
dir2zip(sXlsxDir, sEditorXLSX);
}
else
{
NSFile::CFileBinary::Copy(sXlsxFile, sEditorXLSX);
}
// Save to file (from temp dir)
BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer;
@ -3011,7 +3023,7 @@ namespace NExtractTools
return nRes;
}
int fromXlsxDir(const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params, bool isSavedXFile)
int fromXlsxDir(const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params, const std::wstring &sXlsxFile)
{
int nRes = 0;
if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo) && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV != nFormatTo)
@ -3042,11 +3054,11 @@ namespace NExtractTools
}
else if(AVS_OFFICESTUDIO_FILE_OTHER_JSON == nFormatTo)
{
nRes = xlsx_dir2xlst_bin(sFrom, sTo, params, true);
nRes = xlsx_dir2xlst_bin(sFrom, sTo, params, true, sXlsxFile);
}
else if(AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET == nFormatTo)
{
nRes = xlsx_dir2xlst_bin(sFrom, sTo, params, true);
nRes = xlsx_dir2xlst_bin(sFrom, sTo, params, true, sXlsxFile);
}
else
{
@ -3054,19 +3066,14 @@ namespace NExtractTools
NSDirectory::CreateDirectory(sXlstDir);
std::wstring sTFile = sXlstDir + FILE_SEPARATOR_STR + _T("Editor.bin");
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV == nFormatTo)
nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, false);
nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, false, sXlsxFile);
else
nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, true);
nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, true, sXlsxFile);
if(SUCCEEDED_X2T(nRes))
{
nRes = fromXlstBin(sTFile, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params);
}
}
if (SUCCEEDED_X2T(nRes) && !isSavedXFile && params.getSaveXFile())
{
std::wstring sToDir = NSDirectory::GetFolderPath(sTo);
nRes = dir2zip(sFrom, sToDir + FILE_SEPARATOR_STR + _T("Editor.xlsx"));
}
return nRes;
}
int fromXlstBin(const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params)
@ -3098,7 +3105,8 @@ namespace NExtractTools
nRes = xlst_bin2xlsx_dir(sFrom, sTo, sXlsxDir, bFromChanges, sThemeDir, params);
if(SUCCEEDED_X2T(nRes))
{
nRes = fromXlsxDir(sXlsxDir, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params, false);
std::wstring sXlsxFile;
nRes = fromXlsxDir(sXlsxDir, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params, sXlsxFile);
}
}
else
@ -3146,18 +3154,13 @@ namespace NExtractTools
}
else
{
std::wstring sXlsxFile;
std::wstring sXlsxDir = sTemp + FILE_SEPARATOR_STR + _T("xlsx_unpacked");
NSDirectory::CreateDirectory(sXlsxDir);
bool isSavedXFile = false;
if ((AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatFrom || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatFrom ||
AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX == nFormatFrom || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM == nFormatFrom) && params.getSaveXFile())
{
NSFile::CFileBinary::Copy(sFrom, NSSystemPath::GetDirectoryName(sTo) + FILE_SEPARATOR_STR + _T("Editor.xlsx"));
isSavedXFile = true;
}
if (AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatFrom)
{
nRes = zip2dir(sFrom, sXlsxDir);
sXlsxFile = sFrom;
}
else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatFrom)
{
@ -3197,7 +3200,7 @@ namespace NExtractTools
nRes = AVS_FILEUTILS_ERROR_CONVERT;
if(SUCCEEDED_X2T(nRes))
{
nRes = fromXlsxDir(sXlsxDir, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params, isSavedXFile);
nRes = fromXlsxDir(sXlsxDir, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params, sXlsxFile);
}
}
return nRes;

View File

@ -65,7 +65,7 @@ namespace NExtractTools
int dotm2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params);
int xlsx2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xlsx_dir2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params, bool bXmlOptions);
int xlsx_dir2xlst_bin (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params, bool bXmlOptions, const std::wstring &sXlsxFile);
int xlsx2xlst (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params);
int xlst_bin2xlsx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bFromChanges, const std::wstring &sThemeDir, InputParams& params);
int xlst_bin2xlsx_dir (const std::wstring &sFrom, const std::wstring &sToResult, const std::wstring &sTo, bool bFromChanges, const std::wstring &sThemeDir, InputParams& params);
@ -177,7 +177,7 @@ namespace NExtractTools
int fromDoctBin (const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params);
int fromDocument (const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTemp, InputParams& params);
int fromXlsxDir (const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params, bool isSavedXFile);
int fromXlsxDir (const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params, const std::wstring &sXlsxFile);
int fromXlstBin (const std::wstring &sFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bFromChanges, bool bPaid, InputParams& params);
int fromSpreadsheet (const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTemp, InputParams& params);

File diff suppressed because it is too large Load Diff

View File

@ -374,7 +374,6 @@ namespace NExtractTools
std::wstring* m_sPassword;
std::wstring* m_sTempDir;
bool* m_bIsNoBase64;
bool* m_bSaveXFile;
//output params
mutable bool m_bOutputConvertCorrupted;
public:
@ -401,7 +400,6 @@ namespace NExtractTools
m_sPassword = NULL;
m_sTempDir = NULL;
m_bIsNoBase64 = NULL;
m_bSaveXFile = NULL;
m_bOutputConvertCorrupted = false;
}
@ -428,7 +426,6 @@ namespace NExtractTools
RELEASEOBJECT(m_sPassword);
RELEASEOBJECT(m_sTempDir);
RELEASEOBJECT(m_bIsNoBase64);
RELEASEOBJECT(m_bSaveXFile);
}
bool FromXmlFile(const std::wstring& sFilename)
@ -519,8 +516,6 @@ namespace NExtractTools
m_sTempDir = new std::wstring(sValue);
else if(_T("m_bIsNoBase64") == sName)
m_bIsNoBase64 = new bool(XmlUtils::GetBoolean2(sValue));
else if(_T("m_bSaveXFile") == sName)
m_bSaveXFile = new bool(XmlUtils::GetBoolean2(sValue));
}
else if(_T("m_nCsvDelimiterChar") == sName)
{
@ -552,10 +547,6 @@ namespace NExtractTools
{
return (NULL != m_bIsNoBase64) ? (*m_bIsNoBase64) : true;
}
bool getSaveXFile() const
{
return (NULL != m_bSaveXFile) ? (*m_bSaveXFile) : false;
}
std::wstring getXmlOptions()
{
std::wstring sRes;

View File

@ -52,36 +52,57 @@
{
[super viewDidLoad];
//[self testDOCX];
[self testDOCX];
[self testXLSX];
}
- (void)testDOCX
{
NSLog(@"==================== OPEN DOCX ====================");
{
NSLog(@"==================== OPEN DOCX ====================");
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"docx"];
NSString* fullFileName = path;
NSString* fullFileNameTo = [NSString stringWithFormat:@"%@demo.bin", NSTemporaryDirectory()];
NSString* tempDir = NSTemporaryDirectory();
NSString* fontsPath = @"/System/Library/Fonts";
X2tConverter* conv = [[X2tConverter alloc]init];
conv.isNoBase64 = YES;
[conv sdk_docx2doct_bin:fullFileName nsTo:fullFileNameTo nsTemp:tempDir nsFontPath:fontsPath];
NSLog(@"doct output : %@", fullFileNameTo);
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"docx"];
NSString* fullFileName = path;
NSString* fullFileNameTo = [NSString stringWithFormat:@"%@demo.bin", NSTemporaryDirectory()];
NSString* tempDir = NSTemporaryDirectory();
NSString* fontsPath = @"/System/Library/Fonts";
X2tConverter* conv = [[X2tConverter alloc]init];
[conv sdk_docx2doct_bin:fullFileName nsTo:fullFileNameTo nsTemp:tempDir nsFontPath:fontsPath];
NSLog(@"%@",fullFileNameTo);
NSString* docxOut = [NSString stringWithFormat:@"%@document.docx", NSTemporaryDirectory()];
NSString* outTemp = [NSString stringWithFormat:@"%@OUT_TEMP", NSTemporaryDirectory()];
[self createDirectory:outTemp];
[self clearDirectory:outTemp];
X2tConverter* conv2 = [[X2tConverter alloc]init];
[conv2 sdk_doct_bin2docx:fullFileNameTo nsTo:docxOut nsTemp:outTemp nsFontPath:fontsPath fromChanges:@(NO) nsThemeDir:@""];
NSLog(@"doct output: %@",fullFileNameTo);
{
NSLog(@"==================== OPEN DOCT ====================");
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"docx"];
NSString* fullFileName = path;
NSString* fullFileNameTo = [NSString stringWithFormat:@"%@demo.bin", NSTemporaryDirectory()];
NSString* tempDir = NSTemporaryDirectory();
NSString* fontsPath = @"/System/Library/Fonts";
X2tConverter* conv = [[X2tConverter alloc]init];
conv.isNoBase64 = YES;
[conv sdk_docx2doct_bin:fullFileName nsTo:fullFileNameTo nsTemp:tempDir nsFontPath:fontsPath];
NSLog(@"%@",fullFileNameTo);
NSString* docxOut = [NSString stringWithFormat:@"%@document.docx", NSTemporaryDirectory()];
NSString* outTemp = [NSString stringWithFormat:@"%@OUT_TEMP", NSTemporaryDirectory()];
[self createDirectory:outTemp];
[self clearDirectory:outTemp];
X2tConverter* conv2 = [[X2tConverter alloc]init];
conv.isNoBase64 = YES;
[conv2 sdk_doct_bin2docx:fullFileNameTo nsTo:docxOut nsTemp:outTemp nsFontPath:fontsPath fromChanges:@(NO) nsThemeDir:@""];
NSLog(@"doct output: %@",fullFileNameTo);
}
}
- (void)testXLSX
@ -97,6 +118,7 @@
NSString* fontsPath = @"/System/Library/Fonts";
X2tConverter* conv = [[X2tConverter alloc]init];
conv.isNoBase64 = YES;
[conv sdk_xlsx2xlst_bin:fullFileName nsTo:fullFileNameTo nsTemp:tempDir nsFontPath:fontsPath];
NSLog(@"xlst output : %@", fullFileNameTo);
@ -114,6 +136,7 @@
X2tConverter* conv = [[X2tConverter alloc]init];
conv.password = @"555";
conv.isNoBase64 = YES;
if ((int)AVS_FILEUTILS_ERROR_CONVERT_PASSWORD == [conv sdk_xlsx2xlst_bin:fullFileName nsTo:fullFileNameTo nsTemp:tempDir nsFontPath:fontsPath]) {
NSLog(@"Error password : %@",conv.password);
}