diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp index 25aa23521c..3dcb2724a3 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.cpp @@ -52,10 +52,72 @@ void odf_text_context::set_single_object(bool val, style_paragraph_properties *p } -void odf_text_context::add_text_content(const std::wstring & text) +void odf_text_context::add_text_content(std::wstring & text) { - if (current_level_.size() > 0 ) - current_level_.back().elm->add_text(text); + if (current_level_.size() < 1) return; + + //boost::wregex re(L"?:([ ]{2,})|(.+)");//(L"(\\w+)"); + //std::list result; + ////boost::match_results result; + ////bool b = boost::regex_match(text, result, re); + //std::wstring t = text; + //bool b = boost::regex_split(std::back_inserter(result),t, re); + + //int res; + //int sz=0; + //for (std::list::iterator i=result.begin(); i!=result.end(); ++i) + //{ + // office_element_ptr elm; + // text = *i; + // sz = text.length(); + + // if (res = text.find(L" ")) + // { + // add_text_space(sz); + // } + // else + // current_level_.back().elm->add_text(text); + //} + + //std::string expression = "1a234bc43"; + boost::wregex re(L"[ ]{2,}"); + boost::wsregex_iterator i( + text.begin (), + text.end (), + re); + boost::wsregex_iterator j; + size_t pos=0; + for(; i!=j;++i) + { + std::wstring s = text.substr(pos, (*i).position()-pos); + if (s.length() > 0)current_level_.back().elm->add_text(s); + + std::wstringstream s1; + s1 << (*i); + s= s1.str(); + if (s.length() >0) + add_text_space(s.length()); + + pos = (*i).position() + s.length(); + } + std::wstring last = text.substr(pos); + if (last.length() > 0)current_level_.back().elm->add_text(last); +} +void odf_text_context::add_text_space(int count) +{ + office_element_ptr s_elm; + create_element(L"text", L"s", s_elm, odf_context_); + + text_s* s = dynamic_cast(s_elm.get()); + if (s)s->text_c_ = count; + + //необязательно хранить.. + //int level = current_level_.size(); + //odf_element_state state={ s_elm, L"", office_element_ptr(), level}; + //text_elements_list_.push_back(state); + + if (current_level_.size()>0) + current_level_.back().elm->add_child_element(s_elm); } void odf_text_context::set_symbol_font(std::wstring & font) { diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h index 6d3ed07c4a..02cf61fc75 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/odf_text_context.h @@ -34,7 +34,10 @@ public: void add_text_style(office_element_ptr & style_elm, std::wstring style_name); void set_single_object(bool val, style_paragraph_properties *para_props, style_text_properties *text_props); - void add_text_content(const std::wstring & text); + + void add_text_content(std::wstring & text); + void add_text_space(int count); + void set_symbol_font(std::wstring & font); void set_symbol_text(int sym); diff --git a/ASCOfficeOdfFileW/source/OdfFormat/office_elements.h b/ASCOfficeOdfFileW/source/OdfFormat/office_elements.h index ee49e47cd5..a71505f420 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/office_elements.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/office_elements.h @@ -7,14 +7,12 @@ #include #include #include -//#include -//#include + #include #include "office_elements_type.h" #include "visitor.h" -//#include "..\conversionelement.h" namespace cpdoccore { namespace odf { diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp index 5379226972..c5aa6fbcbf 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp @@ -1125,15 +1125,16 @@ void DocxConverter::convert(OOX::Logic::CRunProperty *oox_run_pr, odf::style_tex { if (oox_run_pr->m_oRFonts->m_sAscii.IsInit()) text_properties->content().fo_font_family_ = string2std_string(oox_run_pr->m_oRFonts->m_sAscii.get()); + else convert(oox_run_pr->m_oRFonts->m_oAsciiTheme.GetPointer(), text_properties->content().fo_font_family_); + if (oox_run_pr->m_oRFonts->m_sCs.IsInit()) text_properties->content().style_font_family_complex_ = string2std_string(oox_run_pr->m_oRFonts->m_sCs.get()); + else convert(oox_run_pr->m_oRFonts->m_oCsTheme.GetPointer(), text_properties->content().style_font_family_complex_); + if (oox_run_pr->m_oRFonts->m_sEastAsia.IsInit()) text_properties->content().style_font_family_asian_= string2std_string(oox_run_pr->m_oRFonts->m_sEastAsia.get()); - //nullable m_sAscii; - //nullable> m_oAsciiTheme; - //nullable> m_oCsTheme; - //nullable m_sEastAsia; - //nullable> m_oEastAsiaTheme; + else convert(oox_run_pr->m_oRFonts->m_oEastAsiaTheme.GetPointer(), text_properties->content().style_font_family_asian_); + //nullable m_sHAnsi; //nullable> m_oHAnsiTheme; //nullable > m_oHint; @@ -1186,10 +1187,77 @@ void DocxConverter::convert(OOX::Logic::CRunProperty *oox_run_pr, odf::style_tex } } +void DocxConverter::convert(SimpleTypes::CTheme<>* oox_font_theme, _CP_OPT(std::wstring) & odf_font_name) +{ + if (oox_font_theme == NULL) return; + + OOX::CTheme * docx_theme= docx_document->GetTheme(); + if (docx_theme == NULL) return; + + std::wstring font; + + switch(oox_font_theme->GetValue()) + { + case SimpleTypes::themeMajorAscii: + case SimpleTypes::themeMajorHAnsi : + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oLatin.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oLatin.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + case SimpleTypes::themeMajorBidi: + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oCs.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oCs.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + case SimpleTypes::themeMajorEastAsia: + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oEa.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMajorFont.m_oEa.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + case SimpleTypes::themeMinorAscii: + case SimpleTypes::themeMinorHAnsi: + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oLatin.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oLatin.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + case SimpleTypes::themeMinorBidi: + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oCs.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oCs.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + case SimpleTypes::themeMinorEastAsia: + if (docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oEa.m_oTypeFace.IsInit()) + { + font = string2std_string(docx_theme->m_oThemeElements.m_oFontScheme.m_oMinorFont.m_oEa.m_oTypeFace->GetValue()); + if (font.length() > 0) odf_font_name = font; + } + break; + } + + +} + void DocxConverter::convert(OOX::Logic::CText *oox_text) { if (oox_text == NULL) return; + if (oox_text->m_oSpace.IsInit()) + { + if (oox_text->m_oSpace->GetValue() == SimpleTypes::xmlspacePreserve) + { + } + //odt_context->text_context()->add_text_space(26); + } odt_context->add_text_content(string2std_string(oox_text->m_sText)); } void DocxConverter::convert(OOX::Logic::CAlternateContent *oox_alt_content) @@ -1755,9 +1823,20 @@ void DocxConverter::convert(OOX::CDocDefaults *def_style) odt_context->styles_context()->create_default_style(odf::style_family::Paragraph); odf::style_paragraph_properties * paragraph_properties = odt_context->styles_context()->last_state().get_paragraph_properties(); - convert(def_style->m_oParPr.GetPointer(), paragraph_properties/*, text_properties*/); + convert(def_style->m_oParPr.GetPointer(), paragraph_properties); + if (def_style->m_oParPr->m_oRPr.IsInit()) + { + odf::style_text_properties * text_properties = odt_context->styles_context()->last_state().get_text_properties(); + convert(def_style->m_oParPr->m_oRPr.GetPointer(), text_properties); + } + else if (def_style->m_oRunPr.IsInit()) + { + odf::style_text_properties * text_properties = odt_context->styles_context()->last_state().get_text_properties(); + + convert(def_style->m_oRunPr.GetPointer(), text_properties); + } } - if (def_style->m_oRunPr.IsInit()) + else if (def_style->m_oRunPr.IsInit()) { odt_context->styles_context()->create_default_style(odf::style_family::Text); odf::style_text_properties * text_properties = odt_context->styles_context()->last_state().get_text_properties(); diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h index 8865a87557..6e446b3f26 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h @@ -133,6 +133,7 @@ namespace Oox2Odf void convert(OOX::Drawing::CChart *oox_chart); void convert(OOX::Drawing::CPicture *oox_picture); + void convert(SimpleTypes::CTheme<> *oox_font_theme,_CP_OPT(std::wstring) & odf_font_name); void convert(ComplexTypes::Word::CColor *color, _CP_OPT(odf::color) & odf_color); void convert(SimpleTypes::CUniversalMeasure *oox_size, _CP_OPT(odf::length) & odf_size); void convert(SimpleTypes::CUniversalMeasure *oox_size, _CP_OPT(odf::length_or_percent) & odf_size); diff --git a/ASCOfficeOdfFileW/version.h b/ASCOfficeOdfFileW/version.h index d55b157edc..3c5ad15179 100644 --- a/ASCOfficeOdfFileW/version.h +++ b/ASCOfficeOdfFileW/version.h @@ -2,6 +2,6 @@ //1 //2 //0 -//101 -#define INTVER 1,2,0,101 -#define STRVER "1,2,0,101\0" +//103 +#define INTVER 1,2,0,103 +#define STRVER "1,2,0,103\0"