• 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 
23 class SkPaint;
24 class SkTypeface;
25 
26 namespace android {
27 
28 class ANDROID_API MinikinFontSkia : public MinikinFont {
29 public:
30     // Note: this takes ownership of the reference (will unref on dtor)
31     explicit MinikinFontSkia(SkTypeface *typeface, const void* fontData, size_t fontSize,
32         int ttcIndex);
33 
34     ~MinikinFontSkia();
35 
36     float GetHorizontalAdvance(uint32_t glyph_id,
37         const MinikinPaint &paint) const;
38 
39     void GetBounds(MinikinRect* bounds, uint32_t glyph_id,
40         const MinikinPaint &paint) const;
41 
42     const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy);
43 
44     SkTypeface* GetSkTypeface() const;
45 
46     // Access to underlying raw font bytes
47     const void* GetFontData() const;
48     size_t GetFontSize() const;
49     int GetFontIndex() 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 MinikinFont* font, FontFakery fakery);
56 private:
57     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