/*---------------------------------------------------------------------------* Project: NintendoWare File: lyt_FontContainer.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 27719 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #ifdef NW_PLATFORM_CTR #define stricmp std::strcasecmp #endif namespace nw { namespace lyt { FontRefLink::FontRefLink() : m_pFont(0), m_Own(false) { } FontRefLink::~FontRefLink() { if (m_Own) { // 所有するフォントはライブラリで生成されたもの。 // font::ResFontのインスタンスでなければならない。 font::ResFont* pResFont = (font::ResFont*)(m_pFont); if (pResFont != NULL) { void* drawBuffer = pResFont->GetDrawBuffer(); if (drawBuffer != NULL) { pResFont->SetDrawBuffer(NULL); Layout::FreeMemory(drawBuffer); } } Layout::DeleteObj(m_pFont); m_pFont = NULL; } } void FontRefLink::Set( const char* name, font::Font* pFont, bool own ) { ut::strcpy(m_FontName, sizeof(m_FontName), name); m_pFont = pFont; m_Own = own; } FontContainer::~FontContainer() { this->Finalize(); } void FontContainer::Finalize() { while (!this->empty()) { FontRefLink* pLink = &this->front(); this->erase(pLink); Layout::DeleteObj(pLink); } } nw::font::Font* FontContainer::FindFontByName( const char* name ) { for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (0 == std::strcmp(name, it->GetFontName())) { return it->GetFont(); } } return NULL; } nw::font::Font* FontContainer::FindFontByKey(FontKey key) { NW_NULL_ASSERT(key); FontRefLink* pLink = (FontRefLink*)(key); for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (&(*it) == pLink) { return it->GetFont(); } } return NULL; } FontKey FontContainer::RegistFont(const char* name, font::Font* pFont, bool own) { FontRefLink* pLink = Layout::NewObj(); if (pLink == NULL) { return NULL; } pLink->Set(name, pFont, own); this->push_back(pLink); return reinterpret_cast(pLink); } void FontContainer::UnregistFont(FontKey key) { NW_NULL_ASSERT(key); FontRefLink* pLink = (FontRefLink*)(key); this->erase(pLink); Layout::DeleteObj(pLink); } } // namespace lyt } // namespace nw