3
0

FFontXML.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : XML parsing to load a font.
  9. #if !defined(USE_NULLFONT_ALWAYS)
  10. #include "FFontXML_Internal.h"
  11. #include <AtomLyIntegration/AtomFont/FFont.h>
  12. #include <AtomLyIntegration/AtomFont/FontTexture.h>
  13. #include <CryCommon/Cry_Math.h>
  14. #include <CryCommon/CryPath.h>
  15. #include <AzCore/PlatformIncl.h>
  16. //////////////////////////////////////////////////////////////////////////
  17. // Main loading function
  18. bool AZ::FFont::Load(const char* xmlFile)
  19. {
  20. m_curPath = "";
  21. if (xmlFile)
  22. {
  23. m_curPath = PathUtil::GetPath(xmlFile);
  24. }
  25. XmlNodeRef root = GetISystem()->LoadXmlFromFile(xmlFile);
  26. if (!root)
  27. {
  28. return false;
  29. }
  30. AtomFontInternal::XmlFontShader xmlfs(this);
  31. xmlfs.ScanXmlNodesRecursively(root);
  32. // if this was not a valid font XML file then return false
  33. if (!m_fontTexture || !m_fontBuffer)
  34. {
  35. return false;
  36. }
  37. // if there was a font effect file then parse that for effects
  38. if (!xmlfs.m_strFontEffectPath.empty())
  39. {
  40. XmlNodeRef fontEffectRoot = GetISystem()->LoadXmlFromFile(xmlfs.m_strFontEffectPath.c_str());
  41. if (!fontEffectRoot)
  42. {
  43. AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' pathname %s could not be found.",
  44. xmlFile, xmlfs.m_strFontEffectPath.c_str());
  45. return false;
  46. }
  47. if (m_effects.size() > 1 || (m_effects.size() == 1 && (m_effects[0].m_name != "default" || m_effects[0].m_passes.size() > 1)))
  48. {
  49. AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' and 'effect' cannot both be used in the same font file.",
  50. xmlFile);
  51. m_effects.clear();
  52. }
  53. // parse the font effects file, adding to this font object
  54. AtomFontInternal::XmlFontShader xmlfsEffect(this);
  55. xmlfsEffect.ScanXmlNodesRecursively(fontEffectRoot);
  56. }
  57. return true;
  58. }
  59. #endif