本文整理汇总了C++中FT_New_Memory_Face函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_New_Memory_Face函数的具体用法?C++ FT_New_Memory_Face怎么用?C++ FT_New_Memory_Face使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FT_New_Memory_Face函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: libaroma_font
/*
* Function : libaroma_font
* Return Value: byte
* Descriptions: load new font
*/
byte libaroma_font(
byte fontid,
LIBAROMA_STREAMP stream) {
if (!stream) {
ALOGW("libaroma_font stream not found");
return 0;
}
if (fontid >= _LIBAROMA_FONT_MAX_FACE) {
ALOGW("libaroma_font fontid(%i)>=%i",
fontid, _LIBAROMA_FONT_MAX_FACE);
return 0;
}
/* thread safe */
_libaroma_font_lock(1);
/* load face */
FT_Face tmp_face;
if (FT_New_Memory_Face(_libaroma_font_instance,
stream->data,
stream->size,
0,
&tmp_face) == 0) {
/* set default face size */
int def_size = libaroma_font_size_px(2);
if (FT_Set_Pixel_Sizes(tmp_face, 0, def_size) == 0) {
/* save it */
libaroma_font_free(fontid);
_libaroma_font_faces[fontid].size = def_size;
_libaroma_font_faces[fontid].id = fontid;
_libaroma_font_faces[fontid].face = tmp_face;
_libaroma_font_faces[fontid].stream = stream;
_libaroma_font_faces[fontid].cache =
libaroma_iarray(libaroma_font_freecache_cb);
/* force ucs2 */
libaroma_font_set_ucs2(_libaroma_font_faces[fontid].face);
/* init harfbuzz */
_libaroma_font_hb_init(fontid);
/* unlock */
_libaroma_font_lock(0);
ALOGV("font loaded %ibytes (%s)", stream->size, stream->uri);
return 1;
}
else {
ALOGW("libaroma_font libaroma_font_set_size error");
FT_Done_Face(tmp_face);
}
}
else {
ALOGW("libaroma_font FT_New_Memory_Face Error");
libaroma_stream_close(stream);
}
_libaroma_font_lock(0);
return 0;
} /* End of libaroma_font */
示例2: TTF_New_Memory_Face
TTF_Font* TTF_New_Memory_Face(const FT_Byte* file_base, FT_Long file_size, int ptsize)
{
TTF_Font *font = (TTF_Font*)malloc(sizeof *font);
if (font == NULL)
E_Exit("TTF: Out of memory");
memset(font, 0, sizeof(*font));
if (FT_New_Memory_Face(library, file_base, file_size, 0, &font->face))
E_Exit("TTF: Couldn't init font");
FT_Face face = font->face;
if (!FT_IS_SCALABLE(face)) // Make sure that our font face is scalable (global metrics)
E_Exit("TTF: Font is not scalable");
for (int i = 0; i < face->num_charmaps; i++) // Set charmap for loaded font
{
FT_CharMap charmap = face->charmaps[i];
if (charmap->platform_id == 3 && charmap->encoding_id == 1) // Windows Unicode
{
FT_Set_Charmap(face, charmap);
break;
}
}
TTF_SetCharSize(font, ptsize);
bool fontOK = false;
if (!FT_Load_Glyph(face, 0, FT_LOAD_DEFAULT)) // Test pixel mode
if (!FT_Render_Glyph(font->face->glyph, FT_RENDER_MODE_NORMAL)) // Render the glyph
if (font->face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY)
fontOK = true;
if (!fontOK)
E_Exit("TTF: Font is not 8 bits gray scale");
return font;
}
示例3: _isReady
Font::Font(const int& data_index)
: _isReady(false)
{
if (FT_Init_FreeType(&_freeType)) {
ax::Error("Could not init freetype library.");
FT_Done_FreeType(_freeType);
}
else {
if (data_index > 1) {
ax::Error("Only two default font buffer.");
FT_Done_FreeType(_freeType);
}
else {
FT_Error err
= FT_New_Memory_Face(_freeType, GetDefaultFontData(data_index),
GetDefaultFontDataSize(data_index), 0, &_face);
if (err) {
ax::Error("Could not open font index", data_index);
FT_Done_FreeType(_freeType);
}
else {
_isReady = true;
SetFontSize(12);
// glGenTextures(1, &_texture);
}
}
}
}
示例4: pdf_loadembeddedfont
fz_error *
pdf_loadembeddedfont(pdf_font *font, pdf_xref *xref, fz_obj *stmref)
{
fz_error *error;
int fterr;
FT_Face face;
fz_buffer *buf;
error = initfontlibs();
if (error)
return fz_rethrow(error, "cannot init font libraries");
pdf_logfont("load embedded font\n");
error = pdf_loadstream(&buf, xref, fz_tonum(stmref), fz_togen(stmref));
if (error)
return fz_rethrow(error, "cannot load font stream");
fterr = FT_New_Memory_Face(ftlib, buf->rp, buf->wp - buf->rp, 0, &face);
if (fterr)
{
fz_dropbuffer(buf);
return fz_throw("freetype: cannot load embedded font: %s", ft_errstr(fterr));
}
font->ftface = face;
font->fontdata = buf;
return fz_okay;
}
示例5: FT_New_Memory_Face
static VChar *objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
{
VChar *che;
/* Freetype2 */
FT_Face face;
/* Load the font to memory */
if (vfont->temp_pf) {
err = FT_New_Memory_Face(library,
vfont->temp_pf->data,
vfont->temp_pf->size,
0,
&face);
if (err) {
return NULL;
}
}
else {
err = TRUE;
return NULL;
}
/* Read the char */
che = freetypechar_to_vchar(face, charcode, vfont->data);
/* And everything went ok */
return che;
}
示例6: AddFontDir
void kGUI::AddFontDir(const char *path)
{
unsigned int i,n;
kGUIDir dir;
unsigned long fontfilesize;
unsigned char *mem;
kGUIFontFileInfo *ffi;
FT_Face ftface;
dir.LoadDir(path,false,true,"ttf");
n=dir.GetNumFiles();
for(i=0;i<n;++i)
{
mem=kGUI::LoadFile(dir.GetFilename(i),&fontfilesize);
if(mem)
{
if(FT_New_Memory_Face( kGUIFont::GetLibrary(),
mem, /* first byte in memory */
fontfilesize, /* size in bytes */
0, /* face_index */
&ftface )==0)
{
/* make a name for this font */
ffi=kGUIFont::m_ffilist.GetEntryPtr(kGUIFont::m_ffinumentries++);
ffi->SetFilename(dir.GetFilename(i));
ffi->SetFacename(ftface->family_name);
ffi->SetStyle(ftface->style_name);
kGUI::Trace("Font fn='%s',face='%s',style='%s'\n",ffi->GetFilename()->GetString(),ffi->GetFacename()->GetString(),ffi->GetStyle()->GetString());
}
delete []mem;
}
}
}
示例7: fz_new_font_from_memory
fz_font *
fz_new_font_from_memory(fz_context *ctx, char *name, unsigned char *data, int len, int index, int use_glyph_bbox)
{
FT_Face face;
fz_font *font;
int fterr;
fz_keep_freetype(ctx);
fz_lock(ctx, FZ_LOCK_FREETYPE);
fterr = FT_New_Memory_Face(ctx->font->ftlib, data, len, index, &face);
fz_unlock(ctx, FZ_LOCK_FREETYPE);
if (fterr)
{
fz_drop_freetype(ctx);
fz_throw(ctx, FZ_ERROR_GENERIC, "freetype: cannot load font: %s", ft_error_string(fterr));
}
if (!name)
name = face->family_name;
font = fz_new_font(ctx, name, use_glyph_bbox, face->num_glyphs);
font->ft_face = face;
fz_set_font_bbox(ctx, font,
(float) face->bbox.xMin / face->units_per_EM,
(float) face->bbox.yMin / face->units_per_EM,
(float) face->bbox.xMax / face->units_per_EM,
(float) face->bbox.yMax / face->units_per_EM);
return font;
}
示例8: MPQFile
void font_data::init(const std::string& fname, unsigned int _h, bool fromMPQ)
{
h = _h;
if (FT_Init_FreeType(&_library))
{
LogError << "FT_Init_FreeType failed" << std::endl;
throw std::runtime_error("FT_Init_FreeType failed");
}
bool failed;
if (fromMPQ)
{
_mpqFile = new MPQFile(fname);
failed = FT_New_Memory_Face(_library, _mpqFile->get<FT_Byte>(0), _mpqFile->getSize(), 0, &_face) != 0;
}
else
{
failed = FT_New_Face(_library, fname.c_str(), 0, &_face) != 0;
}
if (failed)
{
LogError << "FT_New_Face failed (there is probably a problem with your font file)" << std::endl;
throw std::runtime_error("FT_New_Face failed (there is probably a problem with your font file)");
}
// For some twisted reason, Freetype measures font size in terms of 1/64ths of pixels.
FT_Set_Char_Size(_face, h << 6, h << 6, 72, 72);
}
示例9: numGlyphs
FTFace::FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes,
bool precomputeKerning)
: numGlyphs(0),
fontEncodingList(0),
kerningCache(0),
err(0)
{
const FT_Long DEFAULT_FACE_INDEX = 0;
ftFace = new FT_Face;
err = FT_New_Memory_Face(*FTLibrary::Instance().GetLibrary(),
(FT_Byte const *)pBufferBytes, (FT_Long)bufferSizeInBytes,
DEFAULT_FACE_INDEX, ftFace);
if(err)
{
delete ftFace;
ftFace = 0;
return;
}
FTCleanup::Instance()->RegisterObject(&ftFace);
numGlyphs = (*ftFace)->num_glyphs;
hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);
if(hasKerningTable && precomputeKerning)
{
BuildKerningCache();
}
}
示例10: fz_newfontfrombuffer
fz_error
fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index)
{
fz_error error;
fz_font *font;
int fterr;
error = fz_initfreetype();
if (error)
return fz_rethrow(error, "cannot init freetype library");
font = fz_newfont();
fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, (FT_Face*)&font->ftface);
if (fterr)
{
fz_free(font);
return fz_throw("freetype: cannot load font: %s", ft_errorstring(fterr));
}
/* SumatraPDF */
font->_data = data;
font->_data_len = len;
*fontp = font;
return fz_okay;
}
示例11: load_font
void load_font(caStack* stack)
{
caValue* filename = circa_input(stack, 0);
FontFace* font = new FontFace();
circa_read_file_with_stack(stack, circa_string(filename), &font->rawData);
if (circa_is_null(&font->rawData))
return circa_output_error(stack, "Failed to load file");
if (!g_ftLibraryInitialized) {
FT_Init_FreeType(&g_ftLibrary);
g_ftLibraryInitialized = true;
}
int error = FT_New_Memory_Face(g_ftLibrary,
(FT_Byte*) circa_blob(&font->rawData),
circa_blob_size(&font->rawData),
0,
&font->ftFace);
if (error)
return circa_output_error(stack, "FT_New_Memory_Face failed");
font->cairoFace = cairo_ft_font_face_create_for_ft_face(font->ftFace, 0);
caValue* out = circa_set_default_output(stack, 0);
circa_set_native_ptr(circa_index(out, 0), font, FontFaceRelease);
}
示例12: createFontCustomPlatformData
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
{
ASSERT_ARG(buffer, buffer);
int error;
static FT_Library library = 0;
if (!library) {
error = FT_Init_FreeType(&library);
if (error) {
library = 0;
return 0;
}
}
FT_Face face;
error = FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &face);
if (error)
return 0;
buffer->ref();
cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_ft_face(face, 0);
static cairo_user_data_key_t bufferKey;
cairo_font_face_set_user_data(fontFace, &bufferKey, buffer, releaseData);
return new FontCustomPlatformData(fontFace);
}
示例13: glf_create_font_mem
/**
* Creates gl texture font from true type font;
* @param ft_library: base font library;
* @param face_data: pointer to the buffer with font file content; DO NOT FREE that pointer otherway using FT_Face prevets to crash;
* @param face_data_size: size of buffer with font file content;
* @param font_size: size of font glyph?
* @return pointer to the gl_tex_font_s structure;
*/
gl_tex_font_p glf_create_font_mem(FT_Library ft_library, void *face_data, size_t face_data_size, uint16_t font_size)
{
if(ft_library != nullptr)
{
gl_tex_font_p glf = static_cast<gl_tex_font_p>(malloc(sizeof(gl_tex_font_t)));
glf->ft_face = nullptr;
if(FT_New_Memory_Face(ft_library, static_cast<const FT_Byte*>(face_data), face_data_size, 0, &glf->ft_face))
{
free(glf);
return nullptr;
}
glf->glyphs_count = glf->ft_face->num_glyphs;
glf->glyphs = static_cast<char_info_p>(malloc(glf->glyphs_count * sizeof(char_info_t)));
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glf->gl_max_tex_width);
glf->gl_tex_width = glf->gl_max_tex_width;
glf->gl_tex_indexes = nullptr;
glf->gl_tex_indexes_count = 0;
glf->gl_real_tex_indexes_count = 0;
glf_resize(glf, font_size);
FT_Select_Charmap(glf->ft_face, FT_ENCODING_UNICODE);
return glf;
}
return nullptr;
}
示例14: createFontObject
bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
{
int dpi = 72;
int len = 0;
unsigned char* data = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", (unsigned long *)(&len));
if (!data)
return false;
// create the new face
FT_Face face;
// create the face from the data
if (FT_New_Memory_Face(getFTLibrary(), data, len, 0, &face ))
return false;
//we want to use unicode
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE))
return false;
// set the requested font size
int fontSizePoints = (int)(64.f * fontSize);
if (FT_Set_Char_Size(face, fontSizePoints, fontSizePoints, dpi, dpi))
return false;
// store the face globally
_fontRef = face;
// save font name locally
_fontName = fontName;
// done and good
return true;
}
示例15: FT_New_Memory_Face
// Loads a FreeType face from memory.
void* FontDatabase::LoadFace(const byte* data, int data_length, const String& source, bool local_data)
{
FT_Face face = NULL;
int error = FT_New_Memory_Face(ft_library, (const FT_Byte*) data, data_length, 0, &face);
if (error != 0)
{
Log::Message(Log::LT_ERROR, "FreeType error %d while loading face from %s.", error, source.CString());
if (local_data)
delete[] data;
return NULL;
}
// Initialise the character mapping on the face.
if (face->charmap == NULL)
{
FT_Select_Charmap(face, FT_ENCODING_APPLE_ROMAN);
if (face->charmap == NULL)
{
Log::Message(Log::LT_ERROR, "Font face (from %s) does not contain a Unicode or Apple Roman character map.", source.CString());
FT_Done_Face(face);
if (local_data)
delete[] data;
return NULL;
}
}
return face;
}