FontEffect.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "../Common/TestsShell.h"
  29. #include <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Element.h>
  31. #include <RmlUi/Core/ElementDocument.h>
  32. #include <RmlUi/Core/Types.h>
  33. #include <doctest.h>
  34. #include <nanobench.h>
  35. using namespace ankerl;
  36. using namespace Rml;
  37. static const String rml_font_effect_document = R"(
  38. <rml>
  39. <head>
  40. <title>Table</title>
  41. <link type="text/rcss" href="/../Tests/Data/style.rcss"/>
  42. <style>
  43. body {
  44. font-size: 25px;
  45. font-effect: %s(%dpx #ff6);
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. The quick brown fox jumps over the lazy dog.
  51. </body>
  52. </rml>
  53. )";
  54. TEST_CASE("font_effect")
  55. {
  56. Context* context = TestsShell::GetContext();
  57. REQUIRE(context);
  58. nanobench::Bench bench;
  59. bench.title("Font effect");
  60. bench.relative(true);
  61. for (const char* effect_name : {"shadow", "blur", "outline", "glow"})
  62. {
  63. constexpr int effect_size = 8;
  64. const String rml_document = CreateString(rml_font_effect_document.c_str(), effect_name, effect_size);
  65. ElementDocument* document = context->LoadDocumentFromMemory(rml_document);
  66. document->Show();
  67. context->Update();
  68. context->Render();
  69. bench.run(effect_name, [&]() {
  70. Rml::ReleaseFontResources();
  71. context->Render();
  72. });
  73. document->Close();
  74. }
  75. TestsShell::ShutdownShell();
  76. }