Greg Haerr:
On a first test with GrSetGCUseBackground(gc, GR_FALSE); the application
work but not show the symbol (also with unsigned short type).

Then there is second bug with the internal font display where
for some reason the clear background triggers an assert
in fblin32.c.  I can probably debug this (unrelated) bug if
you send me your .bdf file and original nano-X .c program.

Ok. (The bdf file is too big for the ML)


I have wrote a win32 application starting from mtest.c (see attach) Both application not draw the symbol 1024

The quickest test I can think of for the next step would be
to use convbdf -f to create a .fnt file from your .bdf file,
and then comment out the builtin font, and let nano-X/win32
load the .fnt file (using the same code in your application) from
disk, and using the tested .fnt file method for displaying unicode
fonts. If this works, then we know that the problem is in the builtin font display mechanism. If it still fails, then there
is some issue relating to the .bdf file and/or the way we're
decoding and indexing the font glyphs.



where I call MwExtTextOut directly but result is the same: symbols from UTF8 coded file are wrong.
but everyone show different
symbol reading from the same file.
Furthermore, I have see that I read 20 char from UTF8 file but only 8 are showed.

Do the nano-X and win32 programs display different text in these
cases?

Yes.


You might put some printf() debug statements in the engine/devfont.c::ConvertEncoding (I think that's the function name)
which converts to and from all text encodings).

We should also take a quick look at the builtin font structure
where you specify your builtin .c font: its very important what
you use for the "encoding" member.

You are a big big man Greg!
Looking in drivers/genfont.c I'm using the same fontprocs of the others
font but they use the ASCII encoding.
I have added a fontprocsUC16 with MWTF_UC16 as encoding flag and the
UTF8 text in mwin application is correctly showed!!!! :D
Also 1024 symbol work well!
(see genfont.c)

The only one things that not work is the text in nanox application that
is still display different text.
Symbol 1024 and ascii is the same.
Nanox not show utf8 text, mwin yes.
Nanox show 2 more char than mwin app with unicode text.

Regards, Cristian

/*
 * pcfdemo - demonstrate PCF font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
draw_string(void)
{
        int count = 0;
        int x = 10;
        int y = 10;
        unsigned char ch;
        int tmp = 1024;
        GR_GC_ID gc = GrNewGC();

        GrSetGCFont(gc, font);

        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        GrSetGCBackground(gc, GR_RGB(0, 0, 0));

        printf("First char = %d, last char = %d\n", finfo.firstchar,
               finfo.lastchar);
        printf("Max width = %d, max height = %d\n", finfo.maxwidth,
               finfo.height);

        GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16); //this cause 
an assert error

/*
        for (ch = 0; ch < 255; ch++) {
                if (ch < finfo.firstchar || ch > finfo.lastchar)
                        GrFillRect(main_wid, gc, x, y, finfo.maxwidth, 
finfo.height);
                else
                        GrText(main_wid, gc, x, y, &ch, 1, GR_TFTOP | 
GR_TFASCII);

                if (++count >= 16) {
                        x = 0;
                        y += finfo.height;
                        count = 0;
                } else
                        x += finfo.maxwidth + 2;
        }
*/
        GrDestroyGC(gc);
}

static void drawFile(const char * fname){
        char buf[20]; //or int... unsigned?
        int count = 0;
        int x = 0;
        int y = 10;
        unsigned char ch;
        FILE * pfile;

        GR_GC_ID gc = GrNewGC();

        GrSetGCFont(gc, font);

        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        GrSetGCBackground(gc, GR_RGB(0, 0, 0));

        pfile = fopen(fname, "r");
        if( pfile > 0 ){
                fread(buf, 1, 20, pfile);
                GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
        }
        GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
        int width, height;

        if (GrOpen() == -1)
                return (-1);

        font = GrCreateFont("DejaVuLGCSans", 19, 0); //This is a builtin fonts 
generated by convbdf
        if (!font)
                printf("Unable to load font\n");

        GrGetFontInfo(font, &finfo);

        width = ((finfo.maxwidth + 2) * 16);
        height =
                (((finfo.lastchar - finfo.firstchar) / 16) +
                 5) * finfo.height;

        main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
                        GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
        GrSelectEvents(main_wid, 
GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
        GrMapWindow(main_wid);

        while (1) {
                GR_EVENT event;
                GrGetNextEvent(&event);

                if (event.type == GR_EVENT_TYPE_EXPOSURE)
                        draw_string();
//                      drawFile("utf8.txt");
//                      drawFile("unicode.txt");

                if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
                        GrClose();
                        exit(0);
              }
        }
}


/*
 * pcfdemo - demonstrate PCF font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
draw_string(void)
{
        int count = 0;
        int x = 0;
        int y = 10;
        unsigned char ch;
        GR_GC_ID gc = GrNewGC();

        GrSetGCFont(gc, font);

        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        GrSetGCBackground(gc, GR_RGB(0, 0, 0));

        printf("First char = %d, last char = %d\n", finfo.firstchar,
               finfo.lastchar);
        printf("Max width = %d, max height = %d\n", finfo.maxwidth,
               finfo.height);

        for (ch = 0; ch < 255; ch++) {
                if (ch < finfo.firstchar || ch > finfo.lastchar)
                        GrFillRect(main_wid, gc, x, y, finfo.maxwidth,
                                   finfo.height);
                else
                        GrText(main_wid, gc, x, y, &ch, 1,
                               GR_TFTOP | GR_TFASCII);

                if (++count >= 16) {
                        x = 0;
                        y += finfo.height;
                        count = 0;
                } else
                        x += finfo.maxwidth + 2;
        }

        GrDestroyGC(gc);
}

static void
drawSymbol(void)
{
        int x = 10;
        int y = 10;
        unsigned short tmp = 1024; //This should be the first symbol of 
cyrillic alphabet

        GR_GC_ID gc = GrNewGC();
        GrSetGCFont(gc, font);
        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        //GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application
        GrSetGCUseBackground(gc, GR_FALSE);

        GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16);
        GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII);

        GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
        int width, height;

        if (argc < 3){
                printf("Usage: %s <font> <size>\n", argv[0]);
                return (-1);
        }

        if (GrOpen() == -1)
                return (-1);

        font = GrCreateFont(argv[1], atoi(argv[2]), 0);
        if (!font)
                printf("Unable to load %s\n", argv[1]);

        GrGetFontInfo(font, &finfo);

        width = ((finfo.maxwidth + 2) * 16);
        height =
                (((finfo.lastchar - finfo.firstchar) / 16) +
                 5) * finfo.height;

        main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "pcfdemo",
                        GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
        GrSelectEvents(main_wid, 
GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
        GrMapWindow(main_wid);

        while (1) {
                GR_EVENT event;
                GrGetNextEvent(&event);

                if (event.type == GR_EVENT_TYPE_EXPOSURE)
                        //draw_string();
                        drawSymbol();

                if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
                        GrClose();
                        exit(0);
              }
        }
}

/*
 * builtinfont - demonstrate unicode builtin font loading for Nano-X
 */
#include <stdio.h>
#include <stdlib.h>
#define MWINCLUDECOLORS
#include "nano-X.h"

GR_FONT_ID font = 0;
GR_WINDOW_ID main_wid;
GR_FONT_INFO finfo;

static void
drawSymbol(void)
{
        int x = 10;
        int y = 10;
        unsigned short tmp = 1024; //This should be the first symbol of 
cyrillic alphabet

        GR_GC_ID gc = GrNewGC();
        GrSetGCFont(gc, font);
        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        //GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application
        GrSetGCUseBackground(gc, GR_FALSE);

        GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16);
        GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII);

        GrDestroyGC(gc);
}


static void drawFileUTF8(const char * fname){
        /* see
        static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned 
short *unicode16)
        in microwin_cvs/src/engine/devfont.c
        for text array type
        */
        unsigned char buf[20];
        int x = 10;
        int y = 50;
        FILE * pfile;

        GR_GC_ID gc = GrNewGC();
        GrSetGCFont(gc, font);
        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        GrSetGCUseBackground(gc, GR_FALSE);

        pfile = fopen(fname, "r");
        if( pfile > 0 ){
                fread(buf, 1, 20, pfile);
                GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8);
                fclose(pfile);
        }
        GrDestroyGC(gc);
}

static void drawFileUC16(const char * fname){
        /* see
        static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned 
short *unicode16)
        in microwin_cvs/src/engine/devfont.c
        for text array type
        */
        unsigned short buf[20];
        int x = 10;
        int y = 70;
        FILE * pfile;

        GR_GC_ID gc = GrNewGC();
        GrSetGCFont(gc, font);
        GrSetGCForeground(gc, GR_RGB(255, 255, 255));
        GrSetGCUseBackground(gc, GR_FALSE);

        pfile = fopen(fname, "r");
        if( pfile > 0 ){
                fread(buf, 1, 20, pfile);
                GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUC16);
                fclose(pfile);
        }
        GrDestroyGC(gc);
}

int
main(int argc, char **argv)
{
        int width, height;

        if (GrOpen() == -1)
                return (-1);

        font = GrCreateFont("DejaVuSans", 19, 0);
        if (!font)
                printf("Unable to load font\n");

        GrGetFontInfo(font, &finfo);

        width = ((finfo.maxwidth + 2) * 16);
        height =
                (((finfo.lastchar - finfo.firstchar) / 16) +
                 5) * finfo.height;

        main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont",
                        GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
        GrSelectEvents(main_wid, 
GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
        GrMapWindow(main_wid);

        while (1) {
                GR_EVENT event;
                GrGetNextEvent(&event);

                if (event.type == GR_EVENT_TYPE_EXPOSURE)
                        drawSymbol();
                        drawFileUTF8("utf8.txt");
                        drawFileUC16("unicode.txt");

                if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
                        GrClose();
                        exit(0);
              }
        }
}

/* builtin test program*/
#include <windows.h>

extern BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
                CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
                CONST INT *lpDx, int flags);

LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);

unsigned char bufUTF8[20];
unsigned short bufUC16[20];

static void loadBufFromFileUTF8(const char * fname){
        FILE * pfile;
        int readed;

        pfile = fopen(fname, "r");
        if( pfile > 0 ){
                readed = fread(bufUTF8, 1, 20, pfile);
                printf("%d bytes readed from %s\n", readed, fname);
                fclose(pfile);
        }
}

static void loadBufFromFileUC16(const char * fname){
        FILE * pfile;
        int readed;

        pfile = fopen(fname, "r");
        if( pfile > 0 ){
                readed = fread(bufUC16, 1, 20, pfile);
                printf("%d bytes readed from %s\n", readed, fname);
                fclose(pfile);
        }
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
        static char szAppName[]="FontWin";
        HWND hwnd;
        MSG msg;
        WNDCLASS wndclass;

        wndclass.style          = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = (WNDPROC)wproc;
        wndclass.cbClsExtra     =0;
        wndclass.cbWndExtra     =0;
        wndclass.hInstance      =0;
        wndclass.hIcon          =0;
        wndclass.hCursor        =0;
        wndclass.hbrBackground  =(HBRUSH)GetStockObject(LTGRAY_BRUSH);
        wndclass.lpszMenuName   =NULL;
        wndclass.lpszClassName  = szAppName;

        RegisterClass(&wndclass);
        hwnd=CreateWindowEx(0L,
                          szAppName,
                          "mbuiltinfont",
                          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          200,
                          200,
                          NULL,
                          NULL,
                          NULL,
                          NULL);
               
               
        ShowWindow(hwnd,iCmdShow);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,NULL,0,0)) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }      
        return msg.wParam;
}       
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{       
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
        short tmp = 1024;
        HGDIOBJ oldfont;
        
        switch (iMsg) {
        case WM_CREATE:
                break;
        case WM_PAINT:
        /*case WM_MOUSEFIRST:*/
                hdc=BeginPaint(hwnd,&ps);
                GetClientRect(hwnd,&rect);
                oldfont=SelectObject(hdc,CreateFont(19,
                        0,0,0,0,0,0,0,0,0,0,0,
                        FF_DONTCARE|DEFAULT_PITCH,
                        "DejaVuSans"));
                loadBufFromFileUTF8("utf8.txt");
                loadBufFromFileUC16("unicode.txt");
                MwExtTextOut(hdc, 0, 10, 0, NULL, &tmp, 1, NULL, MWTF_UC16); 
//This do not show nothing
                MwExtTextOut(hdc, 0, 20, 0, NULL, "ASCII", 5, NULL, 
MWTF_ASCII); 
                MwExtTextOut(hdc, 0, 40, 0, NULL, bufUTF8, 19, NULL, 
MWTF_UTF8); //This show only 8 symbols
                MwExtTextOut(hdc, 0, 60, 0, NULL, bufUC16, 19, NULL, MWTF_UC16);
//              DrawText(hdc, "Hola, NOS ¤¾¤¿¤¤ÇÑ", -1, &rect, 
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                EndPaint(hwnd,&ps);
                break;
        case WM_DESTROY:
                PostQuitMessage(0);
                break;
        default:
                return DefWindowProc(hwnd,iMsg,wParam,lParam);
        }      
        return (0);
}

/*
 * Copyright (c) 1999, 2000, 2003, 2005 Greg Haerr <[EMAIL PROTECTED]>
 *
 * Screen Driver Utilities
 * 
 * Microwindows Proportional Fonts & Routines (proportional font format)
 *
 * Modify this file to add/subtract builtin fonts from Microwindows
 *
 * This file contains the generalized low-level font/text
 * drawing routines.  Both fixed and proportional fonts are
 * supported, with fixed pitch structure allowing much smaller
 * font files.
 */
#include <stdio.h>
#include "device.h"
#include "genfont.h"

/* compiled in fonts*/
extern MWCFONT font_winFreeSansSerif11x13;      /* new MWFONT_SYSTEM_VAR (was 
MWFONT_GUI_VAR)*/
extern MWCFONT font_X6x13;                      /* MWFONT_SYSTEM_FIXED (should 
be ansi)*/
extern MWCFONT font_DejaVuSans;         /**/
/*extern MWCFONT font_winFreeSystem14x16;*/     /* deprecated 
MWFONT_SYSTEM_VAR*/
/*extern MWCFONT font_rom8x16;*/                /* deprecated MWFONT_OEM_FIXED*/
/*extern MWCFONT font_rom8x8, font_X5x7;*/      /* unused*/

/* handling routines for MWCOREFONT*/
static MWFONTPROCS fontprocs = {
        MWTF_ASCII,             /* routines expect ascii*/
        gen_getfontinfo,
        gen_gettextsize,
        gen_gettextbits,
        gen_unloadfont,
        corefont_drawtext,
        NULL,                   /* setfontsize*/
        NULL,                   /* setfontrotation*/
        NULL,                   /* setfontattr*/
};

/* handling routines for MWCOREFONT*/
static MWFONTPROCS fontprocsUC16 = {
        MWTF_UC16,              /* routines expect UC16*/
        gen_getfontinfo,
        gen_gettextsize,
        gen_gettextbits,
        gen_unloadfont,
        corefont_drawtext,
        NULL,                   /* setfontsize*/
        NULL,                   /* setfontrotation*/
        NULL,                   /* setfontattr*/
};

/*
 * Starting in v0.89pl12, we've moved to just two standard fonts,
 * MWFONT_SYSTEM_VAR, and MWFONT_SYSTEM_FIXED in order to reduce
 * the core Microwindows size.  The original, slightly smaller
 * MWFONT_GUI_VAR (ansi) is used as MWFONT_SYSTEM_VAR.  The original
 * MWFONT_SYSTEM_VAR (ansi) and MWFONT_OEM_FIXED are removed.
 * However, we redirect requests for the deprecated MWFONT_GUI_VAR
 * and MWFONT_OEM_FIXED to the included system variable and fixed
 * pitch fonts, respectively, to keep older programs running as expected.
 *
 * Additional builtin fonts can be added here by extending the 
 * gen_fonts array.  An better alternative, if running on a filesystem
 * is to use the new HAVE_FNT_SUPPORT .fnt file loader, which operates
 * internally exactly the same way after the fonts are loaded.  BDF
 * fonts can be converted to either .c format for use here or .fnt 
 * format for use by the .fnt loader using the fonts/convbdf.c program.
 */

/* first font is default font*/
MWCOREFONT gen_fonts[NUMBER_FONTS] = {
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR,   &font_winFreeSansSerif11x13},
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13},
        /* deprecated redirections for the time being*/
        {&fontprocs, 0, 0, 0, "Helvetica",         
&font_winFreeSansSerif11x13}, /* redirect*/
        {&fontprocs, 0, 0, 0, "Terminal",          &font_X6x13},        /* 
redirect*/
        {&fontprocsUC16, 0, 0, 0, "DejaVuSans",     &font_DejaVuSans}
};

/*GB: pointer to an user builtin font table. */
MWCOREFONT *user_builtin_fonts = NULL;

/*  Sets the fontproc to fontprocs.  */
void
gen_setfontproc(MWCOREFONT *pf)
{
        pf->fontprocs = &fontprocs;
}

/*
 * Generalized low level get font info routine.  This
 * routine works with fixed and proportional fonts.
 */
MWBOOL
gen_getfontinfo(PMWFONT pfont, PMWFONTINFO pfontinfo)
{
        PMWCFONT        pf = ((PMWCOREFONT)pfont)->cfont;
        int             i;

        pfontinfo->maxwidth = pf->maxwidth;
        pfontinfo->height = pf->height;
        pfontinfo->baseline = pf->ascent;
        pfontinfo->firstchar = pf->firstchar;
        pfontinfo->lastchar = pf->firstchar + pf->size - 1;
        pfontinfo->fixed = pf->width == NULL? TRUE: FALSE;
        for(i=0; i<256; ++i) {
                if(pf->width == NULL)
                        pfontinfo->widths[i] = pf->maxwidth;
                else {
                        if(i<pf->firstchar || i >= pf->firstchar+pf->size)
                                pfontinfo->widths[i] = 0;
                        else pfontinfo->widths[i] = pf->width[i-pf->firstchar];
                }
        }
        return TRUE;
}

/*
 * Generalized low level routine to calc bounding box for text output.
 * Handles both fixed and proportional fonts.  Passed ascii string.
 */
void
gen_gettextsize(PMWFONT pfont, const void *text, int cc, MWTEXTFLAGS flags,
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
        PMWCFONT                pf = ((PMWCOREFONT)pfont)->cfont;
        const unsigned char *   str = text;
        unsigned int            c;
        int                     width;

        if(pf->width == NULL)
                width = cc * pf->maxwidth;
        else {
                width = 0;
                while(--cc >= 0) {
                        c = *str++;
                        if(c >= pf->firstchar && c < pf->firstchar+pf->size)
                                width += pf->width[c - pf->firstchar];
                }
        }
        *pwidth = width;
        *pheight = pf->height;
        *pbase = pf->ascent;
}

#if HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT
/*
 * Routine to calc bounding box for text output.
 * Handles both fixed and proportional fonts.  Passed MWTF_UC16 string.
 */
void
gen16_gettextsize(PMWFONT pfont, const void *text, int cc, MWTEXTFLAGS flags,
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
        PMWCFONT                pf = ((PMWCOREFONT) pfont)->cfont;
        const unsigned short *  str = text;
        unsigned                int c;
        int                     width;

        if (pf->width == NULL)
                width = cc * pf->maxwidth;
        else {
                width = 0;
                while (--cc >= 0) {
                        c = *str++;
                        if (c >= pf->firstchar && c < pf->firstchar + pf->size)
                                width += pf->width[c - pf->firstchar];
                }
        }
        *pwidth = width;
        *pheight = pf->height;
        *pbase = pf->ascent;
}
#endif /* HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT*/

/*
 * Generalized low level routine to get the bitmap associated
 * with a character.  Handles fixed and proportional fonts.
 */
void
gen_gettextbits(PMWFONT pfont, int ch, const MWIMAGEBITS **retmap,
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
{
        PMWCFONT                pf = ((PMWCOREFONT)pfont)->cfont;
        int                     count, width;
        const MWIMAGEBITS *     bits;

        /* if char not in font, map to first character by default*/
        if(ch < pf->firstchar || ch >= pf->firstchar+pf->size)
                ch = pf->firstchar;

        ch -= pf->firstchar;

        /* get font bitmap depending on fixed pitch or not*/
        /* GB: automatically detect if offset is 16 or 32 bit */
        if( pf->offset ) {
                if( ((unsigned long*)pf->offset)[0] >= 0x00010000 )
                        bits = pf->bits + ((unsigned short*)pf->offset)[ch];
                else
                        bits = pf->bits + ((unsigned long*)pf->offset)[ch];
        } else
                bits = pf->bits + (pf->height * ch);
                
        width = pf->width ? pf->width[ch] : pf->maxwidth;
        count = MWIMAGE_WORDS(width) * pf->height; 

        *retmap = bits;

        /* return width depending on fixed pitch or not*/
        *pwidth = width; 
        *pheight = pf->height;
        *pbase = pf->ascent; 
}

void
gen_unloadfont(PMWFONT pfont)
{
        /* builtins can't be unloaded*/
}

#if NOTUSED
/* 
 * Generalized low level text draw routine, called only
 * if no clipping is required
 */
void
gen_drawtext(PMWFONT pfont,PSD psd,MWCOORD x,MWCOORD y,const void *text,
        int n,MWPIXELVAL fg)
{
        PMWCFONT                pf = ((PMWCOREFONT)pfont)->cfont;
        const unsigned char *   str = text;
        MWCOORD                 width;          /* width of character */
        MWCOORD                 height;         /* height of character */
        const MWIMAGEBITS *     bitmap;

        /* x, y is bottom left corner*/
        y -= pf->height - 1;
        while (n-- > 0) {
                pfont->GetTextBits(pfont, *s++, &bitmap, &width, &height);
                gen_drawbitmap(psd, x, y, width, height, bitmap, fg);
                x += width;
        }
}

/*
 * Generalized low level bitmap output routine, called
 * only if no clipping is required.  Only the set bits
 * in the bitmap are drawn, in the foreground color.
 */
void
gen_drawbitmap(PSD psd,MWCOORD x, MWCOORD y, MWCOORD width, MWCOORD height,
        MWIMAGEBITS *table, PIXELVAL fgcolor)
{
  MWCOORD minx;
  MWCOORD maxx;
  MWIMAGEBITS bitvalue; /* bitmap word value */
  int bitcount;         /* number of bits left in bitmap word */

  minx = x;
  maxx = x + width - 1;
  bitcount = 0;
  while (height > 0) {
        if (bitcount <= 0) {
                bitcount = MWIMAGE_BITSPERIMAGE;
                bitvalue = *table++;
        }
        if (MWIMAGE_TESTBIT(bitvalue))
                psd->DrawPixel(psd, x, y, fgcolor);
        bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
        --bitcount;
        if (x++ == maxx) {
                x = minx;
                ++y;
                --height;
                bitcount = 0;
        }
  }
}
#endif /* NOTUSED*/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to