1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include "rtflookahead.hxx"
11 #include <com/sun/star/uno/Reference.hxx>
12 #include <tools/stream.hxx>
13 #include "rtftokenizer.hxx"
14 
15 namespace com
16 {
17 namespace sun
18 {
19 namespace star
20 {
21 namespace task
22 {
23 class XStatusIndicator;
24 }
25 }
26 }
27 }
28 
29 using namespace com::sun::star;
30 
31 namespace writerfilter
32 {
33 namespace rtftok
34 {
RTFLookahead(SvStream & rStream,sal_uInt64 nGroupStart)35 RTFLookahead::RTFLookahead(SvStream& rStream, sal_uInt64 nGroupStart)
36     : m_rStream(rStream)
37     , m_bHasTable(false)
38     , m_bHasColumns(false)
39 {
40     sal_uInt64 const nPos = m_rStream.Tell();
41     m_rStream.Seek(nGroupStart);
42     uno::Reference<task::XStatusIndicator> xStatusIndicator;
43     m_pTokenizer = new RTFTokenizer(*this, &m_rStream, xStatusIndicator);
44     m_pTokenizer->resolveParse();
45     m_rStream.Seek(nPos);
46 }
47 
48 RTFLookahead::~RTFLookahead() = default;
49 
dispatchDestination(RTFKeyword)50 RTFError RTFLookahead::dispatchDestination(RTFKeyword /*nKeyword*/) { return RTFError::OK; }
51 
dispatchFlag(RTFKeyword nKeyword)52 RTFError RTFLookahead::dispatchFlag(RTFKeyword nKeyword)
53 {
54     if (nKeyword == RTF_INTBL)
55         m_bHasTable = true;
56     return RTFError::OK;
57 }
58 
dispatchSymbol(RTFKeyword)59 RTFError RTFLookahead::dispatchSymbol(RTFKeyword /*nKeyword*/) { return RTFError::OK; }
60 
dispatchToggle(RTFKeyword,bool,int)61 RTFError RTFLookahead::dispatchToggle(RTFKeyword /*nKeyword*/, bool /*bParam*/, int /*nParam*/)
62 {
63     return RTFError::OK;
64 }
65 
dispatchValue(RTFKeyword nKeyword,int nParam)66 RTFError RTFLookahead::dispatchValue(RTFKeyword nKeyword, int nParam)
67 {
68     if (nKeyword == RTF_COLS && nParam >= 2)
69         m_bHasColumns = true;
70     return RTFError::OK;
71 }
72 
resolveChars(char ch)73 RTFError RTFLookahead::resolveChars(char ch)
74 {
75     while (!m_rStream.eof() && (ch != '{' && ch != '}' && ch != '\\'))
76         m_rStream.ReadChar(ch);
77     if (!m_rStream.eof())
78         m_rStream.SeekRel(-1);
79     return RTFError::OK;
80 }
81 
pushState()82 RTFError RTFLookahead::pushState()
83 {
84     m_pTokenizer->pushGroup();
85     return RTFError::OK;
86 }
87 
popState()88 RTFError RTFLookahead::popState()
89 {
90     m_pTokenizer->popGroup();
91     return RTFError::OK;
92 }
93 
getDestination()94 Destination RTFLookahead::getDestination() { return Destination::NORMAL; }
95 
setDestination(Destination)96 void RTFLookahead::setDestination(Destination /*eDestination*/) {}
97 
getInternalState()98 RTFInternalState RTFLookahead::getInternalState() { return RTFInternalState::NORMAL; }
99 
setInternalState(RTFInternalState)100 void RTFLookahead::setInternalState(RTFInternalState /*nInternalState*/) {}
101 
getSkipUnknown()102 bool RTFLookahead::getSkipUnknown() { return false; }
103 
setSkipUnknown(bool)104 void RTFLookahead::setSkipUnknown(bool /*bSkipUnknown*/) {}
105 
finishSubstream()106 void RTFLookahead::finishSubstream() {}
107 
isSubstream() const108 bool RTFLookahead::isSubstream() const { return false; }
109 
110 } // namespace rtftok
111 } // namespace writerfilter
112 
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
114