XFree86/src/xfstt/xfstt.cpp
//### listXLFD is an ugly hack and needs a major cleanup
listXLFD is an ugly hack and needs a major cleanup
listXLFD is an ugly hack and needs a major cleanup
static int listXLFDFonts( char* pattern0, int index, char* buf)
{
        static TTFNdata* ttfn = 0;
        static int mapIndex = 0;
        if( index == 0) {
                ttfn = (TTFNdata*)(infoBase + sizeof( TTFNheader));
                mapIndex = 0;
        } else if( mapIndex == 0 && (char*)++ttfn >= infoBase + infoSize)
                return -1;
        char* pattern = pattern0;
        char* xlfdName = nameBase + ttfn->nameOfs;
        xlfdName += ttfn->nameLen + ttfn->pathLen + 2;
        char proportion = (ttfn->bProportion == 9) ? 'm' : 'p';
        char* buf0 = buf++;
        if( pattern[0] == '*'
        || (pattern[0] == '-' && pattern[1] == '*' && pattern[2] == 0)) { 
                char xlfdExt[] = "0-0-0-0-p-0-iso8859-1";
                xlfdExt[8] = proportion;
                strcpy( buf, xlfdName);
                strcpy( buf + ttfn->xlfdLen, xlfdExt);
                strcpy( buf + ttfn->xlfdLen + 12, encodings[mapIndex]->strName);
                if( !encodings[++mapIndex]) mapIndex = 0;
                *buf0 = strlen( buf);
                return *buf0 + 1;
        }
        int delim = 0;
        for(;;) {
                if( *pattern == '-')
                        if( ++delim >= 7)
                                break;
                if( tolower( *pattern) == *xlfdName)
                        *(buf++) = *(pattern++), ++xlfdName;
                else if( *(pattern++) == '*')
                        while( *xlfdName && *xlfdName != '-')
                                *(buf++) = *(xlfdName++);
                else return 0;
        }
        *(buf++) = '-';
        for(; delim <= 14 && *pattern; ++pattern) {
                char c = pattern[1];
                if( *pattern == '-')
                        if( ++delim == 12 && c == '*')
                                c = proportion;
                *(buf++) = (c=='*') ? '0' : c;
        }
        *buf = 0;
        if( !strcmp( buf-4, "-0-0")) {
                strcpy( buf-3, encodings[ mapIndex]->strName);
                buf += encodings[ mapIndex]->lenName - 3;
                if( !encodings[ ++mapIndex]) mapIndex = 0;
        } else
                mapIndex = 0;
        dprintf1( "match\t\"%s\"\n", buf0+1);
        *buf0 = buf - buf0;
        return *buf0 + 1;
}
static int listXLFDFonts ( char * pattern0 , int index , char * buf ) { static TTFNdata * ttfn = 0 ; static int mapIndex = 0 ; if ( index == 0 ) { ttfn = ( TTFNdata * ) ( infoBase + sizeof ( TTFNheader ) ) ; mapIndex = 0 ; } else if ( mapIndex == 0 && ( char * ) ++ ttfn >= infoBase + infoSize ) return -1 ; char * pattern = pattern0 ; char * xlfdName = nameBase + ttfn -> nameOfs ; xlfdName += ttfn -> nameLen + ttfn -> pathLen + 2 ; char proportion = ( ttfn -> bProportion == 9 ) ? ' ' : ' ' ; char * buf0 = buf ++ ; if ( pattern [ 0 ] == ' ' || ( pattern [ 0 ] == ' ' && pattern [ 1 ] == ' ' && pattern [ 2 ] == 0 ) ) { char xlfdExt [ ] = " " ; xlfdExt [ 8 ] = proportion ; strcpy ( buf , xlfdName ) ; strcpy ( buf + ttfn -> xlfdLen , xlfdExt ) ; strcpy ( buf + ttfn -> xlfdLen + 12 , encodings [ mapIndex ] -> strName ) ; if ( ! encodings [ ++ mapIndex ] ) mapIndex = 0 ; * buf0 = strlen ( buf ) ; return * buf0 + 1 ; } int delim = 0 ; for ( ; ; ) { if ( * pattern == ' ' ) if ( ++ delim >= 7 ) break ; if ( tolower ( * pattern ) == * xlfdName ) * ( buf ++ ) = * ( pattern ++ ) , ++ xlfdName ; else if ( * ( pattern ++ ) == ' ' ) while ( * xlfdName && * xlfdName != ' ' ) * ( buf ++ ) = * ( xlfdName ++ ) ; else return 0 ; } * ( buf ++ ) = ' ' ; for ( ; delim <= 14 && * pattern ; ++ pattern ) { char c = pattern [ 1 ] ; if ( * pattern == ' ' ) if ( ++ delim == 12 && c == ' ' ) c = proportion ; * ( buf ++ ) = ( c == ' ' ) ? ' ' : c ; } * buf = 0 ; if ( ! strcmp ( buf - 4 , " " ) ) { strcpy ( buf - 3 , encodings [ mapIndex ] -> strName ) ; buf += encodings [ mapIndex ] -> lenName - 3 ; if ( ! encodings [ ++ mapIndex ] ) mapIndex = 0 ; } else mapIndex = 0 ; dprintf1 ( " \t \" \" \n " , buf0 + 1 ) ; * buf0 = buf - buf0 ; return * buf0 + 1 ; }
listXLFD is an ugly hack and needs a major cleanup
listXLFD is an ugly hack and needs a major cleanup
//CK // this hack satisfies Mozilla, thanks Andrew Turner