1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/*
* This source file is part of libRocket, the HTML/CSS Interface Middleware
*
* For the latest information, see http://www.librocket.com
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include "../precompiled.h"
#include "FontFace.h"
#include "FontFaceHandle.h"
#include <Rocket/Core/Log.h>
namespace Rocket {
namespace Core {
namespace BitmapFont {
FontFace::FontFace(BitmapFontDefinitions *_face, Font::Style _style, Font::Weight _weight, bool _release_stream) : Rocket::Core::FontFace(_style, _weight, _release_stream)
{
face = _face;
}
FontFace::~FontFace()
{
ReleaseFace();
}
// 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 (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 (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;
}
// Releases the face's structure.
void FontFace::ReleaseFace()
{
delete face;
}
}
}
}
|