DocumentHeader.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "DocumentHeader.h"
  2. #include "../../Include/RmlUi/Core/Core.h"
  3. #include "../../Include/RmlUi/Core/StringUtilities.h"
  4. #include "../../Include/RmlUi/Core/SystemInterface.h"
  5. #include "XMLParseTools.h"
  6. namespace Rml {
  7. void DocumentHeader::MergeHeader(const DocumentHeader& header)
  8. {
  9. // Copy the title across if ours is empty
  10. if (title.empty())
  11. title = header.title;
  12. // Copy the url across if ours is empty
  13. if (source.empty())
  14. source = header.source;
  15. // Combine external data, keeping relative paths
  16. MergePaths(template_resources, header.template_resources, header.source);
  17. MergeResources(rcss, header.rcss);
  18. MergeResources(scripts, header.scripts);
  19. }
  20. void DocumentHeader::MergePaths(StringList& target, const StringList& source, const String& source_path)
  21. {
  22. for (size_t i = 0; i < source.size(); i++)
  23. {
  24. String joined_path;
  25. ::Rml::GetSystemInterface()->JoinPath(joined_path, StringUtilities::Replace(source_path, '|', ':'),
  26. StringUtilities::Replace(source[i], '|', ':'));
  27. target.push_back(StringUtilities::Replace(joined_path, ':', '|'));
  28. }
  29. }
  30. void DocumentHeader::MergeResources(ResourceList& target, const ResourceList& source)
  31. {
  32. target.insert(target.end(), source.begin(), source.end());
  33. }
  34. } // namespace Rml