/* * 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 */
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; }
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); } } } }
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; }
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; }
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; } } }
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; }
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); }
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(); } }
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; }
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); }
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); }
/** * 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; }
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; }
// 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; }
bool load(const ResourcePtr& resource) { if(!Font::FTLibrary::Instance().library) return false; if(face) { FT_Done_Face(face); } if(resource && resource->getResourceStream()) { font_data = resource->getResourceStream()->readIntoMemory(); if(FT_New_Memory_Face(Font::FTLibrary::Instance().library, static_cast<MemoryStream*>(font_data.get())->data(), font_data->size(), 0, &face)) { return false; } FT_Select_Charmap(face, FT_ENCODING_UNICODE); return true; } else { if(FT_New_Face(Font::FTLibrary::Instance().library, string::WStringToString(resource->getName()).c_str(), 0, &face)) { return false; } return true; } return false; }
static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) { // Freetype2 FT_Face face; struct TmpFont *tf; // Find the correct FreeType font tf= vfont_find_tmpfont(vfont); // What, no font found. Something strange here if(!tf) return FALSE; // Load the font to memory if(tf->pf) { err= FT_New_Memory_Face( library, tf->pf->data, tf->pf->size, 0, &face); if (err) return FALSE; } else { err = TRUE; return FALSE; } // Read the char freetypechar_to_vchar(face, charcode, vfont->data); // And everything went ok return TRUE; }
static int Face_init(Face *self, PyObject *args, PyObject *kwds) { FT_Error error = 0; char *data; Py_ssize_t sz; PyObject *ft; if (!PyArg_ParseTuple(args, "Os#", &ft, &data, &sz)) return -1; Py_BEGIN_ALLOW_THREADS; error = FT_New_Memory_Face( ( (FreeType*)ft )->library, (const FT_Byte*)data, (FT_Long)sz, 0, &self->face); Py_END_ALLOW_THREADS; if (error) { self->face = NULL; if ( error == FT_Err_Unknown_File_Format || error == FT_Err_Invalid_Stream_Operation) PyErr_SetString(FreeTypeError, "Not a supported font format"); else PyErr_Format(FreeTypeError, "Failed to initialize the Font with error: 0x%x", error); return -1; } self->library = ft; Py_XINCREF(ft); self->data = PySequence_GetItem(args, 1); return 0; }
static FT_Face create_face_from_contents (FontLoadJob *job, gchar **contents, GError **error) { FT_Error ft_error; FT_Face retval; ft_error = FT_New_Memory_Face (job->library, (const FT_Byte *) job->face_contents, (FT_Long) job->face_length, job->face_index, &retval); if (ft_error != 0) { g_set_error_literal (error, G_IO_ERROR, 0, "Unable to read the font face file"); retval = NULL; g_free (job->face_contents); } else { *contents = job->face_contents; } return retval; }
//////////////////////////////////////////////////////////// /// Load the font from a file in memory //////////////////////////////////////////////////////////// bool FontLoader::LoadFontFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize, std::wstring Charset, Font& LoadedFont) { // Check if Freetype is correctly initialized if (!myLibrary) { std::cerr << "Failed to load font from memory, FreeType has not been initialized" << std::endl; return false; } // Create a new font face from the specified memory data FT_Face FontFace; FT_Error Error = FT_New_Memory_Face(myLibrary, reinterpret_cast<const FT_Byte*>(Data), static_cast<FT_Long>(SizeInBytes), 0, &FontFace); if (Error) { std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl; return false; } // Create the bitmap font Error = CreateBitmapFont(FontFace, CharSize, Charset, LoadedFont); if (Error) std::cerr << "Failed to load font from memory (" << GetErrorDesc(Error) << ")" << std::endl; // Delete the font FT_Done_Face(FontFace); return Error == 0; }
fz_error * pdf_loadbuiltinfont(pdf_font *font, char *fontname) { fz_error *error; unsigned char *data; unsigned int len; int fterr; int i; error = initfontlibs(); if (error) return fz_rethrow(error, "cannot init font libraries"); for (i = 0; i < 15; i++) if (!strcmp(fontname, basefonts[i].name)) goto found; return fz_throw("cannot find font: %s", fontname); found: pdf_logfont("load builtin font %s\n", fontname); data = (unsigned char *) basefonts[i].cff; len = *basefonts[i].len; fterr = FT_New_Memory_Face(ftlib, data, len, 0, (FT_Face*)&font->ftface); if (fterr) return fz_throw("freetype: cannot load font: %s", ft_errstr(fterr)); return fz_okay; }
FT_Error TA_font_init(FONT* font) { FT_Error error; FT_Face f; FT_Int major, minor, patch; error = FT_Init_FreeType(&font->lib); if (error) return error; /* assure correct FreeType version to avoid using the wrong DLL */ FT_Library_Version(font->lib, &major, &minor, &patch); if (((major*1000 + minor)*1000 + patch) < 2004005) return TA_Err_Invalid_FreeType_Version; /* get number of faces (i.e. subfonts) */ error = FT_New_Memory_Face(font->lib, font->in_buf, (FT_Long)font->in_len, -1, &f); if (error) return error; font->num_sfnts = f->num_faces; FT_Done_Face(f); /* it is a TTC if we have more than a single subfont */ font->sfnts = (SFNT*)calloc(1, (size_t)font->num_sfnts * sizeof (SFNT)); if (!font->sfnts) return FT_Err_Out_Of_Memory; return TA_Err_Ok; }
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 error; pdf_logfont("load embedded font\n"); error = pdf_loadstream(&buf, xref, fz_tonum(stmref), fz_togen(stmref)); if (error) return error; fterr = FT_New_Memory_Face(ftlib, buf->rp, buf->wp - buf->rp, 0, &face); if (fterr) { fz_free(buf); return fz_throw("freetype could not load embedded font: %s", pdf_fterrorstring(fterr)); } font->ftface = face; font->fontdata = buf; return nil; }
FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size) { FontBLF *font; FT_Error err; font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem"); err = FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face); if (err) { MEM_freeN(font); return NULL; } err = FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); MEM_freeN(font); return NULL; } font->name = BLI_strdup(name); font->filename = NULL; blf_font_fill(font); return font; }
static int check_freetypefont(PackedFile *pf) { FT_Face face; FT_GlyphSlot glyph; FT_UInt glyph_index; #if 0 FT_CharMap charmap; FT_CharMap found; FT_UShort my_platform_id = TT_PLATFORM_MICROSOFT; FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS; int n; #endif int success = 0; err = FT_New_Memory_Face(library, pf->data, pf->size, 0, &face); if (err) { success = 0; //XXX error("This is not a valid font"); } else { #if 0 for (n = 0; n < face->num_charmaps; n++) { charmap = face->charmaps[n]; if (charmap->platform_id == my_platform_id && charmap->encoding_id == my_encoding_id) { found = charmap; break; } } if (!found) { return 0; } /* now, select the charmap for the face object */ err = FT_Set_Charmap(face, found); if (err) { return 0; } #endif glyph_index = FT_Get_Char_Index(face, 'A'); err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); if (err) { success = 0; } else { glyph = face->glyph; if (glyph->format == ft_glyph_format_outline) { success = 1; } else { //XXX error("Selected Font has no outline data"); success = 0; } } } return success; }
/** * 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(void *face_data, size_t face_data_size, uint16_t font_size) { if(g_ft_library) { gl_tex_font_p glf = (gl_tex_font_p)malloc(sizeof(gl_tex_font_t)); glf->ft_face = NULL; if(FT_New_Memory_Face(g_ft_library, (const FT_Byte*)face_data, face_data_size, 0, (FT_Face*)&glf->ft_face)) { free(glf); return NULL; } glf->glyphs_count = ((FT_Face)glf->ft_face)->num_glyphs; glf->glyphs = (char_info_p)malloc(glf->glyphs_count * sizeof(char_info_t)); qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &glf->gl_max_tex_width); glf->gl_tex_width = glf->gl_max_tex_width; glf->gl_tex_indexes = NULL; 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 NULL; }
Font * FontCache::Create(const res::path & font, FontFile & file, unsigned int size) { if(!file.data) { LogDebug("loading file " << font); file.data = resources->readAlloc(font, file.size); if(!file.data) { return NULL; } } LogDebug("creating font " << font << " @ " << size); FT_Face face; const FT_Byte * data = reinterpret_cast<const FT_Byte *>(file.data); FT_Error error = FT_New_Memory_Face(g_FTLibrary, data, file.size, 0, &face); if(error == FT_Err_Unknown_File_Format) { // the font file's format is unsupported LogError << "Font creation error: FT_Err_Unknown_File_Format"; return NULL; } else if(error) { // ... another error code means that the font file could not // ... be opened or read, or simply that it is broken... return NULL; } // Windows default is 96dpi // Freetype default is 72dpi error = FT_Set_Char_Size(face, 0, size * 64, 64, 64); if(error) { return NULL; } return new Font(font, size, face); }
PFont create_font_freetype_buf(const char* buf,int bsize, int height,int disp) { PFontFreetype pf; //FT_Error error; /* allocate font structure */ pf = (PFontFreetype) malloc(sizeof(FontFreetype)); memset(pf,0,sizeof(FontFreetype)); if (!pf) { return NULL; } FT_Init_FreeType( &pf->library ); FT_New_Memory_Face( pf->library, (const unsigned char *)buf,bsize, 0, &pf->face ); FT_Set_Char_Size( pf->face,height<< 6, height << 6, 96, 96); pf->procs = &freetype2_procs; pf->size = height; pf->disp = disp==0?DISPLAY_PIXEL_FORMAT_5551:disp; pf->r = 0; pf->g = 0; pf->a = 0; pf->encodingBuf.datalen = 2048; pf->encodingBuf.data = (char*)malloc(pf->encodingBuf.datalen); memset(pf->encodingBuf.data,0,pf->encodingBuf.datalen); memset(pf->alpha_table,0,256); return (PFont)pf; }
void CocoFontsCache::add(std::string name, FONT_STYLE style, const char* filename) { trace("CocoFontsCache::add(%s)", name.c_str()); CocoFontsCache ff(name, style); if(fonts.find(ff) != fonts.end()) return; CocoAssetFile* file = CocoAssetFile::open(filename); if(!file) return; switch(file->mime) { case CocoAssetFile::MIME::FONT_TTF: { FT_Face ftFace; int er = 0; if((er = FT_New_Memory_Face(ftLibrary, (const FT_Byte*)file->getData(), file->getLength(), 0, &ftFace))) { trace("Could not load FreeType Face(%d)!", er); } fonts.insert(std::pair<CocoFontsCache, FT_Face>(ff, ftFace)); break; } default: trace("Unsupported font type!\n"); return; } }
face_ptr freetype_engine::create_face(std::string const& family_name) { std::map<std::string, std::pair<int,std::string> >::const_iterator itr; itr = name2file_.find(family_name); if (itr != name2file_.end()) { FT_Face face; std::map<std::string,std::string>::const_iterator mem_font_itr = memory_fonts_.find(itr->second.second); if (mem_font_itr != memory_fonts_.end()) // memory font { FT_Error error = FT_New_Memory_Face(library_, reinterpret_cast<FT_Byte const*>(mem_font_itr->second.c_str()), static_cast<FT_Long>(mem_font_itr->second.size()), // size itr->second.first, // face index &face); if (!error) return std::make_shared<font_face>(face); } else { // load font into memory #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif std::ifstream is(itr->second.second.c_str() , std::ios::binary); std::string buffer((std::istreambuf_iterator<char>(is)), std::istreambuf_iterator<char>()); std::pair<std::map<std::string,std::string>::iterator,bool> result = memory_fonts_.insert(std::make_pair(itr->second.second, buffer)); FT_Error error = FT_New_Memory_Face (library_, reinterpret_cast<FT_Byte const*>(result.first->second.c_str()), static_cast<FT_Long>(buffer.size()), itr->second.first, &face); if (!error) return std::make_shared<font_face>(face); else { // we can't load font, erase it. memory_fonts_.erase(result.first); } } } return face_ptr(); }