| 1413 | | |
|---|
| 1414 | | /* |
|---|
| | 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; |
|---|
| | 1422 | |
|---|
| | 1423 | /* Scan windows */ |
|---|
| | 1424 | for (i = 0; i < MAX_TERM_DATA; i++) |
|---|
| | 1425 | { |
|---|
| | 1426 | /* 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 | } |
|---|
| | 1457 | |
|---|
| | 1458 | /* 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 | /** |
|---|
| 1437 | | |
|---|
| 1438 | | /* Forget the old font (if needed) */ |
|---|
| 1439 | | if (td->font_id) DeleteObject(td->font_id); |
|---|
| 1440 | | |
|---|
| 1441 | | /* Forget old font */ |
|---|
| 1442 | | if (td->font_file) |
|---|
| 1443 | | { |
|---|
| 1444 | | bool used = FALSE; |
|---|
| 1445 | | |
|---|
| 1446 | | /* Scan windows */ |
|---|
| 1447 | | for (i = 0; i < MAX_TERM_DATA; i++) |
|---|
| 1448 | | { |
|---|
| 1449 | | /* Check "screen" */ |
|---|
| 1450 | | if ((td != &data[i]) && |
|---|
| 1451 | | (data[i].font_file) && |
|---|
| 1452 | | (streq(data[i].font_file, td->font_file))) |
|---|
| 1453 | | { |
|---|
| 1454 | | used = TRUE; |
|---|
| 1455 | | } |
|---|
| 1456 | | } |
|---|
| 1457 | | |
|---|
| 1458 | | /* Remove unused font resources */ |
|---|
| 1459 | | if (!used) term_remove_font(td->font_file); |
|---|
| 1460 | | |
|---|
| | 1489 | /* Local copy */ |
|---|
| | 1490 | my_strcpy(buf, path, sizeof(buf)); |
|---|
| | 1491 | |
|---|
| | 1492 | /* Analyze font path */ |
|---|
| | 1493 | base = analyze_font(buf, &wid, &hgt); |
|---|
| | 1494 | |
|---|
| | 1495 | /* Verify suffix */ |
|---|
| | 1496 | if (!suffix(base, ".FON")) return 1; |
|---|
| | 1497 | |
|---|
| | 1498 | /* 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 */ |
|---|
| 1464 | | /* Forget it */ |
|---|
| 1465 | | td->font_file = NULL; |
|---|
| 1466 | | } |
|---|
| 1467 | | |
|---|
| 1468 | | |
|---|
| 1469 | | |
|---|
| 1470 | | /* Local copy */ |
|---|
| 1471 | | my_strcpy(buf, path, sizeof(buf)); |
|---|
| 1472 | | |
|---|
| 1473 | | /* Analyze font path */ |
|---|
| 1474 | | base = analyze_font(buf, &wid, &hgt); |
|---|
| 1475 | | |
|---|
| 1476 | | /* Verify suffix */ |
|---|
| 1477 | | if (!suffix(base, ".FON")) return (1); |
|---|
| 1478 | | |
|---|
| 1479 | | /* Verify file */ |
|---|
| 1480 | | if (!file_exists(buf)) return (1); |
|---|
| | 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 | } |
|---|
| 1495 | | td->font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0, |
|---|
| | 1533 | tmp_font_id = CreateFont(hgt, wid, 0, 0, FW_DONTCARE, 0, 0, 0, |
|---|