MinikinSkia.h revision ba3028c1fc9fca2d45acc841557da2c9a83923bf
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
18#define _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
19
20#include <cutils/compiler.h>
21#include <minikin/MinikinFont.h>
22#include <SkRefCnt.h>
23
24class SkPaint;
25class SkTypeface;
26
27namespace android {
28
29class ANDROID_API MinikinFontSkia : public minikin::MinikinFont {
30public:
31    explicit MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize,
32        int ttcIndex);
33
34    float GetHorizontalAdvance(uint32_t glyph_id,
35        const minikin::MinikinPaint &paint) const;
36
37    void GetBounds(minikin::MinikinRect* bounds, uint32_t glyph_id,
38        const minikin::MinikinPaint &paint) const;
39
40    SkTypeface* GetSkTypeface() const;
41    sk_sp<SkTypeface> RefSkTypeface() const;
42
43    // Access to underlying raw font bytes
44    const void* GetFontData() const;
45    size_t GetFontSize() const;
46    int GetFontIndex() const;
47    minikin::MinikinFont* createFontWithVariation(
48            const std::vector<minikin::FontVariation>&) const;
49
50    static uint32_t packPaintFlags(const SkPaint* paint);
51    static void unpackPaintFlags(SkPaint* paint, uint32_t paintFlags);
52
53    // set typeface and fake bold/italic parameters
54    static void populateSkPaint(SkPaint* paint, const minikin::MinikinFont* font,
55            minikin::FontFakery fakery);
56private:
57    sk_sp<SkTypeface> mTypeface;
58
59    // A raw pointer to the font data - it should be owned by some other object with
60    // lifetime at least as long as this object.
61    const void* mFontData;
62    size_t mFontSize;
63    int mTtcIndex;
64};
65
66}  // namespace android
67
68#endif  // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
69