Move Bitmap to a different namespace
namespace naming collision. Move minikin's Bitmap out of android:: and into minikin:: Change-Id: I5ae3925f81b848dc79576429ab55243b96f7fed2
This commit is contained in:
parent
d24df3eb94
commit
1be122da96
@ -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();
|
||||
|
@ -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)) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user