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 terralib/se/Font.cpp
22 
23  \brief A Font specifies the text font to use in a text symbolizer.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "Font.h"
29 #include "SvgParameter.h"
30 
31 std::map<te::se::Font::FontStyleType, std::string> te::se::Font::sm_fontStyleMap;
32 std::map<te::se::Font::FontWeightType, std::string> te::se::Font::sm_fontWeightMap;
33 
34 const std::string te::se::Font::sm_family = "font-family";
35 const std::string te::se::Font::sm_style = "font-style";
36 const std::string te::se::Font::sm_weight = "font-weight";
37 const std::string te::se::Font::sm_size = "font-size";
38 
40 {
41  // FontStyle
45 
46  // FontWeightType
52 }
53 
55 {
57 }
58 
60 {
61  std::string name = p->getName();
62  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
63  if(it != m_svgParams.end())
64  delete it->second;
65  m_svgParams[name] = p;
66 }
67 
68 void te::se::Font::setFamily(const std::string& family)
69 {
70  setParameter(sm_family, family);
71 }
72 
74 {
76 }
77 
79 {
81 }
82 
83 void te::se::Font::setSize(const std::string& size)
84 {
85  setParameter(sm_size, size);
86 }
87 
89 {
90  return getParameter(sm_family);
91 }
92 
94 {
95  return getParameter(sm_style);
96 }
97 
99 {
100  return getParameter(sm_weight);
101 }
102 
104 {
105  return getParameter(sm_size);
106 }
107 
109 {
110  Font* font = new Font;
111 
112  std::map<std::string, SvgParameter*>::const_iterator it;
113  for(it = m_svgParams.begin(); it != m_svgParams.end(); ++it)
114  font->add(it->second->clone());
115 
116  return font;
117 }
118 
119 void te::se::Font::setParameter(const std::string& name, const std::string& value)
120 {
121  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
122  if(it != m_svgParams.end())
123  delete it->second;
124  m_svgParams[name] = new te::se::SvgParameter(name, value);
125 }
126 
127 const te::se::SvgParameter* te::se::Font::getParameter(const std::string& name) const
128 {
129  std::map<std::string, te::se::SvgParameter*>::const_iterator it = m_svgParams.find(name);
130  if(it != m_svgParams.end())
131  return it->second;
132 
133  return nullptr; // Not found
134 }
A Font specifies the text font to use in a text symbolizer.
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
static const std::string sm_family
SVG/CSS "font-family" parameter.
Definition: Font.h:153
const SvgParameter * getParameter(const std::string &name) const
Definition: Font.cpp:127
void add(SvgParameter *p)
Add a SvgParameter to this Font.
Definition: Font.cpp:59
const SvgParameter * getFamily() const
Definition: Font.cpp:88
void setSize(const std::string &size)
Definition: Font.cpp:83
~Font()
Destructor.
Definition: Font.cpp:54
const SvgParameter * getWeight() const
Definition: Font.cpp:98
static std::map< FontStyleType, std::string > sm_fontStyleMap
A map that associates FontStyleType to the correct string value.
Definition: Font.h:150
const SvgParameter * getSize() const
Definition: Font.cpp:103
std::map< std::string, SvgParameter * > m_svgParams
Set of SvgParameters.
Definition: Font.h:148
A Font specifies the text font to use in a text symbolizer.
Definition: Font.h:63
static const std::string sm_weight
SVG/CSS "font-weight" parameter.
Definition: Font.h:155
te::gm::Polygon * p
std::string getName() const
FontStyleType
It defines the style to use for a font.
Definition: Font.h:72
static const std::string sm_size
SVG/CSS "font-size" parameter.
Definition: Font.h:156
Font()
It initializes a new Font.
Definition: Font.cpp:39
void setWeight(const FontWeightType &weight)
Definition: Font.cpp:78
static std::map< FontWeightType, std::string > sm_fontWeightMap
A map that associates FontWeightType to the correct string value.
Definition: Font.h:151
void setFamily(const std::string &family)
Definition: Font.cpp:68
const SvgParameter * getStyle() const
Definition: Font.cpp:93
void setParameter(const std::string &name, const std::string &value)
Definition: Font.cpp:119
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Definition: SvgParameter.h:48
static const std::string sm_style
SVG/CSS "font-style parameter.
Definition: Font.h:154
void setStyle(const FontStyleType &style)
Definition: Font.cpp:73
FontWeightType
It gives the amount of weight or boldness to use for a font.
Definition: Font.h:84
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
Font * clone() const
It creates a new copy of this object.
Definition: Font.cpp:108