Compare commits

...

25 Commits

Author SHA1 Message Date
abb7a85337 [android][x2t] fix build script 2018-11-28 15:37:24 +03:00
f0fe00aa3e Merge remote-tracking branch 'origin/hotfix/v5.2.4' into develop 2018-11-27 15:27:12 +03:00
98a568177d . 2018-11-27 15:26:08 +03:00
e58f1929e1 x2t - version up - 2.5.556 2018-11-27 14:57:53 +03:00
2143869e69 OdfFormatReader - .. 2018-11-27 14:28:21 +03:00
ac6a1a19da Merge remote-tracking branch 'origin/hotfix/v5.2.4' into develop 2018-11-26 14:43:12 +03:00
fb574f1994 [android][pe] utils 2018-11-23 17:50:54 +03:00
f9af786d5a . 2018-11-23 12:19:38 +03:00
3cde3a4444 OdfFormatReader - fix after testing 2018-11-22 19:27:58 +03:00
eb2221f006 Fix previous commit 2018-11-22 11:30:02 +03:00
394d1e7b38 Remove preload libcef library 2018-11-22 11:24:18 +03:00
d9d1473fd0 Add support of RLE8 compression for Wmf/Emf 2018-11-21 18:17:58 +03:00
45ba99b9bf Up cef version on linux 2018-11-21 16:20:33 +03:00
9576ce5f28 OdfFormatReader - convert ms ole objects in open office 2018-11-20 15:42:00 +03:00
7092922d1b DocFormatReader - parsing extra property draw - blob 2018-11-20 11:19:43 +03:00
e112c63f12 OdfFormatReader - external links in formulas and defineds 2018-11-20 11:13:33 +03:00
ae9ec197f1 Merge remote-tracking branch 'origin/hotfix/v5.2.4' into develop 2018-11-16 18:29:14 +03:00
af7640e736 DocFormat - fix after testing 2018-11-16 18:28:34 +03:00
f467912988 Merge remote-tracking branch 'origin/hotfix/v5.2.4' into develop 2018-11-16 15:53:13 +03:00
292781e6fb DocFormat - fix after testing
x2t version up - 2.4.556
2018-11-16 15:50:05 +03:00
9cd97d48b8 MetaFile - fix bugs #39745, #39747 2018-11-16 14:10:37 +03:00
579b441edc . 2018-11-16 12:05:22 +03:00
63b71d256b Merge remote-tracking branch 'origin/hotfix/v5.2.4' into develop 2018-11-15 19:51:18 +03:00
90f1aa055c OdfFormatReader - fix after testing 2018-11-15 19:49:54 +03:00
d75352f1f2 x2t - fix convert vml -> drawing_ml 2018-11-13 14:29:19 +03:00
47 changed files with 1231 additions and 806 deletions

View File

@ -992,6 +992,11 @@ namespace DocFileFormat
_writeAfterRun = oVmlMapper.m_equationXml;
bFormula = true;
}
else if (oVmlMapper.m_isBlob)
{
_writeAfterRun = oVmlMapper.m_blobXml;
bFormula = true;
}
}
else
{
@ -1071,7 +1076,9 @@ namespace DocFileFormat
int cpPic = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::Picture);
int cpFieldEnd = searchNextTextMark( m_document->Text, cpFieldStart, TextMark::FieldEndMark );
if (cpFieldStart < cpPic && cpPic < cpFieldEnd)
bool bStartField = _fieldLevels.empty() ? false : (_fieldLevels.back().bBegin && !_fieldLevels.back().bSeparate);
if (cpFieldStart < cpPic && cpPic < cpFieldEnd && !bStartField)
{
writeField(text, cpFieldStart, cpFieldEnd);
text.clear();

View File

@ -31,6 +31,7 @@
*/
#include "MainDocumentMapping.h"
#include "OfficeDrawing/FillStyleBooleanProperties.h"
namespace DocFileFormat
{
@ -83,16 +84,27 @@ namespace DocFileFormat
if ((m_document->GetOfficeArt()) && (m_document->GetOfficeArt()->GetShapeBackgound()))
{
bool bFilled = true;
m_document->DocProperties->bDisplayBackgroundShape = true;
ShapeContainer* pShape = m_document->GetOfficeArt()->GetShapeBackgound();
m_pXmlWriter->WriteNodeBegin ( L"w:background", TRUE);
m_pXmlWriter->WriteAttribute ( L"w:color", L"FFFFFF");
m_pXmlWriter->WriteNodeEnd( L"", TRUE, FALSE );
VMLShapeMapping oVmlWriter (m_context, m_pXmlWriter, NULL, NULL, _caller);
pShape->Convert(&oVmlWriter);
m_pXmlWriter->WriteNodeEnd (L"w:background");
OptionEntryPtr boolFill = pShape->ExtractOption(fillStyleBooleanProperties);
FillStyleBooleanProperties booleans(boolFill ? boolFill->op : 0);
if (booleans.fUsefFilled && !booleans.fFilled)
{
bFilled = false;
}
if (bFilled)
{
m_pXmlWriter->WriteNodeBegin ( L"w:background", TRUE);
m_pXmlWriter->WriteAttribute ( L"w:color", L"FFFFFF");
m_pXmlWriter->WriteNodeEnd( L"", TRUE, FALSE );
VMLShapeMapping oVmlWriter (m_context, m_pXmlWriter, NULL, NULL, _caller);
pShape->Convert(&oVmlWriter);
m_pXmlWriter->WriteNodeEnd (L"w:background");
}
}
m_pXmlWriter->WriteNodeBegin( L"w:body", FALSE );

View File

@ -101,6 +101,24 @@ namespace DocFileFormat
return new ShapeContainer( _reader, bodySize, typeCode, version, instance );
}
OptionEntryPtr ExtractOption(const PropertyId & prop) const
{
OptionEntryPtr ret;
for ( size_t i = 0; i < this->Children.size(); ++i )
{
ShapeOptions* opt = dynamic_cast<ShapeOptions*>( this->Children[i] );
if ( opt == NULL ) continue;
std::map<PropertyId, OptionEntryPtr>::iterator pFind = opt->OptionsByID.find(prop);
if (pFind != opt->OptionsByID.end())
{
ret = pFind->second;
}
}
return ret;
}
std::vector<OptionEntryPtr> ExtractOptions() const
{
std::vector<OptionEntryPtr> ret;

View File

@ -138,6 +138,51 @@ namespace DocFileFormat
}
return btWin32;
}
bool VMLPictureMapping::ParseEmbeddedBlob( const std::string & xmlString, std::wstring & newXmlString)
{
newXmlString.clear();
std::wstring sTempFolder = m_context->_doc->m_sTempFolder;
if (sTempFolder.empty())
{
sTempFolder = NSFile::CFileBinary::GetTempPath();
}
std::wstring sTempXmlFile = NSDirectory::CreateTempFileWithUniqueName(sTempFolder, L"emb");
NSFile::CFileBinary file;
file.CreateFileW(sTempXmlFile);
file.WriteFile((BYTE*)xmlString.c_str(), xmlString.size());
file.CloseFile();
COfficeUtils officeUtils(NULL);
BYTE *utf8Data = NULL;
ULONG utf8DataSize = 0;
if (S_OK != officeUtils.LoadFileFromArchive(sTempXmlFile, L"drs/shapexml.xml", &utf8Data, utf8DataSize))
{
if (S_OK == officeUtils.IsFileExistInArchive(sTempXmlFile, L"drs/diagrams"))
{
officeUtils.LoadFileFromArchive(sTempXmlFile, L"drs/diagrams/drawing1.xml", &utf8Data, utf8DataSize);
}
else if (S_OK != officeUtils.LoadFileFromArchive(sTempXmlFile, L"drs/e2oDoc.xml", &utf8Data, utf8DataSize))
{
}
}
if (utf8Data && utf8DataSize > 0)
{
newXmlString = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(utf8Data, utf8DataSize);
delete []utf8Data;
}
NSFile::CFileBinary::Remove(sTempXmlFile);
if (newXmlString.empty()) return false;
return true;
}
bool VMLPictureMapping::ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString)
{
newXmlString.clear();
@ -221,6 +266,7 @@ namespace DocFileFormat
m_isBullete = false;
m_isEquation = false;
m_isEmbedded = false;
m_isBlob = false;
m_imageData = new XMLTools::XMLElement( L"v:imagedata" );
}
@ -314,7 +360,9 @@ namespace DocFileFormat
case metroBlob:
{
//встроенная неведомая хуйня
m_isBlob = true;
m_isEmbedded = true;
m_embeddedData = std::string((char*)iter->opComplex.get(), iter->op);
//if (ParseEmbeddedBlob( m_embeddedData, m_blobXml)) // todoooo

View File

@ -58,6 +58,7 @@ namespace DocFileFormat
void writePictureBorder (const std::wstring & name, const BorderCode* brc);
void appendStyleProperty( std::wstring* b, const std::wstring& propName, const std::wstring& propValue ) const;
bool ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString );
bool ParseEmbeddedBlob(const std::string & xmlString, std::wstring & newXmlString);
std::wstring GetShapeID(const Shape* pShape) const;
protected:
/// Copies the picture from the binary stream to the zip archive
@ -69,11 +70,13 @@ namespace DocFileFormat
static std::wstring GetTargetExt (Global::BlipType nType);
static std::wstring GetContentType (Global::BlipType nType);
bool m_isBlob;
bool m_isBullete;
bool m_isEquation;
bool m_isEmbedded;
std::string m_embeddedData;
std::wstring m_equationXml;
std::wstring m_blobXml;
std::wstring m_shapeId;
private:

View File

@ -36,6 +36,7 @@
#include "../include/CPScopedPtr.h"
namespace cpdoccore {
namespace formulasconvert {
@ -44,7 +45,7 @@ namespace formulasconvert {
class odf2oox_converter
{
public:
odf2oox_converter();
odf2oox_converter();
~odf2oox_converter();
// of:=SUM([.DDA1:.BA3]) -> SUM(DDA1:BA3)

View File

@ -35,6 +35,7 @@
#include <boost/algorithm/string.hpp>
#include"../../Common/DocxFormat/Source/XML/Utils.h"
#include "../src/docx/xlsxconversioncontext.h"
namespace cpdoccore {
namespace formulasconvert {
@ -42,6 +43,9 @@ namespace formulasconvert {
class odf2oox_converter::Impl
{
public:
Impl() {}
static std::unordered_map<std::wstring, int> & mapExternalLink_;
std::wstring convert(const std::wstring& expr);
std::wstring convert_chart_distance(const std::wstring& expr);
@ -54,21 +58,155 @@ namespace formulasconvert {
void replace_tilda(std::wstring& expr);
void replace_vertical(std::wstring& expr);
void replace_space(std::wstring& expr);
std::wstring convert_named_ref(const std::wstring& expr, bool withTableName, std::wstring separator);
std::wstring convert_named_expr(const std::wstring& expr, bool withTableName);
static std::wstring replace_named_ref_formater(boost::wsmatch const & what);
static std::wstring replace_named_ref_formater1(boost::wsmatch const & what);
static std::wstring replace_cell_range_formater(boost::wsmatch const & what);
//static std::wstring replace_cell_range_formater(boost::wsmatch const & what);
void replace_named_formula(std::wstring & expr, bool w = true);
void replace_named_ref(std::wstring & expr, bool w = true);
bool find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref);
bool find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last);
static bool convert_with_TableName;
static std::wstring table_name_;
static bool convert_with_TableName;
static std::wstring table_name_;
//-------------------------------------------------------------------------------------------------------------
static std::wstring replace_semicolons_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L",";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
else
return L"";
}
static std::wstring replace_tilda_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
else
return L"";
}
static std::wstring replace_vertical_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L"|", L";");
return L"{" + inner + L"}";
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
static void replace_tmp_back(std::wstring &expr)
{
XmlUtils::replace_all( expr, L"ТОСHKA", L".");
XmlUtils::replace_all( expr, L"VOSKL", L"!");
XmlUtils::replace_all( expr, L"SCOBCAIN", L"(");
XmlUtils::replace_all( expr, L"SCOBCAOUT", L")");
XmlUtils::replace_all( expr, L"KVADRATIN", L"[");
XmlUtils::replace_all( expr, L"KVADRATOUT", L"]");
XmlUtils::replace_all( expr, L"PROBEL", L" ");
XmlUtils::replace_all( expr, L"APOSTROF", L"'");
XmlUtils::replace_all( expr, L"KAVYCHKA", L"\"");
}
static void replace_tmp(std::wstring &expr)
{
XmlUtils::replace_all( expr, L".", L"ТОСHKA");
XmlUtils::replace_all( expr, L"!", L"VOSKL");
XmlUtils::replace_all( expr, L"(", L"SCOBCAIN");
XmlUtils::replace_all( expr, L")", L"SCOBCAOUT");
//XmlUtils::replace_all( expr, L"[", L"KVADRATIN");
//XmlUtils::replace_all( expr, L"]", L"KVADRATOUT");
XmlUtils::replace_all( expr, L" ", L"PROBEL");
// XmlUtils::replace_all( expr, L"'", L"APOSTROF");
// XmlUtils::replace_all( expr, L"\"", L"KAVYCHKA");
}
static std::wstring convert_scobci(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
replace_tmp(inner);
return inner;
}
else if (what[2].matched)
{
std::wstring inner = what[2].str();
replace_tmp(inner);
return inner;
}
else if (what[3].matched)
return what[3].str();
return L"";
}
static std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L" ", L",");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
static std::wstring is_forbidden(const std::wstring & formula)
{
std::wstring result = formula;
std::map<std::wstring, std::wstring> forbidden_formulas;
forbidden_formulas.insert(std::make_pair(L"FORMULA", L"_xlfn.FORMULATEXT"));
for (std::map<std::wstring, std::wstring>::iterator it = forbidden_formulas.begin(); it != forbidden_formulas.end(); ++it)
{
if (boost::algorithm::contains(formula, it->first))
{
XmlUtils::replace_all(result, it->first, it->second);
}
}
return result;
}
};
bool odf2oox_converter::Impl::convert_with_TableName = true;
std::wstring odf2oox_converter::Impl::table_name_ = L"";
std::unordered_map<std::wstring, int> &odf2oox_converter::Impl::mapExternalLink_ = oox::xlsx_conversion_context::mapExternalLink_;
bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std::wstring & table,std::wstring & ref_first,std::wstring & ref_last)
{
@ -76,14 +214,14 @@ namespace formulasconvert {
boost::algorithm::split(splitted, expr, boost::algorithm::is_any_of(L".:"), boost::algorithm::token_compress_on);
if (splitted.size()==3)
if (splitted.size() == 3)
{
table = splitted[0];
ref_first = splitted[1];
ref_last = splitted[2];
return true;
}
if (splitted.size()==4)
if (splitted.size() == 4)
{
table = splitted[0];
ref_first = splitted[1];
@ -118,101 +256,92 @@ namespace formulasconvert {
}
std::wstring odf2oox_converter::Impl::replace_cell_range_formater(boost::wsmatch const & what)
{
const size_t sz = what.size();
if (sz == 4 && !what[1].matched)
{
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
else if (sz == 4 && what[1].matched)
{
std::wstring sheet1 = what[1].str();
XmlUtils::replace_all( sheet1, L"$", L"");
//std::wstring odf2oox_converter::Impl::replace_cell_range_formater(boost::wsmatch const & what)
//{
// const size_t sz = what.size();
// if (sz == 4 && !what[1].matched)
// {
// const std::wstring c1 = what[2].str();
// const std::wstring c2 = what[3].str();
// const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// else if (sz == 4 && what[1].matched)
// {
// std::wstring sheet1 = what[1].str();
// XmlUtils::replace_all( sheet1, L"$", L"");
const std::wstring c1 = what[2].str();
std::wstring c2 = what[3].str();
if (c2.empty()) c2 = what[4].str();
const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
return L"";
}
// const std::wstring c1 = what[2].str();
// std::wstring c2 = what[3].str();
// if (c2.empty()) c2 = what[4].str();
// const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// return L"";
//}
std::wstring odf2oox_converter::Impl::replace_named_ref_formater(boost::wsmatch const & what)
{
const size_t sz = what.size();
if (sz == 4 && !what[1].matched)
if (sz < 6) return what[0].str();
std::wstring c0 = what[0].str();
std::wstring external = sz == 7 ? what[1].matched ? what[1].str() : what[2].str() : what[1].str();
std::wstring sheet1 = sz == 7 ? what[3].str() : what[2].str();
std::wstring ref1 = sz == 7 ? what[4].str() : what[3].str();
std::wstring sheet2 = sz == 7 ? what[5].str() : what[4].str();
std::wstring ref2 = sz == 7 ? what[6].str() : what[5].str();
XmlUtils::replace_all( sheet1, L"$", L"");
//XmlUtils::replace_all( sheet2, L"$", L"");
std::wstring result;
if (false == external.empty())
{
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
else if (sz == 4 && what[1].matched)
{
std::wstring sheet1 = what[1].str();
XmlUtils::replace_all( sheet1, L"$", L"");
replace_tmp_back(external);
table_name_ = sheet1;
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
if (convert_with_TableName)
int id = -1;//add_external_link(external);
std::unordered_map<std::wstring, int>::iterator pFind = mapExternalLink_.find(external);
if ( pFind == mapExternalLink_.end())
{
if (std::wstring::npos != sheet1.find(L" "))
{
if (sheet1[0] != L'\'')
{
sheet1 = L"'" + sheet1 + L"'";
}
}
return (sheet1 + L"!") + c1 + (c2.empty() ? L"" : (L":" + c2) );
id = (int)mapExternalLink_.size() + 1;
mapExternalLink_.insert(std::make_pair(external, id));
}
else
{
return c1 + (c2.empty() ? L"" : (L":" + c2) );
id = pFind->second;
}
}
else if (sz == 5 && what[1].matched)
{
std::wstring sheet1 = what[1].str();
XmlUtils::replace_all( sheet1, L"$", L"");
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str(); //sheet name 2
const std::wstring c3 = what[4].str();
table_name_ = sheet1;
if (convert_with_TableName)
if (sheet1[0] == L'\'')
{
return (sheet1 + L"!") + c1 + (c3.empty() ? L"" : (L":" + c3) );
}
else
{
return c1 + (c3.empty() ? L"" : (L":" + c3) );
sheet1 = sheet1.substr(1, sheet1.length() - 2);
}
sheet1 = L"'[" + std::to_wstring(id) + L"]" + sheet1 + L"'";
}
else if (sz == 5 && !what[1].matched)
else if (std::wstring::npos != sheet1.find(L" "))
{
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str(); //sheet name 2
const std::wstring c3 = what[4].str();
return c1 + (c3.empty() ? L"" : (L":" + c3) );
if (sheet1[0] != L'\'')
{
sheet1 = L"'" + sheet1 + L"'";
}
}
table_name_ = sheet1;
if (convert_with_TableName)
{
return (sheet1.empty() ? L"" : (sheet1 + L"!")) + ref1 + (ref2.empty() ? L"" : (L":" + ref2) );
}
else
{
return ref1 + (ref2.empty() ? L"" : (L":" + ref2) );
}
return L"";
}
std::wstring odf2oox_converter::Impl::replace_named_ref_formater1(boost::wsmatch const & what)
{
boost::wregex complexRef(L"\\${0,1}([^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]+\\${0,1}\\d+)(?::\\.(\\${0,1}[\\w^0-9]+\\${0,1}\\d+)){0,1}");
boost::wregex complexRef(L"(?:\'([^\']*)\'#){0,1}\\${0,1}([^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]+\\${0,1}\\d+)(?::\\.(\\${0,1}[\\w^0-9]+\\${0,1}\\d+)){0,1}");
// 'external'# $ Sheet2 . A1 : ( $ Sheet2)? . B5
std::wstring expr = what[1].str();
const std::wstring res = boost::regex_replace(
expr,
@ -233,26 +362,34 @@ namespace formulasconvert {
// [$'Sheet2 A'.$B2] -> 'Sheet2 A'!$B2
void odf2oox_converter::Impl::replace_cells_range(std::wstring& expr, bool withTableName)
{
XmlUtils::replace_all( expr, L"#REF !", L"#REF!");
XmlUtils::replace_all( expr, L"#REF!#REF!", L"#REF!");
XmlUtils::replace_all( expr, L"$#REF!$#REF!", L"#REF!");
convert_with_TableName = withTableName;
boost::wregex complexRef(L"\\[(?:\$)?([^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)(?::(\\${0,1}[^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)){0,1}\\]");
/*
[ $ Sheet2 . A1 : ( $ Sheet2)? . B5 ]
*/
//boost::wregex complexRef(L"\\[(?:\'([^\']*)\'#){0,1}\\[{0,1}(?:\\$){0,1}([^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)(?::(\\${0,1}[^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)){0,1}\\]{0,1}");
boost::wregex complexRef(L"(?:(?:(?:(?:\\[\'([^\']*)\'#)|(?:\'([^\']*)\'#\\[)))|(?:\\[))\
(?:\\$){0,1}([^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)(?::(\\${0,1}[^\\.]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)){0,1}\\]");
// [ 'external'# [ $ Sheet2 . A1 : ( $ Sheet2)? . B5 ]
const std::wstring res = boost::regex_replace(
expr,
expr = boost::regex_replace(
expr,
complexRef,
&replace_named_ref_formater,
boost::match_default | boost::format_all);
expr = res;
}
void odf2oox_converter::Impl::replace_named_ref(std::wstring & expr, bool withTableName)
{
XmlUtils::replace_all( expr, L"#REF !", L"#REF!");
XmlUtils::replace_all( expr, L"#REF!#REF!", L"#REF!");
XmlUtils::replace_all( expr, L"$#REF!$#REF!", L"#REF!");
convert_with_TableName = withTableName;
//boost::wregex complexRef(L"\\${0,1}([^\\.]+?){0,1}\\.(\\${0,1}[a-zA-Z]+\\${0,1}\\d+)(?::\\.(\\${0,1}[a-zA-Z]+\\${0,1}\\d+)){0,1}");
boost::wregex complexRef(L"\\${0,1}([^\\.\\s]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)(?::\\${0,1}([^\\.\\s]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)){0,1}");
boost::wregex complexRef(L"\\[{0,1}(?:\'([^\']*)\'#){0,1}\\${0,1}([^\\.\\s]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)(?::\\${0,1}([^\\.\\s]+?){0,1}\\.(\\${0,1}[\\w^0-9]*\\${0,1}\\d*)){0,1}\\]{0,1}");
// 'external'# $ Sheet2 . A1 : ( $ Sheet2)? . B5
const std::wstring res = boost::regex_replace(
expr,
@ -281,29 +418,7 @@ namespace formulasconvert {
}
std::wstring replace_semicolons_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L",";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
else
return L"";
}
std::wstring replace_tilda_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
else
return L"";
}
// TODO
// заменить точки с запятой во всех вхождениях кроме находящихся в кавычках --*и в фигурных скобках*--
void odf2oox_converter::Impl::replace_semicolons(std::wstring& expr)
{
@ -327,140 +442,6 @@ namespace formulasconvert {
expr = res;
}
std::wstring replace_vertical_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L"|", L";");
return L"{" + inner + L"}";
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
std::wstring replace_point_space(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L" ", L"PROBEL");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
void odf_replace_tmp_back(std::wstring &expr)
{
XmlUtils::replace_all( expr, L"ТОСHKA", L".");
XmlUtils::replace_all( expr, L"VOSKL", L"!");
XmlUtils::replace_all( expr, L"SCOBCAIN", L"(");
XmlUtils::replace_all( expr, L"SCOBCAOUT", L")");
XmlUtils::replace_all( expr, L"KVADRATIN", L"[");
XmlUtils::replace_all( expr, L"KVADRATOUT", L"]");
XmlUtils::replace_all( expr, L"PROBEL", L" ");
XmlUtils::replace_all( expr, L"APOSTROF", L"'");
XmlUtils::replace_all( expr, L"KAVYCHKA", L"\"");
}
void odf_replace_tmp(std::wstring &expr)
{
XmlUtils::replace_all( expr, L".", L"ТОСHKA");
XmlUtils::replace_all( expr, L"!", L"VOSKL");
XmlUtils::replace_all( expr, L"(", L"SCOBCAIN");
XmlUtils::replace_all( expr, L")", L"SCOBCAOUT");
XmlUtils::replace_all( expr, L"[", L"KVADRATIN");
XmlUtils::replace_all( expr, L"]", L"KVADRATOUT");
XmlUtils::replace_all( expr, L" ", L"PROBEL");
XmlUtils::replace_all( expr, L"'", L"APOSTROF");
XmlUtils::replace_all( expr, L"\"", L"KAVYCHKA");
}
std::wstring convert_scobci(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
odf_replace_tmp(inner);
return inner;
}
else if (what[2].matched)
{
std::wstring inner = what[2].str();
odf_replace_tmp(inner);
return inner;
}
else if (what[3].matched)
return what[3].str();
return L"";
}
std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L" ", L",");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
//std::wstring forbidden_formulas[] =
//{
// L"NULLFORMULA"
// //L"BETADIST",
// //L"CEILING",
// //L"FLOOR",
// //L"RANK",
// //L"ROUND",
// //L"ROUNDDOWN",
// //L"ROUNDUP",
// //L"SUBTOTAL",
// //L"FORMULA",
// //L"ISREF"
//};
std::wstring is_forbidden(const std::wstring & formula)
{
std::wstring result = formula;
std::map<std::wstring, std::wstring> forbidden_formulas;
forbidden_formulas.insert(std::make_pair(L"FORMULA", L"_xlfn.FORMULATEXT"));
for (std::map<std::wstring, std::wstring>::iterator it = forbidden_formulas.begin(); it != forbidden_formulas.end(); ++it)
{
if (boost::algorithm::contains(formula, it->first))
{
XmlUtils::replace_all(result, it->first, it->second);
}
}
return result;
}
// заменить вертикальную черту во всех вхождениях в фигурных скобках, но не внутри строк
void odf2oox_converter::Impl::replace_vertical(std::wstring& expr)
{
@ -485,17 +466,11 @@ namespace formulasconvert {
std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
{
std::wstring workstr = is_forbidden(expr);
//boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// Better_Donut.ods- cell(c27)
//std::wstring workstr = boost::regex_replace(
// expr,
// complexRef,
// &replace_point_space,
// boost::match_default | boost::format_all);
bool isFormula = check_formula(workstr);
boost::regex_replace(
workstr,
//экранирование
workstr = boost::regex_replace(workstr,
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
@ -526,28 +501,23 @@ namespace formulasconvert {
//-----------------------------------------------------------
odf_replace_tmp_back(workstr);
replace_tmp_back(workstr);
return workstr;
}
void odf2oox_converter::Impl::split_distance_by(const std::wstring& expr, const std::wstring& by, std::vector<std::wstring>& out)
{
std::wstring workstr = expr;
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
workstr = boost::regex_replace(
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_space,
boost::match_default | boost::format_all);
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
boost::algorithm::split(out, workstr, boost::algorithm::is_any_of(by), boost::algorithm::token_compress_on);
for (size_t i = 0; i < out.size(); i++)
{
XmlUtils::replace_all( out[i], L"PROBEL", L" ");
XmlUtils::replace_all( out[i], L"TOCHKA", L".");
replace_tmp_back(out[i]);
}
}
@ -557,15 +527,10 @@ namespace formulasconvert {
std::wstring odf2oox_converter::Impl::convert_chart_distance(const std::wstring& expr)
{
std::wstring workstr = is_forbidden(expr);
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_space,
boost::match_default | boost::format_all);
std::wstring workstr = boost::regex_replace(
is_forbidden(expr),
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
//распарсить по диапазонам - одф-пробел, ик-эль-запятая
@ -597,10 +562,10 @@ namespace formulasconvert {
cells_out.append(cells[j]);
cells_out.append(L":");
}
int res1 = sheet.find(L"-");
int res2 = sheet.find(L"'");
size_t res1 = sheet.find(L"-");
size_t res2 = sheet.find(L"'");
if (res1 >= 0 && !(res2 == 0))
if (res1 != std::wstring::npos && res2 != std::wstring::npos && !(res2 == 0))
{
sheet = L"'" + sheet + L"'";
}
@ -614,12 +579,78 @@ namespace formulasconvert {
result.append(distance_out[i]);
result.append(L",");
}
XmlUtils::replace_all( result, L"PROBEL" , L" ");
XmlUtils::replace_all( result, L"TOCHKA", L".");
replace_tmp_back( result );
return result.substr(0, result.size() - 1);// минус последняя лишняя запятая
}
odf2oox_converter::odf2oox_converter(): impl_(new odf2oox_converter::Impl)
std::wstring odf2oox_converter::Impl::convert_named_ref(const std::wstring& expr, bool withTableName, std::wstring separator)
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
std::wstring workstr = expr;
workstr = boost::regex_replace(
workstr,
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
replace_named_ref(workstr, withTableName);
if (separator != L" ")
{
XmlUtils::replace_all( workstr, L" ", separator);
}
replace_tmp_back( workstr );
if (table_name_.empty() == false)
{
replace_tmp_back( table_name_ );
}
return workstr;
}
std::wstring odf2oox_converter::Impl::convert_named_expr(const std::wstring& expr, bool withTableName)
{
std::wstring workstr = expr;
bool isFormula = check_formula(workstr);
if (isFormula)
{
workstr = convert(expr);
}
else
{
workstr = boost::regex_replace(
workstr,
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
replace_cells_range(workstr, withTableName);
replace_semicolons(workstr);
replace_vertical(workstr);
size_t res_find = 0;
if ((res_find = workstr.find(L"CONCATINATE")) != std::wstring::npos)
{
//могут быть частично заданы диапазоны
//todooo
}
replace_tmp_back(workstr);
if (table_name_.empty() == false)
{
replace_tmp_back(table_name_);
}
}
return workstr;
}
//------------------------------------------------------------------------------------------------------------
odf2oox_converter::odf2oox_converter() : impl_(new odf2oox_converter::Impl())
{
}
@ -646,82 +677,11 @@ namespace formulasconvert {
}
std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr, bool withTableName, std::wstring separator)
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_space,
boost::match_default | boost::format_all);
XmlUtils::replace_all( workstr, L"'", L"APOSTROF");
//XmlUtils::replace_all( workstr, L"", L"APOSTROF");
impl_->replace_named_ref(workstr, withTableName);
if (separator != L" ")
{
XmlUtils::replace_all( workstr, L" " , separator);
}
XmlUtils::replace_all( workstr, L"PROBEL" , L" ");
XmlUtils::replace_all( workstr, L"APOSTROF" , L"'");
XmlUtils::replace_all( workstr, L"TOCHKA" , L".");
if (impl_->table_name_.empty() == false)
{
XmlUtils::replace_all( impl_->table_name_, L"PROBEL" , L" ");
XmlUtils::replace_all( impl_->table_name_, L"APOSTROF" , L"'");
XmlUtils::replace_all( impl_->table_name_, L"TOCHKA" , L".");
}
return workstr;
return impl_->convert_named_ref(expr, withTableName, separator);
}
std::wstring odf2oox_converter::convert_named_expr(const std::wstring& expr, bool withTableName)
{
std::wstring workstr = expr;
bool isFormula = impl_->check_formula(workstr);
if (isFormula)
{
workstr = impl_->convert(expr);
}
else
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
workstr = boost::regex_replace(
workstr,
complexRef,
&replace_point_space,
boost::match_default | boost::format_all);
XmlUtils::replace_all( workstr, L"'", L"APOSTROF");
impl_->replace_cells_range(workstr, withTableName);
impl_->replace_semicolons(workstr);
impl_->replace_vertical(workstr);
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
{
//могут быть частично заданы диапазоны
//todooo
}
XmlUtils::replace_all( workstr, L"PROBEL" , L" ");
XmlUtils::replace_all( workstr, L"APOSTROF" , L"'");
XmlUtils::replace_all( workstr, L"TOCHKA" , L".");
if (impl_->table_name_.empty() == false)
{
XmlUtils::replace_all( impl_->table_name_, L"PROBEL" , L" ");
XmlUtils::replace_all( impl_->table_name_, L"APOSTROF" , L"'");
XmlUtils::replace_all( impl_->table_name_, L"TOCHKA" , L".");
}
}
return workstr;
return impl_->convert_named_expr(expr, withTableName);
}
std::wstring odf2oox_converter::convert_ref(std::wstring const & expr)
@ -734,8 +694,8 @@ namespace formulasconvert {
{
while(true)
{
int pos = expr.find(L"%20");
if (pos <0)break;
size_t pos = expr.find(L"%20");
if (pos == std::wstring::npos)break;
expr.replace(pos,3,L" ");
}

View File

@ -39,6 +39,22 @@
namespace cpdoccore {
namespace formulasconvert {
static std::wstring forbidden_formulas1[] =
{
L"NULLFORMULA()"
/*
L"BETADIST",
L"CEILING",
L"FLOOR",
L"RANK",
L"ROUND",
L"ROUNDDOWN",
L"ROUNDUP",
L"SUBTOTAL",
L"FORMULA",
L"ISREF"*/
};
class oox2odf_converter::Impl
{
public:
@ -59,7 +75,104 @@ public:
static std::wstring replace_arguments(boost::wsmatch const & what);
static std::wstring convert_scobci(boost::wsmatch const & what);
void replace_named_ref(std::wstring & expr);
static std::wstring replace_tilda_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
//else if (what[4].matched)
// return what[4].str();
else
return L"";
}
static std::wstring replace_semicolons_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
//else if (what[4].matched)
// return what[4].str();
else
return L"";
}
static std::wstring replace_vertical_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L";", L"|");
return L"{" + inner + L"}";
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
static std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L",", L" ");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
static void oox_replace_tmp_back(std::wstring &expr)
{
XmlUtils::replace_all( expr, L"ТОСHKA", L".");
XmlUtils::replace_all( expr, L"VOSKL", L"!");
XmlUtils::replace_all( expr, L"SCOBCAIN", L"(");
XmlUtils::replace_all( expr, L"SCOBCAOUT", L")");
XmlUtils::replace_all( expr, L"KVADRATIN", L"[");
XmlUtils::replace_all( expr, L"KVADRATOUT", L"]");
XmlUtils::replace_all( expr, L"PROBEL", L" ");
XmlUtils::replace_all( expr, L"APOSTROF", L"'");
XmlUtils::replace_all( expr, L"KAVYCHKA", L"\"");
}
static void oox_replace_tmp(std::wstring &expr)
{
XmlUtils::replace_all( expr, L".", L"ТОСHKA");
XmlUtils::replace_all( expr, L"!", L"VOSKL");
XmlUtils::replace_all( expr, L"(", L"SCOBCAIN");
XmlUtils::replace_all( expr, L")", L"SCOBCAOUT");
XmlUtils::replace_all( expr, L"[", L"KVADRATIN");
XmlUtils::replace_all( expr, L"]", L"KVADRATOUT");
XmlUtils::replace_all( expr, L" ", L"PROBEL");
XmlUtils::replace_all( expr, L"'", L"APOSTROF");
XmlUtils::replace_all( expr, L"\"", L"KAVYCHKA");
}
static bool is_forbidden1(const std::wstring & formula)
{
for (size_t i = 0; i < 1; i++)
{
if (boost::algorithm::contains(formula, forbidden_formulas1[i]))
return true;
}
return false;
}
void replace_named_ref(std::wstring & expr);
void replace_named_formula(std::wstring & expr);
static bool isFindBaseCell_;
@ -69,37 +182,7 @@ public:
bool oox2odf_converter::Impl::isFindBaseCell_ = false;
std::wstring oox2odf_converter::Impl::table_name_ = L"";
void oox_replace_tmp_back(std::wstring &expr)
{
XmlUtils::replace_all( expr, L"ТОСHKA", L".");
XmlUtils::replace_all( expr, L"VOSKL", L"!");
XmlUtils::replace_all( expr, L"SCOBCAIN", L"(");
XmlUtils::replace_all( expr, L"SCOBCAOUT", L")");
XmlUtils::replace_all( expr, L"KVADRATIN", L"[");
XmlUtils::replace_all( expr, L"KVADRATOUT", L"]");
XmlUtils::replace_all( expr, L"PROBEL", L" ");
XmlUtils::replace_all( expr, L"APOSTROF", L"'");
XmlUtils::replace_all( expr, L"KAVYCHKA", L"\"");
}
void oox_replace_tmp(std::wstring &expr)
{
XmlUtils::replace_all( expr, L".", L"ТОСHKA");
XmlUtils::replace_all( expr, L"!", L"VOSKL");
XmlUtils::replace_all( expr, L"(", L"SCOBCAIN");
XmlUtils::replace_all( expr, L")", L"SCOBCAOUT");
XmlUtils::replace_all( expr, L"[", L"KVADRATIN");
XmlUtils::replace_all( expr, L"]", L"KVADRATOUT");
XmlUtils::replace_all( expr, L" ", L"PROBEL");
XmlUtils::replace_all( expr, L"'", L"APOSTROF");
XmlUtils::replace_all( expr, L"\"", L"KAVYCHKA");
}
void oox2odf_converter::Impl::replace_cells_range(std::wstring& expr)
{
if ((0 == expr.find(L"KAVYCHKA")) && (expr.length() - 8 == expr.rfind(L"KAVYCHKA") ))
@ -203,7 +286,6 @@ void oox2odf_converter::Impl::replace_named_formula(std::wstring & expr)
isFindBaseCell_ = false;
}
// Лист1!$A$1 -> $Лист1.$A$1
void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
{
table_name_.clear();
@ -245,38 +327,6 @@ void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
}
namespace
{
std::wstring replace_tilda_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
//else if (what[4].matched)
// return what[4].str();
else
return L"";
}
std::wstring replace_semicolons_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
//else if (what[4].matched)
// return what[4].str();
else
return L"";
}
}
// TODO
// заменить запятые на точки с запятой во всех вхождениях кроме находящихся в кавычках --*и в фигурных скобках*--
@ -291,67 +341,8 @@ void oox2odf_converter::Impl::replace_semicolons(std::wstring& expr)
boost::match_default | boost::format_all);
expr = res;
}
namespace
{
std::wstring replace_vertical_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L";", L"|");
return L"{" + inner + L"}";
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L",", L" ");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
}
std::wstring forbidden_formulas1[] =
{
L"NULLFORMULA()"
/*
L"BETADIST",
L"CEILING",
L"FLOOR",
L"RANK",
L"ROUND",
L"ROUNDDOWN",
L"ROUNDUP",
L"SUBTOTAL",
L"FORMULA",
L"ISREF"*/
};
bool is_forbidden1(const std::wstring & formula)
{
for (size_t i = 0; i < 1; i++)
{
if (boost::algorithm::contains(formula, forbidden_formulas1[i]))
return true;
}
return false;
}
//void oox2odf_converter::Impl::split_(std::wstring& expr)
//{
// const std::wstring res = boost::regex_split(
@ -382,22 +373,6 @@ void oox2odf_converter::Impl::replace_space(std::wstring& expr)
expr = res;
}
std::wstring replace_(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
XmlUtils::replace_all( inner, L",", L" ");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
return L"";
}
std::wstring oox2odf_converter::Impl::convert_scobci(boost::wsmatch const & what)
{
if (what[1].matched)

View File

@ -117,9 +117,9 @@ public:
}
static RelsType detectMediaType(const std::wstring & fileName)
{
int pos = fileName.rfind(L".");
size_t pos = fileName.rfind(L".");
std::wstring sExt = (pos >=0 ? fileName.substr(pos + 1) : L"");
std::wstring sExt = (pos != std::wstring::npos ? fileName.substr(pos + 1) : L"");
if (sExt.empty()) return typeMedia;

View File

@ -245,12 +245,16 @@ void oox_serialize_aLst(std::wostream & strm, const std::vector<odf_reader::_pro
{
names.push_back(L"adj1");
}
else if (std::wstring::npos != shapeGeomPreset.find(L"heptagon") ||
std::wstring::npos != shapeGeomPreset.find(L"decagon"))
{
values.clear();
}
//else if (std::wstring::npos != shapeGeomPreset.find(L"decagon"))
//{
// names.push_back(L"vf");
//}
//else if (std::wstring::npos != shapeGeomPreset.find(L"heptagon") ||
// std::wstring::npos != shapeGeomPreset.find(L"pentagon"))
//else if (std::wstring::npos != shapeGeomPreset.find(L"pentagon"))
//{
// names.push_back(L"hf");
// names.push_back(L"vf");

View File

@ -45,13 +45,6 @@ class xlsx_defined_names::Impl
public:
void add(std::wstring const & name, std::wstring const & ref, bool formula, int tableId)
{
int is_file_link = 0;
if (!formula)
{
if ((is_file_link = ref.find(L"\\")) >=0) return;
if ((is_file_link = ref.find(L"/")) >=0) return;
}
formulasconvert::odf2oox_converter converter;
std::wstring oox_ref;
@ -72,34 +65,31 @@ public:
void xlsx_serialize(std::wostream & _Wostream)
{
if (content_.size() > 0)
if (content_.empty()) return;
CP_XML_WRITER(_Wostream)
{
CP_XML_WRITER(_Wostream)
CP_XML_NODE(L"definedNames")
{
CP_XML_NODE(L"definedNames")
for (size_t i = 0 ; i < content_.size(); i++)
{
for (size_t i = 0 ; i < content_.size(); i++)
CP_XML_NODE(L"definedName")
{
CP_XML_NODE(L"definedName")
{
CP_XML_ATTR(L"name", content_[i].name);
if (content_[i].tableId >= 0)
{
CP_XML_ATTR(L"localSheetId", content_[i].tableId);
}
int pos;
if ( (pos = content_[i].ref.find(L"#REF!")) >= 0 )
{
CP_XML_ATTR(L"comment", content_[i].ref);
CP_XML_CONTENT(L"#REF!");
}
else
CP_XML_CONTENT(content_[i].ref);
CP_XML_ATTR(L"name", content_[i].name);
if (content_[i].tableId >= 0)
{
CP_XML_ATTR(L"localSheetId", content_[i].tableId);
}
if ( content_[i].ref.find(L"#REF!") != std::wstring::npos )
{
CP_XML_ATTR(L"comment", content_[i].ref);
CP_XML_CONTENT(L"#REF!");
}
else
CP_XML_CONTENT(content_[i].ref);
}
}
}
}

View File

@ -46,7 +46,6 @@ namespace oox {
xlsx_defined_names();
~xlsx_defined_names();
public:
void add(std::wstring const & name, std::wstring const & ref, bool formula, int tableId);
void xlsx_serialize(std::wostream & _Wostream);

View File

@ -211,13 +211,6 @@ void xlsx_xml_worksheet::write_to(std::wostream & strm)
CP_XML_STREAM() << impl_->drawing_.str();
if (!impl_->tableParts_.str().empty())
{
CP_XML_NODE(L"tableParts")
{
CP_XML_STREAM() << impl_->tableParts_.str();
}
}
if (!impl_->commentsId_.empty())
{
CP_XML_NODE(L"legacyDrawing")
@ -239,6 +232,13 @@ void xlsx_xml_worksheet::write_to(std::wostream & strm)
CP_XML_STREAM() << impl_->controls_.str();
}
}
if (!impl_->tableParts_.str().empty())
{
CP_XML_NODE(L"tableParts")
{
CP_XML_STREAM() << impl_->tableParts_.str();
}
}
CP_XML_STREAM() << impl_->picture_background_.str();
//CP_XML_NODE(L"headerFooter){}

View File

@ -88,7 +88,6 @@ void xlsx_document::write(const std::wstring & RootPath)
pivot_cache_content::pivot_cache_content() : definitions_rels_file_(rels_file::create(L""))
{
}
_CP_PTR(pivot_cache_content) pivot_cache_content::create()
{
return boost::make_shared<pivot_cache_content>();
@ -97,17 +96,23 @@ _CP_PTR(pivot_cache_content) pivot_cache_content::create()
pivot_table_content::pivot_table_content() : rels_file_(rels_file::create(L""))
{
}
_CP_PTR(pivot_table_content) pivot_table_content::create()
{
return boost::make_shared<pivot_table_content>();
}
//--------------------------------------------------------------------------------------------
external_links_content::external_links_content() : rels_file_(rels_file::create(L""))
{
}
_CP_PTR(external_links_content) external_links_content::create()
{
return boost::make_shared<external_links_content>();
}
//--------------------------------------------------------------------------------------------
sheet_content::sheet_content() : rels_(rels_file::create(L""))
{
}
_CP_PTR(sheet_content) sheet_content::create()
{
return boost::make_shared<sheet_content>();
@ -198,8 +203,11 @@ void xl_files::write(const std::wstring & RootPath)
control_props_files_.set_main_document( this->get_main_document() );
control_props_files_.write(path);
}
int index = 1;
if (true)
{
external_links_files_.set_rels(&rels_files_);
external_links_files_.set_main_document(get_main_document());
external_links_files_.write(path);
}
{
//workbook_->hyperlinks->write(path);
rels_files_.add( relationship( L"hId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", L"xl/workbook.xml" ) );
@ -217,7 +225,6 @@ void xl_files::write(const std::wstring & RootPath)
content_type * contentTypes = this->get_main_document()->get_content_types_file().content();
contentTypes->add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml");
}
if (styles_)
{
styles_->write(path);
@ -249,6 +256,7 @@ void xl_files::write(const std::wstring & RootPath)
table_part_files_.set_main_document(get_main_document());
table_part_files_.write(path);
}
if (drawings_)
{
drawings_->set_main_document(get_main_document());
@ -338,6 +346,10 @@ void xl_files::add_control_props (simple_element_ptr element)
{
control_props_files_.add_control_props(element);
}
void xl_files::add_external_links(external_links_content_ptr content)
{
external_links_files_.add_external_links(content);
}
//----------------------------------------------------------------------------------------
void xl_pivot_cache_files::add_pivot_cache(pivot_cache_content_ptr pivot_cache)
{
@ -426,6 +438,44 @@ void xl_pivot_table_files::write(const std::wstring & RootPath)
}
}
//------------------------------------------------------------------------------------------------------
void xl_external_links_files::add_external_links(external_links_content_ptr content)
{
external_links_.push_back(content);
}
void xl_external_links_files::write(const std::wstring & RootPath)
{
if (external_links_.empty()) return;
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"externalLinks";
NSDirectory::CreateDirectory(path.c_str());
for (size_t i = 0; i < external_links_.size(); i++)
{
const std::wstring fileName = std::wstring(L"externalLink") + std::to_wstring(i + 1) + L".xml";
content_type * contentTypes = this->get_main_document()->get_content_types_file().content();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml";
contentTypes->add_override(std::wstring(L"/xl/externalLinks/") + fileName, kWSConType);
package::simple_element(fileName, external_links_[i]->content_.str()).write(path);
{
rels_files relFiles;
external_links_[i]->rels_file_->set_file_name(fileName + L".rels");
relFiles.add_rel_file(external_links_[i]->rels_file_);
relFiles.write(path);
}
if (rels_)
{
static const std::wstring kWSRel = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink";
const std::wstring fileRef = std::wstring(L"externalLinks/") + fileName;
rels_->add(external_links_[i]->rId_, kWSRel, fileRef);
}
}
}
//------------------------------------------------------------------------------------------------------
void xl_table_part_files::add_table_part(const std::wstring & table_part)
{
table_parts_.push_back(table_part);

View File

@ -72,6 +72,7 @@ typedef _CP_PTR(sheet_content) sheet_content_ptr;
//------------------------------------------------------------------------
class pivot_cache_content;
typedef _CP_PTR(pivot_cache_content) pivot_cache_content_ptr;
class pivot_cache_content : boost::noncopyable
{
public:
@ -94,6 +95,7 @@ private:
//------------------------------------------------------------------------
class pivot_table_content;
typedef _CP_PTR(pivot_table_content) pivot_table_content_ptr;
class pivot_table_content : boost::noncopyable
{
public:
@ -111,6 +113,28 @@ private:
rels_file_ptr rels_file_;
};
//------------------------------------------------------------------------
class external_links_content;
typedef _CP_PTR(external_links_content) external_links_content_ptr;
class external_links_content : boost::noncopyable
{
public:
external_links_content();
static external_links_content_ptr create();
std::wstring & rId() { return rId_;}
std::wostream & content() { return content_; }
rels & get_rels() { return rels_file_->get_rels(); }
std::wstring str() { return content_.str(); }
friend class xl_external_links_files;
private:
std::wstringstream content_;
rels_file_ptr rels_file_;
std::wstring rId_;
};
//------------------------------------------------------------------------
class sheets_files : public element
{
public:
@ -153,7 +177,22 @@ public:
std::vector<chart_content_ptr> charts_;
};
class xl_external_links_files : public element
{
public:
xl_external_links_files(){}
void add_external_links(external_links_content_ptr content);
virtual void write(const std::wstring & RootPath);
void set_rels(rels_files * rels)
{
rels_ = rels;
}
private:
std::vector<external_links_content_ptr> external_links_;
rels_files * rels_;
};
class xl_pivot_table_files : public element
{
public:
@ -255,6 +294,7 @@ public:
void add_jsaProject (const std::string &content);
void add_control_props (simple_element_ptr Element);
void add_table_part (const std::wstring &content);
void add_external_links (external_links_content_ptr content);
private:
rels_files rels_files_;
@ -264,7 +304,8 @@ private:
xl_pivot_table_files pivot_table_files_;
xl_control_props_files control_props_files_;
xl_table_part_files table_part_files_;
xl_external_links_files external_links_files_;
element_ptr theme_;
element_ptr workbook_;
@ -289,7 +330,7 @@ public:
virtual content_types_file & get_content_types_file() { return content_type_file_; }
xl_files & get_xl_files() { return xl_files_; }
rels_files & get_rels_files() { return rels_files_; }
private:
xlsx_content_types_file content_type_file_;
xl_files xl_files_;

View File

@ -302,12 +302,24 @@ void xlsx_pivots_context::Impl::calc_headers()
std::map<size_t, size_t>::iterator pFind;
//current_.bAxisCol = false;
//current_.bAxisRow = false;
size_t min_col = 0xffffff, min_row = 0xffffff;
size_t prev_col, prev_row;
for (size_t i = 0; i < current_.headers.size(); i++)//("F18","F19","F23","G21","H21")
{
size_t row = 0, col = 0;
oox::getCellAddressInv(current_.headers[i], col, row);
//if (i > 0)
//{
// if (col != prev_col)current_.bAxisCol = true;
// if (row != prev_row)current_.bAxisRow = true;
//}
prev_col = col;
prev_row = row;
if (col < min_col) min_col = col;
if (row < min_row) min_row = row;
@ -578,11 +590,17 @@ void xlsx_pivots_context::Impl::sort_fields()
i--;
}
}
if ((bAddRepeateCol || (count_items_col == 0 && current_.bAxisCol))/* && bShowEmptyCol*/) ///* || (bEmptyColCache && current_.grand_total < 0)*/?? Financial Execution (template).ods
bool data_col_repeate = false;
if ((bAddRepeateRow || (count_items_row == 0 && current_.bAxisRow)) && (current_.grand_total == 1 || current_.grand_total == 3 || current_.data_on_row))/* && bShowEmptyRow*/
{
current_.row_fields.push_back(-2);
data_col_repeate = true;
}
if (!data_col_repeate && (bAddRepeateCol || (count_items_col == 0 && current_.bAxisCol)) && (current_.grand_total == 1 || current_.grand_total == 2 || current_.data_fields.size() > 1 ))/* && bShowEmptyCol*/ ///* || (bEmptyColCache && current_.grand_total < 0)*/?? Financial Execution (template).ods
current_.col_fields.push_back(-2);
if ((bAddRepeateRow || (count_items_row == 0 && current_.bAxisRow))/* && bShowEmptyRow*/)
current_.row_fields.push_back(-2);
}
void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
{

View File

@ -81,8 +81,8 @@ void xlsx_data_range::serialize_sort (std::wostream & _Wostream)
std::wstring ref1, ref2;
size_t col_1, row_1, col_2, row_2;
int pos = ref.find(L":");
if (pos >= 0)
size_t pos = ref.find(L":");
if (pos != std::wstring::npos)
{
ref1 = ref.substr(0, pos );
ref2 = ref.substr(pos + 1);

View File

@ -53,42 +53,20 @@ typedef _CP_PTR(xlsx_table_state) xlsx_table_state_ptr;
class xlsx_data_range;
typedef _CP_PTR(xlsx_data_range) xlsx_data_range_ptr;
class xlsx_data_range_values;
typedef _CP_PTR(xlsx_data_range_values) xlsx_data_range_values_ptr;
class xlsx_data_range_values
{
public:
xlsx_data_range_values(size_t row, size_t col1, size_t col2) : row_header(row), start_column(col1), end_column(col2) {}
size_t row_header;
size_t start_column;
size_t end_column;
std::vector<std::wstring> values;
void set_value(size_t col, size_t row, const std::wstring& value)
{
while (col - start_column + 1 > values.size())
values.push_back(L"");
values[col - start_column] = value;
}
bool in_range(size_t col, size_t row) {return (row_header == row && (col >= start_column && col <= end_column));}
};
class xlsx_data_range
{
public:
xlsx_data_range() : byRow(true), filter(false), withHeader(false), cell_start(0,0), cell_end(0,0) {}
xlsx_data_range() : byRow(true), filter(false), bTablePart(true), withHeader(false), cell_start(0,0), cell_end(0,0) {}
std::wstring table_name;
std::wstring name;
std::wstring ref;
std::pair<int, int> cell_start;
std::pair<int, int> cell_end;
bool bTablePart;
bool byRow;
bool filter;
bool withHeader;
@ -97,6 +75,33 @@ public:
void serialize_sort (std::wostream & _Wostream);
void serialize_autofilter (std::wostream & _Wostream);
size_t row_header;
size_t start_column_header;
size_t end_column_header;
std::vector<std::wstring> header_values;
void set_header(size_t row, size_t col1, size_t col2)
{
row_header = row;
start_column_header = col1;
end_column_header = col2;
for (size_t i = start_column_header; i <= end_column_header; i++)
header_values.push_back(L"");
}
void set_header_value(size_t col, size_t row, const std::wstring& value)
{
while (col - start_column_header + 1 >= header_values.size())
header_values.push_back(L"");
header_values[col - start_column_header] = value;
}
bool in_header(size_t col, size_t row)
{
return (row_header == row && (col >= start_column_header && col <= end_column_header));
}
};
class xlsx_table_state

View File

@ -60,23 +60,20 @@ xlsx_table_state_ptr xlsx_table_context::state()
return xlsx_table_state_ptr();
}
void xlsx_table_context::start_database_range(std::wstring tableName, std::wstring ref)
bool xlsx_table_context::start_database_range(const std::wstring & name, const std::wstring & ref)
{
formulasconvert::odf2oox_converter convert;
ref = convert.convert_named_ref(ref);
std::wstring oox_ref = convert.convert_named_ref(ref);
std::wstring ref1, ref2;
size_t pos = ref.find(L":");
size_t pos = oox_ref.find(L":");
std::wstring xlsx_table_name;
if (pos != std::wstring::npos)
{
xlsx_data_ranges_.push_back(xlsx_data_range_ptr(new xlsx_data_range()));
xlsx_data_ranges_.back()->table_name = tableName;
ref1 = ref.substr(0, pos );
ref2 = ref.substr(pos + 1);
ref1 = oox_ref.substr(0, pos );
ref2 = oox_ref.substr(pos + 1);
pos = ref1.find(L"!");
if (pos > 0)
@ -88,25 +85,33 @@ void xlsx_table_context::start_database_range(std::wstring tableName, std::wstri
pos = ref2.find(L"!");
if (pos > 0) ref2 = ref2.substr(pos + 1);
xlsx_data_ranges_.back()->ref = ref1 + L":" + ref2;
size_t col1, col2, row1, row2;
getCellAddressInv(ref1, col1, row1);
xlsx_data_ranges_.back()->cell_start = std::pair<int, int>(col1, row1);
XmlUtils::replace_all( xlsx_table_name, L"'", L"");
getCellAddressInv(ref1, col1, row1);
getCellAddressInv(ref2, col2, row2);
xlsx_data_ranges_.push_back(xlsx_data_range_ptr(new xlsx_data_range()));
if (/*name.find(L"__Anonymous_Sheet_DB__") != std::wstring::npos ||*/ col1 == col2)
{//check range in pivots
xlsx_data_ranges_.back()->bTablePart = false;
}
xlsx_data_ranges_.back()->name = name;
xlsx_data_ranges_.back()->table_name = xlsx_table_name;
xlsx_data_ranges_.back()->ref = ref1 + L":" + ref2;
xlsx_data_ranges_.back()->cell_start = std::pair<int, int>(col1, row1);
xlsx_data_ranges_.back()->cell_end = std::pair<int, int>(col2, row2);
xlsx_data_ranges_values_.push_back(xlsx_data_range_values_ptr(new xlsx_data_range_values(row1, col1, col2)));
xlsx_data_ranges_.back()->set_header(row1, col1, col2);
}
if (!xlsx_table_name.empty())
{
XmlUtils::replace_all( xlsx_table_name, L"'", L"");
xlsx_data_ranges_map_.insert(std::pair<std::wstring, int> (xlsx_table_name, xlsx_data_ranges_.size() - 1));
}
return true;
}
void xlsx_table_context::set_database_orientation (bool val)
{
@ -132,20 +137,55 @@ void xlsx_table_context::end_database_range()
void xlsx_table_context::set_database_range_value(int index, const std::wstring& value)
{
if (index < 0 || index > xlsx_data_ranges_.size()) return;
size_t col = state()->current_column();
size_t row = state()->current_row();
xlsx_data_ranges_values_[index]->set_value(col, row, value);
xlsx_data_ranges_[index]->set_header_value(col, row, value);
}
void xlsx_table_context::check_database_range_intersection(const std::wstring& table_name, const std::wstring& ref)
{
std::wstring ref1, ref2;
size_t col_1, row_1, col_2, row_2;
size_t pos = ref.find(L":");
if (pos != std::wstring::npos)
{
ref1 = ref.substr(0, pos );
ref2 = ref.substr(pos + 1);
}
getCellAddressInv(ref1, col_1, row_1);
getCellAddressInv(ref2, col_2, row_2);
for (size_t i = 0; i < xlsx_data_ranges_.size(); i++)
{
if (xlsx_data_ranges_[i]->table_name != table_name) continue;
//if ( xlsx_data_ranges_[i]->cell_start.second < row_2 || xlsx_data_ranges_[i]->cell_end.second > row_1
// || xlsx_data_ranges_[i]->cell_end.first < col_1 || xlsx_data_ranges_[i]->cell_start.first > col_2 )
if (((col_1 <= xlsx_data_ranges_[i]->cell_start.first && xlsx_data_ranges_[i]->cell_start.first <= col_2) ||
(xlsx_data_ranges_[i]->cell_start.first <= col_1 && col_1 <= xlsx_data_ranges_[i]->cell_end.first))
&&
(( row_1 <= xlsx_data_ranges_[i]->cell_start.second && xlsx_data_ranges_[i]->cell_start.second <= row_2) ||
(xlsx_data_ranges_[i]->cell_start.second <= row_1 && row_1 <= xlsx_data_ranges_[i]->cell_end.second )))
{
xlsx_data_ranges_[i]->bTablePart = false;
}
}
}
int xlsx_table_context::in_database_range()
{
int col = state()->current_column();
int row = state()->current_row();
for (size_t i = 0; i < xlsx_data_ranges_values_.size(); i++)
for (size_t i = 0; i < xlsx_data_ranges_.size(); i++)
{
if (xlsx_data_ranges_values_[i]->in_range(col, row))
if (xlsx_data_ranges_[i]->table_name != state()->get_table_name()) continue;
if (/*(xlsx_data_ranges_values_[i]->withHeader || xlsx_data_ranges_values_[i]->filter)&& */
xlsx_data_ranges_[i]->in_header(col, row))
{
return (int)i;
}
@ -279,6 +319,8 @@ void xlsx_table_context::serialize_sort(std::wostream & _Wostream)
for (std::multimap<std::wstring, int>::iterator it = range.first; it != range.second; ++it)
{
if (xlsx_data_ranges_[it->second]->bTablePart) continue;
xlsx_data_ranges_[it->second]->serialize_sort(_Wostream);
}
}
@ -288,10 +330,12 @@ void xlsx_table_context::serialize_tableParts(std::wostream & _Wostream, rels &
std::pair<std::multimap<std::wstring, int>::iterator, std::multimap<std::wstring, int>::iterator> range;
range = xlsx_data_ranges_map_.equal_range(state()->tableName_);
range = xlsx_data_ranges_map_.equal_range(state()->get_table_name());
for (std::multimap<std::wstring, int>::iterator it = range.first; it != range.second; ++it)
{
if (false == xlsx_data_ranges_[it->second]->bTablePart) continue;
size_t id = xlsx_conversion_context_->get_table_parts_size() + 1;
std::wstring rId = L"tprtId" + std::to_wstring(id);
@ -314,9 +358,15 @@ void xlsx_table_context::serialize_tableParts(std::wostream & _Wostream, rels &
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
CP_XML_ATTR(L"id", id);
CP_XML_ATTR(L"name", xlsx_data_ranges_[it->second]->table_name);
CP_XML_ATTR(L"displayName", xlsx_data_ranges_[it->second]->table_name);
CP_XML_ATTR(L"name", xlsx_data_ranges_[it->second]->name);
CP_XML_ATTR(L"displayName", xlsx_data_ranges_[it->second]->name);
CP_XML_ATTR(L"ref", xlsx_data_ranges_[it->second]->ref);
if (xlsx_data_ranges_[it->second]->withHeader == false &&
xlsx_data_ranges_[it->second]->filter == false)
CP_XML_ATTR(L"headerRowCount", 0);
//CP_XML_ATTR(L"totalsRowCount", 0);
CP_XML_ATTR(L"totalsRowShown", 0);
xlsx_data_ranges_[it->second]->serialize_autofilter(CP_XML_STREAM());
@ -331,8 +381,13 @@ void xlsx_table_context::serialize_tableParts(std::wostream & _Wostream, rels &
{
CP_XML_NODE(L"tableColumn")
{
std::wstring column_name = xlsx_data_ranges_[it->second]->header_values[id];
if (column_name.empty())
{
column_name = L"Column_" + std::to_wstring(id + 1);
}
CP_XML_ATTR(L"id", id + 1);
CP_XML_ATTR(L"name", xlsx_data_ranges_values_[it->second]->values[id]);
CP_XML_ATTR(L"name", column_name);
}
}
}
@ -363,6 +418,8 @@ void xlsx_table_context::serialize_autofilter(std::wostream & _Wostream)
for (std::multimap<std::wstring, int>::iterator it = range.first; it != range.second; ++it)
{
if (xlsx_data_ranges_[it->second]->bTablePart) continue;
if (xlsx_data_ranges_[it->second]->filter)
{
if (cell_start.first < 0 || xlsx_data_ranges_[it->second]->cell_start.first < cell_start.first )
@ -388,7 +445,7 @@ void xlsx_table_context::serialize_autofilter(std::wostream & _Wostream)
{
CP_XML_NODE(L"autoFilter")
{
//в автофильтре тока простые диапазоны .. для сложных нужно выделять tablePart - todooo
//в автофильтре тока простые диапазоны .. для сложных - tablePart
CP_XML_ATTR(L"ref", getCellAddress(cell_start.first, cell_start.second) + L":" + getCellAddress(cell_end.first, cell_end.second));
//CP_XML_ATTR(L"ref", ref);
}

View File

@ -112,23 +112,23 @@ public:
void dump_rels_hyperlinks (rels & Rels);
void dump_rels_ole_objects (rels & Rels);
void start_database_range(std::wstring table_name, std::wstring ref);
bool start_database_range(const std::wstring &table_name, const std::wstring &ref);
void set_database_orientation (bool val);
void set_database_header (bool val);
void set_database_filter (bool val);
void add_database_sort (int field_number, int order);
void add_database_sort (int field_number, int order);
void end_database_range();
int in_database_range();
void set_database_range_value(int index, const std::wstring& value);
void check_database_range_intersection(const std::wstring& table_name, const std::wstring& ref);
private:
xlsx_conversion_context *xlsx_conversion_context_;
xlsx_text_context &xlsx_text_context_;
std::vector<xlsx_table_state_ptr> xlsx_table_states_;
std::vector<xlsx_data_range_ptr> xlsx_data_ranges_;
std::vector<xlsx_data_range_values_ptr> xlsx_data_ranges_values_;
std::multimap<std::wstring, int> xlsx_data_ranges_map_;

View File

@ -79,6 +79,8 @@ xlsx_conversion_context::xlsx_conversion_context(odf_reader::odf_document * odfD
applicationFonts_ = NSFonts::NSApplication::Create();
}
std::unordered_map<std::wstring, int> xlsx_conversion_context::mapExternalLink_;
void xlsx_conversion_context::set_output_document (package::xlsx_document * document)
{
output_document_ = document;
@ -235,7 +237,41 @@ void xlsx_conversion_context::end_document()
{
CP_XML_STREAM() << workbook_content.str();
}
if (false == mapExternalLink_.empty())
{
CP_XML_NODE(L"externalReferences")
{
for (std::unordered_map<std::wstring, int>::iterator it = mapExternalLink_.begin();
it != mapExternalLink_.end(); ++it)
{
package::external_links_content_ptr content = package::external_links_content::create();
content->rId() = L"extRef" + std::to_wstring(it->second);
{
CP_XML_WRITER(content->content())
{
CP_XML_NODE(L"externalLink")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
CP_XML_NODE(L"externalBook")
{
CP_XML_ATTR(L"xmlns:r", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships");
CP_XML_ATTR(L"r:id", L"rId1");
}
}
}
}
content->get_rels().add(relationship(L"rId1", mediaitems::get_rel_type(typeExternalLink), it->first, L"External"));
output_document_->get_xl_files().add_external_links(content);
CP_XML_NODE(L"externalReference")
{
CP_XML_ATTR(L"r:id", content->rId());
}
}
}
}
get_xlsx_defined_names().xlsx_serialize(CP_XML_STREAM());
int pivot_cache_count = xlsx_pivots_context_.get_count();
@ -441,8 +477,8 @@ void xlsx_conversion_context::end_table()
get_table_context().serialize_page_properties (current_sheet().page_properties());
get_table_context().serialize_conditionalFormatting (current_sheet().conditionalFormatting());
get_table_context().serialize_tableParts (current_sheet().tableParts(), current_sheet().sheet_rels());
//get_table_context().serialize_autofilter (current_sheet().autofilter());
//get_table_context().serialize_sort (current_sheet().sort());
get_table_context().serialize_autofilter (current_sheet().autofilter());
get_table_context().serialize_sort (current_sheet().sort());
get_table_context().serialize_merge_cells (current_sheet().mergeCells());
get_table_context().serialize_data_validation (current_sheet().dataValidations());
@ -507,6 +543,20 @@ void xlsx_conversion_context::end_table()
}
get_table_context().end_table();
}
//int xlsx_conversion_context::add_external_link(const std::wstring & external)
//{
// std::unordered_map<std::wstring, int>::iterator pFind = mapExternalLink_.find(external);
// if ( pFind == mapExternalLink_.end())
// {
// int id = (int)mapExternalLink_.size() + 1;
// mapExternalLink_.insert(std::make_pair(external, id));
// return id;
// }
// else
// {
// return pFind->second;
// }
//}
void xlsx_conversion_context::add_control_props(const std::wstring & rid, const std::wstring & target, const std::wstring & props)
{
if (rid.empty()) return;

View File

@ -34,6 +34,8 @@
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>
#include <unordered_map>
#include "oox_conversion_context.h"
@ -161,8 +163,11 @@ public:
void add_control_props(const std::wstring & rid, const std::wstring & target, const std::wstring & props);
//int add_external_link(const std::wstring & external);
void add_table_part(const std::wstring & table) {table_parts_.push_back(table);}
size_t get_table_parts_size() {return table_parts_.size();}
//------------------------------------------------------------------------------------
odf_reader::odf_document * root()
@ -195,6 +200,8 @@ public:
mediaitems & get_mediaitems() { return mediaitems_; }
static std::unordered_map<std::wstring, int> mapExternalLink_;
std::map<std::wstring, int> mapUsedNames_;
private:
void create_new_sheet (std::wstring const & name);
@ -217,8 +224,8 @@ private:
size_t default_style_;
mediaitems mediaitems_;
std::multimap<std::wstring, int> mapPivotsTableView_;
std::map<std::wstring, std::wstring>control_props_;
std::map<std::wstring, std::wstring> control_props_;
xlsx_style_manager xlsx_style_;
xlsx_defined_names xlsx_defined_names_;
@ -231,6 +238,8 @@ private:
math_context math_context_;
forms_context forms_context_;
static std::wstring change_external(boost::wsmatch const & what);
};
}

View File

@ -54,6 +54,7 @@
#include "datatypes/borderstyle.h"
#include "../../../OfficeUtils/src/OfficeUtils.h"
#include "../../../Common/OfficeFileFormatChecker.h"
#include "../../../Common/3dParty/pole/pole.h"
namespace cpdoccore {
@ -295,50 +296,63 @@ void draw_object_ole::add_child_element( xml::sax * Reader, const std::wstring &
CP_NOT_APPLICABLE_ELM();
}
std::wstring draw_object_ole::detectObject(const std::wstring &fileName)
void draw_object_ole::detectObject(const std::wstring &fileName, std::wstring &prog, std::wstring &extension, oox::RelsType &rels)
{
extension = L".bin";
POLE::Storage *storage = new POLE::Storage(fileName.c_str());
if (storage == NULL) return L"";
if (storage->open(false, false) == false)
if ((storage) && (storage->open(false, false) == true))
{
delete storage;
return L"";
}
std::wstring prog;
POLE::Stream* pStream = new POLE::Stream(storage, L"CompObj");
if ((pStream) && (pStream->size() > 28))
{
//skip the CompObjHeader
pStream->seek(28);
int sz_obj = (int)pStream->size() - 28;
std::vector<std::string> str;
while (sz_obj > 0)
std::wstring prog;
POLE::Stream* pStream = new POLE::Stream(storage, L"CompObj");
if ((pStream) && (pStream->size() > 28))
{
_UINT32 sz = 0;
pStream->read((unsigned char*)&sz, 4); sz_obj-= 4;
//skip the CompObjHeader
pStream->seek(28);
int sz_obj = (int)pStream->size() - 28;
std::vector<std::string> str;
if (sz > sz_obj)
break;
unsigned char *data = new unsigned char[sz];
pStream->read(data, sz);
while (sz_obj > 0)
{
_UINT32 sz = 0;
pStream->read((unsigned char*)&sz, 4); sz_obj-= 4;
if (sz > sz_obj)
break;
unsigned char *data = new unsigned char[sz];
pStream->read(data, sz);
str.push_back(std::string((char*)data, sz));
delete []data;
str.push_back(std::string((char*)data, sz));
delete []data;
sz_obj-= sz;
}
if (!str.empty())
{
prog = std::wstring (str.back().begin(), str.back().end());
}
delete pStream;
}
delete storage;
}
else
{
COfficeFileFormatChecker checker(fileName);
switch(checker.nFileType)
{
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC: extension = L".doc"; prog = L"Word"; rels = oox::typeOleObject; break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX: extension = L".docx"; prog = L"Word"; rels = oox::typeMsObject; break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS: extension = L".xls"; prog = L"Excel"; rels = oox::typeOleObject; break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX: extension = L".xlsx"; prog = L"Excel"; rels = oox::typeMsObject; break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT: extension = L".ppt"; prog = L"PowerPoint"; rels = oox::typeOleObject; break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX: extension = L".pptx"; prog = L"PowerPoint"; rels = oox::typeMsObject; break;
sz_obj-= sz;
}
if (!str.empty())
{
prog = std::wstring (str.back().begin(), str.back().end());
}
delete pStream;
}
delete storage;
return prog;
}

View File

@ -327,7 +327,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
std::wstring detectObject(const std::wstring &fileName);
void detectObject(const std::wstring &fileName, std::wstring &prog, std::wstring &extension, oox::RelsType &rels);
};
CP_REGISTER_OFFICE_ELEMENT2(draw_object_ole);

View File

@ -1638,18 +1638,20 @@ void draw_object_ole::docx_convert(oox::docx_conversion_context & Context)
if (href.empty()) return;
draw_frame* frame = Context.get_drawing_context().get_current_frame(); //owner
draw_frame* frame = Context.get_drawing_context().get_current_frame(); //owner
if (!frame) return;
oox::_docx_drawing * drawing = dynamic_cast<oox::_docx_drawing *>(frame->oox_drawing_.get());
oox::_docx_drawing * drawing = dynamic_cast<oox::_docx_drawing *>(frame->oox_drawing_.get());
if (!drawing) return;
drawing->type = oox::typeOleObject;
bool isMediaInternal = true;
drawing->objectId = Context.get_mediaitems().add_or_find(href, drawing->type, isMediaInternal, href);
std::wstring extension;
detectObject(href, drawing->objectProgId, extension, drawing->type);
NSFile::CFileBinary::Copy(objectPath, objectPath + extension);
bool isMediaInternal = true;
drawing->objectId = Context.get_mediaitems().add_or_find(href + extension, drawing->type, isMediaInternal, href);
drawing->objectProgId = detectObject(objectPath);
}
void draw_control::docx_convert(oox::docx_conversion_context & Context)
{

View File

@ -384,7 +384,18 @@ void draw_object_ole::pptx_convert(oox::pptx_conversion_context & Context)
std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href;
if (!href.empty())
Context.get_slide_context().set_ole_object(href, detectObject(objectPath));
{
std::wstring prog, extension;
oox::RelsType relsType;
detectObject(objectPath, prog, extension, relsType);
NSFile::CFileBinary::Copy(objectPath, objectPath + extension);
if (relsType == oox::typeMsObject)
Context.get_slide_context().set_ms_object(href + extension, prog);
else
Context.get_slide_context().set_ole_object(href + extension, prog);
}
}
void draw_param::pptx_convert(oox::pptx_conversion_context & Context)

View File

@ -359,8 +359,18 @@ void draw_object_ole::xlsx_convert(oox::xlsx_conversion_context & Context)
std::wstring objectPath = folderPath + FILE_SEPARATOR_STR + href;
if (!href.empty())
Context.get_drawing_context().set_ole_object(href, detectObject(objectPath));
{
std::wstring prog, extension;
oox::RelsType relsType;
detectObject(objectPath, prog, extension, relsType);
NSFile::CFileBinary::Copy(objectPath, objectPath + extension);
if (relsType == oox::typeMsObject)
Context.get_drawing_context().set_ms_object(href + extension, prog);
else
Context.get_drawing_context().set_ole_object(href + extension, prog);
}
}
}

View File

@ -284,6 +284,7 @@ void form_button::docx_convert(oox::docx_conversion_context & Context)
void form_button::xlsx_convert(oox::xlsx_conversion_context & Context)
{
Context.get_forms_context().start_element(1);
Context.get_forms_context().set_element(dynamic_cast<form_element*>(this));
form_element::xlsx_convert(Context);
}

View File

@ -87,6 +87,7 @@ void table_data_pilot_table::add_child_element( xml::sax * Reader, const std::ws
CP_CREATE_ELEMENT (source_);
}
void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context)
{
if (!source_) return;
@ -105,6 +106,8 @@ void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context
std::wstring ref = formulas_converter.convert_named_ref(*table_target_range_address_, false);
sheet_name = formulas_converter.get_table_name();
Context.get_table_context().check_database_range_intersection(sheet_name, ref);
Context.get_pivots_context().set_view_target_range(ref);
Context.get_pivots_context().set_view_target_table_name(sheet_name);
}
@ -195,10 +198,12 @@ void table_data_pilot_field::xlsx_convert(oox::xlsx_conversion_context & Context
if (type == table_function::String)
{
formulasconvert::odf2oox_converter formulas_converter;
std::wstring formula = table_function_->get_string();
std::wstring user_funtion = formulas_converter.convert(table_function_->get_string());
Context.get_pivots_context().set_field_user_function(user_funtion);
formulasconvert::odf2oox_converter formulas_converter;
std::wstring oox_formula = formulas_converter.convert(formula);
Context.get_pivots_context().set_field_user_function(oox_formula);
}
else
{

View File

@ -88,24 +88,43 @@ void table_database_range::add_child_element( xml::sax * Reader, const std::wstr
void table_database_range::xlsx_convert(oox::xlsx_conversion_context & Context)
{
if (!table_target_range_address_) return;
if (!table_name_) return;
Context.get_table_context().start_database_range(table_name_.get_value_or(L""), *table_target_range_address_);
if (table_display_filter_buttons_)
Context.get_table_context().set_database_filter(table_display_filter_buttons_->get());
std::wstring name = table_name_.get();
if (table_orientation_)
Context.get_table_context().set_database_orientation(table_orientation_->get_type() == table_orientation::row ? true : false);
if (table_contains_header_)
Context.get_table_context().set_database_header(table_contains_header_->get());
for (size_t i = 0; i < content_.size(); i++)
std::map<std::wstring, int>::iterator pFind = Context.mapUsedNames_.find(name);
if (pFind == Context.mapUsedNames_.end())
{
content_[i]->xlsx_convert(Context);
Context.mapUsedNames_.insert(std::make_pair(name, 1));
}
else
{
name += L"_" + std::to_wstring(pFind->second);
pFind->second++;
}
if (Context.get_table_context().start_database_range(name, *table_target_range_address_))
{
if (table_display_filter_buttons_)
Context.get_table_context().set_database_filter(table_display_filter_buttons_->get());
Context.get_table_context().end_database_range();
if (table_orientation_)
Context.get_table_context().set_database_orientation(table_orientation_->get_type() == table_orientation::row ? true : false);
if (table_contains_header_)
Context.get_table_context().set_database_header(table_contains_header_->get());
for (size_t i = 0; i < content_.size(); i++)
{
content_[i]->xlsx_convert(Context);
}
Context.get_table_context().end_database_range();
}
else
{
Context.get_xlsx_defined_names().add(name, table_target_range_address_.get(), false, -1);
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -94,8 +94,19 @@ void table_named_range::xlsx_convert(oox::xlsx_conversion_context & Context)
{
tableId = Context.get_table_context().state()->get_table_id();
}
oox::xlsx_defined_names & ctx = Context.get_xlsx_defined_names();
ctx.add(table_name_.get(), table_cell_range_address_.get(), false, tableId);
std::wstring name = table_name_.get();
std::map<std::wstring, int>::iterator pFind = Context.mapUsedNames_.find(name);
if (pFind == Context.mapUsedNames_.end())
{
Context.mapUsedNames_.insert(std::make_pair(name, 1));
}
else
{
name += L"_" + std::to_wstring(pFind->second);
pFind->second++;
}
Context.get_xlsx_defined_names().add(name, table_cell_range_address_.get(), false, tableId);
}
}
@ -130,8 +141,18 @@ void table_named_expression::xlsx_convert(oox::xlsx_conversion_context & Context
{
tableId = Context.get_table_context().state()->get_table_id();
}
oox::xlsx_defined_names & ctx = Context.get_xlsx_defined_names();
ctx.add(table_name_.get(), table_expression_.get(), true, tableId);
std::wstring name = table_name_.get();
std::map<std::wstring, int>::iterator pFind = Context.mapUsedNames_.find(name);
if (pFind == Context.mapUsedNames_.end())
{
Context.mapUsedNames_.insert(std::make_pair(name, 1));
}
else
{
name += L"_" + std::to_wstring(pFind->second);
pFind->second++;
}
Context.get_xlsx_defined_names().add(name, table_expression_.get(), true, tableId);
}
}

View File

@ -73,19 +73,6 @@ int table_table_cell_content::xlsx_convert(oox::xlsx_conversion_context & Contex
const int sharedStrId = Context.get_table_context().end_cell_content();
int index = Context.get_table_context().in_database_range();
if (index >= 0)
{
std::wstringstream strm;
for (size_t i = 0 ; i < elements_.size(); i++)
{
elements_[i]->text_to_stream(strm);
}
Context.get_table_context().set_database_range_value(index, strm.str());
}
return sharedStrId;
}
@ -854,9 +841,31 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
const int sharedStringId = content_.xlsx_convert(Context, &textFormatProperties);
if (t_val == oox::XlsxCellType::str && sharedStringId >= 0)
t_val = oox::XlsxCellType::s;//в случае текста, если он есть берем кэшированное значение
//---------------------------------------------------------------------------------------------------------
if (t_val == oox::XlsxCellType::str || t_val == oox::XlsxCellType::inlineStr)
{
int index = Context.get_table_context().in_database_range();
if (index >= 0)
{
if (sharedStringId >= 0)
{
std::wstringstream strm;
content_.text_to_stream(strm);
Context.get_table_context().set_database_range_value(index, strm.str());
}
else if (str_val)
{
Context.get_table_context().set_database_range_value(index, str_val.get());
}
}
}
if (t_val == oox::XlsxCellType::str && sharedStringId >= 0)
{
t_val = oox::XlsxCellType::s;//в случае текста, если он есть берем кэшированное значение
}
//---------------------------------------------------------------------------------------------------------
if (skip_next_cell)break;
// пустые ячейки пропускаем.
@ -1139,7 +1148,7 @@ void table_covered_table_cell::xlsx_convert(oox::xlsx_conversion_context & Conte
const int sharedStringId = content_.xlsx_convert(Context, &textFormatProperties);
if (t_val == oox::XlsxCellType::str && sharedStringId >=0)
if (t_val == oox::XlsxCellType::str && sharedStringId >= 0)
t_val = oox::XlsxCellType::s;//в случае текста, если он есть берем кэшированное значение
if (skip_next_cell)break;
@ -1157,7 +1166,7 @@ void table_covered_table_cell::xlsx_convert(oox::xlsx_conversion_context & Conte
if (!formula.empty())
{
const std::wstring xlsxFormula = formulas_converter.convert(formula);
const std::wstring xlsxFormula = formulas_converter.convert(formula);
if (!xlsxFormula.empty())
{
CP_XML_NODE(L"f")

View File

@ -42,7 +42,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
AdditionalIncludeDirectories="..\include"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"

View File

@ -666,7 +666,14 @@ namespace PPTX
std::wstring strValue = strParams.substr(nPosOld, nPosition - nPosOld);
m_mapSettings.insert(std::pair<std::wstring, std::wstring>(strName, strValue));
if (m_mapSettings.find(strName) == m_mapSettings.end())
{
m_mapSettings.insert(std::make_pair(strName, strValue));
}
else
{
m_mapSettings[strName] += L"," + strValue;
}
}
}
@ -733,8 +740,14 @@ namespace PPTX
if (pData[nPosOld] == WCHAR('.'))
strValue = (L"0" + strValue);
//добавляем через [], а не insert, потому что ключи могут дублироваться(а в предыдущей реализации использовалось последнее значение)
m_mapSettings[strName] = strValue;
if (m_mapSettings.find(strName) == m_mapSettings.end())
{
m_mapSettings.insert(std::make_pair(strName, strValue));
}
else
{
m_mapSettings[strName] += L"," + strValue;
}
}
}
@ -2864,7 +2877,8 @@ void CDrawingConverter::doc_LoadShape(PPTX::Logic::SpTreeElem *elem, XmlUtils::C
pSpPr->xfrm->flipH = true;
else if (pFind->second == L"y")
pSpPr->xfrm->flipV = true;
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x"))
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x")
|| (pFind->second == L"y,x") || (pFind->second == L"x,y"))
{
pSpPr->xfrm->flipH = true;
pSpPr->xfrm->flipV = true;
@ -2898,7 +2912,8 @@ void CDrawingConverter::doc_LoadShape(PPTX::Logic::SpTreeElem *elem, XmlUtils::C
pSpPr->xfrm->flipH = true;
else if (pFind->second == L"y")
pSpPr->xfrm->flipV = true;
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x"))
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x")
|| (pFind->second == L"y,x") || (pFind->second == L"x,y"))
{
pSpPr->xfrm->flipH = true;
pSpPr->xfrm->flipV = true;
@ -3062,7 +3077,8 @@ void CDrawingConverter::doc_LoadGroup(PPTX::Logic::SpTreeElem *result, XmlUtils:
pTree->grpSpPr.xfrm->flipH = true;
else if (pFind->second == L"y")
pTree->grpSpPr.xfrm->flipV = true;
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x"))
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x")
|| (pFind->second == L"y,x") || (pFind->second == L"x,y"))
{
pTree->grpSpPr.xfrm->flipH = true;
pTree->grpSpPr.xfrm->flipV = true;
@ -3102,7 +3118,8 @@ void CDrawingConverter::doc_LoadGroup(PPTX::Logic::SpTreeElem *result, XmlUtils:
pTree->grpSpPr.xfrm->flipH = true;
else if (pFind->second == L"y")
pTree->grpSpPr.xfrm->flipV = true;
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x"))
else if ((pFind->second == L"xy") || (pFind->second == L"yx") || (pFind->second == L"x y") || (pFind->second == L"y x")
|| (pFind->second == L"y,x") || (pFind->second == L"x,y"))
{
pTree->grpSpPr.xfrm->flipH = true;
pTree->grpSpPr.xfrm->flipV = true;
@ -4787,6 +4804,14 @@ HRESULT CDrawingConverter::SaveObject(LONG lStart, LONG lLength, const std::wstr
if(oPic.oleObject.IsInit())
{
bOle = oPic.oleObject->isValid();
if (oPic.oleObject->m_oDxaOrig.IsInit() == false)
{
oPic.oleObject->m_oDxaOrig = 0;
}
if (oPic.oleObject->m_oDyaOrig.IsInit() == false)
{
oPic.oleObject->m_oDyaOrig = 0;
}
}
}
bool bSignatureLine = false;

View File

@ -323,7 +323,8 @@ namespace PPTX
{
m_OleObjectFile = new OOX::OleObject(NULL, true, pReader->m_nDocumentType == XMLWRITER_DOC_TYPE_DOCX);
std::wstring strOlePath = pReader->GetString(_embed_data_size);
BYTE type = pReader->GetUChar();
std::wstring strOlePath = pReader->GetString2();
m_OleObjectFile->set_filename(strOlePath, false); //temp !!! for ImageManager original file name
}
else if (embedded_type == 4)

View File

@ -37,7 +37,14 @@ mkdir "build"
fi
cef_binary=cef_binary
cef_arch=$cef_binary.7z
cef_url=http://d2ettrnqo7v976.cloudfront.net/cef/3163/$platform$arch/$cef_arch
cef_version="3163"
if [[ "$platform" == *"linux"* ]]
then
cef_version="3202"
fi
cef_url=http://d2ettrnqo7v976.cloudfront.net/cef/$cef_version/$platform$arch/$cef_arch
if [[ "$platform" == *"linux"* ]]
then

View File

@ -262,7 +262,7 @@ std::wstring COfficeFileFormatChecker::getDocumentID (const std::wstring & _file
}
else
{
if ( false == isOpenOfficeFormatFile(fileName, sDocumentID))
if ( false == isOpenOfficeFormatFile(fileName, documentID))
{
NSFile::CFileBinary file;
if (!file.OpenFile(fileName))
@ -275,12 +275,13 @@ std::wstring COfficeFileFormatChecker::getDocumentID (const std::wstring & _file
file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes);
file.CloseFile();
if (isPdfFormatFile(buffer, (int)dwReadBytes, sDocumentID) )
if (isPdfFormatFile(buffer, (int)dwReadBytes, documentID) )
{
nFileType = AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF;
}
}
}
sDocumentID = documentID;
return documentID;
}

View File

@ -1 +1 @@
2.4.555.0
2.5.556.0

View File

@ -255,12 +255,12 @@ public:
double bottom;
public:
CDoubleRect()
CDoubleRect(double dLeft = 0.0, double dTop = 0.0, double dRight = 0.0, double dBottom = 0.0)
{
left = 0;
top = 0;
right = 0;
bottom = 0;
left = dLeft;
top = dTop;
right = dRight;
bottom = dBottom;
}
CDoubleRect& operator=(const CDoubleRect& oSrc)
{
@ -303,6 +303,11 @@ public:
return (top + bottom) / 2.0;
}
inline CDoublePoint GetCenter() const
{
return CDoublePoint((left + right) / 2.0, (top + bottom) / 2.0);
}
inline INT IsPointInside(const CDoublePoint& oPoint)
{
return IsPointInside(oPoint.x, oPoint.y);

View File

@ -398,6 +398,72 @@ namespace MetaFile
nAdd++;
}
BYTE* pUncompressedBuffer = NULL;
if (BI_RLE8 == unCompression)
{
int nStride = nWidth + nAdd;
int lUncompressedLen = nStride * abs(nHeight);
pUncompressedBuffer = new BYTE[lUncompressedLen];
if (!pUncompressedBuffer)
return false;
for (int nPos = 0, nUncompressedPos = 0, nLinePos = 0; nPos < lBufLen; nPos += 2)
{
BYTE nCount = pBuffer[nPos];
BYTE nColor = pBuffer[nPos + 1];
if (nCount == 0)
{
// End of line.
if (0 == nColor)
{
if (nLinePos < nStride)
{
int nAdditionalSpace = nStride - nLinePos;
if (nUncompressedPos + nAdditionalSpace > lUncompressedLen)
break;
::memset(pUncompressedBuffer + nUncompressedPos, 0, nAdditionalSpace);
nUncompressedPos += nAdditionalSpace;
}
nLinePos = 0;
continue;
}
// End of bitmap.
else if (1 == nColor)
{
break;
}
else
{
// TODO: 2
break;
}
}
nLinePos += nCount;
while (nLinePos >= nStride)
{
nLinePos -= nStride;
}
if (nUncompressedPos + nCount > lUncompressedLen)
break;
for (int i = 0; i < nCount; ++i)
pUncompressedBuffer[nUncompressedPos + i] = nColor;
::memset(pUncompressedBuffer + nUncompressedPos, nColor, nCount);
nUncompressedPos += nCount;
}
pBuffer = pUncompressedBuffer;
lBufLen = lUncompressedLen;
}
if (lBufLen < (nWidth + nAdd) * abs(nHeight))
return false;
@ -449,6 +515,9 @@ namespace MetaFile
*pulWidth = ulWidth;
*pulHeight = ulHeight;
if (pUncompressedBuffer)
delete[] pUncompressedBuffer;
return true;
}
else if (BI_BITCOUNT_4 == ushBitCount)

View File

@ -407,7 +407,9 @@ static const struct ActionNamesEmf
BYTE* pHeaderBuffer = m_oStream.GetCurPtr();
m_oStream.Skip(ulHeaderSize + lBitsOffset);
BYTE* pBitsBuffer = m_oStream.GetCurPtr();
m_oStream.Skip(ulBitsSize);
unsigned int ulBitsSizeSkip = 0 == ulBitsSize ? 0 : ((int)(((double)ulBitsSize - 0.5) / 4) + 1) * 4;
m_oStream.Skip(ulBitsSizeSkip);
MetaFile::ReadImage(pHeaderBuffer, ulHeaderSize, pBitsBuffer, ulBitsSize, ppBgraBuffer, pulWidth, pulHeight);

View File

@ -177,47 +177,49 @@ namespace MetaFile
{
return m_lType;
}
void CMetaFile::GetBounds(double* pdX, double* pdY, double* pdW, double* pdH)
{
if (c_lMetaWmf == m_lType)
{
const TRectD& oRect = m_oWmfFile.GetBounds();
*pdX = oRect.dLeft;
*pdY = oRect.dTop;
*pdW = oRect.dRight - oRect.dLeft;
*pdH = oRect.dBottom - oRect.dTop;
}
else if (c_lMetaEmf == m_lType)
{
TEmfRectL* pRect = m_oEmfFile.GetBounds();
*pdX = pRect->lLeft;
*pdY = pRect->lTop;
*pdW = pRect->lRight - pRect->lLeft;
*pdH = pRect->lBottom - pRect->lTop;
}
else if (c_lMetaSvm == m_lType)
{
TRect* pRect = m_oSvmFile.GetBounds();
*pdX = pRect->nLeft;
*pdY = pRect->nTop;
*pdW = pRect->nRight - pRect->nLeft;
*pdH = pRect->nBottom - pRect->nTop;
void CMetaFile::GetBounds(double* pdX, double* pdY, double* pdW, double* pdH)
{
if (c_lMetaWmf == m_lType)
{
const TRectD& oRect = m_oWmfFile.GetBounds();
*pdX = oRect.dLeft;
*pdY = oRect.dTop;
*pdW = oRect.dRight - oRect.dLeft;
*pdH = oRect.dBottom - oRect.dTop;
}
else if (c_lMetaEmf == m_lType)
{
TEmfRectL* pRect = m_oEmfFile.GetBounds();
*pdX = pRect->lLeft;
*pdY = pRect->lTop;
*pdW = pRect->lRight - pRect->lLeft;
*pdH = pRect->lBottom - pRect->lTop;
}
else if (c_lMetaSvm == m_lType)
{
TRect* pRect = m_oSvmFile.GetBounds();
*pdX = pRect->nLeft;
*pdY = pRect->nTop;
*pdW = pRect->nRight - pRect->nLeft;
*pdH = pRect->nBottom - pRect->nTop;
if (*pdW > 10000 || *pdH > 10000)
{
*pdW /= 10;
*pdH /= 10;
}
}
else
{
*pdX = 0;
*pdY = 0;
*pdW = 0;
*pdH = 0;
}
};
void CMetaFile::ConvertToRaster(const wchar_t* wsOutFilePath, unsigned int unFileType, int nWidth, int nHeight)
if (*pdW > 10000 || *pdH > 10000)
{
*pdW /= 10;
*pdH /= 10;
}
}
else
{
*pdX = 0;
*pdY = 0;
*pdW = 0;
*pdH = 0;
}
if (*pdW < 0) *pdW = -*pdW;
if (*pdH < 0) *pdH = -*pdH;
};
void CMetaFile::ConvertToRaster(const wchar_t* wsOutFilePath, unsigned int unFileType, int nWidth, int nHeight)
{
CFontManager *pFontManager = (CFontManager*)m_pAppFonts->GenerateFontManager();
CFontsCache* pFontCache = new CFontsCache();

View File

@ -398,9 +398,9 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
const char* nenv[4];
nenv[0] = sLibraryDir.c_str();
nenv[1] = "LD_PRELOAD=./libcef.so";
nenv[2] = "DISPLAY=:0";
nenv[3] = NULL;
nenv[1] = "DISPLAY=:0";
nenv[2] = NULL;
nenv[3] = NULL;
execve(sProgramm.c_str(),
(char * const *)nargs,
@ -419,9 +419,8 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
const char* nenv[4];
nenv[0] = sLibraryDir.c_str();
nenv[1] = "LD_PRELOAD=./libcef.so";
nenv[2] = NULL;//"DISPLAY=:99";
nenv[3] = NULL;
nenv[1] = NULL;//"DISPLAY=:99";
nenv[2] = NULL;
execve("/usr/bin/xvfb-run", (char * const *)nargs, (char * const *)nenv);
exit(EXIT_SUCCESS);

View File

@ -16,6 +16,11 @@ CONFIG -= debug_and_release debug_and_release_target
DEFINES += HTMLFILE_USE_DYNAMIC_LIBRARY
DEFINES += UNICODECONVERTER_USE_DYNAMIC_LIBRARY
CORE_ROOT_DIR = $$PWD/../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
CONFIG(debug, debug|release) {
DESTDIR = $$PWD/Debug
} else {
@ -25,41 +30,10 @@ CONFIG(debug, debug|release) {
CONFIG += c++11
TEMPLATE = app
############### destination path ###############
DESTINATION_SDK_PATH = $$PWD/../../build/lib
# WINDOWS
win32:contains(QMAKE_TARGET.arch, x86_64):{
CONFIG(debug, debug|release) {
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/win_64/DEBUG
} else {
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/win_64
}
}
win32:!contains(QMAKE_TARGET.arch, x86_64):{
CONFIG(debug, debug|release) {
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/win_32/DEBUG
} else {
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/win_32
}
}
linux-g++:contains(QMAKE_HOST.arch, x86_64):{
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/linux_64
}
linux-g++:!contains(QMAKE_HOST.arch, x86_64):{
DESTINATION_SDK_PATH = $$DESTINATION_SDK_PATH/linux_32
}
LIBS += -L$$DESTINATION_SDK_PATH -lHtmlFile
LIBS += -L$$DESTINATION_SDK_PATH -lUnicodeConverter
LIBS += -L$$DESTINATION_SDK_PATH -lgraphics
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lUnicodeConverter -lkernel -lgraphics -lHtmlFile
linux-g++ | linux-g++-64 | linux-g++-32 {
QMAKE_LFLAGS += -Wl,--rpath=./
LIBS += $$PWD/../../build/bin/icu/linux_64/libicuuc.so.55
LIBS += $$PWD/../../build/bin/icu/linux_64/libicudata.so.55
message(linux)
}
@ -67,9 +41,6 @@ win32 {
LIBS += -ladvapi32 \
-luser32 \
-lshell32
LIBS += -L$$PWD/../../build/bin/icu/win_64/ -licudt
LIBS += -L$$PWD/../../build/bin/icu/win_64/ -licuuc
}
SOURCES += main.cpp

View File

@ -11,7 +11,7 @@ apply from: "$rootProject.projectDir/extra-builds/gradle/common.gradle"
// Common native libs path
def TOOLCHAIN_VERSION = 4.9
def NDK_VERSION = "android-ndk-r17c"
def HOST_PLATFORM = getHostName()
def HOST_PLATFORM = getHostNameFull()
def PATH_NDK = "${project.rootDir.path}/${NDK_VERSION}"
def PATH_TOOLCHAIN = "$PATH_NDK/toolchains/\$1/prebuilt/$HOST_PLATFORM/bin"
def PATH_STANDALONE_SCRIPT = "$PATH_NDK/build/tools"
@ -43,7 +43,7 @@ def ICONV_LIBS_PATH = "$project.ext.PATH_TO_NATIVE_LIBS/iconv"
def ICONV_LIBS_INSTALL = "$ICONV_LIBS_PATH/install"
// Icu
def ICU_SRC = "$PATH_3PARTY/icu/" + getDirName("$PATH_3PARTY/icu")
def ICU_SRC = "$PATH_3PARTY/icu/" + findDirName("$PATH_3PARTY/icu", getHostName())
def ICU_BUILD = "$ICU_SRC/build"
def ICU_SRC_ROOT = "$ICU_SRC/icu/source"
def ICU_LIBS_PATH = "$project.ext.PATH_TO_NATIVE_LIBS/icu"

View File

@ -28,7 +28,8 @@ endif()
if (NOT DEFINED ARG_LIBS)
message(FATAL_ERROR "You must set argument \"ARG_LIBS\" with path to 3d-party library...")
elseif (NOT EXISTS ${ARG_LIBS})
message(FATAL_ERROR "3d party libraries path doesn't exist!")
file(MAKE_DIRECTORY ${ARG_LIBS})
message(STATUS "3d party libraries path doesn't exist! Created!")
endif()
# ---------- Libs names ----------

View File

@ -89,13 +89,15 @@ def getBackSlashExt(String str) {
return str.replaceAll("\\\\", "/")
}
def getDirNameExt(String path) {
def findDirNameExt(String path, String name) {
def countFolders = 0
def nameFolder = ''
file(path).listFiles().each { it ->
if (it.isDirectory()) {
nameFolder = it.getName()
++countFolders
if (it.getName().contains(name)) {
nameFolder = it.getName()
++countFolders
}
}
}
@ -144,7 +146,7 @@ ext {
// Extra path
// Args for cmake
project.ext.SRC_CORE = "$rootProject.rootDir/../../../"
project.ext.SRC_CORE = "$rootProject.rootDir/../../.."
project.ext.PATH_TO_NATIVE_BUILDS = getBackSlashExt("$rootProject.projectDir/extra-builds/native")
project.ext.PATH_TO_NATIVE_LIBS = "$project.ext.PATH_TO_NATIVE_BUILDS/libs"
project.ext.PATH_TO_NATIVE_ARCHS = "$project.ext.PATH_TO_NATIVE_BUILDS/libs.tar"
@ -171,7 +173,8 @@ ext {
getPathEnv = this.&getPathEnvOs
isFolderNotEmpty = this.&isFolderNotEmptyCheck
getBackSlash = this.&getBackSlashExt
getDirName = this.&getDirNameExt
getHostName = this.&getHostNameFullExt
findDirName = this.&findDirNameExt
getHostNameFull = this.&getHostNameFullExt
getHostName = this.&getHostNameExt
}