2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrGlyph_DEFINED
|
|
|
|
#define GrGlyph_DEFINED
|
|
|
|
|
|
|
|
#include "GrRect.h"
|
2012-04-27 15:52:53 +00:00
|
|
|
#include "SkPath.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2013-09-27 19:39:38 +00:00
|
|
|
class GrPlot;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/* Need this to be quad-state:
|
|
|
|
- complete w/ image
|
|
|
|
- just metrics
|
|
|
|
- failed to get image, but has metrics
|
|
|
|
- failed to get metrics
|
|
|
|
*/
|
|
|
|
struct GrGlyph {
|
|
|
|
typedef uint32_t PackedID;
|
|
|
|
|
2013-09-27 19:39:38 +00:00
|
|
|
GrPlot* fPlot;
|
2012-04-27 15:52:53 +00:00
|
|
|
SkPath* fPath;
|
2010-12-22 21:39:39 +00:00
|
|
|
PackedID fPackedID;
|
|
|
|
GrIRect16 fBounds;
|
|
|
|
GrIPoint16 fAtlasLocation;
|
|
|
|
|
2013-07-17 21:39:42 +00:00
|
|
|
void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
|
2013-09-27 19:39:38 +00:00
|
|
|
fPlot = NULL;
|
2010-12-22 21:39:39 +00:00
|
|
|
fPath = NULL;
|
|
|
|
fPackedID = packed;
|
|
|
|
fBounds.set(bounds);
|
|
|
|
fAtlasLocation.set(0, 0);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
void free() {
|
|
|
|
if (fPath) {
|
|
|
|
delete fPath;
|
|
|
|
fPath = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
int width() const { return fBounds.width(); }
|
|
|
|
int height() const { return fBounds.height(); }
|
|
|
|
bool isEmpty() const { return fBounds.isEmpty(); }
|
|
|
|
uint16_t glyphID() const { return UnpackID(fPackedID); }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) {
|
|
|
|
// two most significant fraction bits from fixed-point
|
|
|
|
return (pos >> 14) & 3;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) {
|
|
|
|
x = ExtractSubPixelBitsFromFixed(x);
|
|
|
|
y = ExtractSubPixelBitsFromFixed(y);
|
|
|
|
return (x << 18) | (y << 16) | glyphID;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
static inline GrFixed UnpackFixedX(PackedID packed) {
|
|
|
|
return ((packed >> 18) & 3) << 14;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
static inline GrFixed UnpackFixedY(PackedID packed) {
|
|
|
|
return ((packed >> 16) & 3) << 14;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
static inline uint16_t UnpackID(PackedID packed) {
|
|
|
|
return (uint16_t)packed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|