FontEngineInterfaceBitmap.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "FontEngineInterfaceBitmap.h"
  29. #include "FontEngineBitmap.h"
  30. #include <RmlUi/Core.h>
  31. FontEngineInterfaceBitmap::FontEngineInterfaceBitmap()
  32. {
  33. FontProviderBitmap::Initialise();
  34. }
  35. FontEngineInterfaceBitmap::~FontEngineInterfaceBitmap()
  36. {
  37. FontProviderBitmap::Shutdown();
  38. }
  39. bool FontEngineInterfaceBitmap::LoadFontFace(const String& file_name, bool /*fallback_face*/, FontWeight /*weight*/)
  40. {
  41. return FontProviderBitmap::LoadFontFace(file_name);
  42. }
  43. bool FontEngineInterfaceBitmap::LoadFontFace(const byte* /*data*/, int /*data_size*/, const String& font_family, FontStyle /*style*/,
  44. FontWeight /*weight*/, bool /*fallback_face*/)
  45. {
  46. // We return 'true' here to allow the debugger to continue loading, but we will use our own fonts when it asks for a handle.
  47. // The debugger might look a bit off with our own fonts, but hey it works.
  48. if (font_family == "rmlui-debugger-font")
  49. return true;
  50. return false;
  51. }
  52. FontFaceHandle FontEngineInterfaceBitmap::GetFontFaceHandle(const String& family, FontStyle style, FontWeight weight, int size)
  53. {
  54. auto handle = FontProviderBitmap::GetFontFaceHandle(family, style, weight, size);
  55. return reinterpret_cast<FontFaceHandle>(handle);
  56. }
  57. FontEffectsHandle FontEngineInterfaceBitmap::PrepareFontEffects(FontFaceHandle /*handle*/, const FontEffectList& /*font_effects*/)
  58. {
  59. // Font effects are not rendered in this implementation.
  60. return 0;
  61. }
  62. const FontMetrics& FontEngineInterfaceBitmap::GetFontMetrics(FontFaceHandle handle)
  63. {
  64. auto handle_bitmap = reinterpret_cast<FontFaceBitmap*>(handle);
  65. return handle_bitmap->GetMetrics();
  66. }
  67. int FontEngineInterfaceBitmap::GetStringWidth(FontFaceHandle handle, const String& string, const TextShapingContext& /*text_shaping_context*/,
  68. Character prior_character)
  69. {
  70. auto handle_bitmap = reinterpret_cast<FontFaceBitmap*>(handle);
  71. return handle_bitmap->GetStringWidth(string, prior_character);
  72. }
  73. int FontEngineInterfaceBitmap::GenerateString(FontFaceHandle handle, FontEffectsHandle /*font_effects_handle*/, const String& string,
  74. const Vector2f& position, const Colourb& colour, float /*opacity*/, const TextShapingContext& /*text_shaping_context*/, GeometryList& geometry)
  75. {
  76. auto handle_bitmap = reinterpret_cast<FontFaceBitmap*>(handle);
  77. return handle_bitmap->GenerateString(string, position, colour, geometry);
  78. }
  79. int FontEngineInterfaceBitmap::GetVersion(FontFaceHandle /*handle*/)
  80. {
  81. return 0;
  82. }