gfx/skia/trunk/src/sfnt/SkOTUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/sfnt/SkOTUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/*
     1.5 + * Copyright 2012 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 SkOTUtils_DEFINED
    1.12 +#define SkOTUtils_DEFINED
    1.13 +
    1.14 +#include "SkOTTableTypes.h"
    1.15 +#include "SkOTTable_name.h"
    1.16 +#include "SkTypeface.h"
    1.17 +
    1.18 +class SkData;
    1.19 +class SkStream;
    1.20 +
    1.21 +struct SkOTUtils {
    1.22 +    /**
    1.23 +      *  Calculates the OpenType checksum for data.
    1.24 +      */
    1.25 +    static uint32_t CalcTableChecksum(SK_OT_ULONG *data, size_t length);
    1.26 +
    1.27 +    /**
    1.28 +      *  Renames an sfnt font. On failure (invalid data or not an sfnt font)
    1.29 +      *  returns NULL.
    1.30 +      *
    1.31 +      *  Essentially, this removes any existing 'name' table and replaces it
    1.32 +      *  with a new one in which FontFamilyName, FontSubfamilyName,
    1.33 +      *  UniqueFontIdentifier, FullFontName, and PostscriptName are fontName.
    1.34 +      *
    1.35 +      *  The new 'name' table records will be written with the Windows,
    1.36 +      *  UnicodeBMPUCS2, and English_UnitedStates settings.
    1.37 +      *
    1.38 +      *  fontName and fontNameLen must be specified in terms of ASCII chars.
    1.39 +      */
    1.40 +    static SkData* RenameFont(SkStream* fontData, const char* fontName, int fontNameLen);
    1.41 +
    1.42 +    /** An implementation of LocalizedStrings which obtains it's data from a 'name' table. */
    1.43 +    class LocalizedStrings_NameTable : public SkTypeface::LocalizedStrings {
    1.44 +    public:
    1.45 +        /** Takes ownership of the nameTableData and will free it with SK_DELETE. */
    1.46 +        LocalizedStrings_NameTable(SkOTTableName* nameTableData,
    1.47 +                                   SkOTTableName::Record::NameID::Predefined::Value types[],
    1.48 +                                   int typesCount)
    1.49 +            : fTypes(types), fTypesCount(typesCount), fTypesIndex(0)
    1.50 +            , fNameTableData(nameTableData), fFamilyNameIter(*nameTableData, fTypes[fTypesIndex])
    1.51 +        { }
    1.52 +
    1.53 +        /** Creates an iterator over all the family names in the 'name' table of a typeface.
    1.54 +         *  If no valid 'name' table can be found, returns NULL.
    1.55 +         */
    1.56 +        static LocalizedStrings_NameTable* CreateForFamilyNames(const SkTypeface& typeface);
    1.57 +
    1.58 +        virtual bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE;
    1.59 +    private:
    1.60 +        static SkOTTableName::Record::NameID::Predefined::Value familyNameTypes[3];
    1.61 +
    1.62 +        SkOTTableName::Record::NameID::Predefined::Value* fTypes;
    1.63 +        int fTypesCount;
    1.64 +        int fTypesIndex;
    1.65 +        SkAutoTDeleteArray<SkOTTableName> fNameTableData;
    1.66 +        SkOTTableName::Iterator fFamilyNameIter;
    1.67 +    };
    1.68 +
    1.69 +    /** An implementation of LocalizedStrings which has one name. */
    1.70 +    class LocalizedStrings_SingleName : public SkTypeface::LocalizedStrings {
    1.71 +    public:
    1.72 +        LocalizedStrings_SingleName(SkString name, SkString language)
    1.73 +            : fName(name), fLanguage(language), fHasNext(true)
    1.74 +        { }
    1.75 +
    1.76 +        virtual bool next(SkTypeface::LocalizedString* localizedString) SK_OVERRIDE {
    1.77 +            localizedString->fString = fName;
    1.78 +            localizedString->fLanguage = fLanguage;
    1.79 +
    1.80 +            bool hadNext = fHasNext;
    1.81 +            fHasNext = false;
    1.82 +            return hadNext;
    1.83 +        }
    1.84 +
    1.85 +    private:
    1.86 +        SkString fName;
    1.87 +        SkString fLanguage;
    1.88 +        bool fHasNext;
    1.89 +    };
    1.90 +};
    1.91 +
    1.92 +#endif

mercurial