OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGdBitmapFont.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks.com)
6 // Description:
7 //
8 //********************************************************************
9 // $Id: ossimGdBitmapFont.cpp 15833 2009-10-29 01:41:53Z eshirschorn $
11 #include "string.h"
12 
13 RTTI_DEF1(ossimGdBitmapFont, "ossimGdBitmapFont", ossimFont);
14 
16  const ossimString& styleName,
17  const ossimGdFont* gdFontPtr)
18  :ossimFont(familyName,
19  styleName,
20  (int)gdFontPtr->w,
21  (int)gdFontPtr->h),
22  theGdFontPtr(gdFontPtr),
23  theBufferSize(0),
24  theOutputBuffer(NULL)
25 {
26 }
27 
29  :ossimFont(rhs),
30  theGdFontPtr(rhs.theGdFontPtr),
31  theBufferSize(rhs.theBufferSize),
32  theOutputBuffer(NULL)
33 {
34  if(theBufferSize)
35  {
38  }
39 }
40 
42 {
43  if(theOutputBuffer)
44  {
45  delete [] theOutputBuffer;
46  theOutputBuffer = NULL;
47  }
48 }
49 
51 {
53  {
54  box = ossimIrect(0,0,
57  }
58  else
59  {
60  box = ossimIrect(0,
61  0,
62  0,
63  0);
64  }
65 
66  // I currently don't support rotations and other affine operations so I will comment this
67  // bounding box test out and use the above.
68  //
69 #if 0
70  if(theGdFontPtr)
71  {
72  if((theRotation == 0.0)&&
73  (theHorizontalScale == 1.0)&&
74  (theVerticalScale == 1.0))
75  {
76  box = ossimIrect(0,0, theGdFontPtr->w-1, theGdFontPtr->h-1);
77  }
78  else
79  {
80  ossimIrect localBox(0,0, theGdFontPtr->w-1, theGdFontPtr->h-1);
81  double ulx, uly;
82  double llx, lly;
83  double lrx, lry;
84  double urx, ury;
85 
86  double min_x, min_y, max_x, max_y;
87 
88  ulx = 0.0;
89  uly = 0.0;
90 
91  llx = (theAffineTransform[0][0]*localBox.ll().x +
92  theAffineTransform[0][1]*localBox.ll().y);
93  lly = theAffineTransform[1][0]*localBox.ll().x +
94  theAffineTransform[1][1]*localBox.ll().y;
95 
96  lrx = (theAffineTransform[0][0]*localBox.lr().x +
97  theAffineTransform[0][1]*localBox.lr().y);
98  lry = theAffineTransform[1][0]*localBox.lr().x +
99  theAffineTransform[1][1]*localBox.lr().y;
100  urx = (theAffineTransform[0][0]*localBox.ur().x +
101  theAffineTransform[0][1]*localBox.ur().y);
102  ury = theAffineTransform[1][0]*localBox.ur().x +
103  theAffineTransform[1][1]*localBox.ur().y;
104 
105 
106  min_x = std::min(ulx, std::min(llx, (std::min(lrx, urx))));
107  max_x = std::max(ulx, std::max(llx, (std::max(lrx, urx))));
108 
109  min_y = std::min(uly, std::min(lly, (std::min(lry, ury))));
110  max_y = std::max(uly, std::max(lly, (std::max(lry, ury))));
111 
112 
113 
114  box = ossimIrect((int)floor(min_x), (int)floor(min_y),
115  (int)ceil(max_x), (int)ceil(max_y));
116  }
117  }
118 #endif
119 }
120 
122 {
123  // make sure the buffer is allocated for the output string
124  allocateBuffer();
125 
126  if(theOutputBuffer)
127  {
128  memset(theOutputBuffer, 0, theBufferSize);
129  rasterizeNormal();
130  }
131 
132  return theOutputBuffer;
133 }
134 
136 {
137  ossimIrect outBox;
138  ossimIrect inBox(0,0,
140  theGdFontPtr->h-1);
141 
142  getBoundingBox(outBox);
143 
144 
145  long charOffset = 0;
146  long bufOffset = 0;
147  long inW = inBox.width();
148  long inH = inBox.height();
149  long outW = outBox.width();
150  long outH = outBox.height();
151  ossim_uint8* inBuf = new ossim_uint8[inBox.width()*inBox.height()];
152 
153  for(std::string::size_type character = 0;
154  character < theStringToRasterize.size();
155  ++character)
156  {
157  charOffset = theStringToRasterize[character];
158 
159  // we need to shift the offset to a positive value.
160  // if it goes negative we just add 256 to the value.
161  if(charOffset < 0)
162  {
163  charOffset += 256;
164  }
165 
166  // which col do we start on
167  bufOffset = (long)character*theGdFontPtr->w;
168 
169  // get the starting offset to the bitmap
170  charOffset = charOffset*theGdFontPtr->w*theGdFontPtr->h;
171 
172  for(long row = 0; row < (theGdFontPtr->h); ++row)
173  {
174  for(long col = 0; col < theGdFontPtr->w; ++col)
175  {
176  if(theGdFontPtr->data[charOffset])
177  {
178  inBuf[bufOffset+col] = 255;
179  }
180  ++charOffset;
181  }
182  bufOffset += inW;
183  }
184  }
185 
186  if((inW == outW)&&(inH==outH))
187  {
188  memcpy(theOutputBuffer, inBuf, inW*inH);
189  }
190  else
191  {
192  // now lets expand or contract the input buf to the output buf.
193  long *xLut = new long[outW];
194  long *yLut = new long[outH];
195  long i = 0;
196  for(i = 0; i < outW; ++i)
197  {
198  xLut[i] = (int)(i*((double)inW/(double)outW));
199  }
200  for(i = 0; i < outH; ++i)
201  {
202  yLut[i] = (int)(i*((double)inH/(double)outH));
203  }
204 
205  ossim_uint8* outBuf = theOutputBuffer;
206  for(long row= 0; row < outH; ++row)
207  {
208  long inYOffset = yLut[row]*inW;
209  for(long col=0; col < outW; ++col)
210  {
211  *outBuf = inBuf[inYOffset + xLut[col]];
212  ++outBuf;
213  }
214  }
215  delete [] xLut;
216  delete [] yLut;
217  }
218 
219  delete [] inBuf;
220 }
221 
223 {
224  ossimIrect box;
225 
226  getBoundingBox(box);
227  long bufferSize = box.width()*box.height();
228  if(bufferSize != theBufferSize)
229  {
230  theBufferSize = bufferSize;
231 
232  if(theOutputBuffer)
233  {
234  delete theOutputBuffer;
235  theOutputBuffer = NULL;
236  }
238  {
240 
241  }
242  }
243 }
244 
245 void ossimGdBitmapFont::getFixedSizes(vector<ossimIpt>& sizes)const
246 {
247  sizes.push_back(ossimIpt(theHorizontalPixelSize,
249 }
ossimGdBitmapFont(const ossimString &familyName, const ossimString &styleName, const ossimGdFont *gdFontPtr)
ossimString theStringToRasterize
Definition: ossimFont.h:292
virtual void getFixedSizes(vector< ossimIpt > &sizes) const
double theRotation
Definition: ossimFont.h:295
NEWMAT::Matrix theAffineTransform
Definition: ossimFont.h:314
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ll() const
Definition: ossimIrect.h:277
double theVerticalScale
Definition: ossimFont.h:299
RTTI_DEF1(ossimGdBitmapFont, "ossimGdBitmapFont", ossimFont)
std::string::size_type length() const
Definition: ossimString.h:408
std::string::size_type size() const
Definition: ossimString.h:405
ossim_uint8 * theOutputBuffer
const ossimIpt & lr() const
Definition: ossimIrect.h:276
ossim_uint32 width() const
Definition: ossimIrect.h:500
const ossimIpt & ur() const
Definition: ossimIrect.h:275
const ossimGdFont * theGdFontPtr
virtual const ossim_uint8 * rasterize()
virtual void getBoundingBox(ossimIrect &box)
#define max(a, b)
Definition: auxiliary.h:76
ossim_int32 y
Definition: ossimIpt.h:142
ossim_int32 x
Definition: ossimIpt.h:141
int theHorizontalPixelSize
Definition: ossimFont.h:300
unsigned char ossim_uint8
#define min(a, b)
Definition: auxiliary.h:75
int ossim_int32
int theVerticalPixelSize
Definition: ossimFont.h:301
double theHorizontalScale
Definition: ossimFont.h:298