Search code examples
c++pango

How to subclass Pango::Renderer in C++


I'm trying to subclass the Pango::Renderer to draw text on an osg::Texture2D, but I cannot find a public constructor (except a copy-constructor) in its header file, neither another method to create a Pango::Renderer instance (like a static create method the Layout class for example provides).

So, how would I:

  1. create a Pango::Renderer instance
  2. subclass Pango::Renderer.

I've tried the following code for subclassing:

#include <pangomm/renderer.h>

class PangoRendererCanvas: public Pango::Renderer {
    public:
        PangoRendererCanvas() {}
};

but that gave the following compilation error:

error: no matching function for call to ‘Pango::Renderer::Renderer()’

        PangoRendererCanvas::PangoRendererCanvas() {
                                                                                   ^

According to the docs for Pango::Renderer, this should be possible:

Pango::Renderer API documentation

By subclassing Pango::Renderer and overriding operations such as draw_glyphs and draw_rectangle, renderers for particular font backends and destinations can be created.

I'm using PangoMM 2.46.2.


Solution

  • I just checked, the manual was generated directly from the source code, as the code comment states exactly the same.

    As I suggested, I would look at the header files. The manual is not clear enough. There are protected constructors, they are inherited from Object. The first one is what you need to use.

    protected:
      explicit Renderer(const Glib::ConstructParams& construct_params);
      explicit Renderer(PangoRenderer* castitem);
    

    Inherited from

    protected:
      explicit Object(const Glib::ConstructParams &construct_params);
      explicit Object(GObject *castitem);