OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimFontInformation.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //********************************************************************
9 // $Id: ossimFontInformation.cpp 9094 2006-06-13 19:12:40Z dburken $
10 
11 #include <iostream>
12 #include <sstream>
15 
16 const char* ossimFontInformation::FAMILY_NAME_KW = "family_name";
17 const char* ossimFontInformation::STYLE_NAME_KW = "style_name";
18 const char* ossimFontInformation::POINT_SIZE_KW = "point_size";
19 const char* ossimFontInformation::POINT_SIZE_X_KW = "point_size_x";
20 const char* ossimFontInformation::POINT_SIZE_Y_KW = "point_size_y";
21 const char* ossimFontInformation::FIXED_FLAG_KW = "fixed_flag";
22 const char* ossimFontInformation::SHEAR_KW = "shear";
23 const char* ossimFontInformation::SHEAR_X_KW = "shear_x";
24 const char* ossimFontInformation::SHEAR_Y_KW = "shear_y";
25 const char* ossimFontInformation::SCALE_KW = "scale";
26 const char* ossimFontInformation::SCALE_X_KW = "scale_x";
27 const char* ossimFontInformation::SCALE_Y_KW = "scale_y";
28 const char* ossimFontInformation::ROTATION_KW = "rotation";
29 
31  const ossimFontInformation& rhs)
32 {
33  out << "Family name: " << rhs.theFamilyName
34  << "\nStyle name: " << rhs.theStyleName
35  << "\nPoint size: " << rhs.thePointSize
36  << "\nFixed flag: " << (rhs.theFixedFlag?"true":"false")
37  << std::endl;
38 
39  return out;
40 }
41 
43  :theFamilyName(""),
44  theStyleName(""),
45  thePointSize(0,0),
46  theFixedFlag(false),
47  theScale(1.0,1.0),
48  theRotation(0.0),
49  theShear(0.0,0.0)
50 {
51 }
52 
54  const ossimString& style,
55  const ossimIpt& pointSize,
56  bool fixedFlag,
57  const ossimDpt& scale,
58  double rotation,
59  const ossimDpt& shear)
60  :theFamilyName(family),
61  theStyleName(style),
62  thePointSize(pointSize),
63  theFixedFlag(fixedFlag),
64  theScale(scale),
65  theRotation(rotation),
66  theShear(shear)
67 {}
68 
70  : theFamilyName(rhs.theFamilyName),
71  theStyleName(rhs.theStyleName),
72  thePointSize(rhs.thePointSize),
73  theFixedFlag(rhs.theFixedFlag),
74  theScale(rhs.theScale),
75  theRotation(rhs.theRotation),
76  theShear(rhs.theShear)
77 {
78 }
79 
81 {
82  return theFixedFlag;
83 }
84 
86  const char* prefix)const
87 {
88  kwl.add(prefix,
91  true);
92  kwl.add(prefix,
95  true);
96 
97  kwl.add(prefix,
100  true);
101 
102  kwl.add(prefix,
103  SHEAR_KW,
104  theShear.toString().c_str(),
105  true);
106 
107  kwl.add(prefix,
108  SCALE_KW,
109  theScale.toString().c_str(),
110  true);
111 
112 #if 0
113  kwl.add(prefix,
115  thePointSize.x,
116  true);
117  kwl.add(prefix,
119  thePointSize.y,
120  true);
121  kwl.add(prefix,
122  SHEAR_Y_KW,
123  theShear.y,
124  true);
125  kwl.add(prefix,
126  SCALE_X_KW,
127  theScale.x,
128  true);
129  kwl.add(prefix,
130  SCALE_X_KW,
131  theScale.x,
132  true);
133  kwl.add(prefix,
134  SCALE_Y_KW,
135  theScale.y,
136  true);
137 #endif
138 
139  kwl.add(prefix,
141  (int)theFixedFlag,
142  true);
143  kwl.add(prefix,
144  ROTATION_KW,
145  theRotation,
146  true);
147 
148 
149  return true;
150 }
151 
153  const char* prefix)
154 {
155  bool result = true;
156 
157  const char* family_name = kwl.find(prefix, FAMILY_NAME_KW);
158  const char* style_name = kwl.find(prefix, STYLE_NAME_KW);
159  const char* fixed = kwl.find(prefix, FIXED_FLAG_KW);
160  const char* rotation = kwl.find(prefix, ROTATION_KW);
161 
162  if(family_name)
163  {
164  theFamilyName = family_name;
165  }
166  else
167  {
168  result = false;
169  }
170 
171  if(style_name)
172  {
173  theStyleName = style_name;
174  }
175  else
176  {
177  result = false;
178  }
179 
180  // Look for point_size:
181  const char* lookup;
182  lookup = kwl.find(prefix, POINT_SIZE_KW);
183  if (lookup)
184  {
185  std::istringstream is(lookup);
186  is >> thePointSize;
187  }
188  else // backwards compat...
189  {
190  const char* point_x = kwl.find(prefix, POINT_SIZE_X_KW);
191  const char* point_y = kwl.find(prefix, POINT_SIZE_Y_KW);
192  if((point_x)&&(point_y))
193  {
194  thePointSize = ossimIpt(ossimString(point_x).toLong(),
195  ossimString(point_y).toLong());
196  }
197  else
198  {
199  result = false;
200  }
201  }
202 
203  // Look for shear:
204  lookup = kwl.find(prefix, SHEAR_KW);
205  if (lookup)
206  {
207  std::istringstream is(lookup);
208  is >> theShear;
209  }
210  else
211  {
212  const char* shear_x = kwl.find(prefix, SHEAR_X_KW);
213  if(shear_x)
214  {
215  theShear.x = ossimString(shear_x).toDouble();
216  }
217  else
218  {
219  result = false;
220  }
221  const char* shear_y = kwl.find(prefix, SHEAR_Y_KW);
222  if(shear_y)
223  {
224  theShear.y = ossimString(shear_y).toDouble();
225  }
226  else
227  {
228  result = false;
229  }
230  }
231 
232  // Look for scale:
233  lookup = kwl.find(prefix, SCALE_KW);
234  if (lookup)
235  {
236  std::istringstream is(lookup);
237  is >> theScale;
238  }
239  else
240  {
241  const char* scale_x = kwl.find(prefix, SCALE_X_KW);
242  if(scale_x)
243  {
244  theScale.x = ossimString(scale_x).toDouble();
245  }
246  else
247  {
248  result = false;
249  }
250  const char* scale_y = kwl.find(prefix, SCALE_Y_KW);
251  if(scale_y)
252  {
253  theScale.y = ossimString(scale_y).toDouble();
254  }
255  else
256  {
257  result = false;
258  }
259  }
260 
261  if(fixed)
262  {
263  theFixedFlag = ossimString(fixed).toBool();
264  }
265 
266  if(rotation)
267  {
268  theRotation = ossimString(rotation).toDouble();
269  }
270  else
271  {
272  result = false;
273  }
274 
275  return result;
276 }
277 
279 {
280  return ( (theFamilyName == rhs.theFamilyName)&&
281  (theStyleName == rhs.theStyleName)&&
282  (thePointSize == rhs.thePointSize)&&
283  (theFixedFlag == rhs.theFixedFlag)&&
284  (theScale == rhs.theScale)&&
285  (theRotation == rhs.theRotation)&&
286  (theShear == rhs.theShear));
287 }
288 
290 {
291  return ( (theFamilyName != rhs.theFamilyName)||
292  (theStyleName != rhs.theStyleName)||
293  (thePointSize != rhs.thePointSize)||
294  (theFixedFlag != rhs.theFixedFlag)||
295  (theScale != rhs.theScale)||
296  (theRotation != rhs.theRotation)||
297  (theShear != rhs.theShear));
298 }
299 
301  const ossimFontInformation& rhs)
302 {
307  theScale = rhs.theScale;
308  theRotation = rhs.theRotation;
309  theShear = rhs.theShear;
310 
311  return *this;
312 }
ossimString toString() const
Definition: ossimIpt.cpp:139
static const char * SHEAR_KW
static const char * FAMILY_NAME_KW
static const char * FIXED_FLAG_KW
Represents serializable keyword/value map.
static const char * SCALE_KW
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
bool operator==(const ossimFontInformation &rhs) const
bool operator!=(const ossimFontInformation &rhs) const
const ossimFontInformation & operator=(const ossimFontInformation &rhs)
static const char * SHEAR_X_KW
std::ostream & operator<<(std::ostream &out, const ossimFontInformation &rhs)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const char * SCALE_Y_KW
static const char * POINT_SIZE_X_KW
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
bool toBool() const
String to numeric methods.
static const char * ROTATION_KW
double toDouble() const
static const char * STYLE_NAME_KW
static const char * SHEAR_Y_KW
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the current state of this object.
ossim_int32 y
Definition: ossimIpt.h:142
double x
Definition: ossimDpt.h:164
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static const char * POINT_SIZE_Y_KW
ossim_int32 x
Definition: ossimIpt.h:141
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
static const char * SCALE_X_KW
static const char * POINT_SIZE_KW
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23