freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] ftgray.c STANDALONE module demo?


From: Wenlin Institute
Subject: Re: [ft-devel] ftgray.c STANDALONE module demo?
Date: Mon, 17 Dec 2007 15:23:35 -0800


On Dec 17, 2007, at 1:34 AM, Werner LEMBERG wrote:

Referenced to ftgray.c's comments, I have compile `ftgrays' with the
_STANDALONE_ macro defined.  [...]  My question is how to us this
lib after compile it?  Anybody would give a usage demo?

I believe that such a demo usage has never been given on the list.  In
case someone can provide this I would be glad to add it as a very
simple demo to the ft2demos bundle.

I'm not sure if this is helpful, since I don't define _STANDALONE_, I use the whole FreeType library; but I do use a callback function with ft_raster_flag_direct. The following code works with FreeType version 2.1.4 (sorry, haven't updated for a while).

    params.flags = ft_raster_flag_aa | ft_raster_flag_direct;
    params.gray_spans = WenlinGrayRenderSpan; // callback
    wenlinGrayTarget = &ttMap;
    FT_Outline_Render(ttEngine, &ftOutline, &params);

static void WenlinGrayRenderSpan(int y, int count, FT_Span* spans, void *raster)
/* Callback function.
See FT_Raster_Span_Func in ftimage.h, and model gray_render_span () in ftgrays.c The original fourth parameter was "PRaster", but that's only defined in ftgrays.c, so we just set wenlinGrayTarget to point to the bitmap (same as raster->target). The difference from the original function is that we require that the new value for a pixel ("coverage") is "darker" (numerically greater) than the current value; if not darker, keep the current color. This allows us to rasterize Hanzi one stroke at a time; otherwise, the anti-aliasing looks wrong when strokes overlap. */
{
    FT_Bitmap *map = wenlinGrayTarget; // = &raster->target;
    size_t scanlineOffset, offsetLimit;

    /* First of all, compute the scanline offset. */
    if (map->pitch >= 0) {
        if (y + 1 > map->rows) {
             return;
        }
        scanlineOffset = (map->rows - 1 - y) * map->pitch;
    }
    else {
        scanlineOffset = y * (0 - map->pitch);
    }
    /* Make it bomb-proof, don't write outside bitmap! */
    offsetLimit = map->width * map->rows;
    if (scanlineOffset >= offsetLimit) {
        SorryGenericWarning("WenlinGrayRenderSpan");
        return;
    }
    for ( ; count > 0; count--, spans++) {
        uc c = spans->coverage;
        if (c) {
            size_t ofs = scanlineOffset + spans->x;
            size_t len = spans->len;
            if (ofs + len <= offsetLimit) {
                while (len--) {
                    // This test is unique to the Wenlin version.
                    if (c > map->buffer[ofs]) {
                        map->buffer[ofs] = c;
                    }
                    ++ofs;
                }
            }
        }
    }
} // WenlinGrayRenderSpan

文林 Wenlin Institute, Inc.        Software for Learning Chinese
E-mail: address@hidden     Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)
☯









reply via email to

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