| 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 | */ |
|---|
| | 1424 | static 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; |
|---|
| 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); |
|---|
| 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 | |
|---|
| 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); |
|---|
| 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, |
|---|