sw: read both platform dependent binary table autoformats

The WriterSpecificAutoFormatBlock class actually writes a length
into the file that covers the offending SwFormatVertOrient item.

Put in a gross hack to read either 32-bit or 64-bit in
SwFormatVertOrient::Store depending on that length.

The length also covers another item, so we'll just hope nobody ever
changes this stuff ever again!

Change-Id: Idf2f05cc00c098571508adb849f60940966c3328
Reviewed-on: https://gerrit.libreoffice.org/44254
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
This commit is contained in:
Michael Stahl
2017-11-03 13:20:14 +01:00
parent b3cfb849b1
commit cc88a2bcfd
2 changed files with 32 additions and 15 deletions

View File

@@ -149,13 +149,13 @@ namespace
};
/// Checks whether a writer-specific block exists (i.e. size is not zero)
bool WriterSpecificBlockExists(SvStream &stream)
sal_Int64 WriterSpecificBlockExists(SvStream &stream)
{
sal_uInt64 endOfSwBlock = 0;
stream.ReadUInt64( endOfSwBlock );
// end-of-block pointing to itself indicates a zero-size block.
return endOfSwBlock != stream.Tell();
return endOfSwBlock - stream.Tell();
}
}
@@ -452,10 +452,15 @@ bool SwBoxAutoFormat::Load( SvStream& rStream, const SwAfVersions& rVersions, sa
SetAdjust( *static_cast<SvxAdjustItem*>(pNew) );
delete pNew;
if (nVer >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
if (nVer >= AUTOFORMAT_DATA_ID_31005)
{
READ(m_aTextOrientation, SvxFrameDirectionItem, rVersions.m_nTextOrientationVersion);
READ(m_aVerticalAlignment, SwFormatVertOrient, rVersions.m_nVerticalAlignmentVersion);
sal_Int64 const nSize(WriterSpecificBlockExists(rStream));
if (0 < nSize && nSize < std::numeric_limits<sal_uInt16>::max())
{
READ(m_aTextOrientation, SvxFrameDirectionItem, rVersions.m_nTextOrientationVersion);
// HORRIBLE HACK to read both 32-bit and 64-bit "long": abuse nSize
READ(m_aVerticalAlignment, SwFormatVertOrient, /*rVersions.m_nVerticalAlignmentVersion*/ nSize);
}
}
READ( m_aHorJustify, SvxHorJustifyItem , rVersions.nHorJustifyVersion)

View File

@@ -1265,20 +1265,32 @@ SvStream& SwFormatVertOrient::Store(SvStream &rStream, sal_uInt16 /*version*/) c
return rStream;
}
SfxPoolItem* SwFormatVertOrient::Create(SvStream &rStream, sal_uInt16 /*itemVersion*/) const
SfxPoolItem* SwFormatVertOrient::Create(SvStream &rStream, sal_uInt16 nVersionAbusedAsSize) const
{
SwTwips yPos(0);
sal_Int16 orient(0);
sal_Int16 relation(0);
// compatibility hack for Table Auto Format: SwTwips is "long" :(
// (this means that the file format is platform dependent)
#if SAL_TYPES_SIZEOFLONG == 8
rStream.ReadInt64(yPos);
#else
sal_Int32 n;
rStream.ReadInt32(n);
yPos = n;
#endif
switch (nVersionAbusedAsSize)
{
// compatibility hack for Table Auto Format: SwTwips is "long" :(
// (this means that the file format is platform dependent)
case 14:
{
sal_Int64 n(0);
rStream.ReadInt64(n);
yPos = n;
}
break;
case 10:
{
sal_Int32 n(0);
rStream.ReadInt32(n);
yPos = n;
}
break;
default:
SAL_WARN("sw.core", "SwFormatVertOrient::Create: unknown size");
}
rStream.ReadInt16( orient ).ReadInt16( relation );
return new SwFormatVertOrient(yPos, orient, relation);