Merge remote-tracking branch 'origin/fix/bug61378' into release/v8.1.0

This commit is contained in:
Elena Subbotina
2024-04-05 16:50:09 +03:00
7 changed files with 86 additions and 34 deletions

View File

@ -43,7 +43,7 @@
// Определение основных форматов даты
std::vector<std::wstring> DateFormats = {
L"%d.%m.%Y", L"%d.%m.%y", L"%Y-%m-%d", L"%m/%d/%Y",
L"%d.%m.%Y", L"%d.%m.%y", L"%Y-%m-%d",L"%d/%m/%Y",L"%d/%m/%y", L"%m/%d/%Y",
L"%m/%d/%y", L"%d %B %Y", L"%d %B, %Y", L"%d %b %Y",
L"%d %b, %Y", L"%B %d %Y", L"%B %d, %Y", L"%b %d %Y",
L"%b %d, %Y", L"%Y/%m/%d", L"%Y/%d/%m", L"%m-%d-%Y",
@ -67,7 +67,10 @@ bool DateReader::GetDigitalDate(const std::wstring &date, _INT32 &result)
if(time.tm_year > 0)
{
result = getStandartDate(time);
if(time.tm_year >= 70)
result = getStandartDate(time);
else
result = getNonUnixDate(time);
return true;
}
return false;
@ -80,8 +83,38 @@ bool DateReader::GetDigitalDate(const std::wstring &date, _INT32 &result)
_INT32 DateReader::getStandartDate(tm &date)
{
// Преобразование даты в формат excel
auto tp = std::chrono::system_clock::from_time_t(mktime(&date));
auto excelTime = (tp.time_since_epoch().count() / 10000000) + 2209161600;
_INT32 tempTime = round(excelTime / 86400.0);
return tempTime;
}
auto timeT = mktime(&date);
auto tp = std::chrono::system_clock::from_time_t(timeT);
auto excelTime = (tp.time_since_epoch().count() / 10000000) + 2209161600;
_INT32 tempTime = round(excelTime / 86400.0);
return tempTime;
}
// Функция для определения високосного года
bool isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
_INT32 DateReader::getNonUnixDate(tm &date)
{
const int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long days = 1;
// Добавляем количество дней за предыдущие годы
for (int year = 1900; year < date.tm_year + 1900; ++year) {
days += isLeapYear(year) ? 366 : 365;
}
// Добавляем количество дней до начала текущего года
for (int month = 0; month < date.tm_mon; ++month) {
days += daysInMonth[month];
if (month == 1 && isLeapYear(date.tm_year + 1900))
days++; // добавляем 1 день для февраля в високосном году
}
// Добавляем количество дней текущего месяца
days += date.tm_mday;
return days;
}

View File

@ -51,5 +51,10 @@ private:
/// @param datetime структура с датой
/// @return дата в формате excel
_INT32 getStandartDate(tm &date);
/// @brief получение даты в виде числа в формате excel из дат от 1900 года и до 1970
/// @param datetime структура с датой
/// @return дата в формате excel
_INT32 getNonUnixDate(tm &date);
};

View File

@ -475,7 +475,7 @@ namespace OOX
}
return nLen;
}
_UINT32 CFormulaXLSB::toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula)
_UINT16 CFormulaXLSB::toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula)
{
_UINT16 nFlags = 0;
if(m_oCa.ToBool())
@ -486,7 +486,7 @@ namespace OOX
oStream.WriteULONG(0);//cce
oStream.WriteULONG(0);//cb
_UINT32 nFlagsExt = 0;
_UINT16 nFlagsExt = 0;
nFlagsExt |= m_oT.GetValue();
nFlagsExt |= 0x4;
if(m_oAca.ToBool())
@ -693,12 +693,20 @@ namespace OOX
oStream.XlsbStartRecord(nType, nLen);
oStream.WriteULONG(m_nCol & 0x3FFF);
_UINT32 nStyle = m_nStyle;
_UINT32 nFlags2 = m_nStyle;
if (m_oShowPhonetic.ToBool())
{
nStyle |= 0x1000000;
nFlags2 |= 0x1000000;
}
oStream.WriteULONG(nStyle);
if (m_oCellMetadata.IsInit())
{
nFlags2 |= 0x2000000;
}
if (m_oValueMetadata.IsInit())
{
nFlags2 |= 0x4000000;
}
oStream.WriteULONG(nFlags2);
//todo RkNumber
switch(nType)
{
@ -721,25 +729,16 @@ namespace OOX
break;
}
_UINT32 nFlags = 0;
_UINT16 nFlags = 0;
if(m_oFormula.m_bIsInit)
{
nFlags = m_oFormula.toXLSB(oStream, bIsBlankFormula);
}
if(m_oRichText.IsInit())
{
nFlags |= 0x2000;
}
if (m_oCellMetadata.IsInit())
{
nFlags |= 0x8000;
}
if (m_oValueMetadata.IsInit())
{
nFlags |= 0x10000;
}
oStream.WriteULONG(nFlags);
oStream.WriteUSHORT(nFlags);
if(m_oFormula.m_bIsInit)
{
m_oFormula.toXLSBExt(oStream);
@ -1715,13 +1714,13 @@ namespace OOX
m_oRow = nRow;
m_oCol = (oStream.GetULong() & 0x3FFF);
_UINT32 nStyleRef = oStream.GetULong();
if(0 != (nStyleRef & 0xFFFFFF))
_UINT32 nFlags2 = oStream.GetULong();
if(0 != (nFlags2 & 0xFFFFFF))
{
m_oStyle = (nStyleRef & 0xFFFFFF);
m_oStyle = (nFlags2 & 0xFFFFFF);
}
if(0 != (nStyleRef & 0x1000000))
if(0 != (nFlags2 & 0x1000000))
{
m_oShowPhonetic.Init();
m_oShowPhonetic->FromBool(true);
@ -1784,7 +1783,7 @@ namespace OOX
m_oFormula->fromXLSB(oStream);
}
//todo it breaks xslb format
_UINT32 nFlags = oStream.GetULong();
_UINT16 nFlags = oStream.GetUShort();
if(0 != (nFlags & 0x4))
{
if(!m_oFormula.IsInit())
@ -1806,11 +1805,11 @@ namespace OOX
m_oRichText.Init();
m_oRichText->fromXLSBExt(oStream);
}
if (0 != (nFlags & 0x8000))
if (0 != (nFlags2 & 0x2000000))
{
m_oCellMetadata = oStream.GetULong();
}
if (0 != (nFlags & 0x10000))
if (0 != (nFlags2 & 0x4000000))
{
m_oValueMetadata = oStream.GetULong();
}

View File

@ -61,7 +61,7 @@ namespace OOX
void Clean();
void fromXML(XmlUtils::CXmlLiteReader& oReader);
_UINT32 getXLSBSize();
_UINT32 toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula);
_UINT16 toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula);
void toXLSBExt(NSBinPptxRW::CXlsbBinaryWriter& oStream);
bool m_bIsInit;

View File

@ -205,7 +205,8 @@ SOURCES += \
../../Reader/Format/office_settings.cpp \
../../Reader/Format/office_spreadsheet.cpp \
../../Reader/Format/office_text.cpp \
../../Reader/Format/office_meta.cpp \
../../Reader/Format/office_drawing.cpp \
../../Reader/Format/office_meta.cpp \
../../Reader/Format/paragraph_elements.cpp \
../../Reader/Format/ruby.cpp \
../../Reader/Format/search_table_cell.cpp \
@ -389,7 +390,6 @@ SOURCES += \
../../Writer/Format/odp_page_state.cpp \
../../Writer/Format/odp_slide_context.cpp \
../../Writer/Format/office_presentation.cpp \
../../Writer/Format/office_drawing.cpp \
../../Writer/Format/style_presentation.cpp \
../../Writer/Format/odf_math_context.cpp \
../../Writer/Format/math_elementaries.cpp \

View File

@ -945,6 +945,7 @@
<ClInclude Include="..\..\Reader\Converter\pptx_animation_context.h">
<Filter>oox\pptx</Filter>
</ClInclude>
<<<<<<< HEAD
<ClInclude Include="..\..\Reader\Converter\StarMath2OOXML\cconversionsmtoooxml.h">
<Filter>starmath</Filter>
</ClInclude>
@ -953,6 +954,8 @@
</ClInclude>
<ClInclude Include="..\..\Reader\Converter\StarMath2OOXML\typeselements.h">
<Filter>starmath</Filter>
=======
>>>>>>> origin/fix/bug61378
<ClInclude Include="..\..\Reader\Format\office_drawing.h">
<Filter>elements</Filter>
</ClInclude>

View File

@ -140,6 +140,8 @@ private:
//-------------------------------------------------------------------------------
std::vector<std::wstring> list_style_stack_;
bool first_element_list_item_;
_CP_OPT(odf_types::length) last_run_font_size_;
int new_list_style_number_; // счетчик для нумерации имен созданных в процессе конвертации стилей
@ -451,6 +453,10 @@ void pptx_text_context::Impl::write_rPr(std::wostream & strm)
strm << get_styles_context().text_style().str();
if (text_properties_.fo_font_size_)
last_run_font_size_ = text_properties_.fo_font_size_->get_length();
else
last_run_font_size_ = boost::none;
}
std::wstring pptx_text_context::Impl::dump_paragraph(/*bool last*/)
{
@ -474,7 +480,13 @@ std::wstring pptx_text_context::Impl::dump_paragraph(/*bool last*/)
}
else
{
CP_XML_NODE(L"a:endParaRPr");
CP_XML_NODE(L"a:endParaRPr")
{
if(last_run_font_size_)
{
CP_XML_ATTR(L"sz", last_run_font_size_->get_value_unit(odf_types::length::pt) * 100);
}
}
}
}
}