OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAnnotationFontObject.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: ossimAnnotationFontObject.cpp 15766 2009-10-20 12:37:09Z gpotts $
10 
13 
14 RTTI_DEF1(ossimAnnotationFontObject, "ossimAnnotationFontObject", ossimAnnotationObject);
15 
18  theFont(ossimFontFactoryRegistry::instance()->getDefaultFont()),
19  thePosition(0,0),
20  theString(""),
21  theRotation(0.0),
22  theHorizontalScale(0.0),
23  theVerticalScale(0.0),
24  theHorizontalShear(0.0),
25  theVerticalShear(0.0)
26 {
27  setFontInfo();
29 }
30 
32  const ossimString& s,
33  const ossimIpt& pixelSize,
34  double rotation,
35  const ossimDpt& scale,
36  const ossimDpt& shear,
37  unsigned char r,
38  unsigned char g,
39  unsigned char b)
40  :ossimAnnotationObject(r,g,b),
41  theFont(ossimFontFactoryRegistry::instance()->getDefaultFont()),
42  theString(s),
43  thePixelSize(pixelSize),
44  theRotation(rotation),
45  theHorizontalScale(scale.x),
46  theVerticalScale(scale.y),
47  theHorizontalShear(shear.x),
48  theVerticalShear(shear.y)
49 {
50  setFontInfo();
51  thePosition = upperLeft;
53 #if 0
54  if (theFont)
55  {
57  }
58  theBoundingRect += upperLeft;
60 #endif
61 }
62 
65  thePosition(rhs.thePosition),
66  theString(rhs.theString),
67  thePixelSize(rhs.thePixelSize),
68  theRotation(rhs.theRotation),
69  theHorizontalScale(rhs.theHorizontalScale),
70  theVerticalScale(rhs.theVerticalScale),
71  theHorizontalShear(rhs.theHorizontalShear),
72  theVerticalShear(rhs.theVerticalShear),
73  theBoundingRect(rhs.theBoundingRect)
74 {
75  theFont = rhs.theFont;
76  setFontInfo();
77 }
78 
79 
81 {
82  theFont = 0;
83 }
84 
86 {
88  {
89  return;
90  }
91  if (!theFont)
92  {
93  return;
94  }
95 
96  if(!thePixelSize.x || !thePixelSize.y)
97  {
98  return; // (DAH) we have to have some demension to write!
99  }
100 
101  ossimRefPtr<ossimImageData> destination = anImage.getImageData();
102 
103  if(destination.valid())
104  {
105  ossimIrect destRect = anImage.getImageData()->getImageRectangle();
106 
107  ossimIpt shift(-theBoundingRect.ul().x,
108  -theBoundingRect.ul().y);
109 
110  destRect += shift;
111  ossimIrect boundingRect = theBoundingRect + shift;
112 
113  if(boundingRect.intersects(destRect))
114  {
115  setFontInfo();
116 
117  ossimIrect fontBufferRect;
118  ossimIrect boundingFontBox;
119 
120  theFont->setClippingBox(destRect);
121  theFont->getBoundingBox(boundingFontBox);
122 
123  const ossim_uint8* srcBuf = theFont->rasterize();
124  if (!srcBuf)
125  {
126  return;
127  }
128 
129  theFont->getBufferRect(fontBufferRect);
130  ossimIrect clipRect = boundingRect.clipToRect(fontBufferRect);
131 
132  long clipHeight = clipRect.height();
133  long clipWidth = clipRect.width();
134 
135  long destinationOffset = (long)(((clipRect.ul().y - destRect.ul().y)* destRect.width()) +
136  (clipRect.ul().x - destRect.ul().x));
137  long fontBufferOffset = (long)(((clipRect.ul().y - fontBufferRect.ul().y)*fontBufferRect.width()) +
138  (clipRect.ul().x - fontBufferRect.ul().x));
139 
140 
141  long destinationIndex = destinationOffset;
142  long srcIndex = fontBufferOffset;
143  long num_bands = destination->getNumberOfBands();
144  ossim_int32 s_width = (ossim_int32)fontBufferRect.width();
145  ossim_int32 d_width = (ossim_int32)destRect.width();
146 
147  num_bands = num_bands > 3? 3:num_bands;
148 
149  unsigned char colorArray[3];
150  long band = 0;
151  colorArray[0] = theRed;
152  colorArray[1] = theGreen;
153  colorArray[2] = theBlue;
154  ossim_uint8** destBuf = new ossim_uint8*[num_bands];
155  for(band = 0; band < num_bands;++band)
156  {
157  destBuf[band] = static_cast<ossim_uint8*>(destination->getBuf(band));
158  if (!destBuf[band])
159  {
160  delete [] destBuf;
161  return;
162  }
163  }
164 
165  for(long line = 0; line < clipHeight; ++line)
166  {
167  for(long col = 0; col < clipWidth; ++col)
168  {
169  if(srcBuf[srcIndex + col])
170  {
171  for (band=0; band<num_bands; ++band)
172  {
173  *(destBuf[band] + destinationIndex + col) = colorArray[band];
174  }
175  }
176  }
177  srcIndex += s_width;
178  destinationIndex += d_width;
179  }
180  delete [] destBuf;
181  }
182  }
183 }
184 
186 {
187  if(theFont.valid())
188  {
189  out << "Family: " << theFont->getFamilyName() << endl
190  << "Style: " << theFont->getStyleName() << endl;
191  }
192  out << "String: " << theString << endl
193  << "Upper Left Position: " << thePosition << endl
194  << "Rotation: " << theRotation << endl
195  << "Horizontal shear: " << theHorizontalShear << endl
196  << "Vertical shear: " << theVerticalShear << endl
197  << "Vertical scale: " << theVerticalScale << endl
198  << "Horizontal scale: " << theHorizontalScale << endl
199  << "Bounding rect: " << theBoundingRect << endl;
200  return out;
201 }
202 
204 {
205  rect = theBoundingRect;
206 }
207 
209 {
210  setFontInfo();
211  if(theFont.valid())
212  {
213  ossimIrect textRect;
214  theFont->getBoundingBox(textRect);
215  ossim_int32 w = textRect.width();
216  ossim_int32 h = textRect.height();
217  ossim_int32 ulx = thePosition.x;
218  ossim_int32 uly = thePosition.y;
220  uly,
221  ulx + w - 1,
222  uly + h - 1);
223  }
224 }
225 
227 {
228  return theBoundingRect.pointWithin(imagePoint);
229 }
230 
232 {
233  theFont = font;
234 
235  if(!theFont)
236  {
238  }
239 }
240 
242 {
244  ossimIpt delta = position-pt;
245  theBoundingRect += delta;
247 }
248 
250 {
251  ossimDpt pt = theBoundingRect.ul();
252  ossimIpt delta = position-pt;
253  theBoundingRect += delta;
255 }
256 
258 {
259  if(theFont.valid())
260  {
266  thePixelSize.y);
267  }
268 }
269 
271 {
272  theString = s;
273 }
274 
276 {
277  return theString;
278 }
279 
281 {
282  if(intersects(rect))
283  {
284  return (ossimAnnotationObject*)dup();
285  }
286 
287  return (ossimAnnotationObject*)NULL;
288 }
289 
291 {
292  return rect.intersects(theBoundingRect);
293 }
294 
296 {
297  thePixelSize = size;
298  setFontInfo();
299  if (theFont.valid())
300  {
302  }
305 }
306 
308 {
309  theRotation = rotation;
310  setFontInfo();
311  if (theFont.valid())
312  {
314  }
317 }
318 
320 {
321  theHorizontalScale = scale.x;
322  theVerticalScale = scale.y;
323  setFontInfo();
324  if (theFont.valid())
325  {
327  }
330 }
331 
333 {
334  theHorizontalShear = shear.x;
335  theVerticalShear = shear.y;
336  setFontInfo();
337  if (theFont.valid())
338  {
340  }
343 }
344 
346 {
347  thePixelSize = info.thePointSize;
348  theRotation = info.theRotation;
350  theVerticalScale = info.theScale.y;
352  theVerticalShear = info.theShear.y;
353 
354  setFontInfo();
355  if (theFont.valid())
356  {
358  }
361 }
362 
364 {
365  thePosition.x = ossim::round<int>(thePosition.x *x);
366  thePosition.y = ossim::round<int>(thePosition.y *y);
367 
368  setFontInfo();
370 
371 }
372 
374 {
375  return new ossimAnnotationFontObject(*this);
376 }
ossim_uint32 x
virtual void getBufferRect(ossimIrect &bufRect)
Definition: ossimFont.h:252
virtual ossim_uint32 getNumberOfBands() const
virtual bool intersects(const ossimDrect &rect) const
virtual bool isPointWithin(const ossimDpt &imagePoint) const
virtual ossimObject * dup() const
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
virtual void setFont(ossimFont *font)
double y
Definition: ossimDpt.h:165
ossim_uint32 height() const
Definition: ossimIrect.h:487
ossimRefPtr< ossimFont > theFont
virtual ossimString getString() const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual void setPointSize(const ossimIpt &size)
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
virtual void applyScale(double x, double y)
virtual void setUpperLeftPosition(const ossimIpt &position)
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual const ossim_uint8 * rasterize()=0
virtual void draw(ossimRgbImage &anImage) const
virtual ossimDrect getBoundingRect() const
yy_size_t size
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
virtual void setScale(const ossimDpt &scale)
virtual ossimString getFamilyName() const
Definition: ossimFont.h:133
ossimIpt midPoint() const
Definition: ossimIrect.h:750
virtual void setString(const ossimString &s)
RTTI_DEF1(ossimAnnotationFontObject, "ossimAnnotationFontObject", ossimAnnotationObject)
virtual void getBoundingBox(ossimIrect &box)=0
virtual void setRotation(double rotation)
virtual ossimIrect getImageRectangle() const
Class to draw fonts onto an image.
virtual void setGeometryInformation(const ossimFontInformation &info)
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
virtual ossimString getStyleName() const
Definition: ossimFont.h:141
virtual void setHorizontalVerticalShear(double horizontalShear, double verticalShear)
Definition: ossimFont.h:161
virtual void setString(const ossimString &s)
Definition: ossimFont.h:119
static ossimFontFactoryRegistry * instance()
virtual void setClippingBox(const ossimIrect &clipBox=ossimIrect(0, 0, 0, 0))
Definition: ossimFont.h:266
virtual void setScale(double horizontal, double vertical)
Definition: ossimFont.cpp:26
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
virtual const void * getBuf() const
virtual void setPixelSize(int horizontalPixelSize, int verticalPixelSize)
Definition: ossimFont.h:205
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
double x
Definition: ossimDpt.h:164
bool hasNans() const
Definition: ossimIrect.h:337
ossim_int32 x
Definition: ossimIpt.h:141
virtual void setRotation(double rotationInDegrees)
Definition: ossimFont.cpp:19
unsigned char ossim_uint8
virtual void setShear(const ossimDpt &shear)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void setCenterPosition(const ossimIpt &position)
int ossim_int32
bool pointWithin(const ossimIpt &pt) const
Definition: ossimIrect.h:729