gfx/skia/trunk/include/ports/SkFontMgr.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/ports/SkFontMgr.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkFontMgr_DEFINED
    1.12 +#define SkFontMgr_DEFINED
    1.13 +
    1.14 +#include "SkRefCnt.h"
    1.15 +#include "SkFontStyle.h"
    1.16 +
    1.17 +class SkData;
    1.18 +class SkStream;
    1.19 +class SkString;
    1.20 +class SkTypeface;
    1.21 +
    1.22 +class SK_API SkFontStyleSet : public SkRefCnt {
    1.23 +public:
    1.24 +    SK_DECLARE_INST_COUNT(SkFontStyleSet)
    1.25 +
    1.26 +    virtual int count() = 0;
    1.27 +    virtual void getStyle(int index, SkFontStyle*, SkString* style) = 0;
    1.28 +    virtual SkTypeface* createTypeface(int index) = 0;
    1.29 +    virtual SkTypeface* matchStyle(const SkFontStyle& pattern) = 0;
    1.30 +
    1.31 +    static SkFontStyleSet* CreateEmpty();
    1.32 +
    1.33 +private:
    1.34 +    typedef SkRefCnt INHERITED;
    1.35 +};
    1.36 +
    1.37 +class SkTypeface;
    1.38 +
    1.39 +class SK_API SkFontMgr : public SkRefCnt {
    1.40 +public:
    1.41 +    SK_DECLARE_INST_COUNT(SkFontMgr)
    1.42 +
    1.43 +    int countFamilies() const;
    1.44 +    void getFamilyName(int index, SkString* familyName) const;
    1.45 +    SkFontStyleSet* createStyleSet(int index) const;
    1.46 +
    1.47 +    /**
    1.48 +     *  The caller must call unref() on the returned object.
    1.49 +     *  Never returns NULL; will return an empty set if the name is not found.
    1.50 +     */
    1.51 +    SkFontStyleSet* matchFamily(const char familyName[]) const;
    1.52 +
    1.53 +    /**
    1.54 +     *  Find the closest matching typeface to the specified familyName and style
    1.55 +     *  and return a ref to it. The caller must call unref() on the returned
    1.56 +     *  object. Will never return NULL, as it will return the default font if
    1.57 +     *  no matching font is found.
    1.58 +     */
    1.59 +    SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&) const;
    1.60 +
    1.61 +    SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const;
    1.62 +
    1.63 +    /**
    1.64 +     *  Create a typeface for the specified data and TTC index (pass 0 for none)
    1.65 +     *  or NULL if the data is not recognized. The caller must call unref() on
    1.66 +     *  the returned object if it is not null.
    1.67 +     */
    1.68 +    SkTypeface* createFromData(SkData*, int ttcIndex = 0) const;
    1.69 +
    1.70 +    /**
    1.71 +     *  Create a typeface for the specified stream and TTC index
    1.72 +     *  (pass 0 for none) or NULL if the stream is not recognized. The caller
    1.73 +     *  must call unref() on the returned object if it is not null.
    1.74 +     */
    1.75 +    SkTypeface* createFromStream(SkStream*, int ttcIndex = 0) const;
    1.76 +
    1.77 +    /**
    1.78 +     *  Create a typeface for the specified fileName and TTC index
    1.79 +     *  (pass 0 for none) or NULL if the file is not found, or its contents are
    1.80 +     *  not recognized. The caller must call unref() on the returned object
    1.81 +     *  if it is not null.
    1.82 +     */
    1.83 +    SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const;
    1.84 +
    1.85 +    SkTypeface* legacyCreateTypeface(const char familyName[],
    1.86 +                                     unsigned typefaceStyleBits) const;
    1.87 +
    1.88 +    /**
    1.89 +     *  Return a ref to the default fontmgr. The caller must call unref() on
    1.90 +     *  the returned object.
    1.91 +     */
    1.92 +    static SkFontMgr* RefDefault();
    1.93 +
    1.94 +protected:
    1.95 +    virtual int onCountFamilies() const = 0;
    1.96 +    virtual void onGetFamilyName(int index, SkString* familyName) const = 0;
    1.97 +    virtual SkFontStyleSet* onCreateStyleSet(int index)const  = 0;
    1.98 +
    1.99 +    /** May return NULL if the name is not found. */
   1.100 +    virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const = 0;
   1.101 +
   1.102 +    virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
   1.103 +                                           const SkFontStyle&) const = 0;
   1.104 +    virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
   1.105 +                                         const SkFontStyle&) const = 0;
   1.106 +
   1.107 +    virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0;
   1.108 +    virtual SkTypeface* onCreateFromStream(SkStream*, int ttcIndex) const = 0;
   1.109 +    virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;
   1.110 +
   1.111 +    virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
   1.112 +                                               unsigned styleBits) const = 0;
   1.113 +private:
   1.114 +    static SkFontMgr* Factory();    // implemented by porting layer
   1.115 +    friend void set_up_default(SkFontMgr** singleton);
   1.116 +
   1.117 +    typedef SkRefCnt INHERITED;
   1.118 +};
   1.119 +
   1.120 +#endif

mercurial