LibreOffice Module lotuswordpro (master) 1
lwpfrib.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 *
31 *
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
38 *
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
60
61#include <memory>
62#include <lwpfrib.hxx>
63#include "lwphyperlinkmgr.hxx"
69#include "lwpfribheader.hxx"
70#include "lwpfribtext.hxx"
71#include "lwpfribtable.hxx"
72#include "lwpfribbreaks.hxx"
73#include "lwpfribframe.hxx"
74#include "lwpfribsection.hxx"
75#include "lwpcharacterstyle.hxx"
76#include "lwpfootnote.hxx"
77#include "lwpnotes.hxx"
78#include "lwpfribmark.hxx"
79#include <lwpglobalmgr.hxx>
80
81#include <osl/diagnose.h>
82
84 : m_pFribMap(nullptr)
85 , m_pPara(pPara)
86 , m_pNext(nullptr)
87 , m_nFribType(0)
88 , m_ModFlag(false)
89 , m_nRevisionType(0)
90 , m_bRevisionFlag(false)
91 , m_nEditor(0)
92{
93}
94
96
98 sal_uInt8 editID)
99{
100 //Read Modifier
101 std::unique_ptr<ModifierInfo> xModInfo;
102 if (fribtag & FRIB_TAG_MODIFIER)
103 {
104 xModInfo.reset(new ModifierInfo);
105 xModInfo->CodePage = 0;
106 xModInfo->FontID = 0;
107 xModInfo->RevisionType = 0;
108 xModInfo->RevisionFlag = false;
109 xModInfo->HasCharStyle = false;
110 xModInfo->HasLangOverride = false;
111 xModInfo->HasHighlight = false;
112 ReadModifiers(pObjStrm, xModInfo.get());
113 }
114
115 //Read frib data
116 std::unique_ptr<LwpFrib> newFrib;
117 sal_uInt16 friblen = pObjStrm->QuickReaduInt16();
118 sal_uInt8 fribtype = fribtag & ~FRIB_TAG_TYPEMASK;
119 switch (fribtype)
120 {
121 case FRIB_TAG_INVALID: //fall through
122 case FRIB_TAG_EOP: //fall through
123 default:
124 newFrib.reset(new LwpFrib(pPara));
125 break;
126 case FRIB_TAG_TEXT:
127 {
128 newFrib.reset(new LwpFribText(pPara, (fribtag & FRIB_TAG_NOUNICODE) != 0));
129 break;
130 }
131 case FRIB_TAG_TABLE:
132 newFrib.reset(new LwpFribTable(pPara));
133 break;
134 case FRIB_TAG_TAB:
135 newFrib.reset(new LwpFribTab(pPara));
136 break;
138 newFrib.reset(new LwpFribPageBreak(pPara));
139 break;
140 case FRIB_TAG_FRAME:
141 newFrib.reset(new LwpFribFrame(pPara));
142 break;
144 newFrib.reset(new LwpFribFootnote(pPara));
145 break;
147 newFrib.reset(new LwpFribColumnBreak(pPara));
148 break;
150 newFrib.reset(new LwpFribLineBreak(pPara));
151 break;
153 newFrib.reset(new LwpFribHardSpace(pPara));
154 break;
156 newFrib.reset(new LwpFribSoftHyphen(pPara));
157 break;
159 newFrib.reset(new LwpFribParaNumber(pPara));
160 break;
161 case FRIB_TAG_UNICODE: //fall through
162 case FRIB_TAG_UNICODE2: //fall through
163 case FRIB_TAG_UNICODE3: //fall through
164 newFrib.reset(new LwpFribUnicode(pPara));
165 break;
166 case FRIB_TAG_NOTE:
167 newFrib.reset(new LwpFribNote(pPara));
168 break;
169 case FRIB_TAG_SECTION:
170 newFrib.reset(new LwpFribSection(pPara));
171 break;
173 newFrib.reset(new LwpFribPageNumber(pPara));
174 break;
175 case FRIB_TAG_DOCVAR:
176 newFrib.reset(new LwpFribDocVar(pPara));
177 break;
179 newFrib.reset(new LwpFribBookMark(pPara));
180 break;
181 case FRIB_TAG_FIELD:
182 newFrib.reset(new LwpFribField(pPara));
183 break;
184 case FRIB_TAG_CHBLOCK:
185 newFrib.reset(new LwpFribCHBlock(pPara));
186 break;
188 newFrib.reset(new LwpFribRubyMarker(pPara));
189 break;
191 newFrib.reset(new LwpFribRubyFrame(pPara));
192 break;
193 }
194
195 //Do not know why the fribTag judgment is necessary, to be checked with
196 if (fribtag & FRIB_TAG_MODIFIER)
197 {
198 newFrib->SetModifiers(xModInfo.release());
199 }
200
201 newFrib->m_nFribType = fribtype;
202 newFrib->m_nEditor = editID;
203 newFrib->Read(pObjStrm, friblen);
204 return newFrib.release();
205}
206
207void LwpFrib::Read(LwpObjectStream* pObjStrm, sal_uInt16 len) { pObjStrm->SeekRel(len); }
208
210{
211 if (pModifiers)
212 {
213 m_pModifiers.reset(pModifiers);
214 m_ModFlag = true;
215 if (pModifiers->RevisionFlag)
216 {
217 m_bRevisionFlag = true;
218 m_nRevisionType = pModifiers->RevisionType;
219 }
220 }
221}
222
224{
225 if (!m_pModifiers)
226 return;
227 if (!m_pModifiers->FontID && !m_pModifiers->HasCharStyle && !m_pModifiers->HasHighlight)
228 {
229 m_ModFlag = false;
230 return;
231 }
232 //we only read four modifiers, in these modifiers,CodePage and LangOverride are not styles,
233 //so we can only handle fontid and charstyle, if others, we should not reg style
234 //note by ,1-27
236 XFTextStyle* pStyle = nullptr;
237 m_StyleName.clear();
239 XFTextStyle* pNamedStyle = nullptr;
240 if (m_pModifiers->HasCharStyle && pFoundry)
241 {
242 pNamedStyle = dynamic_cast<XFTextStyle*>(
243 pFoundry->GetStyleManager()->GetStyle(m_pModifiers->CharStyleID));
244 }
245 if (pNamedStyle)
246 {
247 LwpCharacterStyle* pCharStyle = nullptr;
248 if (m_pModifiers->FontID && pFoundry)
249 pCharStyle = dynamic_cast<LwpCharacterStyle*>(m_pModifiers->CharStyleID.obj().get());
250 if (pCharStyle)
251 {
252 std::unique_ptr<XFTextStyle> pNewStyle(new XFTextStyle());
253 *pNewStyle = *pNamedStyle;
254
255 pNewStyle->SetStyleName("");
256 pFont = pFoundry->GetFontManager().CreateOverrideFont(pCharStyle->GetFinalFontID(),
257 m_pModifiers->FontID);
258 pNewStyle->SetFont(pFont);
259 IXFStyleRet aNewStyle = pXFStyleManager->AddStyle(std::move(pNewStyle));
260 m_StyleName = aNewStyle.m_pStyle->GetStyleName();
261 pStyle = dynamic_cast<XFTextStyle*>(aNewStyle.m_pStyle);
262 if (aNewStyle.m_bOrigDeleted)
263 pStyle = nullptr;
264 }
265 else
266 m_StyleName = pNamedStyle->GetStyleName();
267 }
268 else
269 {
270 if (m_pModifiers->FontID && pFoundry)
271 {
272 std::unique_ptr<XFTextStyle> pNewStyle(new XFTextStyle());
273 pFont = pFoundry->GetFontManager().CreateFont(m_pModifiers->FontID);
274 pNewStyle->SetFont(pFont);
275 IXFStyleRet aNewStyle = pXFStyleManager->AddStyle(std::move(pNewStyle));
276 m_StyleName = aNewStyle.m_pStyle->GetStyleName();
277 pStyle = dynamic_cast<XFTextStyle*>(aNewStyle.m_pStyle);
278 if (aNewStyle.m_bOrigDeleted)
279 pStyle = nullptr;
280 }
281 }
282
283 if (!m_pModifiers->HasHighlight)
284 return;
285
286 XFColor aColor = GetHighlightColor(); //right yellow
287 if (pStyle) //change the style directly
288 pStyle->GetFont()->SetBackColor(aColor);
289 else //register a new style
290 {
291 std::unique_ptr<XFTextStyle> pNewStyle(new XFTextStyle());
292
293 if (!m_StyleName.isEmpty())
294 {
295 XFTextStyle* pOldStyle = pXFStyleManager->FindTextStyle(m_StyleName);
296 *pNewStyle = *pOldStyle;
297 pNewStyle->GetFont()->SetBackColor(aColor);
298 }
299 else
300 {
301 pFont = new XFFont;
302 pFont->SetBackColor(aColor);
303 pNewStyle->SetFont(pFont);
304 }
305 m_StyleName = pXFStyleManager->AddStyle(std::move(pNewStyle)).m_pStyle->GetStyleName();
306 }
307}
308
310{
311 for (;;)
312 {
313 bool bFailure;
314
315 // Get the modifier type
316 sal_uInt8 Modifier = pObjStrm->QuickReaduInt8(&bFailure);
317 if (bFailure)
318 break;
319
320 // Stop when we hit the last modifier
321 if (Modifier == FRIB_MTAG_NONE)
322 break;
323
324 // Get the modifier length
325 sal_uInt8 len = pObjStrm->QuickReaduInt8(&bFailure);
326 if (bFailure)
327 break;
328
329 switch (Modifier)
330 {
331 case FRIB_MTAG_FONT:
332 if (len != sizeof(pModInfo->FontID))
333 {
334 OSL_FAIL("FRIB_MTAG_FONT entry wrong size");
335 pObjStrm->SeekRel(len);
336 }
337 else
338 pModInfo->FontID = pObjStrm->QuickReaduInt32();
339 break;
341 pModInfo->HasCharStyle = true;
342 pModInfo->CharStyleID.ReadIndexed(pObjStrm);
343 break;
345 pModInfo->HasLangOverride = true;
346 pModInfo->Language.Read(pObjStrm);
347 break;
349 if (len != sizeof(pModInfo->CodePage))
350 {
351 OSL_FAIL("FRIB_MTAG_CODEPAGE entry wrong size");
352 pObjStrm->SeekRel(len);
353 }
354 else
355 pModInfo->CodePage = pObjStrm->QuickReaduInt16();
356 break;
358 pModInfo->aTxtAttrOverride.Read(pObjStrm);
359 if (pModInfo->aTxtAttrOverride.IsHighlight())
360 pModInfo->HasHighlight = true;
361 break;
363 pModInfo->RevisionType = pObjStrm->QuickReaduInt8();
364 pModInfo->RevisionFlag = true;
365 break;
366 default:
367 pObjStrm->SeekRel(len);
368 break;
369 }
370 // TODO: read the modifier data
371 }
372}
373
379
380void LwpFrib::ConvertChars(XFContentContainer* pXFPara, const OUString& text)
381{
382 if (m_ModFlag)
383 {
384 OUString strStyleName = GetStyleName();
385 XFTextSpan* pSpan = new XFTextSpan(text, strStyleName);
386 pXFPara->Add(pSpan);
387 }
388 else
389 {
390 XFTextContent* pSpan = new XFTextContent();
391 pSpan->SetText(text);
392 pXFPara->Add(pSpan);
393 }
394}
395
397 const OUString& text)
398{
399 XFHyperlink* pHyper = new XFHyperlink;
400 pHyper->SetHRef(pHyperlink->GetHyperlink());
401 pHyper->SetText(text);
402 pHyper->SetStyleName(GetStyleName());
403 pXFPara->Add(pHyper);
404}
405
411{
413 if (m_pModifiers && m_pModifiers->FontID)
414 {
415 LwpFoundry* pFoundry = m_pPara->GetFoundry();
416 if (pFoundry)
417 pFont = pFoundry->GetFontManager().CreateFont(m_pModifiers->FontID);
418 }
419 else
420 {
421 XFParaStyle* pXFParaStyle = m_pPara->GetXFParaStyle();
422 pFont = pXFParaStyle->GetFont();
423 }
424 return pFont;
425}
426
428{
430 return pGlobal->GetEditorName(m_nEditor);
431}
432
434{
436 return pGlobal->GetHighlightColor(m_nEditor);
437}
438
439void LwpFrib::Register(std::map<LwpFrib*, OUString>* pFribMap)
440{
441 if (m_pFribMap)
442 throw std::runtime_error("registered already");
443 m_pFribMap = pFribMap;
444}
445
447{
448 if (m_pFribMap)
449 {
450 m_pFribMap->erase(this);
451 m_pFribMap = nullptr;
452 }
453}
454
455/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString GetStyleName()=0
@descr: return the style name.
rtl::Reference< XFFont > CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
Definition: lwpfont.cxx:484
rtl::Reference< XFFont > CreateFont(sal_uInt32 fontID)
Definition: lwpfont.cxx:471
LwpFontManager & GetFontManager()
Definition: lwpfoundry.hxx:250
LwpStyleManager * GetStyleManager()
Definition: lwpfoundry.hxx:262
TAG_NOTE_FRIB object.
Definition: lwpnotes.hxx:72
const OUString & GetStyleName() const
Definition: lwpfrib.hxx:112
LwpFrib * GetNext()
Definition: lwpfrib.hxx:96
void Register(std::map< LwpFrib *, OUString > *pFribMap)
Definition: lwpfrib.cxx:439
XFColor GetHighlightColor()
Definition: lwpfrib.cxx:433
static void ReadModifiers(LwpObjectStream *pObjStrm, ModifierInfo *pModInfo)
Definition: lwpfrib.cxx:309
virtual void Read(LwpObjectStream *pObjStrm, sal_uInt16 len)
Definition: lwpfrib.cxx:207
OUString GetEditor()
Definition: lwpfrib.cxx:427
LwpPara * m_pPara
Definition: lwpfrib.hxx:104
void ConvertHyperLink(XFContentContainer *pXFPara, const LwpHyperlinkMgr *pHyperlink, const OUString &text)
Definition: lwpfrib.cxx:396
sal_uInt8 m_nRevisionType
Definition: lwpfrib.hxx:137
virtual void RegisterStyle(LwpFoundry *pFoundry)
Definition: lwpfrib.cxx:223
OUString m_StyleName
Definition: lwpfrib.hxx:108
std::unique_ptr< ModifierInfo > m_pModifiers
Definition: lwpfrib.hxx:107
sal_uInt8 GetType() const
Definition: lwpfrib.hxx:98
void SetModifiers(ModifierInfo *pModifiers)
Definition: lwpfrib.cxx:209
std::map< LwpFrib *, OUString > * m_pFribMap
Definition: lwpfrib.hxx:103
rtl::Reference< XFFont > GetFont()
@descr: Get the current frib font style
Definition: lwpfrib.cxx:410
bool m_ModFlag
Definition: lwpfrib.hxx:111
bool m_bRevisionFlag
Definition: lwpfrib.hxx:138
virtual ~LwpFrib()
Definition: lwpfrib.cxx:95
bool HasNextFrib()
@descr: Whether there are other fribs following current frib.
Definition: lwpfrib.cxx:378
void Deregister()
Definition: lwpfrib.cxx:446
sal_uInt8 m_nEditor
Definition: lwpfrib.hxx:139
LwpFrib(LwpPara *pPara)
Definition: lwpfrib.cxx:83
static LwpFrib * CreateFrib(LwpPara *pPara, LwpObjectStream *pObjStrm, sal_uInt8 fribtag, sal_uInt8 editID)
Definition: lwpfrib.cxx:97
void ConvertChars(XFContentContainer *pXFPara, const OUString &text)
Definition: lwpfrib.cxx:380
XFColor GetHighlightColor(sal_uInt8 nID)
OUString GetEditorName(sal_uInt8 nID)
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
const OUString & GetHyperlink() const
void ReadIndexed(LwpSvStream *pStrm)
@descr Read object id with indexed format from stream if index>0, lowid is get from time table per th...
Definition: lwpobjid.cxx:96
stream class for LwpObject body data provide stream like interface to read object data
Definition: lwpobjstrm.hxx:77
sal_uInt16 QuickReaduInt16(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:200
void SeekRel(sal_uInt16 pos)
@descr SeekRel pos in object stream/buffer
Definition: lwpobjstrm.cxx:160
sal_uInt8 QuickReaduInt8(bool *pFailure=nullptr)
@descr Quick read sal_uInt8
Definition: lwpobjstrm.cxx:230
sal_uInt32 QuickReaduInt32(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:189
LwpFoundry * GetFoundry()
Definition: lwpobj.hxx:136
XFParaStyle * GetXFParaStyle()
get paragraph xfstyle
Definition: lwppara1.cxx:118
IXFStyle * GetStyle(const LwpObjectID &styleObjID)
Definition: lwpfoundry.cxx:522
void Read(LwpObjectStream *pStrm) override
void Read(LwpObjectStream *pStrm) override
sal_uInt32 GetFinalFontID() const
Color object.
Definition: xfcolor.hxx:70
A container for content.
virtual void Add(XFContent *pContent)
@descr Add content.
virtual void SetStyleName(const OUString &style)
: All content except XFTextContent can have a style.
Definition: xfcontent.hxx:90
@descr The font struct of openoffice xml filter.
Definition: xffont.hxx:120
Style object for aragraph.
Definition: xfparastyle.hxx:93
const rtl::Reference< XFFont > & GetFont() const
@descr get the font object.
Style manager for the filter.
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
XFTextStyle * FindTextStyle(std::u16string_view name)
virtual OUString GetStyleName() override
@descr get style name.
Definition: xfstyle.cxx:70
virtual void SetStyleName(const OUString &styleName) override
@descr set style name.
Definition: xfstyle.cxx:75
Adapter for text to content.
void SetText(const OUString &text)
@descr Set the text.
const rtl::Reference< XFFont > & GetFont() const
Definition: xftextstyle.hxx:91
For LWP filter architecture prototype - footnote.
#define FRIB_MTAG_CHARSTYLE
#define FRIB_MTAG_NONE
#define FRIB_TAG_MODIFIER
@ FRIB_TAG_CHBLOCK
@ FRIB_TAG_FRAME
@ FRIB_TAG_UNICODE
@ FRIB_TAG_DOCVAR
@ FRIB_TAG_RUBYFRAME
@ FRIB_TAG_PAGENUMBER
@ FRIB_TAG_PAGEBREAK
@ FRIB_TAG_LINEBREAK
@ FRIB_TAG_RUBYMARKER
@ FRIB_TAG_SOFTHYPHEN
@ FRIB_TAG_EOP
@ FRIB_TAG_FOOTNOTE
@ FRIB_TAG_COLBREAK
@ FRIB_TAG_BOOKMARK
@ FRIB_TAG_TEXT
@ FRIB_TAG_UNICODE3
@ FRIB_TAG_FIELD
@ FRIB_TAG_NOTE
@ FRIB_TAG_TAB
@ FRIB_TAG_TABLE
@ FRIB_TAG_INVALID
@ FRIB_TAG_SECTION
@ FRIB_TAG_UNICODE2
@ FRIB_TAG_PARANUMBER
@ FRIB_TAG_HARDSPACE
#define FRIB_MTAG_CODEPAGE
#define FRIB_MTAG_REVISION
#define FRIB_TAG_NOUNICODE
#define FRIB_MTAG_LANGUAGE
#define FRIB_MTAG_FONT
#define FRIB_MTAG_ATTRIBUTE
For LWP filter architecture prototype - notes.
def text(shape, orig_st)
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
bool m_bOrigDeleted
Definition: xfstylecont.hxx:72
LwpTextLanguageOverride Language
Definition: lwpfrib.hxx:76
bool HasHighlight
Definition: lwpfrib.hxx:81
bool HasCharStyle
Definition: lwpfrib.hxx:79
bool RevisionFlag
Definition: lwpfrib.hxx:83
LwpObjectID CharStyleID
Definition: lwpfrib.hxx:75
sal_uInt32 FontID
Definition: lwpfrib.hxx:74
sal_uInt8 RevisionType
Definition: lwpfrib.hxx:82
sal_uInt16 CodePage
Definition: lwpfrib.hxx:78
bool HasLangOverride
Definition: lwpfrib.hxx:80
LwpTextAttributeOverride aTxtAttrOverride
Definition: lwpfrib.hxx:77
unsigned char sal_uInt8