summaryrefslogtreecommitdiff
path: root/plugingui/font.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-01-26 08:52:06 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-01-26 08:52:06 +0100
commit2acc10e603353ec6d520654b448f789a61bd6185 (patch)
treee61afaa1d7f128679aed10ed8ff48e2e3f93ef8c /plugingui/font.cc
parentbe628876b0515ceee40946e923771e1b40d6641b (diff)
Experimental new font renderer.
Diffstat (limited to 'plugingui/font.cc')
-rw-r--r--plugingui/font.cc76
1 files changed, 45 insertions, 31 deletions
diff --git a/plugingui/font.cc b/plugingui/font.cc
index 8e56684..38b1b3e 100644
--- a/plugingui/font.cc
+++ b/plugingui/font.cc
@@ -34,6 +34,35 @@
GUI::Font::Font()
{
+ int px = 0;
+ int c;
+ for(c = 0; c < 255 && px < (int)img_font.width; c++) {
+ character_offset[c] = px + 1;
+ character_pre_bias[c] = 0;
+ character_post_bias[c] = 0;
+ if(c == 't') {
+ character_pre_bias[c] = -1;
+ character_post_bias[c] = -1;
+ }
+ if(c == 'L') character_post_bias[c] = -1;
+ if(c == 'o') character_post_bias[c] = -1;
+ if(c == 'K') character_post_bias[c] = -1;
+ if(c == 'r') character_post_bias[c] = -1;
+ if(c == 'i') character_post_bias[c] = 1;
+ if(c == 'w') character_post_bias[c] = -1;
+ if(c == 'h') character_post_bias[c] = -1;
+ if(c == '.') {
+ character_pre_bias[c] = -1;
+ character_post_bias[c] = -1;
+ }
+ if(c > 0) {
+ character_width[c - 1] = character_offset[c] - character_offset[c - 1] - 1;
+ }
+ px++;
+ while(img_font.pixels[px] != 0xff00ffff) { px++; }
+ }
+ c++;
+ character_width[c - 1] = character_offset[c] - character_offset[c - 1] - 1;
}
void GUI::Font::setFace(std::string face)
@@ -43,7 +72,7 @@ void GUI::Font::setFace(std::string face)
std::string GUI::Font::face()
{
- return "";
+ return "";//face;
}
void GUI::Font::setSize(size_t points)
@@ -58,8 +87,14 @@ size_t GUI::Font::size()
size_t GUI::Font::textWidth(std::string text)
{
- size_t fw = img_font.width / 255;
- return fw * text.length();
+ size_t len = 0;
+
+ for(size_t i = 0; i < text.length(); i++) {
+ unsigned int cha = text[i];
+ len += character_width[(char)cha] + 1 + character_post_bias[(char)cha];
+ }
+
+ return len;
}
size_t GUI::Font::textHeight(std::string text)
@@ -69,48 +104,27 @@ size_t GUI::Font::textHeight(std::string text)
GUI::PixelBufferAlpha *GUI::Font::render(GlobalContext *gctx, std::string text)
{
+ int border = 1;
PixelBufferAlpha *pb =
new PixelBufferAlpha(textWidth(text), textHeight(text));
- size_t fw = img_font.width / 255;
+ int x_offset = 0;
for(size_t i = 0; i < text.length(); i++) {
unsigned int cha = text[i];
- for(size_t x = 0; x < fw; x++) {
+ for(size_t x = 0; x < character_width[(char)cha]; x++) {
for(size_t y = 0; y < img_font.height; y++) {
- unsigned int pixel = img_font.pixels[(x + (cha * fw)) + y * img_font.width];
+ //unsigned int pixel = img_font.pixels[(x + (cha * fw)) + y * img_font.width];
+ unsigned int pixel = img_font.pixels[(x + (character_offset[(char)cha])) + y * img_font.width];
unsigned int order = img_font.order;
unsigned char *c = (unsigned char *)&pixel;
unsigned char *o = (unsigned char *)&order;
- pb->setPixel(x + i * (fw), y,
+ pb->setPixel(x + x_offset + character_pre_bias[(char)cha], y,
c[o[1]], c[o[2]], c[o[3]], c[o[0]]);
}
}
+ x_offset += character_width[(char)cha] + border + character_post_bias[(char)cha];
}
- /*
- for(size_t i = 0; i < text.length(); i++) {
- for(size_t x = 0; x < WIDTH; x++) {
- for(size_t y = 0; y < HEIGHT; y++) {
- pb->setPixel(x + i * (WIDTH + BORDER), y, 255, 255, 255, 255);
- }
- }
- }
- */
-#ifdef X11
- /*
- XTextItem item;
- item.chars = (char*)text.data();
- item.nchars = text.length();
- item.delta = 0;
- item.font = None;
-
- Pixmap pixmap = XCreatePixmap(gctx->display, NULL,
- textWidth(text), textHeight(text), 24);
- GC gc = XCreateGC(gctx->display, pixmap, 0, NULL);
- XDrawText(gctx->display, pixmap, gc, 0, 0, &item, 1);
- */
-#endif/*X11*/
-
return pb;
}