Changeset 963

Show
Ignore:
Timestamp:
06/28/08 05:33:23 (5 months ago)
Author:
takkaria
Message:

Revert r959, because of the problem reported at http://angband.oook.cz/forum/showthread.php?t=837.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main-win.c

    r959 r963  
    14121412} 
    14131413 
    1414 /** 
    1415  * Recover term with target font if possible 
    1416  */ 
    1417 static errr term_find_font_in_use(const char *new_font_file) 
    1418 
    1419         if (new_font_file) 
    1420         { 
    1421                 int i; 
     1414 
     1415/* 
     1416 * Force the use of a new "font file" for a term_data 
     1417 * 
     1418 * This function may be called before the "window" is ready 
     1419 * 
     1420 * This function returns zero only if everything succeeds. 
     1421 * 
     1422 * Note that the "font name" must be capitalized!!! 
     1423 */ 
     1424static errr term_force_font(term_data *td, cptr path) 
     1425
     1426        int i; 
     1427 
     1428        int wid, hgt; 
     1429 
     1430        char *base; 
     1431 
     1432        char buf[1024]; 
     1433 
     1434 
     1435        /* Check we have a path */ 
     1436        if (!path) return (1); 
     1437 
     1438 
     1439        /* Forget the old font (if needed) */ 
     1440        if (td->font_id) DeleteObject(td->font_id); 
     1441 
     1442        /* Forget old font */ 
     1443        if (td->font_file) 
     1444        { 
     1445                bool used = FALSE; 
    14221446 
    14231447                /* Scan windows */ 
     
    14251449                { 
    14261450                        /* Check "screen" */ 
    1427                         if ((data[i].font_file) && 
    1428                         (streq(data[i].font_file, new_font_file))) 
    1429                                 return i; 
    1430                 } 
    1431         } 
    1432         return -1; 
    1433 
    1434  
    1435 /** 
    1436  * Coordinate forgetting all relevant font information. 
    1437  */ 
    1438 static void term_forget_font(term_data *td) 
    1439 
    1440         /* Forget old font */ 
    1441         if (td->font_file) 
    1442         { 
    1443                 char* tmp_font_file = td->font_file;    /* back up font name */ 
    1444                 td->font_file = NULL;                                           /* forget it */ 
    1445  
    1446                 { 
    1447                 errr term_using = term_find_font_in_use(tmp_font_file); 
    1448  
    1449                 if (-1 == term_using) 
    1450                 { 
    1451                         /* forget the old font if needed */ 
    1452                         if (td->font_id) DeleteObject(td->font_id); 
    1453  
    1454                         /* Remove unused font resources */ 
    1455                         term_remove_font(tmp_font_file); 
    1456                 } 
     1451                        if ((td != &data[i]) && 
     1452                            (data[i].font_file) && 
     1453                            (streq(data[i].font_file, td->font_file))) 
     1454                        { 
     1455                                used = TRUE; 
     1456                        } 
     1457                } 
     1458 
     1459                /* Remove unused font resources */ 
     1460                if (!used) term_remove_font(td->font_file); 
    14571461 
    14581462                /* Free the old name */ 
    1459                 string_free(tmp_font_file); 
    1460  
    1461                 /* going out of scope, so commented out */ 
    1462                 /* tmp_font_file = NULL */ 
    1463                 } 
    1464         } 
    1465  
    1466         td->font_id = 0; 
    1467 
    1468  
    1469 /** 
    1470  * Force the use of a new "font file" for a term_data 
    1471  * 
    1472  * This function may be called before the "window" is ready 
    1473  * 
    1474  * This function returns zero only if everything succeeds. 
    1475  * 
    1476  * Note that the "font name" must be capitalized!!! 
    1477  */ 
    1478 static errr term_force_font(term_data *td, cptr path) 
    1479 
    1480         int wid, hgt; 
    1481         errr term_using; 
    1482         HFONT tmp_font_id; 
    1483         char *base; 
    1484         char buf[1024]; 
    1485  
    1486         /* Check we have a path */ 
    1487         if (!path) return (1); 
     1463                string_free(td->font_file); 
     1464 
     1465                /* Forget it */ 
     1466                td->font_file = NULL; 
     1467        } 
     1468 
     1469 
    14881470 
    14891471        /* Local copy */ 
     
    14941476 
    14951477        /* Verify suffix */ 
    1496         if (!suffix(base, ".FON")) return 1
     1478        if (!suffix(base, ".FON")) return (1)
    14971479 
    14981480        /* Verify file */ 
    1499         if (!file_exists(buf)) return 1; 
    1500  
    1501         /* see if we're already using this font */ 
    1502         if (td->font_file && streq(td->font_file, base)) return 0;      /* same font as before */ 
    1503         term_using = term_find_font_in_use(base); 
    1504         if (-1 != term_using) 
    1505         {       /* some other term is using this font already */ 
    1506                 /* Free the old name */ 
    1507                 string_free(td->font_file); 
    1508  
    1509                 /* Save new font name */ 
    1510                 td->font_file = string_make(base); 
    1511  
    1512                 /* recover font information from the other terminal */ 
    1513                 td->font_id = data[term_using].font_id;         /* font id */ 
    1514                 td->font_wid = data[term_using].font_wid;       /* size */ 
    1515                 td->font_hgt = data[term_using].font_hgt; 
    1516  
    1517                 return 0;       /* success */ 
    1518         }        
     1481        if (!file_exists(buf)) return (1); 
    15191482 
    15201483        /* Load the new font */ 
     
    15311494 
    15321495        /* Create the font (using the 'base' of the font file name!) */ 
    1533         tmp_font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0, 
     1496        td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0, 
    15341497                                 ANSI_CHARSET, OUT_DEFAULT_PRECIS, 
    15351498                                 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
    15361499                                 FIXED_PITCH | FF_DONTCARE, base); 
    1537  
    1538         /* Restore the "suffix" */ 
    1539         base[strlen(base)] = '.';        
    1540  
    1541         if (!tmp_font_id) 
    1542         {       /* oops, CreateFont failed */ 
    1543                 RemoveFontResource(buf); 
    1544                 return 1;        
    1545         } 
    1546  
    1547         /* Forget font information */ 
    1548         term_forget_font(td); 
    1549  
    1550         td->font_id = tmp_font_id; 
    1551  
    1552         /* Save new font name */ 
    1553         td->font_file = string_make(base); 
    15541500 
    15551501        /* Hack -- Unknown size */ 
     
    45404486        { 
    45414487                /* Remove all fonts from the system, free resources */ 
    4542                 term_forget_font(data+i); 
     4488                if (data[i].font_file) term_remove_font(data[i].font_file); 
     4489                if (data[i].font_id) DeleteObject(data[i].font_id); 
    45434490                if (data[i].font_want) string_free(data[i].font_want); 
    45444491