All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Font.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Font.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "Font.h"
30 
31 // STL
32 #include <sstream>
33 #include <string>
34 #include <iostream>
35 #include <vector>
36 #include <cstdlib>
37 
39 m_family("Arial"),
40 m_pointSize(12),
41 m_bold(false),
42 m_italic(false),
43 m_underline(false),
44 m_strikeout(false),
45 m_kerning(false),
46 m_textAlign(TPTopLeft)
47 {
48 
49 }
50 
52 {
53 
54 }
55 
56 void te::layout::Font::setFamily( std::string family )
57 {
58  m_family = family;
59 }
60 
62 {
63  return m_family;
64 }
65 
67 {
68  m_pointSize = point;
69 }
70 
72 {
73  return m_pointSize;
74 }
75 
76 void te::layout::Font::setBold( bool bold )
77 {
78  m_bold = bold;
79 }
80 
82 {
83  return m_bold;
84 }
85 
86 void te::layout::Font::setItalic( bool italic )
87 {
88  m_italic = italic;
89 }
90 
92 {
93  return m_italic;
94 }
95 
96 void te::layout::Font::setUnderline( bool underline )
97 {
98  m_underline = underline;
99 }
100 
102 {
103  return m_underline;
104 }
105 
106 void te::layout::Font::setStrikeout( bool strikeout )
107 {
108  m_strikeout = strikeout;
109 }
110 
112 {
113  return m_strikeout;
114 }
115 
116 void te::layout::Font::setKerning( bool kerning )
117 {
118  m_kerning = kerning;
119 }
120 
122 {
123  return m_kerning;
124 }
125 
127 {
128  std::string s_convert;
129  std::stringstream ss;//create a stringstream
130 
131  s_convert = m_family;
132 
133  ss << m_pointSize;
134  s_convert += "," + ss.str();
135  s_convert += ",";
136 
137  s_convert += toString(m_bold);
138  s_convert += ",";
139  s_convert += toString(m_italic);
140  s_convert += ",";
141  s_convert += toString(m_underline);
142  s_convert += ",";
143  s_convert += toString(m_strikeout);
144  s_convert += ",";
145  s_convert += toString(m_kerning);
146 
147  return s_convert;
148 }
149 
150 void te::layout::Font::fromString( std::string font )
151 {
152  std::vector<std::string> strings;
153  std::istringstream f(font);
154  std::string s;
155  while (std::getline(f, s, ','))
156  {
157  strings.push_back(s);
158  }
159 
160  if(strings.empty() || strings.size() > 7)
161  return;
162 
163  m_family = strings[0];
164  m_pointSize = std::atoi(strings[1].c_str());
165  m_bold = toBool(strings[2]);
166  m_italic = toBool(strings[3]);;
167  m_underline = toBool(strings[4]);;
168  m_strikeout = toBool(strings[5]);;
169  m_kerning = toBool(strings[6]);;
170 }
171 
172 std::string te::layout::Font::toString( bool flag )
173 {
174  return flag ? "true" : "false";
175 }
176 
177 bool te::layout::Font::toBool( std::string str )
178 {
179  if(str.compare("true") == 0)
180  {
181  return true;
182  }
183  else
184  {
185  return false;
186  }
187 }
bool isBold()
Returns true if font use bold, false otherwise.
Definition: Font.cpp:81
bool isStrikeout()
Returns true if font use strikeout, false otherwise.
Definition: Font.cpp:111
void setStrikeout(bool strikeout)
Sets font with strikeout style.
Definition: Font.cpp:106
void setKerning(bool kerning)
Sets font with kerning style.
Definition: Font.cpp:116
int getPointSize()
Returns point size of the font.
Definition: Font.cpp:71
virtual bool toBool(std::string str)
State string to boolean.
Definition: Font.cpp:177
void setPointSize(int point)
Sets point size of the font.
Definition: Font.cpp:66
Font()
Constructor.
Definition: Font.cpp:38
virtual void fromString(std::string font)
Sets this object state from a string.
Definition: Font.cpp:150
void setBold(bool bold)
Sets font with bold style.
Definition: Font.cpp:76
void setFamily(std::string family)
Returns font family name.
Definition: Font.cpp:56
void setUnderline(bool underline)
Sets font with underline style.
Definition: Font.cpp:96
bool isItalic()
Returns true if font use italic, false otherwise.
Definition: Font.cpp:91
bool isUnderline()
Returns true if font use underline, false otherwise.
Definition: Font.cpp:101
virtual ~Font()
Destructor.
Definition: Font.cpp:51
void setItalic(bool italic)
Sets font with italic style.
Definition: Font.cpp:86
std::string getFamily()
Sets font family name.
Definition: Font.cpp:61
virtual std::string toString()
Serialize font object.
Definition: Font.cpp:126
bool isKerning()
Returns true if font use kerning, false otherwise.
Definition: Font.cpp:121