Exemplo n.º 1
0
unsigned delete_freetype_font(void* font_info)
{
    unsigned error = 0;
    FT_Face* faces = reinterpret_cast<FT_Face*>(font_info);
    unsigned long face_num = faces[0]->num_faces;

    for (unsigned i = 0; i < face_num; i++)
    {
        error = FT_Done_Face(faces[i]);
        if(error)return error;
    }

    free(font_info);

	if (s_freetype)
	{
		error = FT_Done_Library(s_freetype);
		s_freetype = NULL;
	}
	if(m_stroker){
		FT_Stroker_Done( m_stroker );
		m_stroker=NULL;
	}
    return error;
}
Exemplo n.º 2
0
    FT_Done_FreeType_2(FT_Library  library)
    {
        if(library)
        {
            FT_Memory  memory = library->memory;
            FT_Done_Library(library);
            memory->free(memory, memory);
        }

        return FT_Err_Ok;
    }
bool fsLowLevelAPI::destroyFreeType()
{
    if (FT_Done_Library(s_freetype))
    {
        return false;
    }

    fsFree(s_memory);

    return true;
}
Exemplo n.º 4
0
/* close down and dispose of GlyphEngine */
void FreeGE(FT_GlyphEngine *ge)
{
    if(ge==NULL) return;
    
    if(ge->face_established)
	FT_Done_Face( ge->face );

    FT_Done_Library( ge->engine );

    FreeVec(ge);
}
Exemplo n.º 5
0
bool freetype_engine::register_fonts(std::string const& dir, bool recurse)
{
#ifdef MAPNIK_THREADSAFE
    mapnik::scoped_lock lock(mutex_);
#endif
    std::unique_ptr<FT_MemoryRec_> memory(new FT_MemoryRec_);
    FT_Library library = 0;
    init_freetype(&*memory, library);
    bool result = register_fonts_impl(dir, library, recurse);
    FT_Done_Library(library);
    return result;
}
Exemplo n.º 6
0
FT_Done_FreeType( FT_Library  library )
{
    if ( library )
    {
        FT_Memory  memory = library->memory;


        /* Discard the library object */
        FT_Done_Library( library );

        /* discard memory manager */
        FT_Done_Memory( memory );
    }

    return FT_Err_Ok;
}
Exemplo n.º 7
0
  FT_Done_FreeType( FT_Library  library )
  {
    FT_Memory  memory;


    if ( !library )
      return FT_THROW( Invalid_Library_Handle );

    memory = library->memory;

    /* Discard the library object */
    FT_Done_Library( library );

    /* discard memory manager */
    FT_Done_Memory( memory );

    return FT_Err_Ok;
  }
Exemplo n.º 8
0
font_library::~font_library()
{
    FT_Done_Library(library_);
}
Exemplo n.º 9
0
freetype_engine::~freetype_engine()
{
    FT_Done_Library(library_);
}
Exemplo n.º 10
0
/**
 * Main.
 */
int main(int argc, char* argv[]) {
    FT_Error error;
    std::string fTtf;
    std::string fLff;

    // init:
    fpLff = NULL;
    nodes = 4;
    std::string name = "Unknown";
    double letterSpacing = 3.0;
    double wordSpacing = 6.75;
    double lineSpacingFactor = 1.0;
    std::string author = "Unknown";
    std::string license = "Unknown";
    precision = 6;
    int i;
    int ret;
    library = NULL;
    face = NULL;

    // handle arguments:
    if (argc < 3) {
        usage(1);
        /* NOTREACHED */
    }

    for (i=1; i<argc; ++i) {
        if (!strcmp(argv[i], "-n")) {
            ++i;
            nodes = atoi(argv[i]);
        }
        else if (!strcmp(argv[i], "-a")) {
            ++i;
            author = argv[i];
        }
        else if (!strcmp(argv[i], "-l")) {
            ++i;
            letterSpacing = atof(argv[i]);
        }
        else if (!strcmp(argv[i], "-w")) {
            ++i;
            wordSpacing = atof(argv[i]);
        }
        else if (!strcmp(argv[i], "-d")) {
            ++i;
            precision = atoi(argv[i]);
        }
        else if (!strcmp(argv[i], "-f")) {
            ++i;
            lineSpacingFactor = atof(argv[i]);
        }
        else if (!strcmp(argv[i], "-h")) {
            usage(0);
            /* NOTREACHED */
        }
        else if (!strcmp(argv[i], "-L")) {
            ++i;
            license = argv[i];
        }
        else {
            break;
        }
    }

    if((argc - i) != 2) {
        usage(1);
        /* NOTREACHED */
    }

    fTtf = argv[i++];
    fLff = argv[i];

    std::cout << "TTF file: " << fTtf.c_str() << "\n";
    std::cout << "LFF file: " << fLff.c_str() << "\n";

    ret = 0;

    // init freetype
    error = FT_Init_FreeType(&library);
    if (error) {
        std::cerr << "FT_Init_FreeType: " << FT_StrError(error) << std::endl;
        ret = 1;
    }
    else {
        // load ttf font
        error = FT_New_Face(library,
                            fTtf.c_str(),
                            0,
                            &face);
        if (error) {
            std::cerr << "FT_New_Face: " << fTtf << ": " << FT_StrError(error) << std::endl;
            ret = 1;
        }
        else {
            std::cout << "Family:    " << face->family_name << "\n";
            std::cout << "Height:    " << face->height << "\n";
            std::cout << "Ascender:  " << face->ascender << "\n";
            std::cout << "Descender: " << face->descender << "\n";
            name = face->family_name;

            // find out height by tracing 'A'
            yMax = -1000;
            convertGlyph(65);
            factor = 1.0/(1.0/9.0*yMax);

            std::cout << "Factor:    " << factor << "\n";

            // write font file:
            fpLff = fopen(fLff.c_str(), "wt");
            if (fpLff==NULL) {
                std::cerr << "Can not open " << fLff.c_str() << ": " << strerror(errno) << std::endl;
                ret = 2;
            }
            else {
                snprintf(numFormat,8,"%%.%if", precision);

                // write font header
                fprintf(fpLff, "# Format:            LibreCAD Font 1\n");
                fprintf(fpLff, "# Creator:           ttf2lff\n");
                fprintf(fpLff, "# Version:           1\n");
                fprintf(fpLff, "# Name:              %s\n", name.c_str());
                fprintf(fpLff, "# LetterSpacing:     %s\n", clearZeros(letterSpacing).c_str());
                fprintf(fpLff, "# WordSpacing:       %s\n", clearZeros(wordSpacing).c_str());
                fprintf(fpLff, "# LineSpacingFactor: %s\n", clearZeros(lineSpacingFactor).c_str());

                time_t rawtime;
                struct tm * timeinfo;
                char buffer [12];
                time ( &rawtime );
                timeinfo = localtime ( &rawtime );
                strftime (buffer,sizeof(buffer),"%Y-%m-%d",timeinfo);

                fprintf(fpLff, "# Created:           %s\n", buffer);
                fprintf(fpLff, "# Last modified:     %s\n", buffer);
                fprintf(fpLff, "# Author:            %s\n", author.c_str());
                fprintf(fpLff, "# License:           %s\n", license.c_str());
                fprintf(fpLff, "\n");

                unsigned first;
                FT_Get_First_Char(face, &first);

                FT_ULong  charcode;
                FT_UInt   gindex;

                // iterate through glyphs
                charcode = FT_Get_First_Char( face, &gindex );
                while (gindex != 0) {
                    convertGlyph(charcode);
                    charcode = FT_Get_Next_Char(face, charcode, &gindex);
                }
            }
        }
    }

    if (face) {
        FT_Done_Face(face);
    }
    if (library) {
        FT_Done_Library(library);
    }

    return ret;
}