SkFontConfigTypeface.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkFontConfigTypeface_DEFINED
  8. #define SkFontConfigTypeface_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/core/SkStream.h"
  11. #include "include/ports/SkFontConfigInterface.h"
  12. #include "src/core/SkFontDescriptor.h"
  13. #include "src/ports/SkFontHost_FreeType_common.h"
  14. class SkFontDescriptor;
  15. class SkTypeface_FCI : public SkTypeface_FreeType {
  16. sk_sp<SkFontConfigInterface> fFCI;
  17. SkFontConfigInterface::FontIdentity fIdentity;
  18. SkString fFamilyName;
  19. std::unique_ptr<SkFontData> fFontData;
  20. public:
  21. static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
  22. const SkFontConfigInterface::FontIdentity& fi,
  23. SkString familyName,
  24. const SkFontStyle& style)
  25. {
  26. return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style);
  27. }
  28. static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
  29. SkString familyName, SkFontStyle style, bool isFixedPitch)
  30. {
  31. return new SkTypeface_FCI(std::move(data), std::move(familyName), style, isFixedPitch);
  32. }
  33. const SkFontConfigInterface::FontIdentity& getIdentity() const {
  34. return fIdentity;
  35. }
  36. sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
  37. std::unique_ptr<SkFontData> data = this->cloneFontData(args);
  38. if (!data) {
  39. return nullptr;
  40. }
  41. return sk_sp<SkTypeface>(new SkTypeface_FCI(std::move(data),
  42. fFamilyName,
  43. this->fontStyle(),
  44. this->isFixedPitch()));
  45. }
  46. protected:
  47. SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
  48. const SkFontConfigInterface::FontIdentity& fi,
  49. SkString familyName,
  50. const SkFontStyle& style)
  51. : INHERITED(style, false)
  52. , fFCI(std::move(fci))
  53. , fIdentity(fi)
  54. , fFamilyName(std::move(familyName))
  55. , fFontData(nullptr) {}
  56. SkTypeface_FCI(std::unique_ptr<SkFontData> data,
  57. SkString familyName, SkFontStyle style, bool isFixedPitch)
  58. : INHERITED(style, isFixedPitch)
  59. , fFamilyName(std::move(familyName))
  60. , fFontData(std::move(data))
  61. {
  62. SkASSERT(fFontData);
  63. fIdentity.fTTCIndex = fFontData->getIndex();
  64. }
  65. void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
  66. void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
  67. std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
  68. std::unique_ptr<SkFontData> onMakeFontData() const override;
  69. private:
  70. typedef SkTypeface_FreeType INHERITED;
  71. };
  72. #endif // SkFontConfigTypeface_DEFINED