Commit 9e6d4950 authored by Alexey.Musinov's avatar Alexey.Musinov

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)
parents cb4befa0 ac1292a1
...@@ -229,7 +229,7 @@ const std::wstring int2wstr(const int val, const int radix) ...@@ -229,7 +229,7 @@ const std::wstring int2wstr(const int val, const int radix)
const std::wstring double2str(const double val) const std::wstring double2str(const double val)
{ {
return std::to_wstring(val); return boost::lexical_cast<std::wstring>(val);// std::to_wstring(val); - округление (
} }
......
...@@ -62,6 +62,7 @@ void DXFNum::load(CFRecord& record) ...@@ -62,6 +62,7 @@ void DXFNum::load(CFRecord& record)
int DXFNum::serialize(std::wostream & stream) int DXFNum::serialize(std::wostream & stream)
{ {
if (!parent) return 0; if (!parent) return 0;
if (fmt_id.ifmt == 0) return 0;
CP_XML_WRITER(stream) CP_XML_WRITER(stream)
{ {
......
...@@ -227,7 +227,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB) ...@@ -227,7 +227,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB)
Formula->serialize_attr(CP_GET_XML_NODE()); 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") CP_XML_NODE(L"sharedItems")
{ {
...@@ -266,7 +266,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB) ...@@ -266,7 +266,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB)
else if (!bEmpty && !bString && !bBool) else if (!bEmpty && !bString && !bBool)
{ {
CP_XML_ATTR(L"containsSemiMixedTypes", 0); CP_XML_ATTR(L"containsSemiMixedTypes", 0);
if (bDate) if (bDate && (bNumber || bInteger))
{ {
CP_XML_ATTR(L"containsMixedTypes", 1); CP_XML_ATTR(L"containsMixedTypes", 1);
} }
...@@ -320,7 +320,7 @@ int FDB::serialize(std::wostream & strm, bool bSql, bool bDBB) ...@@ -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") CP_XML_NODE(L"fieldGroup")
{ {
......
...@@ -209,21 +209,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _ ...@@ -209,21 +209,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
XLS::BinReaderProcessor proc(pivot_cache_reader , pivot_cache.get() , true); XLS::BinReaderProcessor proc(pivot_cache_reader , pivot_cache.get() , true);
proc.mandatory(*pivot_cache.get()); proc.mandatory(*pivot_cache.get());
int index = -1; int index = XmlUtils::GetHex(*it);
try
{
index = boost::lexical_cast<int>(it->c_str());
}
catch(...)
{
}
if (index < 0)
{
//может быть шестнадцатеричное
index = XmlUtils::GetHex(*it);
}
if (index < 0)
index = last_index + 1;
xls_global_info->mapPivotCacheStream.insert(std::make_pair(index, pivot_cache)); xls_global_info->mapPivotCacheStream.insert(std::make_pair(index, pivot_cache));
......
...@@ -49,43 +49,45 @@ namespace OOX ...@@ -49,43 +49,45 @@ namespace OOX
public: public:
CExtensionTable() CExtensionTable()
{ {
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("bmp"), _T("image/bmp"))); m_mTable.insert( std::make_pair( _T("bmp"), _T("image/bmp")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("gif"), _T("image/gif"))); m_mTable.insert( std::make_pair( _T("gif"), _T("image/gif")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("png"), _T("image/png"))); m_mTable.insert( std::make_pair( _T("png"), _T("image/png")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("tif"), _T("image/tiff"))); m_mTable.insert( std::make_pair( _T("tif"), _T("image/tiff")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("tiff"), _T("image/tiff"))); m_mTable.insert( std::make_pair( _T("tiff"), _T("image/tiff")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpeg"), _T("image/jpeg"))); m_mTable.insert( std::make_pair( _T("jpeg"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpg"), _T("image/jpeg"))); m_mTable.insert( std::make_pair( _T("jpg"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jpe"), _T("image/jpeg"))); m_mTable.insert( std::make_pair( _T("jpe"), _T("image/jpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("jfif"), _T("image/jpeg"))); m_mTable.insert( std::make_pair( _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::make_pair( _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::make_pair( _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::make_pair( _T("xml"), _T("application/xml")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("emf"), _T("image/x-emf"))); m_mTable.insert( std::make_pair( _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::make_pair( _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::make_pair( _T("wmf"), _T("image/x-wmf")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("svm"), _T("image/svm"))); m_mTable.insert( std::make_pair( _T("svm"), _T("image/svm")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wav"), _T("audio/wav"))); m_mTable.insert( std::make_pair( _T("wav"), _T("audio/wav")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wma"), _T("audio/x-wma"))); m_mTable.insert( std::make_pair( _T("wma"), _T("audio/x-wma")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("m4a"), _T("audio/unknown"))); m_mTable.insert( std::make_pair( _T("m4a"), _T("audio/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mp3"), _T("audio/mpeg"))); m_mTable.insert( std::make_pair( _T("mp3"), _T("audio/mpeg")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mp4"), _T("video/unknown"))); m_mTable.insert( std::make_pair( _T("mp4"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("mov"), _T("video/unknown"))); m_mTable.insert( std::make_pair( _T("mov"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("avi"), _T("video/avi"))); m_mTable.insert( std::make_pair( _T("m4v"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("wmv"), _T("video/x-wmv"))); m_mTable.insert( std::make_pair( _T("mkv"), _T("video/unknown")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xls"), _T("application/vnd.ms-excel"))); m_mTable.insert( std::make_pair( _T("avi"), _T("video/avi")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsm"), _T("application/vnd.ms-excel.sheet.macroEnabled.12"))); m_mTable.insert( std::make_pair( _T("wmv"), _T("video/x-wmv")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsb"), _T("application/vnd.ms-excel.sheet.binary.macroEnabled.12"))); m_mTable.insert( std::make_pair( _T("xls"), _T("application/vnd.ms-excel")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("xlsx"), _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))); m_mTable.insert( std::make_pair( _T("xlsm"), _T("application/vnd.ms-excel.sheet.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("ppt"), _T("application/vnd.ms-powerpoint"))); m_mTable.insert( std::make_pair( _T("xlsb"), _T("application/vnd.ms-excel.sheet.binary.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("pptm"), _T("application/vnd.ms-powerpoint.presentation.macroEnabled.12"))); m_mTable.insert( std::make_pair( _T("xlsx"), _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("pptx"), _T("application/vnd.openxmlformats-officedocument.presentationml.presentation"))); m_mTable.insert( std::make_pair( _T("ppt"), _T("application/vnd.ms-powerpoint")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("sldm"), _T("application/vnd.ms-powerpoint.slide.macroEnabled.12"))); m_mTable.insert( std::make_pair( _T("pptm"), _T("application/vnd.ms-powerpoint.presentation.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("sldx"), _T("application/vnd.openxmlformats-officedocument.presentationml.slide"))); m_mTable.insert( std::make_pair( _T("pptx"), _T("application/vnd.openxmlformats-officedocument.presentationml.presentation")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("doc"), _T("application/msword"))); m_mTable.insert( std::make_pair( _T("sldm"), _T("application/vnd.ms-powerpoint.slide.macroEnabled.12")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("docm"), _T("aapplication/vnd.ms-word.document.macroEnabled.12"))); m_mTable.insert( std::make_pair( _T("sldx"), _T("application/vnd.openxmlformats-officedocument.presentationml.slide")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("docx"), _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document"))); m_mTable.insert( std::make_pair( _T("doc"), _T("application/msword")));
m_mTable.insert( std::pair<std::wstring,std::wstring>( _T("vml"), _T("application/vnd.openxmlformats-officedocument.vmlDrawing"))); 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 const std::wstring operator[] (const std::wstring& sExtension) const
{ {
......
...@@ -387,11 +387,22 @@ public: ...@@ -387,11 +387,22 @@ public:
CChangesWorker oWorkerLoader; CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath()); 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[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(m_isolate, nVersion); 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()) if (try_catch.HasCaught())
{ {
......
...@@ -364,18 +364,18 @@ namespace NSDoctRenderer ...@@ -364,18 +364,18 @@ namespace NSDoctRenderer
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError) static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{ {
#if 0 #if 0
if (m_sErrorsLogFile.empty()) if (m_sErrorsLogFile.empty())
return; 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 sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError); std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
fprintf(f, sT.c_str()); fprintf(f, sT.c_str());
fprintf(f, ": "); fprintf(f, ": ");
fprintf(f, sE.c_str()); fprintf(f, sE.c_str());
fprintf(f, "\n"); fprintf(f, "\n");
fclose(f); fclose(f);
#endif #endif
...@@ -730,11 +730,22 @@ namespace NSDoctRenderer ...@@ -730,11 +730,22 @@ namespace NSDoctRenderer
CChangesWorker oWorkerLoader; CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath()); 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[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(isolate, nVersion); 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()) if (try_catch.HasCaught())
{ {
......
...@@ -305,6 +305,112 @@ void _SaveChanges(const v8::FunctionCallbackInfo<v8::Value>& args) ...@@ -305,6 +305,112 @@ void _SaveChanges(const v8::FunctionCallbackInfo<v8::Value>& args)
pNative->DumpChanges(to_cstringA(args[0]), args[1]->Int32Value(), args[2]->Int32Value()); 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) void _AddImageInChanges(const v8::FunctionCallbackInfo<v8::Value>& args)
{ {
args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent())); args.GetReturnValue().Set(v8::Undefined(v8::Isolate::GetCurrent()));
...@@ -355,6 +461,12 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate) ...@@ -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, "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 и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope // уничтожиться при уничтожении "нашего" HandleScope - handle_scope
...@@ -397,6 +509,12 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplateBuilder(v8::Isolate* i ...@@ -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, "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 и не дает ему
// уничтожиться при уничтожении "нашего" HandleScope - handle_scope // уничтожиться при уничтожении "нашего" HandleScope - handle_scope
......
...@@ -37,6 +37,132 @@ ...@@ -37,6 +37,132 @@
#include "../fontengine/ApplicationFonts.h" #include "../fontengine/ApplicationFonts.h"
#include <iostream> #include <iostream>
#include "../../graphics/Timer.h" #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 // string convert
std::wstring to_cstring(v8::Local<v8::Value> v); std::wstring to_cstring(v8::Local<v8::Value> v);
...@@ -76,6 +202,8 @@ public: ...@@ -76,6 +202,8 @@ public:
std::wstring m_sChangesBuilderPath; std::wstring m_sChangesBuilderPath;
int m_nCurrentChangesBuilderIndex; int m_nCurrentChangesBuilderIndex;
CZipWorker m_oZipWorker;
public: public:
CMemoryStream* m_pStream; CMemoryStream* m_pStream;
...@@ -152,6 +280,8 @@ public: ...@@ -152,6 +280,8 @@ public:
void SetFilePath(const std::wstring& strPath) void SetFilePath(const std::wstring& strPath)
{ {
m_strFilePath = strPath; m_strFilePath = strPath;
m_oZipWorker.m_sWorkerFolder = NSCommon::GetDirectoryName(strPath);
} }
std::wstring GetFilePath() std::wstring GetFilePath()
{ {
...@@ -324,6 +454,14 @@ void _ConsoleLog(const v8::FunctionCallbackInfo<v8::Value>& args); ...@@ -324,6 +454,14 @@ void _ConsoleLog(const v8::FunctionCallbackInfo<v8::Value>& args);
void _SaveChanges(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); void _AddImageInChanges(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate); v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate);
......
...@@ -42,15 +42,15 @@ int main(int argc, char *argv[]) ...@@ -42,15 +42,15 @@ int main(int argc, char *argv[])
#if 1 #if 1
std::wstring strXml = L"<Settings>\ std::wstring strXml = L"<Settings>\
<SrcFileType>0</SrcFileType>\ <SrcFileType>1</SrcFileType>\
<DstFileType>3</DstFileType>\ <DstFileType>1</DstFileType>\
<SrcFilePath>D:\\DE_CAD4</SrcFilePath>\ <SrcFilePath>D:\\source</SrcFilePath>\
<DstFilePath>D:\\DE_CAD4\\EditorWithChanges.bin</DstFilePath>\ <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>\ <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>\ <ThemesDirectory>D:\\activex\\AVS\\Sources\\TeamlabOffice\\trunk\\ServerComponents\\Test\\Applications\\TestAVSOfficeDocxFile2\\TestAVSOfficeDocxFile2\\bin\\x86\\presentationthemes</ThemesDirectory>\
<Changes TopItem=\"-1\">\ <Changes TopItem=\"-1\">\
<Change>D:\\DE_CAD4\\changes\\changes0.json</Change>\ <Change>D:\\source\\changes\\changes0.json</Change>\
</Changes>\ </Changes>\
</Settings>"; </Settings>";
......
...@@ -709,6 +709,44 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory, bool bIsOnly ...@@ -709,6 +709,44 @@ void CFontInfo::ToBuffer(BYTE*& pBuffer, std::wstring strDirectory, bool bIsOnly
pBuffer += sizeof(SHORT); 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 namespace NSCharsets
{ {
...@@ -1583,6 +1621,10 @@ void CFontList::LoadFromArrayFiles(std::vector<std::wstring>& oArray, int nFlag) ...@@ -1583,6 +1621,10 @@ void CFontList::LoadFromArrayFiles(std::vector<std::wstring>& oArray, int nFlag)
shXHeight, shXHeight,
shCapHeight ); shCapHeight );
#ifdef BUILD_FONT_NAMES_DICTIONARY
pFontInfo->ReadNames(pFace);
#endif
Add(pFontInfo); Add(pFontInfo);
FT_Done_Face( pFace ); FT_Done_Face( pFace );
...@@ -1642,6 +1684,7 @@ void CFontList::Add(CFontInfo* pInfo) ...@@ -1642,6 +1684,7 @@ void CFontList::Add(CFontInfo* pInfo)
return; return;
} }
} }
m_pList.Add(pInfo); m_pList.Add(pInfo);
} }
......
...@@ -159,6 +159,12 @@ public: ...@@ -159,6 +159,12 @@ public:
SHORT m_shLineGap; // Межсимвольный интервал SHORT m_shLineGap; // Межсимвольный интервал
SHORT m_shXHeight; // Высота буквы 'x' (в нижнем регистре) SHORT m_shXHeight; // Высота буквы 'x' (в нижнем регистре)
SHORT m_shCapHeight; // Высота буквы 'H' (в верхнем регистре) SHORT m_shCapHeight; // Высота буквы 'H' (в верхнем регистре)
#ifdef BUILD_FONT_NAMES_DICTIONARY
std::vector<std::wstring> names;
void ReadNames(FT_Face pFace);
#endif
}; };
namespace NSCharsets namespace NSCharsets
......
...@@ -44,70 +44,7 @@ ...@@ -44,70 +44,7 @@
#include "../graphics/GraphicsRenderer.h" #include "../graphics/GraphicsRenderer.h"
#endif #endif
namespace NSCommon #include "./application_generate_fonts_common.h"
{
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);
}
}
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
//#define _GENERATE_FONT_MAP_ //#define _GENERATE_FONT_MAP_
...@@ -116,55 +53,6 @@ namespace NSCommon ...@@ -116,55 +53,6 @@ namespace NSCommon
#include "../../freetype_names/FontMaps/FontDictionary.h" #include "../../freetype_names/FontMaps/FontDictionary.h"
#endif #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 namespace NSCommon
{ {
class CFontInfoJS class CFontInfoJS
......
/*
* (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
/*
* (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;
};
\ No newline at end of file

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
<?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>
/*
* (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 */
\ No newline at end of file
/*
* (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 */
\ No newline at end of file
========================================================================
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.
/////////////////////////////////////////////////////////////////////////////
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* (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 */
\ No newline at end of file
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
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
}
/*
* (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
/*
* (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;
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "../DesktopEditor/common/StringBuilder.h" #include "../DesktopEditor/common/StringBuilder.h"
#include "../DesktopEditor/common/String.h" #include "../DesktopEditor/common/String.h"
#include "../DesktopEditor/xml/include/xmlutils.h" #include "../DesktopEditor/xml/include/xmlutils.h"
#include "../DesktopEditor/fontengine/application_generate_fonts_common.h"
#include <vector> #include <vector>
#include <map> #include <map>
...@@ -242,10 +243,30 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr ...@@ -242,10 +243,30 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
oBuilder.WriteString(L"</destination>"); oBuilder.WriteString(L"</destination>");
std::vector<std::wstring> arTmpFiles;
for (std::vector<std::wstring>::const_iterator iter = arFiles.begin(); iter != arFiles.end(); iter++) for (std::vector<std::wstring>::const_iterator iter = arFiles.begin(); iter != arFiles.end(); iter++)
{ {
oBuilder.WriteString(L"<file>"); 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")
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>"); oBuilder.WriteString(L"</file>");
} }
...@@ -411,6 +432,12 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr ...@@ -411,6 +432,12 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
} }
#endif #endif
for (std::vector<std::wstring>::iterator i = arTmpFiles.begin(); i != arTmpFiles.end(); i++)
{
NSFile::CFileBinary::Remove(*i);
}
arTmpFiles.clear();
NSFile::CFileBinary::Remove(sTempFileForParams); NSFile::CFileBinary::Remove(sTempFileForParams);
return nReturnCode; return nReturnCode;
} }
......
...@@ -108,7 +108,10 @@ int main(int argc, char *argv[]) ...@@ -108,7 +108,10 @@ int main(int argc, char *argv[])
#if 1 #if 1
CHtmlFile oFile; CHtmlFile oFile;
std::wstring sMetaInfo; 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; return 0;
#else #else
......
...@@ -487,10 +487,22 @@ namespace NExtractTools ...@@ -487,10 +487,22 @@ namespace NExtractTools
} }
else return AVS_FILEUTILS_ERROR_CONVERT; } 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) // Save to file (from temp dir)
BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer; BinXlsxRW::CXlsxSerializer m_oCXlsxSerializer;
...@@ -3011,7 +3023,7 @@ namespace NExtractTools ...@@ -3011,7 +3023,7 @@ namespace NExtractTools
return nRes; 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; int nRes = 0;
if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo) && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV != nFormatTo) if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo) && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV != nFormatTo)
...@@ -3042,11 +3054,11 @@ namespace NExtractTools ...@@ -3042,11 +3054,11 @@ namespace NExtractTools
} }
else if(AVS_OFFICESTUDIO_FILE_OTHER_JSON == nFormatTo) 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) 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 else
{ {
...@@ -3054,19 +3066,14 @@ namespace NExtractTools ...@@ -3054,19 +3066,14 @@ namespace NExtractTools
NSDirectory::CreateDirectory(sXlstDir); NSDirectory::CreateDirectory(sXlstDir);
std::wstring sTFile = sXlstDir + FILE_SEPARATOR_STR + _T("Editor.bin"); std::wstring sTFile = sXlstDir + FILE_SEPARATOR_STR + _T("Editor.bin");
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV == nFormatTo) 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 else
nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, true); nRes = xlsx_dir2xlst_bin(sFrom, sTFile, params, true, sXlsxFile);
if(SUCCEEDED_X2T(nRes)) if(SUCCEEDED_X2T(nRes))
{ {
nRes = fromXlstBin(sTFile, sTo, nFormatTo, sTemp, sThemeDir, bFromChanges, bPaid, params); 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; 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) 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 ...@@ -3098,7 +3105,8 @@ namespace NExtractTools
nRes = xlst_bin2xlsx_dir(sFrom, sTo, sXlsxDir, bFromChanges, sThemeDir, params); nRes = xlst_bin2xlsx_dir(sFrom, sTo, sXlsxDir, bFromChanges, sThemeDir, params);
if(SUCCEEDED_X2T(nRes)) 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 else
...@@ -3146,18 +3154,13 @@ namespace NExtractTools ...@@ -3146,18 +3154,13 @@ namespace NExtractTools
} }
else else
{ {
std::wstring sXlsxFile;
std::wstring sXlsxDir = sTemp + FILE_SEPARATOR_STR + _T("xlsx_unpacked"); std::wstring sXlsxDir = sTemp + FILE_SEPARATOR_STR + _T("xlsx_unpacked");
NSDirectory::CreateDirectory(sXlsxDir); 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) if (AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatFrom)
{ {
nRes = zip2dir(sFrom, sXlsxDir); nRes = zip2dir(sFrom, sXlsxDir);
sXlsxFile = sFrom;
} }
else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatFrom) else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatFrom)
{ {
...@@ -3197,7 +3200,7 @@ namespace NExtractTools ...@@ -3197,7 +3200,7 @@ namespace NExtractTools
nRes = AVS_FILEUTILS_ERROR_CONVERT; nRes = AVS_FILEUTILS_ERROR_CONVERT;
if(SUCCEEDED_X2T(nRes)) 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; return nRes;
......
...@@ -65,7 +65,7 @@ namespace NExtractTools ...@@ -65,7 +65,7 @@ namespace NExtractTools
int dotm2docx_dir (const std::wstring &sFrom, const std::wstring &sTo, InputParams& params); 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 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 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 (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); 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 ...@@ -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 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 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 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); int fromSpreadsheet (const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTemp, InputParams& params);
......
...@@ -374,7 +374,6 @@ namespace NExtractTools ...@@ -374,7 +374,6 @@ namespace NExtractTools
std::wstring* m_sPassword; std::wstring* m_sPassword;
std::wstring* m_sTempDir; std::wstring* m_sTempDir;
bool* m_bIsNoBase64; bool* m_bIsNoBase64;
bool* m_bSaveXFile;
//output params //output params
mutable bool m_bOutputConvertCorrupted; mutable bool m_bOutputConvertCorrupted;
public: public:
...@@ -401,7 +400,6 @@ namespace NExtractTools ...@@ -401,7 +400,6 @@ namespace NExtractTools
m_sPassword = NULL; m_sPassword = NULL;
m_sTempDir = NULL; m_sTempDir = NULL;
m_bIsNoBase64 = NULL; m_bIsNoBase64 = NULL;
m_bSaveXFile = NULL;
m_bOutputConvertCorrupted = false; m_bOutputConvertCorrupted = false;
} }
...@@ -428,7 +426,6 @@ namespace NExtractTools ...@@ -428,7 +426,6 @@ namespace NExtractTools
RELEASEOBJECT(m_sPassword); RELEASEOBJECT(m_sPassword);
RELEASEOBJECT(m_sTempDir); RELEASEOBJECT(m_sTempDir);
RELEASEOBJECT(m_bIsNoBase64); RELEASEOBJECT(m_bIsNoBase64);
RELEASEOBJECT(m_bSaveXFile);
} }
bool FromXmlFile(const std::wstring& sFilename) bool FromXmlFile(const std::wstring& sFilename)
...@@ -519,8 +516,6 @@ namespace NExtractTools ...@@ -519,8 +516,6 @@ namespace NExtractTools
m_sTempDir = new std::wstring(sValue); m_sTempDir = new std::wstring(sValue);
else if(_T("m_bIsNoBase64") == sName) else if(_T("m_bIsNoBase64") == sName)
m_bIsNoBase64 = new bool(XmlUtils::GetBoolean2(sValue)); 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) else if(_T("m_nCsvDelimiterChar") == sName)
{ {
...@@ -552,10 +547,6 @@ namespace NExtractTools ...@@ -552,10 +547,6 @@ namespace NExtractTools
{ {
return (NULL != m_bIsNoBase64) ? (*m_bIsNoBase64) : true; return (NULL != m_bIsNoBase64) ? (*m_bIsNoBase64) : true;
} }
bool getSaveXFile() const
{
return (NULL != m_bSaveXFile) ? (*m_bSaveXFile) : false;
}
std::wstring getXmlOptions() std::wstring getXmlOptions()
{ {
std::wstring sRes; std::wstring sRes;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment