summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-04-16 15:27:12 -0700
committerJohn Reck <jreck@google.com>2015-04-27 17:23:29 +0000
commit8920e81717c6e51b92ff8f4479a1f959af260556 (patch)
tree3b2e119d4c5dbd14500898fabefa8467897d8608
parent68ae337aa05f598af18b09fe4125146d4d67db83 (diff)
downloadandroid_frameworks_minikin-8920e81717c6e51b92ff8f4479a1f959af260556.tar.gz
android_frameworks_minikin-8920e81717c6e51b92ff8f4479a1f959af260556.tar.bz2
android_frameworks_minikin-8920e81717c6e51b92ff8f4479a1f959af260556.zip
Move Bitmap to a different namespace
namespace naming collision. Move minikin's Bitmap out of android:: and into minikin:: Change-Id: I5ae3925f81b848dc79576429ab55243b96f7fed2
-rw-r--r--include/minikin/Layout.h10
-rw-r--r--libs/minikin/Layout.cpp82
-rw-r--r--sample/example.cpp8
3 files changed, 53 insertions, 47 deletions
diff --git a/include/minikin/Layout.h b/include/minikin/Layout.h
index 930407a..cdf4aac 100644
--- a/include/minikin/Layout.h
+++ b/include/minikin/Layout.h
@@ -24,7 +24,7 @@
#include <minikin/FontCollection.h>
#include <minikin/MinikinFontFreeType.h>
-namespace android {
+namespace minikin {
// The Bitmap class is for debugging. We'll probably move it out
// of here into a separate lightweight software rendering module
@@ -34,13 +34,17 @@ public:
Bitmap(int width, int height);
~Bitmap();
void writePnm(std::ofstream& o) const;
- void drawGlyph(const GlyphBitmap& bitmap, int x, int y);
+ void drawGlyph(const android::GlyphBitmap& bitmap, int x, int y);
private:
int width;
int height;
uint8_t* buf;
};
+} // namespace minikin
+
+namespace android {
+
struct LayoutGlyph {
// index into mFaces and mHbFonts vectors. We could imagine
// moving this into a run length representation, because it's
@@ -89,7 +93,7 @@ public:
void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
int bidiFlags, const FontStyle &style, const MinikinPaint &paint);
- void draw(Bitmap*, int x0, int y0, float size) const;
+ void draw(minikin::Bitmap*, int x0, int y0, float size) const;
// Deprecated. Nont needed. Remove when callers are removed.
static void init();
diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp
index 28dac7f..88baeac 100644
--- a/libs/minikin/Layout.cpp
+++ b/libs/minikin/Layout.cpp
@@ -41,6 +41,48 @@
using std::string;
using std::vector;
+namespace minikin {
+
+Bitmap::Bitmap(int width, int height) : width(width), height(height) {
+ buf = new uint8_t[width * height]();
+}
+
+Bitmap::~Bitmap() {
+ delete[] buf;
+}
+
+void Bitmap::writePnm(std::ofstream &o) const {
+ o << "P5" << std::endl;
+ o << width << " " << height << std::endl;
+ o << "255" << std::endl;
+ o.write((const char *)buf, width * height);
+ o.close();
+}
+
+void Bitmap::drawGlyph(const android::GlyphBitmap& bitmap, int x, int y) {
+ int bmw = bitmap.width;
+ int bmh = bitmap.height;
+ x += bitmap.left;
+ y -= bitmap.top;
+ int x0 = std::max(0, x);
+ int x1 = std::min(width, x + bmw);
+ int y0 = std::max(0, y);
+ int y1 = std::min(height, y + bmh);
+ const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x);
+ uint8_t* dst = buf + y0 * width;
+ for (int yy = y0; yy < y1; yy++) {
+ for (int xx = x0; xx < x1; xx++) {
+ int pixel = (int)dst[xx] + (int)src[xx - x];
+ pixel = pixel > 0xff ? 0xff : pixel;
+ dst[xx] = pixel;
+ }
+ src += bmw;
+ dst += width;
+ }
+}
+
+} // namespace minikin
+
namespace android {
const int kDirection_Mask = 0x1;
@@ -218,44 +260,6 @@ hash_t hash_type(const LayoutCacheKey& key) {
return key.hash();
}
-Bitmap::Bitmap(int width, int height) : width(width), height(height) {
- buf = new uint8_t[width * height]();
-}
-
-Bitmap::~Bitmap() {
- delete[] buf;
-}
-
-void Bitmap::writePnm(std::ofstream &o) const {
- o << "P5" << std::endl;
- o << width << " " << height << std::endl;
- o << "255" << std::endl;
- o.write((const char *)buf, width * height);
- o.close();
-}
-
-void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) {
- int bmw = bitmap.width;
- int bmh = bitmap.height;
- x += bitmap.left;
- y -= bitmap.top;
- int x0 = std::max(0, x);
- int x1 = std::min(width, x + bmw);
- int y0 = std::max(0, y);
- int y1 = std::min(height, y + bmh);
- const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x);
- uint8_t* dst = buf + y0 * width;
- for (int yy = y0; yy < y1; yy++) {
- for (int xx = x0; xx < x1; xx++) {
- int pixel = (int)dst[xx] + (int)src[xx - x];
- pixel = pixel > 0xff ? 0xff : pixel;
- dst[xx] = pixel;
- }
- src += bmw;
- dst += width;
- }
-}
-
void MinikinRect::join(const MinikinRect& r) {
if (isEmpty()) {
set(r);
@@ -814,7 +818,7 @@ void Layout::appendLayout(Layout* src, size_t start) {
}
}
-void Layout::draw(Bitmap* surface, int x0, int y0, float size) const {
+void Layout::draw(minikin::Bitmap* surface, int x0, int y0, float size) const {
/*
TODO: redo as MinikinPaint settings
if (mProps.hasTag(minikinHinting)) {
diff --git a/sample/example.cpp b/sample/example.cpp
index 487357a..3fbfa79 100644
--- a/sample/example.cpp
+++ b/sample/example.cpp
@@ -28,8 +28,8 @@
#include <minikin/Layout.h>
using std::vector;
-
-namespace android {
+using namespace android;
+using namespace minikin;
FT_Library library; // TODO: this should not be a global
@@ -99,8 +99,6 @@ int runMinikinTest() {
return 0;
}
-}
-
int main(int argc, const char** argv) {
- return android::runMinikinTest();
+ return runMinikinTest();
}