FontResFile.cpp 35.4 KB
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
#include "stdafx.h"
#include "FontResFile.h"
#include "FontClass.h"
#include "FontHWCompress.h"




/*****************************************************************************
 * FUNCTION
 *  font_16HexStringToInt
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
int font_16HexStringToInt(string *str)
{
    string hexstr = *str;
    char num = 0;
    int res = 0;
    int bit = 1;
    for(int i = hexstr.length() - 1; i >= 0; i--)
    {
        if((hexstr[i] >= '0') && (hexstr[i] <= '9'))
        {
            num = hexstr[i] - '0';
        }
        else if((hexstr[i] >= 'A') && (hexstr[i] <= 'F'))
        {
            num = hexstr[i] - 'A' + 10;
        }
        else if((hexstr[i] >= 'a') && (hexstr[i] <= 'f'))
        {
            num = hexstr[i] - 'a' + 10;
        }
        else
        {
            return 0;
        }
        res = res + num * bit;
        bit = bit * 16;
    }
    return res;
}


/*****************************************************************************
 * FUNCTION
 *  font_AddLanguageFlagToString
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool font_AddLanguageFlagToString(string * str, char lang_flag)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    string hexstr;
    char temp[9] = {0};
    int num = font_16HexStringToInt(&hexstr);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if(((*str)[0] == '0') && (((*str)[1] == 'x') || ((*str)[1] == 'X')))
    {
       hexstr = str->substr(2);
    }

    num |= (1 << (lang_flag - 1));
    sprintf(temp, "0X%08X", num);
    *str = (char *)temp;
    return true;
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontResFile
 * DESCRIPTION
 *  This function is used to create FontRes.c file.
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
void FontGenFile::GenerateFontResFile(FontEngine *font_engine)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    FILE *pFile;
    string str;
    char cTemp[100] ={0};

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    if(pFile = fopen(string(m_outputPath + ("\\") + FONT_RES_FILENAME).c_str(), ("w")))
	{	
		fputs(_T("#include \"FontRes.h\"\n"),pFile);
		fputs(_T("#include \"MMI_features.h\"\n"),pFile);
		fputs(_T("#include \"vector_font_lang_memory_card_config.h\"\n"),pFile);
		
		fputs(_T("\n#ifndef NULL\n"),pFile);
		fputs(_T("#define NULL  (void *)0           /*  NULL    :   Null pointer */\n"),pFile);
		fputs(_T("#endif\n"),pFile);
		
		fputs(_T("\n#define  MAX_LANGUAGES     30\n"), pFile);

     
		/* include font data file */
        if(font_engine != NULL)
        {
            for(int i = 0; i < MCT_MAX_FONT_TYPES; i++)
            {
                vector<FontData_Info> *pvctr = &(font_engine->m_font_family[i].fontData_contain); 
                vector<FontData_Info>::iterator it;
                for (it = pvctr->begin(); it < pvctr->end(); it++)
                {
                    if(font_engine->CompareInFontFamily(it) != 2)
                    {
                        fputs("\n#include \"", pFile);
                        fputs(it->gen_hfile_name.c_str(), pFile);
                        fputs("\"", pFile);
                    }
                }
            } 
        }

        fputs("\n", pFile);
        GenerateFontResFile_GroupData(font_engine, pFile);

        sprintf(cTemp, "\nconst U8 g_fontfamily_count = %d ;\n", MCT_MAX_FONT_TYPES);
        str = (char *)cTemp;
        fputs(cTemp,pFile);
            
	    fputs(("\n"),pFile);	

        if(IsUseFontCompression())
        {
            GenerateCompressionInfo(font_engine, pFile);
        }

        if(IsUseHWFontCompression()) 
        {
            FontHWCompressWriteLVTableToFile(pFile,
                                LV1Size, LV2Size,
                                &LV1Dict1, &LV1Dict2,
                                lv1_table_name,
                                lv2_table_name); 
        }
        
        GenerateFontResLanguageTable(&string(""), pFile);

        fclose(pFile);
        
	}
	
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontResFile
 * DESCRIPTION
 *  This function is used to create FontRes.c file.
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
void FontGenFile::GenFontGroupString(FontEngine *font_engine, U8 font_size, FILE *p_file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    string str;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    font_group_struct *pgroup = &(font_engine->m_font_family[font_size]);
    if(pgroup->nTotalFonts == 0)
    {
        str = "NULL\n";
        fputs(str.c_str(), p_file);
    }
    else
    {
        for(int i = 0; i < pgroup->nTotalFonts; i++)
        {
            str = "&" + pgroup->fontData_contain[i].font_data_name;
            if(i != pgroup->nTotalFonts - 1)
            {
                str += ",\n";
            }
            else
            {
                str += "\n";
            }
                fputs(str.c_str(), p_file);
        }
    }

     
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontResFile
 * DESCRIPTION
 *  This function is used to create FontRes.c file.
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
void FontGenFile::GenerateFontResFile_GroupData(FontEngine *font_engine, FILE *pFile)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    char cTemp[100] = {0};
    int i = 0;   
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for(i = 0; i < MCT_MAX_FONT_TYPES; i++)
    {    
        fputs(("\n"),pFile);
        switch(i)
        {
            case MCT_ALPHA_SMALL_FONT:
            {
                fputs(("const sCustFontData * const g_small_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile); 
                break;
            }
            case MCT_ALPHA_MEDIUM_FONT:
            {
                fputs(("const sCustFontData * const g_medium_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile);  
                break;
            }
            case MCT_ALPHA_LARGE_FONT:
            {
                fputs(("const sCustFontData * const g_large_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile); 
                break;
                
            }
            case MCT_ALPHA_SUBLCD_FONT:
            {
                fputs(("const sCustFontData * const g_sublcd_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile); 
                break;
            }
            case MCT_ALPHA_DIALER_FONT:
            {
                fputs(("const sCustFontData * const g_dialling_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile);  
                break;
            }
            case MCT_ALPHA_NUMBER1_FONT:
            {
                fputs(("const sCustFontData * const g_number1_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile);  
                break;
            }
            case MCT_ALPHA_NUMBER2_FONT:
            {
                fputs(("const sCustFontData * const g_number2_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile);  
                break;
            }
            case MCT_ALPHA_TOUCH_SCREEN_FONT:
            {
                fputs(("const sCustFontData * const g_touchscreen_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile); 
                break;
            }
            case MCT_ALPHA_TOUCH_SCREEN_LAREG_FONT:
            {
                fputs(("const sCustFontData * const g_touchscreen_large_font_data_array[] = {\n"),pFile);
                GenFontGroupString(font_engine, i, pFile);
                fputs(("}; \n"),pFile);  
                break;
            }
                                                                        
        }
        
    }
    
    fputs(("\nconst font_group_struct g_fontfamily[MAX_FONT_SIZE] = {\n"),pFile);
    for(i = 0; i < MCT_MAX_FONT_TYPES; i++)
    {
        switch(i)
        {
            case MCT_ALPHA_SMALL_FONT:
            {
                sprintf((char *)cTemp, "{%d, g_small_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
            case MCT_ALPHA_MEDIUM_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_medium_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
            case MCT_ALPHA_LARGE_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_large_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
                
            }
            case MCT_ALPHA_SUBLCD_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_sublcd_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
            case MCT_ALPHA_DIALER_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_dialling_font_data_array},", font_engine->m_font_family[i].nTotalFonts);  
                break;
            }
            case MCT_ALPHA_NUMBER1_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_number1_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
            case MCT_ALPHA_NUMBER2_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_number2_font_data_array},", font_engine->m_font_family[i].nTotalFonts);  
                break;
            }
            case MCT_ALPHA_TOUCH_SCREEN_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_touchscreen_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
            case MCT_ALPHA_TOUCH_SCREEN_LAREG_FONT:
            {
                fputs(("\n"),pFile); 
                sprintf((char *)cTemp, "{%d, g_touchscreen_large_font_data_array},", font_engine->m_font_family[i].nTotalFonts);
                break;
            }
        }     
        fputs(cTemp, pFile);
    }
    fputs(("\n};"),pFile);    
         
}

/*****************************************************************************
 * FUNCTION
 *  GenerateCompressionInfo
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool FontGenFile::GenerateCompressionInfo(FontEngine *font_engine, FILE *pFile)
{
    FILE *compress_info_file = NULL;
    char	temp[100] = {0};
    
    if(IsUseFontCompression())
    {
        if(compress_info_file = fopen(string(font_engine->m_outputPath + "\\" +  FONT_COMPRESSION_INFO_NAME).c_str(), ("r")))
        {
            fprintf(pFile,_T("\n\n#if defined(__MMI_FONT_COMPRESSION__)"));
            fputs(_T("\nconst mmi_font_compress_info mtk_font_compress_info[] = {"),pFile);
            while ( fgets(temp, 100, compress_info_file ) != NULL)
            {
               fprintf(pFile,_T("%s"), temp);  
            }
            fprintf(pFile,_T("\n  {NULL, 0, NULL, 0}\n")); 
            fprintf(pFile, _T("};\n"));
            fprintf(pFile,_T("\n#endif\n"));
            fclose(compress_info_file);
            return true;
        } 
    }
    return false;
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontDataFile
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool FontGenFile::GenerateFontDataFile(sMCTCustFontData *font_data)
{
    U32 iCount = 0;  
    FILE*		pFile = NULL;
    FILE* 		pFile_data = NULL;
    if((font_data == NULL))
    {
        return false;
    }
    if(pFile = fopen(string(m_outputPath + "\\" + font_data->gen_hfile_name).c_str(), ("w")))
    {
        
        if(IsUseFontCompression())
        {
            fprintf(pFile,_T("\n#if defined(__MMI_FONT_COMPRESSION__)\n"));

            if((font_data->nEquiDistant) == false)
            {                                
                /* font data width array */
                fprintf(pFile, _T("\nconst U8 %s[%ld]= {"),font_data->fontWidthName, font_data->m_nTotalChars);
                for( iCount = 0 ; iCount < font_data->m_nTotalChars; iCount++)
                { 
                    if (iCount%16 == 0)
                    {
                        fprintf(pFile, _T("\n"));
                    }    
                    fprintf(pFile, _T("0x%-2X,"), font_data->pWidthArray[iCount]);        
                }
                fprintf(pFile,_T("};\n"));
                
                /* font data Dwidth array */
                if(font_data->is_dwidth)
                {
                    fprintf(pFile, ("\nconst U8 %s[%ld]= {"), font_data->fontDWidthName,font_data->m_nTotalChars);
                    for( iCount = 0 ; iCount < font_data->m_nTotalChars; iCount++)
                    {
                        if (iCount%16 == 0)
                        {
                            fprintf(pFile, _T("\n"));               
                        }                    
                        fprintf(pFile, _T("0x%-2X,"), font_data->pDWidthArray[iCount]);        
                    }
                    fprintf(pFile,_T("};\n"));
                }

                /* font data index array (offset)  */
                fprintf(pFile, _T("\nconst U8 %s[%ld]= {"),font_data->fontOffsetName, font_data->m_nTotalChars + 1);
                for( iCount = 0 ; iCount < font_data->m_nTotalChars + 1; iCount++)
                {
                    if (iCount%16 == 0)
                    {
                       fprintf(pFile,_T("\n"));   
                    }  
                    
                    /* Split to several block per 64k, so adjust value data offset table.  */
                    char a[10];
                    int index_value = font_data->pOffsetArray[iCount];
                    index_value = index_value % FONT_ENGINE_DATA_BLOCK_SIZE;  
                    sprintf(a,_T("0x%02X,"), index_value);

                    fprintf(pFile, a);
                }
                fprintf(pFile,_T("};\n"));
                
            }

            /* range offset */
            fprintf(pFile, _T("\nconst U16 %s[%ld]= {"),
                                font_data->pRangeDetails->rangeOffsetName, 
                                font_data->pRangeDetails->nNoOfRanges);
             
            U32 tempvalue;
            for( iCount = 0 ; iCount < font_data->pRangeDetails->nNoOfRanges; iCount++)
            {
                if (iCount%16 == 0)
                {
                    fprintf(pFile, _T("\n"));     
                }                            
                char a[10];
                tempvalue = font_data->pRange[iCount];      
                sprintf(a,_T("%ld,"),  tempvalue);
                fprintf(pFile, a);
            }
            fprintf(pFile,_T("};\n"));  


            /* Font Data */           
            fprintf(pFile,_T("\nconst U8  %s[%ld]= {"), 
                font_data->fontCompressedDataName,
                font_data->nDataArrayCompressionSize);
            for( iCount = 0 ; iCount < font_data->nDataArrayCompressionSize; iCount++)
            {
                if (iCount%16 == 0)
                {
                    fprintf(pFile, ("\n"));  
                }
                fprintf(pFile, ("0x%X,"), font_data->pDataArrayCompression[iCount]);
            }
            fprintf(pFile, ("};\n"));

            fprintf(pFile,_T("\n#if !defined(__MMI_BDF_SW_COMPRESSION__) \n"));
            
            /* RangeBlockIndex */
            if(font_data->nEquiDistant == false)
            { 
                
                fprintf(pFile,_T("\nconst U16 %s[%ld]= {"),
                    font_data->pRangeDetails->fontRangeBlockIndexArrayName,
                    font_data->nBlockIndexArrayCompressionSize+1);
                //{264},       // <= how many character are involved in the block and its previous block
                for(iCount=0; iCount<= font_data->nBlockIndexArrayCompressionSize; iCount++)
                {
                    if(iCount%16 ==0)
                    {
                        fprintf(pFile, _T("\n")); 
                    }
                    fprintf(pFile, _T("%ld,"), font_data->pBlockIndexArrayCompression[iCount]);
                }
                fprintf(pFile,_T("\n};\n"));
            }
            
            /* mmi font range offset struct */
            fprintf(pFile, _T("\nconst mmi_font_range_offset_struct %s = {"),  
                  font_data->pRangeDetails->fontRangeOffsetStructName);
            
            
            if(font_data->nEquiDistant== false)
            {
                //1,           // <= how many block that the data is devided into blocks with size 64KB
                int block_number = font_data->nDataArraySize;
                if(block_number % FONT_ENGINE_DATA_BLOCK_SIZE)  
                {
                    block_number = block_number / FONT_ENGINE_DATA_BLOCK_SIZE + 1;                                    
                }
                else
                {
                    block_number = block_number / FONT_ENGINE_DATA_BLOCK_SIZE;
                }
                fprintf(pFile,_T("\n%d,\n"), block_number); 
                //2
                fprintf(pFile, _T("%s,\n"),font_data->pRangeDetails->fontRangeBlockIndexArrayName);    
            }
            else
            {
                fprintf(pFile,_T("\n0,\n"));
                fprintf(pFile,_T("NULL,\n"));
            }
            
            //3
            fprintf(pFile, _T("%s,\n"),font_data->pRangeDetails->rangeOffsetName);   
            fprintf(pFile,_T("};\n"));

            fprintf(pFile,_T("\n#endif  /* endif of  !defined(__MMI_BDF_SW_COMPRESSION__ */\n"));
            
            //empty array
            fprintf(pFile,_T("\nU8  %s[%ld];"), 
                font_data->fontDataName,
                font_data->nDataArraySize);  
           

            fprintf(pFile,_T("\n#else\n"));

        }

        /* uncompression data */

        if((font_data->nEquiDistant) == false)
        {                                
            /* font data width array */
            fprintf(pFile, _T("\nconst U8 %s[%ld]= {"),font_data->fontWidthName, font_data->m_nTotalChars);
            for( iCount = 0 ; iCount < font_data->m_nTotalChars; iCount++)
            { 
                if (iCount%16 == 0)
                {
                    fprintf(pFile, _T("\n"));
                }    
                fprintf(pFile, _T("0x%-2X,"), font_data->pWidthArray[iCount]);        
            }
            fprintf(pFile,_T("};\n"));
            
            /* font data Dwidth array */
            if(font_data->is_dwidth)
            {
                fprintf(pFile, ("\nconst U8 %s[%ld]= {"), font_data->fontDWidthName,font_data->m_nTotalChars);
                for( iCount = 0 ; iCount < font_data->m_nTotalChars; iCount++)
                {
                    if (iCount%16 == 0)
                    {
                        fprintf(pFile, _T("\n"));               
                    }                    
                    fprintf(pFile, _T("0x%-2X,"), font_data->pDWidthArray[iCount]);        
                }
                fprintf(pFile,_T("};\n"));
            }

        }

        /* If hardware compress, Data offset is necessary. */
        if(IsUseHWFontCompression())
        {
            /* font data index array (offset)  */
            fprintf(pFile,_T("\n#if defined(__MMI_BDF_SW_COMPRESSION__)\n"));
            
            fprintf(pFile, _T("\nconst U8 %s[%ld]= {"),font_data->fontOffsetName, font_data->m_nTotalChars + 1);
            for( iCount = 0 ; iCount < font_data->m_nTotalChars + 1; iCount++)
            {
                if (iCount%16 == 0)
                {
                   fprintf(pFile,_T("\n"));   
                }  
                
                /* Split to several block per 64k, so adjust value data offset table.  */
                char a[10];
                int index_value = font_data->pOffsetArray[iCount];
                index_value = index_value % FONT_ENGINE_DATA_BLOCK_SIZE;  
                sprintf(a,_T("0x%02X,"), index_value);

                fprintf(pFile, a);
            }
            fprintf(pFile,_T("};\n"));
            fprintf(pFile, "\n#endif\n");
        }
        else if(font_data->nEquiDistant == false)
        {
            /* font data index array (offset)  */
            fprintf(pFile, _T("\nconst U32 %s[%ld]= {"), font_data->fontOffsetName,  font_data->m_nTotalChars + 1);
            for( iCount = 0 ; iCount < font_data->m_nTotalChars+1; iCount++)
            {
                if (iCount%16 == 0)
                {
                    fprintf(pFile,_T("\n"));    
                }                             
                char a[10];
                sprintf(a, _T("0x%04X,"),  font_data->pOffsetArray[iCount]);
                fprintf(pFile, a);
            }
            fprintf(pFile,_T("};\n"));    
        }

        /* RangeOffset */
        fprintf(pFile, _T("\nconst U16 %s[%ld]= {"),
                            font_data->pRangeDetails->rangeOffsetName, 
                            font_data->pRangeDetails->nNoOfRanges);
        
        for( iCount = 0 ; iCount < font_data->pRangeDetails->nNoOfRanges; iCount++)
        {
            if (iCount%16 == 0)
            {
                fprintf(pFile, _T("\n"));  
            }
                                               
            char a[10];
            sprintf(a,_T("%ld,"),  font_data->pRange[iCount]);
            fprintf(pFile, a);
        }                
        fprintf(pFile,_T("};\n"));

        /* Font data */
		pFile_data = fopen(string(m_outputPath + ("\\") + FONT_DATA_FILENAME).c_str(), ("a"));
		if(IsUseFontGroupCompression())
		{
			fprintf(pFile,("\nextern const U8 %s[];\n"), font_data->fontDataName);
			if(pFile_data)
			{
				fprintf(pFile_data,("\nconst unsigned char %s[%ld]= {"), font_data->fontDataName,font_data->nDataArraySize);
		        for( iCount = 0 ; iCount < font_data->nDataArraySize; iCount++)
		        {
		            if (iCount%16 == 0)
		            {
		                fprintf(pFile_data, ("\n"));  
		            }
		            fprintf(pFile_data, _T("0x%X,"), font_data->pDataArray[iCount]);
		        }
		        fprintf(pFile_data, ("};\n"));
			}
		}
		else
		{
        fprintf(pFile,("\nconst U8  %s[%ld]= {"), font_data->fontDataName,font_data->nDataArraySize);
        for( iCount = 0 ; iCount < font_data->nDataArraySize; iCount++)
        {
            if (iCount%16 == 0)
            {
                fprintf(pFile, ("\n"));  
            }
            fprintf(pFile, _T("0x%X,"), font_data->pDataArray[iCount]);
        }
        fprintf(pFile, ("};\n"));   
		}
		if(pFile_data)
			fclose(pFile_data);

        if(IsUseFontCompression())
        {
             fprintf(pFile, "\n#endif\n");
        }

        if((IsUseFontCompression()) && (IsUseHWFontCompression()) && (font_data->nEquiDistant == true))
        {
            /* font data index array (offset)  */
            fprintf(pFile,_T("\n#if defined(__MMI_BDF_SW_COMPRESSION__)\n"));
            
            fprintf(pFile, _T("\nconst U8 %s[%ld]= {"),font_data->fontOffsetName, font_data->m_nTotalChars + 1);
            for( iCount = 0 ; iCount < font_data->m_nTotalChars + 1; iCount++)
            {
                if (iCount%16 == 0)
                {
                   fprintf(pFile,_T("\n"));   
                }  
                
                /* Split to several block per 64k, so adjust value data offset table.  */
                char a[10];
                int index_value = font_data->pOffsetArray[iCount];
                index_value = index_value % FONT_ENGINE_DATA_BLOCK_SIZE;  
                sprintf(a,_T("0x%02X,"), index_value);

                fprintf(pFile, a);
            }
            fprintf(pFile,_T("};\n"));
            fprintf(pFile, "\n#endif\n");
        }
        
        if(IsUseHWFontCompression())
        {
            fprintf(pFile,_T("\n#if defined(__MMI_BDF_SW_COMPRESSION__) \n"));
             /* RangeBlockIndex */
            fprintf(pFile,_T("\nconst U16 %s[%ld]= {"),
                font_data->pRangeDetails->fontRangeBlockIndexArrayName,
                font_data->nBlockIndexArrayCompressionSize+1);
            
            for(iCount=0; iCount<= font_data->nBlockIndexArrayCompressionSize; iCount++)
            {
                if(iCount%16 ==0)
                {
                    fprintf(pFile, _T("\n")); 
                }
                fprintf(pFile, _T("%ld,"), font_data->pBlockIndexArrayCompression[iCount]);
            }
            fprintf(pFile,_T("\n};\n"));
            
            /* compression range offset & block struct  */
            fprintf(pFile, _T("\nconst mmi_font_range_offset_struct %s = {"),  
                  font_data->pRangeDetails->fontRangeOffsetStructName);
           
            int block_number;

	    if(IsUseFontGroupCompression())
		block_number = font_data->nDataArrayCompressionSize;
	    else
		block_number = font_data->nDataArraySize;
			
            if(block_number % FONT_ENGINE_DATA_BLOCK_SIZE)  
            {
                block_number = block_number / FONT_ENGINE_DATA_BLOCK_SIZE + 1;                                    
            }
            else
            {
                block_number = block_number / FONT_ENGINE_DATA_BLOCK_SIZE;
            }
            fprintf(pFile,_T("\n%d,\n"), block_number); 
            //2
            fprintf(pFile, _T("%s,\n"),font_data->pRangeDetails->fontRangeBlockIndexArrayName);    

            fprintf(pFile, _T("%s,\n"),font_data->pRangeDetails->rangeOffsetName);   
            fprintf(pFile,_T("};\n"));

            fprintf(pFile, "#endif\n");  
        }
       
        /* Range Data and Range Details */
        GenerateFontResFile_RangeInfo(font_data, pFile);
        if(IsUseFontGroupCompression())
            GenerateFontResFile_GroupInfo(font_data, pFile);

        /* sCustFontData */
        if(IsUseFontCompression())
        {
            fprintf(pFile,_T("\n#if (defined(__MMI_FONT_COMPRESSION__) && !defined(__MMI_BDF_SW_COMPRESSION__)) \n"));
              
            GenerateFontResFile_CustFontData(font_data, pFile, 1);

            fprintf(pFile,_T("\n#else\n"));
        } 

        if(IsUseHWFontCompression())
        {
            GenerateFontResFile_CustFontData(font_data, pFile, 2);  
        }
        else
        {
            GenerateFontResFile_CustFontData(font_data, pFile, 0);  
        }
                            

        if(IsUseFontCompression())
        { 
            fprintf(pFile,_T("\n#endif\n"));
        } 
        
        /* Generate temp file for compression info file */
        if(IsUseFontCompression())
        {
            GenerateCompressionInfoFile(font_data);
        } 
        fclose(pFile); 
        return true;
    }
    return false;     
}


void FontGenFile::GenerateFontResFile_RangeInfo(sMCTCustFontData *font_data, FILE *p_file)
{
    /* Range data */
    fprintf(p_file, ("\nconst RangeData %s[%ld]={\n"), 
            font_data->pRangeDetails->rangeDataName, 
            font_data->pRangeDetails->nNoOfRanges);
        
    for(int k = 0; k < font_data->pRangeDetails->nNoOfRanges; k++ )
    {
        if(k%10==0 && k!=0)
        {
            fputs(_T("\n"), p_file);
        }
        fprintf(p_file,
            "{%ld,%ld},",
            font_data->pRangeDetails->pRangeData[k].nMin,
            font_data->pRangeDetails->pRangeData[k].nMax);
        
    }
    
    fputs(_T("};\n"),p_file);

    /* Range details */
    fprintf(p_file, _T("\nconst RangeDetails %s={\n%ld,\n%s\n};\n"), 
        font_data->pRangeDetails->rangeInfoName, 
        font_data->pRangeDetails->nNoOfRanges, 
        font_data->pRangeDetails->rangeDataName);
     
}


void FontGenFile::GenerateFontResFile_CustFontData(sMCTCustFontData *font_data, FILE *p_file, U8 compress_flag)
{

    /*  CustFontData  */
    fprintf(p_file, _T("\nconst sCustFontData %s = {\n"), font_data->name);
    
    /*  PLUTO_MMI  */
    fprintf(p_file, _T("%ld, %ld,\n#ifdef PLUTO_MMI\n%ld, %ld,\n#endif \n%ld, %ld, %ld,"),
        font_data->nHeight, font_data->nBoxMaxWidth,
        font_data->nAscent, font_data->nDescent,        //Ascent and Descent for baseline
        font_data->nEquiDistant, font_data->nCharBytes, font_data->nMaxChars);
    
    /*  PLUTO_MMI  */
    if(font_data->nEquiDistant == false)
    {
        if(font_data->is_dwidth)
        {
            fprintf(p_file, _T("\n(U8*)%s"), font_data->fontDWidthName);
        }
        else
        {
            fprintf(p_file, _T("\n(U8*)%s"), font_data->fontWidthName);
        }

        if(compress_flag)
        {
            fprintf(p_file, _T(", (U8*)%s, (U8*)%s, (U8*)%s, (mmi_font_range_offset_struct*)&%s,"), 
                font_data->fontWidthName, font_data->fontOffsetName, 
                font_data->fontDataName,  font_data->pRangeDetails->fontRangeOffsetStructName);
        }
        else
        {
            fprintf(p_file, _T(", (U8*)%s, (U32*)%s, (U8*)%s, (U16*)%s,"), 
                font_data->fontWidthName, font_data->fontOffsetName, 
                font_data->fontDataName,  font_data->pRangeDetails->rangeOffsetName);   
        }     
    }       
    else
    {
        if(compress_flag == 1)
        {
            fprintf(p_file, _T("\n(U8*)NULL, (U8*)NULL, (U8*)NULL, (U8*)%s, (mmi_font_range_offset_struct*)&%s,"),
                font_data->fontDataName, font_data->pRangeDetails->fontRangeOffsetStructName);
        }
        else if(compress_flag == 2)
        {
            /* Should add compile option. */
            fprintf(p_file, _T("\n(U8*)NULL, (U8*)NULL, (U8*)%s, (U8*)%s, (mmi_font_range_offset_struct*)&%s,"),
                font_data->fontOffsetName,
                font_data->fontDataName, font_data->pRangeDetails->fontRangeOffsetStructName);
        }
        else 
        {
            fprintf(p_file, _T("\n(U8*)NULL, (U8*)NULL, (U32*)NULL, (U8*)%s, (U16*)%s,"),
                font_data->fontDataName, font_data->pRangeDetails->rangeOffsetName);  
        }
    }    
    fprintf(p_file, ("\n&%s,"), font_data->pRangeDetails->rangeInfoName);
    
    if(IsUseFontGroupCompression())
        fprintf(p_file, ("\n&%s,"), font_data->pRangeDetails->groupInfoName);
    
    MapLanguageWithFontDataFile(font_data, p_file); 

    fprintf(p_file, "\n};\n\n");


}

void FontGenFile::GenerateFontResFile_GroupInfo(sMCTCustFontData *font_data, FILE *p_file)
{
    /* Range data */
    fprintf(p_file, ("\nconst GroupData %s[%ld]={\n"), 
            font_data->pRangeDetails->groupDataName, 
            font_data->pRangeDetails->nNoOfGroup);
        
    for(int k = 0; k < font_data->pRangeDetails->nNoOfGroup; k++ )
    {
        if(k%10==0 && k!=0)
        {
            fputs(_T("\n"), p_file);
        }
        fprintf(p_file,
            "{%ld,%ld},",
            font_data->pRangeDetails->pGroupData[k].nOffset,
            font_data->pRangeDetails->pGroupData[k].nSize);
        
    }
    
    fputs(_T("};\n"),p_file);

    /* Range details */
    fprintf(p_file, _T("\nconst GroupDetails %s={\n%ld,\n%s\n};\n"), 
        font_data->pRangeDetails->groupInfoName, 
        font_data->pRangeDetails->nNoOfGroup, 
        font_data->pRangeDetails->groupDataName);
     
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontDataFile
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool FontGenFile::GenerateCompressionInfoFile(sMCTCustFontData *font_data)
{
    U32 iCount = 0;  
    FILE*		pFile = NULL;
    if((font_data == NULL))
    {
        return false;
    }
    if(IsUseFontCompression())
    {
        if(pFile = fopen(string(m_outputPath + "\\" + FONT_COMPRESSION_INFO_NAME).c_str(), ("a+")))       
        {
            fprintf(pFile, _T("\n {%s, %d,%s, %d}, "),
                font_data->fontDataName,
                font_data->nDataArraySize,
                font_data->fontCompressedDataName,
                font_data->nDataArrayCompressionSize); 
            fclose(pFile);
            return true;           
        }      
    }
    return false;
}


/*****************************************************************************
 * FUNCTION
 *  MapLanguageWithFontDataFile
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool FontGenFile::MapLanguageWithFontDataFile(sMCTCustFontData *font_data, FILE *p_file)
{
    fprintf(p_file, ("\n0X%08X,"), font_data->Language_flags);
    return true;
}


/*****************************************************************************
 * FUNCTION
 *  GenerateFontResLanguageTable
 * DESCRIPTION
 *  
 * PARAMETERS
 *  outputPath [IN]
 * RETURNS
 *  
******************************************************************************/
bool FontGenFile::GenerateFontResLanguageTable(string *readfile_path, FILE *pFile)
{
    FILE *read_file = NULL;
    char temp[FONT_LINE_CHAR] = {0};
    
    if(read_file = fopen(string(FONT_LANGUAGE_TABLE_FILENAME).c_str(), ("r")))       
    {
        printf("[Dependency] %s\n", string(FONT_LANGUAGE_TABLE_FILENAME).c_str());
        while (fgets(temp, FONT_LINE_CHAR, read_file) != NULL)
        {
            fprintf(pFile, temp);
        }
        fclose(read_file);
        return true;           
    }    
    return false;
}