1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018
|
/** @file
Implementation for EFI_HII_FONT_PROTOCOL.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "HiiDatabase.h"
EFI_GRAPHICS_OUTPUT_BLT_PIXEL mHiiEfiColors[16] = {
//
// B G R
//
{ 0x00, 0x00, 0x00, 0x00 }, // BLACK
{ 0x98, 0x00, 0x00, 0x00 }, // BLUE
{ 0x00, 0x98, 0x00, 0x00 }, // GREEN
{ 0x98, 0x98, 0x00, 0x00 }, // CYAN
{ 0x00, 0x00, 0x98, 0x00 }, // RED
{ 0x98, 0x00, 0x98, 0x00 }, // MAGENTA
{ 0x00, 0x98, 0x98, 0x00 }, // BROWN
{ 0x98, 0x98, 0x98, 0x00 }, // LIGHTGRAY
{ 0x30, 0x30, 0x30, 0x00 }, // DARKGRAY - BRIGHT BLACK
{ 0xff, 0x00, 0x00, 0x00 }, // LIGHTBLUE
{ 0x00, 0xff, 0x00, 0x00 }, // LIGHTGREEN
{ 0xff, 0xff, 0x00, 0x00 }, // LIGHTCYAN
{ 0x00, 0x00, 0xff, 0x00 }, // LIGHTRED
{ 0xff, 0x00, 0xff, 0x00 }, // LIGHTMAGENTA
{ 0x00, 0xff, 0xff, 0x00 }, // YELLOW
{ 0xff, 0xff, 0xff, 0x00 }, // WHITE
};
/**
Insert a character cell information to the list specified by GlyphInfoList.
This is a internal function.
@param CharValue Unicode character value, which identifies a glyph
block.
@param GlyphInfoList HII_GLYPH_INFO list head.
@param Cell Incoming character cell information.
@retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
@retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
task.
**/
EFI_STATUS
NewCell (
IN CHAR16 CharValue,
IN LIST_ENTRY *GlyphInfoList,
IN EFI_HII_GLYPH_INFO *Cell
)
{
HII_GLYPH_INFO *GlyphInfo;
ASSERT (Cell != NULL && GlyphInfoList != NULL);
GlyphInfo = (HII_GLYPH_INFO *)AllocateZeroPool (sizeof (HII_GLYPH_INFO));
if (GlyphInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// GlyphInfoList stores a list of default character cell information, each is
// identified by "CharId".
//
GlyphInfo->Signature = HII_GLYPH_INFO_SIGNATURE;
GlyphInfo->CharId = CharValue;
if (Cell->AdvanceX == 0) {
Cell->AdvanceX = Cell->Width;
}
CopyMem (&GlyphInfo->Cell, Cell, sizeof (EFI_HII_GLYPH_INFO));
InsertTailList (GlyphInfoList, &GlyphInfo->Entry);
return EFI_SUCCESS;
}
/**
Get a character cell information from the list specified by GlyphInfoList.
This is a internal function.
@param CharValue Unicode character value, which identifies a glyph
block.
@param GlyphInfoList HII_GLYPH_INFO list head.
@param Cell Buffer which stores output character cell
information.
@retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
@retval EFI_NOT_FOUND The character info specified by CharValue does
not exist.
**/
EFI_STATUS
GetCell (
IN CHAR16 CharValue,
IN LIST_ENTRY *GlyphInfoList,
OUT EFI_HII_GLYPH_INFO *Cell
)
{
HII_GLYPH_INFO *GlyphInfo;
LIST_ENTRY *Link;
ASSERT (Cell != NULL && GlyphInfoList != NULL);
//
// Since the EFI_HII_GIBT_DEFAULTS block won't increment CharValueCurrent,
// the value of "CharId" of a default character cell which is used for a
// EFI_HII_GIBT_GLYPH_DEFAULT or EFI_HII_GIBT_GLYPHS_DEFAULT should be
// less or equal to the value of "CharValueCurrent" of this default block.
//
// For instance, if the CharId of a GlyphInfoList is {1, 3, 7}, a default glyph
// with CharValue equals "7" uses the GlyphInfo with CharId = 7;
// a default glyph with CharValue equals "6" uses the GlyphInfo with CharId = 3.
//
for (Link = GlyphInfoList->BackLink; Link != GlyphInfoList; Link = Link->BackLink) {
GlyphInfo = CR (Link, HII_GLYPH_INFO, Entry, HII_GLYPH_INFO_SIGNATURE);
if (GlyphInfo->CharId <= CharValue) {
CopyMem (Cell, &GlyphInfo->Cell, sizeof (EFI_HII_GLYPH_INFO));
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Convert the glyph for a single character into a bitmap.
This is a internal function.
@param Private HII database driver private data.
@param Char Character to retrieve.
@param StringInfo Points to the string font and color information
or NULL if the string should use the default
system font and color.
@param GlyphBuffer Buffer to store the retrieved bitmap data.
@param Cell Points to EFI_HII_GLYPH_INFO structure.
@param Attributes If not NULL, output the glyph attributes if any.
@retval EFI_SUCCESS Glyph bitmap outputted.
@retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer GlyphBuffer.
@retval EFI_NOT_FOUND The glyph was unknown can not be found.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
GetGlyphBuffer (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN CHAR16 Char,
IN EFI_FONT_INFO *StringInfo,
OUT UINT8 **GlyphBuffer,
OUT EFI_HII_GLYPH_INFO *Cell,
OUT UINT8 *Attributes OPTIONAL
)
{
HII_DATABASE_RECORD *Node;
LIST_ENTRY *Link;
HII_SIMPLE_FONT_PACKAGE_INSTANCE *SimpleFont;
LIST_ENTRY *Link1;
UINT16 Index;
EFI_NARROW_GLYPH Narrow;
EFI_WIDE_GLYPH Wide;
HII_GLOBAL_FONT_INFO *GlobalFont;
UINTN HeaderSize;
EFI_NARROW_GLYPH *NarrowPtr;
EFI_WIDE_GLYPH *WidePtr;
if ((GlyphBuffer == NULL) || (Cell == NULL)) {
return EFI_INVALID_PARAMETER;
}
if ((Private == NULL) || (Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE)) {
return EFI_INVALID_PARAMETER;
}
ZeroMem (Cell, sizeof (EFI_HII_GLYPH_INFO));
//
// If StringInfo is not NULL, it must point to an existing EFI_FONT_INFO rather
// than system default font and color.
// If NULL, try to find the character in simplified font packages since
// default system font is the fixed font (narrow or wide glyph).
//
if (StringInfo != NULL) {
if (!IsFontInfoExisted (Private, StringInfo, NULL, NULL, &GlobalFont)) {
return EFI_INVALID_PARAMETER;
}
if (Attributes != NULL) {
*Attributes = PROPORTIONAL_GLYPH;
}
return FindGlyphBlock (GlobalFont->FontPackage, Char, GlyphBuffer, Cell, NULL);
} else {
HeaderSize = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR);
for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {
Node = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);
for (Link1 = Node->PackageList->SimpleFontPkgHdr.ForwardLink;
Link1 != &Node->PackageList->SimpleFontPkgHdr;
Link1 = Link1->ForwardLink
)
{
SimpleFont = CR (Link1, HII_SIMPLE_FONT_PACKAGE_INSTANCE, SimpleFontEntry, HII_S_FONT_PACKAGE_SIGNATURE);
//
// Search the narrow glyph array
//
NarrowPtr = (EFI_NARROW_GLYPH *)((UINT8 *)(SimpleFont->SimpleFontPkgHdr) + HeaderSize);
for (Index = 0; Index < SimpleFont->SimpleFontPkgHdr->NumberOfNarrowGlyphs; Index++) {
CopyMem (&Narrow, NarrowPtr + Index, sizeof (EFI_NARROW_GLYPH));
if (Narrow.UnicodeWeight == Char) {
*GlyphBuffer = (UINT8 *)AllocateZeroPool (EFI_GLYPH_HEIGHT);
if (*GlyphBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Cell->Width = EFI_GLYPH_WIDTH;
Cell->Height = EFI_GLYPH_HEIGHT;
Cell->AdvanceX = Cell->Width;
CopyMem (*GlyphBuffer, Narrow.GlyphCol1, Cell->Height);
if (Attributes != NULL) {
*Attributes = (UINT8)(Narrow.Attributes | NARROW_GLYPH);
}
return EFI_SUCCESS;
}
}
//
// Search the wide glyph array
//
WidePtr = (EFI_WIDE_GLYPH *)(NarrowPtr + SimpleFont->SimpleFontPkgHdr->NumberOfNarrowGlyphs);
for (Index = 0; Index < SimpleFont->SimpleFontPkgHdr->NumberOfWideGlyphs; Index++) {
CopyMem (&Wide, WidePtr + Index, sizeof (EFI_WIDE_GLYPH));
if (Wide.UnicodeWeight == Char) {
*GlyphBuffer = (UINT8 *)AllocateZeroPool (EFI_GLYPH_HEIGHT * 2);
if (*GlyphBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Cell->Width = EFI_GLYPH_WIDTH * 2;
Cell->Height = EFI_GLYPH_HEIGHT;
Cell->AdvanceX = Cell->Width;
CopyMem (*GlyphBuffer, Wide.GlyphCol1, EFI_GLYPH_HEIGHT);
CopyMem (*GlyphBuffer + EFI_GLYPH_HEIGHT, Wide.GlyphCol2, EFI_GLYPH_HEIGHT);
if (Attributes != NULL) {
*Attributes = (UINT8)(Wide.Attributes | EFI_GLYPH_WIDE);
}
return EFI_SUCCESS;
}
}
}
}
}
return EFI_NOT_FOUND;
}
/**
Convert bitmap data of the glyph to blt structure.
This is a internal function.
@param GlyphBuffer Buffer points to bitmap data of glyph.
@param Foreground The color of the "on" pixels in the glyph in the
bitmap.
@param Background The color of the "off" pixels in the glyph in the
bitmap.
@param ImageWidth Width of the whole image in pixels.
@param RowWidth The width of the text on the line, in pixels.
@param RowHeight The height of the line, in pixels.
@param Transparent If TRUE, the Background color is ignored and all
"off" pixels in the character's drawn will use the
pixel value from BltBuffer.
@param Origin On input, points to the origin of the to be
displayed character, on output, points to the
next glyph's origin.
**/
VOID
NarrowGlyphToBlt (
IN UINT8 *GlyphBuffer,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
IN UINT16 ImageWidth,
IN UINTN RowWidth,
IN UINTN RowHeight,
IN BOOLEAN Transparent,
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
)
{
UINT8 Xpos;
UINT8 Ypos;
UINT8 Height;
UINT8 Width;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer;
ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);
Height = EFI_GLYPH_HEIGHT;
Width = EFI_GLYPH_WIDTH;
//
// Move position to the left-top corner of char.
//
Buffer = *Origin - EFI_GLYPH_HEIGHT * ImageWidth;
//
// Char may be partially displayed when CLIP_X or CLIP_Y is not set.
//
if (RowHeight < Height) {
Height = (UINT8)RowHeight;
}
if (RowWidth < Width) {
Width = (UINT8)RowWidth;
}
for (Ypos = 0; Ypos < Height; Ypos++) {
for (Xpos = 0; Xpos < Width; Xpos++) {
if ((GlyphBuffer[Ypos] & (1 << (EFI_GLYPH_WIDTH - Xpos - 1))) != 0) {
Buffer[Ypos * ImageWidth + Xpos] = Foreground;
} else {
if (!Transparent) {
Buffer[Ypos * ImageWidth + Xpos] = Background;
}
}
}
}
*Origin = *Origin + EFI_GLYPH_WIDTH;
}
/**
Convert bitmap data of the glyph to blt structure.
This is a internal function.
@param GlyphBuffer Buffer points to bitmap data of glyph.
@param Foreground The color of the "on" pixels in the glyph in the
bitmap.
@param Background The color of the "off" pixels in the glyph in the
bitmap.
@param ImageWidth Width of the whole image in pixels.
@param BaseLine BaseLine in the line.
@param RowWidth The width of the text on the line, in pixels.
@param RowHeight The height of the line, in pixels.
@param Transparent If TRUE, the Background color is ignored and all
"off" pixels in the character's drawn will use the
pixel value from BltBuffer.
@param Cell Points to EFI_HII_GLYPH_INFO structure.
@param Attributes The attribute of incoming glyph in GlyphBuffer.
@param Origin On input, points to the origin of the to be
displayed character, on output, points to the
next glyph's origin.
**/
VOID
GlyphToBlt (
IN UINT8 *GlyphBuffer,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
IN UINT16 ImageWidth,
IN UINT16 BaseLine,
IN UINTN RowWidth,
IN UINTN RowHeight,
IN BOOLEAN Transparent,
IN CONST EFI_HII_GLYPH_INFO *Cell,
IN UINT8 Attributes,
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
)
{
UINT16 Xpos;
UINT16 Ypos;
UINT8 Data;
UINT16 Index;
UINT16 YposOffset;
UINTN OffsetY;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL);
//
// Only adjust origin position if char has no bitmap.
//
if (GlyphBuffer == NULL) {
*Origin = *Origin + Cell->AdvanceX;
return;
}
//
// Move position to the left-top corner of char.
//
BltBuffer = *Origin + Cell->OffsetX - (Cell->OffsetY + Cell->Height) * ImageWidth;
YposOffset = (UINT16)(BaseLine - (Cell->OffsetY + Cell->Height));
//
// Since non-spacing key will be printed OR'd with the previous glyph, don't
// write 0.
//
if ((Attributes & EFI_GLYPH_NON_SPACING) == EFI_GLYPH_NON_SPACING) {
Transparent = TRUE;
}
//
// The glyph's upper left hand corner pixel is the most significant bit of the
// first bitmap byte.
//
for (Ypos = 0; Ypos < Cell->Height && (((UINT32)Ypos + YposOffset) < RowHeight); Ypos++) {
OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos);
//
// All bits in these bytes are meaningful.
//
for (Xpos = 0; Xpos < Cell->Width / 8; Xpos++) {
Data = *(GlyphBuffer + OffsetY + Xpos);
for (Index = 0; Index < 8 && (((UINT32)Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
if ((Data & (1 << (8 - Index - 1))) != 0) {
BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
} else {
if (!Transparent) {
BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background;
}
}
}
}
if (Cell->Width % 8 != 0) {
//
// There are some padding bits in this byte. Ignore them.
//
Data = *(GlyphBuffer + OffsetY + Xpos);
for (Index = 0; Index < Cell->Width % 8 && (((UINT32)Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
if ((Data & (1 << (8 - Index - 1))) != 0) {
BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
} else {
if (!Transparent) {
BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background;
}
}
}
} // end of if (Width % 8...)
} // end of for (Ypos=0...)
*Origin = *Origin + Cell->AdvanceX;
}
/**
Convert bitmap data of the glyph to blt structure.
This is a internal function.
@param GlyphBuffer Buffer points to bitmap data of glyph.
@param Foreground The color of the "on" pixels in the glyph in the
bitmap.
@param Background The color of the "off" pixels in the glyph in the
bitmap.
@param ImageWidth Width of the whole image in pixels.
@param BaseLine BaseLine in the line.
@param RowWidth The width of the text on the line, in pixels.
@param RowHeight The height of the line, in pixels.
@param Transparent If TRUE, the Background color is ignored and all
"off" pixels in the character's drawn will use the
pixel value from BltBuffer.
@param Cell Points to EFI_HII_GLYPH_INFO structure.
@param Attributes The attribute of incoming glyph in GlyphBuffer.
@param Origin On input, points to the origin of the to be
displayed character, on output, points to the
next glyph's origin.
@return Points to the address of next origin node in BltBuffer.
**/
VOID
GlyphToImage (
IN UINT8 *GlyphBuffer,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
IN UINT16 ImageWidth,
IN UINT16 BaseLine,
IN UINTN RowWidth,
IN UINTN RowHeight,
IN BOOLEAN Transparent,
IN CONST EFI_HII_GLYPH_INFO *Cell,
IN UINT8 Attributes,
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
)
{
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer;
ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL);
Buffer = *Origin;
if ((Attributes & EFI_GLYPH_NON_SPACING) == EFI_GLYPH_NON_SPACING) {
//
// This character is a non-spacing key, print it OR'd with the previous glyph.
// without advancing cursor.
//
Buffer -= Cell->AdvanceX;
GlyphToBlt (
GlyphBuffer,
Foreground,
Background,
ImageWidth,
BaseLine,
RowWidth,
RowHeight,
Transparent,
Cell,
Attributes,
&Buffer
);
} else if ((Attributes & EFI_GLYPH_WIDE) == EFI_GLYPH_WIDE) {
//
// This character is wide glyph, i.e. 16 pixels * 19 pixels.
// Draw it as two narrow glyphs.
//
NarrowGlyphToBlt (
GlyphBuffer,
Foreground,
Background,
ImageWidth,
RowWidth,
RowHeight,
Transparent,
Origin
);
NarrowGlyphToBlt (
GlyphBuffer + EFI_GLYPH_HEIGHT,
Foreground,
Background,
ImageWidth,
RowWidth,
RowHeight,
Transparent,
Origin
);
} else if ((Attributes & NARROW_GLYPH) == NARROW_GLYPH) {
//
// This character is narrow glyph, i.e. 8 pixels * 19 pixels.
//
NarrowGlyphToBlt (
GlyphBuffer,
Foreground,
Background,
ImageWidth,
RowWidth,
RowHeight,
Transparent,
Origin
);
} else if ((Attributes & PROPORTIONAL_GLYPH) == PROPORTIONAL_GLYPH) {
//
// This character is proportional glyph, i.e. Cell->Width * Cell->Height pixels.
//
GlyphToBlt (
GlyphBuffer,
Foreground,
Background,
ImageWidth,
BaseLine,
RowWidth,
RowHeight,
Transparent,
Cell,
Attributes,
Origin
);
}
}
/**
Write the output parameters of FindGlyphBlock().
This is a internal function.
@param BufferIn Buffer which stores the bitmap data of the found
block.
@param BufferLen Length of BufferIn.
@param InputCell Buffer which stores cell information of the
encoded bitmap.
@param GlyphBuffer Output the corresponding bitmap data of the found
block. It is the caller's responsibility to free
this buffer.
@param Cell Output cell information of the encoded bitmap.
@param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
@retval EFI_SUCCESS The operation is performed successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
@retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
task.
**/
EFI_STATUS
WriteOutputParam (
IN UINT8 *BufferIn,
IN UINTN BufferLen,
IN EFI_HII_GLYPH_INFO *InputCell,
OUT UINT8 **GlyphBuffer OPTIONAL,
OUT EFI_HII_GLYPH_INFO *Cell OPTIONAL,
OUT UINTN *GlyphBufferLen OPTIONAL
)
{
if ((BufferIn == NULL) || (InputCell == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (Cell != NULL) {
CopyMem (Cell, InputCell, sizeof (EFI_HII_GLYPH_INFO));
}
if ((GlyphBuffer != NULL) && (BufferLen > 0)) {
*GlyphBuffer = (UINT8 *)AllocateZeroPool (BufferLen);
if (*GlyphBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyMem (*GlyphBuffer, BufferIn, BufferLen);
}
if (GlyphBufferLen != NULL) {
*GlyphBufferLen = BufferLen;
}
return EFI_SUCCESS;
}
/**
Parse all glyph blocks to find a glyph block specified by CharValue.
If CharValue = (CHAR16) (-1), collect all default character cell information
within this font package and backup its information.
@param FontPackage Hii string package instance.
@param CharValue Unicode character value, which identifies a glyph
block.
@param GlyphBuffer Output the corresponding bitmap data of the found
block. It is the caller's responsibility to free
this buffer.
@param Cell Output cell information of the encoded bitmap.
@param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
@retval EFI_SUCCESS The bitmap data is retrieved successfully.
@retval EFI_NOT_FOUND The specified CharValue does not exist in current
database.
@retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
task.
**/
EFI_STATUS
FindGlyphBlock (
IN HII_FONT_PACKAGE_INSTANCE *FontPackage,
IN CHAR16 CharValue,
OUT UINT8 **GlyphBuffer OPTIONAL,
OUT EFI_HII_GLYPH_INFO *Cell OPTIONAL,
OUT UINTN *GlyphBufferLen OPTIONAL
)
{
EFI_STATUS Status;
UINT8 *BlockPtr;
UINT16 CharCurrent;
UINT16 Length16;
UINT32 Length32;
EFI_HII_GIBT_GLYPHS_BLOCK Glyphs;
UINTN BufferLen;
UINT16 Index;
EFI_HII_GLYPH_INFO DefaultCell;
EFI_HII_GLYPH_INFO LocalCell;
INT16 MinOffsetY;
UINT16 BaseLine;
ASSERT (FontPackage != NULL);
ASSERT (FontPackage->Signature == HII_FONT_PACKAGE_SIGNATURE);
BaseLine = 0;
MinOffsetY = 0;
if (CharValue == (CHAR16)(-1)) {
//
// Collect the cell information specified in font package fixed header.
// Use CharValue =0 to represent this particular cell.
//
Status = NewCell (
0,
&FontPackage->GlyphInfoList,
(EFI_HII_GLYPH_INFO *)((UINT8 *)FontPackage->FontPkgHdr + 3 * sizeof (UINT32))
);
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (
&LocalCell,
(UINT8 *)FontPackage->FontPkgHdr + 3 * sizeof (UINT32),
sizeof (EFI_HII_GLYPH_INFO)
);
}
BlockPtr = FontPackage->GlyphBlock;
CharCurrent = 1;
BufferLen = 0;
while (*BlockPtr != EFI_HII_GIBT_END) {
switch (*BlockPtr) {
case EFI_HII_GIBT_DEFAULTS:
//
// Collect all default character cell information specified by
// EFI_HII_GIBT_DEFAULTS.
//
if (CharValue == (CHAR16)(-1)) {
Status = NewCell (
CharCurrent,
&FontPackage->GlyphInfoList,
(EFI_HII_GLYPH_INFO *)(BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK))
);
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (
&LocalCell,
BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
sizeof (EFI_HII_GLYPH_INFO)
);
if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {
BaseLine = (UINT16)(LocalCell.Height + LocalCell.OffsetY);
}
if (MinOffsetY > LocalCell.OffsetY) {
MinOffsetY = LocalCell.OffsetY;
}
}
BlockPtr += sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK);
break;
case EFI_HII_GIBT_DUPLICATE:
if (CharCurrent == CharValue) {
CopyMem (&CharValue, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (CHAR16));
CharCurrent = 1;
BlockPtr = FontPackage->GlyphBlock;
continue;
}
CharCurrent++;
BlockPtr += sizeof (EFI_HII_GIBT_DUPLICATE_BLOCK);
break;
case EFI_HII_GIBT_EXT1:
BlockPtr += *(UINT8 *)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8));
break;
case EFI_HII_GIBT_EXT2:
CopyMem (
&Length16,
(UINT8 *)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)),
sizeof (UINT16)
);
BlockPtr += Length16;
break;
case EFI_HII_GIBT_EXT4:
CopyMem (
&Length32,
(UINT8 *)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)),
sizeof (UINT32)
);
BlockPtr += Length32;
break;
case EFI_HII_GIBT_GLYPH:
CopyMem (
&LocalCell,
BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
sizeof (EFI_HII_GLYPH_INFO)
);
if (CharValue == (CHAR16)(-1)) {
if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {
BaseLine = (UINT16)(LocalCell.Height + LocalCell.OffsetY);
}
if (MinOffsetY > LocalCell.OffsetY) {
MinOffsetY = LocalCell.OffsetY;
}
}
BufferLen = BITMAP_LEN_1_BIT (LocalCell.Width, LocalCell.Height);
if (CharCurrent == CharValue) {
return WriteOutputParam (
(UINT8 *)((UINTN)BlockPtr + sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8)),
BufferLen,
&LocalCell,
GlyphBuffer,
Cell,
GlyphBufferLen
);
}
CharCurrent++;
BlockPtr += sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8) + BufferLen;
break;
case EFI_HII_GIBT_GLYPHS:
BlockPtr += sizeof (EFI_HII_GLYPH_BLOCK);
CopyMem (&Glyphs.Cell, BlockPtr, sizeof (EFI_HII_GLYPH_INFO));
BlockPtr += sizeof (EFI_HII_GLYPH_INFO);
CopyMem (&Glyphs.Count, BlockPtr, sizeof (UINT16));
BlockPtr += sizeof (UINT16);
if (CharValue == (CHAR16)(-1)) {
if (BaseLine < Glyphs.Cell.Height + Glyphs.Cell.OffsetY) {
BaseLine = (UINT16)(Glyphs.Cell.Height + Glyphs.Cell.OffsetY);
}
if (MinOffsetY > Glyphs.Cell.OffsetY) {
MinOffsetY = Glyphs.Cell.OffsetY;
}
}
BufferLen = BITMAP_LEN_1_BIT (Glyphs.Cell.Width, Glyphs.Cell.Height);
for (Index = 0; Index < Glyphs.Count; Index++) {
if (CharCurrent + Index == CharValue) {
return WriteOutputParam (
BlockPtr,
BufferLen,
&Glyphs.Cell,
GlyphBuffer,
Cell,
GlyphBufferLen
);
}
BlockPtr += BufferLen;
}
CharCurrent = (UINT16)(CharCurrent + Glyphs.Count);
break;
case EFI_HII_GIBT_GLYPH_DEFAULT:
Status = GetCell (CharCurrent, &FontPackage->GlyphInfoList, &DefaultCell);
if (EFI_ERROR (Status)) {
return Status;
}
if (CharValue == (CHAR16)(-1)) {
if (BaseLine < DefaultCell.Height + DefaultCell.OffsetY) {
BaseLine = (UINT16)(DefaultCell.Height + DefaultCell.OffsetY);
}
if (MinOffsetY > DefaultCell.OffsetY) {
MinOffsetY = DefaultCell.OffsetY;
}
}
BufferLen = BITMAP_LEN_1_BIT (DefaultCell.Width, DefaultCell.Height);
if (CharCurrent == CharValue) {
return WriteOutputParam (
BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
BufferLen,
&DefaultCell,
GlyphBuffer,
Cell,
GlyphBufferLen
);
}
CharCurrent++;
BlockPtr += sizeof (EFI_HII_GLYPH_BLOCK) + BufferLen;
break;
case EFI_HII_GIBT_GLYPHS_DEFAULT:
CopyMem (&Length16, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (UINT16));
Status = GetCell (CharCurrent, &FontPackage->GlyphInfoList, &DefaultCell);
if (EFI_ERROR (Status)) {
return Status;
}
if (CharValue == (CHAR16)(-1)) {
if (BaseLine < DefaultCell.Height + DefaultCell.OffsetY) {
BaseLine = (UINT16)(DefaultCell.Height + DefaultCell.OffsetY);
}
if (MinOffsetY > DefaultCell.OffsetY) {
MinOffsetY = DefaultCell.OffsetY;
}
}
BufferLen = BITMAP_LEN_1_BIT (DefaultCell.Width, DefaultCell.Height);
BlockPtr += sizeof (EFI_HII_GIBT_GLYPHS_DEFAULT_BLOCK) - sizeof (UINT8);
for (Index = 0; Index < Length16; Index++) {
if (CharCurrent + Index == CharValue) {
return WriteOutputParam (
BlockPtr,
BufferLen,
&DefaultCell,
GlyphBuffer,
Cell,
GlyphBufferLen
);
}
BlockPtr += BufferLen;
}
CharCurrent = (UINT16)(CharCurrent + Length16);
break;
case EFI_HII_GIBT_SKIP1:
CharCurrent = (UINT16)(CharCurrent + (UINT16)(*(BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK))));
BlockPtr += sizeof (EFI_HII_GIBT_SKIP1_BLOCK);
break;
case EFI_HII_GIBT_SKIP2:
CopyMem (&Length16, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (UINT16));
CharCurrent = (UINT16)(CharCurrent + Length16);
BlockPtr += sizeof (EFI_HII_GIBT_SKIP2_BLOCK);
break;
default:
ASSERT (FALSE);
break;
}
if (CharValue < CharCurrent) {
return EFI_NOT_FOUND;
}
}
if (CharValue == (CHAR16)(-1)) {
FontPackage->BaseLine = BaseLine;
FontPackage->Height = (UINT16)(BaseLine - MinOffsetY);
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
}
/**
Copy a Font Name to a new created EFI_FONT_INFO structure.
This is a internal function.
@param FontName NULL-terminated string.
@param FontInfo a new EFI_FONT_INFO which stores the FontName.
It's caller's responsibility to free this buffer.
@retval EFI_SUCCESS FontInfo is allocated and copied with FontName.
@retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
task.
**/
EFI_STATUS
SaveFontName (
IN EFI_STRING FontName,
OUT EFI_FONT_INFO **FontInfo
)
{
UINTN FontInfoLen;
UINTN NameSize;
ASSERT (FontName != NULL && FontInfo != NULL);
NameSize = StrSize (FontName);
FontInfoLen = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + NameSize;
*FontInfo = (EFI_FONT_INFO *)AllocateZeroPool (FontInfoLen);
if (*FontInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
}
StrCpyS ((*FontInfo)->FontName, NameSize / sizeof (CHAR16), FontName);
return EFI_SUCCESS;
}
/**
Retrieve system default font and color.
@param Private HII database driver private data.
@param FontInfo Points to system default font output-related
information. It's caller's responsibility to free
this buffer.
@param FontInfoSize If not NULL, output the size of buffer FontInfo.
@retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
@retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
task.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
GetSystemFont (
IN HII_DATABASE_PRIVATE_DATA *Private,
OUT EFI_FONT_DISPLAY_INFO **FontInfo,
OUT UINTN *FontInfoSize OPTIONAL
)
{
EFI_FONT_DISPLAY_INFO *Info;
UINTN InfoSize;
UINTN NameSize;
if ((Private == NULL) || (Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE)) {
return EFI_INVALID_PARAMETER;
}
if (FontInfo == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// The standard font always has the name "sysdefault".
//
NameSize = StrSize (L"sysdefault");
InfoSize = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize;
Info = (EFI_FONT_DISPLAY_INFO *)AllocateZeroPool (InfoSize);
if (Info == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Info->ForegroundColor = mHiiEfiColors[Private->Attribute & 0x0f];
ASSERT ((Private->Attribute >> 4) < 8);
Info->BackgroundColor = mHiiEfiColors[Private->Attribute >> 4];
Info->FontInfoMask = EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_SYS_STYLE;
Info->FontInfo.FontStyle = 0;
Info->FontInfo.FontSize = EFI_GLYPH_HEIGHT;
StrCpyS (Info->FontInfo.FontName, NameSize / sizeof (CHAR16), L"sysdefault");
*FontInfo = Info;
if (FontInfoSize != NULL) {
*FontInfoSize = InfoSize;
}
return EFI_SUCCESS;
}
/**
Check whether EFI_FONT_DISPLAY_INFO points to system default font and color or
returns the system default according to the optional inputs.
This is a internal function.
@param Private HII database driver private data.
@param StringInfo Points to the string output information,
including the color and font.
@param SystemInfo If not NULL, points to system default font and color.
@param SystemInfoLen If not NULL, output the length of default system
info.
@retval TRUE Yes, it points to system default.
@retval FALSE No.
**/
BOOLEAN
IsSystemFontInfo (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_FONT_DISPLAY_INFO *StringInfo,
OUT EFI_FONT_DISPLAY_INFO **SystemInfo OPTIONAL,
OUT UINTN *SystemInfoLen OPTIONAL
)
{
EFI_STATUS Status;
EFI_FONT_DISPLAY_INFO *SystemDefault;
UINTN DefaultLen;
BOOLEAN Flag;
ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
if ((StringInfo == NULL) && (SystemInfo == NULL)) {
return TRUE;
}
SystemDefault = NULL;
DefaultLen = 0;
Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);
ASSERT_EFI_ERROR (Status);
ASSERT ((SystemDefault != NULL) && (DefaultLen != 0));
//
// Record the system default info.
//
if (SystemInfo != NULL) {
*SystemInfo = SystemDefault;
}
if (SystemInfoLen != NULL) {
*SystemInfoLen = DefaultLen;
}
if (StringInfo == NULL) {
return TRUE;
}
Flag = FALSE;
//
// Check the FontInfoMask to see whether it is retrieving system info.
//
if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == 0) {
if (StrCmp (StringInfo->FontInfo.FontName, SystemDefault->FontInfo.FontName) != 0) {
goto Exit;
}
}
if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == 0) {
if (StringInfo->FontInfo.FontSize != SystemDefault->FontInfo.FontSize) {
goto Exit;
}
}
if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == 0) {
if (StringInfo->FontInfo.FontStyle != SystemDefault->FontInfo.FontStyle) {
goto Exit;
}
}
if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == 0) {
if (CompareMem (
&StringInfo->ForegroundColor,
&SystemDefault->ForegroundColor,
sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
) != 0)
{
goto Exit;
}
}
if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == 0) {
if (CompareMem (
&StringInfo->BackgroundColor,
&SystemDefault->BackgroundColor,
sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
) != 0)
{
goto Exit;
}
}
Flag = TRUE;
Exit:
if (SystemInfo == NULL) {
if (SystemDefault != NULL) {
FreePool (SystemDefault);
}
}
return Flag;
}
/**
This function checks whether EFI_FONT_INFO exists in current database. If
FontInfoMask is specified, check what options can be used to make a match.
Note that the masks relate to where the system default should be supplied
are ignored by this function.
@param Private Hii database private structure.
@param FontInfo Points to EFI_FONT_INFO structure.
@param FontInfoMask If not NULL, describes what options can be used
to make a match between the font requested and
the font available. The caller must guarantee
this mask is valid.
@param FontHandle On entry, Points to the font handle returned by a
previous call to GetFontInfo() or NULL to start
with the first font.
@param GlobalFontInfo If not NULL, output the corresponding global font
info.
@retval TRUE Existed
@retval FALSE Not existed
**/
BOOLEAN
IsFontInfoExisted (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_FONT_INFO *FontInfo,
IN EFI_FONT_INFO_MASK *FontInfoMask OPTIONAL,
IN EFI_FONT_HANDLE FontHandle OPTIONAL,
OUT HII_GLOBAL_FONT_INFO **GlobalFontInfo OPTIONAL
)
{
HII_GLOBAL_FONT_INFO *GlobalFont;
HII_GLOBAL_FONT_INFO *GlobalFontBackup1;
HII_GLOBAL_FONT_INFO *GlobalFontBackup2;
LIST_ENTRY *Link;
EFI_FONT_INFO_MASK Mask;
BOOLEAN Matched;
BOOLEAN VagueMatched1;
BOOLEAN VagueMatched2;
ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
ASSERT (FontInfo != NULL);
//
// Matched flag represents an exactly match; VagueMatched1 represents a RESIZE
// or RESTYLE match; VagueMatched2 represents a RESIZE | RESTYLE match.
//
Matched = FALSE;
VagueMatched1 = FALSE;
VagueMatched2 = FALSE;
Mask = 0;
GlobalFontBackup1 = NULL;
GlobalFontBackup2 = NULL;
// The process of where the system default should be supplied instead of
// the specified font info beyonds this function's scope.
//
if (FontInfoMask != NULL) {
Mask = *FontInfoMask & (~SYS_FONT_INFO_MASK);
}
//
// If not NULL, FontHandle points to the next node of the last searched font
// node by previous call.
//
if (FontHandle == NULL) {
Link = Private->FontInfoList.ForwardLink;
} else {
Link = (LIST_ENTRY *)FontHandle;
}
for ( ; Link != &Private->FontInfoList; Link = Link->ForwardLink) {
GlobalFont = CR (Link, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);
if (FontInfoMask == NULL) {
if (CompareMem (GlobalFont->FontInfo, FontInfo, GlobalFont->FontInfoSize) == 0) {
if (GlobalFontInfo != NULL) {
*GlobalFontInfo = GlobalFont;
}
return TRUE;
}
} else {
//
// Check which options could be used to make a match.
//
switch (Mask) {
case EFI_FONT_INFO_ANY_FONT:
if ((GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) &&
(GlobalFont->FontInfo->FontSize == FontInfo->FontSize))
{
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE:
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE:
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_ANY_STYLE:
Matched = TRUE;
break;
//
// If EFI_FONT_INFO_RESTYLE is specified, then the system may attempt to
// remove some of the specified styles to meet the style requested.
//
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE:
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
Matched = TRUE;
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
//
// If EFI_FONT_INFO_RESIZE is specified, then the system may attempt to
// stretch or shrink a font to meet the size requested.
//
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESIZE:
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_RESIZE:
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
} else {
VagueMatched2 = TRUE;
GlobalFontBackup2 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
break;
case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
Matched = TRUE;
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
break;
case EFI_FONT_INFO_ANY_STYLE:
if ((CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0) &&
(GlobalFont->FontInfo->FontSize == FontInfo->FontSize))
{
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_ANY_SIZE:
if (CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0)
{
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
if (CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0)
{
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_ANY_SIZE:
if ((CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0) &&
(GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle))
{
Matched = TRUE;
}
break;
case EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
if (CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0)
{
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
Matched = TRUE;
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_RESTYLE:
if ((CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0) &&
(GlobalFont->FontInfo->FontSize == FontInfo->FontSize))
{
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
Matched = TRUE;
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_RESIZE:
if ((CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0) &&
(GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle))
{
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
}
break;
case EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_RESTYLE:
if (CompareMem (
GlobalFont->FontInfo->FontName,
FontInfo->FontName,
StrSize (FontInfo->FontName)
) == 0)
{
if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
Matched = TRUE;
} else {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
}
} else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
VagueMatched1 = TRUE;
GlobalFontBackup1 = GlobalFont;
} else {
VagueMatched2 = TRUE;
GlobalFontBackup2 = GlobalFont;
}
}
}
break;
default:
break;
}
if (Matched) {
if (GlobalFontInfo != NULL) {
*GlobalFontInfo = GlobalFont;
}
return TRUE;
}
}
}
if (VagueMatched1) {
if (GlobalFontInfo != NULL) {
*GlobalFontInfo = GlobalFontBackup1;
}
return TRUE;
} else if (VagueMatched2) {
if (GlobalFontInfo != NULL) {
*GlobalFontInfo = GlobalFontBackup2;
}
return TRUE;
}
return FALSE;
}
/**
Check whether the unicode represents a line break or not.
This is a internal function. Please see Section 27.2.6 of the UEFI Specification
for a description of the supported string format.
@param Char Unicode character
@retval 0 Yes, it forces a line break.
@retval 1 Yes, it presents a line break opportunity
@retval 2 Yes, it requires a line break happen before and after it.
@retval -1 No, it is not a link break.
**/
INT8
IsLineBreak (
IN CHAR16 Char
)
{
switch (Char) {
//
// Mandatory line break characters, which force a line-break
//
case 0x000A:
case 0x000C:
case 0x000D:
case 0x2028:
case 0x2029:
return 0;
//
// Space characters, which is taken as a line-break opportunity
//
case 0x0020:
case 0x1680:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
case 0x2004:
case 0x2005:
case 0x2006:
case 0x2008:
case 0x2009:
case 0x200A:
case 0x205F:
//
// In-Word Break Opportunities
//
case 0x200B:
return 1;
//
// A space which is not a line-break opportunity
//
case 0x00A0:
case 0x202F:
//
// A hyphen which is not a line-break opportunity
//
case 0x2011:
return -1;
//
// Hyphen characters which describe line break opportunities after the character
//
case 0x058A:
case 0x2010:
case 0x2012:
case 0x2013:
case 0x0F0B:
case 0x1361:
case 0x17D5:
return 1;
//
// A hyphen which describes line break opportunities before and after them, but not between a pair of them
//
case 0x2014:
return 2;
}
return -1;
}
/**
Renders a string to a bitmap or to the display.
@param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
@param Flags Describes how the string is to be drawn.
@param String Points to the null-terminated string to be
displayed.
@param StringInfo Points to the string output information,
including the color and font. If NULL, then the
string will be output in the default system font
and color.
@param Blt If this points to a non-NULL on entry, this
points to the image, which is Width pixels wide
and Height pixels high. The string will be drawn
onto this image and
EFI_HII_OUT_FLAG_CLIP is implied. If this points
to a NULL on entry, then a buffer
will be allocated to hold the generated image and
the pointer updated on exit. It is the caller's
responsibility to free this buffer.
@param BltX Specifies the offset from the left and top edge
of the image of the first character cell in the
image.
@param BltY Specifies the offset from the left and top edge
of the image of the first character cell in the
image.
@param RowInfoArray If this is non-NULL on entry, then on exit, this
will point to an allocated buffer containing
row information and RowInfoArraySize will be
updated to contain the number of elements.
This array describes the characters which were at
least partially drawn and the heights of the
rows. It is the caller's responsibility to free
this buffer.
@param RowInfoArraySize If this is non-NULL on entry, then on exit it
contains the number of elements in RowInfoArray.
@param ColumnInfoArray If this is non-NULL, then on return it will be
filled with the horizontal offset for each
character in the string on the row where it is
displayed. Non-printing characters will have
the offset ~0. The caller is responsible to
allocate a buffer large enough so that there
is one entry for each character in the string,
not including the null-terminator. It is possible
when character display is normalized that some
character cells overlap.
@retval EFI_SUCCESS The string was successfully rendered.
@retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
RowInfoArray or Blt.
@retval EFI_INVALID_PARAMETER The String or Blt was NULL.
@retval EFI_INVALID_PARAMETER Flags were invalid combination..
**/
EFI_STATUS
EFIAPI
HiiStringToImage (
IN CONST EFI_HII_FONT_PROTOCOL *This,
IN EFI_HII_OUT_FLAGS Flags,
IN CONST EFI_STRING String,
IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
IN OUT EFI_IMAGE_OUTPUT **Blt,
IN UINTN BltX,
IN UINTN BltY,
OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
OUT UINTN *RowInfoArraySize OPTIONAL,
OUT UINTN *ColumnInfoArray OPTIONAL
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
UINT8 **GlyphBuf;
EFI_HII_GLYPH_INFO *Cell;
UINT8 *Attributes;
EFI_IMAGE_OUTPUT *Image;
EFI_STRING StringPtr;
EFI_STRING StringTmp;
EFI_HII_ROW_INFO *RowInfo;
UINTN LineWidth;
UINTN LineHeight;
UINTN LineOffset;
UINTN LastLineHeight;
UINTN BaseLineOffset;
UINT16 MaxRowNum;
UINT16 RowIndex;
UINTN Index;
UINTN NextIndex;
UINTN Index1;
EFI_FONT_DISPLAY_INFO *StringInfoOut;
EFI_FONT_DISPLAY_INFO *SystemDefault;
EFI_FONT_HANDLE FontHandle;
EFI_STRING StringIn;
EFI_STRING StringIn2;
UINT16 Height;
UINT16 BaseLine;
EFI_FONT_INFO *FontInfo;
BOOLEAN SysFontFlag;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
BOOLEAN Transparent;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BufferPtr;
UINTN RowInfoSize;
BOOLEAN LineBreak;
UINTN StrLength;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *RowBufferPtr;
HII_GLOBAL_FONT_INFO *GlobalFont;
UINT32 PreInitBkgnd;
//
// Check incoming parameters.
//
if ((This == NULL) || (String == NULL) || (Blt == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (*Blt == NULL) {
//
// These two flag cannot be used if Blt is NULL upon entry.
//
if ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT) {
return EFI_INVALID_PARAMETER;
}
if ((Flags & EFI_HII_OUT_FLAG_CLIP) == EFI_HII_OUT_FLAG_CLIP) {
return EFI_INVALID_PARAMETER;
}
}
//
// These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.
//
if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_X) {
return EFI_INVALID_PARAMETER;
}
if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
return EFI_INVALID_PARAMETER;
}
//
// This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.
//
if ((Flags & (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) {
return EFI_INVALID_PARAMETER;
}
if (*Blt == NULL) {
//
// Create a new bitmap and draw the string onto this image.
//
Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
if (Image == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Image->Width = 800;
Image->Height = 600;
Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
if (Image->Image.Bitmap == NULL) {
FreePool (Image);
return EFI_OUT_OF_RESOURCES;
}
//
// Other flags are not permitted when Blt is NULL.
//
Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;
*Blt = Image;
}
StrLength = StrLen (String);
GlyphBuf = (UINT8 **)AllocateZeroPool (StrLength * sizeof (UINT8 *));
ASSERT (GlyphBuf != NULL);
Cell = (EFI_HII_GLYPH_INFO *)AllocateZeroPool (StrLength * sizeof (EFI_HII_GLYPH_INFO));
ASSERT (Cell != NULL);
Attributes = (UINT8 *)AllocateZeroPool (StrLength * sizeof (UINT8));
ASSERT (Attributes != NULL);
FontInfo = NULL;
RowInfo = NULL;
Status = EFI_SUCCESS;
StringIn2 = NULL;
SystemDefault = NULL;
StringIn = NULL;
//
// Calculate the string output information, including specified color and font .
// If StringInfo does not points to system font info, it must indicate an existing
// EFI_FONT_INFO.
//
StringInfoOut = NULL;
FontHandle = NULL;
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *)StringInfo, &SystemDefault, NULL);
if (SysFontFlag) {
ASSERT (SystemDefault != NULL);
FontInfo = NULL;
Height = SystemDefault->FontInfo.FontSize;
BaseLine = SystemDefault->FontInfo.FontSize;
Foreground = SystemDefault->ForegroundColor;
Background = SystemDefault->BackgroundColor;
} else {
//
// StringInfo must not be NULL if it is not system info.
//
ASSERT (StringInfo != NULL);
Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *)StringInfo, &StringInfoOut, NULL);
if (Status == EFI_NOT_FOUND) {
//
// The specified EFI_FONT_DISPLAY_INFO does not exist in current database.
// Use the system font instead. Still use the color specified by StringInfo.
//
SysFontFlag = TRUE;
FontInfo = NULL;
Height = SystemDefault->FontInfo.FontSize;
BaseLine = SystemDefault->FontInfo.FontSize;
Foreground = ((EFI_FONT_DISPLAY_INFO *)StringInfo)->ForegroundColor;
Background = ((EFI_FONT_DISPLAY_INFO *)StringInfo)->BackgroundColor;
} else if (Status == EFI_SUCCESS) {
FontInfo = &StringInfoOut->FontInfo;
if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {
Height = GlobalFont->FontPackage->Height;
BaseLine = GlobalFont->FontPackage->BaseLine;
Foreground = StringInfoOut->ForegroundColor;
Background = StringInfoOut->BackgroundColor;
} else {
goto Exit;
}
} else {
goto Exit;
}
}
//
// Use the maximum height of font as the base line.
// And, use the maximum height as line height.
//
LineHeight = Height;
LastLineHeight = Height;
BaseLineOffset = Height - BaseLine;
//
// Parse the string to be displayed to drop some ignored characters.
//
StringPtr = String;
//
// Ignore line-break characters only. Hyphens or dash character will be displayed
// without line-break opportunity.
//
if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == EFI_HII_IGNORE_LINE_BREAK) {
StringIn = AllocateZeroPool (StrSize (StringPtr));
if (StringIn == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
StringTmp = StringIn;
while (*StringPtr != 0) {
if (IsLineBreak (*StringPtr) == 0) {
StringPtr++;
} else {
*StringTmp++ = *StringPtr++;
}
}
*StringTmp = 0;
StringPtr = StringIn;
}
//
// If EFI_HII_IGNORE_IF_NO_GLYPH is set, then characters which have no glyphs
// are not drawn. Otherwise they are replaced with Unicode character 0xFFFD.
//
StringIn2 = AllocateZeroPool (StrSize (StringPtr));
if (StringIn2 == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Index = 0;
StringTmp = StringIn2;
StrLength = StrLen (StringPtr);
while (*StringPtr != 0 && Index < StrLength) {
if (IsLineBreak (*StringPtr) == 0) {
*StringTmp++ = *StringPtr++;
Index++;
continue;
}
Status = GetGlyphBuffer (Private, *StringPtr, FontInfo, &GlyphBuf[Index], &Cell[Index], &Attributes[Index]);
if (Status == EFI_NOT_FOUND) {
if ((Flags & EFI_HII_IGNORE_IF_NO_GLYPH) == EFI_HII_IGNORE_IF_NO_GLYPH) {
GlyphBuf[Index] = NULL;
ZeroMem (&Cell[Index], sizeof (Cell[Index]));
Status = EFI_SUCCESS;
} else {
//
// Unicode 0xFFFD must exist in current hii database if this flag is not set.
//
Status = GetGlyphBuffer (
Private,
REPLACE_UNKNOWN_GLYPH,
FontInfo,
&GlyphBuf[Index],
&Cell[Index],
&Attributes[Index]
);
if (EFI_ERROR (Status)) {
Status = EFI_INVALID_PARAMETER;
}
}
}
if (EFI_ERROR (Status)) {
goto Exit;
}
*StringTmp++ = *StringPtr++;
Index++;
}
*StringTmp = 0;
StringPtr = StringIn2;
//
// Draw the string according to the specified EFI_HII_OUT_FLAGS and Blt.
// If Blt is not NULL, then EFI_HII_OUT_FLAG_CLIP is implied, render this string
// to an existing image (bitmap or screen depending on flags) pointed by "*Blt".
// Otherwise render this string to a new allocated image and output it.
//
Image = *Blt;
BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;
if (Image->Height < BltY) {
//
// the top edge of the image should be in Image resolution scope.
//
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
MaxRowNum = (UINT16)((Image->Height - BltY) / Height);
if ((Image->Height - BltY) % Height != 0) {
LastLineHeight = (Image->Height - BltY) % Height;
MaxRowNum++;
}
RowInfo = (EFI_HII_ROW_INFO *)AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));
if (RowInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Format the glyph buffer according to flags.
//
Transparent = (BOOLEAN)((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);
for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {
LineWidth = 0;
LineBreak = FALSE;
//
// Clip the final row if the row's bottom-most on pixel cannot fit when
// EFI_HII_OUT_FLAG_CLEAN_Y is set.
//
if (RowIndex == MaxRowNum - 1) {
if (((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) && (LastLineHeight < LineHeight)) {
//
// Don't draw at all if the row's bottom-most on pixel cannot fit.
//
break;
}
LineHeight = LastLineHeight;
}
//
// Calculate how many characters there are in a row.
//
RowInfo[RowIndex].StartIndex = Index;
while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) {
if (((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) &&
(IsLineBreak (StringPtr[Index]) == 0))
{
//
// It forces a line break that ends this row.
//
Index++;
LineBreak = TRUE;
break;
}
//
// If the glyph of the character is existing, then accumulate the actual printed width
//
LineWidth += (UINTN)Cell[Index].AdvanceX;
Index++;
}
//
// Record index of next char.
//
NextIndex = Index;
//
// Return to the previous char.
//
Index--;
if (LineBreak && (Index > 0)) {
//
// Return the previous non line break char.
//
Index--;
}
//
// If this character is the last character of a row, we need not
// draw its (AdvanceX - Width - OffsetX) for next character.
//
LineWidth -= (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
//
// Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
//
if ((LineWidth + BltX <= Image->Width) ||
((LineWidth + BltX > Image->Width) && ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)))
{
//
// Record right-most character in RowInfo even if it is partially displayed.
//
RowInfo[RowIndex].EndIndex = Index;
RowInfo[RowIndex].LineWidth = LineWidth;
RowInfo[RowIndex].LineHeight = LineHeight;
RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
} else {
//
// When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character
// if its right-most on pixel cannot fit.
//
if (Index > RowInfo[RowIndex].StartIndex) {
//
// Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
//
LineWidth -= (Cell[Index].Width + Cell[Index].OffsetX);
LineWidth -= (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
RowInfo[RowIndex].EndIndex = Index - 1;
RowInfo[RowIndex].LineWidth = LineWidth;
RowInfo[RowIndex].LineHeight = LineHeight;
RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
} else {
//
// There is no enough column to draw any character, so set current line width to zero.
// And go to draw Next line if LineBreak is set.
//
RowInfo[RowIndex].LineWidth = 0;
goto NextLine;
}
}
//
// EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break
// opportunity prior to a character whose right-most extent would exceed Width.
// Search the right-most line-break opportunity here.
//
if (((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) &&
((RowInfo[RowIndex].LineWidth + BltX > Image->Width) || (StringPtr[NextIndex] != 0)) &&
!LineBreak)
{
if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {
LineWidth = RowInfo[RowIndex].LineWidth;
for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {
if (Index1 == RowInfo[RowIndex].EndIndex) {
LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);
} else {
LineWidth -= Cell[Index1].AdvanceX;
}
if (IsLineBreak (StringPtr[Index1]) > 0) {
LineBreak = TRUE;
if (Index1 > RowInfo[RowIndex].StartIndex) {
RowInfo[RowIndex].EndIndex = Index1 - 1;
}
//
// relocate to the character after the right-most line break opportunity of this line
//
NextIndex = Index1 + 1;
break;
}
//
// If don't find a line break opportunity from EndIndex to StartIndex,
// then jump out.
//
if (Index1 == RowInfo[RowIndex].StartIndex) {
break;
}
}
//
// Update LineWidth to the real width
//
if (IsLineBreak (StringPtr[Index1]) > 0) {
if (Index1 == RowInfo[RowIndex].StartIndex) {
LineWidth = 0;
} else {
LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
}
RowInfo[RowIndex].LineWidth = LineWidth;
}
}
//
// If no line-break opportunity can be found, then the text will
// behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.
//
if (!LineBreak) {
LineWidth = RowInfo[RowIndex].LineWidth;
Index1 = RowInfo[RowIndex].EndIndex;
if (LineWidth + BltX > Image->Width) {
if (Index1 > RowInfo[RowIndex].StartIndex) {
//
// Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
//
LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);
LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
RowInfo[RowIndex].EndIndex = Index1 - 1;
RowInfo[RowIndex].LineWidth = LineWidth;
} else {
//
// There is no enough column to draw any character, so set current line width to zero.
// And go to draw Next line if LineBreak is set.
//
RowInfo[RowIndex].LineWidth = 0;
goto NextLine;
}
}
}
}
//
// LineWidth can't exceed Image width.
//
if (RowInfo[RowIndex].LineWidth + BltX > Image->Width) {
RowInfo[RowIndex].LineWidth = Image->Width - BltX;
}
//
// Draw it to screen or existing bitmap depending on whether
// EFI_HII_DIRECT_TO_SCREEN is set.
//
LineOffset = 0;
if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {
BltBuffer = NULL;
if (RowInfo[RowIndex].LineWidth != 0) {
BltBuffer = AllocatePool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
if (BltBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Initialize the background color.
//
PreInitBkgnd = Background.Blue | Background.Green << 8 | Background.Red << 16;
SetMem32 (BltBuffer, RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), PreInitBkgnd);
//
// Set BufferPtr to Origin by adding baseline to the starting position.
//
BufferPtr = BltBuffer + BaseLine * RowInfo[RowIndex].LineWidth;
}
for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
if ((RowInfo[RowIndex].LineWidth > 0) && (RowInfo[RowIndex].LineWidth > LineOffset)) {
//
// Only BLT these character which have corresponding glyph in font database.
//
GlyphToImage (
GlyphBuf[Index1],
Foreground,
Background,
(UINT16)RowInfo[RowIndex].LineWidth,
BaseLine,
RowInfo[RowIndex].LineWidth - LineOffset,
RowInfo[RowIndex].LineHeight,
Transparent,
&Cell[Index1],
Attributes[Index1],
&BufferPtr
);
}
if (ColumnInfoArray != NULL) {
if ( ((GlyphBuf[Index1] == NULL) && (Cell[Index1].AdvanceX == 0))
|| (RowInfo[RowIndex].LineWidth == 0))
{
*ColumnInfoArray = (UINTN) ~0;
} else {
*ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;
}
ColumnInfoArray++;
}
LineOffset += Cell[Index1].AdvanceX;
}
if (BltBuffer != NULL) {
Status = Image->Image.Screen->Blt (
Image->Image.Screen,
BltBuffer,
EfiBltBufferToVideo,
0,
0,
BltX,
BltY,
RowInfo[RowIndex].LineWidth,
RowInfo[RowIndex].LineHeight,
0
);
if (EFI_ERROR (Status)) {
FreePool (BltBuffer);
goto Exit;
}
FreePool (BltBuffer);
}
} else {
//
// Save the starting position for calculate the starting position of next row.
//
RowBufferPtr = BufferPtr;
//
// Set BufferPtr to Origin by adding baseline to the starting position.
//
BufferPtr = BufferPtr + BaseLine * Image->Width;
for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
if ((RowInfo[RowIndex].LineWidth > 0) && (RowInfo[RowIndex].LineWidth > LineOffset)) {
//
// Only BLT these character which have corresponding glyph in font database.
//
GlyphToImage (
GlyphBuf[Index1],
Foreground,
Background,
Image->Width,
BaseLine,
RowInfo[RowIndex].LineWidth - LineOffset,
RowInfo[RowIndex].LineHeight,
Transparent,
&Cell[Index1],
Attributes[Index1],
&BufferPtr
);
}
if (ColumnInfoArray != NULL) {
if ( ((GlyphBuf[Index1] == NULL) && (Cell[Index1].AdvanceX == 0))
|| (RowInfo[RowIndex].LineWidth == 0))
{
*ColumnInfoArray = (UINTN) ~0;
} else {
*ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;
}
ColumnInfoArray++;
}
LineOffset += Cell[Index1].AdvanceX;
}
//
// Jump to starting position of next row.
//
if (RowIndex == 0) {
BufferPtr = RowBufferPtr - BltX + LineHeight * Image->Width;
} else {
BufferPtr = RowBufferPtr + LineHeight * Image->Width;
}
}
NextLine:
//
// Recalculate the start point of Y axis to draw multi-lines with the order of top-to-down
//
BltY += RowInfo[RowIndex].LineHeight;
RowIndex++;
Index = NextIndex;
if (!LineBreak) {
//
// If there is not a mandatory line break or line break opportunity, only render one line to image
//
break;
}
}
//
// Write output parameters.
//
RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);
if (RowInfoArray != NULL) {
if (RowInfoSize > 0) {
*RowInfoArray = AllocateZeroPool (RowInfoSize);
if (*RowInfoArray == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
CopyMem (*RowInfoArray, RowInfo, RowInfoSize);
} else {
*RowInfoArray = NULL;
}
}
if (RowInfoArraySize != NULL) {
*RowInfoArraySize = RowIndex;
}
Status = EFI_SUCCESS;
Exit:
for (Index = 0; Index < StrLength; Index++) {
if (GlyphBuf[Index] != NULL) {
FreePool (GlyphBuf[Index]);
}
}
if (StringIn != NULL) {
FreePool (StringIn);
}
if (StringIn2 != NULL) {
FreePool (StringIn2);
}
if (StringInfoOut != NULL) {
FreePool (StringInfoOut);
}
if (RowInfo != NULL) {
FreePool (RowInfo);
}
if (SystemDefault != NULL) {
FreePool (SystemDefault);
}
if (GlyphBuf != NULL) {
FreePool (GlyphBuf);
}
if (Cell != NULL) {
FreePool (Cell);
}
if (Attributes != NULL) {
FreePool (Attributes);
}
return Status;
}
/**
Render a string to a bitmap or the screen containing the contents of the specified string.
@param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
@param Flags Describes how the string is to be drawn.
@param PackageList The package list in the HII database to search
for the specified string.
@param StringId The string's id, which is unique within
PackageList.
@param Language Points to the language for the retrieved string.
If NULL, then the current system language is
used.
@param StringInfo Points to the string output information,
including the color and font. If NULL, then the
string will be output in the default system font
and color.
@param Blt If this points to a non-NULL on entry, this
points to the image, which is Width pixels wide
and Height pixels high. The string will be drawn
onto this image and
EFI_HII_OUT_FLAG_CLIP is implied. If this points
to a NULL on entry, then a buffer
will be allocated to hold the generated image and
the pointer updated on exit. It is the caller's
responsibility to free this buffer.
@param BltX Specifies the offset from the left and top edge
of the image of the first character cell in the
image.
@param BltY Specifies the offset from the left and top edge
of the image of the first character cell in the
image.
@param RowInfoArray If this is non-NULL on entry, then on exit, this
will point to an allocated buffer containing
row information and RowInfoArraySize will be
updated to contain the number of elements.
This array describes the characters which were at
least partially drawn and the heights of the
rows. It is the caller's responsibility to free
this buffer.
@param RowInfoArraySize If this is non-NULL on entry, then on exit it
contains the number of elements in RowInfoArray.
@param ColumnInfoArray If this is non-NULL, then on return it will be
filled with the horizontal offset for each
character in the string on the row where it is
displayed. Non-printing characters will have
the offset ~0. The caller is responsible to
allocate a buffer large enough so that there
is one entry for each character in the string,
not including the null-terminator. It is possible
when character display is normalized that some
character cells overlap.
@retval EFI_SUCCESS The string was successfully rendered.
@retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
RowInfoArray or Blt.
@retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.
@retval EFI_INVALID_PARAMETER Flags were invalid combination.
@retval EFI_NOT_FOUND The specified PackageList is not in the Database or the string id is not
in the specified PackageList.
**/
EFI_STATUS
EFIAPI
HiiStringIdToImage (
IN CONST EFI_HII_FONT_PROTOCOL *This,
IN EFI_HII_OUT_FLAGS Flags,
IN EFI_HII_HANDLE PackageList,
IN EFI_STRING_ID StringId,
IN CONST CHAR8 *Language,
IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
IN OUT EFI_IMAGE_OUTPUT **Blt,
IN UINTN BltX,
IN UINTN BltY,
OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
OUT UINTN *RowInfoArraySize OPTIONAL,
OUT UINTN *ColumnInfoArray OPTIONAL
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
EFI_HII_STRING_PROTOCOL *HiiString;
EFI_STRING String;
UINTN StringSize;
UINTN FontLen;
UINTN NameSize;
EFI_FONT_INFO *StringFontInfo;
EFI_FONT_DISPLAY_INFO *NewStringInfo;
CHAR8 TempSupportedLanguages;
CHAR8 *SupportedLanguages;
UINTN SupportedLanguagesSize;
CHAR8 *CurrentLanguage;
CHAR8 *BestLanguage;
if ((This == NULL) || (PackageList == NULL) || (Blt == NULL) || (PackageList == NULL)) {
return EFI_INVALID_PARAMETER;
}
if (!IsHiiHandleValid (PackageList)) {
return EFI_NOT_FOUND;
}
//
// Initialize string pointers to be NULL
//
SupportedLanguages = NULL;
CurrentLanguage = NULL;
BestLanguage = NULL;
String = NULL;
StringFontInfo = NULL;
NewStringInfo = NULL;
//
// Get the string to be displayed.
//
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
HiiString = &Private->HiiString;
//
// Get the size of supported language.
//
SupportedLanguagesSize = 0;
Status = HiiString->GetLanguages (
HiiString,
PackageList,
&TempSupportedLanguages,
&SupportedLanguagesSize
);
if (Status != EFI_BUFFER_TOO_SMALL) {
return Status;
}
SupportedLanguages = AllocatePool (SupportedLanguagesSize);
if (SupportedLanguages == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = HiiString->GetLanguages (
HiiString,
PackageList,
SupportedLanguages,
&SupportedLanguagesSize
);
if (EFI_ERROR (Status)) {
goto Exit;
}
if (Language == NULL) {
Language = "";
}
GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&CurrentLanguage, NULL);
BestLanguage = GetBestLanguage (
SupportedLanguages,
FALSE,
Language,
(CurrentLanguage == NULL) ? CurrentLanguage : "",
(CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
NULL
);
if (BestLanguage == NULL) {
Status = EFI_NOT_FOUND;
goto Exit;
}
StringSize = MAX_STRING_LENGTH;
String = (EFI_STRING)AllocateZeroPool (StringSize);
if (String == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Status = HiiString->GetString (
HiiString,
BestLanguage,
PackageList,
StringId,
String,
&StringSize,
&StringFontInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
FreePool (String);
String = (EFI_STRING)AllocateZeroPool (StringSize);
if (String == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Status = HiiString->GetString (
HiiString,
BestLanguage,
PackageList,
StringId,
String,
&StringSize,
NULL
);
}
if (EFI_ERROR (Status)) {
goto Exit;
}
//
// When StringInfo specifies that string will be output in the system default font and color,
// use particular stringfontinfo described in string package instead if exists.
// StringFontInfo equals NULL means system default font attaches with the string block.
//
if ((StringFontInfo != NULL) && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *)StringInfo, NULL, NULL)) {
NameSize = StrSize (StringFontInfo->FontName);
FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize;
NewStringInfo = AllocateZeroPool (FontLen);
if (NewStringInfo == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR;
NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle;
NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize;
StrCpyS (NewStringInfo->FontInfo.FontName, NameSize / sizeof (CHAR16), StringFontInfo->FontName);
Status = HiiStringToImage (
This,
Flags,
String,
NewStringInfo,
Blt,
BltX,
BltY,
RowInfoArray,
RowInfoArraySize,
ColumnInfoArray
);
goto Exit;
}
Status = HiiStringToImage (
This,
Flags,
String,
StringInfo,
Blt,
BltX,
BltY,
RowInfoArray,
RowInfoArraySize,
ColumnInfoArray
);
Exit:
if (SupportedLanguages != NULL) {
FreePool (SupportedLanguages);
}
if (CurrentLanguage != NULL) {
FreePool (CurrentLanguage);
}
if (BestLanguage != NULL) {
FreePool (BestLanguage);
}
if (String != NULL) {
FreePool (String);
}
if (StringFontInfo != NULL) {
FreePool (StringFontInfo);
}
if (NewStringInfo != NULL) {
FreePool (NewStringInfo);
}
return Status;
}
/**
Convert the glyph for a single character into a bitmap.
@param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
@param Char Character to retrieve.
@param StringInfo Points to the string font and color information
or NULL if the string should use the default
system font and color.
@param Blt Thus must point to a NULL on entry. A buffer will
be allocated to hold the output and the pointer
updated on exit. It is the caller's
responsibility to free this buffer.
@param Baseline Number of pixels from the bottom of the bitmap to
the baseline.
@retval EFI_SUCCESS Glyph bitmap created.
@retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt.
@retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was replaced with the
glyph for Unicode character 0xFFFD.
@retval EFI_INVALID_PARAMETER Blt is NULL or *Blt is not NULL.
**/
EFI_STATUS
EFIAPI
HiiGetGlyph (
IN CONST EFI_HII_FONT_PROTOCOL *This,
IN CHAR16 Char,
IN CONST EFI_FONT_DISPLAY_INFO *StringInfo,
OUT EFI_IMAGE_OUTPUT **Blt,
OUT UINTN *Baseline OPTIONAL
)
{
EFI_STATUS Status;
HII_DATABASE_PRIVATE_DATA *Private;
EFI_IMAGE_OUTPUT *Image;
UINT8 *GlyphBuffer;
EFI_FONT_DISPLAY_INFO *SystemDefault;
EFI_FONT_DISPLAY_INFO *StringInfoOut;
BOOLEAN Default;
EFI_FONT_HANDLE FontHandle;
EFI_STRING String;
EFI_HII_GLYPH_INFO Cell;
EFI_FONT_INFO *FontInfo;
UINT8 Attributes;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
UINT16 BaseLine;
if ((This == NULL) || (Blt == NULL) || (*Blt != NULL)) {
return EFI_INVALID_PARAMETER;
}
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
Default = FALSE;
Image = NULL;
SystemDefault = NULL;
FontHandle = NULL;
String = NULL;
GlyphBuffer = NULL;
StringInfoOut = NULL;
FontInfo = NULL;
ZeroMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
ZeroMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
Default = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *)StringInfo, &SystemDefault, NULL);
if (!Default) {
//
// Find out a EFI_FONT_DISPLAY_INFO which could display the character in
// the specified color and font.
//
String = (EFI_STRING)AllocateZeroPool (sizeof (CHAR16) * 2);
if (String == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
*String = Char;
*(String + 1) = 0;
Status = HiiGetFontInfo (This, &FontHandle, StringInfo, &StringInfoOut, String);
if (EFI_ERROR (Status)) {
goto Exit;
}
ASSERT (StringInfoOut != NULL);
FontInfo = &StringInfoOut->FontInfo;
Foreground = StringInfoOut->ForegroundColor;
Background = StringInfoOut->BackgroundColor;
} else {
ASSERT (SystemDefault != NULL);
Foreground = SystemDefault->ForegroundColor;
Background = SystemDefault->BackgroundColor;
}
Status = GetGlyphBuffer (Private, Char, FontInfo, &GlyphBuffer, &Cell, &Attributes);
if (EFI_ERROR (Status)) {
goto Exit;
}
Image = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
if (Image == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Image->Width = Cell.Width;
Image->Height = Cell.Height;
if (Image->Width * Image->Height > 0) {
Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
if (Image->Image.Bitmap == NULL) {
FreePool (Image);
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
//
// Set BaseLine to the char height.
//
BaseLine = (UINT16)(Cell.Height + Cell.OffsetY);
//
// Set BltBuffer to the position of Origin.
//
BltBuffer = Image->Image.Bitmap + (Cell.Height + Cell.OffsetY) * Image->Width - Cell.OffsetX;
GlyphToImage (
GlyphBuffer,
Foreground,
Background,
Image->Width,
BaseLine,
Cell.Width + Cell.OffsetX,
BaseLine - Cell.OffsetY,
FALSE,
&Cell,
Attributes,
&BltBuffer
);
}
*Blt = Image;
if (Baseline != NULL) {
*Baseline = Cell.OffsetY;
}
Status = EFI_SUCCESS;
Exit:
if (Status == EFI_NOT_FOUND) {
//
// Glyph is unknown and replaced with the glyph for unicode character 0xFFFD
//
if (Char != REPLACE_UNKNOWN_GLYPH) {
Status = HiiGetGlyph (This, REPLACE_UNKNOWN_GLYPH, StringInfo, Blt, Baseline);
if (!EFI_ERROR (Status)) {
Status = EFI_WARN_UNKNOWN_GLYPH;
}
} else {
Status = EFI_WARN_UNKNOWN_GLYPH;
}
}
if (SystemDefault != NULL) {
FreePool (SystemDefault);
}
if (StringInfoOut != NULL) {
FreePool (StringInfoOut);
}
if (String != NULL) {
FreePool (String);
}
if (GlyphBuffer != NULL) {
FreePool (GlyphBuffer);
}
return Status;
}
/**
This function iterates through fonts which match the specified font, using
the specified criteria. If String is non-NULL, then all of the characters in
the string must exist in order for a candidate font to be returned.
@param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
@param FontHandle On entry, points to the font handle returned by a
previous call to GetFontInfo() or NULL to start
with the first font. On return, points to the
returned font handle or points to NULL if there
are no more matching fonts.
@param StringInfoIn Upon entry, points to the font to return information
about. If NULL, then the information about the system
default font will be returned.
@param StringInfoOut Upon return, contains the matching font's information.
If NULL, then no information is returned. This buffer
is allocated with a call to the Boot Service AllocatePool().
It is the caller's responsibility to call the Boot
Service FreePool() when the caller no longer requires
the contents of StringInfoOut.
@param String Points to the string which will be tested to
determine if all characters are available. If
NULL, then any font is acceptable.
@retval EFI_SUCCESS Matching font returned successfully.
@retval EFI_NOT_FOUND No matching font was found.
@retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination.
@retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
request.
**/
EFI_STATUS
EFIAPI
HiiGetFontInfo (
IN CONST EFI_HII_FONT_PROTOCOL *This,
IN OUT EFI_FONT_HANDLE *FontHandle,
IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn OPTIONAL,
OUT EFI_FONT_DISPLAY_INFO **StringInfoOut,
IN CONST EFI_STRING String OPTIONAL
)
{
HII_DATABASE_PRIVATE_DATA *Private;
EFI_STATUS Status;
EFI_FONT_DISPLAY_INFO *SystemDefault;
EFI_FONT_DISPLAY_INFO InfoOut;
UINTN StringInfoOutLen;
EFI_FONT_INFO *FontInfo;
HII_GLOBAL_FONT_INFO *GlobalFont;
EFI_STRING StringIn;
EFI_FONT_HANDLE LocalFontHandle;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
StringInfoOutLen = 0;
FontInfo = NULL;
SystemDefault = NULL;
LocalFontHandle = NULL;
if (FontHandle != NULL) {
LocalFontHandle = *FontHandle;
}
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
//
// Already searched to the end of the whole list, return directly.
//
if (LocalFontHandle == &Private->FontInfoList) {
LocalFontHandle = NULL;
Status = EFI_NOT_FOUND;
goto Exit;
}
//
// Get default system display info, if StringInfoIn points to
// system display info, return it directly.
//
if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *)StringInfoIn, &SystemDefault, &StringInfoOutLen)) {
//
// System font is the first node. When handle is not NULL, system font can not
// be found any more.
//
if (LocalFontHandle == NULL) {
if (StringInfoOut != NULL) {
*StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault);
if (*StringInfoOut == NULL) {
Status = EFI_OUT_OF_RESOURCES;
LocalFontHandle = NULL;
goto Exit;
}
}
LocalFontHandle = Private->FontInfoList.ForwardLink;
Status = EFI_SUCCESS;
goto Exit;
} else {
LocalFontHandle = NULL;
Status = EFI_NOT_FOUND;
goto Exit;
}
}
//
// StringInfoIn must not be NULL if it is not system default font info.
//
ASSERT (StringInfoIn != NULL);
//
// Check the font information mask to make sure it is valid.
//
if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ==
(EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ||
((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ==
(EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ||
((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ==
(EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||
((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ==
(EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ||
((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) ==
(EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)))
{
return EFI_INVALID_PARAMETER;
}
//
// Parse the font information mask to find a matching font.
//
CopyMem (&InfoOut, (EFI_FONT_DISPLAY_INFO *)StringInfoIn, sizeof (EFI_FONT_DISPLAY_INFO));
if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FONT) == EFI_FONT_INFO_SYS_FONT) {
Status = SaveFontName (SystemDefault->FontInfo.FontName, &FontInfo);
} else {
Status = SaveFontName (((EFI_FONT_DISPLAY_INFO *)StringInfoIn)->FontInfo.FontName, &FontInfo);
}
if (EFI_ERROR (Status)) {
goto Exit;
}
if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) {
InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize;
}
if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {
InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle;
}
if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {
InfoOut.ForegroundColor = SystemDefault->ForegroundColor;
}
if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {
InfoOut.BackgroundColor = SystemDefault->BackgroundColor;
}
ASSERT (FontInfo != NULL);
FontInfo->FontSize = InfoOut.FontInfo.FontSize;
FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;
if (IsFontInfoExisted (Private, FontInfo, &InfoOut.FontInfoMask, LocalFontHandle, &GlobalFont)) {
//
// Test to guarantee all characters are available in the found font.
//
if (String != NULL) {
StringIn = String;
while (*StringIn != 0) {
Status = FindGlyphBlock (GlobalFont->FontPackage, *StringIn, NULL, NULL, NULL);
if (EFI_ERROR (Status)) {
LocalFontHandle = NULL;
goto Exit;
}
StringIn++;
}
}
//
// Write to output parameter
//
if (StringInfoOut != NULL) {
StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize;
*StringInfoOut = (EFI_FONT_DISPLAY_INFO *)AllocateZeroPool (StringInfoOutLen);
if (*StringInfoOut == NULL) {
Status = EFI_OUT_OF_RESOURCES;
LocalFontHandle = NULL;
goto Exit;
}
CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO));
CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);
}
LocalFontHandle = GlobalFont->Entry.ForwardLink;
Status = EFI_SUCCESS;
goto Exit;
}
Status = EFI_NOT_FOUND;
Exit:
if (FontHandle != NULL) {
*FontHandle = LocalFontHandle;
}
if (SystemDefault != NULL) {
FreePool (SystemDefault);
}
if (FontInfo != NULL) {
FreePool (FontInfo);
}
return Status;
}
|