OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAnnotationGdBitmapFont.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)
6 // Description:
7 //
8 //*************************************************************************
9 // $Id: ossimAnnotationGdBitmapFont.cpp 12276 2008-01-07 19:58:43Z dburken $
12 #include <ossim/base/ossimCommon.h>
13 
14 #include <ossim/imaging/gdfonts.inc>
15 #include <ossim/imaging/gdfontl.inc>
16 #include <ossim/imaging/gdfontg.inc>
17 #include <ossim/imaging/gdfontmb.inc>
18 #include <ossim/imaging/gdfontt.inc>
19 
21  const ossimString &text,
22  ossimGdFontPtr font,
23  unsigned char r,
24  unsigned char g,
25  unsigned char b,
26  long thickness)
27  :ossimAnnotationObject(r, g, b, thickness),
28  theFontPtr(font),
29  theText(text),
30  thePosition(position)
31 {
33 }
34 
36  : ossimAnnotationObject(rhs),
37  theFontPtr(rhs.theFontPtr),
38  theText(rhs.theText),
39  theBoundingRect(rhs.theBoundingRect),
40  thePosition(rhs.thePosition)
41 {
42 }
43 
45 {
46 }
47 
49 {
50  rect = theBoundingRect;
51 }
52 
54 {
55  thePosition.x *= x;
56  thePosition.y *= y;
57 
59 }
60 
62 {
63  if(!theFontPtr||
64  !anImage.getImageData())
65  {
66  return;
67  }
68  ossimDpt origin = anImage.getImageData()->getOrigin();
69 
70  ossimDrect rect = anImage.getImageData()->getImageRectangle();
71 
72  if(theBoundingRect.intersects(rect))
73  {
75  ossimDpt position(thePosition.x - origin.x,
76  thePosition.y - origin.y);
77  for(std::string::size_type character = 0;
78  character < theText.size();
79  ++character)
80  {
81  long charOffset = theText[character];
82 
83  // we need to shift the offset to a positive value.
84  // if it goes negative we just add 256 to the value.
85  if(charOffset < 0)
86  {
87  charOffset += 256;
88  }
89  // get the starting offset to the bitmap
90  long offset = charOffset*theFontPtr->w*theFontPtr->h;
91  for(long row = 0; row < theFontPtr->h; ++row)
92  {
93  for(long col = 0; col < theFontPtr->w; ++col)
94  {
95  if(theFontPtr->data[(int)offset])
96  {
97  anImage.slowPlotPixel(ossim::round<int>(position.x + col),
98  ossim::round<int>(position.y + row),
99  theRed,
100  theGreen,
101  theBlue);
102  }
103  ++offset;
104  }
105  }
106  position.x += theFontPtr->w;
107  }
108  }
109 }
110 
112 {
114 
115  if(intersects(rect))
116  {
117  result = (ossimAnnotationGdBitmapFont*)dup();
118  }
119 
120  return result;
121 }
122 
124 {
125  out << "text_value: " << theText << endl
126  << "text_bouding_rect: " << theBoundingRect << endl
127  << "text_position: " << thePosition << endl;
128  return out;
129 }
130 
132 {
133  if(theFontPtr)
134  {
136  thePosition.y,
139  }
140 }
141 
143 {
144  theFontPtr = font;
145 }
146 
148 {
149  theText = text;
151 }
152 
154  const ossimString& text)
155 {
156  setText(text);
157  setUpperLeftTextPosition(upperLeft);
158 }
159 
161 {
162  thePosition = position;
164 }
165 
167  const ossimString& text)
168 {
169  setText(text);
170  setCenterTextPosition(upperLeft);
171 }
172 
174 {
175  thePosition.x = position.x - theBoundingRect.width()/2.0;
176  thePosition.y = position.y - theBoundingRect.height()/2.0;
178 }
179 
181 {
182  return theBoundingRect.pointWithin(imagePoint);
183 }
ossim_uint32 x
virtual void applyScale(double x, double y)
bool pointWithin(const ossimDpt &pt, double epsilon=0.0) const
Definition: ossimDrect.h:781
virtual bool intersects(const ossimDrect &rect) const
ossim_float64 width() const
Definition: ossimDrect.h:522
ossim_uint32 y
virtual void draw(ossimRgbImage &anImage) const
double y
Definition: ossimDpt.h:165
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual ossimDrect getBoundingRect() const
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
virtual void setUpperLeftText(const ossimDpt &upperLeft, const ossimString &text)
virtual void setCenterTextPosition(const ossimDpt &position)
void slowPlotPixel(ossim_int32 x, ossim_int32 y, ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
This will plot a pixel and will do inside outside compares.
std::string::size_type size() const
Definition: ossimString.h:405
virtual ossimIrect getImageRectangle() const
virtual bool isPointWithin(const ossimDpt &imagePoint) const
virtual void setFont(ossimGdFontPtr font)
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
virtual void setUpperLeftTextPosition(const ossimDpt &position)
bool intersects(const ossimDrect &rect) const
Definition: ossimDrect.cpp:289
ossim_float64 height() const
Definition: ossimDrect.h:517
virtual void setCenterText(const ossimDpt &center, const ossimString &text)
virtual ossimObject * dup() const
void setDrawColor(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255)
virtual void setText(const ossimString &text)
double x
Definition: ossimDpt.h:164
ossimAnnotationGdBitmapFont(const ossimDpt &position=ossimDpt(0, 0), const ossimString &text=ossimString(""), ossimGdFontPtr font=ossimGdFontLarge, unsigned char r=255, unsigned char g=255, unsigned char b=255, long thickness=1)
virtual const ossimIpt & getOrigin() const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23