summaryrefslogtreecommitdiffstats
path: root/include/minikin/MinikinFont.h
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2013-07-15 14:19:59 -0700
committerRaph Levien <raph@google.com>2014-05-12 09:08:15 -0700
commitecc2d34ac23a497988f21e5f415b53c007b9d8c5 (patch)
tree876b3c943b7841c9600db636738cd0e59b5f2a7c /include/minikin/MinikinFont.h
parent5adafc0d84d238948b5d257ec5311030ca04271c (diff)
downloadandroid_frameworks_minikin-ecc2d34ac23a497988f21e5f415b53c007b9d8c5.tar.gz
android_frameworks_minikin-ecc2d34ac23a497988f21e5f415b53c007b9d8c5.tar.bz2
android_frameworks_minikin-ecc2d34ac23a497988f21e5f415b53c007b9d8c5.zip
A basket of features: itemization, bounds, refcount
This patch improves script run itemization and also exposes metrics and bounds for layouts. In addition, there is a fair amount of internal cleanup, including ref counting, and making the MinikinFont abstraction strong enough to support both FreeType and Skia implementations. There is also a sample implementation using Skia, in the sample directory. As part of its functionality, his patch measures the bounds of the layout and gives access through Layout::GetBounds(). The corresponding method is not implemented in the FreeType-only implementation of MinikinFont, so that will probably have to be fixed. Change-Id: Ib1a3fe9d7c90519ac651fb4aa957848e4bb758ec
Diffstat (limited to 'include/minikin/MinikinFont.h')
-rw-r--r--include/minikin/MinikinFont.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h
index c08e4fe..e84f5df 100644
--- a/include/minikin/MinikinFont.h
+++ b/include/minikin/MinikinFont.h
@@ -31,6 +31,29 @@ struct MinikinPaint {
// todo: skew, stretch, hinting
};
+struct MinikinRect {
+ float mLeft, mTop, mRight, mBottom;
+ bool isEmpty() const {
+ return mLeft == mRight || mTop == mBottom;
+ }
+ void set(const MinikinRect& r) {
+ mLeft = r.mLeft;
+ mTop = r.mTop;
+ mRight = r.mRight;
+ mBottom = r.mBottom;
+ }
+ void offset(float dx, float dy) {
+ mLeft += dx;
+ mTop += dy;
+ mRight += dx;
+ mBottom += dy;
+ }
+ void setEmpty() {
+ mLeft = mTop = mRight = mBottom = 0;
+ }
+ void join(const MinikinRect& r);
+};
+
class MinikinFontFreeType;
class MinikinFont {
@@ -38,6 +61,8 @@ public:
void Ref() { mRefcount_++; }
void Unref() { if (--mRefcount_ == 0) { delete this; } }
+ MinikinFont() : mRefcount_(1) { }
+
virtual ~MinikinFont() { };
virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0;
@@ -45,6 +70,9 @@ public:
virtual float GetHorizontalAdvance(uint32_t glyph_id,
const MinikinPaint &paint) const = 0;
+ virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id,
+ const MinikinPaint &paint) const = 0;
+
// If buf is NULL, just update size
virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0;