FFontXML.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <AzCore/Serialization/Locale.h>
  17. //////////////////////////////////////////////////////////////////////////
  18. // Main loading function
  19. bool AZ::FFont::Load(const char* xmlFile)
  20. {
  21. m_curPath = "";
  22. if (xmlFile)
  23. {
  24. m_curPath = PathUtil::GetPath(xmlFile);
  25. }
  26. XmlNodeRef root = GetISystem()->LoadXmlFromFile(xmlFile);
  27. if (!root)
  28. {
  29. return false;
  30. }
  31. AtomFontInternal::XmlFontShader xmlfs(this);
  32. {
  33. // use the invariant culture so that if the user has a machine that has comma as the decimal separator,
  34. // the font file will still be parsed correctly.
  35. AZ::Locale::ScopedSerializationLocale scopedLocale;
  36. xmlfs.ScanXmlNodesRecursively(root);
  37. }
  38. // if this was not a valid font XML file then return false
  39. if (!m_fontTexture || !m_fontBuffer)
  40. {
  41. return false;
  42. }
  43. // if there was a font effect file then parse that for effects
  44. if (!xmlfs.m_strFontEffectPath.empty())
  45. {
  46. XmlNodeRef fontEffectRoot = GetISystem()->LoadXmlFromFile(xmlfs.m_strFontEffectPath.c_str());
  47. if (!fontEffectRoot)
  48. {
  49. AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' pathname %s could not be found.",
  50. xmlFile, xmlfs.m_strFontEffectPath.c_str());
  51. return false;
  52. }
  53. if (m_effects.size() > 1 || (m_effects.size() == 1 && (m_effects[0].m_name != "default" || m_effects[0].m_passes.size() > 1)))
  54. {
  55. AZ_Warning("Font", false, "Error parsing font file %s, 'effectfile' and 'effect' cannot both be used in the same font file.",
  56. xmlFile);
  57. m_effects.clear();
  58. }
  59. AZ::Locale::ScopedSerializationLocale scopedLocale;
  60. // parse the font effects file, adding to this font object
  61. AtomFontInternal::XmlFontShader xmlfsEffect(this);
  62. xmlfsEffect.ScanXmlNodesRecursively(fontEffectRoot);
  63. }
  64. return true;
  65. }
  66. #endif