tedious string copying changes
[blender.git] / source / blender / blenkernel / intern / font.c
index 7ebd0c3f4578eb184ce2587612487dee2edf9044..5fdb9549179a9e27ca8b6cf5cf6ab3d4707d6e6c 100644 (file)
@@ -46,6 +46,7 @@
 #include "DNA_curve_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_object_types.h"
 
 #include "BKE_utildefines.h"
 
@@ -122,8 +123,8 @@ wcsleninu8(wchar_t *src)
        return len;
 }
 
-int
-static utf8slen(char *src)
+static int
+utf8slen(char *src)
 {
        int size = 0, index = 0;
        unsigned char c;
@@ -264,13 +265,11 @@ static PackedFile *get_builtin_packedfile(void)
 void free_ttfont(void)
 {
        struct TmpFont *tf;
-       
-       tf= ttfdata.first;
-       while(tf) {
-               freePackedFile(tf->pf);
+
+       for(tf= ttfdata.first; tf; tf= tf->next) {
+               if(tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */
                tf->pf= NULL;
                tf->vfont= NULL;
-               tf= tf->next;
        }
        BLI_freelistN(&ttfdata);
 }
@@ -306,7 +305,7 @@ static VFontData *vfont_get_data(VFont *vfont)
        if (!vfont->data) {
                PackedFile *pf;
                
-               if (BLI_streq(vfont->name, "<builtin>")) {
+               if (strcmp(vfont->name, FO_BUILTIN_NAME)==0) {
                        pf= get_builtin_packedfile();
                } else {
                        if (vfont->packedfile) {
@@ -343,7 +342,7 @@ static VFontData *vfont_get_data(VFont *vfont)
                        if(!pf) {
                                printf("Font file doesn't exist: %s\n", vfont->name);
 
-                               strcpy(vfont->name, "<builtin>");
+                               strcpy(vfont->name, FO_BUILTIN_NAME);
                                pf= get_builtin_packedfile();
                        }
                }
@@ -368,7 +367,7 @@ VFont *load_vfont(char *name)
        int is_builtin;
        struct TmpFont *tmpfnt;
        
-       if (BLI_streq(name, "<builtin>")) {
+       if (strcmp(name, FO_BUILTIN_NAME)==0) {
                strcpy(filename, name);
                
                pf= get_builtin_packedfile();
@@ -395,7 +394,7 @@ VFont *load_vfont(char *name)
 
                        /* if there's a font name, use it for the ID name */
                        if (strcmp(vfd->name, "")!=0) {
-                               BLI_strncpy(vfont->id.name+2, vfd->name, 21);
+                               BLI_strncpy(vfont->id.name+2, vfd->name, sizeof(vfont->id.name)-2);
                        }
                        BLI_strncpy(vfont->name, name, sizeof(vfont->name));
 
@@ -404,8 +403,8 @@ VFont *load_vfont(char *name)
                                vfont->packedfile = pf;
                        }
                        
-                       // Do not add <builtin> to temporary listbase
-                       if(strcmp(filename, "<builtin>"))
+                       // Do not add FO_BUILTIN_NAME to temporary listbase
+                       if(strcmp(filename, FO_BUILTIN_NAME))
                        {
                                tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
                                tmpfnt->pf= tpf;
@@ -444,10 +443,10 @@ VFont *get_builtin_font(void)
        VFont *vf;
        
        for (vf= G.main->vfont.first; vf; vf= vf->id.next)
-               if (BLI_streq(vf->name, "<builtin>"))
+               if (strcmp(vf->name, FO_BUILTIN_NAME)==0)
                        return vf;
        
-       return load_vfont("<builtin>");
+       return load_vfont(FO_BUILTIN_NAME);
 }
 
 static VChar *find_vfont_char(VFontData *vfd, intptr_t character)
@@ -515,11 +514,12 @@ static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float
        float *fp, fsize, shear, x, si, co;
        VFontData *vfd = NULL;
        VChar *che = NULL;
-       int i, sel=0;
+       int i;
 
        vfd= vfont_get_data(which_vfont(cu, info));     
        if (!vfd) return;
 
+       /*
        if (cu->selend < cu->selstart) {
                if ((charidx >= (cu->selend)) && (charidx <= (cu->selstart-2)))
                        sel= 1;
@@ -528,6 +528,7 @@ static void buildchar(Curve *cu, unsigned long character, CharInfo *info, float
                if ((charidx >= (cu->selstart-1)) && (charidx <= (cu->selend-1)))
                        sel= 1;
        }
+       */
 
        /* make a copy at distance ofsx,ofsy with shear*/
        fsize= cu->fsize;
@@ -780,10 +781,10 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
 
                /*
                 * The character wasn't in the current curve base so load it
-                * But if the font is <builtin> then do not try loading since
+                * But if the font is FO_BUILTIN_NAME then do not try loading since
                 * whole font is in the memory already
                 */
-               if(che == NULL && strcmp(vfont->name, "<builtin>"))     {
+               if(che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) {
                        BLI_vfontchar_from_freetypefont(vfont, ascii);
                }
 
@@ -814,7 +815,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
                twidth = char_width(cu, che, info);
 
                // Calculate positions
-               if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w) {
+               if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+twidth)*cu->fsize) > tb->w + cu->xof*cu->fsize) {
        //              fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]);
                        for (j=i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak==0); j--) {
                                if (mem[j]==' ' || mem[j]=='-') {
@@ -855,7 +856,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
                        linedata4[lnr]= wsnr;
                        
                        if ( (tb->h != 0.0) &&
-                                ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize))) &&
+                                ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize)) - cu->yof) &&
                                 (cu->totbox > (curbox+1)) ) {
                                maxlen= 0;
                                tb++;
@@ -1147,16 +1148,14 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
                return NULL;
        }
 
-       if(mode==0) {
+       if(mode == FO_EDIT) {
                /* make nurbdata */
-               unsigned long cha;
-               
                freeNurblist(&cu->nurb);
                
                ct= chartransdata;
                if (cu->sepchar==0) {
                        for (i= 0; i<slen; i++) {
-                               cha = (uintptr_t) mem[i];
+                               unsigned long cha = (uintptr_t) 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); */
@@ -1194,8 +1193,12 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode)
                                ascii = mem[i];
                                info = &(custrinfo[i]);
                                if (cu->sepchar == (i+1)) {
-                                       float vecyo[3]= {ct->xof, ct->yof, 0.0f};
-                                       
+                                       float vecyo[3];
+
+                                       vecyo[0]= ct->xof;
+                                       vecyo[1]= ct->yof;
+                                       vecyo[2]= 0.0f;
+
                                        mem[0] = ascii;
                                        mem[1] = 0;
                                        custrinfo[0]= *info;