summaryrefslogtreecommitdiffstats
path: root/include
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
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')
-rw-r--r--include/minikin/Layout.h26
-rw-r--r--include/minikin/MinikinFont.h28
2 files changed, 50 insertions, 4 deletions
diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h
index fd0ed75..896478b 100644
--- a/include/minikin/Layout.h
+++ b/include/minikin/Layout.h
@@ -57,32 +57,50 @@ struct LayoutGlyph {
class Layout {
public:
+
void dump() const;
- void setFontCollection(const FontCollection *collection);
+ void setFontCollection(const FontCollection* collection);
void doLayout(const uint16_t* buf, size_t nchars);
void draw(Bitmap*, int x0, int y0) const;
void setProperties(const std::string css);
- float getAdvance() const;
-
// This must be called before any invocations.
// TODO: probably have a factory instead
static void init();
+
+ // public accessors
+ size_t nGlyphs() const;
+ // Does not bump reference; ownership is still layout
+ MinikinFont *getFont(int i) const;
+ unsigned int getGlyphId(int i) const;
+ float getX(int i) const;
+ float getY(int i) const;
+
+ float getAdvance() const;
+
+ // Get advances, copying into caller-provided buffer. The size of this
+ // buffer must match the length of the string (nchars arg to doLayout).
+ void getAdvances(float* advances);
+
+ void getBounds(MinikinRect* rect);
+
private:
// Find a face in the mFaces vector, or create a new entry
int findFace(MinikinFont* face, MinikinPaint* paint);
CssProperties mProps; // TODO: want spans
std::vector<LayoutGlyph> mGlyphs;
+ std::vector<float> mAdvances;
// In future, this will be some kind of mapping from the
// identifier used to represent font-family to a font collection.
// But for the time being, it should be ok to have just one
// per layout.
- const FontCollection *mCollection;
+ const FontCollection* mCollection;
std::vector<MinikinFont *> mFaces;
std::vector<hb_font_t *> mHbFonts;
float mAdvance;
+ MinikinRect mBounds;
};
} // namespace android
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;