OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimFreeTypeFontFactory.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: ossimFreeTypeFontFactory.cpp 15766 2009-10-20 12:37:09Z gpotts $
10 
11 #include <ossim/ossimConfig.h> /* To pick up OSSIM_HAS_FREETYPE. */
12 
13 #if OSSIM_HAS_FREETYPE
19 
21 
23 {
24  theInstance = this;
25 }
26 
28 {
29  theInstance = 0;
30 }
31 
33 {
34  if(!theInstance)
35  {
38  }
39 
40  return theInstance;
41 }
42 
43 
45 
46 {
48 
49  ossimString rightFamilyName = information.theFamilyName;
50  ossimString rightStyleName = information.theStyleName;
51  rightFamilyName = rightFamilyName.upcase().trim();
52  rightStyleName = rightStyleName.upcase().trim();
53  int i = 0;
54 
55  for(i = 0; ( (i < (int)theFontInformationList.size())&&(!result));++i)
56  {
57  ossimString leftFamilyName = theFontInformationList[i].theFontInformation.theFamilyName;
58  ossimString leftStyleName = theFontInformationList[i].theFontInformation.theStyleName;
59 
60  leftFamilyName = leftFamilyName.upcase().trim();
61  leftStyleName = leftStyleName.upcase().trim();
62 
63  if( (leftFamilyName == rightFamilyName)&&
64  (leftStyleName == rightStyleName))
65  {
66  if(theFontInformationList[i].theFontInformation.theFixedFlag)
67  {
68  if(theFontInformationList[i].theFontInformation.thePointSize ==
69  information.thePointSize)
70  {
71  result = new ossimFreeTypeFont(theFontInformationList[i].theFilename);
72  if(result.valid())
73  {
74  if(result->getErrorStatus())
75  {
76  result = 0;
77  ossimNotify(ossimNotifyLevel_WARN) <<"WARNING ossimFreeTypeFontFactory::createFont: unable to open font file "
78  << theFontInformationList[i].theFilename << std::endl;
79  }
80  }
81  }
82  }
83  else
84  {
85  result = new ossimFreeTypeFont(theFontInformationList[i].theFilename);
86  if(result.valid())
87  {
88  if(result->getErrorStatus())
89  {
90  result = 0;
91  ossimNotify(ossimNotifyLevel_WARN) << "WARNING ossimFreeTypeFontFactory::createFont: unable to open font file "
92  << theFontInformationList[i].theFilename << std::endl;
93  }
94  else
95  {
96  if(information.thePointSize.x&&
97  information.thePointSize.y)
98  {
99  result->setPixelSize(information.thePointSize.x,
100  information.thePointSize.y);
101  }
102  }
103  }
104  }
105  }
106  }
107 
108  if(result.valid())
109  {
110  result->setScale(information.theScale.x,
111  information.theScale.y);
112  result->setScale(information.theScale.x,
113  information.theScale.y);
114  result->setHorizontalVerticalShear(information.theShear.x,
115  information.theShear.y);
116  result->setRotation(information.theRotation);
117  }
118 
119  return result.release();
120 }
121 
123 {
124  ossimRefPtr<ossimFont> result = new ossimFreeTypeFont(file);
125 
126  if(result->getErrorStatus())
127  {
128  result = 0;
129  }
130 
131  return result.release();
132 }
133 
134 void ossimFreeTypeFontFactory::getFontInformation(std::vector<ossimFontInformation>& informationList)const
135 {
136  int i = 0;
137  for(i = 0; i < (int)theFontInformationList.size();++i)
138  {
139  informationList.push_back(theFontInformationList[i].theFontInformation);
140  }
141 }
142 
144 {
145  ossimRefPtr<ossimFreeTypeFont> font = new ossimFreeTypeFont(file);
146 
147  std::vector<ossimFontInformation> fontInfoList;
148 
149  bool result = false;
150  int i = 0;
151  if(font->getFontFace())
152  {
153  if(!font->getErrorStatus())
154  {
155  font->getFontInformation(fontInfoList);
156 
157  for(i = 0; i < (int)fontInfoList.size();++i)
158  {
160  fontInfoList[i]));
161  }
162  result = true;
163  }
164  }
165 
166  // Free memory.
167  font = 0;
168 
169  return result;
170 }
171 
173 {
175  ossimString regExpressionDir = ossimString("^(") + "font.dir[0-9]+)";
176  ossimString regExpressionFile = ossimString("^(") + "font.file[0-9]+)";
177  vector<ossimString> dirs =
178  kwl.getSubstringKeyList( regExpressionDir );
179  vector<ossimString> files =
180  kwl.getSubstringKeyList( regExpressionFile );
181 
182  int idx = 0;
183  for(idx = 0; idx < (int)dirs.size();++idx)
184  {
185  const char* directoryLocation = kwl.find(dirs[idx]);
186  if(directoryLocation)
187  {
188  ossimDirectory d;
189 
190  if(d.open(ossimFilename(directoryLocation)))
191  {
192  ossimFilename file;
193 
195  {
196  do
197  {
198  addFile(file);
199  }while(d.getNext(file));
200  }
201  }
202  }
203  }
204  for(idx = 0; idx < (int)files.size();++idx)
205  {
206  const char* fileName = kwl.find(files[idx]);
207 
208  if(fileName)
209  {
210  addFile(ossimFilename(fileName));
211  }
212  }
213 #if 0
214  if(!numberOfDirs&&!numberOfFiles)
215  {
216 #ifdef __UNIX__
217  ossimFilename file("/usr/X11R6/lib/X11/fonts/Type1");
218 
219  if(file.exists())
220  {
221  ossimDirectory d;
222  if(d.open(file))
223  {
225  {
226  do
227  {
228  addFile(file);
229  }while(d.getNext(file));
230  }
231  }
232  }
233 #endif
234  }
235 #endif
236 }
237 
238 #endif /* #if OSSIM_HAS_FREETYPE */
const ossimKeywordlist & preferencesKWL() const
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
virtual ossimFont * createFont(const ossimFontInformation &information) const
bool addFile(const ossimFilename &file)
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
const char * find(const char *key) const
double y
Definition: ossimDpt.h:165
bool getNext(ossimFilename &filename) const
static ossimFreeTypeFontFactory * instance()
bool exists() const
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
T * release()
Definition: ossimRefPtr.h:93
static ossimPreferences * instance()
bool open(const ossimFilename &dir)
virtual void setHorizontalVerticalShear(double horizontalShear, double verticalShear)
Definition: ossimFont.h:161
std::vector< ossimString > getSubstringKeyList(const ossimString &regularExpression) const
virtual void setScale(double horizontal, double vertical)
Definition: ossimFont.cpp:26
virtual ossimErrorCode getErrorStatus() const
ossim_int32 y
Definition: ossimIpt.h:142
virtual void setPixelSize(int horizontalPixelSize, int verticalPixelSize)
Definition: ossimFont.h:205
static ossimFreeTypeFontFactory * theInstance
double x
Definition: ossimDpt.h:164
virtual ~ossimFreeTypeFontFactory()
ossim_int32 x
Definition: ossimIpt.h:141
virtual void setRotation(double rotationInDegrees)
Definition: ossimFont.cpp:19
std::vector< ossimFreeTypeFontInformation > theFontInformationList
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual void getFontInformation(std::vector< ossimFontInformation > &informationList) const