Example #1
0
/**
 * \brief Load fonts from the specified folder for the UI to use.
 * This should only be used if Cairo is used on Windows, which defaults to the
 * Win32 font backend.
 * This is an ANSI version, so files which contain characters outside of the
 * user's locale will fail to be loaded.
 * \param prefix The folder to read fonts from. Currently the pixmaps folder
 *               and the folder 'ui-fonts' in the FontForge preferences folder.
 */
static void WinLoadUserFonts(const char *prefix) {
    HANDLE fileHandle;
    WIN32_FIND_DATA fileData;
    char path[MAX_PATH], *ext;
    HRESULT ret;
    int i;

    if (prefix == NULL) {
        return;
    }
    ret = snprintf(path, MAX_PATH, "%s/*.???", prefix);
    if (ret <= 0 || ret >= MAX_PATH) {
        return;
    }

    fileHandle = FindFirstFileA(path, &fileData);
    if (fileHandle != INVALID_HANDLE_VALUE) do {
        ext = strrchr(fileData.cFileName, '.');
        if (!ext || (strcasecmp(ext, ".ttf") && strcasecmp(ext, ".ttc") &&
                     strcasecmp(ext,".otf")))
        {
            continue;
        }
        ret = snprintf(path, MAX_PATH, "%s/%s", prefix, fileData.cFileName);
        if (ret > 0 && ret < MAX_PATH) {
            //printf("WIN32-FONT-TEST: %s\n", path);
            ret = AddFontResourceExA(path, FR_PRIVATE, NULL);
            //if (ret > 0) {
            //    printf("\tLOADED FONT OK!\n");
            //}
        }
    } while (FindNextFileA(fileHandle, &fileData) != 0);
}
Example #2
0
HFONT WINAPI CreateFontFromFileA(int cHeight, int cWidth, int cEscapement, int cOrientation, int cWeight, DWORD bItalic, DWORD bUnderline, DWORD bStrikeOut, DWORD iCharSet, DWORD iOutPrecision, DWORD iClipPrecision, DWORD iQuality, DWORD iPitchAndFamily, LPCSTR lpszFontName, LPCTSTR lpszFontRes)
{
    HFONT hFont;

    if (AddFontResourceExA(lpszFontName, FR_PRIVATE, 0) == 0)
        return NULL;

    hFont = CreateFontA(cHeight, cWidth, cEscapement, cOrientation, cWeight, bItalic, bUnderline, bStrikeOut, iCharSet, iOutPrecision, iClipPrecision, iQuality, iPitchAndFamily, lpszFontRes);
    if (hFont == NULL)
    {
        RemoveFontResourceExA(lpszFontName, FR_PRIVATE, 0);
    }

    return hFont;
}
Example #3
0
// TD-2013-07-01 [[ DynamicFonts ]]
bool MCScreenDC::loadfont(const char *p_path, bool p_globally, void*& r_loaded_font_handle)
{
	bool t_success = true;
    DWORD t_private = NULL;
    
    if (!p_globally)
        t_private = FR_PRIVATE;
    
	if (t_success)
		t_success = (MCS_exists(p_path, True) == True);
	
	if (t_success)
		t_success = (AddFontResourceExA(p_path, t_private, 0) != 0);
    
	if (t_success && p_globally)
		PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
    
	return t_success;
}
Example #4
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    std::string typeface;
    char * typeface_c = 0;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()){
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.", NULL, 0);
        fontheight = 16;
        fontwidth  = 8;
    } else {
        getline(fin, typeface);
        typeface_c = new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)){
            MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0);
            fontheight = 16;
            fontwidth  = 8;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth;
    WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectory("data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFile(".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExA(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectory("..\\..");
    }

    // Use desired font, if possible
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Example #5
0
//Basic Init, create the font, backbuffer, etc
WINDOW *initscr(void)
{
    _windows = new WINDOW[20];         //initialize all of our variables
    BITMAPINFO bmi;
    lastchar=-1;
    inputdelay=-1;
    std::string typeface;
    char * typeface_c;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()) {
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.",
                   NULL, NULL);
        fontheight=16;
        fontwidth=8;
    } else {
        getline(fin, typeface);
        typeface_c= new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)) {
            MessageBox(WindowHandle, "Invalid font size specified!",
                       NULL, NULL);
            fontheight=16;
            fontwidth=8;
        }
    }
    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth=80*fontwidth;
    WindowHeight=25*fontheight;
    WindowX=(GetSystemMetrics(SM_CXSCREEN) / 2)-WindowWidth;    //center this
    WindowY=(GetSystemMetrics(SM_CYSCREEN) / 2)-WindowHeight;   //sucker
    WinCreate(TRUE);    //Create the actual window, register it, etc
    CheckMessages();    //Let the message queue handle setting up the window
    WindowDC = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = WindowWidth;
    bmi.bmiHeader.biHeight = -WindowHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount=8;
    bmi.bmiHeader.biCompression = BI_RGB;   //store it in uncompressed bytes
    bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed=16;         //the number of colors in our palette
    bmi.bmiHeader.biClrImportant=16;    //the number of colors in our palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
    if (nResults>0) {
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

    } else {
        MessageBox(WindowHandle, "Failed to load default font, using FixedSys.",
                   NULL, NULL);
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
    }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
    WindowCount=0;

    delete typeface_c;
    return newwin(25,80,0,0);   //create the 'stdscr' window and return its ref
};
Example #6
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    int fontsize = 16;
    std::string typeface;
    char * typeface_c;
    int map_fontwidth = 8;
    int map_fontheight = 16;
    int map_fontsize = 16;
    std::string map_typeface;
    bool fontblending;

    std::ifstream jsonstream(FILENAMES["fontdata"].c_str(), std::ifstream::binary);
    if (jsonstream.good()) {
        JsonIn json(jsonstream);
        JsonObject config = json.get_object();
        // fontsize, fontblending, map_* are ignored in wincurse.
        fontwidth = config.get_int("fontwidth", fontwidth);
        fontheight = config.get_int("fontheight", fontheight);
        typeface = config.get_string("typeface", typeface);
        jsonstream.close();
    } else { // User fontdata is missed. Try to load legacy fontdata.
        // Get and save all values. With unused.
        std::ifstream InStream(FILENAMES["legacy_fontdata"].c_str(), std::ifstream::binary);
        if(InStream.good()) {
            JsonIn jIn(InStream);
            JsonObject config = jIn.get_object();
            fontwidth = config.get_int("fontwidth", fontwidth);
            fontheight = config.get_int("fontheight", fontheight);
            fontsize = config.get_int("fontsize", fontsize);
            typeface = config.get_string("typeface", typeface);
            map_fontwidth = config.get_int("map_fontwidth", fontwidth);
            map_fontheight = config.get_int("map_fontheight", fontheight);
            map_fontsize = config.get_int("map_fontsize", fontsize);
            map_typeface = config.get_string("map_typeface", typeface);
            InStream.close();
            // Save legacy as user fontdata.
            assure_dir_exist(FILENAMES["config_dir"]);
            std::ofstream OutStream(FILENAMES["fontdata"].c_str(), std::ofstream::binary);
            if(!OutStream.good()) {
                DebugLog() << "Can't save user fontdata file.\n"
                << "Check permissions for: " << FILENAMES["fontdata"].c_str();
                return NULL;
            }
            JsonOut jOut(OutStream, true); // pretty-print
            jOut.start_object();
            jOut.member("fontblending", fontblending);
            jOut.member("fontwidth", fontwidth);
            jOut.member("fontheight", fontheight);
            jOut.member("fontsize", fontsize);
            jOut.member("typeface", typeface);
            jOut.member("map_fontwidth", map_fontwidth);
            jOut.member("map_fontheight", map_fontheight);
            jOut.member("map_fontsize", map_fontsize);
            jOut.member("map_typeface", map_typeface);
            jOut.end_object();
            OutStream << "\n";
            OutStream.close();
        } else {
            DebugLog() << "Can't load fontdata files.\n"
            << "Check permissions for:\n" << FILENAMES["legacy_fontdata"].c_str() << "\n"
            << FILENAMES["fontdata"].c_str() << "\n";
            return NULL;
        }
    }
    typeface_c = new char [typeface.size()+1];
    strncpy (typeface_c, typeface.c_str(), typeface.size());
    typeface_c[typeface.size()] = '\0';

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= OPTIONS["TERMINAL_X"] * fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectory("data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFile(".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExA(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectory("..\\..");
    }

    // Use desired font, if possible
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    init_colors();

    delete[] typeface_c;
    mainwin = newwin(OPTIONS["TERMINAL_Y"],OPTIONS["TERMINAL_X"],0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Example #7
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    std::string typeface;
    char * typeface_c;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()){
        MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.", NULL, 0);
        fontheight = 16;
        fontwidth  = 8;
    } else {
        getline(fin, typeface);
        typeface_c = new char [typeface.size()+1];
        strcpy (typeface_c, typeface.c_str());
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)){
            MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0);
            fontheight = 16;
            fontwidth  = 8;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth;
    WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = {0};
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
    if (nResults>0){
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                          ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                          PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

    } else {
        MessageBox(WindowHandle, "Failed to load default font, using FixedSys.", NULL, 0);
        font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
    }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}