• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright 2010 Google Inc.
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 
18 #ifndef GrGlyph_DEFINED
19 #define GrGlyph_DEFINED
20 
21 #include "GrPath.h"
22 #include "GrRect.h"
23 
24 class GrAtlas;
25 
26 /*  Need this to be quad-state:
27     - complete w/ image
28     - just metrics
29     - failed to get image, but has metrics
30     - failed to get metrics
31  */
32 struct GrGlyph {
33     typedef uint32_t PackedID;
34 
35     GrAtlas*    fAtlas;
36     GrPath*     fPath;
37     PackedID    fPackedID;
38     GrIRect16   fBounds;
39     GrIPoint16  fAtlasLocation;
40 
initGrGlyph41     void init(GrGlyph::PackedID packed, const GrIRect& bounds) {
42         fAtlas = NULL;
43         fPath = NULL;
44         fPackedID = packed;
45         fBounds.set(bounds);
46         fAtlasLocation.set(0, 0);
47     }
48 
freeGrGlyph49     void free() {
50         if (fPath) {
51             delete fPath;
52             fPath = NULL;
53         }
54     }
55 
widthGrGlyph56     int width() const { return fBounds.width(); }
heightGrGlyph57     int height() const { return fBounds.height(); }
isEmptyGrGlyph58     bool isEmpty() const { return fBounds.isEmpty(); }
glyphIDGrGlyph59     uint16_t glyphID() const { return UnpackID(fPackedID); }
60 
61     ///////////////////////////////////////////////////////////////////////////
62 
ExtractSubPixelBitsFromFixedGrGlyph63     static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) {
64         // two most significant fraction bits from fixed-point
65         return (pos >> 14) & 3;
66     }
67 
PackGrGlyph68     static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) {
69         x = ExtractSubPixelBitsFromFixed(x);
70         y = ExtractSubPixelBitsFromFixed(y);
71         return (x << 18) | (y << 16) | glyphID;
72     }
73 
UnpackFixedXGrGlyph74     static inline GrFixed UnpackFixedX(PackedID packed) {
75         return ((packed >> 18) & 3) << 14;
76     }
77 
UnpackFixedYGrGlyph78     static inline GrFixed UnpackFixedY(PackedID packed) {
79         return ((packed >> 16) & 3) << 14;
80     }
81 
UnpackIDGrGlyph82     static inline uint16_t UnpackID(PackedID packed) {
83         return (uint16_t)packed;
84     }
85 };
86 
87 
88 #endif
89 
90