Skip to content

Commit

Permalink
Merge pull request 'fix/bug-68408' (#229) from fix/bug-68408 into hot…
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaSubbotina committed Feb 11, 2025
2 parents 2d58b08 + fea3910 commit 7d3488a
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 27 deletions.
58 changes: 56 additions & 2 deletions OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace StarMath
{
//class OOXml2Odf
COOXml2Odf::COOXml2Odf()
COOXml2Odf::COOXml2Odf():m_wsBaseColor(L""),m_uiBaseSize(0)
{
m_pXmlWrite = new XmlUtils::CXmlWriter;
}
Expand Down Expand Up @@ -553,10 +553,13 @@ namespace StarMath
ConversionMRunProperties(pMRun->m_oMRPr.GetPointer(),stRpr);
if(pMRun->m_oMText.GetPointer() != nullptr)
arLine = ConversionMT(pMRun->m_oMText.GetPointer(),stRpr,pMRun->m_oMRPr.GetPointer());
CreateAttribute(stRpr);
if(stRpr != nullptr && !arLine.empty())
{
if(!m_stAttribute.empty())
AttributeCheck(m_stAttribute.top(),stRpr);
else
AttributeCheck(stRpr);
for(int i = 0; i<arLine.size();i++)
{
if(i != 0 )
Expand Down Expand Up @@ -682,6 +685,29 @@ namespace StarMath
pChild->m_enFont = StarMath::TypeFont::empty;
}
}
void COOXml2Odf::AttributeCheck(StValuePr*& pChild)
{
if(pChild == nullptr && !pChild->m_bBaseAttribute)
return;
if(m_uiBaseSize != 0 && pChild->m_iSize == 0)
pChild->m_iSize = m_uiBaseSize;
if(!m_wsBaseColor.empty() && pChild->m_wsColor.empty())
pChild->m_wsColor = m_wsBaseColor;
}
void COOXml2Odf::CreateAttribute(StValuePr*& pAttribute)
{
if(pAttribute != nullptr)
return;
if(m_uiBaseSize != 0 || !m_wsBaseColor.empty())
{
pAttribute = new StValuePr;
pAttribute->m_bBaseAttribute = true;
if(m_uiBaseSize != 0)
pAttribute->m_iSize = m_uiBaseSize;
if(!m_wsBaseColor.empty())
pAttribute->m_wsColor = m_wsBaseColor;
}
}
void COOXml2Odf::ConversionAcc(OOX::Logic::CAcc *pAcc)
{
std::wstring wsSymbol = pAcc->m_oAccPr->m_oChr.IsInit() ? pAcc->m_oAccPr->m_oChr.get().m_val->GetValue() : L"",wsSign;
Expand Down Expand Up @@ -795,6 +821,11 @@ namespace StarMath
stTempPr->m_enStyle = SimpleTypes::EStyle::styleItalic;
bRpr = true;
}
else if(pRPr->m_oU.GetPointer() != nullptr && pRPr->m_oU->m_oVal.GetPointer() != nullptr)
{
stTempPr->m_enUnderLine = pRPr->m_oU->m_oVal->GetValue();
bRpr = true;
}
if(bRpr == true)
return stTempPr;
else
Expand Down Expand Up @@ -1090,10 +1121,13 @@ namespace StarMath
pValue = ConversionRunProperties(pCtrlPr->m_oRPr.GetPointer());
else if(pCtrlPr->m_oARPr.GetPointer() != nullptr)
ConversionARpr(pCtrlPr->m_oARPr.GetPointer(),pValue);
CreateAttribute(pValue);
if(pValue != nullptr)
{
if(!m_stAttribute.empty())
AttributeCheck(m_stAttribute.top(),pValue);
else
AttributeCheck(pValue);
COneElement::ConversionAttribute(pValue,stStyle,m_pXmlWrite,m_wsAnnotationStarMath,bDelimiter);
if(bDelimiter)
m_stAttribute.push(pValue);
Expand All @@ -1120,6 +1154,13 @@ namespace StarMath
{
return m_wsSemantic;
}
void COOXml2Odf::SetBaseAttribute(std::wstring wsBaseColor, unsigned int uiBaseSize)
{
if(!wsBaseColor.empty())
m_wsBaseColor = wsBaseColor;
if(uiBaseSize != 0)
m_uiBaseSize = uiBaseSize;
}
void COOXml2Odf::ConversionRad(OOX::Logic::CRad *pRad)
{
if(pRad == nullptr)
Expand Down Expand Up @@ -1417,8 +1458,13 @@ namespace StarMath
void COOXml2Odf::StyleClosing(const StStyleMenClose &stStyle, XmlUtils::CXmlWriter *pXmlWrite)
{
if(stStyle.m_bMenClose)
{
pXmlWrite->WriteNodeEnd(L"menclose",false,false);
if(stStyle.m_bUnderlineClose)
{
pXmlWrite->WriteNodeBegin(L"mo",false);
pXmlWrite->WriteString(L"\u0332");
pXmlWrite->WriteNodeEnd(L"mo",false,false);
pXmlWrite->WriteNodeEnd(L"munder",false,false);
}
if(stStyle.m_iStyle != 0)
{
Expand Down Expand Up @@ -1733,6 +1779,14 @@ namespace StarMath
wsAnnotation += L"overstrike ";
stStyle.m_bMenClose = true;
}
if(pAttribute->m_enUnderLine == SimpleTypes::EUnderline::underlineSingle)
{
pXmlWrite->WriteNodeBegin(L"munder",true);
pXmlWrite->WriteAttribute(L"accentunder",L"true");
pXmlWrite->WriteNodeEnd(L"w",true,false);
wsAnnotation += L"underline ";
stStyle.m_bUnderlineClose = true;
}
if(!bDelimiter)
pAttribute->Release();
}
Expand Down
12 changes: 10 additions & 2 deletions OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace StarMath
{
struct StValuePr
{
StValuePr():m_wsTypeName(L""),m_wsBegBracket(L""),m_wsEndBracket(L""),m_wsChr(L""),m_wsColor(L""),m_bSupHide(false),m_bSubHide(false),m_enStyle(SimpleTypes::EStyle::stylePlain),m_iSize(0),m_enPos(SimpleTypes::ETopBot::tbBot),m_enVert(SimpleTypes::ETopBot::tbBot),m_enFont(StarMath::TypeFont::empty),m_iCount(0),m_bStrike(false)
StValuePr():m_wsTypeName(L""),m_wsChr(L""),m_wsBegBracket(L""),m_wsEndBracket(L""),m_wsColor(L""),m_bSupHide(false),m_bSubHide(false),m_enStyle(SimpleTypes::EStyle::stylePlain),m_iSize(0),m_enPos(SimpleTypes::ETopBot::tbBot),m_enVert(SimpleTypes::ETopBot::tbBot),m_enFont(StarMath::TypeFont::empty),m_iCount(0),m_bStrike(false),m_enUnderLine(SimpleTypes::EUnderline::underlineNone),m_bBaseAttribute(false)
{
AddRef();
}
Expand All @@ -32,6 +32,8 @@ namespace StarMath
StarMath::TypeFont m_enFont;
int m_iCount;
bool m_bStrike;
SimpleTypes::EUnderline m_enUnderLine;
bool m_bBaseAttribute;
void AddRef()
{
m_iCount++;
Expand All @@ -45,10 +47,11 @@ namespace StarMath
};
struct StStyleMenClose
{
StStyleMenClose():m_iStyle(0),m_bMenClose(false)
StStyleMenClose():m_iStyle(0),m_bMenClose(false),m_bUnderlineClose(false)
{}
unsigned int m_iStyle;
bool m_bMenClose;
bool m_bUnderlineClose;
};
class COneElement;
class COOXml2Odf
Expand Down Expand Up @@ -120,16 +123,21 @@ namespace StarMath
std::wstring TransformationUTF32(const std::wstring& wsText);
bool ComparingAttributes(StValuePr* pRight, StValuePr* pLeft);
void AttributeCheck(StValuePr*& pParent, StValuePr*& pChild);
void AttributeCheck(StValuePr*& pChild);
void CreateAttribute(StValuePr*& pAttribute);
StarMath::TypeFont FontCheck(const std::wstring& wsFont, bool& bAttribute);
static bool ColorCheck(const std::wstring& wsColor,std::wstring& wsRecordColor);
void EndOdf();
std::wstring GetOdf();
std::wstring GetAnnotation();
std::wstring GetSemantic();
void SetBaseAttribute(std::wstring wsBaseColor = L"", unsigned int uiBaseSize = 0);
private:
XmlUtils::CXmlWriter* m_pXmlWrite;
std::wstring m_wsAnnotationStarMath,m_wsSemantic;
std::stack<StValuePr*> m_stAttribute;
std::wstring m_wsBaseColor;
unsigned int m_uiBaseSize;
};
class COneElement
{
Expand Down
6 changes: 5 additions & 1 deletion OdfFile/Writer/Converter/ConvertDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,11 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape)
odf_context()->start_text_context();

//docx_converter->convert(oox_shape->oTextBoxShape.GetPointer());

convert(oox_shape->oTextBoxBodyPr.GetPointer());

if (oox_shape->style.IsInit())
convert(&oox_shape->style->fontRef);

for (size_t i = 0; i < oox_shape->oTextBoxShape->m_arrItems.size(); i++)
{
docx_converter->convert(oox_shape->oTextBoxShape->m_arrItems[i]);
Expand Down
2 changes: 2 additions & 0 deletions OdfFile/Writer/Converter/Converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ namespace Oox2Odf

bool encrypt_document (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath);
bool encrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, std::wstring &encrypt_info, int &size);

std::vector<double> current_font_size;

//.......................................................................................................................
virtual OOX::IFileContainer *current_document() = 0;
Expand Down
2 changes: 0 additions & 2 deletions OdfFile/Writer/Converter/DocxConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@

using namespace cpdoccore;

std::vector<double> current_font_size;

namespace Oox2Odf
{

Expand Down
46 changes: 39 additions & 7 deletions OdfFile/Writer/Converter/MathConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "../Format/math_layout_elements.h"
#include "../Format/math_limit_elements.h"
#include "../Format/math_token_elements.h"
#include "../Format/style_text_properties.h"

#include <set>
#include <vector>
Expand Down Expand Up @@ -173,7 +174,20 @@ namespace Oox2Odf

brackets().resize(1);

bool bStart = odf_context()->start_math();
int base_font_size = current_font_size.empty() ? 12 : current_font_size.back();
std::wstring base_font_color;

if (odf_context()->is_child_text_context())
{
if (odf_context()->drawing_context()->get_text_properties())
{
if (odf_context()->drawing_context()->get_text_properties()->fo_color_)
{
base_font_color = odf_context()->drawing_context()->get_text_properties()->fo_color_->get_hex_value();
}
}
}
bool bStart = odf_context()->start_math(base_font_size, base_font_color);

for (size_t i = 0; i < oox_math->m_arrItems.size(); ++i)
{
Expand All @@ -183,6 +197,7 @@ namespace Oox2Odf
if (bStart)
{
StarMath::COOXml2Odf starMathConverter;
starMathConverter.SetBaseAttribute(base_font_color,base_font_size);
starMathConverter.StartConversion(oox_math);

std::wstring annotation_text = starMathConverter.GetAnnotation();
Expand Down Expand Up @@ -236,7 +251,21 @@ namespace Oox2Odf
{
if (!oox_math_para) return;

bool bStart = odf_context()->start_math();
int base_font_size = current_font_size.empty() ? 12 : current_font_size.back();
std::wstring base_font_color;

if (odf_context()->is_child_text_context())
{
if (odf_context()->drawing_context()->get_text_properties())
{
if (odf_context()->drawing_context()->get_text_properties()->fo_color_)
{
base_font_color = odf_context()->drawing_context()->get_text_properties()->fo_color_->get_hex_value();
}
}
}

bool bStart = odf_context()->start_math(base_font_size, base_font_color);

for (size_t i = 0; i < oox_math_para->m_arrItems.size(); ++i)
{
Expand All @@ -245,6 +274,7 @@ namespace Oox2Odf
if (bStart)
{
StarMath::COOXml2Odf starMathConverter;
starMathConverter.SetBaseAttribute(base_font_color,base_font_size);
starMathConverter.StartConversion(oox_math_para);

std::wstring annotation_text = starMathConverter.GetAnnotation();
Expand Down Expand Up @@ -1260,16 +1290,18 @@ namespace Oox2Odf
odf_context()->settings_context()->start_view();
if (oox_r_pr->m_oSz.IsInit() && oox_r_pr->m_oSz->m_oVal.IsInit())
{
odf_context()->math_context()->size = oox_r_pr->m_oSz->m_oVal->GetValue();
odf_context()->math_context()->font_size = oox_r_pr->m_oSz->m_oVal->GetValue();
}
else

odf_context()->settings_context()->add_config_content_item(L"BaseFontHeight", L"short", std::to_wstring((int)odf_context()->math_context()->font_size));
if (!odf_context()->math_context()->font_color.empty())
{
odf_context()->math_context()->size = 12;
odf_context()->settings_context()->add_config_content_item(L"BaseFontColor", L"string", L"#" + odf_context()->math_context()->font_color);
}
odf_context()->settings_context()->add_config_content_item(L"BaseFontHeight", L"short", std::to_wstring(odf_context()->math_context()->size));

if (oox_r_pr->m_oRFonts.IsInit() && oox_r_pr->m_oRFonts->m_sAscii.IsInit())
{
odf_context()->math_context()->font = *oox_r_pr->m_oRFonts->m_sAscii;
odf_context()->math_context()->font_name = *oox_r_pr->m_oRFonts->m_sAscii;

odf_context()->settings_context()->add_config_content_item(L"FontNameFunctions", L"string", *oox_r_pr->m_oRFonts->m_sAscii);
odf_context()->settings_context()->add_config_content_item(L"FontNameNumbers", L"string", *oox_r_pr->m_oRFonts->m_sAscii);
Expand Down
6 changes: 4 additions & 2 deletions OdfFile/Writer/Format/odf_conversion_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void odf_conversion_context::end_drawing_context()
drawing_context_.pop_back();
}

bool odf_conversion_context::start_math()
bool odf_conversion_context::start_math(int base_font_size, const std::wstring& base_font_color)
{
if (false == math_context_.isEmpty()) return false;

Expand All @@ -401,6 +401,8 @@ bool odf_conversion_context::start_math()
math_context_.set_styles_context(odf_conversion_context::styles_context());
math_context_.start_math(get_current_object_element());

math_context_.font_size = base_font_size;
math_context_.font_color = base_font_color;
return true;
}
void odf_conversion_context::end_math()
Expand All @@ -409,7 +411,7 @@ void odf_conversion_context::end_math()

end_object();

calculate_font_metrix(math_context_.font, math_context_.size, false, false, true); // смотреть по формуле - перевычислять только если есть изменения это шрифт и кегль
calculate_font_metrix(math_context_.font_name, math_context_.font_size, false, false, true); // смотреть по формуле - перевычислять только если есть изменения это шрифт и кегль

double h = math_context_.lvl_max - math_context_.lvl_min;
if (math_context_.lvl_min < 0) h += 1;
Expand Down
4 changes: 3 additions & 1 deletion OdfFile/Writer/Format/odf_conversion_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class odf_conversion_context : boost::noncopyable
virtual odf_text_context * text_context() = 0;
virtual odf_controls_context * controls_context() = 0;

virtual bool is_child_text_context() = 0;

std::wstring add_image (const std::wstring & image_file_name, bool bExternal = false);
std::wstring add_media (const std::wstring & file_name, bool bExternal = false);
std::wstring add_oleobject (const std::wstring & ole_file_name, bool bExternal = false);
Expand All @@ -144,7 +146,7 @@ class odf_conversion_context : boost::noncopyable
void start_chart();
void end_chart();

virtual bool start_math();
virtual bool start_math(int base_font_size, const std::wstring & base_font_color);
virtual void end_math();

void start_spreadsheet();
Expand Down
6 changes: 5 additions & 1 deletion OdfFile/Writer/Format/odf_drawing_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2652,10 +2652,14 @@ graphic_format_properties* odf_drawing_context::get_graphic_properties()
{
return impl_->current_graphic_properties;
}
text_format_properties* odf_drawing_context::get_text_properties()
{
return impl_->current_text_properties;
}

void odf_drawing_context::set_textarea_vertical_align(int align)
{
if (!impl_->current_graphic_properties)return;
if (!impl_->current_graphic_properties) return;
switch(align)
{
case 0://SimpleTypes::textanchoringtypeB:
Expand Down
1 change: 1 addition & 0 deletions OdfFile/Writer/Format/odf_drawing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class odf_drawing_context
bool placeholder_replacing();

graphic_format_properties* get_graphic_properties();
text_format_properties* get_text_properties();

void set_graphic_properties (style_graphic_properties *graphic_properties);
void set_graphic_properties (graphic_format_properties* graphic_properties);
Expand Down
7 changes: 5 additions & 2 deletions OdfFile/Writer/Format/odf_math_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ namespace cpdoccore {
double lvl_down_counter = 0;
double lvl_max = 0;
double lvl_min = 0;
std::wstring font;
double size = 0;

std::wstring font_name;
double font_size = 0;
std::wstring font_color;

std::set<wchar_t> mo;
std::map<std::wstring, std::wstring> diak_symbols;

Expand Down
5 changes: 5 additions & 0 deletions OdfFile/Writer/Format/odp_conversion_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ odp_conversion_context::odp_conversion_context(package::odf_document * outputDoc
: odf_conversion_context (PresentationDocument, outputDocument), root_presentation_(NULL), slide_context_(*this), rId_(1)
{
}
bool odp_conversion_context::is_child_text_context()
{
return (false == text_context_.empty());
}

odf_text_context* odp_conversion_context::text_context()
{
if (false == text_context_.empty())
Expand Down
Loading

0 comments on commit 7d3488a

Please sign in to comment.