Home | History | Annotate | Download | only in ports
      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 
      8 #include "SkFontConfigInterface.h"
      9 #include "SkFontHost_FreeType_common.h"
     10 #include "SkStream.h"
     11 #include "SkTypefaceCache.h"
     12 
     13 class SkFontDescriptor;
     14 
     15 class FontConfigTypeface : public SkTypeface_FreeType {
     16     SkFontConfigInterface::FontIdentity fIdentity;
     17     SkString fFamilyName;
     18     SkAutoTDelete<SkStreamAsset> fLocalStream;
     19 
     20 public:
     21     static FontConfigTypeface* Create(const SkFontStyle& style,
     22                                       const SkFontConfigInterface::FontIdentity& fi,
     23                                       const SkString& familyName) {
     24         return new FontConfigTypeface(style, fi, familyName);
     25     }
     26 
     27     static FontConfigTypeface* Create(const SkFontStyle& style, bool fixedWidth,
     28                                       SkStreamAsset* localStream) {
     29         return new FontConfigTypeface(style, fixedWidth, localStream);
     30     }
     31 
     32     const SkFontConfigInterface::FontIdentity& getIdentity() const {
     33         return fIdentity;
     34     }
     35 
     36     SkStreamAsset* getLocalStream() const { return fLocalStream.get(); }
     37 
     38     bool isFamilyName(const char* name) const {
     39         return fFamilyName.equals(name);
     40     }
     41 
     42     static SkTypeface* LegacyCreateTypeface(const char familyName[], SkTypeface::Style);
     43 
     44 protected:
     45     FontConfigTypeface(const SkFontStyle& style,
     46                        const SkFontConfigInterface::FontIdentity& fi,
     47                        const SkString& familyName)
     48             : INHERITED(style, SkTypefaceCache::NewFontID(), false)
     49             , fIdentity(fi)
     50             , fFamilyName(familyName)
     51             , fLocalStream(nullptr) {}
     52 
     53     FontConfigTypeface(const SkFontStyle& style, bool fixedWidth, SkStreamAsset* localStream)
     54             : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
     55             , fLocalStream(localStream) {
     56         // we default to empty fFamilyName and fIdentity
     57     }
     58 
     59     void onGetFamilyName(SkString* familyName) const override;
     60     void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
     61     SkStreamAsset* onOpenStream(int* ttcIndex) const override;
     62 
     63 private:
     64     typedef SkTypeface_FreeType INHERITED;
     65 };
     66