The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

148 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../jucer_Headers.h"
  19. #include "jucer_FontPropertyComponent.h"
  20. //==============================================================================
  21. class FontList : private DeletedAtShutdown
  22. {
  23. public:
  24. FontList()
  25. {
  26. Array<Font> fonts;
  27. Font::findFonts (fonts);
  28. for (int i = 0; i < fonts.size(); ++i)
  29. fontNames.add (fonts[i].getTypefaceName());
  30. }
  31. ~FontList()
  32. {
  33. clearSingletonInstance();
  34. }
  35. juce_DeclareSingleton_SingleThreaded_Minimal (FontList)
  36. StringArray fontNames;
  37. };
  38. juce_ImplementSingleton_SingleThreaded (FontList)
  39. void FontPropertyComponent::preloadAllFonts()
  40. {
  41. FontList::getInstance();
  42. }
  43. //==============================================================================
  44. const String FontPropertyComponent::defaultFont ("Default font");
  45. const String FontPropertyComponent::defaultSans ("Default sans-serif font");
  46. const String FontPropertyComponent::defaultSerif ("Default serif font");
  47. const String FontPropertyComponent::defaultMono ("Default monospaced font");
  48. FontPropertyComponent::FontPropertyComponent (const String& name)
  49. : ChoicePropertyComponent (name)
  50. {
  51. choices.add (defaultFont);
  52. choices.add (defaultSans);
  53. choices.add (defaultSerif);
  54. choices.add (defaultMono);
  55. choices.add (String::empty);
  56. choices.addArray (FontList::getInstance()->fontNames);
  57. }
  58. FontPropertyComponent::~FontPropertyComponent()
  59. {
  60. }
  61. //==============================================================================
  62. void FontPropertyComponent::setIndex (const int newIndex)
  63. {
  64. String type (choices [newIndex]);
  65. if (type.isEmpty())
  66. type = defaultFont;
  67. if (getTypefaceName() != type)
  68. setTypefaceName (type);
  69. }
  70. int FontPropertyComponent::getIndex() const
  71. {
  72. return choices.indexOf (getTypefaceName());
  73. }
  74. const Font FontPropertyComponent::applyNameToFont (const String& typefaceName, const Font& font)
  75. {
  76. if (typefaceName == defaultFont)
  77. return Font (font.getHeight(), font.getStyleFlags());
  78. else if (typefaceName == defaultSans)
  79. return Font (Font::getDefaultSansSerifFontName(), font.getHeight(), font.getStyleFlags());
  80. else if (typefaceName == defaultSerif)
  81. return Font (Font::getDefaultSerifFontName(), font.getHeight(), font.getStyleFlags());
  82. else if (typefaceName == defaultMono)
  83. return Font (Font::getDefaultMonospacedFontName(), font.getHeight(), font.getStyleFlags());
  84. return Font (typefaceName, font.getHeight(), font.getStyleFlags());
  85. }
  86. const String FontPropertyComponent::getTypefaceNameCode (const String& typefaceName)
  87. {
  88. if (typefaceName == defaultFont)
  89. return String::empty;
  90. else if (typefaceName == defaultSans)
  91. return "Font::getDefaultSansSerifFontName(), ";
  92. else if (typefaceName == defaultSerif)
  93. return "Font::getDefaultSerifFontName(), ";
  94. else if (typefaceName == defaultMono)
  95. return "Font::getDefaultMonospacedFontName(), ";
  96. return "\"" + typefaceName + "\", ";
  97. }
  98. const String FontPropertyComponent::getFontStyleCode (const Font& font)
  99. {
  100. if (font.isBold() && font.isItalic())
  101. return "Font::bold | Font::italic";
  102. else if (font.isBold())
  103. return "Font::bold";
  104. else if (font.isItalic())
  105. return "Font::italic";
  106. return "Font::plain";
  107. }
  108. const String FontPropertyComponent::getCompleteFontCode (const Font& font, const String& typefaceName)
  109. {
  110. return "Font ("
  111. + getTypefaceNameCode (typefaceName)
  112. + valueToFloat (font.getHeight())
  113. + ", "
  114. + getFontStyleCode (font)
  115. + ")";
  116. }