mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 01:04:34 +08:00
fix bug #66312
This commit is contained in:
@ -833,10 +833,10 @@ void XlsConverter::convert(XLS::FORMATTING* formating)
|
||||
|
||||
CP_XML_NODE(L"numFmts")
|
||||
{
|
||||
CP_XML_ATTR(L"count", xls_global_info->m_arNumFormats.size());
|
||||
for (size_t i = 0; i < xls_global_info->m_arNumFormats.size(); i++)
|
||||
CP_XML_ATTR(L"count", xls_global_info->m_mapNumFormats.size());
|
||||
for (std::map<_UINT16, XLS::BaseObjectPtr>::iterator it = xls_global_info->m_mapNumFormats.begin(); it != xls_global_info->m_mapNumFormats.end(); ++it)
|
||||
{
|
||||
XLS::Format* fmt = dynamic_cast<XLS::Format*>(xls_global_info->m_arNumFormats[i].get());
|
||||
XLS::Format* fmt = dynamic_cast<XLS::Format*>(it->second.get());
|
||||
|
||||
if (fmt->ifmt < 5 || (fmt->ifmt > 8 && fmt->ifmt < 23) || (fmt->ifmt > 36 && fmt->ifmt < 41) || (fmt->ifmt > 44 && fmt->ifmt < 50))
|
||||
continue;
|
||||
|
||||
@ -90,11 +90,12 @@ CFRecord::CFRecord(NSFile::CFileBinary &file, GlobalWorkbookInfoPtr global_info)
|
||||
: rdPtr(0),
|
||||
size_(0),
|
||||
data_(NULL),
|
||||
type_id_(rt_EOF),
|
||||
global_info_(global_info)
|
||||
{
|
||||
file_ptr = file.GetFilePosition();
|
||||
|
||||
if (file.GetFilePosition() + 4 < file.GetFileSize())
|
||||
if (file.GetFilePosition() + 4 <= file.GetFileSize())
|
||||
{
|
||||
unsigned short size_short;
|
||||
DWORD size_read = 0;
|
||||
@ -133,7 +134,8 @@ CFRecord::CFRecord(NSBinPptxRW::CBinaryFileReader &reader, GlobalWorkbookInfoPtr
|
||||
: rdPtr(0),
|
||||
size_(0),
|
||||
data_(NULL),
|
||||
global_info_(global_info)
|
||||
type_id_(rt_EOF),
|
||||
global_info_(global_info)
|
||||
{
|
||||
file_ptr = reinterpret_cast<std::uintptr_t>(reader.GetPointer(0)) ;
|
||||
BYTE lenght = 0;
|
||||
|
||||
@ -53,8 +53,8 @@ public:
|
||||
|
||||
int serialize(std::wostream & stream);
|
||||
//-----------------------------
|
||||
_UINT16 ifmt_used;
|
||||
_UINT16 ifmt;
|
||||
_UINT16 ifmt_used = 0xFFFF;
|
||||
_UINT16 ifmt = 0xFFFF;
|
||||
std::wstring stFormat;
|
||||
};
|
||||
|
||||
|
||||
@ -55,16 +55,21 @@ void Window1::readFields(CFRecord& record)
|
||||
{
|
||||
if (record.getGlobalWorkbookInfo()->Version < 0x0800)
|
||||
{
|
||||
unsigned short flags;
|
||||
_INT16 xWn_2b;
|
||||
_INT16 yWn_2b;
|
||||
_INT16 dxWn_2b;
|
||||
_INT16 dyWn_2b;
|
||||
_UINT16 itabCur_2b;
|
||||
_UINT16 itabFirst_2b;
|
||||
_UINT16 wTabRatio_2b;
|
||||
BYTE flags = 0, reserved;
|
||||
_INT16 xWn_2b = 0;
|
||||
_INT16 yWn_2b = 0;
|
||||
_INT16 dxWn_2b = 0;
|
||||
_INT16 dyWn_2b = 0;
|
||||
_UINT16 itabCur_2b = 0;
|
||||
_UINT16 itabFirst_2b = 0;
|
||||
_UINT16 wTabRatio_2b = 0;
|
||||
|
||||
record >> xWn_2b >> yWn_2b >> dxWn_2b >> dyWn_2b >> flags >> itabCur_2b >> itabFirst_2b >> ctabSel >> wTabRatio_2b;
|
||||
record >> xWn_2b >> yWn_2b >> dxWn_2b >> dyWn_2b >> flags;
|
||||
|
||||
if (record.getGlobalWorkbookInfo()->Version > 0x0400)
|
||||
{
|
||||
record >> reserved >> itabCur_2b >> itabFirst_2b >> ctabSel >> wTabRatio_2b;
|
||||
}
|
||||
|
||||
fHidden = GETBIT(flags, 0);
|
||||
fIconic = GETBIT(flags, 1);
|
||||
|
||||
@ -74,15 +74,9 @@ namespace XLS
|
||||
|
||||
fill.fls = GETBIT(flags2, 7) ? 1 : 0;
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
if (ifmt_index < global_info->m_arNumFormats.size() && ifmt_index != 0xff)
|
||||
if (ifmt_index != 0xff)
|
||||
{
|
||||
Format* fmt = dynamic_cast<Format*>(global_info->m_arNumFormats[ifmt_index].get());
|
||||
if (fmt)
|
||||
{
|
||||
format_code = fmt->stFormat;
|
||||
ifmt = fmt->ifmt_used = global_info->RegisterNumFormat(fmt->ifmt, format_code); // return update
|
||||
}
|
||||
ifmt = global_info->RegisterNumFormat(ifmt_index, L""); // return update
|
||||
}
|
||||
|
||||
if (font_index >= 0 && font_index < global_info->m_arFonts.size())
|
||||
@ -144,14 +138,9 @@ namespace XLS
|
||||
border.dgRight = static_cast<unsigned char>(GETBITS(flags5, 24, 26));
|
||||
border.icvRight = (0 != border.dgRight) ? static_cast<unsigned char>(GETBITS(flags5, 27, 31)) : 0;
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
if (ifmt_index < global_info->m_arNumFormats.size() && ifmt_index != 0xff)
|
||||
if (ifmt_index != 0xff)
|
||||
{
|
||||
Format* fmt = dynamic_cast<Format*>(global_info->m_arNumFormats[ifmt_index].get());
|
||||
if (fmt)
|
||||
{
|
||||
format_code = fmt->stFormat;
|
||||
ifmt = fmt->ifmt_used = global_info->RegisterNumFormat(fmt->ifmt, format_code); // return update
|
||||
}
|
||||
ifmt = global_info->RegisterNumFormat(ifmt_index, L"");
|
||||
}
|
||||
|
||||
if (font_index >= 0 && font_index < global_info->m_arFonts.size())
|
||||
@ -186,6 +175,8 @@ namespace XLS
|
||||
|
||||
ixfParent = 0;
|
||||
font_index = 0xffff;
|
||||
|
||||
ifmt = 0xffff;
|
||||
}
|
||||
XF::~XF()
|
||||
{
|
||||
@ -389,14 +380,9 @@ void XF::readFields(CFRecord& record)
|
||||
case 2: trot = 90; break; // Text orientation: 90 deg counterclockwise.
|
||||
case 3: trot = 270; break; // Text orientation: 90 deg clockwise.
|
||||
}
|
||||
if (ifmt_index < global_info->m_arNumFormats.size() && ifmt_index != 0xff)
|
||||
if (ifmt_index != 0xff)
|
||||
{
|
||||
Format* fmt = dynamic_cast<Format*>(global_info->m_arNumFormats[ifmt_index].get());
|
||||
if (fmt)
|
||||
{
|
||||
format_code = fmt->stFormat;
|
||||
ifmt = fmt->ifmt_used = global_info->RegisterNumFormat(fmt->ifmt, format_code); // return update
|
||||
}
|
||||
ifmt = global_info->RegisterNumFormat(ifmt_index, L"");
|
||||
}
|
||||
|
||||
if (font_index >= 0 && font_index < global_info->m_arFonts.size())
|
||||
|
||||
@ -94,24 +94,8 @@ const bool FORMATTING::loadContent(BinProcessor& proc)
|
||||
count = proc.repeated<Format>(0, 218); // Originally: proc.repeated<Format>(8, 218);
|
||||
while(count > 0)
|
||||
{
|
||||
Format *fmt = dynamic_cast<Format *>(elements_.back().get());
|
||||
if ((fmt) && (fmt->ifmt == 0xffff))
|
||||
{
|
||||
std::map<std::wstring, int>::iterator pFind = global_info->mapDefaultFormatCode.find(fmt->stFormat);
|
||||
if (pFind != global_info->mapDefaultFormatCode.end())
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = pFind->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = global_info->last_User_NumFmt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = global_info->RegisterNumFormat(fmt->ifmt, fmt->stFormat);
|
||||
}
|
||||
global_info->m_arNumFormats.insert(global_info->m_arNumFormats.begin(), elements_.back());
|
||||
global_info->RegisterNumFormat(elements_.back());
|
||||
|
||||
elements_.pop_back();
|
||||
count--;
|
||||
}
|
||||
|
||||
@ -32,8 +32,9 @@
|
||||
#include "GlobalWorkbookInfo.h"
|
||||
|
||||
#include "Biff_records/Font.h"
|
||||
#include "../../../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
#include "Biff_records/Format.h"
|
||||
|
||||
#include "../../../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
|
||||
namespace XLS
|
||||
{
|
||||
@ -93,6 +94,7 @@ std::vector<GlobalWorkbookInfo::_xti> GlobalWorkbookInfo::arXti_External_stat
|
||||
std::unordered_map<int, std::wstring> GlobalWorkbookInfo::mapTableNames_static;
|
||||
std::unordered_map<int, std::vector<std::wstring>> GlobalWorkbookInfo::mapTableColumnNames_static;
|
||||
std::vector<std::wstring> GlobalWorkbookInfo::arDefineNames_static;
|
||||
|
||||
GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConverter * converter) : CodePage(code_page), xls_converter(converter)
|
||||
{
|
||||
fill_x_ids[FillInfo(0, 0, 0)] = 0;
|
||||
@ -125,7 +127,7 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
|
||||
idPivotCache = 0;
|
||||
currentPivotCacheRecord = 0;
|
||||
|
||||
|
||||
// common for all lcid
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"0", 1));
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"0.00", 2));
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"#,##0", 3));
|
||||
@ -154,6 +156,35 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"##0.0E+0", 48));
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"@", 49));
|
||||
mapDefaultFormatCode.insert(std::make_pair(L"General", 0));
|
||||
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(0, L"General"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(1, L"0"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(2, L"0.00"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(3, L"#,##0"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(4, L"#,##0.00"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(9, L"0%"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(10,L"0.00%"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(11, L"0.00E+00"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(12, L"# ?/?"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(13, L"# ??/??"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(14, L"mm-dd-yy"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(15, L"d-mmm-yy"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(16, L"d-mmm"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(17, L"mmm-yy"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(18, L"h:mm AM/PM"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(19, L"h:mm:ss AM/PM"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(20, L"h:mm"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(21, L"h:mm:ss"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(22, L"m/d/yy h:mm"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(37, L"#,##0 ;(#,##0)"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(38, L"#,##0 ;[Red](#,##0)"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(39, L"#,##0.00;(#,##0.00)"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(40, L"#,##0.00;[Red](#,##0.00)"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(45, L"mm:ss"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(46, L"[h]:mm:ss"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(47, L"mmss.0"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(48, L"##0.0E+0"));
|
||||
mapDefaultFormatCodeNum.insert(std::make_pair(49, L"@"));
|
||||
}
|
||||
|
||||
GlobalWorkbookInfo::~GlobalWorkbookInfo()
|
||||
@ -220,9 +251,57 @@ void GlobalWorkbookInfo::RegisterPaletteColor(int id, const std::wstring & rgb)
|
||||
{
|
||||
colors_palette.insert(std::make_pair(id, rgb));
|
||||
}
|
||||
_UINT16 GlobalWorkbookInfo::RegisterNumFormat(_UINT16 ifmt, const std::wstring & format_code)
|
||||
void GlobalWorkbookInfo::RegisterNumFormat(BaseObjectPtr element)
|
||||
{
|
||||
_UINT16 ifmt_used = ifmt;
|
||||
Format* fmt = dynamic_cast<Format*>(element.get());
|
||||
if (!fmt) return;
|
||||
|
||||
if (fmt->ifmt == 0xffff)
|
||||
{
|
||||
std::map<std::wstring, _UINT16>::iterator pFind = mapDefaultFormatCode.find(fmt->stFormat);
|
||||
if (pFind != mapDefaultFormatCode.end())
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = pFind->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = last_User_NumFmt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<_UINT16, _UINT16>::iterator pFindCode = mapUsedFormatCode.find(fmt->ifmt);
|
||||
if (pFindCode != mapUsedFormatCode.end())
|
||||
{
|
||||
fmt->ifmt_used = pFindCode->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fmt->ifmt > 49)
|
||||
{
|
||||
fmt->ifmt_used = last_User_NumFmt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt;
|
||||
}
|
||||
mapUsedFormatCode.insert(std::make_pair(fmt->ifmt, fmt->ifmt_used));
|
||||
}
|
||||
}
|
||||
std::map<_UINT16, BaseObjectPtr>::iterator pFindFormat = m_mapNumFormats.find(fmt->ifmt_used);
|
||||
if (pFindFormat == m_mapNumFormats.end())
|
||||
{
|
||||
m_mapNumFormats.insert(std::make_pair(fmt->ifmt_used, element));
|
||||
}
|
||||
else
|
||||
{
|
||||
//меняем
|
||||
pFindFormat->second = element;
|
||||
}
|
||||
}
|
||||
_UINT16 GlobalWorkbookInfo::RegisterNumFormat(_UINT16 ifmt, const std::wstring & format_code_)
|
||||
{
|
||||
std::wstring format_code = format_code_;
|
||||
|
||||
std::map<_UINT16, _UINT16>::iterator pFind = mapUsedFormatCode.find(ifmt);
|
||||
if (pFind != mapUsedFormatCode.end())
|
||||
@ -231,17 +310,86 @@ _UINT16 GlobalWorkbookInfo::RegisterNumFormat(_UINT16 ifmt, const std::wstring &
|
||||
}
|
||||
else
|
||||
{
|
||||
if (format_code.empty())
|
||||
{
|
||||
if (59 <= ifmt && ifmt <= 78)
|
||||
{
|
||||
if (69 <= ifmt && ifmt <= 71)
|
||||
{
|
||||
ifmt += 1;
|
||||
}
|
||||
ifmt -= 58;
|
||||
}
|
||||
else if (79 <= ifmt && ifmt <= 81)
|
||||
{
|
||||
ifmt -= 34;
|
||||
}
|
||||
switch (ifmt)
|
||||
{
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
ifmt = 0;
|
||||
break;
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 36:
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
ifmt = 14;
|
||||
break;
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
ifmt = 21;
|
||||
break;
|
||||
}
|
||||
|
||||
std::map<_UINT16, std::wstring>::iterator pFindCode = mapDefaultFormatCodeNum.find(ifmt);
|
||||
if (pFindCode != mapDefaultFormatCodeNum.end())
|
||||
{
|
||||
format_code = pFindCode->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ???? todooo
|
||||
}
|
||||
}
|
||||
|
||||
_UINT16 ifmt_used = ifmt;
|
||||
if (ifmt > 49)
|
||||
{
|
||||
ifmt_used = last_User_NumFmt++;
|
||||
ifmt_used = last_User_NumFmt++;
|
||||
}
|
||||
else
|
||||
|
||||
std::map<_UINT16, BaseObjectPtr>::iterator pFindFormat = m_mapNumFormats.find(ifmt_used);
|
||||
if (pFindFormat == m_mapNumFormats.end())
|
||||
{
|
||||
//todooo проверка по mapDefaultFormatCode -> ooxml fmtNum format code
|
||||
// генерим хоть что то
|
||||
Format* fmt = new Format();
|
||||
fmt->ifmt = ifmt;
|
||||
fmt->ifmt_used = ifmt_used;
|
||||
|
||||
fmt->stFormat = format_code;
|
||||
|
||||
m_mapNumFormats.insert(std::make_pair(fmt->ifmt_used, BaseObjectPtr(fmt)));
|
||||
}
|
||||
mapUsedFormatCode.insert(std::make_pair(ifmt, ifmt_used));
|
||||
|
||||
return ifmt_used;
|
||||
}
|
||||
return ifmt_used;
|
||||
}
|
||||
const int GlobalWorkbookInfo::RegistrDxfn(const std::wstring & dxfn)
|
||||
{
|
||||
|
||||
@ -89,7 +89,7 @@ public:
|
||||
const size_t RegisterFontId (const FontInfo& font);
|
||||
const int RegistrDxfn (const std::wstring& dx_style);
|
||||
_UINT16 RegisterNumFormat (_UINT16 ifmt, const std::wstring & format_code);
|
||||
|
||||
void RegisterNumFormat (BaseObjectPtr element);
|
||||
void RegisterPaletteColor(int id, const std::wstring & argb);
|
||||
|
||||
void GetDigitFontSizePixels();
|
||||
@ -114,7 +114,6 @@ public:
|
||||
std::map<int, int> fonts_charsets;
|
||||
std::map<int, std::wstring> colors_palette;
|
||||
|
||||
std::vector<BaseObjectPtr> m_arNumFormats;
|
||||
std::vector<BaseObjectPtr> m_arFonts;
|
||||
PPTX::ThemePtr m_pTheme;
|
||||
|
||||
@ -202,8 +201,11 @@ public:
|
||||
int cellStyleXfs_count;
|
||||
int cellStyleDxfs_count;
|
||||
|
||||
std::map<std::wstring, int> mapDefaultFormatCode;
|
||||
std::map<std::wstring, _UINT16> mapDefaultFormatCode;
|
||||
std::map<_UINT16, std::wstring> mapDefaultFormatCodeNum;
|
||||
|
||||
std::map<_UINT16, _UINT16> mapUsedFormatCode; //original, used
|
||||
std::map<_UINT16, BaseObjectPtr> m_mapNumFormats;
|
||||
|
||||
std::map<std::wstring, int> mapUserDxfs;
|
||||
std::vector<std::wstring> arrUserDxfs;
|
||||
|
||||
@ -681,24 +681,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
Format *fmt = dynamic_cast<Format *>(elements_.front().get());
|
||||
if ((fmt) && (fmt->ifmt == 0xffff))
|
||||
{
|
||||
std::map<std::wstring, int>::iterator pFind = global_info_->mapDefaultFormatCode.find(fmt->stFormat);
|
||||
if (pFind != global_info_->mapDefaultFormatCode.end())
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = pFind->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = fmt->ifmt = global_info_->last_User_NumFmt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt->ifmt_used = global_info_->RegisterNumFormat(fmt->ifmt, fmt->stFormat);
|
||||
}
|
||||
global_info_->m_arNumFormats.push_back(elements_.front());
|
||||
global_info_->RegisterNumFormat(elements_.front());
|
||||
elements_.pop_front();
|
||||
count--;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user