mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
OdfFileReader. расширение конвертации.
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63041 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
committed by
Alexander Trofimov
parent
c55c668ee4
commit
b067d43c35
@ -9,16 +9,16 @@ namespace oox {
|
||||
|
||||
void conversion_element::docx_convert(docx_conversion_context & Context)
|
||||
{
|
||||
//_CP_LOG << L"[warning] empty conversion_element::docx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
_CP_LOG << L"[warning] empty conversion_element::docx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
}
|
||||
|
||||
void conversion_element::xlsx_convert(xlsx_conversion_context & Context)
|
||||
{
|
||||
//_CP_LOG << L"[warning] empty conversion_element::xlsx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
_CP_LOG << L"[warning] empty conversion_element::xlsx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
}
|
||||
void conversion_element::pptx_convert(pptx_conversion_context & Context)
|
||||
{
|
||||
// _CP_LOG << L"[warning] empty conversion_element::pptx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
_CP_LOG << L"[warning] empty conversion_element::pptx_convert: \"" << typeid(*this).name() << L"\"\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,14 @@
|
||||
namespace cpdoccore {
|
||||
namespace oox {
|
||||
|
||||
void removeCharsFromString( std::wstring &str, std::wstring charsToRemove )
|
||||
{
|
||||
for ( unsigned int i = 0; i < charsToRemove.length(); ++i )
|
||||
{
|
||||
str.erase( std::remove(str.begin(), str.end(), charsToRemove[i]), str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
class xlsx_text_context::Impl: boost::noncopyable
|
||||
{
|
||||
public:
|
||||
@ -219,7 +227,13 @@ void xlsx_text_context::Impl::write_rPr(std::wostream & strm)
|
||||
|
||||
_CP_OPT(std::wstring) sValFontFamily;
|
||||
if (text_properties_.fo_font_family_)
|
||||
{
|
||||
std::wstring val =text_properties_.fo_font_family_.get();
|
||||
//'Arial' глючит
|
||||
removeCharsFromString(val, _T("'"));
|
||||
|
||||
sValFontFamily=text_properties_.fo_font_family_.get();
|
||||
}
|
||||
//else if (text_properties_.style_font_name_) - тут может быть отсылка к font_face)decl !!!!
|
||||
// sValFontFamily=text_properties_.style_font_name_.get();
|
||||
|
||||
@ -247,7 +261,7 @@ void xlsx_text_context::Impl::write_rPr(std::wostream & strm)
|
||||
if (dValFontSize) {CP_XML_ATTR(L"sz", (int)(dValFontSize.get()*100));}
|
||||
if ((iValFontStyle) && (iValFontStyle.get() >0)) {CP_XML_ATTR(L"i", "1");} //"true");} Exercícios de Aprendizagem.ods
|
||||
if ((iValFontWeight) && (iValFontWeight.get() >0)) {CP_XML_ATTR(L"b", "1");} //"true");} Exercícios de Aprendizagem.ods
|
||||
if (sValFontFamily) {CP_XML_ATTR(L"typeface", sValFontFamily.get());} //'Arial' глючит
|
||||
if (sValFontFamily) {CP_XML_ATTR(L"typeface", sValFontFamily.get());}
|
||||
|
||||
if (sValFontColor){CP_XML_NODE(L"a:solidFill") {CP_XML_NODE(L"a:srgbClr"){CP_XML_ATTR(L"val", sValFontColor.get());}}}
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ enum ElementType
|
||||
typeTextRubyText,
|
||||
typeTextOfficeAnnotation,
|
||||
typeTextTitle,
|
||||
typeTextChapter,
|
||||
typeTextPlaceholder,
|
||||
typeTextPageNumber,
|
||||
typeTextPageCount,
|
||||
|
||||
@ -284,7 +284,6 @@ const wchar_t * span::name = L"span";
|
||||
|
||||
::std::wostream & span::text_to_stream(::std::wostream & _Wostream) const
|
||||
{
|
||||
// TODO!!!!
|
||||
BOOST_FOREACH(const office_element_ptr & parElement, paragraph_content_)
|
||||
{
|
||||
parElement->text_to_stream(_Wostream);
|
||||
@ -323,7 +322,6 @@ void span::add_text(const std::wstring & Text)
|
||||
|
||||
void span::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
|
||||
bool addNewRun = false;
|
||||
bool pushed = false;
|
||||
|
||||
@ -671,8 +669,12 @@ void common_field_fixed_attlist::add_attributes( const xml::attributes_wc_ptr &
|
||||
const wchar_t * title::ns = L"text";
|
||||
const wchar_t * title::name = L"title";
|
||||
|
||||
::std::wostream & title::text_to_stream(::std::wostream & _Wostream) const
|
||||
std::wostream & title::text_to_stream(::std::wostream & _Wostream) const
|
||||
{
|
||||
BOOST_FOREACH(const office_element_ptr & parElement, content_)
|
||||
{
|
||||
parElement->text_to_stream(_Wostream);
|
||||
}
|
||||
return _Wostream;
|
||||
}
|
||||
|
||||
@ -683,6 +685,7 @@ void title::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
|
||||
void title::add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
|
||||
void title::add_text(const std::wstring & Text)
|
||||
@ -690,6 +693,93 @@ void title::add_text(const std::wstring & Text)
|
||||
office_element_ptr elm = text::create(Text) ;
|
||||
content_.push_back( elm );
|
||||
}
|
||||
void title::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
std::wostream & strm = Context.output_stream();
|
||||
Context.finish_run();
|
||||
strm << L"<w:r><w:fldChar w:fldCharType=\"begin\" /></w:r>";
|
||||
strm << L"<w:r><w:instrText>TITLE</w:instrText></w:r><w:r><w:fldChar w:fldCharType=\"separate\" /></w:r>";
|
||||
Context.add_new_run();
|
||||
|
||||
std::wostream & _Wostream = Context.output_stream();
|
||||
_Wostream << L"<w:t xml:space=\"preserve\">";
|
||||
this->text_to_stream(_Wostream);
|
||||
_Wostream << L"</w:t>";
|
||||
|
||||
Context.finish_run();
|
||||
strm << L"<w:r><w:fldChar w:fldCharType=\"end\" /></w:r>";
|
||||
}
|
||||
|
||||
void title::xlsx_convert(oox::xlsx_conversion_context & Context)
|
||||
{
|
||||
std::wstringstream val;
|
||||
this->text_to_stream(val);
|
||||
Context.get_text_context().add_text(val.str());
|
||||
}
|
||||
void title::pptx_convert(oox::pptx_conversion_context & Context)
|
||||
{
|
||||
std::wstringstream val;
|
||||
this->text_to_stream(val);
|
||||
Context.get_text_context().add_text(val.str());
|
||||
}
|
||||
// text:chapter
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * chapter::ns = L"text";
|
||||
const wchar_t * chapter::name = L"chapter";
|
||||
|
||||
std::wostream & chapter::text_to_stream(::std::wostream & _Wostream) const
|
||||
{
|
||||
BOOST_FOREACH(const office_element_ptr & parElement, content_)
|
||||
{
|
||||
parElement->text_to_stream(_Wostream);
|
||||
}
|
||||
return _Wostream;
|
||||
}
|
||||
|
||||
void chapter::add_attributes( const xml::attributes_wc_ptr & Attributes )
|
||||
{
|
||||
common_field_fixed_attlist_.add_attributes(Attributes);
|
||||
}
|
||||
|
||||
void chapter::add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
|
||||
void chapter::add_text(const std::wstring & Text)
|
||||
{
|
||||
office_element_ptr elm = text::create(Text) ;
|
||||
content_.push_back( elm );
|
||||
}
|
||||
void chapter::docx_convert(oox::docx_conversion_context & Context)
|
||||
{
|
||||
std::wostream & strm = Context.output_stream();
|
||||
Context.finish_run();
|
||||
//strm << L"<w:r><w:fldChar w:fldCharType=\"begin\" /></w:r>";
|
||||
//strm << L"<w:r><w:instrText>BIBLIOGRAPHY</w:instrText></w:r><w:r><w:fldChar w:fldCharType=\"separate\" /></w:r>";
|
||||
Context.add_new_run();
|
||||
|
||||
std::wostream & _Wostream = Context.output_stream();
|
||||
_Wostream << L"<w:t xml:space=\"preserve\">";
|
||||
this->text_to_stream(_Wostream);
|
||||
_Wostream << L"</w:t>";
|
||||
|
||||
Context.finish_run();
|
||||
//strm << L"<w:r><w:fldChar w:fldCharType=\"end\" /></w:r>";
|
||||
}
|
||||
|
||||
void chapter::xlsx_convert(oox::xlsx_conversion_context & Context)
|
||||
{
|
||||
std::wstringstream val;
|
||||
this->text_to_stream(val);
|
||||
Context.get_text_context().add_text(val.str());
|
||||
}
|
||||
void chapter::pptx_convert(oox::pptx_conversion_context & Context)
|
||||
{
|
||||
std::wstringstream val;
|
||||
this->text_to_stream(val);
|
||||
Context.get_text_context().add_text(val.str());
|
||||
}
|
||||
|
||||
// text:placeholder
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -449,13 +449,10 @@ public:
|
||||
static const ElementType type = typeTextNote;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
public:
|
||||
void docx_convert(oox::docx_conversion_context & Context);
|
||||
void pptx_convert(oox::pptx_conversion_context & Context);
|
||||
|
||||
public:
|
||||
virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const;
|
||||
public:
|
||||
note();
|
||||
|
||||
private:
|
||||
@ -463,7 +460,6 @@ 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);
|
||||
|
||||
private:
|
||||
std::wstring text_id_;
|
||||
odf_types::noteclass text_note_class_;
|
||||
office_element_ptr text_note_citation_;
|
||||
@ -485,14 +481,12 @@ public:
|
||||
static const ElementType type = typeTextRuby;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
public:
|
||||
virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const;
|
||||
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);
|
||||
virtual void add_text(const std::wstring & Text);
|
||||
|
||||
private:
|
||||
odf_types::style_ref text_style_name_;
|
||||
office_element_ptr text_ruby_base_;
|
||||
office_element_ptr text_ruby_text_;
|
||||
@ -523,14 +517,17 @@ public:
|
||||
static const ElementType type = typeTextTitle;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
public:
|
||||
virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const;
|
||||
|
||||
virtual void docx_convert(oox::docx_conversion_context & Context);
|
||||
virtual void xlsx_convert(oox::xlsx_conversion_context & Context);
|
||||
virtual void pptx_convert(oox::pptx_conversion_context & Context) ;
|
||||
|
||||
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);
|
||||
virtual void add_text(const std::wstring & Text);
|
||||
|
||||
private:
|
||||
common_field_fixed_attlist common_field_fixed_attlist_;
|
||||
office_element_ptr_array content_;
|
||||
|
||||
@ -538,8 +535,35 @@ private:
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(title);
|
||||
|
||||
// text:chapter
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
class chapter : public paragraph_content_element<chapter>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeTextChapter;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
virtual std::wostream & text_to_stream(::std::wostream & _Wostream) const;
|
||||
virtual void docx_convert(oox::docx_conversion_context & Context);
|
||||
virtual void xlsx_convert(oox::xlsx_conversion_context & Context);
|
||||
virtual void pptx_convert(oox::pptx_conversion_context & Context) ;
|
||||
|
||||
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);
|
||||
virtual void add_text(const std::wstring & Text);
|
||||
|
||||
common_field_fixed_attlist common_field_fixed_attlist_;
|
||||
office_element_ptr_array content_;
|
||||
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(chapter);
|
||||
|
||||
// text:placeholder
|
||||
// text-placeholder
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
class text_placeholder : public paragraph_content_element<text_placeholder>
|
||||
{
|
||||
@ -553,14 +577,12 @@ public:
|
||||
void docx_convert(oox::docx_conversion_context & Context);
|
||||
void pptx_convert(oox::pptx_conversion_context & Context);
|
||||
|
||||
public:
|
||||
virtual ::std::wostream & text_to_stream(::std::wostream & _Wostream) const;
|
||||
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);
|
||||
virtual void add_text(const std::wstring & Text);
|
||||
|
||||
private:
|
||||
office_element_ptr_array content_;
|
||||
};
|
||||
|
||||
|
||||
@ -18,7 +18,13 @@ namespace cpdoccore {
|
||||
|
||||
namespace odf_reader {
|
||||
|
||||
|
||||
void removeCharsFromString( std::wstring &str, std::wstring charsToRemove )
|
||||
{
|
||||
for ( unsigned int i = 0; i < charsToRemove.length(); ++i )
|
||||
{
|
||||
str.erase( std::remove(str.begin(), str.end(), charsToRemove[i]), str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring delete_apostroph_in_name(std::wstring value)
|
||||
{
|
||||
@ -342,13 +348,16 @@ void text_format_properties_content::pptx_convert_as_list(oox::pptx_conversion_c
|
||||
if (font == NULL)font = fonts.font_by_style_name(w_eastAsia);
|
||||
if (font == NULL)font = fonts.font_by_style_name(w_cs);
|
||||
if (font)w_font = font->name();
|
||||
|
||||
//'Arial' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
removeCharsFromString(w_font, _T("'"));
|
||||
}
|
||||
|
||||
if (w_font.length()>0)
|
||||
{
|
||||
CP_XML_NODE(L"a:buFont")
|
||||
{
|
||||
CP_XML_ATTR(L"typeface",w_font);
|
||||
CP_XML_ATTR(L"typeface", w_font);
|
||||
if ((style_font_charset_))
|
||||
{
|
||||
if ((*style_font_charset_!=L"x-symbol")) CP_XML_ATTR(L"charset",(*style_font_charset_));
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "odfcontext.h"
|
||||
|
||||
#include "draw_common.h"
|
||||
#include "datatypes/borderstyle.h"
|
||||
|
||||
namespace cpdoccore {
|
||||
|
||||
@ -32,6 +33,93 @@ namespace cpdoccore {
|
||||
|
||||
namespace odf_reader {
|
||||
|
||||
namespace {
|
||||
|
||||
std::wstring process_border(const border_style & borderStyle,
|
||||
const _CP_OPT(border_widths) & borderLineWidths,
|
||||
const _CP_OPT(length) & borderPadding, const std::wstring & Shadow = L"")
|
||||
{
|
||||
std::wstring w_sz;
|
||||
std::wstring w_color;
|
||||
std::wstring w_val = L"single";
|
||||
std::wstring w_space;
|
||||
|
||||
if (!borderStyle.initialized() || borderStyle.is_none())
|
||||
{
|
||||
w_val = L"none";
|
||||
}
|
||||
else if (borderStyle.initialized())
|
||||
{
|
||||
double width = borderStyle.get_length().get_value_unit(length::pt);
|
||||
//borderLineWidths ? borderLineWidths->get_summ_unit(length::pt) : borderStyle.get_length().get_value_unit(length::pt);
|
||||
int szInt = (int)(0.5 + 8.0 * width);
|
||||
if (szInt <= 0)
|
||||
szInt = 1;
|
||||
w_sz = boost::lexical_cast<std::wstring>( szInt );
|
||||
w_color = boost::lexical_cast<std::wstring>( borderStyle.get_color().get_hex_value() );
|
||||
|
||||
if (borderPadding)
|
||||
w_space = boost::lexical_cast<std::wstring>((int)(borderPadding->get_value_unit(length::pt) + 0.5) );
|
||||
|
||||
const std::wstring borderStyleStr = borderStyle.get_style();
|
||||
if (szInt == 0)
|
||||
w_val = L"none";
|
||||
else if (borderStyleStr == L"solid"
|
||||
|| borderStyleStr == L"single")
|
||||
w_val = L"single";
|
||||
else if (borderStyleStr == L"double")
|
||||
w_val = L"double";
|
||||
else if (borderStyleStr == L"dotted")
|
||||
w_val = borderStyleStr;
|
||||
else if (borderStyleStr == L"dashed")
|
||||
w_val = borderStyleStr;
|
||||
else if (borderStyleStr == L"groove")
|
||||
w_val = L"thinThickMediumGap";
|
||||
else if (borderStyleStr == L"ridge")
|
||||
w_val = L"thickThinMediumGap";
|
||||
else if (borderStyleStr == L"inset")
|
||||
w_val = L"inset";
|
||||
else if (borderStyleStr == L"outset")
|
||||
w_val = L"outset";
|
||||
else if (borderStyleStr == L"hidden")
|
||||
w_val = L"nil";
|
||||
|
||||
}
|
||||
std::wstring res;
|
||||
if (!w_val.empty())
|
||||
res += L" w:val=\"" + w_val + L"\" ";
|
||||
if (!w_sz.empty())
|
||||
res += L"w:sz=\"" + w_sz + L"\" ";
|
||||
if (!w_color.empty())
|
||||
res += L"w:color=\"" + w_color + L"\" ";
|
||||
if (!w_space.empty())
|
||||
res += L"w:space=\"" + w_space + L"\" ";
|
||||
if (!Shadow.empty())
|
||||
res += L"w:shadow=\"" + Shadow + L"\" ";
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::wstring process_margin(const _CP_OPT(length_or_percent) & margin, double Mul)
|
||||
{
|
||||
if (margin)
|
||||
{
|
||||
if (margin->get_type() == length_or_percent::Length)
|
||||
{
|
||||
int val = (int)(0.5 + Mul * margin->get_length().get_value_unit(length::pt));
|
||||
return boost::lexical_cast<std::wstring>( val );
|
||||
}
|
||||
else
|
||||
{
|
||||
_CP_LOG << L"[docx_convert] convert margin warning: invalid type (percent)\n";
|
||||
}
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
style_text_properties * style_content::get_style_text_properties() const
|
||||
{
|
||||
return dynamic_cast<style_text_properties *>(style_text_properties_.get());
|
||||
@ -908,6 +996,24 @@ void style_page_layout_properties_attlist::docx_convert_serialize(std::wostream
|
||||
strm << L"/>";
|
||||
}
|
||||
|
||||
if (common_border_attlist_.fo_border_)
|
||||
{
|
||||
odf_types::border_style style(*common_border_attlist_.fo_border_);
|
||||
|
||||
std::wstring w_shadow, w_border;
|
||||
_CP_OPT(border_widths) border_line_width;
|
||||
_CP_OPT(length) border_padding;
|
||||
|
||||
w_border = process_border(style, border_line_width , border_padding, w_shadow);
|
||||
|
||||
strm << L"<w:pgBorders>";
|
||||
strm << L"<w:top " << w_border << L"/>";
|
||||
strm << L"<w:left " << w_border << L"/>";
|
||||
strm << L"<w:bottom " << w_border << L"/>";
|
||||
strm << L"<w:right " << w_border << L"/>";
|
||||
strm << L"</w:pgBorders>";
|
||||
}
|
||||
|
||||
if (common_horizontal_margin_attlist_.fo_margin_left_ ||
|
||||
common_horizontal_margin_attlist_.fo_margin_right_ ||
|
||||
common_vertical_margin_attlist_.fo_margin_top_ ||
|
||||
|
||||
Reference in New Issue
Block a user