freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Information Request


From: Feinberg, Matthew
Subject: RE: Information Request
Date: Mon, 10 Apr 2000 13:28:33 -0400

Yep, I see one problem already... it's missing

  char index;

and

  index = *string;

There are probably other problems.  

Anyway, the point is, what you want to do is possible.  The code I
provided is one example of how to do it.

--Matthew

-----Original Message-----
From: Feinberg, Matthew [mailto:address@hidden
Sent: Monday, April 10, 2000 1:26 PM
To: 'address@hidden'; address@hidden
Subject: RE: Information Request


Yes.  You would need to write a function to get the advance width of
each character at the appropriate size.

Here's some code I use to accomplish the same thing use FreeType 1.3.1.
Note that I've omitted error handling for clarity and deleted a lot of
proprietary stuff that I'm not supposed disclose, and I haven't tried
compiling it after deleting the proprietary stuff, so it will probably
need tweaking in order to work properly.  Also, it assumes there's
already a FreeType library instance avaialble in the global variable
FreeTypeLib, and it assumes you only care about the Unicode character
map from the font.  Anyway, for what it's worth, here it is:

int GetStringPixelLength(
        char *string,
        char *font,
        int dpi_x,
        int dpi_y,
        int ptsize)
{
    TT_Instance Instance;
    TT_Face Face;
    TT_Face_Properties Properties;
    short Platform, Encoding;
        int i, width=0;
        bool FoundOne
    TT_Glyph     glyph;
    TT_Glyph_Metrics metrics;

    TT_Open_Face( FreeTypeLib, font, &Face );
    TT_Get_Face_Properties( Face, &Properties );

    for ( i = 0; i < Properties.num_CharMaps; i++ )
    {
        if ( TT_Get_CharMap_ID( Face, i, &Platform, &Encoding ) == 0)
        {
            if ( Platform == 3 && Encoding == 1 ) || 
               ( Platform == 0 && Encoding == 0) )
             {
                TT_Get_CharMap( Face, i, &Chars );
                FoundOne = 1;
                break;
             }
        }
    }

        if( !FoundOne )
        {
                // error
        }

    TT_New_Instance( CF->Face, &Instance );
    TT_Set_Instance_Resolutions( Instance, dpi_x, dpi_y );
        TT_Set_Instance_Transform_Flags( Instance, FALSE, FALSE );
        TT_Set_Instance_CharSize( Instance, ptsize  * 64 );
    width=0;

    for ( ; *string; string++ )
    {
                TT_New_Glyph( face, &glyph );

                TT_Load_Glyph( Instance, glyph, index, 
                        TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH );
                TT_Get_Glyph_Metrics( glyph, &metrics );

                width += (metrics.advance+32) / 64;

                TT_Done_Glyph( glyph );
        }

        return width;
}

Hope this helps!

--
Matthew A. Feinberg
Lead Programmer
Catharon Productions, Inc.
2119 Route 66, Ghent, NY 12075, USA

E-Mail:  address@hidden
Web:  http://www.catharon.com

Tel: (518)392-9003
Fax: (518)392-6444



-----Original Message-----
From: Brian Cowie [mailto:address@hidden
Sent: Monday, April 10, 2000 11:49 AM
To: address@hidden
Subject: Information Request


I've looked through the documentation and can't find an answer for my
question, so I'm writing directly.

What I'd like is some function, where I can give it the following
parameters:

a string
a font
a font size
a device resolution

The return from the function would give me:

the length of the string, in the device resolution, at the specified
font
size.

For example, if I gave the function a string "0123456789', for a Courier
10-pitch font and a 300 dpi device, the function should return a result
of
300. That is, ten characters of a 10-pitch font should be 1 inch or 300
dots
long. It would also be helpful if the function could also return the
height
of the string.

Can I use FreeType to do this?

Regards,
Brian Cowie



reply via email to

[Prev in Thread] Current Thread [Next in Thread]