typography_provider.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_
  5. #define UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_
  6. #include "third_party/skia/include/core/SkColor.h"
  7. #include "ui/base/resource/resource_bundle.h"
  8. #include "ui/gfx/font.h"
  9. #include "ui/views/views_export.h"
  10. namespace gfx {
  11. class FontList;
  12. }
  13. namespace views {
  14. class View;
  15. // Provides a default provider of fonts to use in toolkit-views UI.
  16. class VIEWS_EXPORT TypographyProvider {
  17. public:
  18. TypographyProvider() = default;
  19. TypographyProvider(const TypographyProvider&) = delete;
  20. TypographyProvider& operator=(const TypographyProvider&) = delete;
  21. virtual ~TypographyProvider() = default;
  22. // Gets the FontDetails for the given |context| and |style|.
  23. virtual ui::ResourceBundle::FontDetails GetFontDetails(int context,
  24. int style) const;
  25. // Convenience wrapper that gets a FontList for |context| and |style|.
  26. const gfx::FontList& GetFont(int context, int style) const;
  27. // Gets the color for the given |context| and |style|. |view| is the View
  28. // requesting the color.
  29. virtual SkColor GetColor(const views::View& view,
  30. int context,
  31. int style) const;
  32. // Gets the line spacing. By default this is the font height.
  33. virtual int GetLineHeight(int context, int style) const;
  34. // Returns whether the given style can be used in the given context.
  35. virtual bool StyleAllowedForContext(int context, int style) const;
  36. // Returns the weight that will result in the ResourceBundle returning an
  37. // appropriate "medium" weight for UI. This caters for systems that are known
  38. // to be unable to provide a system font with weight other than NORMAL or BOLD
  39. // and for user configurations where the NORMAL font is already BOLD. In both
  40. // of these cases, NORMAL is returned instead.
  41. static gfx::Font::Weight MediumWeightForUI();
  42. };
  43. } // namespace views
  44. #endif // UI_VIEWS_STYLE_TYPOGRAPHY_PROVIDER_H_