Compare commits

..

21 Commits

Author SHA1 Message Date
4ca2126abc OdfFormatReader - fix issue #128 2018-07-18 17:10:27 +03:00
89235ca12a Changes for core develop branch (desktop) 2018-07-18 12:01:02 +03:00
08d551752e Changes for desktop (develop branch) 2018-07-17 19:55:31 +03:00
77b1303d62 . 2018-07-17 18:12:51 +03:00
93e56e2b8a OdfFormatReader - fix issue #128, add cross references, fix simple annotations 2018-07-17 16:14:20 +03:00
e032fc8294 [bug] Compilation bug 2018-07-17 14:04:07 +03:00
5ae2ac2385 [ios][x2t] fixed build 2018-07-16 15:43:07 +03:00
6b8cb6cae4 Merge pull request #94 from ONLYOFFICE/feature/bin2xlsx-enh
[x2t] Decrease memory consumption while bin->xlsx conversion
2018-07-16 14:10:56 +03:00
e66ea7c628 [x2t] Add saving of templates to fromDocxDir, fromXlsxDir, fromPptxDir 2018-07-16 13:57:20 +03:00
2447925fd6 OdfFormatWriter - alphabetical indexes 2018-07-16 11:31:58 +03:00
9991195d56 . 2018-07-13 18:59:23 +03:00
51f579a682 [ios][pe] events 2018-07-13 18:23:28 +03:00
45e0459434 OdfFormatWriter - .. 2018-07-13 15:26:51 +03:00
2f194ebd97 . 2018-07-13 13:24:56 +03:00
5e4ce83dc1 Ignore -no-warrowing warning while building PdfWriter
Errors looks like:
`../Src/ICCProfile.h:52: error: narrowing conversion of '-72' from 'int'
to 'unsigned char' inside { } [-Wnarrowing]`
2018-07-13 13:05:13 +03:00
50d4f451b9 . 2018-07-12 20:46:00 +03:00
d464aa659a OdfFormat - .. 2018-07-12 19:37:33 +03:00
db2d001110 Fix possible typo
`realink -n` return empty string
Introduced in
51569b626f
Seems have nothing to do with mac, since all other file has `readlink
-f`
2018-07-12 18:24:22 +03:00
b883cfcbd4 Add workaround for building icu on ArchLinux
See https://bugs.archlinux.org/task/55246
2018-07-12 16:51:17 +03:00
bb8add215a Fail on any error in subscripts
Without this command any errors are just ignored and script continues
2018-07-12 16:24:32 +03:00
5e126e28ff [x2t] Decrease memory consumption while bin->xlsx conversion 2018-07-11 16:58:07 +03:00
82 changed files with 2231 additions and 1168 deletions

View File

@ -306,10 +306,15 @@ void docx_conversion_context::finish_run()
{
if (false == in_run_) return;
if (get_comments_context().state() == 4)
{
output_stream()<< L"<w:commentReference w:id=\"" << get_comments_context().current_id() << L"\"/>";
get_comments_context().state(0);
}
output_stream() << L"</w:r>";
in_run_ = false;
if (get_comments_context().state()==2)
if (get_comments_context().state() == 2)
{
output_stream()<< L"<w:commentRangeEnd w:id=\"" << get_comments_context().current_id() << L"\"/>";
@ -318,7 +323,6 @@ void docx_conversion_context::finish_run()
get_comments_context().state(0);
finish_run();
}
}
void docx_conversion_context::start_math_formula()
{
@ -369,42 +373,51 @@ void docx_conversion_context::start_index_content()
std::wstring sInstrText;
switch(table_content_context_.type_table_content)
if (table_content_context_.type_table_content == 3)
{
case 1: sInstrText += L" TOC \\f \\h \\u"; break;
case 2:
case 4:
case 6:
case 7: sInstrText += L" TOC \\h \\z"; break;
case 5: sInstrText += L" INDEX \\z"; break;
case 3: sInstrText += L" BIBLIOGRAPHY"; break;
sInstrText = L" BIBLIOGRAPHY ";
}
if (table_content_context_.min_outline_level > 0)
else if (table_content_context_.type_table_content == 5)
{
if (table_content_context_.max_outline_level > 9)
table_content_context_.max_outline_level = 9;
sInstrText += L" \\o \"" + std::to_wstring(table_content_context_.min_outline_level) + L"-" +
std::to_wstring(table_content_context_.max_outline_level) + L"\"";
sInstrText = L" INDEX";
if (table_content_context_.bSeparators)
sInstrText += L" \\h \"A\"";
}
if (false == table_content_context_.outline_level_styles.empty())
else
{
sInstrText += L"\\t \"";
sInstrText += L" TOC \\h";
for (std::map<int, std::wstring>::iterator it = table_content_context_.outline_level_styles.begin();
it != table_content_context_.outline_level_styles.end(); ++it)
if (table_content_context_.type_table_content == 1)
sInstrText += L" \\f \\u";
else
sInstrText += L" \\z";
if (table_content_context_.min_outline_level > 0)
{
sInstrText += it->second + L";" + std::to_wstring(it->first) + L";";
if (table_content_context_.max_outline_level > 9)
table_content_context_.max_outline_level = 9;
sInstrText += L" \\o \"" + std::to_wstring(table_content_context_.min_outline_level) + L"-" +
std::to_wstring(table_content_context_.max_outline_level) + L"\"";
}
if (false == table_content_context_.outline_level_styles.empty())
{
sInstrText += L" \\t \"";
for (std::map<int, std::wstring>::iterator it = table_content_context_.outline_level_styles.begin();
it != table_content_context_.outline_level_styles.end(); ++it)
{
sInstrText += it->second + L";" + std::to_wstring(it->first) + L";";
}
sInstrText += L"\"";
}
sInstrText += L"\"";
if (!table_content_context_.caption_sequence_name.empty())
{
sInstrText += L" \\c \"" + table_content_context_.caption_sequence_name + L"\"";
}
}
if (!table_content_context_.caption_sequence_name.empty())
{
sInstrText += L" \\c \"" + table_content_context_.caption_sequence_name + L"\"";
}
output_stream() << L"<w:r>";
output_stream() << L"<w:fldChar w:fldCharType=\"begin\"/>";
output_stream() << L"</w:r>";
@ -578,7 +591,8 @@ oox_chart_context & docx_conversion_context::current_chart()
void docx_conversion_context::add_new_run(std::wstring parentStyleId)
{
finish_run();
if (get_comments_context().state()==1)
if (get_comments_context().state() == 1 ||
get_comments_context().state() == 4)//??? comment in run
{
output_stream() << L"<w:commentRangeStart w:id=\"" << get_comments_context().current_id() << L"\" />";
get_comments_context().state(2);//active

View File

@ -486,14 +486,14 @@ public:
std::wstring author;
std::wstring initials;
};
void start_comment(const std::wstring & content, const std::wstring & author, const std::wstring & date)
void start_comment(const std::wstring & content, const std::wstring & author, const std::wstring & date, bool inRun = false)
{
int id = comments_.size()+1;
_comment_desc new_comment={content,id,date,author};
int id = comments_.size() + 1;
_comment_desc new_comment={content, id, date, author};
comments_.push_back(new_comment);
state_ = 1;
state_ = inRun ? 4 : 1;
}
int current_id()
{
@ -693,7 +693,8 @@ public:
{
current_content_template_.clear();
}
current_content_template_ = pFind->second.content;
else
current_content_template_ = pFind->second.content;
current_content_template_index_ = 0;
}
@ -730,6 +731,7 @@ public:
min_outline_level = -1;
max_outline_level = -1;
outline_level_styles.clear();
bSeparators = false;
}
void add_sequence(const std::wstring & name, int outline_level)
{
@ -754,6 +756,7 @@ public:
int min_outline_level;
int max_outline_level;
std::map<int, std::wstring> outline_level_styles;
bool bSeparators;
private:
std::vector<int> current_content_template_;

View File

@ -50,7 +50,7 @@ std::wostream & operator << (std::wostream & _Wostream, const style_repeat & _Va
case style_repeat::Stretch:
_Wostream << L"stretch";
break;
default:
default:
break;
}
return _Wostream;
@ -67,9 +67,10 @@ style_repeat style_repeat::parse(const std::wstring & Str)
return style_repeat( Repeat );
else if (tmp == L"stretch")
return style_repeat( Stretch );
else
else if (tmp == L"scale")//LOWriter-form-controls modded.odt
return style_repeat( Stretch );
else
{
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
return style_repeat( NoRepeat );
}
}

View File

@ -73,7 +73,9 @@ text_transform text_transform::parse(const std::wstring & Str)
return text_transform(Uppercase);
else if (tmp == L"capitalize")
return text_transform(Capitalize);
else
else if (tmp == L"underline")
return text_transform(Underline);
else
{
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
return None;

View File

@ -52,7 +52,8 @@ public:
None,
Lowercase,
Uppercase,
Capitalize
Capitalize,
Underline
};
text_transform()

View File

@ -39,21 +39,22 @@ namespace odf_reader {
class document_context::Impl
{
public:
Impl() : last_paragraph_(NULL) {}
Impl() : last_element_(NULL) {}
public:
void set_last_paragraph(text::paragraph * Paragraph)
void set_last_element(office_element* elem)
{
last_paragraph_ = Paragraph;
last_element_ = elem;
}
text::paragraph * get_last_paragraph()
office_element* get_last_element()
{
return last_paragraph_;
return last_element_;
}
private:
text::paragraph * last_paragraph_;
office_element * last_element_;
};
@ -68,18 +69,15 @@ document_context::~document_context()
{
delete impl_;
}
void document_context::set_last_paragraph(text::paragraph * Paragraph)
void document_context::set_last_element(office_element* elem)
{
return impl_->set_last_paragraph(Paragraph);
return impl_->set_last_element(elem);
}
text::paragraph * document_context::get_last_paragraph()
office_element* document_context::get_last_element()
{
return impl_->get_last_paragraph();
return impl_->get_last_element();
}
}
}

View File

@ -36,18 +36,14 @@ namespace odf_reader {
class office_element;
namespace text {
class paragraph;
}
class document_context
{
public:
document_context();
virtual ~document_context();
void set_last_paragraph(text::paragraph * Paragraph);
text::paragraph * get_last_paragraph();
void set_last_element(office_element* elem);
office_element* get_last_element();
int level;

View File

@ -1255,7 +1255,19 @@ void draw_text_box::docx_convert(oox::docx_conversion_context & Context)
//}
auto_fit_shape = true;
}
else if ((frame->draw_frame_attlist_.fo_min_height_) && (draw_text_box_attlist_.fo_min_height_->get_type()==length_or_percent::Length))
{
size_t min_y = get_value_emu(frame->draw_frame_attlist_.fo_min_height_->get_length());
if (drawing->cy < min_y)
{
drawing->cy = min_y;
}
auto_fit_shape = true;
}
else if ((frame->common_draw_attlists_.rel_size_.style_rel_height_) && (frame->common_draw_attlists_.rel_size_.style_rel_height_->get_type() == percent_or_scale::ScaleMin))
{
auto_fit_shape = true;
}
if ((draw_text_box_attlist_.fo_min_width_) && (draw_text_box_attlist_.fo_min_width_->get_type()==length_or_percent::Length))
{

View File

@ -450,7 +450,7 @@ const page_layout_instance * page_layout_container::page_layout_first() const
bool page_layout_container::compare_page_properties(const std::wstring & master1, const std::wstring & master2)
{
const page_layout_instance *page_layout1 = page_layout_by_style(master1);
const page_layout_instance *page_layout2 = page_layout_by_style(master1);
const page_layout_instance *page_layout2 = page_layout_by_style(master2);
if (!page_layout1 || !page_layout2) return true;
if (!page_layout1->style_page_layout_ || !page_layout1->style_page_layout_) return true;
@ -458,7 +458,9 @@ bool page_layout_container::compare_page_properties(const std::wstring & master1
style_page_layout_properties *props1 = dynamic_cast<style_page_layout_properties*>(page_layout1->style_page_layout_->style_page_layout_properties_.get());
style_page_layout_properties *props2 = dynamic_cast<style_page_layout_properties*>(page_layout2->style_page_layout_->style_page_layout_properties_.get());
if (!props1 || !props1) return true;
if (!props1 || !props2) return true;
if (props1 == props2) return true;
return props1->attlist_.compare(props2->attlist_);
}

View File

@ -148,7 +148,7 @@ void office_annotation::docx_convert(oox::docx_conversion_context & Context)
Context.set_run_state(runState);
Context.set_paragraph_state(pState);
Context.get_comments_context().start_comment(temp_stream.str(), author,date);//content, date, author
Context.get_comments_context().start_comment(temp_stream.str(), author, date, runState);//content, date, author
Context.dump_hyperlinks(Context.get_comments_context().get_rels(), oox::hyperlinks::comment_place);

View File

@ -142,14 +142,14 @@ void office_body::docx_convert(oox::docx_conversion_context & Context)
if (content_)
content_->docx_convert(Context);
if (!Context.get_section_context().dump_.empty() && !Context.get_table_context().in_table())
if (false == Context.get_section_context().dump_.empty() && false == Context.get_table_context().in_table())
{
Context.output_stream() << Context.get_section_context().dump_;
Context.get_section_context().dump_.clear();
}
else
{
if (page_layout_instance * lastPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
if (page_layout_instance *lastPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
{
Context.next_dump_page_properties(true);

View File

@ -34,7 +34,6 @@
#include <vector>
#include <CPSharedPtr.h>
#include <CPWeakPtr.h>
#include <xml/xmlelement.h>
#include <common/readdocelement.h>
@ -47,16 +46,17 @@
#include "visitor.h"
#include "../conversionelement.h"
#include "documentcontext.h"
#include "../../../Common/DocxFormat/Source/XML/Utils.h"
namespace cpdoccore {
namespace odf_reader {
class document_context;
class office_element;
typedef shared_ptr<office_element>::Type office_element_ptr;
typedef weak_ptr<office_element>::Type office_element_weak_ptr;
typedef std::vector<office_element_ptr> office_element_ptr_array;
class office_element : public xml::element<wchar_t>,
@ -69,17 +69,41 @@ public:
virtual ElementType get_type() const = 0;
virtual ~office_element() = 0;
void set_root(bool isRoot) { is_root_ = isRoot; }
bool is_root() const { return is_root_; }
virtual void afterCreate() {};
virtual void afterReadContent() {};
virtual void afterCreate()
{
if (context_ && this->get_type() != typeTextSection)
{
context_->level++;
}
}
virtual void afterReadContent()
{
if (context_ && this->get_type() != typeTextSection)
{
if (context_->level == 4)
{
if (office_element * prev= context_->get_last_element())
{
prev->next_element_style_name = element_style_name;
}
context_->set_last_element(this);
}
context_->level--;
}
}
CPDOCCORE_DEFINE_VISITABLE();
void setContext(document_context * Context) { context_ = Context; }
public:
_CP_OPT(std::wstring) element_style_name;
_CP_OPT(std::wstring) next_element_style_name; //for master page
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const
{
_CP_LOG << L"[warning] use base text_to_stream\n";
@ -92,8 +116,7 @@ public:
return _Wostream;
}
document_context * getContext() { return context_; }
//
//protected:
const document_context * getContext() const { return context_; }
private:

View File

@ -36,8 +36,10 @@
#include <xml/xmlchar.h>
#include <xml/attributes.h>
#include <xml/utils.h>
#include <odf/odf_document.h>
#include "serialize_elements.h"
#include "odfcontext.h"
namespace cpdoccore {
namespace odf_reader {
@ -94,17 +96,17 @@ bool is_text_content(const std::wstring & ns, const std::wstring & name)
{
return true; // all shapes //
}
else if (ns == L"office" && name == L"forms")
{
return true;
}
return false;
}
void office_text::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{
if CP_CHECK_NAME(L"office", L"forms")
{
CP_CREATE_ELEMENT(forms_);
}
else if CP_CHECK_NAME(L"text", L"tracked-changes")
if CP_CHECK_NAME(L"text", L"tracked-changes")
{
CP_CREATE_ELEMENT(tracked_changes_);
}
@ -149,13 +151,50 @@ void office_text::docx_convert(oox::docx_conversion_context & Context)
if (tracked_changes_)
tracked_changes_->docx_convert(Context);
if (forms_)
forms_->docx_convert(Context);
//if (forms_)
//forms_->docx_convert(Context);
Context.start_office_text();
for (size_t i = 0; i < content_.size(); i++)
{
content_[i]->docx_convert(Context);
if (content_[i]->element_style_name)
{
std::wstring text___ = *content_[i]->element_style_name;
const _CP_OPT(std::wstring) masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*content_[i]->element_style_name);
if (masterPageName)
{
std::wstring masterPageNameLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_name_by_style(*masterPageName);
if (false == masterPageNameLayout.empty())
{
Context.set_master_page_name(*masterPageName); //проверка на то что тема действительно существует????
Context.remove_page_properties();
Context.add_page_properties(masterPageNameLayout);
}
}
}
if (content_[i]->next_element_style_name)
{
std::wstring text___ = *content_[i]->next_element_style_name;
// проверяем не сменится ли свойства страницы.
// если да — устанавливаем контексту флаг на то что необходимо в текущем параграфе
// распечатать свойства раздела/секции
//проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*content_[i]->next_element_style_name);
if ((next_masterPageName) && (Context.get_master_page_name() != *next_masterPageName))
{
if (false == Context.root()->odf_context().pageLayoutContainer().compare_page_properties(Context.get_master_page_name(), *next_masterPageName))
{
Context.next_dump_page_properties(true);
//is_empty = false;
}
}
}
content_[i]->docx_convert(Context);
}
Context.end_office_text();
}

View File

@ -67,7 +67,7 @@ private:
office_element_ptr user_fields_;
office_element_ptr variables_;
office_element_ptr sequences_;
office_element_ptr forms_;
//office_element_ptr forms_; -> content
office_element_ptr_array content_;
};

View File

@ -128,9 +128,17 @@ std::wostream & text::text_to_stream(std::wostream & _Wostream) const
void text::add_text(const std::wstring & Text)
{
text_ = Text;
text_.reserve(Text.length());
for (size_t i =0; i < Text.length(); i++)
{
if (Text[i] < 0x20) continue;
text_ += Text[i];
}
}
text::text(const std::wstring & Text)
{
add_text(Text);
}
void text::docx_convert(oox::docx_conversion_context & Context)
{
if (Context.get_process_note() != oox::docx_conversion_context::noNote &&
@ -1209,10 +1217,21 @@ void sequence_ref::add_attributes( const xml::attributes_wc_ptr & Attributes )
}
void sequence_ref::add_text(const std::wstring & Text)
{
content_ = Text;
text_ = text::create(Text) ;
}
void sequence_ref::docx_convert(oox::docx_conversion_context & Context)
{
std::wstring ref, sequence;
if (!ref_name_) return;
Context.finish_run();
Context.output_stream() << L"<w:fldSimple w:instr=\" REF " << *ref_name_ << L" \\h\">";
Context.add_new_run();
if (text_)
text_->docx_convert(Context);
Context.finish_run();
Context.output_stream() << L"</w:fldSimple>";
}
//------------------------------------------------------------------------------------------------------------
const wchar_t * sequence::ns = L"text";
@ -1277,8 +1296,8 @@ void sequence::docx_convert(oox::docx_conversion_context & Context)
num_format= L"ARABIC"; break;
}
}
Context.output_stream() << L"<w:fldSimple w:instr=\" SEQ " << sequence << L" \\* " << num_format << L" \">";
Context.start_bookmark(*ref_name_);
Context.output_stream() << L"<w:fldSimple w:instr=\" SEQ " << XmlUtils::EncodeXmlString(sequence) << L" \\* " << num_format << L" \">";
Context.add_new_run();
for (size_t i = 0; i < text_.size(); i++)
{
@ -1291,6 +1310,8 @@ void sequence::docx_convert(oox::docx_conversion_context & Context)
// Context.end_bookmark(ref);
//}
Context.output_stream() << L"</w:fldSimple>";
Context.end_bookmark(*ref_name_);
}
void sequence::pptx_convert(oox::pptx_conversion_context & Context)
{
@ -1846,12 +1867,22 @@ void alphabetical_index_mark::add_attributes( const xml::attributes_wc_ptr & Att
}
void alphabetical_index_mark::docx_convert(oox::docx_conversion_context & Context)
{
if (!string_value_) return;
std::wstring value;
if (string_value_ && false == string_value_->empty())
{
if (*string_value_ != L" ")
value = *string_value_;
}
if (value.empty() && key1_)
{
value = *key1_;
}
if (value.empty()) return;
Context.finish_run();
Context.output_stream() << L"<w:r><w:fldChar w:fldCharType=\"begin\"/></w:r>";
Context.output_stream() << L"<w:r><w:instrText> XE \"" << *string_value_ << L"\"</w:instrText></w:r><w:r><w:fldChar w:fldCharType=\"end\"/></w:r>";
Context.output_stream() << L"<w:r><w:instrText> XE \"" << XmlUtils::EncodeXmlString(value) << L"\"</w:instrText></w:r><w:r><w:fldChar w:fldCharType=\"end\"/></w:r>";
}
//-----------------------------------------------------------------------------------------------
// text:alphabetical-index-mark-start

View File

@ -83,7 +83,7 @@ public:
bool preserve_;
text(const std::wstring & Text) : text_(Text) {preserve_ = true;};
text(const std::wstring & Text);
text() {preserve_ = true;};
std::wstring text_;
@ -891,7 +891,7 @@ public:
_CP_OPT(std::wstring) reference_format_;//caption, category-and-value, value, chapter, direction, page, text, number, number-all-superior, number-no-superior
_CP_OPT(std::wstring) ref_name_;
std::wstring content_;
office_element_ptr text_;
private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );

View File

@ -365,6 +365,7 @@ void text_format_properties_content::drawing_serialize(std::wostream & strm, std
CP_XML_ATTR(L"cap", "small");
}
}
std::wstring underline = L"";
if (fo_text_transform_)
{
if (fo_text_transform_->get_type() == text_transform::Uppercase)
@ -375,6 +376,10 @@ void text_format_properties_content::drawing_serialize(std::wostream & strm, std
{
CP_XML_ATTR(L"cap", "small");
}
else if (fo_text_transform_->get_type() == text_transform::Underline)
{
underline = L"sng";
}
}
const int W = process_font_weight(fo_font_weight_);
if (W > 0) CP_XML_ATTR(L"b", true);
@ -382,9 +387,7 @@ void text_format_properties_content::drawing_serialize(std::wostream & strm, std
// underline
line_width under = style_text_underline_width_.get_value_or(line_width::Auto);
bool underlineBold = under.get_type() == line_width::Bold ||
under.get_type() == line_width::Thick;
std::wstring underline = L"";
under.get_type() == line_width::Thick;
if ((style_text_underline_type_ && style_text_underline_type_->get_type() == line_type::None) ||
(style_text_underline_style_ && style_text_underline_style_->get_type() == line_style::None))

View File

@ -142,7 +142,9 @@ const wchar_t * table_table::name = L"table";
void table_table::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
table_table_attlist_.add_attributes(Attributes);
CP_APPLY_ATTR(L"table:style-name", element_style_name);
table_table_attlist_.add_attributes(Attributes);
}
void table_table::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)

View File

@ -144,6 +144,16 @@ void table_table::docx_convert(oox::docx_conversion_context & Context)
{
std::wostream & _Wostream = Context.output_stream();
std::wstring sDumpPageProperties;
if (false == Context.get_paragraph_state())
{
std::wstringstream strm;
if (Context.process_page_properties(strm))
{
sDumpPageProperties = strm.str();
}
}
bool sub_table = table_table_attlist_.table_is_sub_table_.get_value_or(false);
//todooo придумать как сделать внешние границы sub-таблицы границами внешней ячейки (чтоб слияние произошло)
@ -173,6 +183,15 @@ void table_table::docx_convert(oox::docx_conversion_context & Context)
Context.get_table_context().end_table();
_Wostream << L"</w:tbl>";
if (false == sDumpPageProperties.empty())
{
Context.output_stream() << L"<w:p>";
Context.output_stream() << L"<w:pPr>";
Context.output_stream() << sDumpPageProperties;
Context.output_stream() << L"</w:pPr>";
Context.output_stream() << L"</w:p>";
}
}
void table_columns::docx_convert(oox::docx_conversion_context & Context)

View File

@ -71,12 +71,6 @@ public:
};
template <class ElementT>
class text_content_impl : public office_element_impl<ElementT>
{
};
}
}
}

View File

@ -161,35 +161,6 @@ void paragraph::add_text(const std::wstring & Text)
office_element_ptr elm = text::create(Text) ;
content_.push_back( elm );
}
void paragraph::afterCreate(document_context * Context)
{
// вызывается сразу после создания объекта
if (Context)
{
Context->level++;
// выставляем у предыдущего параграфа указатель на следующий (т.е. на вновь созданный)
if (Context->level == 1)
{
if (paragraph * prevPar = Context->get_last_paragraph())
{
prevPar->set_next(this);
}
// запоминаем в контексте вновь созданный параграф
Context->set_last_paragraph(this);
}
}
}
void paragraph::afterReadContent(document_context * Context)
{
if (Context)
{
Context->level--;
}
}
const wchar_t * emptyParagraphContent = L"<w:pPr></w:pPr><w:r><w:rPr></w:rPr></w:r>";
const wchar_t * emptyParagraphDrawing = L"<w:p><w:pPr></w:pPr></w:p>";
@ -315,30 +286,22 @@ void paragraph::docx_convert(oox::docx_conversion_context & Context)
if (masterPageName)
{
Context.set_master_page_name(*masterPageName);
const std::wstring masterPageNameLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_name_by_style(*masterPageName);
Context.remove_page_properties();
Context.add_page_properties(masterPageNameLayout);
is_empty = false;
}
if (next_par_)
if (next_element_style_name)
{
// проверяем не сменит ли следующий параграф свойства страницы.
// если да — устанавливаем контексту флаг на то что необходимо в текущем параграфе
// распечатать свойства раздела/секции
//проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
const std::wstring & next_styleName = next_par_->attrs_.text_style_name_;
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(next_styleName);
// проверить ... не она ли текущая - может быть прописан дубляж - и тогда разрыв нарисуется ненужный
// dump был выше уровнем
const _CP_OPT(std::wstring) next_masterPageName = Context.root()->odf_context().styleContainer().master_page_name_by_name(*next_element_style_name);
if ((next_masterPageName) && (Context.get_master_page_name() != *next_masterPageName))
{
if (false == Context.root()->odf_context().pageLayoutContainer().compare_page_properties(Context.get_master_page_name(), *next_masterPageName))
{
Context.next_dump_page_properties(true);
is_empty = false;
}
}
@ -473,7 +436,9 @@ std::wostream & h::text_to_stream(std::wostream & _Wostream) const
void h::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"text:outline-level" , outline_level_);
CP_APPLY_ATTR(L"text:style-name", element_style_name);
CP_APPLY_ATTR(L"text:outline-level" , outline_level_);
CP_APPLY_ATTR(L"text:restart-numbering" , restart_numbering_);
CP_APPLY_ATTR(L"text:start-value" , start_value_);
CP_APPLY_ATTR(L"text:is-list-header" , is_list_header_);
@ -494,14 +459,12 @@ void h::add_text(const std::wstring & Text)
paragraph_.add_text(Text);
}
void h::afterCreate()
{
paragraph_.afterCreate( getContext() );
}
void h::afterReadContent()
{
paragraph_.afterReadContent( getContext() );
office_element::afterReadContent();
paragraph_.next_element_style_name = next_element_style_name;
}
void h::docx_convert(oox::docx_conversion_context & Context)
{
paragraph_.docx_convert(Context);
@ -520,14 +483,6 @@ void h::pptx_convert(oox::pptx_conversion_context & Context)
const wchar_t * p::ns = L"text";
const wchar_t * p::name = L"p";
void p::afterCreate()
{
paragraph_.afterCreate( getContext() );
}
void p::afterReadContent()
{
paragraph_.afterReadContent( getContext() );
}
std::wostream & p::text_to_stream(std::wostream & _Wostream) const
{
return paragraph_.text_to_stream(_Wostream);
@ -535,6 +490,8 @@ std::wostream & p::text_to_stream(std::wostream & _Wostream) const
void p::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"text:style-name", element_style_name);
paragraph_.add_attributes(Attributes);
}
@ -562,6 +519,11 @@ void p::pptx_convert(oox::pptx_conversion_context & Context)
{
paragraph_.pptx_convert(Context);
}
void p::afterReadContent()
{
office_element::afterReadContent();
paragraph_.next_element_style_name = next_element_style_name;
}
// text:list
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * list::ns = L"text";
@ -661,24 +623,35 @@ std::wostream & section::text_to_stream(std::wostream & _Wostream) const
void section::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
void section::afterReadContent()
{
if (document_context * context = getContext())
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void section::add_attributes( const xml::attributes_wc_ptr & Attributes )
@ -1076,11 +1049,17 @@ const wchar_t * illustration_index::name = L"illustration-index";
void illustration_index::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
@ -1089,11 +1068,16 @@ void illustration_index::afterReadContent()
{
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void illustration_index::docx_convert(oox::docx_conversion_context & Context)
{
@ -1219,11 +1203,17 @@ void alphabetical_index::add_child_element( xml::sax * Reader, const std::wstrin
}
void alphabetical_index::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
@ -1231,11 +1221,16 @@ void alphabetical_index::afterReadContent()
{
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void alphabetical_index::docx_convert(oox::docx_conversion_context & Context)
{
@ -1273,7 +1268,9 @@ const wchar_t * alphabetical_index_source::name = L"alphabetical-index-source";
void alphabetical_index_source::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"text:index-scope", index_scope_); // chapter or document
CP_APPLY_ATTR(L"text:index-scope", index_scope_); // chapter or document
CP_APPLY_ATTR(L"text:alphabetical-separators", alphabetical_separators_);
CP_APPLY_ATTR(L"text:ignore-case", ignore_case_);
}
void alphabetical_index_source::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
@ -1286,6 +1283,11 @@ void alphabetical_index_source::add_child_element( xml::sax * Reader, const std:
}
void alphabetical_index_source::docx_convert(oox::docx_conversion_context & Context)
{
if (alphabetical_separators_)
{
Context.get_table_content_context().bSeparators = alphabetical_separators_->get();
}
Context.get_table_content_context().start_template(5);
for (size_t i = 0; i < entry_templates_.size(); i++)
{
@ -1317,11 +1319,17 @@ const wchar_t * object_index::name = L"object-index";
void object_index::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
@ -1329,11 +1337,16 @@ void object_index::afterReadContent()
{
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void object_index::docx_convert(oox::docx_conversion_context & Context)
{
@ -1419,11 +1432,17 @@ const wchar_t * user_index::name = L"user-index";
void user_index::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
@ -1431,11 +1450,16 @@ void user_index::afterReadContent()
{
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void user_index::docx_convert(oox::docx_conversion_context & Context)
{
@ -1560,11 +1584,17 @@ const wchar_t * bibliography::name = L"bibliography";
void bibliography::afterCreate()
{
if (document_context * context = getContext())
office_element::afterCreate();
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_section(true);
lastPar->paragraph_.set_next_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_section(true);
}
}
}
@ -1573,11 +1603,16 @@ void bibliography::afterReadContent()
{
if (document_context * context = getContext())
{
if (paragraph * lastPar = context->get_last_paragraph())
if (p *lastPar = dynamic_cast<p*>(context->get_last_element()))
{
lastPar->set_next_end_section(true);
lastPar->paragraph_.set_next_end_section(true);
}
else if (h *lastPar = dynamic_cast<h*>(context->get_last_element()))
{
lastPar->paragraph_.set_next_end_section(true);
}
}
office_element::afterReadContent();
}
void bibliography::docx_convert(oox::docx_conversion_context & Context)
{

View File

@ -51,7 +51,7 @@ namespace text {
class paragraph
{
public:
paragraph() : next_par_(NULL), next_section_(false), next_end_section_(false), is_header_(false) {}
paragraph() : next_section_(false), next_end_section_(false), is_header_(false) {}
std::wostream & text_to_stream(std::wostream & _Wostream) const;
@ -59,9 +59,8 @@ public:
void add_child_element ( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name, document_context * Context);
void add_text (const std::wstring & Text);
paragraph * get_next() { return next_par_; }
void set_next(paragraph * next) {next_par_ = next;}
_CP_OPT(std::wstring) next_element_style_name; //for master page
void set_next_section(bool Val)
{
next_section_ = Val;
@ -71,9 +70,6 @@ public:
{
next_end_section_ = Val;
}
void afterCreate(document_context * ctx);
void afterReadContent(document_context * ctx);
void docx_convert (oox::docx_conversion_context & Context) ;
void xlsx_convert (oox::xlsx_conversion_context & Context) ;
@ -88,21 +84,18 @@ private:
paragraph_attrs attrs_;
paragraph *next_par_;
bool next_section_;
bool next_end_section_;
bool is_header_;
friend class par_docx_convert_class;
friend class p;
friend class h;
};
//---------------------------------------------------------------------------------------------------
class h : public text_content_impl<h>
class h : public office_element_impl<h>
{
public:
static const wchar_t * ns;
@ -115,9 +108,8 @@ public:
void xlsx_convert(oox::xlsx_conversion_context & Context) ;
void pptx_convert(oox::pptx_conversion_context & Context) ;
virtual void afterCreate();
virtual void afterReadContent();
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const;
paragraph paragraph_;
@ -134,14 +126,12 @@ private:
_CP_OPT(bool) is_list_header_;
_CP_OPT(std::wstring) number_;
friend class par_docx_convert_class;
};
CP_REGISTER_OFFICE_ELEMENT2(h);
//---------------------------------------------------------------------------------------------------
class p : public text_content_impl<p>
class p : public office_element_impl<p>
{
public:
static const wchar_t * ns;
@ -154,7 +144,6 @@ public:
void xlsx_convert(oox::xlsx_conversion_context & Context) ;
void pptx_convert(oox::pptx_conversion_context & Context) ;
virtual void afterCreate();
virtual void afterReadContent();
virtual std::wostream & text_to_stream(std::wostream & _Wostream) const;
@ -167,12 +156,11 @@ private:
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
virtual void add_text(const std::wstring & Text);
friend class par_docx_convert_class;
};
CP_REGISTER_OFFICE_ELEMENT2(p);
//---------------------------------------------------------------------------------------------------
class list : public text_content_impl<list>
class list : public office_element_impl<list>
{
public:
static const wchar_t * ns;
@ -203,7 +191,7 @@ private:
CP_REGISTER_OFFICE_ELEMENT2(list);
//---------------------------------------------------------------------------------------------------
class soft_page_break : public text_content_impl<soft_page_break>
class soft_page_break : public office_element_impl<soft_page_break>
{
public:
static const wchar_t * ns;
@ -223,7 +211,7 @@ private:
CP_REGISTER_OFFICE_ELEMENT2(soft_page_break);
//---------------------------------------------------------------------------------------------------
class section : public text_content_impl<section>
class section : public office_element_impl<section>
{
public:
static const wchar_t * ns;
@ -265,7 +253,7 @@ private:
};
//---------------------------------------------------------------------------------------------------
class section_source : public text_content_impl<section_source>
class section_source : public office_element_impl<section_source>
{
public:
static const wchar_t * ns;
@ -305,7 +293,7 @@ public:
};
//---------------------------------------------------------------------------------------------------
class table_of_content : public text_content_impl<table_of_content>
class table_of_content : public office_element_impl<table_of_content>
{
public:
static const wchar_t * ns;
@ -335,7 +323,7 @@ CP_REGISTER_OFFICE_ELEMENT2(table_of_content);
//---------------------------------------------------------------------------------------------------
// text:table-index
//---------------------------------------------------------------------------------------------------
class table_index : public text_content_impl<table_index>
class table_index : public office_element_impl<table_index>
{
public:
static const wchar_t * ns;
@ -364,7 +352,7 @@ CP_REGISTER_OFFICE_ELEMENT2(table_index);
//---------------------------------------------------------------------------------------------------
// text:illustration-index
//---------------------------------------------------------------------------------------------------
class illustration_index : public text_content_impl<illustration_index>
class illustration_index : public office_element_impl<illustration_index>
{
public:
static const wchar_t * ns;
@ -396,7 +384,7 @@ CP_REGISTER_OFFICE_ELEMENT2(illustration_index);
//---------------------------------------------------------------------------------------------------
// text:alphabetical-index
//---------------------------------------------------------------------------------------------------
class alphabetical_index : public text_content_impl<alphabetical_index>
class alphabetical_index : public office_element_impl<alphabetical_index>
{
public:
static const wchar_t * ns;
@ -428,7 +416,7 @@ CP_REGISTER_OFFICE_ELEMENT2(alphabetical_index);
//---------------------------------------------------------------------------------------------------
// text:object-index
//---------------------------------------------------------------------------------------------------
class object_index : public text_content_impl<object_index>
class object_index : public office_element_impl<object_index>
{
public:
static const wchar_t * ns;
@ -460,7 +448,7 @@ CP_REGISTER_OFFICE_ELEMENT2(object_index);
//---------------------------------------------------------------------------------------------------
// text:user-index
//---------------------------------------------------------------------------------------------------
class user_index : public text_content_impl<user_index>
class user_index : public office_element_impl<user_index>
{
public:
static const wchar_t * ns;
@ -492,7 +480,7 @@ CP_REGISTER_OFFICE_ELEMENT2(user_index);
//------------------------------------------------------------------------------------------------------------
// text:bibliography
//------------------------------------------------------------------------------------------------------------
class bibliography : public text_content_impl<bibliography>
class bibliography : public office_element_impl<bibliography>
{
public:
static const wchar_t * ns;
@ -565,7 +553,7 @@ CP_REGISTER_OFFICE_ELEMENT2(bibliography_entry_template);
//---------------------------------------------------------------------------------------------------
//text:index-body
//---------------------------------------------------------------------------------------------------
class index_body : public text_content_impl<index_body>
class index_body : public office_element_impl<index_body>
{
public:
static const wchar_t * ns;
@ -588,7 +576,7 @@ private:
};
CP_REGISTER_OFFICE_ELEMENT2(index_body);
//---------------------------------------------------------------------------------------------------
class index_title : public text_content_impl<index_title>
class index_title : public office_element_impl<index_title>
{
public:
static const wchar_t * ns;
@ -613,7 +601,7 @@ public:
};
CP_REGISTER_OFFICE_ELEMENT2(index_title);
//---------------------------------------------------------------------------------------------------
class index_title_template : public text_content_impl<index_title_template>
class index_title_template : public office_element_impl<index_title_template>
{
public:
static const wchar_t * ns;
@ -1283,7 +1271,9 @@ 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);
_CP_OPT(std::wstring) index_scope_; // chapter or document:
_CP_OPT(std::wstring) index_scope_; // chapter or document:
_CP_OPT(odf_types::Bool) alphabetical_separators_;
_CP_OPT(odf_types::Bool) ignore_case_;
//fo:country
//fo:language
@ -1295,7 +1285,6 @@ private:
//text:combine-entries-with-dash
//text:combine-entries-with-pp
//text:comma-separated
//text:ignore-case
//text:main-entry-style-name
//text:relative-tab-stop-position
//text:sort-algorithm

View File

@ -284,8 +284,8 @@ private:
class Impl;
_CP_PTR(Impl) impl_;
};
typedef shared_ptr<odf_drawing_context>::Type odf_drawing_context_ptr;
}
}

View File

@ -464,35 +464,49 @@ void odf_text_context::end_list()
}
//------------------------------------------------------------------------------------------ LIST
bool odf_text_context::start_field(int type)
bool odf_text_context::start_field(int type, const std::wstring& value)
{
if (single_paragraph_ == true) return false;
office_element_ptr elm;
if (type == 2)
switch(type)
{
create_element(L"text", L"page-number", elm, odf_context_);
text_page_number *page_numb = dynamic_cast<text_page_number*>(elm.get());
if (page_numb)
case fieldXE:
{
page_numb->text_select_page_ = L"current";
create_element(L"text", L"alphabetical-index-mark", elm, odf_context_);
text_alphabetical_index_mark *index = dynamic_cast<text_alphabetical_index_mark*>(elm.get());
if (index)
{
index->key1_ = value;
index->string_value_ = value;
}
}break;
case fieldPage:
{
create_element(L"text", L"page-number", elm, odf_context_);
text_page_number *page_numb = dynamic_cast<text_page_number*>(elm.get());
if (page_numb)
{
page_numb->text_select_page_ = L"current";
if ( (odf_context_->page_layout_context()) &&
(odf_context_->page_layout_context()->last_layout()) &&
(odf_context_->page_layout_context()->last_layout()->page_number_format))
{
if ( (odf_context_->page_layout_context()) &&
(odf_context_->page_layout_context()->last_layout()) &&
(odf_context_->page_layout_context()->last_layout()->page_number_format))
{
page_numb->common_num_format_attlist_.style_num_format_ = odf_context_->page_layout_context()->last_layout()->page_number_format;
}
}
}
if (type == 3)
{
create_element(L"text", L"page-count", elm, odf_context_);
}
if (type == 4)
{
create_element(L"text", L"date", elm, odf_context_);
page_numb->common_num_format_attlist_.style_num_format_ = odf_context_->page_layout_context()->last_layout()->page_number_format;
}
}
}break;
case fieldNumPages:
{
create_element(L"text", L"page-count", elm, odf_context_);
}break;
case fieldTime:
{
create_element(L"text", L"date", elm, odf_context_);
}break;
}
if (elm)

View File

@ -43,7 +43,23 @@
namespace cpdoccore {
namespace odf_writer
{
enum _typeField
{
fieldUnknown = 0,
fieldHyperlink,
fieldPage,
fieldNumPages,
fieldTime,
fieldPageRef,
fieldSeq,
fieldXE,
fieldBibliography = 0xff + 1,
fieldIndex,
fieldIllustration,
fieldTable,
fieldToc
};
class odf_conversion_context;
class odf_style_context;
class paragraph;
@ -80,7 +96,7 @@ public:
void start_element (office_element_ptr & elm, office_element_ptr style_elm = office_element_ptr(),std::wstring style_name = L"");
void end_element ();
bool start_field (int type);
bool start_field (int type, const std::wstring& value);
void end_field ();
void start_span (bool styled = false);
@ -139,6 +155,7 @@ private:
std::wstring parent_span_style_;
std::wstring parent_paragraph_style_;
};
typedef shared_ptr<odf_text_context>::Type odf_text_context_ptr;
}
}

View File

@ -37,7 +37,6 @@
#include "../utils.h"
#include "odt_conversion_context.h"
#include "odf_text_context.h"
#include "styles.h"
@ -114,6 +113,27 @@ void odt_conversion_context::start_document()
void odt_conversion_context::end_document()
{
if (false == mapSequenceDecls.empty())
{
office_element_ptr seq_decls;
create_element(L"text", L"sequence-decls", seq_decls, this);
for (std::map<std::wstring, int>::iterator it = mapSequenceDecls.begin(); it != mapSequenceDecls.end(); ++it)
{
office_element_ptr elm;
create_element(L"text", L"sequence-decl", elm, this);
text_sequence_decl* decl = dynamic_cast<text_sequence_decl*>(elm.get());
if (decl)
{
decl->name_ = it->first;
decl->display_outline_level_ = 0;
}
seq_decls->add_child_element(elm);
}
root_document_->add_child_element(seq_decls);
}
//add sections to root
for (size_t i = 0; i < sections_.size(); i++)
{
@ -283,16 +303,17 @@ void odt_conversion_context::end_drawings()
}
void odt_conversion_context::start_paragraph(bool styled)
{
if (!current_fields.empty() && current_fields.back().started == false && !current_fields.back().in_span)
if (!current_fields.empty() && current_fields.back().status == 1 && !current_fields.back().in_span)
{
current_fields.back().status = 2;
//if (!current_fields.empty() && !current_fields.back().result) return; //Стандартное_составное_письмо.docx
switch (current_fields.back().type)
{
case 6: current_fields.back().started = start_bibliography(); break;
case 7: current_fields.back().started = start_alphabetical_index(); break;
case 8: //current_fields.back().started = start_table_index(); break;
case 9: current_fields.back().started = start_illustration_index(); break;
case 10:current_fields.back().started = start_table_of_content(); break;
case fieldBibliography: start_bibliography(); break;
case fieldIndex: start_alphabetical_index(); break;
case fieldIllustration: start_illustration_index(); break;
case fieldTable: start_table_index(); break;
case fieldToc: start_table_of_content(); break;
}
}
if (is_paragraph_in_current_section_ && !styled)
@ -352,56 +373,100 @@ void odt_conversion_context::add_paragraph_break(int type)
//}
}
}
bool odt_conversion_context::start_table_of_content()
void odt_conversion_context::start_table_of_content()
{
office_element_ptr elm1, elm2;
office_element_ptr elm;
create_element(L"text", L"table-of-content", elm1, this);
text_context()->start_element(elm1);
create_element(L"text", L"table-of-content", elm, this);
text_context()->start_element(elm);
add_to_root();
start_index_field();
}
void odt_conversion_context::end_table_of_content()
{
text_context()->end_element();
office_element_ptr elm;
create_element(L"text", L"table-of-content-source", elm, this);
text_table_of_content_source* source = dynamic_cast<text_table_of_content_source*>(elm.get());
if (source)
{
if (false == current_fields.back().arStyleLevels.empty())
{
source->outline_level_ = (int) current_fields.back().arStyleLevels.size();
source->use_index_source_styles_ = true;
}
else if (current_fields.back().outline_levels > 0)
{
source->outline_level_ = current_fields.back().outline_levels;
}
}
text_context()->start_element(elm);
//template
text_context()->end_element();
text_context()->end_element();
}
void odt_conversion_context::start_alphabetical_index()
{
office_element_ptr elm;
create_element(L"text", L"alphabetical-index", elm, this);
text_context()->start_element(elm);
add_to_root();
create_element(L"text", L"table-of-content-source", elm2, this);
text_context()->start_element(elm2);
text_context()->end_element();
start_index_field();
return true;
}
bool odt_conversion_context::start_alphabetical_index()
void odt_conversion_context::end_alphabetical_index()
{
office_element_ptr elm1, elm2;
create_element(L"text", L"alphabetical-index", elm1, this);
text_context()->start_element(elm1);
add_to_root();
create_element(L"text", L"alphabetical-index-source", elm2, this);
text_context()->start_element(elm2);
text_context()->end_element();
start_index_field();
return true;
}
bool odt_conversion_context::start_illustration_index()
office_element_ptr elm;
create_element(L"text", L"alphabetical-index-source", elm, this);
text_context()->start_element(elm);
//tempalte
text_context()->end_element();
text_context()->end_element();
}
void odt_conversion_context::start_illustration_index()
{
office_element_ptr elm1, elm2;
create_element(L"text", L"illustration-index", elm1, this);
text_context()->start_element(elm1);
office_element_ptr elm;
create_element(L"text", L"illustration-index", elm, this);
text_context()->start_element(elm);
add_to_root();
create_element(L"text", L"illustration-index-source", elm2, this);
text_context()->start_element(elm2);
text_context()->end_element();
start_index_field();
return true;
}
void odt_conversion_context::end_illustration_index()
{
text_context()->end_element();
office_element_ptr elm;
create_element(L"text", L"illustration-index-source", elm, this);
text_illustration_index_source* index_source = dynamic_cast<text_illustration_index_source*>(elm.get());
if (index_source)
{
if (false == current_fields.back().captionSEQ.empty())
{
index_source->caption_sequence_name_ = current_fields.back().captionSEQ;
index_source->caption_sequence_format_ = L"text";
}
}
text_context()->start_element(elm);
//template
text_context()->end_element();
text_context()->end_element();
}
bool odt_conversion_context::start_bibliography()
void odt_conversion_context::start_bibliography()
{
office_element_ptr elm;
create_element(L"text", L"bibliography", elm, this);
@ -409,34 +474,42 @@ bool odt_conversion_context::start_bibliography()
add_to_root();
create_element(L"text", L"bibliography-source", elm, this);
text_context()->start_element(elm);
text_context()->end_element();
start_index_field();
return true;
}
bool odt_conversion_context::start_table_index()
void odt_conversion_context::end_bibliography()
{
text_context()->end_element();
office_element_ptr elm;
create_element(L"text", L"bibliography-source", elm, this);
text_context()->start_element(elm);
//template
text_context()->end_element();
text_context()->end_element();
}
void odt_conversion_context::start_table_index()
{
end_paragraph();
office_element_ptr elm;
create_element(L"text", L"table-index", elm, this);
text_context()->start_element(elm);
add_to_root();
create_element(L"text", L"table-index-source", elm, this);
text_context()->start_element(elm);
text_context()->end_element();
start_index_field();
start_paragraph();
return true;
}
void odt_conversion_context::end_table_index()
{
text_context()->end_element();
office_element_ptr elm;
create_element(L"text", L"table-index-source", elm, this);
text_context()->start_element(elm);
//template
text_context()->end_element();
text_context()->end_element();
}
void odt_conversion_context::start_index_field()
{
if (current_fields.empty()) return;
@ -458,26 +531,21 @@ void odt_conversion_context::end_index_field()
text_context()->end_element();
}
bool odt_conversion_context::start_hyperlink(std::wstring ref)
void odt_conversion_context::start_hyperlink(std::wstring ref)
{
office_element_ptr hyperlink_elm;
create_element(L"text", L"a", hyperlink_elm, this);
text_a* hyperlink = dynamic_cast<text_a*>(hyperlink_elm.get());
if (!hyperlink)return false;
if (hyperlink)
{
hyperlink->common_xlink_attlist_.href_ = ref;
hyperlink->common_xlink_attlist_.type_ = xlink_type::Simple;
text_context()->start_element(hyperlink_elm);
////////////////////////////
hyperlink->common_xlink_attlist_.href_ = ref;
hyperlink->common_xlink_attlist_.type_ = xlink_type::Simple;
//current_level_.back()->add_child_element(hyperlink_elm);
//current_level_.push_back(hyperlink_elm);
text_context()->start_element(hyperlink_elm);
is_hyperlink_ = true;
return true;
is_hyperlink_ = true;
}
}
void odt_conversion_context::end_hyperlink()
{
@ -487,7 +555,37 @@ void odt_conversion_context::end_hyperlink()
is_hyperlink_ = false; //метка .. для гиперлинков в объектах - там не будет span
}
void odt_conversion_context::start_sequence()
{
std::map<std::wstring, int>::iterator pFind = mapSequenceDecls.find(current_fields.back().value);
int index = 0;
if (pFind == mapSequenceDecls.end())
{
mapSequenceDecls.insert(std::make_pair(current_fields.back().value, index));
}
else
{
index = ++pFind->second;
}
office_element_ptr seq_elm;
create_element(L"text", L"sequence", seq_elm, this);
text_sequence* sequence = dynamic_cast<text_sequence*>(seq_elm.get());
if (sequence)
{
sequence->name_ = current_fields.back().value;
sequence->ref_name_ = L"ref" + current_fields.back().value + std::to_wstring(index);
sequence->formula_ = L"ooow:" + current_fields.back().value + L"+1";
sequence->style_num_format_ = style_numformat(style_numformat::arabic);
text_context()->start_element(seq_elm);
}
}
void odt_conversion_context::end_sequence()
{
text_context()->end_element();
}
std::map<std::wstring, std::wstring> odt_conversion_context::parse_instr_options(const std::wstring& value)
{
std::map<std::wstring, std::wstring> result;
@ -499,9 +597,23 @@ std::map<std::wstring, std::wstring> odt_conversion_context::parse_instr_options
{
std::wstring key = arOptions[i].substr(0, 1);
std::wstring value;
if (arOptions[i].length() > 1)
if (arOptions[i].length() > 2)
{
value = arOptions[i].substr(1);
size_t pos = arOptions[i].find(L"\"");
if (std::wstring::npos != pos)
{
value = arOptions[i].substr(pos + 1, arOptions[i].length() - pos - 1);
pos = value.rfind(L"\"");
if (std::wstring::npos != pos)
{
value = value.substr(0, pos);
}
}
else
{
value = arOptions[i].substr(1);
}
}
result.insert(std::make_pair(key, value));
}
@ -514,10 +626,12 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
{
if (current_fields.empty()) return;
current_fields.back().status = 1; //prepare
size_t res1 = instr.find(L"HYPERLINK");
if (std::wstring::npos != res1)
{
current_fields.back().type = 1;
current_fields.back().type = fieldHyperlink;
current_fields.back().in_span = false;
std::wstring ref;
@ -533,41 +647,73 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
res1 = instr.find(L"NUMPAGES");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 3;
current_fields.back().type = fieldNumPages;
}
res1 = instr.find(L"PAGEREF");
if (std::wstring::npos != res1 && current_fields.back().type == 0 )
{
current_fields.back().type = 5;
current_fields.back().type = fieldPageRef;
if (instr.length() > 9)
current_fields.back().value = instr.substr(9, instr.length() - 5);
}
res1 = instr.find(L"PAGE");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 2;
current_fields.back().type = fieldPage;
}
res1 = instr.find(L"TIME");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 4;
current_fields.back().type = fieldTime;
}
res1 = instr.find(L"SEQ");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = fieldSeq;
std::map<std::wstring, std::wstring> options = parse_instr_options(instr.substr(4));
for (std::map<std::wstring, std::wstring>::iterator it = options.begin(); it != options.end(); ++it)
{
if (it->first == L" ")//field-argument
{
current_fields.back().value = it->second.substr(0, it->second.length() - 1);
}
else if (it->first == L"*")
{
current_fields.back().format = it->second.substr(0, it->second.length() - 1);
}
}
}
res1 = instr.find(L"XE");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = fieldXE;
std::map<std::wstring, std::wstring> options = parse_instr_options(instr.substr(3));
for (std::map<std::wstring, std::wstring>::iterator it = options.begin(); it != options.end(); ++it)
{
if (it->first == L" ")//field-argument
{
current_fields.back().value = it->second.substr(0, it->second.length() - 1);
}
}
}
res1 = instr.find(L"BIBLIOGRAPHY");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 6;
current_fields.back().type = fieldBibliography;
current_fields.back().in_span = false;
}
res1 = instr.find(L"INDEX");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 7;
current_fields.back().type = fieldIndex;
current_fields.back().in_span = false;
}
res1 = instr.find(L"TOC");
if (std::wstring::npos != res1 && current_fields.back().type == 0)
{
current_fields.back().type = 8;
current_fields.back().type = fieldIllustration;
current_fields.back().in_span = false;
std::map<std::wstring, std::wstring> options = parse_instr_options(instr.substr(res1 + 3));
@ -584,12 +730,36 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
pFind = options.find(L"u"); //paragraph outline level
if ( pFind != options.end())
{
current_fields.back().type = 10; //table of content
current_fields.back().type = fieldToc; //table of content
}
pFind = options.find(L"o");
if ( pFind != options.end())//table of content outline levels style
{
current_fields.back().type = 10;
std::vector<std::wstring> arLevels;
boost::algorithm::split(arLevels, pFind->second, boost::algorithm::is_any_of(L"-"), boost::algorithm::token_compress_on);
if (arLevels.size() > 1)
{
current_fields.back().type = fieldToc;
current_fields.back().outline_levels = XmlUtils::GetInteger(arLevels[1]);
}
}
pFind = options.find(L"t");
if ( pFind != options.end())//content styles name
{
std::vector<std::wstring> arStyles;
boost::algorithm::split(arStyles, pFind->second, boost::algorithm::is_any_of(L";"), boost::algorithm::token_compress_on);
for (size_t i = 0; i < arStyles.size() - 1; i += 2)
{
int level = XmlUtils::GetInteger(arStyles[i + 1]);
if (level < 1) continue;
while(current_fields.back().arStyleLevels.size() + 1 < level )
{
current_fields.back().arStyleLevels.push_back(L"");
}
current_fields.back().arStyleLevels.push_back(arStyles[i]);
}
}
pFind = options.find(L"z");
if ( pFind != options.end())//table of content outline levels style
@ -615,6 +785,9 @@ void odt_conversion_context::set_field_instr(std::wstring instr)
}
void odt_conversion_context::start_field(bool in_span)
{
if (false == current_fields.empty() && current_fields.back().status == 0)
return; //start_field из sdt
_field_state field;
current_fields.push_back(field);
}
@ -761,28 +934,42 @@ void odt_conversion_context::end_field()
{
if (current_fields.empty()) return;
if (current_fields.back().started)
if (current_fields.back().status == 2)
{
switch(current_fields.back().type)
current_fields.back().status = 3;//prepare for delete
if (current_fields.back().type < 0xff)
{
case 1: end_hyperlink(); break;
case 6:
case 7:
case 8:
case 9:
case 10: end_index_field(); break;
default:
text_context()->end_field();
if (current_fields.back().type == fieldHyperlink) end_hyperlink();
else if (current_fields.back().type == fieldSeq) end_sequence();
else text_context()->end_field();
current_fields.pop_back();
}
}
current_fields.pop_back();
else if (current_fields.back().status == 0)
{
current_fields.pop_back();
}
}
void odt_conversion_context::end_paragraph()
{
if (!current_fields.empty() && !current_fields.back().result) return; //Стандартное_составное_письмо.docx
//if (!current_fields.empty() && !current_fields.back().result) return; //Стандартное_составное_письмо.docx
text_context()->end_paragraph();
if (false == current_fields.empty() && current_fields.back().status == 3) //prepare for delete
{
switch(current_fields.back().type)
{
case fieldBibliography: end_bibliography(); break;
case fieldIndex: end_alphabetical_index(); break;
case fieldIllustration: end_illustration_index(); break;
case fieldTable: end_table_index(); break;
case fieldToc: end_table_of_content(); break;
}
current_fields.pop_back();
}
flush_section();
}
@ -882,10 +1069,13 @@ void odt_conversion_context::start_run(bool styled)
{
if (is_hyperlink_ && text_context_.size() > 0) return;
if (!current_fields.empty() && current_fields.back().started == false && !current_fields.back().in_span)
if (!current_fields.empty() && current_fields.back().status == 1 && !current_fields.back().in_span && current_fields.back().type < 0xff)
{
if (current_fields.back().type == 1) current_fields.back().started = start_hyperlink(current_fields.back().value);
else if (current_fields.back().type < 6) current_fields.back().started = text_context()->start_field(current_fields.back().type);
current_fields.back().status = 2;
if (current_fields.back().type == fieldHyperlink) start_hyperlink(current_fields.back().value);
else if (current_fields.back().type == fieldSeq) start_sequence();
else text_context()->start_field(current_fields.back().type, current_fields.back().value);
}
text_context()->start_span(styled);
@ -897,16 +1087,17 @@ void odt_conversion_context::start_run(bool styled)
props->apply_from(dynamic_cast<style_text_properties*>(drop_cap_state_.text_properties.get()));
}
if (!current_fields.empty() && current_fields.back().started == false && current_fields.back().in_span)//поле стартуется в span - нужно для сохранения стиля
if (!current_fields.empty() && current_fields.back().status == 1 && current_fields.back().in_span)//поле стартуется в span - нужно для сохранения стиля
{
current_fields.back().started = text_context()->start_field(current_fields.back().type);
current_fields.back().status = 2;
text_context()->start_field(current_fields.back().type, current_fields.back().value);
}
}
void odt_conversion_context::end_run()
{
if (is_hyperlink_ && text_context_.size() > 0) return;
if (!current_fields.empty() && current_fields.back().started == true && current_fields.back().in_span)
if (!current_fields.empty() && current_fields.back().status == 1 && current_fields.back().in_span)
{
end_field();
}

View File

@ -36,17 +36,14 @@
#include "odf_comment_context.h"
#include "odf_notes_context.h"
#include "odf_table_context.h"
#include "odf_text_context.h"
namespace cpdoccore {
namespace odf_writer {
namespace cpdoccore
{
namespace odf_writer
{
class office_text;
class odf_text_context;
typedef shared_ptr<odf_text_context>::Type odf_text_context_ptr;
typedef shared_ptr<odf_drawing_context>::Type odf_drawing_context_ptr;
struct odt_section_state
{
office_element_ptr elm;
@ -90,14 +87,26 @@ public:
void add_paragraph_break(int type);
bool start_hyperlink (std::wstring ref);
void start_hyperlink (std::wstring ref);
void end_hyperlink ();
bool start_table_of_content ();
bool start_bibliography ();
bool start_alphabetical_index ();
bool start_illustration_index ();
bool start_table_index ();
void start_sequence ();
void end_sequence ();
void start_table_of_content ();
void end_table_of_content ();
void start_bibliography ();
void end_bibliography ();
void start_alphabetical_index ();
void end_alphabetical_index ();
void start_illustration_index ();
void end_illustration_index ();
void start_table_index ();
void end_table_index ();
void start_index_field();
void end_index_field();
@ -192,23 +201,29 @@ private:
std::vector<odf_element_state> current_root_elements_; // for section, if needed
std::vector<odt_section_state> sections_;
std::map<std::wstring, int> mapSequenceDecls;
void add_to_root();
struct _field_state
{
int type = 0;
_typeField type = fieldUnknown;
std::wstring name;
std::wstring value;
std::wstring format;
bool started = false;
short status = 0;//0, 1, 2, 3 - init, prapare, start, finish
bool in_span = false;
bool result;
bool result = false; //after separate
bool bHyperlinks = false;
bool bHidePageNumbers = false;
std::wstring captionSEQ;
std::wstring title;
std::vector<std::wstring> arStyleLevels;
int outline_levels = 0;
std::vector<int> arTemplateTypes;//text, link, tab ....
int tabLeader = 0;//dot
};
std::vector<_field_state> current_fields;

View File

@ -89,14 +89,34 @@ void office_text_attlist::serialize(CP_ATTR_NODE)
}
void office_text::create_child_element( const std::wstring & Ns, const std::wstring & Name)
{
if (is_text_content(Ns, Name))
{
CP_CREATE_ELEMENT(content_);
}
if CP_CHECK_NAME(L"office", L"forms")
{
CP_CREATE_ELEMENT(forms_);
}
else if CP_CHECK_NAME(L"text", L"tracked-changes")
{
CP_CREATE_ELEMENT(tracked_changes_);
}
else if CP_CHECK_NAME(L"table", L"content-validations")
{
CP_CREATE_ELEMENT(table_content_validations_);
}
else if CP_CHECK_NAME(L"text", L"user-field-decls")
{
CP_CREATE_ELEMENT(user_fields_);
}
else if CP_CHECK_NAME(L"text", L"sequence-decls")
{
CP_CREATE_ELEMENT(sequences_);
}
else if CP_CHECK_NAME(L"text", L"variable-decls")
{
CP_CREATE_ELEMENT(variables_);
}
else if (is_text_content(Ns, Name))
{
CP_CREATE_ELEMENT(content_);
}
else
CP_NOT_APPLICABLE_ELM();
}
@ -107,6 +127,10 @@ void office_text::add_child_element( const office_element_ptr & child_element)
switch(child_element->get_type())
{
case typeTextSequenceDecls:
{
sequences_ = child_element;
}break;
case typeTextTrackedChanges:
{
tracked_changes_ = child_element;
@ -130,6 +154,9 @@ void office_text::serialize(std::wostream & _Wostream)
{
office_text_attlist_.serialize(CP_GET_XML_NODE());
if (sequences_)
sequences_->serialize(CP_XML_STREAM());
if (tracked_changes_)
tracked_changes_->serialize(CP_XML_STREAM());

View File

@ -71,7 +71,13 @@ public:
private:
office_element_ptr tracked_changes_;
office_element_ptr_array content_;
office_element_ptr table_content_validations_;
office_element_ptr user_fields_;
office_element_ptr variables_;
office_element_ptr sequences_;
office_element_ptr forms_;
office_element_ptr_array content_;
// TODO: office-text-content-prelude:
// TODO: office-forms

View File

@ -71,6 +71,13 @@ using xml::xml_char_wc;
const wchar_t * text_text::ns = L"";
const wchar_t * text_text::name = L"";
std::wostream & text_text::text_to_stream(std::wostream & _Wostream) const
{
_Wostream << xml::utils::replace_text_to_xml( text_ );
return _Wostream;
}
void text_text::serialize(std::wostream & _Wostream)
{
_Wostream << xml::utils::replace_text_to_xml( text_ );
@ -236,6 +243,14 @@ void text_reference_mark_end::serialize(std::wostream & _Wostream)
const wchar_t * text_span::ns = L"text";
const wchar_t * text_span::name = L"span";
std::wostream & text_span::text_to_stream(std::wostream & _Wostream) const
{
for (size_t i = 0; i < paragraph_content_.size(); i++)
{
paragraph_content_[i]->text_to_stream(_Wostream);
}
return _Wostream;
}
void text_span::serialize(std::wostream & _Wostream)
{
CP_XML_WRITER(_Wostream)
@ -772,9 +787,15 @@ void text_sequence::serialize(std::wostream & _Wostream)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"text:name", name_);
CP_XML_ATTR_OPT(L"text:ref-name", ref_name_);
CP_XML_ATTR_OPT(L"style:num-format", style_num_format_);
CP_XML_ATTR_OPT(L"style:num-letter-syn", style_num_letter_sync_);
CP_XML_ATTR_OPT(L"text:formula", formula_);
for (size_t i = 0; i < text_.size(); i++)
{
text_[i]->serialize(CP_XML_STREAM());
text_[i]->text_to_stream(CP_XML_STREAM());
}
}
}

View File

@ -65,7 +65,8 @@ public:
virtual void create_child_element(const std::wstring & Ns, const std::wstring & Name){}
virtual void add_child_element( const office_element_ptr & child_element){}
virtual void serialize(std::wostream & _Wostream);
std::wostream & text_to_stream(std::wostream & _Wostream) const;
virtual void serialize(std::wostream & _Wostream);
text_text(const std::wstring & Text) : text_(Text) {}
text_text() {}
@ -316,6 +317,7 @@ public:
virtual void add_child_element( const office_element_ptr & child_element);
virtual void serialize(std::wostream & _Wostream);
std::wostream & text_to_stream(std::wostream & _Wostream) const;
text_span() {}
@ -678,7 +680,14 @@ public:
virtual void serialize(std::wostream & _Wostream);
virtual void add_text(const std::wstring & Text);
office_element_ptr_array text_;
_CP_OPT(odf_types::style_numformat) style_num_format_;
_CP_OPT(std::wstring) style_num_letter_sync_;
_CP_OPT(std::wstring) formula_;
_CP_OPT(std::wstring) name_;
_CP_OPT(std::wstring) ref_name_;
_CP_OPT(std::wstring) template_;
office_element_ptr_array text_;
};
CP_REGISTER_OFFICE_ELEMENT2(text_sequence);

View File

@ -1255,5 +1255,46 @@ void text_index_entry_text::serialize(std::wostream & _Wostream)
CP_XML_NODE_SIMPLE();
}
}
//----------------------------------------------------------------------------------------------------------
const wchar_t * text_sequence_decl::ns = L"text";
const wchar_t * text_sequence_decl::name = L"sequence-decl";
void text_sequence_decl::serialize(std::wostream & _Wostream)
{
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"text:name", name_);
CP_XML_ATTR_OPT(L"text:separation-character", separation_character_);
CP_XML_ATTR_OPT(L"text:display-outline-level", display_outline_level_);
}
}
}
//----------------------------------------------------------------------------------------------------------
const wchar_t * text_sequence_decls::ns = L"text";
const wchar_t * text_sequence_decls::name = L"sequence-decls";
void text_sequence_decls::create_child_element(const std::wstring & Ns, const std::wstring & Name)
{
CP_CREATE_ELEMENT(content_);
}
void text_sequence_decls::add_child_element( const office_element_ptr & child_element)
{
content_.push_back(child_element);
}
void text_sequence_decls::serialize(std::wostream & _Wostream)
{
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE_SIMPLE()
{
for (size_t i = 0 ; i < content_.size(); i++)
{
content_[i]->serialize(CP_XML_STREAM());
}
}
}
}
}
}

View File

@ -678,48 +678,48 @@ public:
_CP_OPT(std::wstring) content_;
};
CP_REGISTER_OFFICE_ELEMENT2(text_index_title_template);
////---------------------------------------------------------------------------------------------------
////text:sequence-decl
////---------------------------------------------------------------------------------------------------
//class text_sequence_decl : public office_element_impl<text_sequence_decl>
//{
//public:
// static const wchar_t * ns;
// static const wchar_t * name;
// static const xml::NodeType xml_type = xml::typeElement;
// static const ElementType type = typeTextSequenceDecl;
// CPDOCCORE_DEFINE_VISITABLE()
//
// virtual void create_child_element (const std::wstring & Ns, const std::wstring & Name);
// virtual void add_child_element ( const office_element_ptr & child_element);
//
// virtual void serialize(std::wostream & _Wostream);
//
// _CP_OPT(std::wstring) separation_character_; //one char
// _CP_OPT(unsigned int) display_outline_level_;
// _CP_OPT(std::wstring) name_;
//};
//CP_REGISTER_OFFICE_ELEMENT2(text_sequence_decl);
////---------------------------------------------------------------------------------------------------
////text:sequence-decls
////---------------------------------------------------------------------------------------------------
//class text_sequence_decls : public office_element_impl<text_sequence_decls>
//{
//public:
// static const wchar_t * ns;
// static const wchar_t * name;
// static const xml::NodeType xml_type = xml::typeElement;
// static const ElementType type = typeTextSequenceDecls;
// CPDOCCORE_DEFINE_VISITABLE()
//
// virtual void create_child_element (const std::wstring & Ns, const std::wstring & Name);
// virtual void add_child_element ( const office_element_ptr & child_element);
//
// virtual void serialize(std::wostream & _Wostream);
//
// office_element_ptr_array content_;
//};
//CP_REGISTER_OFFICE_ELEMENT2(text_sequence_decls);
//---------------------------------------------------------------------------------------------------
//text:sequence-decl
//---------------------------------------------------------------------------------------------------
class text_sequence_decl : public office_element_impl<text_sequence_decl>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeTextSequenceDecl;
CPDOCCORE_DEFINE_VISITABLE()
virtual void create_child_element (const std::wstring & Ns, const std::wstring & Name){}
virtual void add_child_element ( const office_element_ptr & child_element){}
virtual void serialize(std::wostream & _Wostream);
_CP_OPT(std::wstring) separation_character_; //one char
_CP_OPT(unsigned int) display_outline_level_;
_CP_OPT(std::wstring) name_;
};
CP_REGISTER_OFFICE_ELEMENT2(text_sequence_decl);
//---------------------------------------------------------------------------------------------------
//text:sequence-decls
//---------------------------------------------------------------------------------------------------
class text_sequence_decls : public office_element_impl<text_sequence_decls>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeTextSequenceDecls;
CPDOCCORE_DEFINE_VISITABLE()
virtual void create_child_element (const std::wstring & Ns, const std::wstring & Name);
virtual void add_child_element ( const office_element_ptr & child_element);
virtual void serialize(std::wostream & _Wostream);
office_element_ptr_array content_;
};
CP_REGISTER_OFFICE_ELEMENT2(text_sequence_decls);
//---------------------------------------------------------------------------------------------------
//text:table-of-content-source
//---------------------------------------------------------------------------------------------------

View File

@ -623,9 +623,9 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape)
//docx_converter->convert(oox_shape->oTextBoxShape.GetPointer());
for (std::vector<OOX::WritingElement*>::iterator it = oox_shape->oTextBoxShape->m_arrItems.begin(); it != oox_shape->oTextBoxShape->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_shape->oTextBoxShape->m_arrItems.size(); i++)
{
docx_converter->convert(*it);
docx_converter->convert(oox_shape->oTextBoxShape->m_arrItems[i]);
convert(oox_shape->oTextBoxBodyPr.GetPointer());

View File

@ -197,6 +197,7 @@ bool OoxConverter::encrypt_document (const std::wstring &password, const std::ws
encrypt_file(password, inp_file_name, out_file_name, rels->relationships_[i].encryption_, rels->relationships_[i].size_);
}
return true;
}
bool OoxConverter::encrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, std::wstring &encrypt_info, int &size)
{

View File

@ -403,18 +403,47 @@ void DocxConverter::convert(OOX::WritingElement *oox_unknown)
void DocxConverter::convert(OOX::Logic::CSdt *oox_sdt)
{
if (oox_sdt == NULL) return;
//nullable<OOX::Logic::CSdtEndPr > m_oSdtEndPr;
//nullable<OOX::Logic::CSdtPr > m_oSdtPr;
bool bField = false;
if (oox_sdt->m_oSdtPr.IsInit())
{
if (oox_sdt->m_oSdtPr->m_oAlias.IsInit())//friendly name
{
}
if (oox_sdt->m_oSdtPr->m_oDocPartObj.IsInit())
{
if (oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery.IsInit() &&
oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal.IsInit())
{
if (*oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal == L"List od Illustrations" ||
*oox_sdt->m_oSdtPr->m_oDocPartObj->m_oDocPartGallery->m_sVal == L"Table of Contents")
{
odt_context->start_field(false);
bField = true;
}
}
}
if (oox_sdt->m_oSdtPr->m_eType == OOX::Logic::sdttypeBibliography)
{
odt_context->start_field(false);
bField = true;
}
}
convert(oox_sdt->m_oSdtContent.GetPointer());
if (bField)
{
odt_context->end_field();
}
}
void DocxConverter::convert(OOX::Logic::CSdtContent *oox_sdt)
{
if (oox_sdt == NULL) return;
for (std::vector<OOX::WritingElement*>::iterator it = oox_sdt->m_arrItems.begin(); it != oox_sdt->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_sdt->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_sdt->m_arrItems[i]);
}
}
void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
@ -607,9 +636,9 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
{//rapcomnat12.docx - стр 185
bool empty_para = true;
for (std::vector<OOX::WritingElement*>::iterator it = oox_paragraph->m_arrItems.begin(); it != oox_paragraph->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_paragraph->m_arrItems.size(); ++i)
{
switch((*it)->getType())
switch(oox_paragraph->m_arrItems[i]->getType())
{
case OOX::et_w_pPr: break;
default:
@ -631,17 +660,17 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
}
//---------------------------------------------------------------------------------------------------------------------
for (std::vector<OOX::WritingElement*>::iterator it = oox_paragraph->m_arrItems.begin(); it != oox_paragraph->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_paragraph->m_arrItems.size(); ++i)
{
//те элементы которые тока для Paragraph - здесь - остальные в общей куче
switch((*it)->getType())
switch(oox_paragraph->m_arrItems[i]->getType())
{
case OOX::et_w_pPr:
{
// пропускаем ..
}break;
default:
convert(*it);
convert(oox_paragraph->m_arrItems[i]);
break;
}
}
@ -691,24 +720,24 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
odt_context->start_run(styled);
for (std::vector<OOX::WritingElement*>::iterator it = oox_run->m_arrItems.begin(); it != oox_run->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_run->m_arrItems.size(); ++i)
{
//те элементы которые тока для Run - здесь - остальные в общей куче
switch((*it)->getType())
switch(oox_run->m_arrItems[i]->getType())
{
case OOX::et_w_fldChar:
{
OOX::Logic::CFldChar* pFldChar= dynamic_cast<OOX::Logic::CFldChar*>(*it);
OOX::Logic::CFldChar* pFldChar= dynamic_cast<OOX::Logic::CFldChar*>(oox_run->m_arrItems[i]);
convert(pFldChar);
}break;
case OOX::et_w_instrText:
{
OOX::Logic::CInstrText* pInstrText= dynamic_cast<OOX::Logic::CInstrText*>(*it);
OOX::Logic::CInstrText* pInstrText= dynamic_cast<OOX::Logic::CInstrText*>(oox_run->m_arrItems[i]);
convert(pInstrText);
}break;
case OOX::et_w_delText:
{
OOX::Logic::CDelText* pDelText= dynamic_cast<OOX::Logic::CDelText*>(*it);
OOX::Logic::CDelText* pDelText= dynamic_cast<OOX::Logic::CDelText*>(oox_run->m_arrItems[i]);
convert(pDelText);
}break;
case OOX::et_w_rPr: // пропускаем ..
@ -719,7 +748,7 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
}break;
case OOX::et_w_br:
{
OOX::Logic::CBr* pBr= dynamic_cast<OOX::Logic::CBr*>(*it);
OOX::Logic::CBr* pBr= dynamic_cast<OOX::Logic::CBr*>(oox_run->m_arrItems[i]);
if (pBr)
{
int type = pBr->m_oType.GetValue();
@ -732,17 +761,17 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
}break;
case OOX::et_w_t:
{
OOX::Logic::CText* pText= dynamic_cast<OOX::Logic::CText*>(*it);
OOX::Logic::CText* pText= dynamic_cast<OOX::Logic::CText*>(oox_run->m_arrItems[i]);
convert(pText);
}break;
case OOX::et_w_sym:
{
OOX::Logic::CSym* pSym= dynamic_cast<OOX::Logic::CSym*>(*it);
OOX::Logic::CSym* pSym= dynamic_cast<OOX::Logic::CSym*>(oox_run->m_arrItems[i]);
convert(pSym);
}break;
case OOX::et_w_tab:
{
OOX::Logic::CTab* pTab= dynamic_cast<OOX::Logic::CTab*>(*it);
OOX::Logic::CTab* pTab= dynamic_cast<OOX::Logic::CTab*>(oox_run->m_arrItems[i]);
odt_context->text_context()->add_tab();
}break;
@ -759,7 +788,7 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
//softHyphen
//delInstrText
default:
convert(*it);
convert(oox_run->m_arrItems[i]);
}
}
odt_context->end_run();
@ -898,9 +927,9 @@ void DocxConverter::convert(OOX::Logic::CIns *oox_ins)
bool start_change = odt_context->start_change(id, 1, author, userId, date);
for (std::vector<OOX::WritingElement*>::iterator it = oox_ins->m_arrItems.begin(); it != oox_ins->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_ins->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_ins->m_arrItems[i]);
}
if (start_change)
@ -1103,9 +1132,9 @@ void DocxConverter::convert(OOX::Logic::CDel *oox_del)
bool res_change = odt_context->start_change(id, 2, author, userId, date);
for (std::vector<OOX::WritingElement*>::iterator it = oox_del->m_arrItems.begin(); it != oox_del->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_del->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_del->m_arrItems[i]);
}
if (res_change)
odt_context->end_change(id, 2);
@ -1114,9 +1143,9 @@ void DocxConverter::convert(OOX::Logic::CSmartTag *oox_tag)
{
if (oox_tag == NULL) return;
for (std::vector<OOX::WritingElement*>::iterator it = oox_tag->m_arrItems.begin(); it != oox_tag->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_tag->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_tag->m_arrItems[i]);
}
}
void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cpdoccore::odf_writer::style_paragraph_properties * paragraph_properties)
@ -3036,27 +3065,34 @@ void DocxConverter::convert_styles()
void DocxConverter::convert(OOX::Logic::CHyperlink *oox_hyperlink)
{
if (oox_hyperlink == NULL)return;
std::wstring ref;
if (oox_hyperlink->m_oId.IsInit()) //гиперлинк
{
std::wstring ref = find_link_by_id(oox_hyperlink->m_oId->GetValue(),2);
ref = find_link_by_id(oox_hyperlink->m_oId->GetValue(),2);
}
else if (oox_hyperlink->m_sAnchor.IsInit())
{
ref = L"#" + *oox_hyperlink->m_sAnchor;
}
if (false == ref.empty())
{
odt_context->start_hyperlink(ref);
for (std::vector<OOX::WritingElement*>::iterator it = oox_hyperlink->m_arrItems.begin(); it != oox_hyperlink->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_hyperlink->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_hyperlink->m_arrItems[i]);
}
odt_context->end_hyperlink();
}
else
{//ссылка внутри дока
//anchor todooo
for (std::vector<OOX::WritingElement*>::iterator it = oox_hyperlink->m_arrItems.begin(); it != oox_hyperlink->m_arrItems.end(); ++it)
{
for (size_t i = 0; i < oox_hyperlink->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_hyperlink->m_arrItems[i]);
}
}
//nullable<std::wstring > m_sAnchor;
//nullable<std::wstring > m_sDocLocation;
//nullable<SimpleTypes::COnOff<SimpleTypes::onoffFalse> > m_oHistory;
//nullable<std::wstring > m_sTgtFrame;
@ -3606,9 +3642,9 @@ void DocxConverter::convert_comment(int oox_comm_id)
if (oox_comment->m_oDate.IsInit()) odt_context->comment_context()->set_date (oox_comment->m_oDate->GetValue());
if (oox_comment->m_oInitials.IsInit()) {}
for (std::vector<OOX::WritingElement*>::iterator it = oox_comment->m_arrItems.begin(); it != oox_comment->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_comment->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_comment->m_arrItems[i]);
}
}
odt_context->end_comment_content();
@ -3631,9 +3667,9 @@ void DocxConverter::convert_footnote(int oox_ref_id)
{
odt_context->start_note_content();
{
for (std::vector<OOX::WritingElement*>::iterator it = oox_note->m_arrItems.begin(); it != oox_note->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_note->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_note->m_arrItems[i]);
}
}
odt_context->end_note_content();
@ -3658,9 +3694,9 @@ void DocxConverter::convert_endnote(int oox_ref_id)
{
odt_context->start_note_content();
{
for (std::vector<OOX::WritingElement*>::iterator it = oox_note->m_arrItems.begin(); it != oox_note->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_note->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_note->m_arrItems[i]);
}
}
odt_context->end_note_content();
@ -3675,9 +3711,9 @@ void DocxConverter::convert_hdr_ftr (std::wstring sId)
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(oox_hdr_ftr);
for (std::vector<OOX::WritingElement*>::iterator it = oox_hdr_ftr->m_arrItems.begin(); it != oox_hdr_ftr->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_hdr_ftr->m_arrItems.size(); ++i)
{
convert(*it);
convert(oox_hdr_ftr->m_arrItems[i]);
}
oox_current_child_document = NULL;
}
@ -3854,16 +3890,16 @@ void DocxConverter::convert(OOX::Logic::CTbl *oox_table)
convert(oox_table->m_oTblGrid.GetPointer());
//------ строки
for (std::vector<OOX::WritingElement*>::iterator it = oox_table->m_arrItems.begin(); it != oox_table->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_table->m_arrItems.size(); ++i)
{
switch((*it)->getType())
switch(oox_table->m_arrItems[i]->getType())
{
case OOX::et_w_tblPr:
{
//skip
}break;
default:
convert(*it);
convert(oox_table->m_arrItems[i]);
}
}
if (in_frame)
@ -3970,16 +4006,16 @@ void DocxConverter::convert(OOX::Logic::CTr *oox_table_row)
convert(oox_table_row->m_pTableRowProperties);
for (std::vector<OOX::WritingElement*>::iterator it = oox_table_row->m_arrItems.begin(); it != oox_table_row->m_arrItems.end(); ++it)
for (size_t i =0; i < oox_table_row->m_arrItems.size(); ++i)
{
switch((*it)->getType())
switch(oox_table_row->m_arrItems[i]->getType())
{
case OOX::et_w_trPr:
{
//skip
}break;
default:
convert(*it);
convert(oox_table_row->m_arrItems[i]);
}
}
odt_context->end_table_row();
@ -4030,16 +4066,16 @@ void DocxConverter::convert(OOX::Logic::CTc *oox_table_cell)
odt_context->table_context()->set_cell_column_span(oox_table_cell->m_pTableCellProperties->m_oGridSpan->m_oVal->GetValue());
}
for (std::vector<OOX::WritingElement*>::iterator it = oox_table_cell->m_arrItems.begin(); it != oox_table_cell->m_arrItems.end(); ++it)
for (size_t i = 0; i < oox_table_cell->m_arrItems.size(); ++i)
{
switch((*it)->getType())
switch(oox_table_cell->m_arrItems[i]->getType())
{
case OOX::et_w_tcPr:
{
//skip
}break;
default:
convert(*it);
convert(oox_table_cell->m_arrItems[i]);
}
}
odt_context->end_table_cell();

View File

@ -1,6 +1,6 @@
#!/bin/bash
SCRIPT=$(readlink -n "$0" || grealpath "$0")
SCRIPT=$(readlink -f "$0" || grealpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
os=$(uname -s)

View File

@ -59,6 +59,13 @@ else
svn export http://source.icu-project.org/repos/icu/tags/release-$ICU_MAJOR_VER-$ICU_MINOR_VER/icu4c ./icu
fi
# Workaround for building icu older than 60.0 on Archlinux
# See https://bugs.archlinux.org/task/55246
if [ -f "/etc/arch-release" ]; then
echo "Arch Linux detected. Applying 'xlocale.h' error patch"
sed -i 's/xlocale/locale/' ./icu/source/i18n/digitlst.cpp
fi
cd ./icu/source/
if [ ! -f "./Makefile" ]

View File

@ -1,4 +1,5 @@
#!/bin/bash
set -e
SCRIPT=$(readlink -f "$0" || grealpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

View File

@ -218,6 +218,8 @@
69E6AC8D2031ACA900795D9D /* VbaProject.h in Headers */ = {isa = PBXBuildFile; fileRef = 69E6AC8B2031ACA900795D9D /* VbaProject.h */; };
69E6AC8F2031B72500795D9D /* Worksheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69E6AC8E2031B72500795D9D /* Worksheet.cpp */; };
69F181EC1C7734A700B2952B /* strings_hack_printf.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F181EA1C7734A700B2952B /* strings_hack_printf.h */; };
8A218DBF20FCC770006589C2 /* StreamWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A218DBD20FCC76F006589C2 /* StreamWriter.h */; };
8A218DC020FCC770006589C2 /* StreamWriter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A218DBE20FCC770006589C2 /* StreamWriter.cpp */; };
8A404FCA2089FF7E00F2D5CF /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FC92089FF7E00F2D5CF /* Base64.cpp */; };
8A404FCC2089FFE700F2D5CF /* Directory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FCB2089FFE700F2D5CF /* Directory.cpp */; };
8A404FCE208A001E00F2D5CF /* Path.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A404FCD208A001D00F2D5CF /* Path.cpp */; };
@ -443,6 +445,8 @@
69E6AC8B2031ACA900795D9D /* VbaProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VbaProject.h; sourceTree = "<group>"; };
69E6AC8E2031B72500795D9D /* Worksheet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Worksheet.cpp; sourceTree = "<group>"; };
69F181EA1C7734A700B2952B /* strings_hack_printf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = strings_hack_printf.h; path = ../../Common/DocxFormat/Source/Base/strings_hack_printf.h; sourceTree = "<group>"; };
8A218DBD20FCC76F006589C2 /* StreamWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamWriter.h; sourceTree = "<group>"; };
8A218DBE20FCC770006589C2 /* StreamWriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamWriter.cpp; sourceTree = "<group>"; };
8A404FC92089FF7E00F2D5CF /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Base64.cpp; path = ../../../../DesktopEditor/common/Base64.cpp; sourceTree = "<group>"; };
8A404FCB2089FFE700F2D5CF /* Directory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Directory.cpp; path = ../../../../DesktopEditor/common/Directory.cpp; sourceTree = "<group>"; };
8A404FCD208A001D00F2D5CF /* Path.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Path.cpp; path = ../../../../DesktopEditor/common/Path.cpp; sourceTree = "<group>"; };
@ -925,6 +929,8 @@
17E6B3C01AC4298500F28F8B /* Path.h */,
17E6B3C11AC4298500F28F8B /* Types.h */,
69F181EA1C7734A700B2952B /* strings_hack_printf.h */,
8A218DBE20FCC770006589C2 /* StreamWriter.cpp */,
8A218DBD20FCC76F006589C2 /* StreamWriter.h */,
);
name = common;
path = ../../../../DesktopEditor/common;
@ -970,6 +976,7 @@
17C1FBEE1ACC4250006B99B3 /* MergeCells.h in Headers */,
17C1FBEF1ACC4250006B99B3 /* Docx.h in Headers */,
17C1FBF11ACC4250006B99B3 /* SimpleTypes_OMath.h in Headers */,
8A218DBF20FCC770006589C2 /* StreamWriter.h in Headers */,
17C1FBF21ACC4250006B99B3 /* StringOutput.h in Headers */,
17C1FBF41ACC4250006B99B3 /* Image.h in Headers */,
17C1FBF51ACC4250006B99B3 /* Dir.h in Headers */,
@ -1198,6 +1205,7 @@
17C1FBBA1ACC4250006B99B3 /* SimpleTypes_Word.cpp in Sources */,
17C1FBBB1ACC4250006B99B3 /* MathEquation.cpp in Sources */,
17C1FBBC1ACC4250006B99B3 /* Wrap.cpp in Sources */,
8A218DC020FCC770006589C2 /* StreamWriter.cpp in Sources */,
17C1FBBD1ACC4250006B99B3 /* Common.cpp in Sources */,
1732414A1BBEC90000E67992 /* pole.cpp in Sources */,
17C1FBBE1ACC4250006B99B3 /* IFileContainer.cpp in Sources */,

View File

@ -91,6 +91,12 @@ namespace OOX
bool FileInDirectoryCorrect();
AVSINLINE std::wstring GetBasename() const
{
std::wstring sFilename = GetFilename();
std::wstring sExt = GetExtention();
return sFilename.substr(0, sFilename.length() - sExt.length());
}
AVSINLINE std::wstring GetExtention(bool bIsPoint = true) const
{
int nFind = (int)m_strFilename.rfind('.');

View File

@ -229,6 +229,22 @@ namespace OOX
pWorkbookView->m_oWindowHeight->SetValue(9720);
}
}
LONG GetActiveSheetIndex()
{
LONG lActiveSheet = 0;
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
// Get active sheet
if ( m_oBookViews.IsInit() && !m_oBookViews->m_arrItems.empty())
{
if (m_oBookViews->m_arrItems.front()->m_oActiveTab.IsInit())
{
lActiveSheet = m_oBookViews->m_arrItems.front()->m_oActiveTab->GetValue();
if (0 > lActiveSheet)
lActiveSheet = 0;
}
}
return lActiveSheet;
}
private:
CPath m_oReadPath;

View File

@ -376,6 +376,20 @@ namespace OOX
return _T("");
}
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
{
toXMLStart(writer);
for ( size_t i = 0; i < m_arrItems.size(); ++i)
{
if ( m_arrItems[i] )
{
m_arrItems[i]->toXML(writer);
}
}
toXMLEnd(writer);
}
virtual void toXMLStart(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("<row"));
WritingStringNullableAttrBool(L"collapsed", m_oCollapsed);
@ -390,15 +404,9 @@ namespace OOX
WritingStringNullableAttrBool(L"thickBot", m_oThickBot);
WritingStringNullableAttrBool(L"thickTop", m_oThickTop);
writer.WriteString(_T(">"));
for ( size_t i = 0; i < m_arrItems.size(); ++i)
{
if ( m_arrItems[i] )
{
m_arrItems[i]->toXML(writer);
}
}
}
virtual void toXMLEnd(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("</row>"));
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)
@ -489,8 +497,7 @@ namespace OOX
}
virtual void toXML(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("<sheetData>"));
toXMLStart(writer);
for ( size_t i = 0; i < m_arrItems.size(); ++i)
{
if ( m_arrItems[i] )
@ -498,7 +505,14 @@ namespace OOX
m_arrItems[i]->toXML(writer);
}
}
toXMLEnd(writer);
}
virtual void toXMLStart(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("<sheetData>"));
}
virtual void toXMLEnd(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("</sheetData>"));
}
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader)

View File

@ -345,54 +345,71 @@ namespace OOX
}
void CWorksheet::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const
{
NSStringUtils::CStringBuilder sXml;
sXml.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"));
if(m_oSheetPr.IsInit())
m_oSheetPr->toXML(sXml);
if(m_oSheetViews.IsInit())
m_oSheetViews->toXML(sXml);
if(m_oSheetFormatPr.IsInit())
m_oSheetFormatPr->toXML(sXml);
if(m_oCols.IsInit())
m_oCols->toXML(sXml);
if(m_oSheetData.IsInit())
m_oSheetData->toXML(sXml);
if(m_oAutofilter.IsInit())
m_oAutofilter->toXML(sXml);
if(m_oMergeCells.IsInit())
m_oMergeCells->toXML(sXml);
for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex)
m_arrConditionalFormatting[nIndex]->toXML(sXml);
if(m_oHyperlinks.IsInit())
m_oHyperlinks->toXML(sXml);
if(m_oPrintOptions.IsInit())
m_oPrintOptions->toXML(sXml);
if(m_oPageMargins.IsInit())
m_oPageMargins->toXML(sXml);
if(m_oPageSetup.IsInit())
m_oPageSetup->toXML(sXml);
if(m_oDrawing.IsInit())
m_oDrawing->toXML(sXml);
if(m_oLegacyDrawing.IsInit())
m_oLegacyDrawing->toXML(sXml);
if(m_oLegacyDrawingHF.IsInit())
m_oLegacyDrawingHF->toXML(sXml);
if(m_oOleObjects.IsInit())
m_oOleObjects->toXML(sXml);
if (m_oControls.IsInit())
m_oControls->toXML(sXml);
if(m_oTableParts.IsInit())
m_oTableParts->toXML(sXml);
if(m_oExtLst.IsInit())
if (m_sOutputFilename.empty())
{
sXml.WriteString(m_oExtLst->toXMLWithNS(_T("")));
NSStringUtils::CStringBuilder sXml;
toXMLStart(sXml);
if(m_oSheetPr.IsInit())
m_oSheetPr->toXML(sXml);
if(m_oSheetViews.IsInit())
m_oSheetViews->toXML(sXml);
if(m_oSheetFormatPr.IsInit())
m_oSheetFormatPr->toXML(sXml);
if(m_oCols.IsInit())
m_oCols->toXML(sXml);
if(m_oSheetData.IsInit())
m_oSheetData->toXML(sXml);
if(m_oAutofilter.IsInit())
m_oAutofilter->toXML(sXml);
if(m_oMergeCells.IsInit())
m_oMergeCells->toXML(sXml);
for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex)
m_arrConditionalFormatting[nIndex]->toXML(sXml);
if(m_oHyperlinks.IsInit())
m_oHyperlinks->toXML(sXml);
if(m_oPrintOptions.IsInit())
m_oPrintOptions->toXML(sXml);
if(m_oPageMargins.IsInit())
m_oPageMargins->toXML(sXml);
if(m_oPageSetup.IsInit())
m_oPageSetup->toXML(sXml);
if(m_oDrawing.IsInit())
m_oDrawing->toXML(sXml);
if(m_oLegacyDrawing.IsInit())
m_oLegacyDrawing->toXML(sXml);
if(m_oLegacyDrawingHF.IsInit())
m_oLegacyDrawingHF->toXML(sXml);
if(m_oOleObjects.IsInit())
m_oOleObjects->toXML(sXml);
if (m_oControls.IsInit())
m_oControls->toXML(sXml);
if(m_oTableParts.IsInit())
m_oTableParts->toXML(sXml);
if(m_oExtLst.IsInit())
{
sXml.WriteString(m_oExtLst->toXMLWithNS(_T("")));
}
toXMLEnd(sXml);
NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData());
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
IFileContainer::Write( oPath, oDirectory, oContent );
}
sXml.WriteString(_T("</worksheet>"));
NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData());
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
IFileContainer::Write( oPath, oDirectory, oContent );
else
{
CPath oRealPath(oPath.GetDirectory() + FILE_SEPARATOR_STR + m_sOutputFilename);
oContent.Registration( type().OverrideType(), oDirectory, oRealPath.GetFilename() );
IFileContainer::Write( oRealPath, oDirectory, oContent );
}
}
void CWorksheet::toXMLStart(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"));
}
void CWorksheet::toXMLEnd(NSStringUtils::CStringBuilder& writer) const
{
writer.WriteString(_T("</worksheet>"));
}
const OOX::RId CWorksheet::AddHyperlink (std::wstring& sHref)
@ -427,4 +444,4 @@ namespace OOX
m_arrConditionalFormatting.clear();
}
}
}
}

View File

@ -90,6 +90,8 @@ namespace OOX
void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing);
void PrepareToWrite();
virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const;
void toXMLStart(NSStringUtils::CStringBuilder& writer) const;
void toXMLEnd(NSStringUtils::CStringBuilder& writer) const;
virtual const OOX::FileType type() const
{
return OOX::Spreadsheet::FileTypes::Worksheet;

View File

@ -266,10 +266,10 @@ std::wstring COfficeFileFormatChecker::getDocumentID (const std::wstring & _file
{
NSFile::CFileBinary file;
if (!file.OpenFile(fileName))
return false;
return documentID;
unsigned char* buffer = new unsigned char[4096]; //enaf !!
if (!buffer){file.CloseFile();return false;}
if (!buffer){file.CloseFile();return documentID;}
DWORD dwReadBytes = 0;
file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes);
@ -649,6 +649,8 @@ bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring & fileN
delete []pBuffer;
pBuffer = NULL;
}
nBufferSize = 0;
hresult = OfficeUtils.LoadFileFromArchive(fileName, L"mimetype", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
@ -689,7 +691,8 @@ bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring & fileN
else
{
//если не записан тип смотрим манифест
HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"META-INF/manifest.xml", &pBuffer, nBufferSize);
nBufferSize = 0;
HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"META-INF/manifest.xml", &pBuffer, nBufferSize);
if (hresult == S_OK && pBuffer != NULL)
{
std::string xml_string((char*)pBuffer, nBufferSize);

View File

@ -97,6 +97,9 @@ SOURCES += ./../DesktopEditor/common/Base64.cpp
HEADERS += ./../DesktopEditor/common/File.h
SOURCES += ./../DesktopEditor/common/File.cpp
HEADERS += ./../DesktopEditor/common/StreamWriter.h
SOURCES += ./../DesktopEditor/common/StreamWriter.cpp
# DIRECTORY
HEADERS += ./../DesktopEditor/common/Directory.h
SOURCES += ./../DesktopEditor/common/Directory.cpp

View File

@ -1,4 +1,4 @@
/*
/*
* (c) Copyright Ascensio System SIA 2010-2018
*
* This program is a free software product. You can redistribute it and/or
@ -981,6 +981,88 @@ namespace NSEditorApi
LINK_PROPERTY_INT_JS(InsertPageNum)
};
class CAscSlideTiming : public IMenuEventDataBase
{
private:
js_wrapper<int> m_nTransitionType;
js_wrapper<int> m_nTransitionOption;
js_wrapper<int> m_nTransitionDuration;
js_wrapper<bool> m_bSlideAdvanceOnMouseClick;
js_wrapper<bool> m_bSlideAdvanceAfter;
js_wrapper<bool> m_bSlideAdvanceDuration;
js_wrapper<bool> m_bShowLoop;
public:
CAscSlideTiming()
{
}
virtual ~CAscSlideTiming()
{
}
LINK_PROPERTY_INT_JS(TransitionType)
LINK_PROPERTY_INT_JS(TransitionOption)
LINK_PROPERTY_INT_JS(TransitionDuration)
LINK_PROPERTY_BOOL_JS(SlideAdvanceOnMouseClick)
LINK_PROPERTY_BOOL_JS(SlideAdvanceAfter)
LINK_PROPERTY_BOOL_JS(SlideAdvanceDuration)
LINK_PROPERTY_BOOL_JS(ShowLoop)
};
class CAscTransitions : public IMenuEventDataBase
{
public:
std::vector<CAscSlideTiming> m_arTransitions;
public:
CAscTransitions()
{}
virtual ~CAscTransitions()
{
}
};
class CAscSlideProp : public IMenuEventDataBase
{
js_wrapper<CAscFill> m_oBackground;
js_wrapper<CAscSlideTiming> m_oTiming;
js_wrapper<int> m_nLayoutIndex;
js_wrapper<bool> m_bIsHidden;
js_wrapper<bool> m_bLockBackground;
js_wrapper<bool> m_bLockDelete;
js_wrapper<bool> m_bLockLayout;
js_wrapper<bool> m_bLockRemove;
js_wrapper<bool> m_bLockTiming;
js_wrapper<bool> m_bLockTransition;
public:
CAscSlideProp()
{
}
virtual ~CAscSlideProp()
{
}
LINK_PROPERTY_OBJECT_JS(CAscFill, Background)
LINK_PROPERTY_OBJECT_JS(CAscSlideTiming, Timing)
LINK_PROPERTY_INT_JS(LayoutIndex)
LINK_PROPERTY_BOOL_JS(IsHidden)
LINK_PROPERTY_BOOL_JS(LockBackground)
LINK_PROPERTY_BOOL_JS(LockDelete)
LINK_PROPERTY_BOOL_JS(LockLayout)
LINK_PROPERTY_BOOL_JS(LockRemove)
LINK_PROPERTY_BOOL_JS(LockTiming)
LINK_PROPERTY_BOOL_JS(LockTransition)
};
class CAscImagePosition
{

View File

@ -689,6 +689,7 @@
#define ASC_MENU_EVENT_TYPE_TABLESPLITCELLS 16
#define ASC_MENU_EVENT_TYPE_SECTION 17
#define ASC_MENU_EVENT_TYPE_SHAPE 18
#define ASC_MENU_EVENT_TYPE_SLIDE 20
// insert commands
#define ASC_MENU_EVENT_TYPE_INSERT_IMAGE 50

View File

@ -130,9 +130,9 @@ namespace NSFile
public:
CFileBinary();
~CFileBinary();
virtual ~CFileBinary();
void CloseFile();
virtual void CloseFile();
FILE* GetFileNative();
long GetFileSize();

View File

@ -0,0 +1,70 @@
/*
* (c) Copyright Ascensio System SIA 2010-2018
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "StreamWriter.h"
namespace NSFile
{
CStreamWriter::CStreamWriter(size_t bufferSize)
{
m_lSize = bufferSize;
m_pData = (wchar_t*)malloc(bufferSize * sizeof(wchar_t));
m_lSizeCur = 0;
m_pDataCur = m_pData;
}
void CStreamWriter::AddSize(size_t nSize)
{
if ((m_lSizeCur + nSize) > m_lSize)
{
Flush();
if ((m_lSizeCur + nSize) > m_lSize)
{
NSStringUtils::CStringBuilder::AddSize(nSize);
}
}
}
void CStreamWriter::CloseFile()
{
Flush();
CFileBinary::CloseFile();
}
void CStreamWriter::Flush()
{
if (m_lSizeCur > 0)
{
CFileBinary::WriteStringUTF8(NSStringUtils::CStringBuilder::GetData());
}
m_lSizeCur = 0;
m_pDataCur = m_pData;
}
}

View File

@ -0,0 +1,51 @@
/*
* (c) Copyright Ascensio System SIA 2010-2018
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef _BUILD_STREAM_WRITER_CROSSPLATFORM_H_
#define _BUILD_STREAM_WRITER_CROSSPLATFORM_H_
#include "File.h"
#include "StringBuilder.h"
namespace NSFile
{
class KERNEL_DECL CStreamWriter : public CFileBinary, public NSStringUtils::CStringBuilder
{
public:
CStreamWriter(size_t bufferSize = 16777216);
void AddSize(size_t nSize);
void CloseFile();
void Flush();
};
}
#endif // _BUILD_STREAM_WRITER_CROSSPLATFORM_H_

View File

@ -78,7 +78,7 @@ namespace NSStringUtils
class KERNEL_DECL CStringBuilder
{
private:
protected:
wchar_t* m_pData;
size_t m_lSize;
@ -87,9 +87,9 @@ namespace NSStringUtils
public:
CStringBuilder();
~CStringBuilder();
virtual ~CStringBuilder();
void AddSize(size_t nSize);
virtual void AddSize(size_t nSize);
public:

View File

@ -1406,7 +1406,7 @@ void CFontList::Add(NSFonts::CFontInfo* pInfo)
}
// ApplicationFonts
CApplicationFonts::CApplicationFonts()
CApplicationFonts::CApplicationFonts() : NSFonts::IApplicationFonts()
{
m_oCache.m_pApplicationFontStreams = &m_oStreams;
}

View File

@ -40,26 +40,12 @@ CFontStream::CFontStream() : NSFonts::IFontStream()
{
m_pData = NULL;
m_lSize = 0;
m_lRef = 1;
m_bIsAttach = false;
}
CFontStream::~CFontStream()
{
if (!m_bIsAttach)
RELEASEARRAYOBJECTS(m_pData);
}
int CFontStream::AddRef()
{
++m_lRef;
return m_lRef;
}
int CFontStream::Release()
{
int ret = --m_lRef;
if (0 == m_lRef)
delete this;
return ret;
RELEASEARRAYOBJECTS(m_pData);
}
int CFontStream::CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse)
@ -234,7 +220,7 @@ NSFonts::IFontFile* CFontsCache::LockFont(NSFonts::CLibrary& library, const std:
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
CFontManager::CFontManager()
CFontManager::CFontManager() : NSFonts::IFontManager()
{
m_pLibrary = NULL;
FT_Init_FreeType(&m_pLibrary);
@ -246,7 +232,6 @@ CFontManager::CFontManager()
m_bStringGID = FALSE;
m_nLOAD_MODE = 40968;
m_lRef = 1;
m_nRENDER_MODE = FT_RENDER_MODE_NORMAL;
@ -631,18 +616,6 @@ INT CFontManager::GetStringPath(NSFonts::ISimpleGraphicsPath* pInterface)
return TRUE;
}
int CFontManager::AddRef()
{
++m_lRef;
return m_lRef;
}
int CFontManager::Release()
{
int ret = --m_lRef;
if (0 == m_lRef)
delete this;
return ret;
}
NSFonts::CFontInfo* CFontManager::GetFontInfoByParams(NSFonts::CFontSelectFormat& oFormat, bool bIsDictionaryUse)
{
NSFonts::CFontInfo* pRes = NULL;
@ -773,32 +746,32 @@ void CFontManager::SetSubpixelRendering(const bool& hmul, const bool& vmul)
m_nRENDER_MODE = FT_RENDER_MODE_LCD_V;
else
m_nRENDER_MODE = FT_RENDER_MODE_NORMAL;
}
void CFontManager::GetFace(double& d0, double& d1, double& d2)
{
d0 = 2048;
d1 = 0;
d2 = 0;
if (m_pFont)
{
TT_OS2* os2 = NULL;
TT_Header* header = NULL;
if (m_pFont->m_pFace)
{
if ((header = (TT_Header*)FT_Get_Sfnt_Table(m_pFont->m_pFace, ft_sfnt_head)) != NULL)
{
d1 = header->yMax;
d2 = header->yMin;
d0 = header->Units_Per_EM;
}
if ((os2 = (TT_OS2*)FT_Get_Sfnt_Table(m_pFont->m_pFace, ft_sfnt_os2)) != NULL && os2->version != 0xFFFFU)
{
d1 = os2->usWinAscent;
d2 = -os2->usWinDescent;
}
}
}
}
void CFontManager::GetFace(double& d0, double& d1, double& d2)
{
d0 = 2048;
d1 = 0;
d2 = 0;
if (m_pFont)
{
TT_OS2* os2 = NULL;
TT_Header* header = NULL;
if (m_pFont->m_pFace)
{
if ((header = (TT_Header*)FT_Get_Sfnt_Table(m_pFont->m_pFace, ft_sfnt_head)) != NULL)
{
d1 = header->yMax;
d2 = header->yMin;
d0 = header->Units_Per_EM;
}
if ((os2 = (TT_OS2*)FT_Get_Sfnt_Table(m_pFont->m_pFace, ft_sfnt_os2)) != NULL && os2->version != 0xFFFFU)
{
d1 = os2->usWinAscent;
d2 = -os2->usWinDescent;
}
}
}
}

View File

@ -38,9 +38,6 @@
class CFontStream : public NSFonts::IFontStream
{
private:
int m_lRef;
public:
BYTE* m_pData;
LONG m_lSize;
@ -50,10 +47,6 @@ public:
CFontStream();
virtual ~CFontStream();
virtual int AddRef();
virtual int Release();
public:
virtual int CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse = NULL);
};
@ -125,8 +118,7 @@ class CApplicationFonts;
class CFontManager : public NSFonts::IFontManager
{
friend class CApplicationFonts;
private:
int m_lRef;
public:
FT_Library m_pLibrary;
@ -203,10 +195,6 @@ public:
virtual INT GetStringPath(NSFonts::ISimpleGraphicsPath* pPath);
// addref/release
virtual int AddRef();
virtual int Release();
virtual NSFonts::CFontInfo* GetFontInfoByParams(NSFonts::CFontSelectFormat& oFormat, bool bIsDictionaryUse = true);
virtual std::vector<NSFonts::CFontInfo*> GetAllStylesByFontName(const std::wstring& strName);
virtual INT LoadFontByName(const std::wstring& sName, const double& dSize, const int& lStyle, const double& dDpiX, const double& dDpiY);
@ -217,8 +205,8 @@ public:
virtual std::wstring GetFontType();
virtual unsigned int GetNameIndex(const std::wstring& wsName);
virtual void SetSubpixelRendering(const bool& hmul, const bool& vmul);
virtual void SetSubpixelRendering(const bool& hmul, const bool& vmul);
virtual void GetFace(double& d0, double& d1, double& d2);
};

View File

@ -492,7 +492,7 @@ namespace NSCommon
pImageData[i] = 0;
}
NSGraphics::IGraphicsRenderer pRenderer = NSGraphics::Create();
NSGraphics::IGraphicsRenderer* pRenderer = NSGraphics::Create();
pRenderer->CreateFromBgraFrame(&oFrame);
pRenderer->SetFontManager(pManager);

View File

@ -180,6 +180,11 @@ namespace NSThreads
Join();
RELEASEOBJECT(m_hThread);
}
void CBaseThread::StopNoJoin()
{
m_bRunThread = FALSE;
RELEASEOBJECT(m_hThread);
}
INT CBaseThread::IsSuspended() { return m_bSuspend; }
INT CBaseThread::IsRunned() { return m_bRunThread; }

View File

@ -73,6 +73,7 @@ namespace NSThreads
virtual void Suspend();
virtual void Resume();
virtual void Stop();
virtual void StopNoJoin();
INT IsSuspended();
INT IsRunned();

View File

@ -120,7 +120,7 @@ public:
void SaveBrush(NSStructures::CBrush& oBrush) { oBrush = m_oBrush; }
void RestoreBrush(const NSStructures::CBrush& oBrush) { m_oBrush = oBrush; }
virtual void SetSwapRGB(bool bValue){ if (m_pRenderer) m_pRenderer->m_bSwapRGB = bValue; }
void SetTileImageDpi(const double& dDpi) { if (m_pRenderer) m_pRenderer->m_dDpiTile = dDpi; }
virtual void SetTileImageDpi(const double& dDpi) { if (m_pRenderer) m_pRenderer->m_dDpiTile = dDpi; }
void Save();
void Restore();

View File

@ -49,15 +49,13 @@ class CCacheImage : public NSImages::ICacheImage
{
private:
Aggplus::CImage m_oImage;
LONG m_lRef;
public:
CCacheImage(CApplicationFonts* pFonts) : m_oImage()
CCacheImage(CApplicationFonts* pFonts) : NSImages::ICacheImage(), m_oImage()
{
m_lRef = 1;
}
CCacheImage(CApplicationFonts* pFonts, const std::wstring& strFile)
CCacheImage(CApplicationFonts* pFonts, const std::wstring& strFile) : NSImages::ICacheImage()
{
if (NULL == pFonts)
{
@ -80,32 +78,12 @@ public:
NSFile::CFileBinary::Remove(sTempFile);
}
}
m_lRef = 1;
}
virtual ~CCacheImage()
{
}
virtual LONG AddRef()
{
++m_lRef;
return m_lRef;
}
virtual LONG Release()
{
--m_lRef;
if (0 == m_lRef)
{
delete this;
return 0;
}
return m_lRef;
}
Aggplus::CImage* GetImage()
{
return &m_oImage;
@ -118,18 +96,15 @@ private:
std::map<std::wstring, CCacheImage*> m_mapImages;
LONG m_lMaxCount;
LONG m_lRef;
CApplicationFonts* m_pApplicationFonts;
NSCriticalSection::CRITICAL_SECTION m_oCS;
public:
CImageFilesCache(CApplicationFonts* pFonts = NULL)
CImageFilesCache(CApplicationFonts* pFonts = NULL) : NSImages::IImageFilesCache()
{
m_pApplicationFonts = pFonts;
m_lMaxCount = 10;
m_lRef = 1;
m_oCS.InitializeCriticalSection();
}
@ -188,12 +163,7 @@ public:
return pImage;
}
virtual LONG AddRef()
{
++m_lRef;
return m_lRef;
}
virtual LONG Release()
virtual int Release()
{
m_oCS.Enter();
--m_lRef;

View File

@ -63,6 +63,24 @@ struct TBBoxAdvance
float fAdvanceY;
};
namespace NSBase
{
class GRAPHICS_DECL CBaseRefCounter
{
protected:
volatile int m_lRef;
public:
CBaseRefCounter();
virtual ~CBaseRefCounter();
virtual int AddRef();
virtual int Release();
};
void GRAPHICS_DECL Release(CBaseRefCounter* base);
}
namespace NSFonts
{
class CFontSelectFormat
@ -382,7 +400,7 @@ namespace NSFonts
virtual bool _Close() = 0;
};
class GRAPHICS_DECL IFontPath
class GRAPHICS_DECL IFontPath : public NSBase::CBaseRefCounter
{
public:
IFontPath();
@ -400,20 +418,17 @@ namespace NSFonts
namespace NSFonts
{
class GRAPHICS_DECL IFontStream
class GRAPHICS_DECL IFontStream : public NSBase::CBaseRefCounter
{
public:
IFontStream();
virtual ~IFontStream();
virtual int AddRef() = 0;
virtual int Release() = 0;
public:
virtual int CreateFromFile(const std::wstring& strFileName, unsigned char* pDataUse = NULL) = 0;
};
class GRAPHICS_DECL IApplicationFontStreams
class GRAPHICS_DECL IApplicationFontStreams : public NSBase::CBaseRefCounter
{
public:
IApplicationFontStreams();
@ -438,7 +453,7 @@ namespace NSFonts
namespace NSFonts
{
class GRAPHICS_DECL IFontFile
class GRAPHICS_DECL IFontFile : public NSBase::CBaseRefCounter
{
public:
IFontFile();
@ -483,7 +498,7 @@ namespace NSFonts
namespace NSFonts
{
class GRAPHICS_DECL IFontsCache
class GRAPHICS_DECL IFontsCache : public NSBase::CBaseRefCounter
{
public:
IFontsCache();
@ -506,7 +521,7 @@ namespace NSFonts
namespace NSFonts
{
class IApplicationFonts;
class GRAPHICS_DECL IFontManager
class GRAPHICS_DECL IFontManager : public NSBase::CBaseRefCounter
{
public:
IFontManager();
@ -553,10 +568,6 @@ namespace NSFonts
virtual int GetStringPath(ISimpleGraphicsPath* pPath) = 0;
// addref/release
virtual int AddRef() = 0;
virtual int Release() = 0;
virtual CFontInfo* GetFontInfoByParams(CFontSelectFormat& oFormat, bool bIsDictionaryUse = true) = 0;
virtual std::vector<CFontInfo*> GetAllStylesByFontName(const std::wstring& strName) = 0;
@ -584,7 +595,7 @@ namespace NSFonts
namespace NSFonts
{
class GRAPHICS_DECL IFontList
class GRAPHICS_DECL IFontList : public NSBase::CBaseRefCounter
{
public:
IFontList();
@ -596,7 +607,7 @@ namespace NSFonts
virtual void ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory = L"", bool bIsOnlyFileName = false) = 0;
};
class GRAPHICS_DECL IApplicationFonts
class GRAPHICS_DECL IApplicationFonts : public NSBase::CBaseRefCounter
{
public:
IApplicationFonts();

View File

@ -42,7 +42,8 @@
#include "../IRenderer.h"
#include "../structures.h"
namespace Aggplus {
namespace Aggplus
{
class CDIB : public IGrObject
{
public:
@ -83,6 +84,7 @@ namespace NSGraphics
virtual void CloseFont() = 0;
virtual void SetSwapRGB(bool bValue) = 0;
virtual void SetTileImageDpi(const double& dDpi) = 0;
public:
virtual void CreateFromBgraFrame(CBgraFrame* pFrame) = 0;

View File

@ -38,14 +38,11 @@
namespace NSImages
{
class GRAPHICS_DECL ICacheImage
class GRAPHICS_DECL ICacheImage : public NSBase::CBaseRefCounter
{
public:
ICacheImage() {}
ICacheImage() : NSBase::CBaseRefCounter() {}
virtual ~ICacheImage() {}
virtual LONG AddRef() = 0;
virtual LONG Release() = 0;
};
namespace NSCacheImage
@ -53,19 +50,16 @@ namespace NSImages
GRAPHICS_DECL ICacheImage* Create(NSFonts::IApplicationFonts* pFonts, const std::wstring& sFile = L"");
}
class GRAPHICS_DECL IImageFilesCache
class GRAPHICS_DECL IImageFilesCache : public NSBase::CBaseRefCounter
{
public:
IImageFilesCache() {}
IImageFilesCache() : NSBase::CBaseRefCounter() {}
virtual ~IImageFilesCache() {}
virtual void Clear() = 0;
virtual ICacheImage* Lock(const std::wstring& strFile) = 0;
virtual LONG AddRef() = 0;
virtual LONG Release() = 0;
void SetApplicationFonts(NSFonts::IApplicationFonts* pApplicationFonts);
};
@ -116,7 +110,7 @@ namespace MetaFile
const int c_lMetaSvg = 0x04;
const int c_lMetaSvm = 0x05;
class GRAPHICS_DECL IMetaFile
class GRAPHICS_DECL IMetaFile : public NSBase::CBaseRefCounter
{
public:
IMetaFile(NSFonts::IApplicationFonts *pAppFonts) {}

View File

@ -34,6 +34,10 @@
#include "../../common/File.h"
#include "../../fontengine/ApplicationFonts.h"
#ifdef __APPLE__
#include <libkern/OSAtomic.h>
#endif
namespace NSFonts
{
CLibrary::CLibrary()
@ -47,9 +51,56 @@ namespace NSFonts
}
}
namespace NSBase
{
CBaseRefCounter::CBaseRefCounter()
{
m_lRef = 1;
}
CBaseRefCounter::~CBaseRefCounter()
{
}
#ifdef __APPLE__
int CBaseRefCounter::AddRef()
{
OSAtomicIncrement32(&m_lRef);
return m_lRef;
}
int CBaseRefCounter::Release()
{
int32_t ret = OSAtomicDecrement32(&m_lRef);
if (0 == m_lRef)
delete this;
return ret;
}
#else
int CBaseRefCounter::AddRef()
{
++m_lRef;
return m_lRef;
}
int CBaseRefCounter::Release()
{
int ret = --m_lRef;
if (0 == m_lRef)
delete this;
return ret;
}
#endif
void Release(CBaseRefCounter* base)
{
delete base;
}
}
namespace NSFonts
{
IFontPath::IFontPath() {}
IFontPath::IFontPath() : NSBase::CBaseRefCounter() {}
IFontPath::~IFontPath() {}
namespace NSFontPath
{
@ -59,7 +110,7 @@ namespace NSFonts
}
}
IFontStream::IFontStream() {}
IFontStream::IFontStream() : NSBase::CBaseRefCounter() {}
IFontStream::~IFontStream() {}
namespace NSStream
{
@ -69,7 +120,7 @@ namespace NSFonts
}
}
IApplicationFontStreams::IApplicationFontStreams() {}
IApplicationFontStreams::IApplicationFontStreams() : NSBase::CBaseRefCounter() {}
IApplicationFontStreams::~IApplicationFontStreams() {}
namespace NSApplicationFontStream
{
@ -79,7 +130,7 @@ namespace NSFonts
}
}
IFontFile::IFontFile() {}
IFontFile::IFontFile() : NSBase::CBaseRefCounter() {}
IFontFile::~IFontFile() {}
namespace NSFontFile
{
@ -89,7 +140,7 @@ namespace NSFonts
}
}
IFontsCache::IFontsCache() {}
IFontsCache::IFontsCache() : NSBase::CBaseRefCounter() {}
IFontsCache::~IFontsCache() {}
namespace NSFontCache
{
@ -99,7 +150,7 @@ namespace NSFonts
}
}
IFontManager::IFontManager() {}
IFontManager::IFontManager() : NSBase::CBaseRefCounter() {}
IFontManager::~IFontManager() {}
namespace NSFontManager
{
@ -109,10 +160,10 @@ namespace NSFonts
}
}
IFontList::IFontList() {}
IFontList::IFontList() : NSBase::CBaseRefCounter() {}
IFontList::~IFontList() {}
IApplicationFonts::IApplicationFonts() {}
IApplicationFonts::IApplicationFonts() : NSBase::CBaseRefCounter() {}
IApplicationFonts::~IApplicationFonts() {}
namespace NSApplication
{

View File

@ -39,6 +39,10 @@
#include "../../common/StringBuilder.h"
#ifndef XML_UNUSED
#define XML_UNUSED( arg ) ( (arg) = (arg) )
#endif
namespace XmlUtils
{
typedef enum XmlNodeType
@ -64,6 +68,12 @@ namespace XmlUtils
_XmlNodeType_Last = 17
} XmlNodeType;
typedef enum {
XML_C14N_1_0 = 0, /* Origianal C14N 1.0 spec */
XML_C14N_EXCLUSIVE_1_0 = 1, /* Exclusive C14N 1.0 spec */
XML_C14N_1_1 = 2 /* C14N 1.1 spec */
} xmlC14NMode;
class CXmlLiteReader_Private;
class KERNEL_DECL CXmlLiteReader
{
@ -178,6 +188,8 @@ namespace XmlUtils
std::wstring ReadAttributeBase(const wchar_t* bstrName);
std::wstring ReadAttribute(const std::wstring& strAttibuteName);
void ReadAllAttributesA(std::vector<std::string>& strNames, std::vector<std::string>& strValues);
void ReadAllAttributes(std::vector<std::wstring>& strNames, std::vector<std::wstring>& strValues);
int GetAttributesCount();
void GetAllAttributes(std::vector<std::wstring>& names, std::vector<std::wstring>& values);
@ -302,6 +314,12 @@ namespace XmlUtils
{ \
value = node.ReadNodeTextBase(name); \
}
namespace NSXmlCanonicalizator
{
std::string KERNEL_DECL Execute(const std::string& sXml, int mode = XML_C14N_1_0, bool withComments = false);
std::string KERNEL_DECL Execute(const std::wstring& sXmlFile, int mode = XML_C14N_1_0, bool withComments = false);
}
}
#endif // _BUILD_XMLUTILS_CROSSPLATFORM_H_

View File

@ -437,6 +437,32 @@ namespace XmlUtils
return GetAttribute(std::wstring(strAttibuteName));
}
void CXmlNode::ReadAllAttributesA(std::vector<std::string>& strNames, std::vector<std::string>& strValues)
{
if (!IsValid())
return;
std::map<std::string, std::string>::iterator p;
for (p = m_pBase->m_attributes.begin(); p != m_pBase->m_attributes.end(); ++p)
{
strNames.push_back(p->first);
strValues.push_back(p->second);
}
}
void CXmlNode::ReadAllAttributes(std::vector<std::wstring>& strNames, std::vector<std::wstring>& strValues)
{
if (!IsValid())
return;
std::map<std::string, std::string>::iterator p;
for (p = m_pBase->m_attributes.begin(); p != m_pBase->m_attributes.end(); ++p)
{
strNames.push_back (NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)p->first.c_str(), (long)p->first.length()));
strValues.push_back (NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)p->second.c_str(), (long)p->second.length()));
}
}
std::string CXmlNode::GetAttributeA(const std::string& sName, const std::string& _default)
{
if (!IsValid())
@ -956,3 +982,73 @@ namespace XmlUtils
WriteString(L"\"");
}
}
namespace XmlUtils
{
class CXmlBuffer
{
public:
NSStringUtils::CStringBuilderA builder;
public:
CXmlBuffer()
{
}
~CXmlBuffer()
{
}
};
static int buffer_xmlBufferIOWrite(CXmlBuffer* buf, const char* buffer, int len)
{
buf->builder.WriteString(buffer, (size_t)len);
return len;
}
static int buffer_xmlBufferIOClose(CXmlBuffer* buf)
{
XML_UNUSED(buf);
return 0;
}
static int buffer_xmlC14NIsVisibleCallback(void * user_data, xmlNodePtr node, xmlNodePtr parent)
{
XML_UNUSED(user_data);
XML_UNUSED(parent);
if (node->type == XML_TEXT_NODE)
{
const char* cur = (char*)node->content;
size_t size = strlen(cur);
for (size_t i = 0; i < size; ++i, ++cur)
{
if (*cur != '\n' && *cur != '\r' && *cur != '\t')
return 1;
}
return 0;
}
return 1;
}
std::string NSXmlCanonicalizator::Execute(const std::string& sXml, int mode, bool withComments)
{
xmlDocPtr xmlDoc = xmlParseMemory((char*)sXml.c_str(), (int)sXml.length());
CXmlBuffer bufferC14N;
xmlOutputBufferPtr _buffer = xmlOutputBufferCreateIO((xmlOutputWriteCallback)buffer_xmlBufferIOWrite,
(xmlOutputCloseCallback)buffer_xmlBufferIOClose,
&bufferC14N,
NULL);
xmlC14NExecute(xmlDoc, buffer_xmlC14NIsVisibleCallback, NULL, mode, NULL, withComments ? 1 : 0, _buffer);
xmlOutputBufferClose(_buffer);
return bufferC14N.builder.GetData();
}
std::string NSXmlCanonicalizator::Execute(const std::wstring& sXmlFile, int mode, bool withComments)
{
std::string sXml;
NSFile::CFileBinary::ReadAllTextUtf8A(sXmlFile, sXml);
return Execute(sXml, mode, withComments);
}
}

View File

@ -36,6 +36,7 @@
#include "../libxml2/libxml.h"
#include "../libxml2/include/libxml/xmlreader.h"
#include "../libxml2/include/libxml/c14n.h"
#include "../include/xmlutils.h"
namespace XmlUtils

View File

@ -16,8 +16,7 @@ CORE_ROOT_DIR = $$PWD/../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
CONFIG += core_static_link_xml_full
include($$CORE_ROOT_DIR/DesktopEditor/xml/build/qt/libxml2.pri)
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lkernel
DEFINES -= UNICODE

View File

@ -69,7 +69,7 @@ public:
std::string GetHashXml(const std::wstring& xml)
{
std::string sXmlSigned = U_TO_UTF8(xml);
sXmlSigned = CXmlCanonicalizator::Execute(sXmlSigned, XML_C14N_1_0);
sXmlSigned = XmlUtils::NSXmlCanonicalizator::Execute(sXmlSigned, XmlUtils::XML_C14N_1_0);
return m_certificate->GetHash(sXmlSigned, m_certificate->GetHashAlg());
}
@ -517,7 +517,7 @@ Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-sign
sSignedXml += sXml;
sSignedXml += L"</xd:SignedProperties>";
std::string sXmlTmp = CXmlCanonicalizator::Execute(U_TO_UTF8(sSignedXml), XML_C14N_1_0);
std::string sXmlTmp = XmlUtils::NSXmlCanonicalizator::Execute(U_TO_UTF8(sSignedXml), XmlUtils::XML_C14N_1_0);
m_signed_info.WriteString("<Reference Type=\"http://uri.etsi.org/01903#SignedProperties\" URI=\"#idSignedProperties\">");
m_signed_info.WriteString("<Transforms><Transform Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/></Transforms>");
@ -568,7 +568,7 @@ Type=\"http://schemas.openxmlformats.org/package/2006/relationships/digital-sign
std::string sSignedInfoData = m_signed_info.GetData();
std::string sSignedXml = "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + sSignedInfoData + "</SignedInfo>";
sSignedXml = CXmlCanonicalizator::Execute(sSignedXml, XML_C14N_1_0);
sSignedXml = XmlUtils::NSXmlCanonicalizator::Execute(sSignedXml, XmlUtils::XML_C14N_1_0);
sSignedXml = m_certificate->Sign(sSignedXml);
NSStringUtils::CStringBuilder builderResult;

View File

@ -1,4 +1,3 @@
#include "./XmlCanonicalizator.h"
#include "./XmlTransform.h"
#include "./../include/OOXMLVerifier.h"

View File

@ -1,88 +0,0 @@
#ifndef _XML_CANONICALIZATOR_H_
#define _XML_CANONICALIZATOR_H_
#include "../../../common/File.h"
#include "../../../common/Directory.h"
#include "../../../common/StringBuilder.h"
#include "../../../xml/include/xmlutils.h"
#include "../../../xml/libxml2/include/libxml/c14n.h"
#ifndef XML_UNUSED
#define XML_UNUSED( arg ) ( (arg) = (arg) )
#endif
class CXmlCanonicalizator
{
private:
class CXmlBuffer
{
public:
NSStringUtils::CStringBuilderA builder;
public:
CXmlBuffer()
{
}
~CXmlBuffer()
{
}
};
static int buffer_xmlBufferIOWrite(CXmlBuffer* buf, const char* buffer, int len)
{
buf->builder.WriteString(buffer, (size_t)len);
return len;
}
static int buffer_xmlBufferIOClose(CXmlBuffer* buf)
{
XML_UNUSED(buf);
return 0;
}
static int buffer_xmlC14NIsVisibleCallback(void * user_data, xmlNodePtr node, xmlNodePtr parent)
{
XML_UNUSED(user_data);
XML_UNUSED(parent);
if (node->type == XML_TEXT_NODE)
{
const char* cur = (char*)node->content;
size_t size = strlen(cur);
for (size_t i = 0; i < size; ++i, ++cur)
{
if (*cur != '\n' && *cur != '\r' && *cur != '\t')
return 1;
}
return 0;
}
return 1;
}
public:
static std::string Execute(const std::string& sXml, int mode = XML_C14N_1_0, bool withComments = false)
{
xmlDocPtr xmlDoc = xmlParseMemory((char*)sXml.c_str(), (int)sXml.length());
CXmlBuffer bufferC14N;
xmlOutputBufferPtr _buffer = xmlOutputBufferCreateIO((xmlOutputWriteCallback)buffer_xmlBufferIOWrite,
(xmlOutputCloseCallback)buffer_xmlBufferIOClose,
&bufferC14N,
NULL);
xmlC14NExecute(xmlDoc, buffer_xmlC14NIsVisibleCallback, NULL, mode, NULL, withComments ? 1 : 0, _buffer);
xmlOutputBufferClose(_buffer);
return bufferC14N.builder.GetData();
}
static std::string Execute(const std::wstring& sXmlFile, int mode = XML_C14N_1_0, bool withComments = false)
{
std::string sXml;
NSFile::CFileBinary::ReadAllTextUtf8A(sXmlFile, sXml);
return Execute(sXml, mode, withComments);
}
};
#endif //_XML_CANONICALIZATOR_H_

View File

@ -1,7 +1,10 @@
#ifndef _XML_RELS_H_
#define _XML_RELS_H_
#include "./XmlCanonicalizator.h"
#include "../../../xml/include/xmlutils.h"
#include "../../../common/StringBuilder.h"
#include "../../../common/File.h"
#include "../../../common/Directory.h"
class COOXMLRelationship
{

View File

@ -77,32 +77,32 @@ public:
m_mode = -1;
if ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315" == alg)
{
m_mode = XML_C14N_1_0;
m_mode = XmlUtils::XML_C14N_1_0;
m_comments = false;
}
else if ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" == alg)
{
m_mode = XML_C14N_1_0;
m_mode = XmlUtils::XML_C14N_1_0;
m_comments = true;
}
else if ("http://www.w3.org/2006/12/xml-c14n11" == alg)
{
m_mode = XML_C14N_1_1;
m_mode = XmlUtils::XML_C14N_1_1;
m_comments = false;
}
else if ("http://www.w3.org/2006/12/xml-c14n11#WithComments" == alg)
{
m_mode = XML_C14N_1_1;
m_mode = XmlUtils::XML_C14N_1_1;
m_comments = true;
}
else if ("http://www.w3.org/2001/10/xml-exc-c14n#" == alg)
{
m_mode = XML_C14N_EXCLUSIVE_1_0;
m_mode = XmlUtils::XML_C14N_EXCLUSIVE_1_0;
m_comments = false;
}
else if ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments" == alg)
{
m_mode = XML_C14N_EXCLUSIVE_1_0;
m_mode = XmlUtils::XML_C14N_EXCLUSIVE_1_0;
m_comments = true;
}
return (-1 != m_mode) ? true : false;
@ -112,7 +112,7 @@ public:
{
if (-1 == m_mode)
return xml;
return CXmlCanonicalizator::Execute(xml, m_mode, m_comments);
return XmlUtils::NSXmlCanonicalizator::Execute(xml, m_mode, m_comments);
}
virtual void LoadFromXml(XmlUtils::CXmlNode& node)

View File

@ -80,7 +80,7 @@ namespace NSHtmlRenderer
{
RELEASEOBJECT(m_pSimpleGraphicsConverter);
if(m_bDeleteFontManager)
RELEASEOBJECT(m_pFontManager);
NSBase::Release(m_pFontManager);
RELEASEOBJECT(m_pPen);
RELEASEOBJECT(m_pBrush);
RELEASEOBJECT(m_pFont);
@ -930,7 +930,7 @@ namespace NSHtmlRenderer
if(NULL != pFontManager)
{
if(m_bDeleteFontManager)
RELEASEOBJECT(m_pFontManager);
NSBase::Release(m_pFontManager);
m_pFontManager = pFontManager;
m_bDeleteFontManager = false;
}

View File

@ -22,6 +22,10 @@ LIBS += -lCryptoPPLib
DEFINES += NOMINMAX
core_linux {
QMAKE_CXXFLAGS += -Wno-narrowing
}
core_windows {
DEFINES -= UNICODE
DEFINES -= _UNICODE

View File

@ -98,6 +98,21 @@ namespace NExtractTools
}
return sExt;
}
bool replaceContentType(const std::wstring &sDir, const std::wstring &sCTFrom, const std::wstring &sCTTo)
{
bool res = false;
std::wstring sContentTypesPath = sDir + FILE_SEPARATOR_STR + _T("[Content_Types].xml");
if (NSFile::CFileBinary::Exists(sContentTypesPath))
{
std::wstring sData;
if (NSFile::CFileBinary::ReadAllTextUtf8(sContentTypesPath, sData))
{
sData = string_replaceAll(sData, sCTFrom, sCTTo);
res = NSFile::CFileBinary::SaveToFile(sContentTypesPath, sData, true);
}
}
return res;
}
// docx -> bin
int docx2doct_bin (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
{
@ -3078,20 +3093,36 @@ namespace NExtractTools
int nRes = 0;
if(0 != (AVS_OFFICESTUDIO_FILE_DOCUMENT & nFormatTo))
{
if(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatTo)
{
if(params.hasSavePassword())
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM == nFormatTo ||
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM == nFormatTo)
{
if (AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX == nFormatTo || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM == nFormatTo)
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.docx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
std::wstring sCTTo;
switch(nFormatTo)
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: sCTTo = _T("application/vnd.ms-word.document.macroEnabled.main+xml");break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml");break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM: sCTTo = _T("application/vnd.ms-word.template.macroEnabledTemplate.main+xml");break;
}
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
else
if(SUCCEEDED_X2T(nRes))
{
nRes = dir2zip(sFrom, sTo);
if(params.hasSavePassword())
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.docx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
}
}
else
{
nRes = dir2zip(sFrom, sTo);
}
}
}
else if(AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC == nFormatTo)
@ -3290,20 +3321,36 @@ namespace NExtractTools
int nRes = 0;
if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo) && AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV != nFormatTo)
{
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatTo)
{
if(params.hasSavePassword())
if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatTo ||
AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM == nFormatTo)
{
if (AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX == nFormatTo || AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM == nFormatTo)
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.xlsx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
std::wstring sCTTo;
switch(nFormatTo)
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM: sCTTo = _T("application/vnd.ms-excel.sheet.macroEnabled.main+xml");break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml");break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM: sCTTo = _T("application/vnd.ms-excel.template.macroEnabled.main+xml");break;
}
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
else
if(SUCCEEDED_X2T(nRes))
{
nRes = dir2zip(sFrom, sTo);
if(params.hasSavePassword())
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.xlsx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
}
}
else
{
nRes = dir2zip(sFrom, sTo);
}
}
}
//else if(AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS == nFormatTo)
@ -3477,20 +3524,39 @@ namespace NExtractTools
int nRes = 0;
if (0 != (AVS_OFFICESTUDIO_FILE_PRESENTATION & nFormatTo))
{
if(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX == nFormatTo)
if (AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX == nFormatTo ||
AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM == nFormatTo)
{
if(params.hasSavePassword())
if (AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX == nFormatTo ||
AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM == nFormatTo || AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM == nFormatTo)
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.pptx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
std::wstring sCTFrom = _T("application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml");
std::wstring sCTTo;
switch(nFormatTo)
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM: sCTTo = _T("application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml");break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX: sCTTo = _T("application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml");break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX: sCTTo = _T("application/vnd.openxmlformats-officedocument.presentationml.template.main+xml");break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM: sCTTo = _T("application/vnd.ms-powerpoint.template.macroEnabled.main+xml");break;
case AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM: sCTTo = _T("application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml");break;
}
nRes = replaceContentType(sFrom, sCTFrom, sCTTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT;
}
else
if(SUCCEEDED_X2T(nRes))
{
nRes = dir2zip(sFrom, sTo);
if(params.hasSavePassword())
{
std::wstring sToMscrypt = sTemp + FILE_SEPARATOR_STR + _T("tomscrypt.pptx");
nRes = dir2zip(sFrom, sToMscrypt);
if(SUCCEEDED_X2T(nRes))
{
nRes = oox2mscrypt(sToMscrypt, sTo, sTemp, params);
}
}
else
{
nRes = dir2zip(sFrom, sTo);
}
}
}
//else if(AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT == nFormatTo)

View File

@ -42,11 +42,12 @@ using namespace OOX::Spreadsheet;
namespace BinXlsxRW
{
SaveParams::SaveParams(const std::wstring& _sThemePath, OOX::CContentTypes* _pContentTypes)
SaveParams::SaveParams(const std::wstring& _sThemePath, OOX::CContentTypes* _pContentTypes, CSVWriter::CCSVWriter* _pCSVWriter)
{
pContentTypes = _pContentTypes;
sThemePath = _sThemePath;
nThemeOverrideCount = 1;
pCSVWriter = _pCSVWriter;
}
BYTE c_oserct_extlstEXT = 0;

View File

@ -36,6 +36,7 @@
#include "../../Common/DocxFormat/Source/XlsxFormat/Chart/ChartSerialize.h"
#include "../Writer/BinaryCommonReader.h"
#include "../../ASCOfficePPTXFile/ASCOfficeDrawingConverter.h"
#include "../../XlsxSerializerCom/Writer/CSVWriter.h"
namespace OOX
{
@ -50,12 +51,13 @@ namespace BinXlsxRW
class SaveParams
{
public:
SaveParams (const std::wstring& _sThemePath, OOX::CContentTypes *pContentTypes);
SaveParams (const std::wstring& _sThemePath, OOX::CContentTypes *pContentTypes, CSVWriter::CCSVWriter* pCSVWriter = NULL);
smart_ptr<PPTX::Theme> pTheme;
std::wstring sThemePath;
OOX::CContentTypes* pContentTypes;
int nThemeOverrideCount;
CSVWriter::CCSVWriter* pCSVWriter;
};
class BinaryChartReader : public Binary_CommonReader

View File

@ -38,6 +38,7 @@
#include "../../DesktopEditor/common/Path.h"
#include "../../DesktopEditor/common/Directory.h"
#include "../../DesktopEditor/common/StreamWriter.h"
#include "../Common/BinReaderWriterDefines.h"
#include "../Common/Common.h"
@ -70,6 +71,19 @@
namespace BinXlsxRW
{
#define SEEK_TO_POS_START(type) \
nPos = aSeekPositions[2 * type - 1]; \
length = aSeekPositions[2 * type]; \
if (nPos > 0) \
{ \
m_oBufferedStream.Seek(nPos); \
#define SEEK_TO_POS_END(elem) \
elem.toXML(oStreamWriter); \
}
#define SEEK_TO_POS_END2(elem) \
}
class ImageObject
{
@ -151,20 +165,21 @@ namespace BinXlsxRW
};
class BinaryTableReader : public Binary_CommonReader
{
OOX::Spreadsheet::CWorksheet* m_pCurWorksheet;
public:
BinaryTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream):Binary_CommonReader(oBufferedStream)
BinaryTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorksheet* pCurWorksheet):Binary_CommonReader(oBufferedStream), m_pCurWorksheet(pCurWorksheet)
{
}
int Read(long length, OOX::Spreadsheet::CWorksheet* pWorksheet)
int Read(long length, OOX::Spreadsheet::CTableParts* pTableParts)
{
int res = c_oSerConstants::ReadOk;
READ1_DEF(length, res, this->ReadTablePart, pWorksheet);
READ1_DEF(length, res, this->ReadTablePart, pTableParts);
return res;
}
int ReadTablePart(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
OOX::Spreadsheet::CWorksheet* pWorksheet = static_cast<OOX::Spreadsheet::CWorksheet*>(poResult);
OOX::Spreadsheet::CTableParts* pTableParts = static_cast<OOX::Spreadsheet::CTableParts*>(poResult);
if(c_oSer_TablePart::Table == type)
{
OOX::Spreadsheet::CTableFile* pTable = new OOX::Spreadsheet::CTableFile(NULL);
@ -173,10 +188,10 @@ namespace BinXlsxRW
OOX::Spreadsheet::CTablePart* pTablePart = new OOX::Spreadsheet::CTablePart();
NSCommon::smart_ptr<OOX::File> pTableFile(pTable);
const OOX::RId oRId = pWorksheet->Add(pTableFile);
const OOX::RId oRId = m_pCurWorksheet->Add(pTableFile);
pTablePart->m_oRId.Init();
pTablePart->m_oRId->SetValue(oRId.get());
pWorksheet->m_oTableParts->m_arrItems.push_back(pTablePart);
pTableParts->m_arrItems.push_back(pTablePart);
}
else
res = c_oSerConstants::ReadUnknown;
@ -2505,6 +2520,8 @@ namespace BinXlsxRW
OOX::Spreadsheet::CWorksheet* m_pCurWorksheet;
OOX::Spreadsheet::CDrawing* m_pCurDrawing;
OOX::CVmlDrawing* m_pCurVmlDrawing;
NSFile::CStreamWriter* m_pCurStreamWriter;
OOX::Spreadsheet::COleObjects* m_pCurOleObjects;
const std::wstring& m_sDestinationDir;
const std::wstring& m_sMediaDir;
@ -2551,20 +2568,24 @@ namespace BinXlsxRW
m_pCurVmlDrawing->m_lObjectIdVML = (long)(1024 * (m_oWorkbook.m_oSheets->m_arrItems.size() + 1) + 1);
READ1_DEF(length, res, this->ReadWorksheet, poResult);
_UINT32 aSeekPositions[2 * c_oSerWorksheetsTypes::PivotTable + 1];
memset(aSeekPositions, 0, (2 * c_oSerWorksheetsTypes::PivotTable + 1) * sizeof(_UINT32));
READ1_DEF(length, res, this->ReadWorksheetSeekPositions, aSeekPositions);
m_pCurWorksheet->m_sOutputFilename = m_pCurWorksheet->DefaultFileName().GetBasename();
m_pCurWorksheet->m_sOutputFilename += std::to_wstring(m_arWorksheets.size() + 1);
m_pCurWorksheet->m_sOutputFilename += m_pCurWorksheet->DefaultFileName().GetExtention();
std::wstring sWsPath = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + m_pCurWorksheet->DefaultDirectory().GetPath();
NSDirectory::CreateDirectories(sWsPath);
sWsPath += FILE_SEPARATOR_STR + m_pCurWorksheet->m_sOutputFilename;
NSFile::CStreamWriter oStreamWriter;
oStreamWriter.CreateFileW(sWsPath);
m_pCurStreamWriter = &oStreamWriter;
res = ReadWorksheet(aSeekPositions, oStreamWriter, poResult);
oStreamWriter.CloseFile();
if(m_pCurSheet->m_oName.IsInit())
{
//ole & comment
if(m_pCurVmlDrawing->m_aXml.size() > 0 || (NULL != m_pCurVmlDrawing->m_mapComments && m_pCurVmlDrawing->m_mapComments->size() > 0))
{
NSCommon::smart_ptr<OOX::File> pVmlDrawingFile(m_pCurVmlDrawing);
m_pCurVmlDrawing = NULL;
const OOX::RId oRId = m_pCurWorksheet->Add(pVmlDrawingFile);
m_pCurWorksheet->m_oLegacyDrawing.Init();
m_pCurWorksheet->m_oLegacyDrawing->m_oId.Init();
m_pCurWorksheet->m_oLegacyDrawing->m_oId->SetValue(oRId.get());
}
smart_ptr<OOX::File> oCurFile(m_pCurWorksheet);
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
m_pCurSheet->m_oRid.Init();
@ -2580,114 +2601,129 @@ namespace BinXlsxRW
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadWorksheet(BYTE type, long length, void* poResult)
}
int ReadWorksheetSeekPositions(BYTE type, long length, void* poResult)
{
_UINT32* aSeekPositions = static_cast<_UINT32*>(poResult);
aSeekPositions[2 * type - 1] = m_oBufferedStream.GetPos();
aSeekPositions[2 * type] = length;
return c_oSerConstants::ReadUnknown;
}
int ReadWorksheet(_UINT32* aSeekPositions, NSFile::CStreamWriter& oStreamWriter, void* poResult)
{
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::WorksheetProp == type)
{
READ2_DEF(length, res, this->ReadWorksheetProp, poResult);
}
else if(c_oSerWorksheetsTypes::Cols == type)
{
m_pCurWorksheet->m_oCols.Init();
READ1_DEF(length, res, this->ReadWorksheetCols, poResult);
}
else if (c_oSerWorksheetsTypes::SheetViews == type)
{
m_pCurWorksheet->m_oSheetViews.Init();
READ1_DEF(length, res, this->ReadSheetViews, poResult);
}
else if (c_oSerWorksheetsTypes::SheetPr == type)
{
m_pCurWorksheet->m_oSheetPr.Init();
READ1_DEF(length, res, this->ReadSheetPr, m_pCurWorksheet->m_oSheetPr.GetPointer());
}
else if(c_oSerWorksheetsTypes::SheetFormatPr == type)
{
m_pCurWorksheet->m_oSheetFormatPr.Init();
READ2_DEF(length, res, this->ReadSheetFormatPr, m_pCurWorksheet->m_oSheetFormatPr.GetPointer());
}
else if(c_oSerWorksheetsTypes::PageMargins == type)
{
m_pCurWorksheet->m_oPageMargins.Init();
READ2_DEF(length, res, this->ReadPageMargins, m_pCurWorksheet->m_oPageMargins.GetPointer());
}
else if(c_oSerWorksheetsTypes::PageSetup == type)
{
m_pCurWorksheet->m_oPageSetup.Init();
READ2_DEF(length, res, this->ReadPageSetup, m_pCurWorksheet->m_oPageSetup.GetPointer());
}
else if(c_oSerWorksheetsTypes::PrintOptions == type)
{
m_pCurWorksheet->m_oPrintOptions.Init();
READ2_DEF(length, res, this->ReadPrintOptions, m_pCurWorksheet->m_oPrintOptions.GetPointer());
}
else if(c_oSerWorksheetsTypes::Hyperlinks == type)
{
m_pCurWorksheet->m_oHyperlinks.Init();
READ1_DEF(length, res, this->ReadHyperlinks, poResult);
}
else if(c_oSerWorksheetsTypes::MergeCells == type)
{
m_pCurWorksheet->m_oMergeCells.Init();
READ1_DEF(length, res, this->ReadMergeCells, poResult);
m_pCurWorksheet->m_oMergeCells->m_oCount.Init();
m_pCurWorksheet->m_oMergeCells->m_oCount->SetValue((unsigned int)m_pCurWorksheet->m_oMergeCells->m_arrItems.size());
}
else if(c_oSerWorksheetsTypes::Drawings == type)
{
OOX::CPath pathDrawingsDir = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + _T("drawings");
OOX::CSystemUtility::CreateDirectories(pathDrawingsDir.GetPath());
OOX::CPath pathDrawingsRelsDir = pathDrawingsDir.GetPath() + FILE_SEPARATOR_STR + _T("_rels");
OOX::CSystemUtility::CreateDirectories(pathDrawingsRelsDir.GetPath());
m_pCurWorksheet->toXMLStart(oStreamWriter);
LONG nOldPos = m_oBufferedStream.GetPos();
LONG nPos;
LONG length;
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetPr);
OOX::Spreadsheet::CSheetPr oSheetPr;
READ1_DEF(length, res, this->ReadSheetPr, &oSheetPr);
SEEK_TO_POS_END(oSheetPr);
m_pOfficeDrawingConverter->SetDstContentRels();
m_pCurDrawing = new OOX::Spreadsheet::CDrawing(NULL);
READ1_DEF(length, res, this->ReadDrawings, m_pCurDrawing);
NSCommon::smart_ptr<OOX::File> pDrawingFile(m_pCurDrawing);
const OOX::RId oRId = m_pCurWorksheet->Add(pDrawingFile);
m_pCurWorksheet->m_oDrawing.Init();
m_pCurWorksheet->m_oDrawing->m_oId.Init();
m_pCurWorksheet->m_oDrawing->m_oId->SetValue(oRId.get());
OOX::Spreadsheet::CSheetViews oSheetViews;
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetViews);
READ1_DEF(length, res, this->ReadSheetViews, &oSheetViews);
SEEK_TO_POS_END2();
if(oSheetViews.m_arrItems.empty())
oSheetViews.m_arrItems.push_back(new OOX::Spreadsheet::CSheetView());
OOX::Spreadsheet::CSheetView* pSheetView = oSheetViews.m_arrItems.front();
if(false == pSheetView->m_oWorkbookViewId.IsInit())
{
pSheetView->m_oWorkbookViewId.Init();
pSheetView->m_oWorkbookViewId->SetValue(0);
}
oSheetViews.toXML(oStreamWriter);
OOX::CPath pathDrawingsRels = pathDrawingsRelsDir.GetPath() + FILE_SEPARATOR_STR + m_pCurDrawing->m_sOutputFilename + _T(".rels");
m_pOfficeDrawingConverter->SaveDstContentRels(pathDrawingsRels.GetPath());
}
else if(c_oSerWorksheetsTypes::SheetData == type)
OOX::Spreadsheet::CSheetFormatPr oSheetFormatPr;
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetFormatPr);
READ2_DEF(length, res, this->ReadSheetFormatPr, &oSheetFormatPr);
SEEK_TO_POS_END2();
if(!oSheetFormatPr.m_oDefaultRowHeight.IsInit())
{
m_pCurWorksheet->m_oSheetData.Init();
READ1_DEF(length, res, this->ReadSheetData, poResult);
oSheetFormatPr.m_oDefaultRowHeight.Init();
oSheetFormatPr.m_oDefaultRowHeight->SetValue(15);
}
else if (c_oSerWorksheetsTypes::ConditionalFormatting == type)
{
OOX::Spreadsheet::CConditionalFormatting* pConditionalFormatting = new OOX::Spreadsheet::CConditionalFormatting();
READ1_DEF(length, res, this->ReadConditionalFormatting, pConditionalFormatting);
m_pCurWorksheet->m_arrConditionalFormatting.push_back(pConditionalFormatting);
}
else if(c_oSerWorksheetsTypes::Comments == type)
{
oSheetFormatPr.toXML(oStreamWriter);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Cols);
OOX::Spreadsheet::CCols oCols;
READ1_DEF(length, res, this->ReadWorksheetCols, &oCols);
SEEK_TO_POS_END(oCols);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SheetData);
OOX::Spreadsheet::CSheetData oSheetData;
if (NULL == m_oSaveParams.pCSVWriter)
{
oSheetData.toXMLStart(oStreamWriter);
READ1_DEF(length, res, this->ReadSheetData, NULL);
oSheetData.toXMLEnd(oStreamWriter);
}
else if(m_arWorksheets.size() == m_oWorkbook.GetActiveSheetIndex())
{
m_oSaveParams.pCSVWriter->WriteSheetStart(m_pCurWorksheet);
READ1_DEF(length, res, this->ReadSheetData, NULL);
m_oSaveParams.pCSVWriter->WriteSheetEnd(m_pCurWorksheet);
}
SEEK_TO_POS_END2();
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Autofilter);
OOX::Spreadsheet::CAutofilter oAutofilter;
BinaryTableReader oBinaryTableReader(m_oBufferedStream, m_pCurWorksheet);
READ1_DEF(length, res, oBinaryTableReader.ReadAutoFilter, &oAutofilter);
SEEK_TO_POS_END(oAutofilter);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::MergeCells);
OOX::Spreadsheet::CMergeCells oMergeCells;
READ1_DEF(length, res, this->ReadMergeCells, &oMergeCells);
oMergeCells.m_oCount.Init();
oMergeCells.m_oCount->SetValue((unsigned int)oMergeCells.m_arrItems.size());
SEEK_TO_POS_END(oMergeCells);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::ConditionalFormatting);
OOX::Spreadsheet::CConditionalFormatting oConditionalFormatting;
READ1_DEF(length, res, this->ReadConditionalFormatting, &oConditionalFormatting);
SEEK_TO_POS_END(oConditionalFormatting);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Hyperlinks);
OOX::Spreadsheet::CHyperlinks oHyperlinks;
READ1_DEF(length, res, this->ReadHyperlinks, &oHyperlinks);
SEEK_TO_POS_END(oHyperlinks);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PrintOptions);
OOX::Spreadsheet::CPrintOptions oPrintOptions;
READ2_DEF(length, res, this->ReadPrintOptions, &oPrintOptions);
SEEK_TO_POS_END(oPrintOptions);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PageMargins);
OOX::Spreadsheet::CPageMargins oPageMargins;
READ2_DEF(length, res, this->ReadPageMargins, &oPageMargins);
SEEK_TO_POS_END(oPageMargins);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PageSetup);
OOX::Spreadsheet::CPageSetup oPageSetup;
READ2_DEF(length, res, this->ReadPageSetup, &oPageSetup);
SEEK_TO_POS_END(oPageSetup);
//important before Drawings
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Comments);
BinaryCommentReader oBinaryCommentReader(m_oBufferedStream, m_pCurWorksheet);
oBinaryCommentReader.Read(length, poResult);
if(m_pCurWorksheet->m_mapComments.size() > 0)
{
m_pCurVmlDrawing->m_mapComments = &m_pCurWorksheet->m_mapComments;
boost::unordered_map<std::wstring, unsigned int> mapByAuthors;
boost::unordered_map<std::wstring, unsigned int> mapByAuthors;
OOX::Spreadsheet::CComments* pComments = new OOX::Spreadsheet::CComments(NULL);
pComments->m_oCommentList.Init();
std::vector<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems;
std::vector<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems;
pComments->m_oAuthors.Init();
for (boost::unordered_map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it)
for (boost::unordered_map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it)
{
if(it->second->IsValid())
{
@ -2702,18 +2738,18 @@ namespace BinXlsxRW
if(pCommentItem->m_sAuthor.IsInit())
{
const std::wstring& sAuthor = pCommentItem->m_sAuthor.get();
boost::unordered_map<std::wstring, unsigned int>::const_iterator pFind = mapByAuthors.find(sAuthor);
boost::unordered_map<std::wstring, unsigned int>::const_iterator pFind = mapByAuthors.find(sAuthor);
int nAuthorId;
if(pFind != mapByAuthors.end())
nAuthorId = pFind->second;
else
{
nAuthorId = (int)mapByAuthors.size();
mapByAuthors.insert(std::make_pair(sAuthor, nAuthorId));
pComments->m_oAuthors->m_arrItems.push_back( sAuthor );
pComments->m_oAuthors->m_arrItems.push_back( sAuthor );
}
pNewComment->m_oAuthorId.Init();
pNewComment->m_oAuthorId->SetValue(nAuthorId);
@ -2729,42 +2765,79 @@ namespace BinXlsxRW
NSCommon::smart_ptr<OOX::File> pCommentsFile(pComments);
m_pCurWorksheet->Add(pCommentsFile);
}
}
else if(c_oSerWorksheetsTypes::Autofilter == type)
{
BinaryTableReader oBinaryTableReader(m_oBufferedStream);
m_pCurWorksheet->m_oAutofilter.Init();
READ1_DEF(length, res, oBinaryTableReader.ReadAutoFilter, m_pCurWorksheet->m_oAutofilter.GetPointer());
}
else if(c_oSerWorksheetsTypes::TableParts == type)
{
BinaryTableReader oBinaryTableReader(m_oBufferedStream);
m_pCurWorksheet->m_oTableParts.Init();
oBinaryTableReader.Read(length, m_pCurWorksheet);
m_pCurWorksheet->m_oTableParts->m_oCount.Init();
m_pCurWorksheet->m_oTableParts->m_oCount->SetValue((unsigned int)m_pCurWorksheet->m_oTableParts->m_arrItems.size());
}
else if(c_oSerWorksheetsTypes::SparklineGroups == type)
{
OOX::Drawing::COfficeArtExtension* pOfficeArtExtension = new OOX::Drawing::COfficeArtExtension();
pOfficeArtExtension->m_oSparklineGroups.Init();
SEEK_TO_POS_END2();
SEEK_TO_POS_START(c_oSerWorksheetsTypes::Drawings);
OOX::CPath pathDrawingsDir = m_sDestinationDir + FILE_SEPARATOR_STR + _T("xl") + FILE_SEPARATOR_STR + _T("drawings");
OOX::CSystemUtility::CreateDirectories(pathDrawingsDir.GetPath());
OOX::CPath pathDrawingsRelsDir = pathDrawingsDir.GetPath() + FILE_SEPARATOR_STR + _T("_rels");
OOX::CSystemUtility::CreateDirectories(pathDrawingsRelsDir.GetPath());
m_pOfficeDrawingConverter->SetDstContentRels();
m_pCurDrawing = new OOX::Spreadsheet::CDrawing(NULL);
OOX::Spreadsheet::COleObjects oOleObjects;
m_pCurOleObjects = &oOleObjects;
READ1_DEF(length, res, this->ReadDrawings, m_pCurDrawing);
NSCommon::smart_ptr<OOX::File> pDrawingFile(m_pCurDrawing);
const OOX::RId oRId = m_pCurWorksheet->Add(pDrawingFile);
OOX::Spreadsheet::CDrawingWorksheet oDrawingWorksheet;
oDrawingWorksheet.m_oId.Init();
oDrawingWorksheet.m_oId->SetValue(oRId.get());
oDrawingWorksheet.toXML(oStreamWriter);
//ole & comment
if(m_pCurVmlDrawing->m_aXml.size() > 0 || (NULL != m_pCurVmlDrawing->m_mapComments && m_pCurVmlDrawing->m_mapComments->size() > 0))
{
NSCommon::smart_ptr<OOX::File> pVmlDrawingFile(m_pCurVmlDrawing);
m_pCurVmlDrawing = NULL;
const OOX::RId oRId = m_pCurWorksheet->Add(pVmlDrawingFile);
OOX::Spreadsheet::CLegacyDrawingWorksheet oLegacyDrawing;
oLegacyDrawing.m_oId.Init();
oLegacyDrawing.m_oId->SetValue(oRId.get());
oLegacyDrawing.toXML(oStreamWriter);
}
if (oOleObjects.m_mapOleObjects.size() > 0)
{
oOleObjects.toXML(oStreamWriter);
}
OOX::CPath pathDrawingsRels = pathDrawingsRelsDir.GetPath() + FILE_SEPARATOR_STR + m_pCurDrawing->m_sOutputFilename + _T(".rels");
m_pOfficeDrawingConverter->SaveDstContentRels(pathDrawingsRels.GetPath());
SEEK_TO_POS_END2();
SEEK_TO_POS_START(c_oSerWorksheetsTypes::TableParts);
BinaryTableReader oBinaryTableReader(m_oBufferedStream, m_pCurWorksheet);
OOX::Spreadsheet::CTableParts oTableParts;
oBinaryTableReader.Read(length, &oTableParts);
oTableParts.m_oCount.Init();
oTableParts.m_oCount->SetValue((unsigned int)oTableParts.m_arrItems.size());
SEEK_TO_POS_END(oTableParts);
SEEK_TO_POS_START(c_oSerWorksheetsTypes::SparklineGroups);
OOX::Drawing::COfficeArtExtension* pOfficeArtExtension = new OOX::Drawing::COfficeArtExtension();
pOfficeArtExtension->m_oSparklineGroups.Init();
READ1_DEF(length, res, this->ReadSparklineGroups, pOfficeArtExtension->m_oSparklineGroups.GetPointer());
pOfficeArtExtension->m_sUri.Init();
pOfficeArtExtension->m_sUri->append(_T("{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"));
pOfficeArtExtension->m_sAdditionalNamespace = _T("xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\"");
m_pCurWorksheet->m_oExtLst.Init();
m_pCurWorksheet->m_oExtLst->m_arrExt.push_back(pOfficeArtExtension);
}
else if(c_oSerWorksheetsTypes::PivotTable == type)
{
pOfficeArtExtension->m_sUri.Init();
pOfficeArtExtension->m_sUri->append(_T("{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"));
pOfficeArtExtension->m_sAdditionalNamespace = _T("xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\"");
OOX::Drawing::COfficeArtExtensionList oExtLst;
oExtLst.m_arrExt.push_back(pOfficeArtExtension);
oStreamWriter.WriteString(oExtLst.toXMLWithNS(_T("")));
SEEK_TO_POS_END2();
SEEK_TO_POS_START(c_oSerWorksheetsTypes::WorksheetProp);
READ2_DEF(length, res, this->ReadWorksheetProp, poResult);
SEEK_TO_POS_END2();
SEEK_TO_POS_START(c_oSerWorksheetsTypes::PivotTable);
PivotCachesTemp oPivotCachesTemp;
READ1_DEF(length, res, this->ReadPivotTable, &oPivotCachesTemp);
boost::unordered_map<long, NSCommon::smart_ptr<OOX::File>>::const_iterator pair = m_mapPivotCacheDefinitions.find(oPivotCachesTemp.nCacheId);
boost::unordered_map<long, NSCommon::smart_ptr<OOX::File>>::const_iterator pair = m_mapPivotCacheDefinitions.find(oPivotCachesTemp.nCacheId);
if(m_mapPivotCacheDefinitions.end() != pair && NULL != oPivotCachesTemp.pTable)
{
NSCommon::smart_ptr<OOX::File> pFileTable(oPivotCachesTemp.pTable);
@ -2775,9 +2848,10 @@ namespace BinXlsxRW
{
RELEASEOBJECT(oPivotCachesTemp.pTable);
}
}
else
res = c_oSerConstants::ReadUnknown;
SEEK_TO_POS_END2();
m_oBufferedStream.Seek(nOldPos);
m_pCurWorksheet->toXMLEnd(oStreamWriter);
return res;
}
int ReadPivotTable(BYTE type, long length, void* poResult)
@ -2823,12 +2897,13 @@ namespace BinXlsxRW
}
int ReadWorksheetCols(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CCols* pCols = static_cast<OOX::Spreadsheet::CCols*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::Col == type)
{
OOX::Spreadsheet::CCol* pCol = new OOX::Spreadsheet::CCol();
READ2_DEF(length, res, this->ReadWorksheetCol, pCol);
m_pCurWorksheet->m_oCols->m_arrItems.push_back(pCol);
pCols->m_arrItems.push_back(pCol);
}
else
res = c_oSerConstants::ReadUnknown;
@ -2889,12 +2964,13 @@ namespace BinXlsxRW
}
int ReadSheetViews(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CSheetViews* pSheetViews = static_cast<OOX::Spreadsheet::CSheetViews*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::SheetView == type)
{
OOX::Spreadsheet::CSheetView* pSheetView = new OOX::Spreadsheet::CSheetView();
READ1_DEF(length, res, this->ReadSheetView, pSheetView);
m_pCurWorksheet->m_oSheetViews->m_arrItems.push_back(pSheetView);
pSheetViews->m_arrItems.push_back(pSheetView);
}
else
res = c_oSerConstants::ReadUnknown;
@ -3250,12 +3326,13 @@ namespace BinXlsxRW
}
int ReadHyperlinks(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CHyperlinks* pHyperlinks = static_cast<OOX::Spreadsheet::CHyperlinks*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::Hyperlink == type)
{
OOX::Spreadsheet::CHyperlink* pHyperlink = new OOX::Spreadsheet::CHyperlink();
READ1_DEF(length, res, this->ReadHyperlink, pHyperlink);
m_pCurWorksheet->m_oHyperlinks->m_arrItems.push_back(pHyperlink);
pHyperlinks->m_arrItems.push_back(pHyperlink);
}
else
res = c_oSerConstants::ReadUnknown;
@ -3298,13 +3375,14 @@ namespace BinXlsxRW
}
int ReadMergeCells(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CMergeCells* pMergeCells = static_cast<OOX::Spreadsheet::CMergeCells*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::MergeCell == type)
{
OOX::Spreadsheet::CMergeCell* pMergeCell = new OOX::Spreadsheet::CMergeCell();
pMergeCell->m_oRef.Init();
pMergeCell->m_oRef->append(m_oBufferedStream.GetString4(length));
m_pCurWorksheet->m_oMergeCells->m_arrItems.push_back(pMergeCell);
pMergeCells->m_arrItems.push_back(pMergeCell);
}
else
res = c_oSerConstants::ReadUnknown;
@ -3404,10 +3482,6 @@ namespace BinXlsxRW
oRIdImg = new OOX::RId(m_pCurWorksheet->Add(pFileWorksheet));
}
//add oleObject rels
if(!m_pCurWorksheet->m_oOleObjects.IsInit())
{
m_pCurWorksheet->m_oOleObjects.Init();
}
smart_ptr<OOX::File> pFileObject = pOleObject->m_OleObjectFile.smart_dynamic_cast<OOX::File>();
const OOX::RId oRIdBin = m_pCurWorksheet->Add(pFileObject);
@ -3442,7 +3516,7 @@ namespace BinXlsxRW
pOleObject->m_oObjectPr->m_oAnchor->m_oFrom = pCellAnchor->m_oFrom;
pOleObject->m_oObjectPr->m_oAnchor->m_oTo = pCellAnchor->m_oTo;
m_pCurWorksheet->m_oOleObjects->m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
m_pCurOleObjects->m_mapOleObjects[pOleObject->m_oShapeId->GetValue()] = pOleObject;
}
else
{
@ -3582,9 +3656,8 @@ namespace BinXlsxRW
int res = c_oSerConstants::ReadOk;
if(c_oSerWorksheetsTypes::Row == type)
{
OOX::Spreadsheet::CRow* pRow = new OOX::Spreadsheet::CRow();
READ2_DEF(length, res, this->ReadRow, pRow);
m_pCurWorksheet->m_oSheetData->m_arrItems.push_back(pRow);
OOX::Spreadsheet::CRow oRow;
READ2_DEF(length, res, this->ReadRow, &oRow);
}
else
res = c_oSerConstants::ReadUnknown;
@ -3633,7 +3706,18 @@ namespace BinXlsxRW
}
else if(c_oSerRowTypes::Cells == type)
{
READ1_DEF(length, res, this->ReadCells, pRow);
if (NULL == m_oSaveParams.pCSVWriter)
{
pRow->toXMLStart(*m_pCurStreamWriter);
READ1_DEF(length, res, this->ReadCells, pRow);
pRow->toXMLEnd(*m_pCurStreamWriter);
}
else
{
m_oSaveParams.pCSVWriter->WriteRowStart(pRow);
READ1_DEF(length, res, this->ReadCells, pRow);
m_oSaveParams.pCSVWriter->WriteRowEnd(pRow);
}
}
else
@ -3646,24 +3730,24 @@ namespace BinXlsxRW
int res = c_oSerConstants::ReadOk;
if(c_oSerRowTypes::Cell == type)
{
OOX::Spreadsheet::CCell* pCell = new OOX::Spreadsheet::CCell();
READ1_DEF(length, res, this->ReadCell, pCell);
OOX::Spreadsheet::CCell oCell;
READ1_DEF(length, res, this->ReadCell, &oCell);
//текст error и формул пишем
if(NULL != m_pSharedStrings && pCell->m_oType.IsInit() && pCell->m_oValue.IsInit())
if(NULL != m_pSharedStrings && oCell.m_oType.IsInit() && oCell.m_oValue.IsInit())
{
SimpleTypes::Spreadsheet::ECellTypeType eCellType = pCell->m_oType->GetValue();
SimpleTypes::Spreadsheet::ECellTypeType eCellType = oCell.m_oType->GetValue();
bool bMoveText = false;
if(SimpleTypes::Spreadsheet::celltypeError == eCellType)
bMoveText = true;
else if((SimpleTypes::Spreadsheet::celltypeSharedString == eCellType && pCell->m_oFormula.IsInit()))
else if((SimpleTypes::Spreadsheet::celltypeSharedString == eCellType && oCell.m_oFormula.IsInit()))
{
bMoveText = true;
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeStr);
oCell.m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeStr);
}
if(bMoveText)
{
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
int nValue = _wtoi(oCell.m_oValue->ToString().c_str());
if (nValue >= 0 && nValue < (int)m_pSharedStrings->m_arrItems.size())
{
@ -3674,14 +3758,21 @@ namespace BinXlsxRW
if(OOX::et_x_t == pWe->getType())
{
OOX::Spreadsheet::CText* pText = static_cast<OOX::Spreadsheet::CText*>(pWe);
pCell->m_oValue->m_sText = pText->m_sText;
pCell->m_oValue->m_oSpace = pText->m_oSpace;
oCell.m_oValue->m_sText = pText->m_sText;
oCell.m_oValue->m_oSpace = pText->m_oSpace;
}
}
}
}
}
pRow->m_arrItems.push_back(pCell);
if (NULL == m_oSaveParams.pCSVWriter)
{
oCell.toXML(*m_pCurStreamWriter);
}
else
{
m_oSaveParams.pCSVWriter->WriteCell(&oCell);
}
}
else
res = c_oSerConstants::ReadUnknown;
@ -4518,27 +4609,20 @@ namespace BinXlsxRW
OOX::Spreadsheet::CXlsx oXlsx;
std::wstring params_path = sDstPath + FILE_SEPARATOR_STR + OOX::Spreadsheet::FileTypes::Workbook.DefaultDirectory().GetPath() + FILE_SEPARATOR_STR + OOX::FileTypes::Theme.DefaultDirectory().GetPath();
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes());
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
//std::wstring sAdditionalContentTypes = oSaveParams.sAdditionalContentTypes;
// if(NULL != pOfficeDrawingConverter)
//{
// sAdditionalContentTypes += pOfficeDrawingConverter->GetContentTypes();
//}
oXlsx.PrepareToWrite();
switch(fileType)
if(BinXlsxRW::c_oFileTypes::XLSX == fileType)
{
case BinXlsxRW::c_oFileTypes::CSV:
CSVWriter::WriteFromXlsxToCsv(sDstPathCSV, oXlsx, nCodePage, sDelimiter, false);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes(), NULL);
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
oXlsx.PrepareToWrite();
oXlsx.Write(sDstPath, *oSaveParams.pContentTypes);
break;
}
else
{
CSVWriter::CCSVWriter oCSVWriter(oXlsx, nCodePage, sDelimiter, false);
oCSVWriter.Start(sDstPathCSV);
SaveParams oSaveParams(params_path.c_str(), pOfficeDrawingConverter->GetContentTypes(), &oCSVWriter);
ReadMainTable(oXlsx, oBufferedStream, OOX::CPath(sSrcFileName).GetDirectory(), sDstPath, oSaveParams, pOfficeDrawingConverter);
oCSVWriter.End();
}
bResultOk = true;
}

View File

@ -41,6 +41,13 @@
namespace CSVWriter
{
static std::wstring g_sNewLineN = _T("\n");
static std::wstring g_sEndJson = _T("]");
static std::wstring g_sQuote = _T("\"");
static std::wstring g_sDoubleQuote = _T("\"\"");
static std::wstring g_sBkt = _T("[");
static std::wstring g_sBktComma = _T(",[");
void escapeJson(const std::wstring& sInput, NSStringUtils::CStringBuilder& oBuilder)
{
//http://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c
@ -69,7 +76,7 @@ namespace CSVWriter
}
}
}
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd)
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false)
{
if (NULL == pFile || NULL == pWriteBuffer)
return;
@ -113,59 +120,25 @@ namespace CSVWriter
}
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& sDelimiter, bool bJSON)
{
NSFile::CFileBinary oFile;
oFile.CreateFileW(sFileDst);
// Нужно записать шапку
if (46 == nCodePage)//todo 46 временно CP_UTF8
{
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
oFile.WriteFile(arUTF8, 3);
}
else if (48 == nCodePage)//todo 48 временно CP_UTF16
{
BYTE arUTF16[2] = {0xFF, 0xFE};
oFile.WriteFile(arUTF16, 2);
}
else if (49 == nCodePage)//todo 49 временно CP_unicodeFFFE
{
BYTE arBigEndian[2] = {0xFE, 0xFF};
oFile.WriteFile(arBigEndian, 2);
}
std::wstring sNewLineN = _T("\n");
LONG lActiveSheet = 0;
INT nCurrentIndex = 0;
WCHAR *pWriteBuffer = NULL;
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
CCSVWriter oWriter(oXlsx, nCodePage, sDelimiter, bJSON);
oWriter.Start(sFileDst);
if ( oXlsx.m_pWorkbook )
{
// Get active sheet
if ( oXlsx.m_pWorkbook->m_oBookViews.IsInit() && !oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.empty())
{
if ( oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.front()->m_oActiveTab.IsInit())
{
lActiveSheet = oXlsx.m_pWorkbook->m_oBookViews->m_arrItems.front()->m_oActiveTab->GetValue();
if (0 > lActiveSheet)
lActiveSheet = 0;
}
}
LONG lActiveSheet = oXlsx.m_pWorkbook->GetActiveSheetIndex();
std::wstring sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
// Get active sheet rId (для конвертации в CSV нужно использовать name, т.к. это наш бинарник из js-скриптов и еще нет rId
// А для json-а нужно пользовать rId, т.к. при открытии они используются
if ( oXlsx.m_pWorkbook->m_oSheets.IsInit() && !oXlsx.m_pWorkbook->m_oSheets->m_arrItems.empty())
{
OOX::Spreadsheet::CSheet *pSheet = NULL;
OOX::Spreadsheet::CSheet* pSheet = NULL;
if (lActiveSheet >= 0 && lActiveSheet < oXlsx.m_pWorkbook->m_oSheets->m_arrItems.size())
{
pSheet = oXlsx.m_pWorkbook->m_oSheets->m_arrItems[lActiveSheet];
pSheet = oXlsx.m_pWorkbook-> m_oSheets->m_arrItems[lActiveSheet];
}
else
{
pSheet = oXlsx.m_pWorkbook->m_oSheets->m_arrItems.front();
}
sSheetRId = bJSON ? pSheet->m_oRid->GetValue() : pSheet->m_oName.get2();
}
@ -173,141 +146,192 @@ namespace CSVWriter
if (pFind != oXlsx.m_mapWorksheets.end())
{
OOX::Spreadsheet::CWorksheet *pWorksheet = pFind->second;
if (NULL != pWorksheet && pWorksheet->m_oSheetData.IsInit())
{
std::wstring sEscape = _T("\"\n");
sEscape += sDelimiter;
std::wstring sEndJson = std::wstring(_T("]"));
std::wstring sQuote = _T("\"");
std::wstring sDoubleQuote = _T("\"\"");
std::wstring sBkt = std::wstring(_T("["));
std::wstring sBktComma = _T(",[");
if (bJSON)
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sBkt, nCodePage);
INT nRowCurrent = 1;
for (size_t i = 0; i < pWorksheet->m_oSheetData->m_arrItems.size(); ++i)
oWriter.WriteSheetStart(pWorksheet);
for (size_t i = 0; i < pWorksheet->m_oSheetData->m_arrItems.size(); ++i)
{
OOX::Spreadsheet::CRow *pRow = pWorksheet->m_oSheetData->m_arrItems[i];
INT nRow = pRow->m_oR.IsInit() ? pRow->m_oR->GetValue() : 0 == i ? nRowCurrent : nRowCurrent + 1;
if (bJSON)
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, (0 == i ? sBkt: sBktComma), nCodePage);
else
OOX::Spreadsheet::CRow *pRow = pWorksheet->m_oSheetData->m_arrItems[i];
oWriter.WriteRowStart(pRow);
for (size_t j = 0; j < pRow->m_arrItems.size(); ++j)
{
while (nRow > nRowCurrent)
{
// Write new line
++nRowCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
}
oWriter.WriteCell(pRow->m_arrItems[j]);
}
INT nColCurrent = 1;
bool bIsWriteCell = false; // Нужно только для записи JSON-а
for (size_t j = 0; j < pRow->m_arrItems.size(); ++j)
{
INT nRowTmp = 0;
INT nCol = 0;
OOX::Spreadsheet::CCell *pCell = pRow->m_arrItems[j];
if (pCell->isInitRef())
{
pCell->getRowCol(nRowTmp, nCol);
nRowTmp++;
nCol++;
}
else
{
nCol = 0 == j ? nColCurrent : nColCurrent + 1;
}
while (nCol > nColCurrent)
{
if (bJSON && false == bIsWriteCell)
{
// Запишем пустые строки (для JSON-а)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDoubleQuote, nCodePage);
}
// Write delimiter
++nColCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDelimiter, nCodePage);
bIsWriteCell = false;
}
// Get cell value
std::wstring sCellValue = _T("");
if (pCell->m_oValue.IsInit())
{
if (pCell->m_oType.IsInit() && SimpleTypes::Spreadsheet::celltypeNumber != pCell->m_oType->GetValue())
{
if(SimpleTypes::Spreadsheet::celltypeStr == pCell->m_oType->GetValue())
{
sCellValue = pCell->m_oValue->ToString();
}
else
{
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
if (nValue >= 0 && nValue < oXlsx.m_pSharedStrings->m_arrItems.size())
{
OOX::Spreadsheet::CSi *pSi = oXlsx.m_pSharedStrings->m_arrItems[nValue];
if(NULL != pSi)
{
sCellValue = pSi->ToString();
}
}
}
}
else
{
sCellValue = pCell->m_oValue->ToString();
}
}
// Escape cell value
if(bJSON)
{
NSStringUtils::CStringBuilder oBuilder;
oBuilder.WriteString(_T("\""));
escapeJson(sCellValue, oBuilder);
oBuilder.WriteString(_T("\""));
sCellValue = std::wstring(oBuilder.GetBuffer(), oBuilder.GetCurSize());
}
else if (std::wstring::npos != sCellValue.find_first_of(sEscape))
{
NSStringExt::Replace(sCellValue, sQuote, sDoubleQuote);
sCellValue = sQuote + sCellValue + sQuote;
}
// Write cell value
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sCellValue, nCodePage);
bIsWriteCell = true;
}
if (bJSON)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
}
if (bJSON)
{
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage, true);
oWriter.WriteRowEnd(pRow);
}
oWriter.WriteSheetEnd(pWorksheet);
}
}
}
oWriter.End();
}
CCSVWriter::CCSVWriter(OOX::Spreadsheet::CXlsx &m_oXlsx, UINT m_nCodePage, const std::wstring& m_sDelimiter, bool m_bJSON): m_oXlsx(m_oXlsx), m_nCodePage(m_nCodePage), m_sDelimiter(m_sDelimiter), m_bJSON(m_bJSON)
{
m_pWriteBuffer = NULL;
m_nCurrentIndex = 0;
m_sEscape = _T("\"\n");
m_sEscape += m_sDelimiter;
m_nRowCurrent = 1;
m_nColCurrent = 1;
m_bIsWriteCell = false;
bool m_bStartRow = true;
bool m_bStartCell = true;
}
CCSVWriter::~CCSVWriter()
{
Close();
}
void CCSVWriter::Start(const std::wstring &sFileDst)
{
m_oFile.CreateFileW(sFileDst);
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
if (!bJSON)
// Нужно записать шапку
if (46 == m_nCodePage)//todo 46 временно CP_UTF8
{
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, true);
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
m_oFile.WriteFile(arUTF8, 3);
}
RELEASEARRAYOBJECTS(pWriteBuffer);
oFile.CloseFile();
else if (48 == m_nCodePage)//todo 48 временно CP_UTF16
{
BYTE arUTF16[2] = {0xFF, 0xFE};
m_oFile.WriteFile(arUTF16, 2);
}
else if (49 == m_nCodePage)//todo 49 временно CP_unicodeFFFE
{
BYTE arBigEndian[2] = {0xFE, 0xFF};
m_oFile.WriteFile(arBigEndian, 2);
}
}
void CCSVWriter::WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet)
{
m_nRowCurrent = 1;
if (m_bJSON)
CSVWriter::WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sBkt, m_nCodePage);
}
void CCSVWriter::WriteRowStart(OOX::Spreadsheet::CRow *pRow)
{
INT nRow = pRow->m_oR.IsInit() ? pRow->m_oR->GetValue() : m_bStartRow ? m_nRowCurrent : m_nRowCurrent + 1;
if (m_bJSON)
CSVWriter::WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, (m_bStartRow ? g_sBkt: g_sBktComma), m_nCodePage);
else
{
while (nRow > m_nRowCurrent)
{
// Write new line
++m_nRowCurrent;
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage);
}
}
m_bStartRow = false;
m_bStartCell = true;
m_nColCurrent = 1;
m_bIsWriteCell = false;
}
void CCSVWriter::WriteCell(OOX::Spreadsheet::CCell *pCell)
{
INT nRowTmp = 0;
INT nCol = 0;
if (pCell->isInitRef())
{
pCell->getRowCol(nRowTmp, nCol);
nRowTmp++;
nCol++;
}
else
{
nCol = m_bStartCell ? m_nColCurrent : m_nColCurrent + 1;
}
while (nCol > m_nColCurrent)
{
if (m_bJSON && false == m_bIsWriteCell)
{
// Запишем пустые строки (для JSON-а)
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sDoubleQuote, m_nCodePage);
}
// Write delimiter
++m_nColCurrent;
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, m_sDelimiter, m_nCodePage);
m_bIsWriteCell = false;
}
// Get cell value
std::wstring sCellValue = _T("");
if (pCell->m_oValue.IsInit())
{
if (pCell->m_oType.IsInit() && SimpleTypes::Spreadsheet::celltypeNumber != pCell->m_oType->GetValue())
{
if(SimpleTypes::Spreadsheet::celltypeStr == pCell->m_oType->GetValue())
{
sCellValue = pCell->m_oValue->ToString();
}
else
{
int nValue = _wtoi(pCell->m_oValue->ToString().c_str());
if (nValue >= 0 && nValue < m_oXlsx.m_pSharedStrings->m_arrItems.size())
{
OOX::Spreadsheet::CSi *pSi = m_oXlsx.m_pSharedStrings->m_arrItems[nValue];
if(NULL != pSi)
{
sCellValue = pSi->ToString();
}
}
}
}
else
{
sCellValue = pCell->m_oValue->ToString();
}
}
// Escape cell value
if(m_bJSON)
{
NSStringUtils::CStringBuilder oBuilder;
oBuilder.WriteString(_T("\""));
escapeJson(sCellValue, oBuilder);
oBuilder.WriteString(_T("\""));
sCellValue = std::wstring(oBuilder.GetBuffer(), oBuilder.GetCurSize());
}
else if (std::wstring::npos != sCellValue.find_first_of(m_sEscape))
{
NSStringExt::Replace(sCellValue, g_sQuote, g_sDoubleQuote);
sCellValue = g_sQuote + sCellValue + g_sQuote;
}
// Write cell value
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, sCellValue, m_nCodePage);
m_bIsWriteCell = true;
m_bStartCell = false;
}
void CCSVWriter::WriteRowEnd(OOX::Spreadsheet::CRow* pWorksheet)
{
if (m_bJSON)
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage);
}
void CCSVWriter::WriteSheetEnd(OOX::Spreadsheet::CWorksheet* pWorksheet)
{
if (m_bJSON)
{
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage);
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sEndJson, m_nCodePage, true);
}
}
void CCSVWriter::End()
{
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
if (!m_bJSON)
{
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage);
WriteFile(&m_oFile, &m_pWriteBuffer, m_nCurrentIndex, g_sNewLineN, m_nCodePage, true);
}
Close();
}
void CCSVWriter::Close()
{
RELEASEARRAYOBJECTS(m_pWriteBuffer);
m_oFile.CloseFile();
}
}

View File

@ -35,9 +35,45 @@
#include "../../DesktopEditor/common/File.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
namespace OOX
{
namespace Spreadsheet
{
class CRow;
class CCell;
}
}
namespace CSVWriter
{
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, const std::wstring &sWriteString, UINT &nCodePage, bool bIsEnd = false);
class CCSVWriter
{
protected:
NSFile::CFileBinary m_oFile;
OOX::Spreadsheet::CXlsx& m_oXlsx;
UINT m_nCodePage;
const std::wstring& m_sDelimiter;
bool m_bJSON;
WCHAR* m_pWriteBuffer;
INT m_nCurrentIndex;
std::wstring m_sEscape;
INT m_nRowCurrent;
INT m_nColCurrent;
bool m_bIsWriteCell; // Нужно только для записи JSON-а
bool m_bStartRow;
bool m_bStartCell;
public:
CCSVWriter(OOX::Spreadsheet::CXlsx &oXlsx, UINT m_nCodePage, const std::wstring& sDelimiter, bool m_bJSON);
~CCSVWriter();
void Start(const std::wstring &sFileDst);
void WriteSheetStart(OOX::Spreadsheet::CWorksheet* pWorksheet);
void WriteRowStart(OOX::Spreadsheet::CRow *pRow);
void WriteCell(OOX::Spreadsheet::CCell *pCell);
void WriteRowEnd(OOX::Spreadsheet::CRow* pWorksheet);
void WriteSheetEnd(OOX::Spreadsheet::CWorksheet* pWorksheet);
void End();
void Close();
};
void WriteFromXlsxToCsv(const std::wstring &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const std::wstring& wcDelimiter, bool bJSON);
}