summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-06-06 17:56:41 -0700
committerRaph Levien <raph@google.com>2014-06-10 11:59:29 -0700
commit9a5f713add8cfb91ac2c9ed5c917309053201ab6 (patch)
tree7d6be261f3a7d30b0d7f14a66b2ff5e290e1bc4f /include
parent89566f0ada1cafe673efa064cde38467990235d4 (diff)
downloadandroid_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.tar.gz
android_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.tar.bz2
android_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.zip
Support for fake bold and italics
This patch adds support for computing when fake bold and fake italics are needed (because the styles are requested but not provided by the matching FontFamily), and providing them as part of the layout result. Part of the fix for bug 15436379 Fake bold doesn't fully work (Minikin) Change-Id: I180c034b559837943673b5c272c8e890178dff0d
Diffstat (limited to 'include')
-rw-r--r--include/minikin/FontCollection.h23
-rw-r--r--include/minikin/FontFamily.h21
-rw-r--r--include/minikin/Layout.h5
-rw-r--r--include/minikin/MinikinFont.h2
4 files changed, 30 insertions, 21 deletions
diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h
index 508a129..12700c6 100644
--- a/include/minikin/FontCollection.h
+++ b/include/minikin/FontCollection.h
@@ -32,24 +32,8 @@ public:
~FontCollection();
- class Run {
- public:
- // Do copy constructor, assignment, destructor so it can be used in vectors
- Run() : font(NULL) { }
- Run(const Run& other): font(other.font), start(other.start), end(other.end) {
- if (font) font->RefLocked();
- }
- Run& operator=(const Run& other) {
- if (other.font) other.font->RefLocked();
- if (font) font->UnrefLocked();
- font = other.font;
- start = other.start;
- end = other.end;
- return *this;
- }
- ~Run() { if (font) font->UnrefLocked(); }
-
- MinikinFont* font;
+ struct Run {
+ FakedFont fakedFont;
int start;
int end;
};
@@ -60,6 +44,9 @@ public:
// Get the base font for the given style, useful for font-wide metrics.
MinikinFont* baseFont(FontStyle style);
+ // Get base font with fakery information (fake bold could affect metrics)
+ FakedFont baseFontFaked(FontStyle style);
+
uint32_t getId() const;
private:
static const int kLogCharsPerPage = 8;
diff --git a/include/minikin/FontFamily.h b/include/minikin/FontFamily.h
index 6bdf5d6..060d167 100644
--- a/include/minikin/FontFamily.h
+++ b/include/minikin/FontFamily.h
@@ -94,6 +94,25 @@ inline hash_t hash_type(const FontStyle &style) {
return style.hash();
}
+// attributes representing transforms (fake bold, fake italic) to match styles
+class FontFakery {
+public:
+ FontFakery() : mFakeBold(false), mFakeItalic(false) { }
+ FontFakery(bool fakeBold, bool fakeItalic) : mFakeBold(fakeBold), mFakeItalic(fakeItalic) { }
+ // TODO: want to support graded fake bolding
+ bool isFakeBold() { return mFakeBold; }
+ bool isFakeItalic() { return mFakeItalic; }
+private:
+ bool mFakeBold;
+ bool mFakeItalic;
+};
+
+struct FakedFont {
+ // ownership is the enclosing FontCollection
+ MinikinFont* font;
+ FontFakery fakery;
+};
+
class FontFamily : public MinikinRefCounted {
public:
FontFamily() { }
@@ -107,7 +126,7 @@ public:
bool addFont(MinikinFont* typeface);
void addFont(MinikinFont* typeface, FontStyle style);
- MinikinFont* getClosestMatch(FontStyle style) const;
+ FakedFont getClosestMatch(FontStyle style) const;
FontLanguage lang() const { return mLang; }
int variant() const { return mVariant; }
diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h
index 91b8ef6..1b91ad8 100644
--- a/include/minikin/Layout.h
+++ b/include/minikin/Layout.h
@@ -87,6 +87,7 @@ public:
size_t nGlyphs() const;
// Does not bump reference; ownership is still layout
MinikinFont *getFont(int i) const;
+ FontFakery getFakery(int i) const;
unsigned int getGlyphId(int i) const;
float getX(int i) const;
float getY(int i) const;
@@ -101,7 +102,7 @@ public:
private:
// Find a face in the mFaces vector, or create a new entry
- int findFace(MinikinFont* face, LayoutContext* ctx);
+ int findFace(FakedFont face, LayoutContext* ctx);
// Lay out a single bidi run
void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
@@ -125,7 +126,7 @@ private:
std::vector<float> mAdvances;
const FontCollection* mCollection;
- std::vector<MinikinFont *> mFaces;
+ std::vector<FakedFont> mFaces;
float mAdvance;
MinikinRect mBounds;
};
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h
index 9ff08a9..7915ef2 100644
--- a/include/minikin/MinikinFont.h
+++ b/include/minikin/MinikinFont.h
@@ -18,6 +18,7 @@
#define MINIKIN_FONT_H
#include <minikin/MinikinRefCounted.h>
+#include <minikin/FontFamily.h>
// An abstraction for platform fonts, allowing Minikin to be used with
// multiple actual implementations of fonts.
@@ -34,6 +35,7 @@ struct MinikinPaint {
float scaleX;
float skewX;
uint32_t paintFlags;
+ FontFakery fakery;
};
struct MinikinRect {