Thursday, July 18, 2013

Implementation

Octave use freetype library to render text for OpenGL. Trough ft_render class, string is rendered depending on font size, color an other parameters.
Every text object has interpreter parameter, which is by default set to 'tex'. Although Octave has only limited set of tex functionality implemented. All this is going trough ft_render class, and as a result we have information about text in 8NDArray, which is then used by OpenGL for rendering of rasterized image.

When upgrading existing system, programmer have to save already existing functionality and add a new one. To add latex markup, there have to be class for it. And normally some dispatch mechanism on top, which can pick what type of render will be used. Solution to this problem came with abstract class and dispatch mechanism inside wrapper. So here is new class organisation.

text_render present top wrapper class, and inside it there is a dispatch mechanism pointing to one of three classes for text rendering. It also handles memory and use base_text_render class to create and destroy objects, with rep pointer.

base_text_render is abstract class used as parent class to text rendering classes. It has base virtual methods, named base methods on image presented above this text.

ft_render is existing class, using freetype to render text. It inherit base methods and has additional methods.  Additional methods computes bounding box, rotate image, change mode of rendering and get extent.

dummy_render class is empty. Is integrated to this concept because we can use latex if there are additional programs needed for this system. And renderer used by default is useless without installed freetype library. So to get around null rep pointer, this class will be picked and it will be just have some method to print error and help users install freetype or/and latex.

latex_render present implemented functions already developed in C. They are modified to use C++ libraries and to work as methods inside this class.
 - adapter method - put get input string and then create TEX file for further use.
 - render method - use Latex system and GhostScript as described in earlier post. As final result there is bitmap image. But OpenGL renderer needs 8NDArray, so this part is not finished.
 -  get_bbox method - open EPS file and read bounding box data, which is then transformed to true values

NOTE: Octave community use interesting concept for memory management. There are some abstract class and then wrapper on top. When someone create object it's not handled directly in further code but rep pointers are used. Here is one example liboctave/util/


...
class octave_mutex;
class
octave_base_mutex
{
public:
friend class octave_mutex; 
octave_base_mutex (void) : count (1) { } 
virtual ~octave_base_mutex (void) { } 
virtual void lock (void); 
virtual void unlock (void); 
virtual bool try_lock (void); 
private:
octave_refcount <int>; count;
};
class
OCTAVE_API
octave_mutex
{
public:
octave_mutex (void); 
octave_mutex (const octave_mutex&; m)
: rep (m.rep)
{
rep->count++;
}
~octave_mutex (void)
{
if (--rep->count == 0)
delete rep;
}
octave_mutex& operator = (const octave_mutex& m)
{
if (rep != m.rep)
{
if (--rep->count == 0)
delete rep;
rep = m.rep;
rep->count++;
}
return *this;
}
void lock (void)
{
rep->lock ();
} 
void unlock (void)
{
rep->unlock ();
}
bool try_lock (void)
{
return rep->try_lock ();
} 
protected:
octave_base_mutex *rep;
};
...

No comments:

Post a Comment