OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimFreeTypeFont.h
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: ossimFreeTypeFont.h 21749 2012-09-18 14:06:13Z dburken $
10 #ifndef ossimFreeTypeFont_HEADER
11 #define ossimFreeTypeFont_HEADER
12 
13 #include <ossim/ossimConfig.h> /* To pick up OSSIM_HAS_FREETYPE. */
14 
15 #if OSSIM_HAS_FREETYPE
16 # include <ossim/font/ossimFont.h>
17 # include <ft2build.h>
18 # include FT_FREETYPE_H
19 //#include <freetype/freetype.h>
20 # include FT_MODULE_H // for FT_Done_Library
21 # include FT_GLYPH_H
22 
24 
25 
26 typedef struct TGlyph_
27 {
28  FT_UInt glyph_index; /* glyph index in face */
29  FT_Vector pos; /* position of glyph origin */
30  FT_Glyph image; /* glyph image */
31 
32 } TGlyph, *PGlyph;
33 
34 class ossimFreeTypeFont: public ossimFont
35 {
36 public:
37  ossimFreeTypeFont(const ossimFilename& fontFile);
38  ossimFreeTypeFont(const ossimFreeTypeFont& rhs);
39 
40  virtual ossimObject* dup()const
41  {
42  return new ossimFreeTypeFont(*this);
43  }
44 
45  virtual const ossim_uint8* getBuf()const
46  {
47  return theOutputBuffer;
48  }
49 
50  void layoutGlyphs(vector<TGlyph>& glyphs,
51  const ossimString& s );
52 
53  virtual const ossim_uint8* rasterize();
54  void getBoundingBox(ossimIrect& box);
55 
56  long getNumberOfFaces()const
57  {
58  if(theFontFace)
59  {
60  return theFontFace->num_faces;
61  }
62  return 0;
63  }
64  void setCurrentFace(long index);
65 
69  bool isFixed()const
70  {
71  if(theFontFace)
72  {
73  return (theFontFace->num_fixed_sizes > 0);
74  }
75  return false;
76  }
77 
78  virtual void getFixedSizes(vector<ossimIpt>& sizeArray)const;
79 
87  virtual void enableKerningSupport()
88  {
89  theKerningEnabledFlag = true;
90  theBoundingRectIsValid = false;
91  }
92 
96  virtual void disableKerningSupport()
97  {
98  theKerningEnabledFlag = false;
99  theBoundingRectIsValid = false;
100  }
101 
102  virtual void setHorizontalVerticalShear(double horizontalShear,
103  double verticalShear)
104  {
106  verticalShear);
107  theBoundingRectIsValid = false;
108  }
109  virtual void setScale(double horizontal,
110  double vertical)
111  {
112  ossimFont::setScale(horizontal,
113  vertical);
114  theBoundingRectIsValid = false;
115  }
116 
117  virtual void setPixelSize(int horizontalPixelSize,
118  int verticalPixelSize)
119  {
120  ossimFont::setPixelSize(horizontalPixelSize,
121  verticalPixelSize);
122  theBoundingRectIsValid = false;
123  }
124  virtual void setPixelSize(int pixelSize)
125  {
126  ossimFont::setPixelSize(pixelSize);
127  theBoundingRectIsValid = false;
128  }
129 
130  virtual void setDeviceDpi(int horizontalDeviceUnits,
131  int verticalDeviceUnits)
132  {
133  ossimFont::setDeviceDpi(horizontalDeviceUnits,
134  verticalDeviceUnits);
135  theBoundingRectIsValid = false;
136  }
137  virtual void setString(const ossimString& s)
138  {
140  theBoundingRectIsValid = false;
141  theNeedToLayoutGlyphsFlag = true;
142  }
143 
144  const FT_Face getFontFace()const
145  {
146  return theFontFace;
147  }
148 protected:
149  virtual ~ossimFreeTypeFont();
150 
151  FT_Face theFontFace;
152  FT_Library theLibrary;
153  FT_Matrix theMatrix;
154 
155  ossimFilename theFontFile;
156 
157  ossim_uint8* theOutputBuffer;
158  long theBufferSize;
159  bool theKerningEnabledFlag;
160  bool theNeedToLayoutGlyphsFlag;
161  FT_Vector theStringCenter;
162  ossimIpt theShift;
166  vector<TGlyph> theStringLayout;
167 
173  mutable ossimIrect thePrecomputedBoundingRect;
174 
175 
179  mutable bool theBoundingRectIsValid;
180  void layoutGlyphs(const ossimString& s);
181 
182  void setBaseClassInformation();
183  void setupForRasterization();
184  void allocateBuffer();
185 
186  void drawBitmap(FT_Bitmap* bitmap,
187  const ossimIrect& bufRect,
188  const ossimIrect& glyphBox);
189 
190  void computeGlyphBox(FT_Glyph,
191  ossimIrect& box)const;
192  void deleteGlyphs(vector<TGlyph>& glyphs);
193 
194 TYPE_DATA
195 };
196 
197 #endif
198 
199 #endif
virtual const ossim_uint8 * rasterize()=0
virtual bool isFixed() const =0
#define TYPE_DATA
Definition: ossimRtti.h:339
virtual void getBoundingBox(ossimIrect &box)=0
virtual ossimObject * dup() const =0
virtual void setHorizontalVerticalShear(double horizontalShear, double verticalShear)
Definition: ossimFont.h:161
virtual void setDeviceDpi(int horizontalDeviceUnits, int verticalDeviceUnits)
Definition: ossimFont.h:238
virtual void setString(const ossimString &s)
Definition: ossimFont.h:119
virtual void setScale(double horizontal, double vertical)
Definition: ossimFont.cpp:26
virtual void getFixedSizes(vector< ossimIpt > &sizes) const =0
virtual void setPixelSize(int horizontalPixelSize, int verticalPixelSize)
Definition: ossimFont.h:205
virtual const ossim_uint8 * getBuf() const =0
unsigned char ossim_uint8