OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Markup.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2011-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // markup tags for fonts
17 
18 #ifndef INC_STDMARKUP
19 #define INC_STDMARKUP
20 
21 // one markup tag
23 {
24 public:
25  C4MarkupTag *pPrev{nullptr}, *pNext{nullptr};
26 
27  C4MarkupTag() = default; // ctor
28  virtual ~C4MarkupTag() = default; // dtor
29 
30  virtual void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr)=0; // assign markup
31  virtual const char *TagName()=0; // get character string for this tag
32 };
33 
34 // markup tag for italic text
36 {
37 public:
38  C4MarkupTagItalic() : C4MarkupTag() { } // ctor
39 
40  void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr) override; // assign markup
41  const char *TagName() override { return "i"; }
42 };
43 
44 // markup tag for colored text
46 {
47 private:
48  DWORD dwClr; // color
49 public:
50  C4MarkupTagColor(DWORD dwClr) : C4MarkupTag(), dwClr(dwClr) { } // ctor
51 
52  void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr) override; // assign markup
53  const char *TagName() override { return "c"; }
54 };
55 
56 // markup rendering functionality for text
57 class C4Markup
58 {
59 private:
60  C4MarkupTag *pTags, *pLast; // tag list; single linked
61  bool fDoClr; // set if color changes should be made (not in text shadow!)
62 
63  void Push(C4MarkupTag *pTag)
64  { if ((pTag->pPrev=pLast)) pLast->pNext=pTag; else pTags=pTag; pLast=pTag; }
65  C4MarkupTag *Pop()
66  { C4MarkupTag *pL=pLast; if (!pL) return nullptr; if ((pLast=pL->pPrev)) pLast->pNext=nullptr; else pTags=nullptr; return pL; }
67 public:
68  C4Markup(bool fDoClr) { pTags=pLast=nullptr; this->fDoClr=fDoClr; }; // ctor
69  ~C4Markup() // dtor
70  { C4MarkupTag *pTag=pTags,*pNext; while (pTag) { pNext=pTag->pNext; delete pTag; pTag=pNext; } }
71 
72  bool Read(const char **ppText, bool fSkip=false); // get markup from text
73  bool SkipTags(const char **ppText); // extract markup from text; return whether end is reached
74  void Apply(C4BltTransform &rBltTrf, DWORD &dwClr) // assign markup to vertices
75  { for (C4MarkupTag *pTag=pTags; pTag; pTag=pTag->pNext) pTag->Apply(rBltTrf, fDoClr, dwClr); }
76  bool Clean() { return !pTags; } // empty?
77 
78  static bool StripMarkup(char *szText); // strip any markup codes from given text buffer
79  static bool StripMarkup(StdStrBuf *sText); // strip any markup codes from given text buffer
80 };
81 #endif // INC_STDMARKUP
~C4Markup()
Definition: C4Markup.h:69
virtual ~C4MarkupTag()=default
C4MarkupTag * pPrev
Definition: C4Markup.h:25
virtual const char * TagName()=0
C4MarkupTag * pNext
Definition: C4Markup.h:25
virtual void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr)=0
C4MarkupTagColor(DWORD dwClr)
Definition: C4Markup.h:50
bool SkipTags(const char **ppText)
Definition: C4Markup.cpp:105
bool Clean()
Definition: C4Markup.h:76
C4Markup(bool fDoClr)
Definition: C4Markup.h:68
const char * TagName() override
Definition: C4Markup.h:53
bool Read(const char **ppText, bool fSkip=false)
Definition: C4Markup.cpp:34
const char * TagName() override
Definition: C4Markup.h:41
void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr) override
Definition: C4Markup.cpp:28
C4MarkupTag()=default
void Apply(C4BltTransform &rBltTrf, DWORD &dwClr)
Definition: C4Markup.h:74
uint32_t DWORD
void Apply(C4BltTransform &rBltTrf, bool fDoClr, DWORD &dwClr) override
Definition: C4Markup.cpp:22
static bool StripMarkup(char *szText)
Definition: C4Markup.cpp:113