예제 #1
0
파일: ftmac.c 프로젝트: ImageMagick/ttf
  FT_New_Face_From_FSRef( FT_Library    library,
                          const FSRef*  ref,
                          FT_Long       face_index,
                          FT_Face*      aface )
  {
    FT_Error      error;
    FT_Open_Args  args;

    OSErr  err;
    UInt8  pathname[PATH_MAX];


    /* check of `library' and `aface' delayed to */
    /* `FT_New_Face_From_Resource'               */

    if ( !ref )
      return FT_THROW( Invalid_Argument );

    err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
    if ( err )
      error = FT_THROW( Cannot_Open_Resource );

    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
    if ( error || *aface )
      return error;

    /* fallback to datafork font */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );
  }
예제 #2
0
파일: ftmac.c 프로젝트: Joincheng/lithtech
  FT_EXPORT_DEF( FT_Error )  FT_New_Face( FT_Library   library,
                                          const char*  pathname,
                                          FT_Long      face_index,
                                          FT_Face     *aface )
  {
    FT_Open_Args  args;
    FSSpec        spec;
    OSType        file_type;


    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
    if ( !pathname )
      return FT_Err_Invalid_Argument;

    if ( file_spec_from_path( pathname, &spec ) )
      return FT_Err_Invalid_Argument;

    file_type = get_file_type( &spec );
    if ( file_type == 'FFIL' || file_type == 'tfil' )
      return FT_New_Face_From_Suitcase( library, &spec, face_index, aface );
    else if ( file_type == 'LWFN' )
      return FT_New_Face_From_LWFN( library, &spec, face_index, aface );
    else
    {
      args.flags    = ft_open_pathname;
      args.pathname = (char*)pathname;

      return FT_Open_Face( library, &args, face_index, aface );
    }
  }
예제 #3
0
파일: ftmac.c 프로젝트: 32767/libgdx
  FT_New_Face( FT_Library   library,
               const char*  pathname,
               FT_Long      face_index,
               FT_Face*     aface )
  {
    FT_Open_Args  args;
    FT_Error      error;


    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
    if ( !pathname )
      return FT_Err_Invalid_Argument;

    error  = FT_Err_Ok;
    *aface = NULL;

    /* try resourcefork based font: LWFN, FFIL */
    error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
                                       face_index, aface );
    if ( error != 0 || *aface != NULL )
      return error;

    /* let it fall through to normal loader (.ttf, .otf, etc.) */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );
  }
예제 #4
0
파일: ttf.cpp 프로젝트: Kenzu/solvespace
//-----------------------------------------------------------------------------
// Load a TrueType font into memory. We care about the curves that define
// the letter shapes, and about the mappings that determine which glyph goes
// with which character.
//-----------------------------------------------------------------------------
bool TtfFont::LoadFromFile(FT_Library fontLibrary, bool nameOnly) {
    FT_Open_Args args = {};
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = &fontFile[0]; // FT_String is char* for historical reasons

    // We don't use ssfopen() here to let freetype do its own memory management.
    // This is OK because on Linux/OS X we just delegate to fopen and on Windows
    // we only look into C:\Windows\Fonts, which has a known short path.
    if(int fterr = FT_Open_Face(fontLibrary, &args, 0, &fontFace)) {
        dbp("freetype: loading font from file '%s' failed: %s",
            fontFile.c_str(), ft_error_string(fterr));
        return false;
    }

    if(int fterr = FT_Select_Charmap(fontFace, FT_ENCODING_UNICODE)) {
        dbp("freetype: loading unicode CMap for file '%s' failed: %s",
            fontFile.c_str(), ft_error_string(fterr));
        FT_Done_Face(fontFace);
        return false;
    }

    name = std::string(fontFace->family_name) +
           " (" + std::string(fontFace->style_name) + ")";

    if(nameOnly) {
        FT_Done_Face(fontFace);
        fontFace = NULL;
    }

    return true;
}
예제 #5
0
파일: ftmac.c 프로젝트: 32767/libgdx
  FT_New_Face_From_FSRef( FT_Library    library,
                          const FSRef*  ref,
                          FT_Long       face_index,
                          FT_Face*      aface )
  {
    FT_Error      error;
    FT_Open_Args  args;
    OSErr   err;
    UInt8   pathname[PATH_MAX];


    if ( !ref )
      return FT_Err_Invalid_Argument;

    err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
    if ( err )
      error = FT_Err_Cannot_Open_Resource;

    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
    if ( error != 0 || *aface != NULL )
      return error;

    /* fallback to datafork font */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );
  }
예제 #6
0
파일: freetype.cpp 프로젝트: Artoria2e5/GDJ
FT_Error face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface)
{
	FT_Open_Args args = {};
	args.flags = FT_OPEN_STREAM;
	args.stream = font_mgr_instance.lookup_stream(face_id);

	return FT_Open_Face(library, &args, font_mgr_instance.lookup_face_index(face_id), aface);
}
예제 #7
0
/*************************************************************************
	Function to do real work of constructor
*************************************************************************/
void Font_FreeType::constructor_impl(const String& name, const String& fontname, const String& resourceGroup, uint size, bool antiAliase, bool encrypted)
{
	String		errMsg;

	FontDataStream* fontDataStream = 
		FontManager::getSingleton().getFontDataStream(fontname, resourceGroup, encrypted);

	// create face using input font
	FT_Open_Args  args;
	args.flags	= FT_OPEN_STREAM;
	args.stream	= &(fontDataStream->d_streamRec);

	if (FT_Open_Face(d_impldat->library, &args, 0, &d_impldat->fontFace) == 0)
	{

		// check that default Unicode character map is available
		if (d_impldat->fontFace->charmap != NULL)	
		{
			try
			{
				d_name = name;
				d_ptSize = size;
				d_antiAliase = antiAliase;

				// reprepare font datas.
				resetFontFaces();

				// prepare underline image
				createUnderlineImage();

				return;
			}
			catch(...)
			{
				FT_Done_Face(d_impldat->fontFace);

				// re-throw
				throw;
			}

		}
		// missing Unicode character map
		else
		{
			FT_Done_Face(d_impldat->fontFace);

			errMsg = (utf8*)"Font_FreeType::constructor_impl - The source font '" + fontname +"' does not have a Unicode charmap, and cannot be used.";
		}

	}
	// failed to create face (a problem with the font file?)
	else
	{
		errMsg = (utf8*)"Font_FreeType::constructor_impl - An error occurred while trying to create a FreeType face from source font '" + fontname + "'.";
	}

	throw GenericException(errMsg);
}
예제 #8
0
파일: Font.cpp 프로젝트: decultured/SFML
bool Font::loadFromStream(InputStream& stream)
{
    // Cleanup the previous resources
    cleanup();
    m_refCount = new int(1);

    // Initialize FreeType
    // Note: we initialize FreeType for every font instance in order to avoid having a single
    // global manager that would create a lot of issues regarding creation and destruction order.
    FT_Library library;
    if (FT_Init_FreeType(&library) != 0)
    {
        err() << "Failed to load font from stream (failed to initialize FreeType)" << std::endl;
        return false;
    }
    m_library = library;

    // Prepare a wrapper for our stream, that we'll pass to FreeType callbacks
    FT_StreamRec* rec = new FT_StreamRec;
    std::memset(rec, 0, sizeof(*rec));
    rec->base               = NULL;
    rec->size               = static_cast<unsigned long>(stream.getSize());
    rec->pos                = 0;
    rec->descriptor.pointer = &stream;
    rec->read               = &read;
    rec->close              = &close;

    // Setup the FreeType callbacks that will read our stream
    FT_Open_Args args;
    args.flags  = FT_OPEN_STREAM;
    args.stream = rec;
    args.driver = 0;

    // Load the new font face from the specified stream
    FT_Face face;
    if (FT_Open_Face(static_cast<FT_Library>(m_library), &args, 0, &face) != 0)
    {
        err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
        return false;
    }

    // Select the unicode character map
    if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
    {
        err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl;
        return false;
    }

    // Store the loaded font in our ugly void* :)
    m_face = face;
    m_streamRec = rec;

    return true;
}
예제 #9
0
bool CWin32Font::Create(const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags)
{
	FT_Library library = FontManager().GetFTLibrary();
	if (!library)
		return false;

	const unsigned char *file = FontManager().GetFontFile(windowsFontName);
	if (!file)
	{
		m_szName = UTL_INVAL_SYMBOL;
		return false;
	}

	FT_Face face;

	FT_Open_Args args;
	args.flags = FT_OPEN_MEMORY | FT_OPEN_DRIVER;
	args.memory_base = file + sizeof(int);
	args.memory_size = *((const int *)file);
	args.stream = NULL;
	args.driver = FT_Get_Module(library, "truetype");
	if (FT_Open_Face(library, &args, 0, &face))
	{
		m_szName = UTL_INVAL_SYMBOL;
		return false;
	}
	m_FTFace = face;

	m_szName = windowsFontName;
	m_iTall = tall;
	m_iFlags = flags & WIN32FONT_FLAGS_MASK;
	m_iScanLines = scanlines;
	m_iBlur = blur;
	m_iDropShadowOffset = (flags & vgui::ISurface::FONTFLAG_DROPSHADOW) ? 1 : 0;
	m_iOutlineSize = (flags & vgui::ISurface::FONTFLAG_OUTLINE) ? 1 : 0;
	m_bRotary = (flags & vgui::ISurface::FONTFLAG_ROTARY) ? 1 : 0;
	m_bAdditive = (flags & vgui::ISurface::FONTFLAG_ADDITIVE) ? 1 : 0;

	tall <<= 6;
	FT_Set_Char_Size(face, tall, tall, 72, 72);

	float scale = ((float)(face->size->metrics.ascender) * (1.0f / 64.0f)) / (float)(face->ascender);
	m_iBaseline = (int)(ceilf((float)(face->bbox.yMax) * scale));
	m_iHeight = m_iBaseline + (int)(ceilf((float)(-face->bbox.yMin) * scale)) + m_iDropShadowOffset + (m_iOutlineSize << 1);
	m_iMaxCharWidth = (face->size->metrics.max_advance + 127) >> 6;
	m_iAscent = (int)(ceilf((float)(face->ascender) * scale));

	m_rgiBitmapSize[0] = m_iMaxCharWidth + (m_iOutlineSize << 1);
	m_rgiBitmapSize[1] = m_iHeight;

	return true;
}
예제 #10
0
NSFonts::IFontFile* NSFonts::IFontManager::LoadFontFile(NSFonts::CLibrary& library, NSFonts::IFontStream* pStreamI, int lFaceIndex)
{
    CFontStream* pStream = (CFontStream*)pStreamI;
	FT_Open_Args oOpenArgs;
	oOpenArgs.flags			= FT_OPEN_MEMORY | FT_OPEN_PARAMS;
	oOpenArgs.memory_base	= pStream->m_pData;
	oOpenArgs.memory_size	= pStream->m_lSize;

	FT_Parameter *pParams = (FT_Parameter *)::malloc( sizeof(FT_Parameter) * 4 );
	pParams[0].tag  = FT_MAKE_TAG( 'i', 'g', 'p', 'f' );
	pParams[0].data = NULL;
	pParams[1].tag  = FT_MAKE_TAG( 'i', 'g', 'p', 's' );
	pParams[1].data = NULL; 
	pParams[2].tag  = FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY;
	pParams[2].data = NULL; 
	pParams[3].tag  = FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY;
	pParams[3].data = NULL; 

	oOpenArgs.params = pParams;
	oOpenArgs.num_params = 4;

	FT_Face pFace;
    if ( FT_Open_Face( library.m_internal->m_library, &oOpenArgs, lFaceIndex, &pFace ) )
		return NULL;

	::free(pParams);

	CFontFile* pFont = new CFontFile();
	pFont->m_lFaceIndex = lFaceIndex;

	pFont->m_lUnits_Per_Em	= pFace->units_per_EM;
	pFont->m_lAscender		= pFace->ascender;
	pFont->m_lDescender		= pFace->descender;
	pFont->m_lLineHeight	= pFace->height;

	pFont->m_nNum_charmaps	= pFace->num_charmaps;

	pFont->m_pFace = pFace;
	pFont->LoadDefaultCharAndSymbolicCmapIndex();

	if (FT_Set_Char_Size(pFace, 0, (FT_F26Dot6)(pFont->m_dSize * 64), 0, 0))
	{
		FT_Done_Face(pFace);
		delete pFont;
		return NULL;
	}

	pFont->ResetTextMatrix();
	pFont->ResetFontMatrix();

	return pFont;
}
예제 #11
0
  FT_New_Face_From_FSSpec( FT_Library     library,
                           const FSSpec*  spec,
                           FT_Long        face_index,
                           FT_Face*       aface )
  {

#if HAVE_FSREF

    FSRef  ref;


    if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
      return FT_THROW( Invalid_Argument );
    else
      return FT_New_Face_From_FSRef( library, &ref, face_index, aface );

#elif HAVE_FSSPEC

    FT_Error      error;
    FT_Open_Args  args;
    OSErr         err;
    UInt8         pathname[PATH_MAX];


    if ( !spec )
      return FT_THROW( Invalid_Argument );

    err = FT_FSpMakePath( spec, pathname, sizeof ( pathname ) );
    if ( err )
      error = FT_ERR( Cannot_Open_Resource );

    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
    if ( error || *aface )
      return error;

    /* fallback to datafork font */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );

#else

    FT_UNUSED( library );
    FT_UNUSED( spec );
    FT_UNUSED( face_index );
    FT_UNUSED( aface );

    return FT_THROW( Unimplemented_Feature );

#endif /* HAVE_FSREF, HAVE_FSSPEC */

  }
예제 #12
0
static SkFaceRec* ref_ft_face(uint32_t fontID) {
    SkFaceRec* rec = gFaceRecHead;
    while (rec) {
        if (rec->fFontID == fontID) {
            SkASSERT(rec->fFace);
            rec->fRefCnt += 1;
            return rec;
        }
        rec = rec->fNext;
    }

    SkStream* strm = SkFontHost::OpenStream(fontID);
    if (NULL == strm) {
        SkDEBUGF(("SkFontHost::OpenStream failed opening %x\n", fontID));
        sk_throw();
        return 0;
    }

    // this passes ownership of strm to the rec
    rec = SkNEW_ARGS(SkFaceRec, (strm, fontID));

    FT_Open_Args    args;
    memset(&args, 0, sizeof(args));
    const void* memoryBase = strm->getMemoryBase();

    if (NULL != memoryBase) {
//printf("mmap(%s)\n", keyString.c_str());
        args.flags = FT_OPEN_MEMORY;
        args.memory_base = (const FT_Byte*)memoryBase;
        args.memory_size = strm->getLength();
    } else {
//printf("fopen(%s)\n", keyString.c_str());
        args.flags = FT_OPEN_STREAM;
        args.stream = &rec->fFTStream;
    }

    FT_Error err = FT_Open_Face(gFTLibrary, &args, 0, &rec->fFace);

    if (err) {    // bad filename, try the default font
        fprintf(stderr, "ERROR: unable to open font '%x'\n", fontID);
        SkDELETE(rec);
        sk_throw();
        return 0;
    } else {
        SkASSERT(rec->fFace);
        //fprintf(stderr, "Opened font '%s'\n", filename.c_str());
        rec->fNext = gFaceRecHead;
        gFaceRecHead = rec;
        rec->fRefCnt = 1;
        return rec;
    }
}
예제 #13
0
파일: ft_wrap.c 프로젝트: atizo/pygame
/*********************************************************
 *
 * Font loading
 *
 * TODO:
 *  - Loading from rwops, existing files, etc
 *
 *********************************************************/
static FT_Error
_PGFT_face_request(FTC_FaceID face_id, FT_Library library,
                   FT_Pointer request_data, FT_Face *aface)
{
    PgFaceId *id = (PgFaceId *)face_id;
    FT_Error error;

    Py_BEGIN_ALLOW_THREADS;
    error = FT_Open_Face(library, &id->open_args, id->face_index, aface);
    Py_END_ALLOW_THREADS;

    return error;
}
예제 #14
0
파일: fonts.c 프로젝트: amineas/libGK
static FT_Error openFace(char* filename, FT_Long index, FT_Face* aface)
{
	FT_Open_Args args = {
		FT_OPEN_STREAM,
		0,0,	/* memory_base, memory_size */
		0,	/* filename */
		makeFTStream(filename),	/* stream */
		0,	/* driver */
		0,	/* extra params */
		0	/* params */
	};
	return FT_Open_Face(ftlib, &args, index, aface);
}
예제 #15
0
파일: font.cpp 프로젝트: Try/Tempest
  FT_Error New_Face( FT_Library    library,
                     FT_StreamRec& stream,
                     FT_Long       face_index,
                     FT_Face      *aface ) {
    FT_Open_Args  args;

    args.pathname = 0;

    args.flags    = FT_OPEN_STREAM;
    args.stream   = &stream;

    return FT_Open_Face( library, &args, face_index, aface );
    }
예제 #16
0
파일: l-font.c 프로젝트: IngenicC/xboot
static FT_Error FT_New_Xfs_Face(FT_Library library, const char * pathname, FT_Long face_index, FT_Face * aface)
{
	FT_Open_Args args;

	if(!pathname)
		return -1;

	args.flags = FT_OPEN_STREAM;
	args.pathname = (char *)pathname;
	args.stream = FT_New_Xfs_Stream(pathname);

	return FT_Open_Face(library, &args, face_index, aface);
}
FT_Byte* FreeTypeLibrary::getFace(std::istream &fontstream, unsigned int index, FT_Face &face)
{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getMutex());

    FT_Open_Args args;

    std::streampos start = fontstream.tellg();

    fontstream.seekg(0, std::ios::end);
    std::streampos end = fontstream.tellg();
    fontstream.seekg(start, std::ios::beg);
    std::streampos length = end - start;

    /* empty stream into memory, open that, and keep the pointer in a FreeTypeFont for cleanup */
    FT_Byte *buffer = new FT_Byte[static_cast<int>(length)];
    fontstream.read(reinterpret_cast<char*>(buffer), length);
    if (!fontstream || (static_cast<std::streampos>(fontstream.gcount()) != length))
    {
        OSG_WARN << " .... the font file could not be read from its stream" << std::endl;
        if (buffer)
            delete[] buffer;

        return 0;
    }

    args.flags       = FT_OPEN_MEMORY;
    args.memory_base = buffer;
    args.memory_size = length;

    FT_Error error = FT_Open_Face(_ftlibrary, &args, index, &face);

    if (error == FT_Err_Unknown_File_Format)
    {
        OSG_WARN << " .... the font file could be opened and read, but it appears" << std::endl;
        OSG_WARN << " .... that its font format is unsupported" << std::endl;
        return 0;
    }
    else if (error)
    {
        OSG_WARN << " .... another error code means that the font file could not" << std::endl;
        OSG_WARN << " .... be opened, read or simply that it is broken..." << std::endl;
        return 0;
    }

    //
    // GT: Fix to handle symbol fonts in MS Windows
    //
    verifyCharacterMap(face);

    return buffer;
}
예제 #18
0
파일: fteng.cpp 프로젝트: dirtycold/mactype
bool FreeTypeSysFontData::OpenFaceByIndex(int index)
{
	if(m_ftFace) {
		FT_Done_Face(m_ftFace);
		m_ftFace = NULL;
	}

	FT_Open_Args args = { 0 };
	args.flags		= FT_OPEN_STREAM;
	args.stream		= &m_ftStream;

	// FreeType 偱埖偊傞偐丠
	return (FT_Open_Face(freetype_library, &args, index, &m_ftFace) == 0);
}
예제 #19
0
  /* Create a new FT_Face given a buffer and a driver name. */
  static FT_Error
  open_face_from_buffer( FT_Library  library,
                         FT_Byte*    base,
                         FT_ULong    size,
                         FT_Long     face_index,
                         char*       driver_name,
                         FT_Face*    aface )
  {
    FT_Open_Args  args;
    FT_Error      error;
    FT_Stream     stream;
    FT_Memory     memory = library->memory;


    error = new_memory_stream( library,
                               base,
                               size,
                               memory_stream_close,
                               &stream );
    if ( error )
    {
      FT_FREE( base );
      return error;
    }

    args.flags  = FT_OPEN_STREAM;
    args.stream = stream;
    if ( driver_name )
    {
      args.flags  = args.flags | FT_OPEN_DRIVER;
      args.driver = FT_Get_Module( library, driver_name );
    }

    /* At this point, face_index has served its purpose;      */
    /* whoever calls this function has already used it to     */
    /* locate the correct font data.  We should not propagate */
    /* this index to FT_Open_Face() (unless it is negative).  */

    if ( face_index > 0 )
      face_index = 0;

    error = FT_Open_Face( library, &args, face_index, aface );
    if ( error == FT_Err_Ok )
      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
    else
      FT_Stream_Free( stream, 0 );

    return error;
  }
예제 #20
0
FT_Face Lib::open(const std::string& filename)
{
  FT_Stream stream = ft::open_stream(m_ft, filename);
  FT_Open_Args args;
  memset(&args, 0, sizeof(args));
  args.flags = FT_OPEN_STREAM;
  args.stream = stream;

  LOG(VERBOSE) << "FT: Loading font '" << filename << "'\n";

  FT_Face face = nullptr;
  FT_Error err = FT_Open_Face(m_ft, &args, 0, &face);
  if (!err)
    FT_Select_Charmap(face, FT_ENCODING_UNICODE);
  return face;
}
예제 #21
0
FT_Face FreeType::OpenFace(InputStream *pStream)
{
	FT_Stream stream;
	FT_Open_Args args;
	FT_Face face;

	stream = new FT_StreamRec;  // stream will be deleted in Stream_CloseFunc
	stream->size = pStream->Available();
	stream->descriptor.pointer = pStream;
	stream->read = Stream_ReadFunc;
	stream->close = Stream_CloseFunc;
	args.flags = FT_OPEN_STREAM;
	args.stream = stream;
	if (FT_Open_Face(g_Instance.m_ft, &args, 0, &face) == 0)
		return face;
	return NULL;
}
예제 #22
0
  FT_New_Face_From_FSRef( FT_Library    library,
                          const FSRef*  ref,
                          FT_Long       face_index,
                          FT_Face*      aface )
  {

#if !HAVE_FSREF

    FT_UNUSED( library );
    FT_UNUSED( ref );
    FT_UNUSED( face_index );
    FT_UNUSED( aface );

    return FT_THROW( Unimplemented_Feature );

#else

    FT_Error      error;
    FT_Open_Args  args;
    OSErr   err;
    UInt8   pathname[PATH_MAX];


    /* test for valid `library' and `aface' delayed to `FT_Open_Face' */

    if ( !ref )
      return FT_THROW( Invalid_Argument );

    err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
    if ( err )
      error = FT_ERR( Cannot_Open_Resource );

    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
    if ( error || *aface )
      return error;

    /* fallback to datafork font */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );

#endif /* HAVE_FSREF */

  }
예제 #23
0
bool FontFreeType::init(const vn::FilePath &file, u32 size) {
    FileStream *fs = FileManager::instance().open(file);
    if (!fs) {
        return false;
    }
    m_ftStream.descriptor.pointer = fs;
    m_ftStream.size = (unsigned long)fs->size();
    FT_Open_Args args = { FT_OPEN_STREAM };
	args.stream = &m_ftStream;
    
	if (FT_Open_Face(s_ftLibrary, &args, 0, &m_ftFace )) {
		return false;
	}
	
	s32 height = (s32)((f32)(size << 6) * m_ftFace->units_per_EM / m_ftFace->height / 64.f);
	
    
    FT_Select_Charmap(m_ftFace, FT_ENCODING_UNICODE);
    FT_Set_Pixel_Sizes(m_ftFace, height, 0);
    
    m_height = (s32)(m_ftFace->size->metrics.height >> 6);
    m_baseLine = (s32)(m_ftFace->size->metrics.ascender >> 6);
    
    m_texture = Render2DInterface::instance().createTexture(vector2i(kTexSize, kTexSize));
    
    s32 cell = height + 2;
    s32 cnt = kTexSize / cell;
    for (s32 y = 0; y < cnt; ++y) {
        for (s32 x = 0; x < cnt; ++x) {
            GlyphEx *p = vnnew GlyphEx();
            p->valid = false;
            p->size.y = (real)m_height;
            p->texture = m_texture;
            p->pos.set(x * cell + 1, y * cell + 1);
            p->texcoord.min_corner = vector2f(p->pos) / kTexSize;
            p->pass = 0;
            m_glyphList.push_front(p);
            p->lstIt = m_glyphList.begin();
            p->mapIt = m_glyphMap.end();
        }
    }
    
    return true;
}
예제 #24
0
void TTFont::constructor(const char *filename, float size, bool smoothing)
{
	face_ = NULL;

	G_FILE* fis = g_fopen(filename, "rb");
	if (fis == NULL)
	{
		throw GiderosException(GStatus(6000, filename));		// Error #6000: %s: No such file or directory.
		return;
	}

	memset(&stream_, 0, sizeof(stream_));

	g_fseek(fis, 0, SEEK_END);
	stream_.size = g_ftell(fis);
	g_fseek(fis, 0, SEEK_SET);
	stream_.descriptor.pointer = fis;
	stream_.read = read;
	stream_.close = close;

	FT_Open_Args args;
	memset(&args, 0, sizeof(args));
	args.flags = FT_OPEN_STREAM;
	args.stream = &stream_;

	if (FT_Open_Face(FT_Library_Singleton::instance(), &args, 0, &face_))
		throw GiderosException(GStatus(6012, filename));		// Error #6012: %s: Error while reading font file.

    float scalex = application_->getLogicalScaleX();
    float scaley = application_->getLogicalScaleY();

	const int RESOLUTION = 72;
	if (FT_Set_Char_Size(face_, 0L, (int)floor(size * 64 + 0.5f), (int)floor(RESOLUTION * scalex + 0.5f), (int)floor(RESOLUTION * scaley + 0.5f)))
	{
		FT_Done_Face(face_);
		face_ = NULL;
        throw GiderosException(GStatus(6017, filename));		// Error #6017: Invalid font size.
	}

	ascender_ = face_->size->metrics.ascender >> 6;
	height_ = face_->size->metrics.height >> 6;

    smoothing_ = smoothing;
}
예제 #25
0
파일: ftmac.c 프로젝트: dikerex/theqvd
  /* Create a new FT_Face given a buffer and a driver name. */
  static FT_Error
  open_face_from_buffer( FT_Library  library,
                         FT_Byte*    base,
                         FT_ULong    size,
                         FT_Long     face_index,
                         char*       driver_name,
                         FT_Face    *aface )
  {
    FT_Open_Args  args;
    FT_Error      error;
    FT_Stream     stream;
    FT_Memory     memory = library->memory;


    error = new_memory_stream( library,
                               base,
                               size,
                               memory_stream_close,
                               &stream );
    if ( error )
    {
      FT_FREE( base );
      return error;
    }

    args.flags = ft_open_stream;
    args.stream = stream;
    if ( driver_name )
    {
      args.flags = args.flags | ft_open_driver;
      args.driver = FT_Get_Module( library, driver_name );
    }

    error = FT_Open_Face( library, &args, face_index, aface );
    if ( error == FT_Err_Ok )
      (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
    else
    {
      FT_Stream_CloseFunc( stream );
      FT_FREE( stream );
    }

    return error;
  }
예제 #26
0
파일: ftmac.c 프로젝트: dikerex/theqvd
  FT_New_Face( FT_Library   library,
               const char*  pathname,
               FT_Long      face_index,
               FT_Face     *aface )
  {
    FT_Open_Args  args;
    FSSpec        spec;
    OSType        file_type;


    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
    if ( !pathname )
      return FT_Err_Invalid_Argument;

    if ( file_spec_from_path( pathname, &spec ) )
      return FT_Err_Invalid_Argument;

    /* Regardless of type, don't try to use the resource fork if it is */
    /* empty.  Some TTF fonts have type `FFIL', for example, but they  */
    /* only have data forks.                                           */

    if ( ResourceForkSize( &spec ) != 0 )
    {
      file_type = get_file_type( &spec );
      if ( file_type == 'FFIL' || file_type == 'tfil' )
        return FT_New_Face_From_Suitcase( library, &spec, face_index, aface );

      if ( file_type == 'LWFN' )
        return FT_New_Face_From_LWFN( library, &spec, face_index, aface );
    }

#if TARGET_API_MAC_CARBON

    if ( is_dfont( &spec ) )
      return FT_New_Face_From_dfont( library, &spec, face_index, aface );

#endif

    /* let it fall through to normal loader (.ttf, .otf, etc.) */
    args.flags    = ft_open_pathname;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );
  }
예제 #27
0
/**
 * 指定インデックスのFaceを開く
 * @param index	開くindex
 * @return	Faceを開ければ true そうでなければ false
 */
bool tNativeFreeTypeFace::OpenFaceByIndex(int index)
{
    if(Face) FT_Done_Face(Face), Face = NULL;

    FT_Parameter parameters[1];
    parameters[0].tag = FT_PARAM_TAG_UNPATENTED_HINTING; // Appleの特許回避を行う
    parameters[0].data = NULL;

    FT_Open_Args args;
    memset(&args, 0, sizeof(args));
    args.flags = FT_OPEN_STREAM | FT_OPEN_PARAMS;
    args.stream = &Stream;
    args.driver = 0;
    args.num_params = 1;
    args.params = parameters;

    FT_Error err = FT_Open_Face(FreeTypeLibrary, &args, index, &Face);
    return err == 0;
}
예제 #28
0
  FT_New_Face_From_FSRef( FT_Library    library,
                          const FSRef*  ref,
                          FT_Long       face_index,
                          FT_Face*      aface )
  {

#if !HAVE_FSREF

    FT_UNUSED( library );
    FT_UNUSED( ref );
    FT_UNUSED( face_index );
    FT_UNUSED( aface );

    return FT_Err_Unimplemented_Feature;

#else

    FT_Error      error;
    FT_Open_Args  args;
    OSErr   err;
    UInt8   pathname[HFS_MAXPATHLEN];


    if ( !ref )
      return FT_Err_Invalid_Argument;

    err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
    if ( err )
      error = FT_Err_Cannot_Open_Resource;

    error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
    if ( error != 0 || *aface != NULL )
      return error;

    /* fallback to datafork font */
    args.flags    = FT_OPEN_PATHNAME;
    args.pathname = (char*)pathname;
    return FT_Open_Face( library, &args, face_index, aface );

#endif /* HAVE_FSREF */

  }
예제 #29
0
bool freetype_engine::can_open(std::string const& face_name,
                               font_library & library,
                               font_file_mapping_type const& font_file_mapping,
                               font_file_mapping_type const& global_font_file_mapping)
{
    bool found_font_file = false;
    font_file_mapping_type::const_iterator itr = font_file_mapping.find(face_name);
    if (itr != font_file_mapping.end())
    {
        found_font_file = true;
    }
    else
    {
        itr = global_font_file_mapping.find(face_name);
        if (itr != global_font_file_mapping.end())
        {
            found_font_file = true;
        }
    }
    if (!found_font_file) return false;
    mapnik::util::file file(itr->second.second);
    if (!file) return false;
    FT_Face face = 0;
    FT_Open_Args args;
    FT_StreamRec streamRec;
    memset(&args, 0, sizeof(args));
    memset(&streamRec, 0, sizeof(streamRec));
    streamRec.base = 0;
    streamRec.pos = 0;
    streamRec.size = file.size();
    streamRec.descriptor.pointer = file.get();
    streamRec.read  = ft_read_cb;
    streamRec.close = nullptr;
    args.flags = FT_OPEN_STREAM;
    args.stream = &streamRec;
    // -1 is used to quickly check if the font file appears valid without iterating each face
    FT_Error error = FT_Open_Face(library.get(), &args, -1, &face);
    if (face) FT_Done_Face(face);
    if (error) return false;
    return true;
}
예제 #30
0
/* load a typeface from a URI */
FT_Error
FT_New_Face_From_URI (FT_Library library,
		      const gchar* uri,
		      FT_Long face_index,
		      FT_Face *aface)
{
    FT_Open_Args args;
    FT_Stream stream;
    FT_Error error;

    stream = calloc (1, sizeof (*stream));

    if (stream == NULL)
	return FT_Err_Out_Of_Memory;

    error = vfs_stream_open (stream, uri);

    if (error != FT_Err_Ok) {
	free (stream);
	return error;
    }

    args.flags = FT_OPEN_STREAM;
    args.stream = stream;

    error = FT_Open_Face (library, &args, face_index, aface);

    if (error != FT_Err_Ok) {
	if (stream->close != NULL)
	    stream->close(stream);

	free (stream);
	return error;
    }

    /* so that freetype will free the stream */
    (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;

    return error;
}