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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/ports/SkFontConfigInterface.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     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 SkFontConfigInterface_DEFINED
    1.12 +#define SkFontConfigInterface_DEFINED
    1.13 +
    1.14 +#include "SkDataTable.h"
    1.15 +#include "SkFontStyle.h"
    1.16 +#include "SkRefCnt.h"
    1.17 +#include "SkTArray.h"
    1.18 +#include "SkTypeface.h"
    1.19 +
    1.20 +/**
    1.21 + *  \class SkFontConfigInterface
    1.22 + *
    1.23 + *  Provides SkFontHost clients with access to fontconfig services. They will
    1.24 + *  access the global instance found in RefGlobal().
    1.25 + */
    1.26 +class SK_API SkFontConfigInterface : public SkRefCnt {
    1.27 +public:
    1.28 +    SK_DECLARE_INST_COUNT(SkFontConfigInterface)
    1.29 +
    1.30 +    /**
    1.31 +     *  Returns the global SkFontConfigInterface instance, and if it is not
    1.32 +     *  NULL, calls ref() on it. The caller must balance this with a call to
    1.33 +     *  unref().
    1.34 +     */
    1.35 +    static SkFontConfigInterface* RefGlobal();
    1.36 +
    1.37 +    /**
    1.38 +     *  Replace the current global instance with the specified one, safely
    1.39 +     *  ref'ing the new instance, and unref'ing the previous. Returns its
    1.40 +     *  parameter (the new global instance).
    1.41 +     */
    1.42 +    static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*);
    1.43 +
    1.44 +    /**
    1.45 +     *  This should be treated as private to the impl of SkFontConfigInterface.
    1.46 +     *  Callers should not change or expect any particular values. It is meant
    1.47 +     *  to be a union of possible storage types to aid the impl.
    1.48 +     */
    1.49 +    struct FontIdentity {
    1.50 +        FontIdentity() : fID(0), fTTCIndex(0) {}
    1.51 +
    1.52 +        bool operator==(const FontIdentity& other) const {
    1.53 +            return fID == other.fID &&
    1.54 +                   fTTCIndex == other.fTTCIndex &&
    1.55 +                   fString == other.fString;
    1.56 +        }
    1.57 +        bool operator!=(const FontIdentity& other) const {
    1.58 +            return !(*this == other);
    1.59 +        }
    1.60 +
    1.61 +        uint32_t    fID;
    1.62 +        int32_t     fTTCIndex;
    1.63 +        SkString    fString;
    1.64 +        SkFontStyle fStyle;
    1.65 +
    1.66 +        // If buffer is NULL, just return the number of bytes that would have
    1.67 +        // been written. Will pad contents to a multiple of 4.
    1.68 +        size_t writeToMemory(void* buffer = NULL) const;
    1.69 +
    1.70 +        // Recreate from a flattened buffer, returning the number of bytes read.
    1.71 +        size_t readFromMemory(const void* buffer, size_t length);
    1.72 +    };
    1.73 +
    1.74 +    /**
    1.75 +     *  Given a familyName and style, find the best match.
    1.76 +     *
    1.77 +     *  If a match is found, return true and set its outFontIdentifier.
    1.78 +     *      If outFamilyName is not null, assign the found familyName to it
    1.79 +     *          (which may differ from the requested familyName).
    1.80 +     *      If outStyle is not null, assign the found style to it
    1.81 +     *          (which may differ from the requested style).
    1.82 +     *
    1.83 +     *  If a match is not found, return false, and ignore all out parameters.
    1.84 +     */
    1.85 +    virtual bool matchFamilyName(const char familyName[],
    1.86 +                                 SkTypeface::Style requested,
    1.87 +                                 FontIdentity* outFontIdentifier,
    1.88 +                                 SkString* outFamilyName,
    1.89 +                                 SkTypeface::Style* outStyle) = 0;
    1.90 +
    1.91 +    /**
    1.92 +     *  Given a FontRef, open a stream to access its data, or return null
    1.93 +     *  if the FontRef's data is not available. The caller is responsible for
    1.94 +     *  calling stream->unref() when it is done accessing the data.
    1.95 +     */
    1.96 +    virtual SkStream* openStream(const FontIdentity&) = 0;
    1.97 +
    1.98 +    /**
    1.99 +     *  Return a singleton instance of a direct subclass that calls into
   1.100 +     *  libfontconfig. This does not affect the refcnt of the returned instance.
   1.101 +     */
   1.102 +    static SkFontConfigInterface* GetSingletonDirectInterface();
   1.103 +
   1.104 +    // New APIS, which have default impls for now (which do nothing)
   1.105 +
   1.106 +    virtual SkDataTable* getFamilyNames() { return SkDataTable::NewEmpty(); }
   1.107 +    virtual bool matchFamilySet(const char inFamilyName[],
   1.108 +                                SkString* outFamilyName,
   1.109 +                                SkTArray<FontIdentity>*) {
   1.110 +        return false;
   1.111 +    }
   1.112 +    typedef SkRefCnt INHERITED;
   1.113 +};
   1.114 +
   1.115 +#endif

mercurial