Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. StringArray FTTypefaceList::getDefaultFontDirectories()
  18. {
  19. StringArray fontDirs;
  20. fontDirs.addTokens (String (CharPointer_UTF8 (getenv ("JUCE_FONT_PATH"))), ";,", "");
  21. fontDirs.removeEmptyStrings (true);
  22. if (fontDirs.size() == 0)
  23. {
  24. const ScopedPointer<XmlElement> fontsInfo (XmlDocument::parse (File ("/etc/fonts/fonts.conf")));
  25. if (fontsInfo != nullptr)
  26. {
  27. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  28. {
  29. String fontPath (e->getAllSubText().trim());
  30. if (fontPath.isNotEmpty())
  31. {
  32. if (e->getStringAttribute ("prefix") == "xdg")
  33. {
  34. String xdgDataHome (SystemStats::getEnvironmentVariable ("XDG_DATA_HOME", String::empty));
  35. if (xdgDataHome.trimStart().isEmpty())
  36. xdgDataHome = "~/.local/share";
  37. fontPath = File (xdgDataHome).getChildFile (fontPath).getFullPathName();
  38. }
  39. fontDirs.add (fontPath);
  40. }
  41. }
  42. }
  43. }
  44. if (fontDirs.size() == 0)
  45. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  46. fontDirs.removeDuplicates (false);
  47. return fontDirs;
  48. }
  49. Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  50. {
  51. return new FreeTypeTypeface (font);
  52. }
  53. void Typeface::scanFolderForFonts (const File& folder)
  54. {
  55. FTTypefaceList::getInstance()->scanFontPaths (StringArray (folder.getFullPathName()));
  56. }
  57. StringArray Font::findAllTypefaceNames()
  58. {
  59. return FTTypefaceList::getInstance()->findAllFamilyNames();
  60. }
  61. StringArray Font::findAllTypefaceStyles (const String& family)
  62. {
  63. return FTTypefaceList::getInstance()->findAllTypefaceStyles (family);
  64. }
  65. bool TextLayout::createNativeLayout (const AttributedString&)
  66. {
  67. return false;
  68. }
  69. //==============================================================================
  70. struct DefaultFontNames
  71. {
  72. DefaultFontNames()
  73. : defaultSans (getDefaultSansSerifFontName()),
  74. defaultSerif (getDefaultSerifFontName()),
  75. defaultFixed (getDefaultMonospacedFontName())
  76. {
  77. }
  78. String getRealFontName (const String& faceName) const
  79. {
  80. if (faceName == Font::getDefaultSansSerifFontName()) return defaultSans;
  81. if (faceName == Font::getDefaultSerifFontName()) return defaultSerif;
  82. if (faceName == Font::getDefaultMonospacedFontName()) return defaultFixed;
  83. return faceName;
  84. }
  85. String defaultSans, defaultSerif, defaultFixed;
  86. private:
  87. static String pickBestFont (const StringArray& names, const char* const* choicesArray)
  88. {
  89. const StringArray choices (choicesArray);
  90. for (int j = 0; j < choices.size(); ++j)
  91. if (names.contains (choices[j], true))
  92. return choices[j];
  93. for (int j = 0; j < choices.size(); ++j)
  94. for (int i = 0; i < names.size(); ++i)
  95. if (names[i].startsWithIgnoreCase (choices[j]))
  96. return names[i];
  97. for (int j = 0; j < choices.size(); ++j)
  98. for (int i = 0; i < names.size(); ++i)
  99. if (names[i].containsIgnoreCase (choices[j]))
  100. return names[i];
  101. return names[0];
  102. }
  103. static String getDefaultSansSerifFontName()
  104. {
  105. StringArray allFonts;
  106. FTTypefaceList::getInstance()->getSansSerifNames (allFonts);
  107. static const char* targets[] = { "Verdana", "Bitstream Vera Sans", "Luxi Sans",
  108. "Liberation Sans", "DejaVu Sans", "Sans", nullptr };
  109. return pickBestFont (allFonts, targets);
  110. }
  111. static String getDefaultSerifFontName()
  112. {
  113. StringArray allFonts;
  114. FTTypefaceList::getInstance()->getSerifNames (allFonts);
  115. static const char* targets[] = { "Bitstream Vera Serif", "Times", "Nimbus Roman",
  116. "Liberation Serif", "DejaVu Serif", "Serif", nullptr };
  117. return pickBestFont (allFonts, targets);
  118. }
  119. static String getDefaultMonospacedFontName()
  120. {
  121. StringArray allFonts;
  122. FTTypefaceList::getInstance()->getMonospacedNames (allFonts);
  123. static const char* targets[] = { "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Sans Mono",
  124. "Liberation Mono", "Courier", "DejaVu Mono", "Mono", nullptr };
  125. return pickBestFont (allFonts, targets);
  126. }
  127. JUCE_DECLARE_NON_COPYABLE (DefaultFontNames)
  128. };
  129. Typeface::Ptr Font::getDefaultTypefaceForFont (const Font& font)
  130. {
  131. static DefaultFontNames defaultNames;
  132. Font f (font);
  133. f.setTypefaceName (defaultNames.getRealFontName (font.getTypefaceName()));
  134. return Typeface::createSystemTypefaceFor (f);
  135. }