summaryrefslogtreecommitdiffstats
path: root/sample
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-14 11:01:32 -0700
committerRaph Levien <raph@google.com>2014-05-14 11:01:32 -0700
commitd133eab2a1a59ce4a5b1b3db04ec00dc0dbdf349 (patch)
tree14c44fed92e72bfee3f8bb220073233cac6f99f5 /sample
parentb80c1f19c58b927820a8a24bf2218e5645724608 (diff)
downloadandroid_frameworks_minikin-d133eab2a1a59ce4a5b1b3db04ec00dc0dbdf349.tar.gz
android_frameworks_minikin-d133eab2a1a59ce4a5b1b3db04ec00dc0dbdf349.tar.bz2
android_frameworks_minikin-d133eab2a1a59ce4a5b1b3db04ec00dc0dbdf349.zip
Fix build breakage in sample code
This updates the Skia sample implementation to implement GetBounds, but the FreeType implementation is NYI (to be fixed in future commit). Change-Id: I24eda14d5fb11c2a1e81394ad8c779de3292dd79
Diffstat (limited to 'sample')
-rw-r--r--sample/MinikinSkia.cpp35
-rw-r--r--sample/MinikinSkia.h3
2 files changed, 29 insertions, 9 deletions
diff --git a/sample/MinikinSkia.cpp b/sample/MinikinSkia.cpp
index d67e59f..8b499d8 100644
--- a/sample/MinikinSkia.cpp
+++ b/sample/MinikinSkia.cpp
@@ -25,22 +25,39 @@ bool MinikinFontSkia::GetGlyph(uint32_t codepoint, uint32_t *glyph) const {
return !!glyph;
}
+static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) {
+ skPaint->setTypeface(typeface);
+ skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ // TODO: set more paint parameters from Minikin
+ skPaint->setTextSize(paint.size);
+}
+
float MinikinFontSkia::GetHorizontalAdvance(uint32_t glyph_id,
const MinikinPaint &paint) const {
- SkPaint skpaint;
- skpaint.setTypeface(mTypeface);
- skpaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- // TODO: set paint from Minikin
- skpaint.setTextSize(100);
+ SkPaint skPaint;
uint16_t glyph16 = glyph_id;
SkScalar skWidth;
- SkRect skBounds;
- skpaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, &skBounds);
- // bounds?
- //printf("advance for glyph %d = %f\n", glyph_id, SkScalarToFP(skWidth));
+ MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint);
+ skPaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, NULL);
+#ifdef VERBOSE
+ ALOGD("width for typeface %d glyph %d = %f", mTypeface->uniqueID(), glyph_id
+#endif
return skWidth;
}
+void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id,
+ const MinikinPaint& paint) const {
+ SkPaint skPaint;
+ uint16_t glyph16 = glyph_id;
+ SkRect skBounds;
+ MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint);
+ skPaint.getTextWidths(&glyph16, sizeof(glyph16), NULL, &skBounds);
+ bounds->mLeft = skBounds.fLeft;
+ bounds->mTop = skBounds.fTop;
+ bounds->mRight = skBounds.fRight;
+ bounds->mBottom = skBounds.fBottom;
+}
+
bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) {
if (buf == NULL) {
const size_t tableSize = mTypeface->getTableSize(tag);
diff --git a/sample/MinikinSkia.h b/sample/MinikinSkia.h
index 8286a4c..fca6ca2 100644
--- a/sample/MinikinSkia.h
+++ b/sample/MinikinSkia.h
@@ -11,6 +11,9 @@ public:
float GetHorizontalAdvance(uint32_t glyph_id,
const MinikinPaint &paint) const;
+ void GetBounds(MinikinRect* bounds, uint32_t glyph_id,
+ const MinikinPaint& paint) const;
+
// If buf is NULL, just update size
bool GetTable(uint32_t tag, uint8_t *buf, size_t *size);