• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 class SkPaint;
25 class SkTypeface;
26 
27 namespace android {
28 
29 class ANDROID_API MinikinFontSkia : public minikin::MinikinFont {
30 public:
31     explicit MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize,
32         int ttcIndex, const std::vector<minikin::FontVariation>& axes);
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     const std::vector<minikin::FontVariation>& GetAxes() const;
48     std::shared_ptr<minikin::MinikinFont> createFontWithVariation(
49             const std::vector<minikin::FontVariation>&) const;
50 
51     static uint32_t packPaintFlags(const SkPaint* paint);
52     static void unpackPaintFlags(SkPaint* paint, uint32_t paintFlags);
53 
54     // set typeface and fake bold/italic parameters
55     static void populateSkPaint(SkPaint* paint, const minikin::MinikinFont* font,
56             minikin::FontFakery fakery);
57 private:
58     sk_sp<SkTypeface> mTypeface;
59 
60     // A raw pointer to the font data - it should be owned by some other object with
61     // lifetime at least as long as this object.
62     const void* mFontData;
63     size_t mFontSize;
64     int mTtcIndex;
65     std::vector<minikin::FontVariation> mAxes;
66 };
67 
68 }  // namespace android
69 
70 #endif  // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
71