summaryrefslogtreecommitdiff
path: root/support/highlight/src/core/documentstyle.cpp
blob: 9c5f7307d5fde70f92aa2774450e058a96db9e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/***************************************************************************
                          documentstyle.cpp  -  description
                             -------------------
    begin                : Son Nov 10 2002
    copyright            : (C) 2002 by Andre Simon
    email                : andre.simon1@gmx.de
 ***************************************************************************/


/*
This file is part of Highlight.

Highlight is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Highlight is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "documentstyle.h"
#include "stringtools.h"

namespace highlight
{

	DocumentStyle::DocumentStyle ( const string &styleDefinitionFile )
	{
		fileFound=load ( styleDefinitionFile );
	}
	DocumentStyle::DocumentStyle() :fileFound ( false )
	{}

	bool DocumentStyle::load ( const string &styleDefinitionPath )
	{
		ConfigurationReader styleConfig ( styleDefinitionPath );
		fileFound = false;
		if ( styleConfig.found() )
		{
			fontsize = styleConfig.getParameter ( "fontsize" );
			bgColour.setRGB ( styleConfig.getParameter ( "bgcolour" ) );
			defaultElem.set ( styleConfig.getParameter ( "defaultcolour" ) );
			comment.set ( styleConfig.getParameter ( "comment" ) );
			directive.set ( styleConfig.getParameter ( "directive" ) );
			str.set ( styleConfig.getParameter ( "string" ) );
			escapeChar.set ( styleConfig.getParameter ( "escapechar" ) );
			number.set ( styleConfig.getParameter ( "number" ) );
			dstr.set ( styleConfig.getParameter ( "string-directive" ) );
			line.set ( styleConfig.getParameter ( "line" ) );
			symbol.set ( styleConfig.getParameter ( "symbol" ) );
			markLineColour.setRGB ( styleConfig.getParameter ( "mark-line" ) );

			string tmpstr;
			// TODO: Remove this check as soon as all themes have a sl-comment attribute
			tmpstr=styleConfig.getParameter ( "sl-comment" );
			if ( tmpstr.empty() )
			{
				tmpstr=styleConfig.getParameter ( "comment" );
			}
			slcomment.set ( tmpstr );

			string paramVal;
			vector<string> paramNames=styleConfig.getParameterNames();

			//collect keyword groups, save corresponding style definition
			for ( unsigned int i=0;i<paramNames.size();i++ )
			{
				paramVal=paramNames[i];
				if ( paramVal.find ( "kw-group" ) != string::npos)
				{
					keywordStyles.insert ( make_pair ( StringTools::getParantheseVal ( paramVal ),
					                                   ElementStyle ( styleConfig.getParameter ( paramVal ) ) ) );
				}
			}
			fileFound = true;
		}
		return fileFound;
	}

	DocumentStyle::~DocumentStyle()
	{
	}

	string DocumentStyle::getFontSize() const
	{
		return fontsize;
	}
	Colour DocumentStyle::getBgColour() const
	{
		return bgColour;
	}
	Colour DocumentStyle::getMarkLineColour() const
	{
		return markLineColour;
	}
	ElementStyle DocumentStyle::getDefaultStyle() const
	{
		return defaultElem;
	}
	ElementStyle DocumentStyle::getCommentStyle() const
	{
		return comment;
	}
	ElementStyle DocumentStyle::getSingleLineCommentStyle() const
	{
		return slcomment;
	}
	ElementStyle DocumentStyle::getStringStyle() const
	{
		return str;
	}
	ElementStyle DocumentStyle::getDirectiveStringStyle() const
	{
		return dstr;
	}
	ElementStyle DocumentStyle::getEscapeCharStyle() const
	{
		return escapeChar;
	}
	ElementStyle DocumentStyle::getNumberStyle() const
	{
		return number;
	}
	ElementStyle DocumentStyle::getDirectiveStyle() const
	{
		return directive;
	}
	ElementStyle DocumentStyle::getLineStyle() const
	{
		return line;
	}
	ElementStyle DocumentStyle::getSymbolStyle() const
	{
		return symbol;
	}
	bool DocumentStyle::found () const
	{
		return fileFound;
	}
	ElementStyle DocumentStyle::getKeywordStyle ( const string &className )
	{
		if ( !keywordStyles.count ( className ) ) return defaultElem;
		return keywordStyles[className];
	}

	vector <string> DocumentStyle::getClassNames() const
	{
		vector <string> kwClassNames;
		for ( KSIterator iter = keywordStyles.begin(); iter != keywordStyles.end(); iter++ )
		{
			kwClassNames.push_back ( ( *iter ).first );
		}
		return kwClassNames;
	}

	KeywordStyles DocumentStyle::getKeywordStyles() const
	{
		return keywordStyles;
	}

}