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:
authorCampbell Barton <ideasman42@gmail.com>2013-12-28 10:33:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-12-28 10:40:13 +0400
commit961d0409c89dff01fd4c2c5f9d6e0406068e7552 (patch)
tree00916af7b8c2cdbce51c1c67349a1fcd4482a76b
parent2b3fc4dea7d9928206da639cfc550b0f62377cb6 (diff)
3D Text: use ghash for character lookups
-rw-r--r--source/blender/blenkernel/intern/font.c42
-rw-r--r--source/blender/blenlib/BLI_vfontdata.h7
-rw-r--r--source/blender/blenlib/intern/freetypefont.c11
3 files changed, 32 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index f489adc7445..0839ed82a8d 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -39,11 +39,15 @@
#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_listbase.h"
+#include "BLI_ghash.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
#include "BLI_math.h"
-#include "BLI_blenlib.h"
#include "BLI_threads.h"
#include "BLI_vfontdata.h"
-#include "BLI_utildefines.h"
#include "DNA_packedFile_types.h"
#include "DNA_curve_types.h"
@@ -66,16 +70,21 @@ static ThreadMutex vfont_mutex = BLI_MUTEX_INITIALIZER;
void BKE_vfont_free_data(struct VFont *vfont)
{
if (vfont->data) {
- while (vfont->data->characters.first) {
- VChar *che = vfont->data->characters.first;
+ if (vfont->data->characters) {
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, vfont->data->characters) {
+ VChar *che = BLI_ghashIterator_getValue(&gh_iter);
+
+ while (che->nurbsbase.first) {
+ Nurb *nu = che->nurbsbase.first;
+ if (nu->bezt) MEM_freeN(nu->bezt);
+ BLI_freelinkN(&che->nurbsbase, nu);
+ }
- while (che->nurbsbase.first) {
- Nurb *nu = che->nurbsbase.first;
- if (nu->bezt) MEM_freeN(nu->bezt);
- BLI_freelinkN(&che->nurbsbase, nu);
+ MEM_freeN(che);
}
- BLI_freelinkN(&vfont->data->characters, che);
+ BLI_ghash_free(vfont->data->characters, NULL, NULL);
}
MEM_freeN(vfont->data);
@@ -279,16 +288,9 @@ VFont *BKE_vfont_builtin_get(void)
return BKE_vfont_load(G.main, FO_BUILTIN_NAME);
}
-static VChar *find_vfont_char(VFontData *vfd, intptr_t character)
+static VChar *find_vfont_char(VFontData *vfd, unsigned int character)
{
- VChar *che = NULL;
-
- /* TODO: use ghash */
- for (che = vfd->characters.first; che; che = che->next) {
- if (che->index == character)
- break;
- }
- return che; /* NULL if not found */
+ return BLI_ghash_lookup(vfd->characters, SET_UINT_IN_POINTER(character));
}
static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, int charidx, short mat_nr)
@@ -326,7 +328,7 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i
}
-static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo *info,
+static void buildchar(Main *bmain, Curve *cu, unsigned int character, CharInfo *info,
float ofsx, float ofsy, float rot, int charidx)
{
BezTriple *bezt1, *bezt2;
@@ -1004,7 +1006,7 @@ makebreak:
ct = chartransdata;
if (cu->sepchar == 0) {
for (i = 0; i < slen; i++) {
- unsigned long cha = (uintptr_t) mem[i];
+ unsigned int cha = (unsigned int) mem[i];
info = &(custrinfo[i]);
if (info->mat_nr > (ob->totcol)) {
/* printf("Error: Illegal material index (%d) in text object, setting to 0\n", info->mat_nr); */
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index b0a57ee9288..9130061c53e 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -40,17 +40,14 @@ struct PackedFile;
struct VFont;
typedef struct VFontData {
- ListBase characters;
+ struct GHash *characters;
char name[128];
} VFontData;
typedef struct VChar {
- struct VChar *next, *prev;
ListBase nurbsbase;
- intptr_t index;
- float resol;
+ unsigned int index;
float width;
- float *points;
} VChar;
VFontData *BLI_vfontdata_from_freetypefont(struct PackedFile *pf);
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 4f703d2d148..9cd0bf01856 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -50,6 +50,7 @@
#include "BLI_utildefines.h"
#include "BLI_vfontdata.h"
#include "BLI_listbase.h"
+#include "BLI_ghash.h"
#include "BLI_string.h"
#include "BLI_math.h"
@@ -100,7 +101,6 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
/* First we create entry for the new character to the character list */
che = (VChar *) MEM_callocN(sizeof(struct VChar), "objfnt_char");
- BLI_addtail(&vfd->characters, che);
/* Take some data for modifying purposes */
glyph = face->glyph;
@@ -110,8 +110,10 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
che->index = charcode;
che->width = glyph->advance.x * scale;
+ BLI_ghash_insert(vfd->characters, SET_UINT_IN_POINTER(che->index), che);
+
/* Start converting the FT data */
- npoints = (int *)MEM_callocN((ftoutline.n_contours) * sizeof(int), "endpoints");
+ npoints = (int *)MEM_mallocN((ftoutline.n_contours) * sizeof(int), "endpoints");
onpoints = (int *)MEM_callocN((ftoutline.n_contours) * sizeof(int), "onpoints");
/* calculate total points of each contour */
@@ -319,6 +321,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
{
/* Variables */
FT_Face face;
+ const FT_ULong charcode_reserve = 256;
FT_ULong charcode = 0, lcode;
FT_UInt glyph_index;
const char *fontname;
@@ -393,7 +396,9 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
}
/* Load characters */
- while (charcode < 256) {
+ vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve);
+
+ while (charcode < charcode_reserve) {
/* Generate the font data */
freetypechar_to_vchar(face, charcode, vfd);