Sample C++ Code

The sample C++ code on how to use the TTF and TTC class is as below.

#include <iostream>
#include "../TTFNameLibrary/TTF.h"
#include "../TTFNameLibrary/TTC.h"

#pragma comment(lib, "TTFNameLibrary.lib")

void main()
{
    TTF ttf;
    if( false == ttf.Parse(L"C:\\MyFont.ttf") )
    {
        std::wcout<<L"Font file cannot be parsed!"<<L"\r\n\r\n";
        return;
    }
    else
    {
        std::wcout<<L"FontName          : "<<ttf.GetFontName()          <<L"\r\n\r\n";
        std::wcout<<L"Copyright         : "<<ttf.GetCopyright()         <<L"\r\n\r\n";
        std::wcout<<L"FontFamilyName    : "<<ttf.GetFontFamilyName()    <<L"\r\n\r\n";
        std::wcout<<L"FontSubFamilyName : "<<ttf.GetFontSubFamilyName() <<L"\r\n\r\n";
        std::wcout<<L"FontID            : "<<ttf.GetFontID()            <<L"\r\n\r\n";
        std::wcout<<L"Version           : "<<ttf.GetVersion()           <<L"\r\n\r\n";
        std::wcout<<L"PostScriptName    : "<<ttf.GetPostScriptName()    <<L"\r\n\r\n";
        std::wcout<<L"Trademark         : "<<ttf.GetTrademark()         <<L"\r\n\r\n";
    }

    TTC ttc;
    if( false == ttc.Parse(L"C:\\MyFontC.ttc") )
    {
        std::wcout<<L"Font file cannot be parsed!"<<L"\r\n\r\n";
        return;
    }
    else
    {
        for(size_t i=0; i<ttc.Size(); ++i)
        {
            std::wcout<<L"FontName          : "<<ttc.GetFontName(i)          <<L"\r\n\r\n";
            std::wcout<<L"Copyright         : "<<ttc.GetCopyright(i)         <<L"\r\n\r\n";
            std::wcout<<L"FontFamilyName    : "<<ttc.GetFontFamilyName(i)    <<L"\r\n\r\n";
            std::wcout<<L"FontSubFamilyName : "<<ttc.GetFontSubFamilyName(i) <<L"\r\n\r\n";
            std::wcout<<L"FontID            : "<<ttc.GetFontID(i)            <<L"\r\n\r\n";
            std::wcout<<L"Version           : "<<ttc.GetVersion(i)           <<L"\r\n\r\n";
            std::wcout<<L"PostScriptName    : "<<ttc.GetPostScriptName(i)    <<L"\r\n\r\n";
            std::wcout<<L"Trademark         : "<<ttc.GetTrademark(i)         <<L"\r\n\r\n";

            if(i!=ttc.Size()-1)
                std::wcout<<L"==========================================="<<L"\r\n\r\n";
        }
    }
}

Last edited Jul 14, 2011 at 11:10 AM by shaovoon, version 7

Comments

No comments yet.