thorvg_svg_in_ot.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* thorvg_svg_in_ot.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #ifdef GDEXTENSION
  32. // Headers for building as GDExtension plug-in.
  33. #include <godot_cpp/core/mutex_lock.hpp>
  34. #include <godot_cpp/godot.hpp>
  35. #include <godot_cpp/templates/hash_map.hpp>
  36. using namespace godot;
  37. #elif defined(GODOT_MODULE)
  38. // Headers for building as built-in module.
  39. #include "core/os/mutex.h"
  40. #include "core/templates/hash_map.h"
  41. #include "core/typedefs.h"
  42. #include "modules/modules_enabled.gen.h" // For svg, freetype.
  43. #endif
  44. #ifdef MODULE_SVG_ENABLED
  45. #ifdef MODULE_FREETYPE_ENABLED
  46. #include <freetype/freetype.h>
  47. #include <freetype/otsvg.h>
  48. #include <ft2build.h>
  49. #include <thorvg.h>
  50. struct GL_State {
  51. bool ready = false;
  52. float x = 0;
  53. float y = 0;
  54. float w = 0;
  55. float h = 0;
  56. CharString xml_code;
  57. tvg::Matrix m;
  58. };
  59. struct TVG_NodeCache {
  60. uint64_t document_offset;
  61. uint64_t body_offset;
  62. };
  63. struct TVG_DocumentCache {
  64. String xml_body;
  65. double embox_x;
  66. double embox_y;
  67. HashMap<int64_t, Vector<TVG_NodeCache>> node_caches;
  68. };
  69. struct TVG_State {
  70. Mutex mutex;
  71. HashMap<uint32_t, GL_State> glyph_map;
  72. HashMap<FT_Byte *, TVG_DocumentCache> document_map;
  73. };
  74. FT_Error tvg_svg_in_ot_init(FT_Pointer *p_state);
  75. void tvg_svg_in_ot_free(FT_Pointer *p_state);
  76. FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Pointer *p_state);
  77. FT_Error tvg_svg_in_ot_render(FT_GlyphSlot p_slot, FT_Pointer *p_state);
  78. SVG_RendererHooks *get_tvg_svg_in_ot_hooks();
  79. #endif // MODULE_FREETYPE_ENABLED
  80. #endif // MODULE_SVG_ENABLED