ScaledFontBase.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef MOZILLA_GFX_SCALEDFONTBASE_H_
  6. #define MOZILLA_GFX_SCALEDFONTBASE_H_
  7. #include "2D.h"
  8. // Skia uses cairo_scaled_font_t as the internal font type in ScaledFont
  9. #if defined(USE_SKIA) || defined(USE_CAIRO)
  10. #define USE_CAIRO_SCALED_FONT
  11. #endif
  12. #ifdef USE_SKIA
  13. #include "skia/include/core/SkPath.h"
  14. #include "skia/include/core/SkTypeface.h"
  15. #endif
  16. #ifdef USE_CAIRO_SCALED_FONT
  17. #include "cairo.h"
  18. #endif
  19. namespace mozilla {
  20. namespace gfx {
  21. class ScaledFontBase : public ScaledFont
  22. {
  23. public:
  24. MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontBase)
  25. explicit ScaledFontBase(Float aSize);
  26. virtual ~ScaledFontBase();
  27. virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
  28. virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, const Matrix *aTransformHint);
  29. virtual void GetGlyphDesignMetrics(const uint16_t* aGlyphIndices, uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics);
  30. float GetSize() { return mSize; }
  31. #ifdef USE_SKIA
  32. virtual SkTypeface* GetSkTypeface() { return mTypeface; }
  33. #endif
  34. // Not true, but required to instantiate a ScaledFontBase.
  35. virtual FontType GetType() const { return FontType::SKIA; }
  36. #ifdef USE_CAIRO_SCALED_FONT
  37. bool PopulateCairoScaledFont();
  38. cairo_scaled_font_t* GetCairoScaledFont() { return mScaledFont; }
  39. void SetCairoScaledFont(cairo_scaled_font_t* font);
  40. #endif
  41. protected:
  42. friend class DrawTargetSkia;
  43. #ifdef USE_SKIA
  44. SkTypeface* mTypeface;
  45. SkPath GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer);
  46. #endif
  47. #ifdef USE_CAIRO_SCALED_FONT
  48. // Overridders should ensure the cairo_font_face_t has been addrefed.
  49. virtual cairo_font_face_t* GetCairoFontFace() { return nullptr; }
  50. cairo_scaled_font_t* mScaledFont;
  51. #endif
  52. Float mSize;
  53. };
  54. } // namespace gfx
  55. } // namespace mozilla
  56. #endif /* MOZILLA_GFX_SCALEDFONTBASE_H_ */