[AD] Patch for color font output

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

As Andrew Durdin <andy@xxxxxxxxxx> rightly pointed out, color font
output on a colored background is incorrect. I enclose a patch:

--- c:/home/cvs/allegro/src/font.c	Mon Dec  4 23:47:42 2000
+++ ./font.c	Thu Dec 28 04:09:46 2000
@@ -577,15 +577,13 @@
 
     acquire_bitmap(bmp);
 
+    if(fg < 0 && bg >= 0) rectfill(bmp, x, y, x + text_length(f, text) - 1, y + text_height(f) - 1, bg);
+
     while( (ch = ugetxc(&p)) ) {
         BITMAP* g = color_findglyph(f, ch);
         if(g) {
             if(fg < 0) {
-                if(bg < 0) {
-                    bmp->vtable->draw_256_sprite(bmp, g, x, y);
-                } else {
-                    blit(g, bmp, 0, 0, x, y, g->w, g->h);
-                }
+                bmp->vtable->draw_256_sprite(bmp, g, x, y);
             } else {
                 bmp->vtable->draw_character(bmp, g, x, y, fg);
             }
And also a test program, just to ensure that the change is correct and
all is as it should be:

#include <allegro.h>
#include <stdio.h>

#define ALLEGRO_PATH "d:/allegro"

int black, white, trans, color;

typedef struct TEST {
    const int* text_color;
    const int* text_mode;
    const char* desc;
}TEST;

const TEST tests[] = {
    { &white, &black, "White text on a black background" },
    { &color, &black, "Color text on a black background" },
    { &black, &trans, "Black text on a transparent background" },
    { &color, &trans, "Color text on a transparent background" },
    { 0, 0, 0 }
};

int main(void)
{
    DATAFILE* dat = 0, * obj = 0;
    const TEST* test = tests;
    int y = 0;
    FONT* f = 0;

    if(allegro_init()) return -1;
    if(install_timer()) return -1;
    if(install_keyboard()) return -1;

    set_color_depth(8);
    if(set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) return -1;
    set_palette(desktop_palette);

    dat = load_datafile(ALLEGRO_PATH "/setup/setup.dat");
    if(!dat) return -1;
    obj = find_datafile_object(dat, "setup_font");
    if(!obj) {
        unload_datafile(dat);
        return -1;
    }
    f = obj->dat;

    black = makecol(0, 0, 0);
    white = makecol(255, 255, 255);
    trans = -1;
    color = -1;

    clear_to_color(screen, white);

    while(test->text_color && test->text_mode && test->desc) {
        text_mode(*(test->text_mode));
        textout(screen, f, test->desc, 0, y, *(test->text_color));
        y += text_height(f) * 5 / 4;
        test++;
    }

    clear_keybuf();
    readkey();

    unload_datafile(dat);

    return 0;
}


Bye for now,
-- 
Laurence Withers, lwithers@xxxxxxxxxx
                http://www.lwithers.demon.co.uk/

Attachment: signature.asc
Description: PGP signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/