ScaledFontFontconfig.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "ScaledFontFontconfig.h"
  6. #include "Logging.h"
  7. #ifdef USE_SKIA
  8. #include "skia/include/ports/SkTypeface_cairo.h"
  9. #endif
  10. namespace mozilla {
  11. namespace gfx {
  12. // On Linux and Android our "platform" font is a cairo_scaled_font_t and we use
  13. // an SkFontHost implementation that allows Skia to render using this.
  14. // This is mainly because FT_Face is not good for sharing between libraries, which
  15. // is a requirement when we consider runtime switchable backends and so on
  16. ScaledFontFontconfig::ScaledFontFontconfig(cairo_scaled_font_t* aScaledFont,
  17. FcPattern* aPattern,
  18. Float aSize)
  19. : ScaledFontBase(aSize),
  20. mPattern(aPattern)
  21. {
  22. SetCairoScaledFont(aScaledFont);
  23. FcPatternReference(aPattern);
  24. }
  25. ScaledFontFontconfig::~ScaledFontFontconfig()
  26. {
  27. FcPatternDestroy(mPattern);
  28. }
  29. #ifdef USE_SKIA
  30. SkTypeface* ScaledFontFontconfig::GetSkTypeface()
  31. {
  32. if (!mTypeface) {
  33. mTypeface = SkCreateTypefaceFromCairoFTFontWithFontconfig(mScaledFont, mPattern);
  34. }
  35. return mTypeface;
  36. }
  37. #endif
  38. } // namespace gfx
  39. } // namespace mozilla