[Libreoffice-commits] core.git: 3 commits - sw/inc sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Dec 8 01:09:22 PST 2015


 sw/inc/hintids.hxx                   |    1 
 sw/source/filter/basflt/fltshell.cxx |   14 ++-
 sw/source/filter/ww8/ww8par.hxx      |    1 
 sw/source/filter/ww8/ww8par5.cxx     |   12 ++
 sw/source/filter/ww8/ww8par6.cxx     |    3 
 sw/source/filter/ww8/ww8scan.cxx     |  141 ++++++++++++++++++++++++++++++++++-
 sw/source/filter/ww8/ww8scan.hxx     |   39 ++++++++-
 7 files changed, 204 insertions(+), 7 deletions(-)

New commits:
commit ab94f468a2b2b1b9e2a621e33f9175171caec252
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Dec 8 09:26:00 2015 +0100

    DOC import: handle smart tags via RES_FLTR_RDFMARK
    
    The idea is that a subset of the smart tags will be mapped to RDF
    statements, as done already in the DOCX importer.
    
    Change-Id: I46e0dad37a3905fe591cba0f710156f27be05ff4

diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 0d2fb99..0b18e4b 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1701,6 +1701,7 @@ public:     // really private, but can only be done public
     long Read_Book(WW8PLCFManResult*);
     long Read_And(WW8PLCFManResult* pRes);
     long Read_AtnBook(WW8PLCFManResult*);
+    long Read_FactoidBook(WW8PLCFManResult*);
 
     // attributes
 
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 77960c9..18747c3 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -242,6 +242,18 @@ long SwWW8ImplReader::Read_AtnBook(WW8PLCFManResult*)
     return 0;
 }
 
+long SwWW8ImplReader::Read_FactoidBook(WW8PLCFManResult*)
+{
+    if (WW8PLCFx_FactoidBook* pFactoidBook = m_pPlcxMan->GetFactoidBook())
+    {
+        if (pFactoidBook->getIsEnd())
+            m_pReffedStck->SetAttr(*m_pPaM->GetPoint(), RES_FLTR_RDFMARK, true, pFactoidBook->getHandle());
+        else
+            m_pReffedStck->NewAttr(*m_pPaM->GetPoint(), CntUInt16Item(RES_FLTR_RDFMARK, pFactoidBook->getHandle()));
+    }
+    return 0;
+}
+
 //    general help methods to separate parameters
 
 /// translate FieldParameter names into the system character set and
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 79ecd45..2a9da61 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -5033,7 +5033,8 @@ long SwWW8ImplReader::ImportExtSprm(WW8PLCFManResult* pRes)
         /* 2 (258) */   &SwWW8ImplReader::Read_Field,  // Feld
         /* 3 (259) */   &SwWW8ImplReader::Read_Book,   // Bookmark
         /* 4 (260) */   &SwWW8ImplReader::Read_And,     // Annotation
-        /* 5 (261) */   &SwWW8ImplReader::Read_AtnBook // Annotationmark
+        /* 5 (261) */   &SwWW8ImplReader::Read_AtnBook, // Annotationmark
+        /* 6 (262) */   &SwWW8ImplReader::Read_FactoidBook // Smart tag bookmark
     };
 
     if( pRes->nSprmId < 280 )
commit f30ea8d91ca8e2f938632755d3bdfbd2e181e006
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Dec 8 09:14:11 2015 +0100

    DOC import: tokenize PlcfBkfFactoid and PlcfBklFactoid
    
    So that later SwWW8ImplReader can read these smart tag position
    structures in a way similar to bookmarks.
    
    Change-Id: I0e1dc30d48bbb6641a82d777f6569f59dd922e16

diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index 491adec..aac1f2c 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -1703,6 +1703,7 @@ WW8ScannerBase::WW8ScannerBase( SvStream* pSt, SvStream* pTableSt,
 
     pBook = new WW8PLCFx_Book(pTableSt, *pWwFib);
     pAtnBook = new WW8PLCFx_AtnBook(pTableSt, *pWwFib);
+    pFactoidBook = new WW8PLCFx_FactoidBook(pTableSt, *pWwFib);
 }
 
 WW8ScannerBase::~WW8ScannerBase()
@@ -4339,6 +4340,138 @@ bool WW8PLCFx_AtnBook::getIsEnd() const
     return m_bIsEnd;
 }
 
+WW8PLCFx_FactoidBook::WW8PLCFx_FactoidBook(SvStream* pTableSt, const WW8Fib& rFib)
+    : WW8PLCFx(rFib.GetFIBVersion(), /*bSprm=*/false),
+    m_bIsEnd(false)
+{
+    if (!rFib.fcPlcfBkfFactoid || !rFib.lcbPlcfBkfFactoid || !rFib.fcPlcfBklFactoid || !rFib.lcbPlcfBklFactoid)
+    {
+        m_pBook[0] = m_pBook[1] = nullptr;
+        m_nIMax = 0;
+    }
+    else
+    {
+        m_pBook[0] = new WW8PLCFspecial(pTableSt, rFib.fcPlcfBkfFactoid, rFib.lcbPlcfBkfFactoid, 6);
+        m_pBook[1] = new WW8PLCFspecial(pTableSt, rFib.fcPlcfBklFactoid, rFib.lcbPlcfBklFactoid, 4);
+
+        m_nIMax = m_pBook[0]->GetIMax();
+        if (m_pBook[1]->GetIMax() < m_nIMax)
+            m_nIMax = m_pBook[1]->GetIMax();
+    }
+}
+
+WW8PLCFx_FactoidBook::~WW8PLCFx_FactoidBook()
+{
+    delete m_pBook[1];
+    delete m_pBook[0];
+}
+
+sal_uInt32 WW8PLCFx_FactoidBook::GetIdx() const
+{
+    return m_nIMax ? m_pBook[0]->GetIdx() : 0;
+}
+
+void WW8PLCFx_FactoidBook::SetIdx(sal_uLong nI)
+{
+    if (m_nIMax)
+        m_pBook[0]->SetIdx(nI);
+}
+
+sal_uLong WW8PLCFx_FactoidBook::GetIdx2() const
+{
+    if (m_nIMax)
+        return m_pBook[1]->GetIdx() | (m_bIsEnd ? 0x80000000 : 0);
+    else
+        return 0;
+}
+
+void WW8PLCFx_FactoidBook::SetIdx2(sal_uLong nI)
+{
+    if (m_nIMax)
+    {
+        m_pBook[1]->SetIdx(nI & 0x7fffffff);
+        m_bIsEnd = static_cast<bool>((nI >> 31) & 1);
+    }
+}
+
+bool WW8PLCFx_FactoidBook::SeekPos(WW8_CP nCpPos)
+{
+    if (!m_pBook[0])
+        return false;
+
+    bool bOk = m_pBook[0]->SeekPosExact(nCpPos);
+    bOk &= m_pBook[1]->SeekPosExact(nCpPos);
+    m_bIsEnd = false;
+
+    return bOk;
+}
+
+WW8_CP WW8PLCFx_FactoidBook::Where()
+{
+    return m_pBook[static_cast<int>(m_bIsEnd)]->Where();
+}
+
+long WW8PLCFx_FactoidBook::GetNoSprms(WW8_CP& rStart, WW8_CP& rEnd, sal_Int32& rLen)
+{
+    void* pData;
+    rEnd = WW8_CP_MAX;
+    rLen = 0;
+
+    if (!m_pBook[0] || !m_pBook[1] || !m_nIMax || (m_pBook[static_cast<int>(m_bIsEnd)]->GetIdx()) >= m_nIMax)
+    {
+        rStart = rEnd = WW8_CP_MAX;
+        return -1;
+    }
+
+    (void)m_pBook[static_cast<int>(m_bIsEnd)]->Get(rStart, pData);
+    return m_pBook[static_cast<int>(m_bIsEnd)]->GetIdx();
+}
+
+void WW8PLCFx_FactoidBook::advance()
+{
+    if (m_pBook[0] && m_pBook[1] && m_nIMax)
+    {
+        (*m_pBook[static_cast<int>(m_bIsEnd)]).advance();
+
+        sal_uLong l0 = m_pBook[0]->Where();
+        sal_uLong l1 = m_pBook[1]->Where();
+        if (l0 < l1)
+            m_bIsEnd = false;
+        else if (l1 < l0)
+            m_bIsEnd = true;
+        else
+        {
+            const void * p = m_pBook[0]->GetData(m_pBook[0]->GetIdx());
+            long nPairFor = (p == nullptr)? 0L : SVBT16ToShort(*static_cast<SVBT16 const *>(p));
+            if (nPairFor == m_pBook[1]->GetIdx())
+                m_bIsEnd = false;
+            else
+                m_bIsEnd = !m_bIsEnd;
+        }
+    }
+}
+
+long WW8PLCFx_FactoidBook::getHandle() const
+{
+    if (!m_pBook[0] || !m_pBook[1])
+        return LONG_MAX;
+
+    if (m_bIsEnd)
+        return m_pBook[1]->GetIdx();
+    else
+    {
+        if (const void* p = m_pBook[0]->GetData(m_pBook[0]->GetIdx()))
+            return SVBT16ToShort(*(static_cast<const SVBT16*>(p)));
+        else
+            return LONG_MAX;
+    }
+}
+
+bool WW8PLCFx_FactoidBook::getIsEnd() const
+{
+    return m_bIsEnd;
+}
+
 // In the end of an paragraph in WW6 the attribute extends after the <CR>.
 // This will be reset by one character to be used with SW,
 // if we don't expect trouble thereby.
@@ -4495,6 +4628,7 @@ WW8PLCFMan::WW8PLCFMan(WW8ScannerBase* pBase, ManTypes nType, long nStartCp,
         pPap = &aD[8];
         pSep = &aD[9];
         pAtnBkm = &aD[10];
+        pFactoidBkm = &aD[11];
 
         pSep->pPLCFx = pBase->pSepPLCF;
         pFootnote->pPLCFx = pBase->pFootnotePLCF;
@@ -4502,6 +4636,7 @@ WW8PLCFMan::WW8PLCFMan(WW8ScannerBase* pBase, ManTypes nType, long nStartCp,
         pBkm->pPLCFx = pBase->pBook;
         pAnd->pPLCFx = pBase->pAndPLCF;
         pAtnBkm->pPLCFx = pBase->pAtnBook;
+        pFactoidBkm->pPLCFx = pBase->pFactoidBook;
 
     }
     else
@@ -4519,7 +4654,7 @@ WW8PLCFMan::WW8PLCFMan(WW8ScannerBase* pBase, ManTypes nType, long nStartCp,
         pPap = &aD[5];
         pSep = &aD[6]; // Dummy
 
-        pAnd = pAtnBkm = pFootnote = pEdn = nullptr;     // not used at SpezText
+        pAnd = pAtnBkm = pFactoidBkm = pFootnote = pEdn = nullptr;     // not used at SpezText
     }
 
     pChp->pPLCFx = pBase->pChpPLCF;
@@ -4800,6 +4935,8 @@ void WW8PLCFMan::GetNoSprmStart( short nIdx, WW8PLCFManResult* pRes ) const
         pRes->nSprmId = eBKN;
     else if (p == pAtnBkm)
         pRes->nSprmId = eATNBKN;
+    else if (p == pFactoidBkm)
+        pRes->nSprmId = eFACTOIDBKN;
     else if( p == pAnd )
         pRes->nSprmId = eAND;
     else if( p == pPcd )
@@ -4820,6 +4957,8 @@ void WW8PLCFMan::GetNoSprmEnd( short nIdx, WW8PLCFManResult* pRes ) const
         pRes->nSprmId = eBKN;
     else if (&aD[nIdx] == pAtnBkm)
         pRes->nSprmId = eATNBKN;
+    else if (&aD[nIdx] == pFactoidBkm)
+        pRes->nSprmId = eFACTOIDBKN;
     else if( &aD[nIdx] == pPcd )
     {
         //We slave the piece table attributes to the piece table, the piece
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 36c6062..07f613d 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -364,7 +364,7 @@ public:
 enum ePLCFT{ CHP=0, PAP, SEP, /*HED, FNR, ENR,*/ PLCF_END };
 
 //Its hardcoded that eFTN be the first one: A very poor hack, needs to be fixed
-enum eExtSprm { eFTN = 256, eEDN = 257, eFLD = 258, eBKN = 259, eAND = 260, eATNBKN = 261 };
+enum eExtSprm { eFTN = 256, eEDN = 257, eFLD = 258, eBKN = 259, eAND = 260, eATNBKN = 261, eFACTOIDBKN = 262 };
 
 /*
     pure virtual:
@@ -787,6 +787,36 @@ public:
     bool getIsEnd() const;
 };
 
+/// Handles the import of PlcfBkfFactoid and PlcfBklFactoid: start / end position of factoids.
+class WW8PLCFx_FactoidBook : public WW8PLCFx
+{
+private:
+    /// Start and end positions.
+    WW8PLCFspecial* m_pBook[2];
+    /// Number of factoid marks
+    sal_Int32 m_nIMax;
+    bool m_bIsEnd;
+
+    WW8PLCFx_FactoidBook(const WW8PLCFx_FactoidBook&) = delete;
+    WW8PLCFx_FactoidBook& operator=(const WW8PLCFx_FactoidBook&) = delete;
+
+public:
+    WW8PLCFx_FactoidBook(SvStream* pTableSt,const WW8Fib& rFib);
+    virtual ~WW8PLCFx_FactoidBook();
+    virtual sal_uInt32 GetIdx() const override;
+    virtual void SetIdx(sal_uLong nI) override;
+    virtual sal_uLong GetIdx2() const override;
+    virtual void SetIdx2(sal_uLong nIdx) override;
+    virtual bool SeekPos(WW8_CP nCpPos) override;
+    virtual WW8_FC Where() override;
+    virtual long GetNoSprms(WW8_CP& rStart, WW8_CP& rEnd, sal_Int32& rLen) override;
+    virtual void advance() override;
+
+    /// Handle is the unique ID of a factoid mark.
+    long getHandle() const;
+    bool getIsEnd() const;
+};
+
 /*
     this is what we use outside:
 */
@@ -873,7 +903,7 @@ struct WW8PLCFxSaveAll;
 class WW8PLCFMan
 {
 public:
-    enum WW8PLCFManLimits {MAN_ANZ_PLCF = 11};
+    enum WW8PLCFManLimits {MAN_ANZ_PLCF = 12};
 
 private:
     wwSprmParser maSprmParser;
@@ -890,7 +920,7 @@ private:
 
     WW8PLCFxDesc aD[MAN_ANZ_PLCF];
     WW8PLCFxDesc *pChp, *pPap, *pSep, *pField, *pFootnote, *pEdn, *pBkm, *pPcd,
-        *pPcdA, *pAnd, *pAtnBkm;
+        *pPcdA, *pAnd, *pAtnBkm, *pFactoidBkm;
     WW8PLCFspecial *pFdoa, *pTxbx, *pTxbxBkd,*pMagicTables, *pSubdocs;
     sal_uInt8* pExtendedAtrds;
 
@@ -927,6 +957,7 @@ public:
     WW8PLCFx_SubDoc* GetAtn() const { return static_cast<WW8PLCFx_SubDoc*>(pAnd->pPLCFx); }
     WW8PLCFx_Book* GetBook() const { return static_cast<WW8PLCFx_Book*>(pBkm->pPLCFx); }
     WW8PLCFx_AtnBook* GetAtnBook() const { return static_cast<WW8PLCFx_AtnBook*>(pAtnBkm->pPLCFx); }
+    WW8PLCFx_FactoidBook* GetFactoidBook() const { return static_cast<WW8PLCFx_FactoidBook*>(pFactoidBkm->pPLCFx); }
     long GetCpOfs() const { return pChp->nCpOfs; }  // for Header/Footer...
 
     /* asks, if *current paragraph* has an Sprm of this type */
@@ -1002,6 +1033,8 @@ private:
     sal_uInt8*        pExtendedAtrds;   // Extended ATRDs
     WW8PLCFx_Book*    pBook;            // Bookmarks
     WW8PLCFx_AtnBook* pAtnBook;         // Annotationmarks
+    /// Smart tag bookmarks.
+    WW8PLCFx_FactoidBook* pFactoidBook;
 
     WW8PLCFpcd*         pPiecePLCF; // for FastSave ( Basis-PLCF without iterator )
     WW8PLCFpcd_Iter*    pPieceIter; // for FastSave ( iterator for previous )
commit 329e762db21f5f1250baf207da1b7b5b7477b4b0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Dec 8 09:09:23 2015 +0100

    sw: add RES_FLTR_RDFMARK
    
    This is similar to RES_FLTR_ANNOTATIONMARK, except that it'll be used
    for WW8 import's smart tag bookmark needs.
    
    First just add code so that WW8 import can put this this attribute on
    the import stack, the actual handling of the attribute has to be
    implemented later.
    
    Change-Id: I92e3fac02496e3f5e7a6ea27f0da91dcd47769cc

diff --git a/sw/inc/hintids.hxx b/sw/inc/hintids.hxx
index eccf6a4..fe94004 100644
--- a/sw/inc/hintids.hxx
+++ b/sw/inc/hintids.hxx
@@ -350,6 +350,7 @@ enum RES_FLTRATTR
     RES_FLTR_TOX,
     RES_FLTR_REDLINE,
     RES_FLTR_ANNOTATIONMARK,
+    RES_FLTR_RDFMARK,
     RES_FLTRATTR_END
 };
 
diff --git a/sw/source/filter/basflt/fltshell.cxx b/sw/source/filter/basflt/fltshell.cxx
index becc8ad..97ebd67 100644
--- a/sw/source/filter/basflt/fltshell.cxx
+++ b/sw/source/filter/basflt/fltshell.cxx
@@ -354,7 +354,7 @@ SwFltStackEntry* SwFltControlStack::SetAttr(const SwPosition& rPos,
             }
             else if (nAttrId == rEntry.pAttr->Which())
             {
-                if( nAttrId != RES_FLTR_BOOKMARK && nAttrId != RES_FLTR_ANNOTATIONMARK )
+                if( nAttrId != RES_FLTR_BOOKMARK && nAttrId != RES_FLTR_ANNOTATIONMARK && nAttrId != RES_FLTR_RDFMARK )
                 {
                     // query handle
                     bF = true;
@@ -363,7 +363,7 @@ SwFltStackEntry* SwFltControlStack::SetAttr(const SwPosition& rPos,
                 {
                     bF = true;
                 }
-                else if (nAttrId == RES_FLTR_ANNOTATIONMARK && nHand == static_cast<CntUInt16Item*>(rEntry.pAttr)->GetValue())
+                else if ((nAttrId == RES_FLTR_ANNOTATIONMARK || nAttrId == RES_FLTR_RDFMARK) && nHand == static_cast<CntUInt16Item*>(rEntry.pAttr)->GetValue())
                 {
                     bF = true;
                 }
@@ -610,6 +610,16 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
                 SAL_WARN("sw", "failed to make book region or point");
         }
         break;
+    case RES_FLTR_RDFMARK:
+        {
+            if (MakeBookRegionOrPoint(rEntry, pDoc, aRegion, true))
+            {
+                // TODO handle RDF mark
+            }
+            else
+                SAL_WARN("sw", "failed to make book region or point");
+        }
+        break;
     case RES_FLTR_TOX:
         {
             MakePoint(rEntry, pDoc, aRegion);


More information about the Libreoffice-commits mailing list