Commit 47db6f1a authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

OdfFileReader. Сделаны гиперлинки в сносках.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62990 954022d7-b5bf-4e40-9824-e11837661b57
parent 3d8d8777
...@@ -165,7 +165,12 @@ void docx_conversion_context::add_new_run() ...@@ -165,7 +165,12 @@ void docx_conversion_context::add_new_run()
std::wstring docx_conversion_context::add_hyperlink(const std::wstring & href, bool draw) std::wstring docx_conversion_context::add_hyperlink(const std::wstring & href, bool draw)
{ {
return hyperlinks_.add(href,draw); hyperlinks::_type_place type = hyperlinks::document_place;
if (process_note_ == footNote || process_note_ == footNoteRefSet) type = hyperlinks::footnote_place;
else if (process_note_ == endNote || process_note_ == endNoteRefSet ) type = hyperlinks::endnote_place;
return hyperlinks_.add(href, type, draw);
} }
hyperlinks::_ref docx_conversion_context::last_hyperlink() hyperlinks::_ref docx_conversion_context::last_hyperlink()
{ {
...@@ -173,9 +178,9 @@ hyperlinks::_ref docx_conversion_context::last_hyperlink() ...@@ -173,9 +178,9 @@ hyperlinks::_ref docx_conversion_context::last_hyperlink()
} }
void docx_conversion_context::dump_hyperlinks(rels & Rels) void docx_conversion_context::dump_hyperlinks(rels & Rels, hyperlinks::_type_place type)
{ {
hyperlinks_.dump_rels(Rels); hyperlinks_.dump_rels(Rels, type);
} }
void docx_conversion_context::dump_mediaitems(rels & Rels) void docx_conversion_context::dump_mediaitems(rels & Rels)
...@@ -234,10 +239,14 @@ void docx_conversion_context::end_document() ...@@ -234,10 +239,14 @@ void docx_conversion_context::end_document()
output_document_->get_word_files().set_media( mediaitems_, applicationFonts_); output_document_->get_word_files().set_media( mediaitems_, applicationFonts_);
output_document_->get_word_files().set_headers_footers(headers_footers_); output_document_->get_word_files().set_headers_footers(headers_footers_);
output_document_->get_word_files().set_notes(notes_context_);
output_document_->get_word_files().set_comments(comments_context_); output_document_->get_word_files().set_comments(comments_context_);
output_document_->get_word_files().set_settings(package::simple_element::create(L"settings.xml",dump_settings_document())); output_document_->get_word_files().set_settings(package::simple_element::create(L"settings.xml",dump_settings_document()));
////////////////////////////////////////////////////////////////////////////
dump_hyperlinks (notes_context_.footnotesRels(), hyperlinks::footnote_place);
dump_hyperlinks (notes_context_.endnotesRels(), hyperlinks::endnote_place);
output_document_->get_word_files().set_notes(notes_context_);
//////////////////////// ////////////////////////
int count = 0; int count = 0;
BOOST_FOREACH(const oox_chart_context_ptr& chart, charts_) BOOST_FOREACH(const oox_chart_context_ptr& chart, charts_)
...@@ -836,7 +845,8 @@ namespace ...@@ -836,7 +845,8 @@ namespace
rels internal_rels; rels internal_rels;
Context.dump_mediaitems(internal_rels); Context.dump_mediaitems(internal_rels);
Context.dump_hyperlinks(internal_rels); Context.dump_hyperlinks(internal_rels, hyperlinks::document_place);
Context.get_headers_footers().add(styleName, dbgStr, type, internal_rels); Context.get_headers_footers().add(styleName, dbgStr, type, internal_rels);
if (type == headers_footers::headerLeft || type == headers_footers::footerLeft) if (type == headers_footers::headerLeft || type == headers_footers::footerLeft)
...@@ -922,12 +932,12 @@ void notes_context::dump_rels(rels & Rels) const ...@@ -922,12 +932,12 @@ void notes_context::dump_rels(rels & Rels) const
void docx_conversion_context::add_note_reference() void docx_conversion_context::add_note_reference()
{ {
if (process_note_ != noNote) if (process_note_ == footNote || process_note_ == endNote)
{ {
add_element_to_run(); add_element_to_run();
output_stream() << ((process_note_ == footNote) ? L"<w:footnoteRef />" : L"<w:endnoteRef />"); output_stream() << ((process_note_ == footNote) ? L"<w:footnoteRef />" : L"<w:endnoteRef />");
finish_run(); finish_run();
process_note_ = noNote; process_note_ = (NoteType) (process_note_ + 1); //add ref set
} }
} }
......
...@@ -289,7 +289,7 @@ public: ...@@ -289,7 +289,7 @@ public:
} }
const odf_reader::text::note_citation * get_note_citation() const { return note_citation_; } const odf_reader::text::note_citation * get_note_citation() const { return note_citation_; }
const odf_types::noteclass::type get_type() const {return type_; } const odf_types::noteclass::type get_type() const {return type_; }
struct instance struct instance
{ {
...@@ -297,18 +297,24 @@ public: ...@@ -297,18 +297,24 @@ public:
std::wstring id; std::wstring id;
std::wstring content; std::wstring content;
}; };
typedef boost::shared_ptr<instance> instance_ptr; typedef boost::shared_ptr<instance> instance_ptr;
typedef boost::unordered_map<std::wstring, instance_ptr> instances_map; typedef boost::unordered_map<std::wstring, instance_ptr> instances_map;
instances_map & footnotes() { return instances_footnotes_; } instances_map & footnotes() { return instances_footnotes_; }
instances_map & endnotes() { return instances_endnotes_; } instances_map & endnotes() { return instances_endnotes_; }
void dump_rels(rels & Rels) const; rels & endnotesRels() { return endnoteRels; }
rels & footnotesRels() { return footnoteRels; }
void dump_rels(rels & Rels) const;
private: private:
instances_map instances_footnotes_; instances_map instances_footnotes_;
instances_map instances_endnotes_; instances_map instances_endnotes_;
rels endnoteRels;
rels footnoteRels;
const odf_reader::text::note_citation * note_citation_; const odf_reader::text::note_citation * note_citation_;
odf_types::noteclass::type type_; odf_types::noteclass::type type_;
...@@ -380,9 +386,9 @@ public: ...@@ -380,9 +386,9 @@ public:
bool get_paragraph_state() { return in_paragraph_; } bool get_paragraph_state() { return in_paragraph_; }
void set_paragraph_state(bool Val) {in_paragraph_= Val; } void set_paragraph_state(bool Val) {in_paragraph_= Val; }
std::wstring add_hyperlink(const std::wstring & href,bool drawing); std::wstring add_hyperlink (const std::wstring & href, bool drawing);
hyperlinks::_ref last_hyperlink(); hyperlinks::_ref last_hyperlink ();
void dump_hyperlinks(rels & Rels); void dump_hyperlinks (rels & Rels, hyperlinks::_type_place type);
std::wstring add_mediaitem(const std::wstring & uri, mediaitems::Type type, bool & isInternal, std::wstring & ref); std::wstring add_mediaitem(const std::wstring & uri, mediaitems::Type type, bool & isInternal, std::wstring & ref);
...@@ -481,7 +487,9 @@ public: ...@@ -481,7 +487,9 @@ public:
bool rtl() const {return rtl_;} bool rtl() const {return rtl_;}
notes_context & get_notes_context() { return notes_context_; } notes_context & get_notes_context() { return notes_context_; }
enum NoteType { noNote, footNote, endNote };
enum NoteType { noNote, footNote, footNoteRefSet, endNote, endNoteRefSet };
void set_process_note(NoteType Val) { process_note_ = Val; } void set_process_note(NoteType Val) { process_note_ = Val; }
NoteType get_process_note() const { return process_note_; } NoteType get_process_note() const { return process_note_; }
void add_note_reference(); void add_note_reference();
......
...@@ -75,10 +75,6 @@ void word_files::write(const std::wstring & RootPath) ...@@ -75,10 +75,6 @@ void word_files::write(const std::wstring & RootPath)
headers_footers_->write( path ); headers_footers_->write( path );
} }
if (notes_)
{
notes_->write( path );
}
if (settings_) if (settings_)
{ {
rels_files_.add( relationship(L"rId4", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", L"settings.xml" ) ); rels_files_.add( relationship(L"rId4", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", L"settings.xml" ) );
...@@ -95,12 +91,17 @@ void word_files::write(const std::wstring & RootPath) ...@@ -95,12 +91,17 @@ void word_files::write(const std::wstring & RootPath)
charts_files_.set_main_document(get_main_document()); charts_files_.set_main_document(get_main_document());
charts_files_.write(path); charts_files_.write(path);
} }
if (notes_)
{
notes_->write( path );
}
rels_files_.write(path); rels_files_.write(path);
} }
void word_files::update_rels(docx_conversion_context & Context) void word_files::update_rels(docx_conversion_context & Context)
{ {
Context.dump_hyperlinks (rels_files_.get_rel_file()->get_rels()); Context.dump_hyperlinks (rels_files_.get_rel_file()->get_rels(), hyperlinks::document_place);
Context.dump_mediaitems (rels_files_.get_rel_file()->get_rels()); Context.dump_mediaitems (rels_files_.get_rel_file()->get_rels());
Context.dump_headers_footers(rels_files_.get_rel_file()->get_rels()); Context.dump_headers_footers(rels_files_.get_rel_file()->get_rels());
Context.dump_notes (rels_files_.get_rel_file()->get_rels()); Context.dump_notes (rels_files_.get_rel_file()->get_rels());
...@@ -239,38 +240,67 @@ notes_elements::notes_elements(notes_context & notesContext) : notes_context_(no ...@@ -239,38 +240,67 @@ notes_elements::notes_elements(notes_context & notesContext) : notes_context_(no
namespace namespace
{ {
void process_notes(const notes_context::instances_map & Instances, void process_notes(const notes_context::instances_map & Instances,
const std::wstring & Node, const std::wstring & Node,
const std::wstring & Name, const std::wstring & Name,
const std::wstring & ContentType, const std::wstring & ContentType,
const std::wstring & RootPath, const std::wstring & RootPath,
document * doc rels & Rels,
) document * doc
{ )
if (Instances.size()) {
{ if (Instances.size())
std::wstringstream content; {
std::wstringstream content;
// ! L"s -
content << L"<w:" << Node << L"s xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " << // ! L"s -
L"xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" " << content << L"<w:" << Node << L"s \
L"xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" " << xmlns:o=\"urn:schemas-microsoft-com:office:office\" \
L">"; xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" \
xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" \
xmlns:w10=\"urn:schemas-microsoft-com:office:word\" \
xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" \
xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" \
xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" \
xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" \
xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" \
xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" \
xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" \
xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" \
xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" \
xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" \
xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" >";
//mc:Ignorable=\"w14 wp14\"
//xmlns:v=\"urn:schemas-microsoft-com:vml\"
BOOST_FOREACH(const notes_context::instances_map::value_type & elm, Instances)
{
content << L"<w:" << Node << L" w:id=\"" << elm.second->id << L"\">";
content << elm.second->content;
content << L"</w:" << Node << L">";
}
content << L"</w:" << Node << L"s>";
BOOST_FOREACH(const notes_context::instances_map::value_type & elm, Instances) simple_element(Name, content.str()).write(RootPath);
{
content << L"<w:" << Node << L" w:id=\"" << elm.second->id << L"\">"; if (doc)
content << elm.second->content; doc->content_type().get_content_type().add_override(std::wstring(L"/word/") + Name, ContentType);
content << L"</w:" << Node << L">";
}
content << L"</w:" << Node << L"s>";
simple_element(Name, content.str()).write(RootPath); if (Rels.relationships().size() > 0)
{
if (doc) rels_files relFiles;
doc->content_type().get_content_type().add_override(std::wstring(L"/word/") + Name, ContentType); rels_file_ptr rels_elem = rels_file::create( Node + L"s.xml.rels");
} relFiles.add_rel_file(rels_elem);
}
BOOST_FOREACH(relationship & r, Rels.relationships())
{
relFiles.add(r);
}
relFiles.write(RootPath);
}
}
}
} }
void notes_elements::write(const std::wstring & RootPath) void notes_elements::write(const std::wstring & RootPath)
...@@ -280,6 +310,7 @@ void notes_elements::write(const std::wstring & RootPath) ...@@ -280,6 +310,7 @@ void notes_elements::write(const std::wstring & RootPath)
L"footnotes.xml", L"footnotes.xml",
L"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml",
RootPath, RootPath,
notes_context_.footnotesRels(),
get_main_document()); get_main_document());
process_notes(notes_context_.endnotes(), process_notes(notes_context_.endnotes(),
...@@ -287,6 +318,7 @@ void notes_elements::write(const std::wstring & RootPath) ...@@ -287,6 +318,7 @@ void notes_elements::write(const std::wstring & RootPath)
L"endnotes.xml", L"endnotes.xml",
L"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", L"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml",
RootPath, RootPath,
notes_context_.endnotesRels(),
get_main_document()); get_main_document());
} }
......
...@@ -108,8 +108,8 @@ public: ...@@ -108,8 +108,8 @@ public:
void add_charts(chart_content_ptr chart); void add_charts(chart_content_ptr chart);
private: private:
docx_charts_files charts_files_; docx_charts_files charts_files_;
rels_files rels_files_; rels_files rels_files_;
element_ptr theme_; element_ptr theme_;
element_ptr document_; element_ptr document_;
......
...@@ -19,26 +19,30 @@ hyperlinks::_ref hyperlinks::last() ...@@ -19,26 +19,30 @@ hyperlinks::_ref hyperlinks::last()
return r; return r;
} }
std::wstring hyperlinks::add(const std::wstring & href,bool draw) std::wstring hyperlinks::add(const std::wstring & href, _type_place type_place, bool drawing)
{ {
std::wstring id = std::wstring(L"rHpId") + boost::lexical_cast<std::wstring>(hrefs_.size()+1); std::wstring id = std::wstring(L"rHpId") + boost::lexical_cast<std::wstring>(hrefs_.size()+1);
_ref r ={xml::utils::replace_text_to_xml(href),draw,id,false}; _ref r ={xml::utils::replace_text_to_xml(href), type_place, drawing, id, false};
hrefs_.push_back(r); hrefs_.push_back(r);
// .. (, )
return id; return id;
} }
void hyperlinks::dump_rels(rels & Rels) void hyperlinks::dump_rels(rels & Rels, _type_place type)
{ {
size_t i = 0; size_t i = 0;
BOOST_FOREACH(_ref & elm, hrefs_) BOOST_FOREACH(_ref & elm, hrefs_)
{ {
if (elm.used_rels)continue; // ( ....) if (elm.used_rels)continue; //
Rels.add( relationship(elm.id, L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", elm.href, L"External" ) );
elm.used_rels = true; if (elm.type_place == type)
{
Rels.add( relationship(elm.id, L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", elm.href, L"External" ) );
elm.used_rels = true;
}
} }
} }
......
...@@ -11,19 +11,28 @@ class rels; ...@@ -11,19 +11,28 @@ class rels;
class hyperlinks class hyperlinks
{ {
public: public:
enum _type_place
{
document_place,
endnote_place,
footnote_place
};
struct _ref struct _ref
{ {
std::wstring href; std::wstring href;
bool drawing; _type_place type_place;
std::wstring id; bool drawing;
bool used_rels; std::wstring id;
bool used_rels;
}; };
std::wstring add(const std::wstring & href, bool drawing); std::wstring add(const std::wstring & href, _type_place type_place, bool drawing);
_ref last(); _ref last();
void dump_rels(rels & Rels); void dump_rels(rels & Rels, _type_place type);
private: private:
......
...@@ -987,7 +987,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context) ...@@ -987,7 +987,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
// - // -
if (hyperlink.drawing == true && hyperlink.used_rels == false) if (hyperlink.drawing == true && hyperlink.used_rels == false)
{ {
oox::_hlink_desc desc={hyperlink.id,hyperlink.href,true}; oox::_hlink_desc desc = {hyperlink.id, hyperlink.href, true};
drawing.hlinks.push_back(desc); drawing.hlinks.push_back(desc);
} }
......
...@@ -116,9 +116,9 @@ void office_annotation::docx_convert(oox::docx_conversion_context & Context) ...@@ -116,9 +116,9 @@ void office_annotation::docx_convert(oox::docx_conversion_context & Context)
Context.set_run_state(runState); Context.set_run_state(runState);
Context.set_paragraph_state(pState); 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);//content, date, author
Context.dump_hyperlinks(Context.get_comments_context().get_rels()); Context.dump_hyperlinks(Context.get_comments_context().get_rels(), oox::hyperlinks::document_place);
Context.set_stream_man(prev); Context.set_stream_man(prev);
} }
......
...@@ -59,7 +59,10 @@ void text::docx_convert(oox::docx_conversion_context & Context) ...@@ -59,7 +59,10 @@ void text::docx_convert(oox::docx_conversion_context & Context)
Context.add_element_to_run(); Context.add_element_to_run();
std::wostream & _Wostream = Context.output_stream(); std::wostream & _Wostream = Context.output_stream();
_Wostream << L"<w:t xml:space=\"preserve\">"; if (preserve_)
_Wostream << L"<w:t xml:space=\"preserve\">";
else
_Wostream << L"<w:t>";
_Wostream << xml::utils::replace_text_to_xml( text_ ); _Wostream << xml::utils::replace_text_to_xml( text_ );
_Wostream << L"</w:t>"; _Wostream << L"</w:t>";
...@@ -761,7 +764,11 @@ void text_page_number::add_child_element( xml::sax * Reader, const ::std::wstrin ...@@ -761,7 +764,11 @@ void text_page_number::add_child_element( xml::sax * Reader, const ::std::wstrin
void text_page_number::add_text(const std::wstring & Text) void text_page_number::add_text(const std::wstring & Text)
{ {
office_element_ptr elm = text::create(Text) ; office_element_ptr elm = text::create(Text) ;
text_.push_back( elm );
text *t = dynamic_cast<text*>(elm.get());
if (t) t->preserve_ = false;
text_.push_back( elm );
} }
void text_page_number::docx_convert(oox::docx_conversion_context & Context) void text_page_number::docx_convert(oox::docx_conversion_context & Context)
......
...@@ -55,8 +55,9 @@ public: ...@@ -55,8 +55,9 @@ public:
virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const; virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const;
public: public:
text(const ::std::wstring & Text) : text_(Text) {}; bool preserve_;
text() {}; text(const ::std::wstring & Text) : text_(Text) {preserve_ = true;};
text() {preserve_ = true;};
std::wstring & attr_text() { return text_; }; std::wstring & attr_text() { return text_; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment