FontFace.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "../precompiled.h"
  28. #include "FontFace.h"
  29. #include "FontFaceHandle.h"
  30. #include <Rocket/Core/Log.h>
  31. namespace Rocket {
  32. namespace Core {
  33. namespace BitmapFont {
  34. FontFace::FontFace(BM_Font *_face, Font::Style _style, Font::Weight _weight, bool _release_stream) : Rocket::Core::FontFace(_style, _weight, _release_stream)
  35. {
  36. face = _face;
  37. }
  38. FontFace::~FontFace()
  39. {
  40. ReleaseFace();
  41. }
  42. // Returns a handle for positioning and rendering this face at the given size.
  43. Rocket::Core::FontFaceHandle* FontFace::GetHandle(const String& _raw_charset, int size)
  44. {
  45. // UnicodeRangeList charset;
  46. // HandleMap::iterator iterator = handles.find(size);
  47. // if (iterator != handles.end())
  48. // {
  49. // const HandleList& handles = (*iterator).second;
  50. // // Check all the handles if their charsets match the requested one exactly (ie, were specified by the same
  51. // // string).
  52. // String raw_charset(_raw_charset);
  53. // for (size_t i = 0; i < handles.size(); ++i)
  54. // {
  55. // if (handles[i]->GetRawCharset() == _raw_charset)
  56. // {
  57. // handles[i]->AddReference();
  58. // return (FontFaceHandle*)handles[i];
  59. // }
  60. // }
  61. // // Check all the handles if their charsets contain the requested charset.
  62. // if (!UnicodeRange::BuildList(charset, raw_charset))
  63. // {
  64. // Log::Message(Log::LT_ERROR, "Invalid font charset '%s'.", _raw_charset.CString());
  65. // return NULL;
  66. // }
  67. // for (size_t i = 0; i < handles.size(); ++i)
  68. // {
  69. // bool range_contained = true;
  70. // const UnicodeRangeList& handle_charset = handles[i]->GetCharset();
  71. // for (size_t j = 0; j < charset.size() && range_contained; ++j)
  72. // {
  73. // if (!charset[j].IsContained(handle_charset))
  74. // range_contained = false;
  75. // }
  76. // if (range_contained)
  77. // {
  78. // handles[i]->AddReference();
  79. // return (FontFaceHandle*)handles[i];
  80. // }
  81. // }
  82. // }
  83. // // See if this face has been released.
  84. // if (face == NULL)
  85. // {
  86. // Log::Message(Log::LT_WARNING, "Font face has been released, unable to generate new handle.");
  87. // return NULL;
  88. // }
  89. // // Construct and initialise the new handle.
  90. // FontFaceHandle* handle = new FontFaceHandle();
  91. // if (!handle->Initialise(face, _raw_charset, size))
  92. // {
  93. // handle->RemoveReference();
  94. // return NULL;
  95. // }
  96. // // Save the handle, and add a reference for the callee. The initial reference will be removed when the font face
  97. // // releases it.
  98. // if (iterator != handles.end())
  99. // (*iterator).second.push_back(handle);
  100. // else
  101. // handles[size] = HandleList(1, handle);
  102. // handle->AddReference();
  103. // return handle;
  104. return 0;
  105. }
  106. // Releases the face's structure.
  107. void FontFace::ReleaseFace()
  108. {
  109. delete face;
  110. }
  111. }
  112. }
  113. }