Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c104
1 files changed, 54 insertions, 50 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 98044b965e1..f7c5531f0ac 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1,5 +1,5 @@
/**
- * $Id:
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -45,7 +45,6 @@
#include "BLI_blenlib.h"
#include "BLI_linklist.h" /* linknode */
-#include "BLI_string.h"
#include "BLI_math.h"
#include "BIF_gl.h"
@@ -151,8 +150,9 @@ void blf_font_draw(FontBLF *font, char *str)
void blf_font_buffer(FontBLF *font, char *str)
{
- unsigned char *data, *cbuf;
+ unsigned char *cbuf;
unsigned int c;
+ unsigned char b_col_char[3];
GlyphBLF *g, *g_prev;
FT_Vector delta;
FT_UInt glyph_index;
@@ -160,14 +160,18 @@ void blf_font_buffer(FontBLF *font, char *str)
int pen_x, pen_y, y, x, yb, diff;
int i, has_kerning, st, chx, chy;
- if (!font->glyph_cache)
+ if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
return;
-
+
i= 0;
pen_x= (int)font->pos[0];
pen_y= (int)font->pos[1];
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
+
+ b_col_char[0]= font->b_col[0] * 255;
+ b_col_char[1]= font->b_col[1] * 255;
+ b_col_char[2]= font->b_col[2] * 255;
while (str[i]) {
c= blf_utf8_next((unsigned char *)str, &i);
@@ -217,28 +221,34 @@ void blf_font_buffer(FontBLF *font, char *str)
else
chy= pen_y + ((int)g->pos_y);
- if (font->b_fbuf) {
- if (chx >= 0 && chx < font->bw && pen_y >= 0 && pen_y < font->bh) {
- if (g->pitch < 0)
- yb= 0;
- else
- yb= g->height-1;
-
- for (y= 0; y < g->height; y++) {
- for (x= 0; x < g->width; x++) {
- fbuf= font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
- data= g->bitmap + x + (yb * g->pitch);
- a= data[0]/255.0f;
-
- if (a == 1.0) {
- fbuf[0]= font->b_col[0];
- fbuf[1]= font->b_col[1];
- fbuf[2]= font->b_col[2];
- }
- else {
- fbuf[0]= (font->b_col[0]*a) + (fbuf[0] * (1-a));
- fbuf[1]= (font->b_col[1]*a) + (fbuf[1] * (1-a));
- fbuf[2]= (font->b_col[2]*a) + (fbuf[2] * (1-a));
+ if ((chx + g->width) >= 0 && chx < font->bw && (pen_y + g->height) >= 0 && pen_y < font->bh) {
+ /* dont draw beyond the buffer bounds */
+ int width_clip= g->width;
+ int height_clip= g->height;
+
+ if (width_clip + chx > font->bw) width_clip -= chx + width_clip - font->bw;
+ if (height_clip + pen_y > font->bh) height_clip -= pen_y + height_clip - font->bh;
+
+ yb= g->pitch < 0 ? 0 : g->height-1;
+
+ if (font->b_fbuf) {
+ for (y=(chy >= 0 ? 0:-chy); y < height_clip; y++) {
+ for (x=(chx >= 0 ? 0:-chx); x < width_clip; x++) {
+
+ a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
+
+ if(a > 0.0f) {
+ fbuf= font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
+ if (a >= 1.0f) {
+ fbuf[0]= font->b_col[0];
+ fbuf[1]= font->b_col[1];
+ fbuf[2]= font->b_col[2];
+ }
+ else {
+ fbuf[0]= (font->b_col[0]*a) + (fbuf[0] * (1-a));
+ fbuf[1]= (font->b_col[1]*a) + (fbuf[1] * (1-a));
+ fbuf[2]= (font->b_col[2]*a) + (fbuf[2] * (1-a));
+ }
}
}
@@ -248,30 +258,24 @@ void blf_font_buffer(FontBLF *font, char *str)
yb--;
}
}
- }
- if (font->b_cbuf) {
- if (chx >= 0 && chx < font->bw && pen_y >= 0 && pen_y < font->bh) {
- if (g->pitch < 0)
- yb= 0;
- else
- yb= g->height-1;
-
- for (y= 0; y < g->height; y++) {
- for (x= 0; x < g->width; x++) {
- cbuf= font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
- data= g->bitmap + x + (yb * g->pitch);
- a= data[0];
-
- if (a == 256) {
- cbuf[0]= font->b_col[0];
- cbuf[1]= font->b_col[1];
- cbuf[2]= font->b_col[2];
- }
- else {
- cbuf[0]= (font->b_col[0]*a) + (cbuf[0] * (256-a));
- cbuf[1]= (font->b_col[1]*a) + (cbuf[1] * (256-a));
- cbuf[2]= (font->b_col[2]*a) + (cbuf[2] * (256-a));
+ if (font->b_cbuf) {
+ for (y= 0; y < height_clip; y++) {
+ for (x= 0; x < width_clip; x++) {
+ a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
+
+ if(a > 0.0f) {
+ cbuf= font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
+ if (a >= 1.0f) {
+ cbuf[0]= b_col_char[0];
+ cbuf[1]= b_col_char[1];
+ cbuf[2]= b_col_char[2];
+ }
+ else {
+ cbuf[0]= (b_col_char[0]*a) + (cbuf[0] * (1-a));
+ cbuf[1]= (b_col_char[1]*a) + (cbuf[1] * (1-a));
+ cbuf[2]= (b_col_char[2]*a) + (cbuf[2] * (1-a));
+ }
}
}