Font outline

Hi,

I'm searching a way to retrive font outline using wxpython. Is it possible? I cannot find any method that could be used to do this ...

bye

Gabriele Farina *DarkBard* wrote:

Hi,

I'm searching a way to retrive font outline using wxpython. Is it possible? I cannot find any method that could be used to do this ...

wxWidgets does not have that ability, although it would be a nice feature to add.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Gabriele Farina *DarkBard* wrote:

Hi,

I'm searching a way to retrive font outline using wxpython. Is it possible? I cannot find any method that could be used to do this ...

wxWidgets does not have that ability, although it would be a nice feature to add.

I'm studing some C font libraries ... maybe I'll make a python or wxPython extension. If I'll do the second one, I'll tell you.

I've seen it done in a C library called AntiGrain Geometry. I know
that at least Matplotlib extends python with some drawing functions
that use AGG, but I don't think you're going to find anything that
exposes the internals of the fonts. But it depends what your goal
is...

There's another 3d demo that extrudes a font in Z by getting the
outline, but I can't remember where I saw it.

The AntiGrain function that does it is a little scary:

        while(cur_glyph < end_glyph)
        {
            const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph;
            
            const char* end_poly = cur_glyph + th->cb;
            const char* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER);

            path.move_to(conv(th->pfxStart.x),
                         flip_y ? -conv(th->pfxStart.y) :
                                   conv(th->pfxStart.y));
           
            while(cur_poly < end_poly)
            {
                const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly;
                
                if (pc->wType == TT_PRIM_LINE)
                {
                    int i;
                    for (i = 0; i < pc->cpfx; i++)
                    {
                        path.line_to(conv(pc->apfx[i].x),
                                     flip_y ? -conv(pc->apfx[i].y) :
                                               conv(pc->apfx[i].y));
                    }
                }
                
                if (pc->wType == TT_PRIM_QSPLINE)
                {
                    int u;
                    for (u = 0; u < pc->cpfx - 1; u++) // Walk
through points in spline
                    {
                        POINTFX pnt_b = pc->apfx[u]; // B is always
the current point
                        POINTFX pnt_c = pc->apfx[u+1];
                        
                        if (u < pc->cpfx - 2) // If not on
last spline, compute C
                        {
                            // midpoint (x,y)
                            *(int*)&pnt_c.x = (*(int*)&pnt_b.x +
*(int*)&pnt_c.x) / 2;
                            *(int*)&pnt_c.y = (*(int*)&pnt_b.y +
*(int*)&pnt_c.y) / 2;
                        }
                        
                        path.curve3(conv(pnt_b.x),
                                    flip_y ? -conv(pnt_b.y) :
                                              conv(pnt_b.y),
                                    conv(pnt_c.x),
                                    flip_y ? -conv(pnt_c.y) :
                                              conv(pnt_c.y));
                    }
                }
                cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx;
            }
            cur_glyph += th->cb;
        }
        return true;

···

On Apr 4, 2005 1:28 PM, Robin Dunn <robin@alldunn.com> wrote:

Gabriele Farina *DarkBard* wrote:
> Hi,
>
> I'm searching a way to retrive font outline using wxpython. Is it
> possible? I cannot find any method that could be used to do this ...

The drawing program "skencil" is written in python and it can
supposedly render text along a curve. It must be able to get
font outlines somehow. Personally, I've been using Skencil
(nee Sketch) for 5+ years and I've never been able to get it to
properly display _any_ fonts at all on-screen, so I can't
verify that any of the font stuff actually works.

···

On 2005-04-04, Robin Dunn <robin@alldunn.com> wrote:

Gabriele Farina *DarkBard* wrote:

Hi,

I'm searching a way to retrive font outline using wxpython. Is it
possible? I cannot find any method that could be used to do this ...

wxWidgets does not have that ability, although it would be a nice
feature to add.

--
Grant Edwards grante Yow! I just had a NOSE
                                  at JOB!!
                               visi.com

James Carroll wrote:

Gabriele Farina *DarkBard* wrote:
   

Hi,

I'm searching a way to retrive font outline using wxpython. Is it
possible? I cannot find any method that could be used to do this ...
     
I've seen it done in a C library called AntiGrain Geometry. I know
that at least Matplotlib extends python with some drawing functions
that use AGG, but I don't think you're going to find anything that
exposes the internals of the fonts. But it depends what your goal
is...

There's another 3d demo that extrudes a font in Z by getting the
outline, but I can't remember where I saw it.

It may have been OpenGLContext, but there's lots of others. I've
already told DarkBard this on another list, but in case others are
interested:

    * TTFQuery has the tools required to extract glyph outlines directly
      from TTF fonts
          o See ttfquery/glyph.py
    * It uses FontTools to do the actual extraction from the font, so
      doesn't require FreeType at all
    * OpenGLContext uses this to provide 3D extruded fonts (see
      OpenGLContext/scenegraph/text/_toolsfont.py)
          o http://pyopengl.sourceforge.net/screenshots/context/truetype3d.jpg
    * It supports composite characters (think accents (you can sort of
      see them in that screenshot, but they're at the end of the text
      string)), but has had no testing with exotic (non-Latin-1)
      character/glph sets

I'm not sure, but that code from AntiGrain looks as though it uses
FreeType? I always found that a pain to build on Win32 (though the
Matplotlib guys tell me that problems building FontTools were why they
didn't just use TTFQuery for their font-finding code). Still, it has
the virtue of being standardised on *nixes. Without FreeType, however,
you (I) have to code up the curve decomposition yourself (myself) (done
in glyph.py above)... but once you have the library written, it's pretty
easy to work with IMO.

http://ttfquery.sourceforge.net/
http://pyopengl.sourceforge.net/context/

Anyway, have fun all,
Mike

···

On Apr 4, 2005 1:28 PM, Robin Dunn <robin@alldunn.com> wrote:

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com