// Returns a handle for positioning and rendering this face at the given size. FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size) { UnicodeRangeList charset; HandleMap::iterator iterator = handles.find(size); if (iterator != handles.end()) { iterator->second->AddReference(); return iterator->second; } // See if this face has been released. if (face == NULL) { Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle."); return NULL; } // Construct and initialise the new handle. FontFaceHandle* handle = new FontFaceHandle(); if (!handle->Initialise(face, _raw_charset, size)) { handle->RemoveReference(); return NULL; } // Save the handle, and add a reference for the callee. The initial reference will be removed when the font face // releases it. handles[size] = handle; handle->AddReference(); return handle; }
// Returns a handle to a font face that can be used to position and render text. FontFaceHandle* FontDatabase::GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size) { if( family.Empty() ) { return NULL; } FontProviderInterface *fontprovider_interface = Core::GetFontProviderInterface(); FontHandle fonthandle = fontprovider_interface->GetFontFaceHandle(family, charset, style, weight, size); FontFaceHandleMap::iterator it = instance->font_handles.find(family); if (it == instance->font_handles.end()) { std::pair<FontFaceHandleMap::iterator, bool> const &insert = instance->font_handles.insert(std::pair<const String &, FontFaceHandleList>(family, FontFaceHandleList())); it = insert.first; } FontFaceHandle *handle; FontFaceHandleList::iterator hit = it->second.find(fonthandle); if (hit == it->second.end()) { handle = new FontFaceHandle(); handle->Initialise(fontprovider_interface, fonthandle); handle->AddReference(); std::pair<FontFaceHandleList::iterator, bool> const &insert = it->second.insert(std::pair<FontHandle, FontFaceHandle *>(fonthandle, handle)); hit = insert.first; } handle = hit->second; handle->AddReference(); return handle; }
// Attempts to load the texture from the source. bool TextureResource::Load(RenderInterface* render_interface) const { // Check for special loader tokens. if (!source.Empty() && source[0] == '?') { Vector2i dimensions; bool delete_data = false; const byte* data = NULL; // Find the generation protocol and generate the data accordingly. String protocol = source.Substring(1, source.Find("::") - 1); if (protocol == "font") { // The requested texture is a font layer. delete_data = true; StringList parameters; StringUtilities::ExpandString(parameters, source.Substring(source.Find("::") + 2), '/'); if (parameters.size() == 3) { FontFaceHandle* handle = (FontFaceHandle*) strtol(parameters[0].CString(), NULL, 16); handle->GenerateLayerTexture(data, dimensions, strtol(parameters[1].CString(), NULL, 16), atoi(parameters[2].CString())); } } // If texture data was generated, great! Otherwise, fallback to the LoadTexture() code and // hope the client knows what the hell to do with the question mark in their file name. if (data != NULL) { TextureHandle handle; bool success = render_interface->GenerateTexture(handle, data, dimensions); if (delete_data) delete[] data; if (success) { texture_data[render_interface] = TextureData(handle, dimensions); return true; } else { Log::Message(Log::LT_WARNING, "Failed to generate internal texture %s.", source.CString()); texture_data[render_interface] = TextureData((TextureHandle)NULL, Vector2i(0, 0)); return false; } } } TextureHandle handle; Vector2i dimensions; if (!render_interface->LoadTexture(handle, dimensions, source)) { Log::Message(Log::LT_WARNING, "Failed to load texture from %s.", source.CString()); texture_data[render_interface] = TextureData((TextureHandle)NULL, Vector2i(0, 0)); return false; } texture_data[render_interface] = TextureData((TextureHandle)handle, dimensions); return true; }
// Returns a handle for positioning and rendering this face at the given size. Rocket::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size) { UnicodeRangeList charset; HandleMap::iterator iterator = handles.find(size); if (iterator != handles.end()) { const HandleList& handles = (*iterator).second; // Check all the handles if their charsets match the requested one exactly (ie, were specified by the same // string). String raw_charset(_raw_charset); for (size_t i = 0; i < handles.size(); ++i) { if (handles[i]->GetRawCharset() == _raw_charset) { handles[i]->AddReference(); return (Rocket::Core::FreeType::FontFaceHandle*)handles[i]; } } // Check all the handles if their charsets contain the requested charset. if (!UnicodeRange::BuildList(charset, raw_charset)) { Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", _raw_charset.CString()); return NULL; } for (size_t i = 0; i < handles.size(); ++i) { bool range_contained = true; const UnicodeRangeList& handle_charset = handles[i]->GetCharset(); for (size_t j = 0; j < charset.size() && range_contained; ++j) { if (!charset[j].IsContained(handle_charset)) range_contained = false; } if (range_contained) { handles[i]->AddReference(); return (Rocket::Core::FreeType::FontFaceHandle*)handles[i]; } } } // See if this face has been released. if (face == NULL) { Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle."); return NULL; } // Construct and initialise the new handle. FontFaceHandle* handle = new FontFaceHandle(); if (!handle->Initialise(face, _raw_charset, size)) { handle->RemoveReference(); return NULL; } // Save the handle, and add a reference for the callee. The initial reference will be removed when the font face // releases it. if (iterator != handles.end()) (*iterator).second.push_back(handle); else handles[size] = HandleList(1, handle); handle->AddReference(); return handle; }
// Attempts to load the texture from the source. bool TextureResource::Load(RenderInterface* render_interface) const { // Check for special loader tokens. if (!source.Empty() && source[0] == '?') { Vector2i dimensions; bool delete_data = false; const byte* data = NULL; // Find the generation protocol and generate the data accordingly. String protocol = source.Substring(1, source.Find("::") - 1); if (protocol == "font") { // The requested texture is a font layer. delete_data = true; FontFaceHandle* handle; FontEffect* layer_id; int texture_id; if (sscanf(source.CString(), "?font::%p/%p/%d", &handle, &layer_id, &texture_id) == 3) { handle->GenerateLayerTexture(data, dimensions, layer_id, texture_id); } } // If texture data was generated, great! Otherwise, fallback to the LoadTexture() code and // hope the client knows what the hell to do with the question mark in their file name. if (data != NULL) { TextureHandle handle; bool success = render_interface->GenerateTexture(handle, data, dimensions); if (delete_data) delete[] data; if (success) { texture_data[render_interface] = TextureData(handle, dimensions); return true; } else { Log::Message(Log::LT_WARNING, "Failed to generate internal texture %s.", source.CString()); texture_data[render_interface] = TextureData(NULL, Vector2i(0, 0)); return false; } } } TextureHandle handle; Vector2i dimensions; if (!render_interface->LoadTexture(handle, dimensions, source)) { Log::Message(Log::LT_WARNING, "Failed to load texture from %s.", source.CString()); texture_data[render_interface] = TextureData(NULL, Vector2i(0, 0)); return false; } texture_data[render_interface] = TextureData(handle, dimensions); return true; }