Ejemplo n.º 1
0
	//---------
	ofTrueTypeFont & Register::getFont(string name, int size) {
		pair<string, int> id = pair<string, int>(name, size);
		if (this->fonts.count(id) > 0) {
			return this->fonts[id];
		} else if (this->fontFilenames.count(name) > 0) {
			this->fonts.insert(pair<pair<string,int>,ofTrueTypeFont>(id, ofTrueTypeFont()));
			this->fonts[id].loadFont(this->fontFilenames[name], size);
			ofLogNotice("ofxAssets") << "Loaded font asset '" << name << "' (" << size << ")" << endl;
			return this->fonts[id];
		} else {
			ofLogError("ofxAssets") << "Requested font asset'" << name << "' doesn't exist, have you got all the files in the right place in your data/assets/ folder?";
			return this->blankFont;
		}
	}
Ejemplo n.º 2
0
	//---------
	ofTrueTypeFont & Register::getFont(string name, int size) {
		if (!this->initialised) {
			this->loadAssets();
		}
		pair<string, int> id = pair<string, int>(name, size);
		auto findFont = this->fonts.find(id);
		if (findFont != this->fonts.end()) {
			return findFont->second;
		} else if (this->fontFilenames.find(name) != this->fontFilenames.end()) {
			this->fonts.insert(pair<pair<string,int>,ofTrueTypeFont>(id, ofTrueTypeFont()));
			ofTrueTypeFont & font = this->fonts[id];
			font.loadFont(this->fontFilenames[name], size, true, true, true);
			ofLogNotice("ofxAssets") << "Loaded font asset '" << name << "' (" << size << ")" << endl;
			return font;
		} else {
			ofLogError("ofxAssets") << "Requested font asset'" << name << "' doesn't exist, have you got all the files in the right place in your data/assets/ folder?";
			return this->blankFont;
		}
	}
Ejemplo n.º 3
0
void ofxFontAsset::initialise()
{
    if (initialised)
        return;
    
    initialised = true;
    
    ofxDirList dir;
    
    dir.allowExt("ttf");
    dir.setVerbose(false);
    
    int nFiles = dir.listDir("fonts/");
    
    string filename;
    string sizesFilePath;
    string name;
    
    vector<int>     sizes;
    int currentSize;
    
    for (int i=0; i < nFiles; i++)
    {
        //get filename/name without 3 char extension
        filename = dir.getName(i);
        name = filename.substr(0, filename.length()-4);
        
        //get absolute filename of sizes file
        sizesFilePath = dir.getPath(i);
        sizesFilePath = sizesFilePath.substr(0, sizesFilePath.length()-3) + "txt";

        ////////////////////////
        //try to read sizes file
        sizes.clear();
        try {
            ifstream file;
            file.open(sizesFilePath.c_str());
            
            while (file >> currentSize)
                sizes.push_back(currentSize); 
            
        } catch (...) {
        
        }
        
        if (sizes.size() == 0)
            sizes.push_back(10);
        ////////////////////////
        
        //we didn't throw, so let's        
        //load font/sizes
        
        //if name is 'default' then we have special
        //case of supporting only 1 text size
        if (name == "default")
        {
            dictionary["default"] = ofTrueTypeFont();
            dictionary["default"].loadFont("fonts/" + filename, sizes[0]);
        }
        
        //otherwise we add all text sizes
        //as fonts name with size, e.g.:
        //  "Helvetica_10"
        
        vector<int>::iterator it;
        string compoundName;
        //
        for (it = sizes.begin(); it != sizes.end(); it++)
        {
            compoundName = name + "_" + ofToString(*it);
            
            dictionary[compoundName] = ofTrueTypeFont();
            dictionary[compoundName].loadFont("fonts/" + filename, *it);
        }

    }
    
    //let's output what assets we have
    cout << "////////////////////////\n";
    cout << "//FONTS LOADED\n";
    cout << "////////////////////////\n";
    cout << "//\n";
    
    map<string, ofTrueTypeFont>::iterator it;
    for (it = dictionary.begin(); it != dictionary.end(); it++)
        cout << it->first << "\n";
    
    cout << "////////////////////////\n";
    
}
Ejemplo n.º 4
0
//
//  ofxFontAsset.cpp
//  ofxImageAsset
//
//  Created by Elliot Woods on 12/02/2011.
//  Copyright 2011 Kimchi and Chips. All rights reserved.
//

#include "ofxFontAsset.h"

bool ofxFontAsset::initialised = false;

map<string, ofTrueTypeFont> ofxFontAsset::dictionary = map<string, ofTrueTypeFont>();
ofTrueTypeFont ofxFontAsset::blank = ofTrueTypeFont();

ofxFontAsset::ofxFontAsset()
{
    initialise();
}

ofTrueTypeFont& ofxFontAsset::getFont(string assetName)
{
    initialise();
    
    if (dictionary.count(assetName) != 0)
        return dictionary[assetName];
    else
    {
        if (assetName=="default")
            return blank;
        else