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:
authorDiego Borghetti <bdiego@gmail.com>2009-06-12 01:43:59 +0400
committerDiego Borghetti <bdiego@gmail.com>2009-06-12 01:43:59 +0400
commitec8b2593ecdee9493210df0e6f9c4dbbcb2a1985 (patch)
treea2606bdb7d6da77c4c2243e12efc85fb4a957bd1 /source/blender/blenfont
parenta054f3ccce67ebf32ecc687b1f19ba0a6b6144f0 (diff)
Smal tweak to allow the user set a kerning value.
This commit add two option to the blenfont library: 1) BLF_FONT_KERNING This enable the kerning information that come with the font, by default this option is disable and still don't have a UI for change. 2) BLF USER_KERNING This allow the user set a kerning value to by apply for every character, by default this option is enable but all the font have a kerning value of zero. Ton I add this option to the style with a default value of 1. Access from: Outliner -> User Preferences -> Style -> FontStyle -> Kerning
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/BLF_api.h4
-rw-r--r--source/blender/blenfont/intern/blf.c9
-rw-r--r--source/blender/blenfont/intern/blf_font.c35
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c12
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h3
5 files changed, 55 insertions, 8 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index b5a61f2727f..d1d802622ea 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -85,7 +85,7 @@ float BLF_height_default(char *str);
void BLF_rotation(float angle);
void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
void BLF_blur(int size);
-
+void BLF_kerning(int space);
void BLF_enable(int option);
void BLF_disable(int option);
@@ -117,6 +117,8 @@ void BLF_dir_free(char **dirs, int count);
/* font->flags. */
#define BLF_ROTATION (1<<0)
#define BLF_CLIPPING (1<<1)
+#define BLF_FONT_KERNING (1<<2)
+#define BLF_USER_KERNING (1<<3)
/* font->mode. */
#define BLF_MODE_TEXTURE 0
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 14bc6a33b72..ffb845f7888 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -491,3 +491,12 @@ void BLF_mode(int mode)
if (font)
font->mode= mode;
}
+
+void BLF_kerning(int space)
+{
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font)
+ font->kerning= space;
+}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 1a96dbc13bc..df77aee70e8 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -100,7 +100,7 @@ void blf_font_draw(FontBLF *font, char *str)
GlyphBLF *g, *g_prev;
FT_Vector delta;
FT_UInt glyph_index, g_prev_index;
- int pen_x, pen_y;
+ int pen_x, pen_y, old_pen_x;
int i, has_kerning;
if (!font->glyph_cache)
@@ -138,12 +138,24 @@ void blf_font_draw(FontBLF *font, char *str)
else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
g= blf_glyph_add(font, glyph_index, c);
- if (has_kerning && g_prev) {
+ if ((font->flags & BLF_FONT_KERNING) && has_kerning && g_prev) {
+ old_pen_x= pen_x;
delta.x= 0;
delta.y= 0;
FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
pen_x += delta.x >> 6;
+
+ if (pen_x < old_pen_x)
+ pen_x= old_pen_x;
+ }
+
+ if (font->flags & BLF_USER_KERNING) {
+ old_pen_x= pen_x;
+ pen_x += font->kerning;
+
+ if (pen_x < old_pen_x)
+ pen_x= old_pen_x;
}
/* do not return this loop if clipped, we want every character tested */
@@ -162,7 +174,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
FT_Vector delta;
FT_UInt glyph_index, g_prev_index;
rctf gbox;
- int pen_x, pen_y;
+ int pen_x, pen_y, old_pen_x;
int i, has_kerning;
if (!font->glyph_cache)
@@ -205,12 +217,24 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
g= blf_glyph_add(font, glyph_index, c);
- if (has_kerning && g_prev) {
+ if ((font->flags & BLF_FONT_KERNING) && has_kerning && g_prev) {
+ old_pen_x= pen_x;
delta.x= 0;
delta.y= 0;
FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
pen_x += delta.x >> 6;
+
+ if (pen_x < old_pen_x)
+ old_pen_x= pen_x;
+ }
+
+ if (font->flags & BLF_USER_KERNING) {
+ old_pen_x= pen_x;
+ pen_x += font->kerning;
+
+ if (pen_x < old_pen_x)
+ old_pen_x= pen_x;
}
gbox.xmin= g->box.xmin + pen_x;
@@ -294,9 +318,10 @@ void blf_font_fill(FontBLF *font)
font->clip_rec.xmax= 0.0f;
font->clip_rec.ymin= 0.0f;
font->clip_rec.ymax= 0.0f;
- font->flags= 0;
+ font->flags= BLF_USER_KERNING;
font->dpi= 0;
font->size= 0;
+ font->kerning= 0;
font->cache.first= NULL;
font->cache.last= NULL;
font->glyph_cache= NULL;
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 142d2145ab2..33a435cc5be 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -213,7 +213,11 @@ GlyphBLF *blf_glyph_texture_add(FontBLF *font, FT_UInt index, unsigned int c)
else
do_new= 1;
- err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+ if (font->flags & BLF_FONT_KERNING)
+ err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP);
+ else
+ err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+
if (err)
return(NULL);
@@ -328,7 +332,11 @@ GlyphBLF *blf_glyph_bitmap_add(FontBLF *font, FT_UInt index, unsigned int c)
else
do_new= 1;
- err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+ if (font->flags & BLF_FONT_KERNING)
+ err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP);
+ else
+ err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+
if (err)
return(NULL);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 1c55499b568..d200d910020 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -167,6 +167,9 @@ typedef struct FontBLF {
/* font size. */
int size;
+ /* kerning space, user setting. */
+ int kerning;
+
/* max texture size. */
int max_tex_size;