31 #include <rtl/tencinfo.h>
34 #include <osl/diagnose.h>
47 #ifdef DEBUGSPRMREADER
63 bool TestBeltAndBraces(
SvStream& rStrm)
66 sal_uInt32 nOldPos = rStrm.
Tell();
77 if (rStrm.
good() && cBraces == 0)
429 for (sal_uInt16
nId = 111;
nId <= 113; ++
nId)
449 InfoRow<NS_sprm::PIstd>(),
450 InfoRow<NS_sprm::PIstdPermute>(),
451 InfoRow<NS_sprm::PIncLvl>(),
454 InfoRow<NS_sprm::PJc80>(),
456 InfoRow<NS_sprm::PFKeep>(),
457 InfoRow<NS_sprm::PFKeepFollow>(),
458 InfoRow<NS_sprm::PFPageBreakBefore>(),
462 InfoRow<NS_sprm::PIlvl>(),
463 InfoRow<NS_sprm::PIlfo>(),
464 InfoRow<NS_sprm::PFNoLineNumb>(),
465 InfoRow<NS_sprm::PChgTabsPapx>(),
467 InfoRow<NS_sprm::PDxaRight80>(),
468 InfoRow<NS_sprm::PDxaLeft80>(),
469 InfoRow<NS_sprm::PNest80>(),
470 InfoRow<NS_sprm::PDxaLeft180>(),
471 InfoRow<NS_sprm::PDyaLine>(),
474 InfoRow<NS_sprm::PDyaBefore>(),
475 InfoRow<NS_sprm::PDyaAfter>(),
476 InfoRow<NS_sprm::PChgTabs>(),
478 InfoRow<NS_sprm::PFInTable>(),
479 InfoRow<NS_sprm::PFTtp>(),
480 InfoRow<NS_sprm::PDxaAbs>(),
481 InfoRow<NS_sprm::PDyaAbs>(),
482 InfoRow<NS_sprm::PDxaWidth>(),
483 InfoRow<NS_sprm::PPc>(),
491 InfoRow<NS_sprm::PWr>(),
492 InfoRow<NS_sprm::PBrcTop80>(),
493 InfoRow<NS_sprm::PBrcLeft80>(),
494 InfoRow<NS_sprm::PBrcBottom80>(),
495 InfoRow<NS_sprm::PBrcRight80>(),
496 InfoRow<NS_sprm::PBrcBetween80>(),
497 InfoRow<NS_sprm::PBrcBar80>(),
498 InfoRow<NS_sprm::PFNoAutoHyph>(),
499 InfoRow<NS_sprm::PWHeightAbs>(),
500 InfoRow<NS_sprm::PDcs>(),
501 InfoRow<NS_sprm::PShd80>(),
502 InfoRow<NS_sprm::PDyaFromText>(),
503 InfoRow<NS_sprm::PDxaFromText>(),
504 InfoRow<NS_sprm::PFLocked>(),
505 InfoRow<NS_sprm::PFWidowControl>(),
507 InfoRow<NS_sprm::PFKinsoku>(),
508 InfoRow<NS_sprm::PFWordWrap>(),
509 InfoRow<NS_sprm::PFOverflowPunct>(),
510 InfoRow<NS_sprm::PFTopLinePunct>(),
511 InfoRow<NS_sprm::PFAutoSpaceDE>(),
512 InfoRow<NS_sprm::PFAutoSpaceDN>(),
513 InfoRow<NS_sprm::PWAlignFont>(),
514 InfoRow<NS_sprm::PFrameTextFlow>(),
520 InfoRow<NS_sprm::POutLvl>(),
522 InfoRow<NS_sprm::PFBiDi>(),
523 InfoRow<NS_sprm::PFNumRMIns>(),
525 InfoRow<NS_sprm::PNumRM>(),
528 InfoRow<NS_sprm::PHugePapx>(),
530 InfoRow<NS_sprm::PFUsePgsuSettings>(),
532 InfoRow<NS_sprm::PFAdjustRight>(),
533 InfoRow<NS_sprm::CFRMarkDel>(),
534 InfoRow<NS_sprm::CFRMarkIns>(),
535 InfoRow<NS_sprm::CFFldVanish>(),
536 InfoRow<NS_sprm::CPicLocation>(),
537 InfoRow<NS_sprm::CIbstRMark>(),
539 InfoRow<NS_sprm::CDttmRMark>(),
540 InfoRow<NS_sprm::CFData>(),
541 InfoRow<NS_sprm::CIdslRMark>(),
545 InfoRow<NS_sprm::CSymbol>(),
547 InfoRow<NS_sprm::CFOle2>(),
550 InfoRow<NS_sprm::CHighlight>(),
555 InfoRow<NS_sprm::CIstd>(),
556 InfoRow<NS_sprm::CIstdPermute>(),
558 InfoRow<NS_sprm::CPlain>(),
559 InfoRow<NS_sprm::CKcd>(),
560 InfoRow<NS_sprm::CFBold>(),
561 InfoRow<NS_sprm::CFItalic>(),
562 InfoRow<NS_sprm::CFStrike>(),
563 InfoRow<NS_sprm::CFOutline>(),
564 InfoRow<NS_sprm::CFShadow>(),
565 InfoRow<NS_sprm::CFSmallCaps>(),
566 InfoRow<NS_sprm::CFCaps>(),
567 InfoRow<NS_sprm::CFVanish>(),
569 InfoRow<NS_sprm::CKul>(),
571 InfoRow<NS_sprm::CDxaSpace>(),
573 InfoRow<NS_sprm::CIco>(),
574 InfoRow<NS_sprm::CHps>(),
576 InfoRow<NS_sprm::CHpsPos>(),
578 InfoRow<NS_sprm::CMajority>(),
584 InfoRow<NS_sprm::CIss>(),
587 InfoRow<NS_sprm::CHpsKern>(),
593 InfoRow<NS_sprm::CHresi>(),
594 InfoRow<NS_sprm::CRgFtc0>(),
595 InfoRow<NS_sprm::CRgFtc1>(),
596 InfoRow<NS_sprm::CRgFtc2>(),
597 InfoRow<NS_sprm::CCharScale>(),
598 InfoRow<NS_sprm::CFDStrike>(),
599 InfoRow<NS_sprm::CFImprint>(),
600 InfoRow<NS_sprm::CFSpec>(),
601 InfoRow<NS_sprm::CFObj>(),
602 InfoRow<NS_sprm::CPropRMark90>(),
604 InfoRow<NS_sprm::CFEmboss>(),
605 InfoRow<NS_sprm::CSfxText>(),
606 InfoRow<NS_sprm::CFBiDi>(),
608 InfoRow<NS_sprm::CFBoldBi>(),
609 InfoRow<NS_sprm::CFItalicBi>(),
610 InfoRow<NS_sprm::CFtcBi>(),
611 InfoRow<NS_sprm::CLidBi>(),
612 InfoRow<NS_sprm::CIcoBi>(),
613 InfoRow<NS_sprm::CHpsBi>(),
614 InfoRow<NS_sprm::CDispFldRMark>(),
616 InfoRow<NS_sprm::CIbstRMarkDel>(),
618 InfoRow<NS_sprm::CDttmRMarkDel>(),
619 InfoRow<NS_sprm::CBrc80>(),
620 InfoRow<NS_sprm::CShd80>(),
621 InfoRow<NS_sprm::CIdslRMarkDel>(),
624 InfoRow<NS_sprm::CFUsePgsuSettings>(),
627 InfoRow<NS_sprm::CRgLid0_80>(),
628 InfoRow<NS_sprm::CRgLid1_80>(),
629 InfoRow<NS_sprm::CIdctHint>(),
634 InfoRow<NS_sprm::PicBrcTop80>(),
635 InfoRow<NS_sprm::PicBrcLeft80>(),
636 InfoRow<NS_sprm::PicBrcBottom80>(),
637 InfoRow<NS_sprm::PicBrcRight80>(),
638 InfoRow<NS_sprm::ScnsPgn>(),
639 InfoRow<NS_sprm::SiHeadingPgn>(),
642 InfoRow<NS_sprm::SDxaColWidth>(),
643 InfoRow<NS_sprm::SDxaColSpacing>(),
645 InfoRow<NS_sprm::SFEvenlySpaced>(),
646 InfoRow<NS_sprm::SFProtected>(),
647 InfoRow<NS_sprm::SDmBinFirst>(),
648 InfoRow<NS_sprm::SDmBinOther>(),
649 InfoRow<NS_sprm::SBkc>(),
650 InfoRow<NS_sprm::SFTitlePage>(),
651 InfoRow<NS_sprm::SCcolumns>(),
652 InfoRow<NS_sprm::SDxaColumns>(),
654 InfoRow<NS_sprm::SNfcPgn>(),
657 InfoRow<NS_sprm::SFPgnRestart>(),
658 InfoRow<NS_sprm::SFEndnote>(),
659 InfoRow<NS_sprm::SLnc>(),
661 InfoRow<NS_sprm::SNLnnMod>(),
662 InfoRow<NS_sprm::SDxaLnn>(),
663 InfoRow<NS_sprm::SDyaHdrTop>(),
664 InfoRow<NS_sprm::SDyaHdrBottom>(),
665 InfoRow<NS_sprm::SLBetween>(),
666 InfoRow<NS_sprm::SVjc>(),
667 InfoRow<NS_sprm::SLnnMin>(),
668 InfoRow<NS_sprm::SPgnStart97>(),
669 InfoRow<NS_sprm::SBOrientation>(),
671 InfoRow<NS_sprm::SXaPage>(),
672 InfoRow<NS_sprm::SYaPage>(),
673 InfoRow<NS_sprm::SDxaLeft>(),
674 InfoRow<NS_sprm::SDxaRight>(),
675 InfoRow<NS_sprm::SDyaTop>(),
676 InfoRow<NS_sprm::SDyaBottom>(),
677 InfoRow<NS_sprm::SDzaGutter>(),
678 InfoRow<NS_sprm::SDmPaperReq>(),
681 InfoRow<NS_sprm::SFBiDi>(),
683 InfoRow<NS_sprm::SFRTLGutter>(),
685 InfoRow<NS_sprm::SBrcTop80>(),
686 InfoRow<NS_sprm::SBrcLeft80>(),
687 InfoRow<NS_sprm::SBrcBottom80>(),
688 InfoRow<NS_sprm::SBrcRight80>(),
689 InfoRow<NS_sprm::SPgbProp>(),
690 InfoRow<NS_sprm::SDxtCharSpace>(),
691 InfoRow<NS_sprm::SDyaLinePitch>(),
693 InfoRow<NS_sprm::SClm>(),
694 InfoRow<NS_sprm::STextFlow>(),
695 InfoRow<NS_sprm::TJc90>(),
697 InfoRow<NS_sprm::TDxaLeft>(),
698 InfoRow<NS_sprm::TDxaGapHalf>(),
700 InfoRow<NS_sprm::TFCantSplit90>(),
701 InfoRow<NS_sprm::TTableHeader>(),
702 InfoRow<NS_sprm::TFCantSplit>(),
703 InfoRow<NS_sprm::TTableBorders80>(),
706 InfoRow<NS_sprm::TDyaRowHeight>(),
708 InfoRow<NS_sprm::TDefTableShd80>(),
709 InfoRow<NS_sprm::TTlp>(),
710 InfoRow<NS_sprm::TFBiDi>(),
712 InfoRow<NS_sprm::TSetBrc80>(),
713 InfoRow<NS_sprm::TInsert>(),
714 InfoRow<NS_sprm::TDelete>(),
715 InfoRow<NS_sprm::TDxaCol>(),
716 InfoRow<NS_sprm::TMerge>(),
717 InfoRow<NS_sprm::TSplit>(),
721 InfoRow<NS_sprm::TTextFlow>(),
725 InfoRow<NS_sprm::TVertMerge>(),
726 InfoRow<NS_sprm::TVertAlign>(),
727 InfoRow<NS_sprm::CFELayout>(),
728 InfoRow<NS_sprm::PItap>(),
729 InfoRow<NS_sprm::TTableWidth>(),
730 InfoRow<NS_sprm::TDefTableShd>(),
731 InfoRow<NS_sprm::TTableBorders>(),
732 InfoRow<NS_sprm::TBrcTopCv>(),
733 InfoRow<NS_sprm::TBrcLeftCv>(),
734 InfoRow<NS_sprm::TBrcBottomCv>(),
735 InfoRow<NS_sprm::TBrcRightCv>(),
736 InfoRow<NS_sprm::TCellPadding>(),
737 InfoRow<NS_sprm::TCellPaddingDefault>(),
738 {0xD238, { 0,
L_VAR} },
739 InfoRow<NS_sprm::PBrcTop>(),
740 InfoRow<NS_sprm::PBrcLeft>(),
741 InfoRow<NS_sprm::PBrcBottom>(),
742 InfoRow<NS_sprm::PBrcRight>(),
743 InfoRow<NS_sprm::PBrcBetween>(),
744 InfoRow<NS_sprm::TWidthIndent>(),
745 InfoRow<NS_sprm::CRgLid0>(),
746 InfoRow<NS_sprm::CRgLid1>(),
747 {0x6463, { 4,
L_FIX} },
748 InfoRow<NS_sprm::PJc>(),
749 InfoRow<NS_sprm::PDxaRight>(),
750 InfoRow<NS_sprm::PDxaLeft>(),
751 InfoRow<NS_sprm::PDxaLeft1>(),
752 InfoRow<NS_sprm::TFAutofit>(),
753 InfoRow<NS_sprm::TPc>(),
754 InfoRow<NS_sprm::SRsid>(),
755 InfoRow<NS_sprm::SFpc>(),
756 InfoRow<NS_sprm::PFInnerTableCell>(),
757 InfoRow<NS_sprm::PFInnerTtp>(),
758 InfoRow<NS_sprm::TDxaAbs>(),
759 InfoRow<NS_sprm::TDyaAbs>(),
760 InfoRow<NS_sprm::TDxaFromText>(),
761 InfoRow<NS_sprm::CRsidProp>(),
762 InfoRow<NS_sprm::CRsidText>(),
763 InfoRow<NS_sprm::CCv>(),
764 InfoRow<NS_sprm::PShd>(),
765 InfoRow<NS_sprm::PRsid>(),
766 InfoRow<NS_sprm::PTableProps>(),
767 InfoRow<NS_sprm::TWidthBefore>(),
768 InfoRow<NS_sprm::TSetShdTable>(),
769 InfoRow<NS_sprm::TDefTableShdRaw>(),
770 InfoRow<NS_sprm::CShd>(),
771 InfoRow<NS_sprm::SRncFtn>(),
772 InfoRow<NS_sprm::PFDyaBeforeAuto>(),
773 InfoRow<NS_sprm::PFDyaAfterAuto>(),
775 InfoRow<NS_sprm::PFContextualSpacing>(),
785 "Impossible value for version");
800 if (pFound !=
nullptr)
806 "Unknown ww7- sprm, dangerous, report to development");
853 const sal_uInt16
n = SVBT16ToUInt16( *reinterpret_cast<SVBT16*>(p) );
865 sal_uInt32
n = SVBT32ToUInt32( *reinterpret_cast<SVBT32*>(p) );
877 : mrSprmParser(rParser), m_pSprms( pSprms_), m_nRemLen( nLen_)
912 SAL_WARN_IF(!bValid,
"sw.ww8",
"sprm longer than remaining bytes, doc or parser is wrong");
937 if ( !pNextByteMatch || (aSprmResult.
nRemainingData >= 1 && *aSprmResult.
pSprm == *pNextByteMatch) )
955 :
WW8PLCFx(rFib, true), m_pPcdI(pPLCFx_PCD->GetPLCFIter()),
956 m_pPcd(pPLCFx_PCD), mrGrpprls(pBase->m_aPieceGrpprls)
997 const sal_uInt16 nPrm = SVBT16ToUInt16( static_cast<WW8_PCD*>(pData)->prm );
1001 const sal_uInt16 nSprmIdx = nPrm >> 1;
1013 p->
nSprmsLen = SVBT16ToUInt16( pSprms );
1046 static const sal_uInt16 aSprmId[0x80] =
1049 0x0000,0x0000,0x0000,0x0000,
1056 0x260A,0x0000,0x240C,0x0000,
1058 0x0000,0x0000,0x0000,0x0000,
1060 0x0000,0x0000,0x0000,0x0000,
1062 0x2416,0x2417,0x0000,0x0000,
1064 0x0000,0x261B,0x0000,0x0000,
1066 0x0000,0x0000,0x0000,0x0000,
1068 0x0000,0x2423,0x0000,0x0000,
1070 0x0000,0x0000,0x0000,0x0000,
1072 0x242A,0x0000,0x0000,0x0000,
1074 0x0000,0x0000,0x2430,0x2431,
1077 0x0000,0x2433,0x2434,0x2435,
1080 0x2436,0x2437,0x2438,0x0000,
1084 0x0000,0x0800,0x0801,0x0802,
1086 0x0000,0x0000,0x0000,0x0806,
1088 0x0000,0x0000,0x0000,0x080A,
1090 0x0000,0x2A0C,0x0858,0x2859,
1092 0x0000,0x0000,0x0000,0x2A33,
1094 0x0000,0x0835,0x0836,0x0837,
1096 0x0838,0x0839,0x083a,0x083b,
1098 0x083C,0x0000,0x2A3E,0x0000,
1100 0x0000,0x0000,0x2A42,0x0000,
1104 0x2A48,0x0000,0x0000,0x0000,
1106 0x0000,0x0000,0x0000,0x0000,
1108 0x0000,0x0000,0x0000,0x2A53,
1112 0x2640,0x2441,0x0000,0x0000,
1114 0x0000,0x0000,0x0000,0x0000
1118 const sal_uInt16 nSprmId = aSprmId[ nSprmListIdx ];
1139 WW8_CP nStartCp,
bool bVer67P)
1192 OSL_ENSURE(
m_pPcdI ,
"missing pPcdI");
1202 if ( !
m_pPcdI->Get(nCpStart, nCpEnd, pData) )
1204 OSL_ENSURE(
false,
"CurrentPieceStartCp2Fc() with false Cp found (1)" );
1208 OSL_ENSURE( nCp >= nCpStart && nCp < nCpEnd,
1209 "AktPieceCp2Fc() with false Cp found (2)" );
1211 if( nCp < nCpStart )
1216 bool bIsUnicode =
false;
1217 WW8_FC nFC = SVBT32ToUInt32( static_cast<WW8_PCD*>(pData)->fc );
1225 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1231 bFail = o3tl::checked_multiply<WW8_CP>(nDistance, 2, nDistance);
1234 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1243 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1257 rStartPos = pSBase->
WW8Fc2Cp( rStartPos );
1258 rEndPos = pSBase->
WW8Fc2Cp( rEndPos );
1265 if ( !
m_pPcdI->Get( nCpStart, nCpEnd, pData ) )
1267 OSL_ENSURE(
false,
"CurrentPieceStartFc2Cp() - error" );
1270 bool bIsUnicode =
false;
1271 sal_Int32 nFcStart = SVBT32ToUInt32( static_cast<WW8_PCD*>(pData)->fc );
1275 sal_Int32 nUnicodeFactor = bIsUnicode ? 2 : 1;
1277 if( nStartPos < nFcStart )
1278 nStartPos = nFcStart;
1284 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1292 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1300 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1308 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1313 if (nStartPos >= nFcEnd)
1314 nStartPos = nFcEnd - (1 * nUnicodeFactor);
1316 WW8_FC nFcDiff = (nStartPos - nFcStart) / nUnicodeFactor;
1322 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1337 if (_dptLineWidth > 5)
1339 _brcType = _dptLineWidth;
1351 if (brcVer8.
isNil()) {
1352 UInt32ToSVBT32(0,
aBits1);
1353 UInt32ToSVBT32(0xffffffff,
aBits2);
1357 sal_uInt32 _cv = brcVer8.
ico() == 0 ? 0xff000000
1378 short nMSTotalWidth;
1381 nMSTotalWidth =
static_cast<short>(
dptLineWidth()) * 20 / 8;
1392 OSL_FAIL(
"Can't create these from the menus, please report");
1406 if (nMSTotalWidth == 5)
1408 else if (nMSTotalWidth == 10)
1409 nMSTotalWidth = nMSTotalWidth*9/2;
1429 nMSTotalWidth += 45*2;
1434 *pSpace =
static_cast<short>(
dptSpace()) * 20;
1435 return nMSTotalWidth;
1448 return nFallBackCpEnd;
1467 OSL_ENSURE(
false,
"PLCFpcd-WW8Fc2Cp() went wrong" );
1470 sal_Int32 nFcStart = SVBT32ToUInt32( static_cast<WW8_PCD*>(pData)->fc );
1484 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1489 if (o3tl::checked_multiply<WW8_CP>(nLen, 2, nLen))
1491 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1500 if (nFcPos >= nFcStart)
1506 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1514 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1520 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1523 if (nFcPos < nFcEnd)
1528 else if (nFcPos == nFcEnd)
1532 nFallBackCpEnd = nTempCp;
1543 return nFallBackCpEnd;
1549 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1555 nFallBackCpEnd = nFcDiff;
1557 nFallBackCpEnd = (nFcDiff + 1) / 2;
1559 return nFallBackCpEnd;
1567 WW8_CP* pNextPieceCp,
bool* pTestFlag)
const
1576 pIsUnicode = &bIsUnicode;
1579 *pIsUnicode =
false;
1596 OSL_ENSURE(
false,
"Handed over wrong CP to WW8Cp2Fc()" );
1607 OSL_ENSURE(
false,
"PLCFfpcd-Get went wrong" );
1612 *pNextPieceCp = nCpEnd;
1614 nRet = SVBT32ToUInt32( static_cast<WW8_PCD*>(pData)->fc );
1624 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1630 bFail = o3tl::checked_multiply<WW8_CP>(nCpLen, 2, nCpLen);
1633 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1641 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1650 const bool bFail = o3tl::checked_multiply<WW8_CP>(nCpPos, 2, nCpPos);
1653 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1662 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1669 if (nRet < nSmallestPossibleFib)
1671 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
1691 sal_Int32 nClxLen = pWwF->
m_lcbClx;
1692 sal_Int32 nLeft = nClxLen;
1712 std::unique_ptr<sal_uInt8[]>
p(
new sal_uInt8[nLen+2]);
1713 ShortToSVBT16(nLen, p.get());
1728 sal_Int32 nPLCFfLen(0);
1731 sal_Int16 nWordTwoLen(0);
1733 nPLCFfLen = nWordTwoLen;
1737 OSL_ENSURE( 65536 > nPLCFfLen,
"PLCFfpcd above 64 k" );
1738 return std::make_unique<WW8PLCFpcd>( pStr, pStr->
Tell(), nPLCFfLen, 8 );
1849 sal_uInt64
const nOldPos = pTableSt->
Tell();
1857 pTableSt->
Seek(nOldPos);
1862 OSL_ENSURE(
false,
"nVersion not implemented!" );
1926 if (!rPLCF.
Get(nP, pData))
1931 if((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) != 0x13 )
1934 if( !rPLCF.
Get( nP, pData ) )
1937 while((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x13 )
1941 if( !rPLCF.
Get( nP, pData ) )
1945 if((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x14 )
1951 if( !rPLCF.
Get( nP, pData ) )
1954 while ((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x13)
1958 if( !rPLCF.
Get( nP, pData ) )
1970 sal_uInt32 nOldIdx = rPLCF.
GetIdx();
1980 if (!pData || (static_cast<sal_uInt8*>(pData)[0] & 0x1f) != 0x13)
1995 while((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x13 )
2004 if ((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x14 )
2011 while((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x13 )
2020 if (o3tl::checked_sub<WW8_CP>(rF.
nLRes, rF.
nSCode, nTmp))
2025 if (o3tl::checked_add<WW8_CP>(nTmp, 2, rF.
nLen))
2031 if (o3tl::checked_add<WW8_CP>(rF.
nSRes, 1, rF.
nSRes))
2040 if (o3tl::checked_sub<WW8_CP>(rF.
nSRes, rF.
nSCode, nTmp))
2045 if (o3tl::checked_add<WW8_CP>(nTmp, 2, rF.
nLen))
2059 if((static_cast<sal_uInt8*>(pData)[0] & 0x1f ) == 0x15 )
2095 if (nCurrentStartCp < 0 || nTotalLen < 0)
2098 WW8_CP nBehindTextCp = nCurrentStartCp + nTotalLen;
2099 WW8_CP nNextPieceCp = nBehindTextCp;
2103 bool bIsUnicode(
false), bPosOk(
false);
2104 WW8_FC fcAct =
WW8Cp2Fc(nCurrentStartCp,&bIsUnicode,&nNextPieceCp,&bPosOk);
2114 WW8_CP nEnd = (nNextPieceCp < nBehindTextCp) ? nNextPieceCp
2129 nCurrentStartCp += nLen;
2130 if ( nTotalRead != rStr.getLength() )
2133 while( nTotalRead < nTotalLen );
2135 return rStr.getLength();
2139 sal_uInt32 nPLCF, sal_uInt32 nStruct)
2140 : m_nIdx(0), m_nStru(nStruct)
2142 const sal_uInt32 nValidMin=4;
2144 sal_uInt64
const nOldPos = pSt->
Tell();
2146 bool bValid =
checkSeek(*pSt, nFilePos);
2148 if( nRemainingSize < nValidMin || nPLCF < nValidMin )
2150 nPLCF = bValid ?
std::min(nRemainingSize, static_cast<std::size_t>(nPLCF)) : nValidMin;
2158 nPLCF = std::max(nPLCF, nValidMin);
2160 m_nIMax = ( nPLCF - 4 ) / ( 4 + nStruct );
2161 #ifdef OSL_BIGENDIAN
2162 for( nIdx = 0; nIdx <= nIMax; nIdx++ )
2163 pPLCF_PosArray[nIdx] = OSL_SWAPDWORD( pPLCF_PosArray[nIdx] );
2165 #endif // OSL_BIGENDIAN
2193 for(
int n = (1==
m_nIdx ? 1 : 2);
n; --
n )
2195 for( ; nI <=nEnd; ++nI)
2227 for(
int n = (0==m_nIdx ? 1 : 2);
n; --
n )
2229 for( ; nI < nEnd; ++nI)
2265 WW8_CP nStartPos) : m_nIdx(0), m_nStru(nStruct)
2269 SAL_WARN(
"sw.ww8",
"broken WW8PLCF, ignoring");
2273 m_nIMax = (nPLCF - 4) / (4 + nStruct);
2277 if( nStartPos >= 0 )
2287 WW8_CP nStartPos, sal_Int32 nPN, sal_Int32 ncpN): m_nIdx(0),
2292 SAL_WARN(
"sw.ww8",
"broken WW8PLCF, ignoring");
2296 m_nIMax = (nPLCF - 4) / (4 + nStruct);
2303 if( nStartPos >= 0 )
2309 sal_uInt64
const nOldPos = rSt.
Tell();
2310 bool bValid = nPLCF != 0 &&
checkSeek(rSt, nFilePos)
2316 const size_t nEntries = (nPLCF + 3) / 4;
2319 size_t nBytesAllocated = nEntries *
sizeof(
WW8_CP);
2320 if (bValid && nPLCF != nBytesAllocated)
2323 memset(pStartBlock + nPLCF, 0, nBytesAllocated - nPLCF);
2329 #ifdef OSL_BIGENDIAN
2330 for( nIdx = 0; nIdx <= nIMax; nIdx++ )
2331 pPLCF_PosArray[nIdx] = OSL_SWAPDWORD( pPLCF_PosArray[nIdx] );
2333 #endif // OSL_BIGENDIAN
2340 OSL_ENSURE(bValid,
"Document has corrupt PLCF, ignoring it");
2358 sal_Int32 TruncToSortedRange(
const sal_Int32* pPLCF_PosArray, sal_Int32 nIMax)
2362 for (
auto nI = 0; nI < nIMax; ++nI)
2364 if (pPLCF_PosArray[nI] > pPLCF_PosArray[nI+1])
2366 SAL_WARN(
"sw.ww8",
"Document has unsorted PLCF, truncated to sorted portion");
2387 OSL_ENSURE(
m_nIMax < ncpN,
"Pcl.Fkp: Why is PLCF too big?" );
2389 bool failure =
false;
2405 size_t nElems = ( nSiz + 3 ) / 4;
2408 for (sal_Int32
i = 0;
i < ncpN && !failure; ++
i)
2430 std::size_t nLastFkpPos = nPN +
m_nIMax - 1;
2431 nLastFkpPos = nLastFkpPos << 9;
2439 if (!
checkSeek(rSt, nLastFkpPos + nb * 4))
2456 for (sal_Int32
i = 0;
i < ncpN; ++
i)
2458 ShortToSVBT16(o3tl::narrowing<sal_uInt16>(nPN +
i), p);
2463 SAL_WARN_IF(failure,
"sw.ww8",
"Document has corrupt PLCF, ignoring it");
2487 for(
int n = (1==
m_nIdx ? 1 : 2);
n; --
n )
2489 for( ; nI <=nEnd; ++nI)
2527 sal_uInt32 nPLCF, sal_uInt32 nStruct)
2528 : m_nStru( nStruct )
2530 const sal_uInt32 nValidMin=4;
2532 sal_uInt64
const nOldPos = pSt->
Tell();
2534 bool bValid =
checkSeek(*pSt, nFilePos);
2536 if( nRemainingSize < nValidMin || nPLCF < nValidMin )
2538 nPLCF = bValid ?
std::min(nRemainingSize, static_cast<std::size_t>(nPLCF)) : nValidMin;
2544 nPLCF = std::max(nPLCF, nValidMin);
2546 m_nIMax = ( nPLCF - 4 ) / ( 4 + nStruct );
2547 #ifdef OSL_BIGENDIAN
2549 pPLCF_PosArray[nI] = OSL_SWAPDWORD( pPLCF_PosArray[nI] );
2550 #endif // OSL_BIGENDIAN
2556 pSt->
Seek( nOldPos );
2561 :m_rPLCF( rPLCFpcd ), m_nIdx( 0 )
2563 if( nStartPos >= 0 )
2583 for(
int n = (1==
m_nIdx ? 1 : 2);
n; --
n )
2585 for( ; nI <=nEnd; ++nI)
2621 bool WW8PLCFx_Fc_FKP::WW8Fkp::Entry::operator<
2624 return (mnFC < rSecond.mnFC);
2634 return 0x646B == nSpId;
2638 std::size_t nDataOffset, sal_uInt16 nLen)
2640 bool bValidPos = (nDataOffset <
sizeof(
maRawData));
2642 OSL_ENSURE(bValidPos,
"sprm sequence offset is out of range, ignoring");
2650 const sal_uInt16 nAvailableData =
sizeof(
maRawData)-nDataOffset;
2651 OSL_ENSURE(nLen <= nAvailableData,
"sprm sequence len is out of range, clipping");
2659 : m_nItemSize(nItemSiz), m_nFilePos(_nFilePos),
mnIdx(0),
m_ePLCF(ePl)
2660 , mnMustRemainCached(0), maSprmParser(rFib)
2666 sal_uInt64
const nOldPos = pSt->
Tell();
2675 const size_t nRawDataStart = (
mnIMax + 1) * 4;
2682 if (nRawDataOffset >= 511)
2688 unsigned int nOfs =
maRawData[nRawDataOffset] * 2;
2702 std::size_t nDataOffset = nOfs + 1;
2709 std::vector<sal_uInt8> aSprms =
ChpxToSprms(aChpx);
2710 aEntry.
mnLen =
static_cast< sal_uInt16
>(aSprms.size());
2714 memcpy(aEntry.
mpData, aSprms.data(), aEntry.
mnLen);
2735 if (aEntry.
mnLen >= 1)
2739 if (aEntry.
mnLen >= 6)
2743 unsigned int nOffset = nOfs + 8;
2748 if (nOffset + aEntry.
mnLen > 512)
2749 aEntry.
mnLen = 512 - nOffset;
2759 if (aEntry.
mnLen >= 2)
2762 std::size_t nDataOffset = nOfs + 1 + nDelta;
2764 SVBT16ToUInt16(
maRawData+nDataOffset) : 0;
2769 nDataOffset +=
sizeof(aEntry.
mnIStd);
2778 const sal_uInt16 nSpId = aEntry.
mnLen
2788 = aEntry.
mpData ==
nullptr ?
nullptr : aEntry.
mpData + 2;
2790 if (pStartData !=
nullptr && pStartData > pLastValidDataPos)
2791 pStartData =
nullptr;
2794 sal_uInt32 nCurr = pDataSt->
Tell();
2795 sal_uInt32
nPos = SVBT32ToUInt32(pStartData);
2807 const sal_uInt16 nOrigLen = bExpand ? aEntry.
mnLen : 0;
2810 aEntry.
mnLen = nLen;
2817 pDataSt->
Seek( nCurr );
2822 pOrigData, nOrigLen);
2830 OSL_FAIL(
"sweet god, what have you done!");
2837 #ifdef DEBUGSPRMREADER
2866 : mnFC(rEntry.mnFC), mnLen(rEntry.mnLen), mnIStd(rEntry.mnIStd),
2867 mbMustDelete(rEntry.mbMustDelete)
2881 if (
this == &rEntry)
2888 mnLen = rEntry.
mnLen;
2895 memcpy(mpData, rEntry.
mpData, mnLen);
2933 for( ; nI <=nEnd; ++nI)
2989 return aIter.
FindSprm(nId, bFindFirst);
2993 std::vector<SprmResult> &rResult)
3022 OSL_ENSURE(
false,
"Called wrong GetSprms" );
3031 OSL_ENSURE(
false,
"Called wrong GetNoSprms" );
3055 bool operator()(
const std::unique_ptr<WW8PLCFx_Fc_FKP::WW8Fkp>& pFkp)
3056 {
return mnPo == pFkp->GetFilePos();}
3063 WW8_CP nPLCFStart, nPLCFEnd;
3066 static const int WW8FkpSizeTabVer2[
PLCF_END ] =
3070 static const int WW8FkpSizeTabVer6[
PLCF_END ] =
3074 static const int WW8FkpSizeTabVer8[
PLCF_END ] =
3078 const int* pFkpSizeTab;
3084 pFkpSizeTab = WW8FkpSizeTabVer2;
3088 pFkpSizeTab = WW8FkpSizeTabVer6;
3091 pFkpSizeTab = WW8FkpSizeTabVer8;
3095 OSL_ENSURE(
false,
"nVersion not implemented!" );
3099 if (!
m_pPLCF->Get( nPLCFStart, nPLCFEnd, pPage ))
3105 tools::Long nPo = SVBT16ToUInt16( static_cast<sal_uInt8 *>(pPage) );
3109 if (nCurrentFkpFilePos == nPo)
3169 sal_uInt32
u =
m_pPLCF->GetIdx() << 8;
3177 if( !( nIdx & 0xffffff00L ) )
3185 m_pPLCF->SetIdx( ( nIdx >> 8 ) - 1 );
3200 bool bRet =
m_pPLCF->SeekPos(nFcPos);
3203 WW8_CP nPLCFStart, nPLCFEnd;
3207 tools::Long nPo = SVBT16ToUInt16( static_cast<sal_uInt8 *>(pPage) );
3272 OSL_FAIL(
"+Problem: GetPCDSprms: NewFkp necessary (not possible!)" );
3285 OSL_FAIL(
"+Motz: HasSprm: NewFkp needed ( no const possible )" );
3305 aRes = aIter.FindSprm(nId, bFindFirst);
3317 OSL_FAIL(
"+Motz: HasSprm: NewFkp needed ( no const possible )" );
3351 rBase.WW8Cp2Fc(0)), m_rSBase(rBase), m_nAttrStart(-1), m_nAttrEnd(-1),
3353 m_bComplex( (7 < rBase.m_pWw8Fib->m_nVersion) || rBase.m_pWw8Fib->m_fComplex )
3395 if( !
m_pPcd->SeekPos( nCpPos ) )
3409 return m_pPcd->CurrentPieceStartFc2Cp( nFc );
3453 bool bIsUnicode=
false;
3487 void*
pData=
nullptr;
3496 WW8_FC nLimitFC = SVBT32ToUInt32( static_cast<WW8_PCD*>(pData)->fc );
3497 WW8_FC nBeginLimitFC = nLimitFC;
3509 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3517 bFail = o3tl::checked_multiply<WW8_CP>(nCpLen, 2, nCpLen);
3520 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3530 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3536 if (nOldEndPos <= nLimitFC)
3541 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3547 nCpLen /= (bIsUnicode ? 2 : 1);
3552 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3588 OSL_ENSURE(
false,
"piece iter broken!" );
3592 sal_Int32 nFcStart=SVBT32ToUInt32(static_cast<WW8_PCD*>(pData)->fc);
3598 nFcStart,bIsUnicode );
3604 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3611 bFail = o3tl::checked_multiply<WW8_CP>(nCpLen, 2, nCpLen);
3614 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3623 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3636 if (nSmallest <= nLimitFC)
3642 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3653 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3658 OSL_ENSURE(nEndPos >= p->
nStartPos,
"EndPos before StartPos");
3711 :
WW8PLCFx(rFib, true), maSprmParser(rFib),
3712 m_pStrm(pSt), m_nArrMax(256), m_nSprmSiz(0)
3760 sal_uInt32 nPo = SVBT32ToUInt32( static_cast<sal_uInt8*>(pData)+2 );
3827 bool bFound =
false;
3837 bool bValid = x <= nRemLen;
3840 SAL_WARN(
"sw.ww8",
"sprm longer than remaining bytes, doc or parser is wrong");
3844 if( nCurrentId == nId1 )
3847 r1 =
SprmResult(pSp + nFixedLen, x - nFixedLen);
3849 else if( nCurrentId == nId2 )
3852 r2 =
SprmResult(pSp + nFixedLen, x - nFixedLen);
3854 else if( nCurrentId == nId3 )
3857 r3 =
SprmResult(pSp + nFixedLen, x - nFixedLen);
3859 else if( nCurrentId == nId4 )
3862 r4 =
SprmResult(pSp + nFixedLen, x - nFixedLen);
3880 aRet = aIter.FindSprm(nId,
true, &n2nd);
3890 if( nLenRef && nLenText )
3892 m_pRef.reset(
new WW8PLCF(*pSt, nFcRef, nLenRef, nStruct, nStartCp));
3893 m_pText.reset(
new WW8PLCF(*pSt, nFcText, nLenText, 0, nStartCp));
3915 m_pRef->SetIdx( nIdx >> 16 );
3917 m_pText->SetIdx( nIdx & 0xFFFF );
3941 sal_uInt32 nNr =
m_pRef->GetIdx();
3953 SAL_WARN(
"sw.ww8",
"broken offset, ignoring");
3972 SAL_WARN(
"sw.ww8",
"Document has invalid Cp or Idx, ignoring it");
3992 :
WW8PLCFx(rMyFib, true), m_rFib(rMyFib)
4077 if (
m_pPLCF->Get(nTest, pData) && ((
static_cast<sal_uInt8*
>(pData)[0] & 0x1f) == 0x15) )
4153 sal_uInt16 nExtraLen, rtl_TextEncoding eCS, std::vector<OUString> &rArray,
4154 std::vector<ww::bytes>* pExtraArray, std::vector<OUString>* pValueArray)
4159 sal_uInt64
const nOldPos = rStrm.
Tell();
4162 sal_uInt16 nLen2(0);
4168 sal_uInt16 nStrings(0);
4169 bool bUnicode = (0xFFFF == nLen2);
4177 const size_t nMinStringLen = bUnicode ?
sizeof(sal_uInt16) :
sizeof(
sal_uInt8);
4178 const size_t nMinRecordSize = nExtraLen + nMinStringLen;
4179 assert(nMinRecordSize != 0 &&
"impossible to be zero");
4180 const size_t nMaxPossibleStrings = rStrm.
remainingSize() / nMinRecordSize;
4181 if (nStrings > nMaxPossibleStrings)
4183 SAL_WARN(
"sw.ww8",
"STTBF claims " << nStrings <<
" entries, but only " << nMaxPossibleStrings <<
" are possible");
4184 nStrings = nMaxPossibleStrings;
4187 if (nExtraLen && nStrings)
4189 const size_t nMaxExtraLen = (rStrm.
remainingSize() - (nStrings * nMinStringLen)) / nStrings;
4190 if (nExtraLen > nMaxExtraLen)
4192 SAL_WARN(
"sw.ww8",
"STTBF claims " << nMaxExtraLen <<
" extra len, but only " << nMaxExtraLen <<
" are possible");
4193 nExtraLen = nMaxExtraLen;
4197 for (sal_uInt16
i=0;
i < nStrings; ++
i)
4204 rArray.push_back(OStringToOUString(aTmp, eCS));
4213 rStrm.
ReadBytes(extraData.data(), nExtraLen);
4214 pExtraArray->push_back(extraData);
4223 for (sal_uInt16
i=0;
i < nStrings; ++
i)
4230 pValueArray->push_back(OStringToOUString(aTmp, eCS));
4239 OSL_ENSURE(nLen2 == nLen,
4240 "Fib length and read length are different");
4245 nLen2 = o3tl::narrowing<sal_uInt16>(nLen);
4248 for( nLen2 -= 2; nRead < nLen2; )
4256 nRead += aTmp.getLength();
4257 rArray.push_back(OStringToOUString(aTmp, eCS));
4260 rArray.emplace_back();
4269 rStrm.
ReadBytes(extraData.data(), nExtraLen);
4270 pExtraArray->push_back(extraData);
4279 rStrm.
Seek(nOldPos);
4335 m_pBook[1]->SetIdx( nI & 0x7fffffff );
4336 m_nIsEnd = o3tl::narrowing<sal_uInt16>( ( nI >> 31 ) & 1 );
4345 bool bOk =
m_pBook[0]->SeekPosExact( nCpPos );
4346 bOk &=
m_pBook[1]->SeekPosExact( nCpPos );
4402 tools::Long nPairFor = (p ==
nullptr) ? 0 : SVBT16ToUInt16(*static_cast<SVBT16 const *>(p));
4414 OSL_ENSURE(
false,
"Incorrect call (1) of PLCF_Book::GetLen()" );
4421 OSL_ENSURE(
false,
"Incorrect call (2) of PLCF_Book::GetLen()" );
4424 const sal_uInt16 nEndIdx = SVBT16ToUInt16( *static_cast<SVBT16*>(p) );
4433 "bookmark index " << nIndex <<
" invalid");
4456 return SVBT16ToUInt16( *static_cast<SVBT16 const *>(
p) );
4464 bool bFound =
false;
4468 WW8_CP nStartCurrent, nEndCurrent;
4475 nEndIdx = SVBT16ToUInt16( *static_cast<SVBT16*>(p) );
4478 OSL_ENSURE(
false,
"Bookmark-EndIdx not readable" );
4482 nEndCurrent =
m_pBook[1]->GetPos( nEndIdx );
4484 if ((nStartCurrent >= nStart) && (nEndCurrent <= nEnd))
4498 OUString aRet(rSuggestedName.isEmpty() ? OUString(
"Unnamed") : rSuggestedName);
4504 sal_Int32 len = aRet.getLength();
4505 sal_Int32
p = len - 1;
4506 while (p > 0 && aRet[p] >=
'0' && aRet[p] <=
'9')
4508 aRet = aRet.subView(0, p+1) + OUString::number(
m_nBookmarkId++);
4536 const OUString *pRet =
nullptr;
4588 m_pBook[1]->SetIdx( nI & 0x7fffffff );
4589 m_bIsEnd =
static_cast<bool>(( nI >> 31 ) & 1);
4598 bool bOk =
m_pBook[0]->SeekPosExact(nCpPos);
4599 bOk &=
m_pBook[1]->SeekPosExact(nCpPos);
4642 tools::Long nPairFor = (p ==
nullptr) ? 0 : SVBT16ToUInt16(*static_cast<SVBT16 const *>(p));
4660 return SVBT16ToUInt16(*static_cast<const SVBT16*>(
p));
4717 m_pBook[1]->SetIdx(nI & 0x7fffffff);
4718 m_bIsEnd =
static_cast<bool>((nI >> 31) & 1);
4727 bool bOk =
m_pBook[0]->SeekPosExact(nCpPos);
4728 bOk &=
m_pBook[1]->SeekPosExact(nCpPos);
4771 tools::Long nPairFor = (p ==
nullptr) ? 0 : SVBT16ToUInt16(*static_cast<SVBT16 const *>(p));
4789 return SVBT16ToUInt16(*static_cast<const SVBT16*>(
p));
4813 SAL_WARN(
"sw.ww8",
"WW8PLCFxDesc End same as Start, abandoning to avoid looping");
4846 else if (&rDesc ==
m_pSep)
4876 SAL_WARN(
"sw.ww8",
"broken subdocument piece entry");
4927 bool bDoingDrawTextBox)
4928 : maSprmParser(*pBase->m_pWw8Fib),
4930 mbDoingDrawTextBox(bDoingDrawTextBox)