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 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
49 }
50 
52 {
53  te::common::FreeContents(m_svgParams);
54 }
55 
57 {
58  std::string name = p->getName();
59  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
60  if(it != m_svgParams.end())
61  delete it->second;
62  m_svgParams[name] = p;
63 }
64 
65 void te::se::Font::setFamily(const std::string& family)
66 {
67  setParameter(sm_family, family);
68 }
69 
71 {
72  setParameter(sm_style, sm_fontStyleMap[style]);
73 }
74 
76 {
77  setParameter(sm_weight, sm_fontWeightMap[weight]);
78 }
79 
80 void te::se::Font::setSize(const std::string& size)
81 {
82  setParameter(sm_size, size);
83 }
84 
86 {
87  return getParameter(sm_family);
88 }
89 
91 {
92  return getParameter(sm_style);
93 }
94 
96 {
97  return getParameter(sm_weight);
98 }
99 
101 {
102  return getParameter(sm_size);
103 }
104 
106 {
107  Font* font = new Font;
108 
109  std::map<std::string, SvgParameter*>::const_iterator it;
110  for(it = m_svgParams.begin(); it != m_svgParams.end(); ++it)
111  font->add(it->second->clone());
112 
113  return font;
114 }
115 
116 void te::se::Font::setParameter(const std::string& name, const std::string& value)
117 {
118  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
119  if(it != m_svgParams.end())
120  delete it->second;
121  m_svgParams[name] = new te::se::SvgParameter(name, value);
122 }
123 
124 const te::se::SvgParameter* te::se::Font::getParameter(const std::string& name) const
125 {
126  std::map<std::string, te::se::SvgParameter*>::const_iterator it = m_svgParams.find(name);
127  if(it != m_svgParams.end())
128  return it->second;
129 
130  return 0; // Not found
131 }
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
static const std::string sm_family
SVG/CSS "font-family" parameter.
Definition: Font.h:150
const SvgParameter * getParameter(const std::string &name) const
Definition: Font.cpp:124
void add(SvgParameter *p)
Add a SvgParameter to this Font.
Definition: Font.cpp:56
const SvgParameter * getFamily() const
Definition: Font.cpp:85
void setSize(const std::string &size)
Definition: Font.cpp:80
~Font()
Destructor.
Definition: Font.cpp:51
const SvgParameter * getWeight() const
Definition: Font.cpp:95
static std::map< FontStyleType, std::string > sm_fontStyleMap
A map that associates FontStyleType to the correct string value.
Definition: Font.h:147
const SvgParameter * getSize() const
Definition: Font.cpp:100
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:152
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:153
Font()
It initializes a new Font.
Definition: Font.cpp:39
void setWeight(const FontWeightType &weight)
Definition: Font.cpp:75
static std::map< FontWeightType, std::string > sm_fontWeightMap
A map that associates FontWeightType to the correct string value.
Definition: Font.h:148
void setFamily(const std::string &family)
Definition: Font.cpp:65
const SvgParameter * getStyle() const
Definition: Font.cpp:90
void setParameter(const std::string &name, const std::string &value)
Definition: Font.cpp:116
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:151
void setStyle(const FontStyleType &style)
Definition: Font.cpp:70
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:105
A Font specifies the text font to use in a text symbolizer.