diff options
author | Alexander Ewering <blender@instinctive.de> | 2005-08-29 16:46:07 +0400 |
---|---|---|
committer | Alexander Ewering <blender@instinctive.de> | 2005-08-29 16:46:07 +0400 |
commit | a07394ef2cfd8cb54e68e8bfb1e7210ee4b2b1b4 (patch) | |
tree | 2fcb1b06b7e8dd989510190b8242203c9175905a /source/blender/blenkernel | |
parent | c921ee25cc71decc843b230fb28a7fb195fb6786 (diff) |
More text object fancyness, and fixes:
- "Flush" is now split into two seperate Alignment modes "Flush" and
"Justify":
- Justify does exactly the same as a normal word processor's justify
function does, and in addition, it uses *whitespace* instead of
*character spacing* (kerning) to fill lines. Much more readable.
- Flush is pretty much the old Blender "Flush" mode - and as such it
uses character spacing to fill lines. Just as Justify, this only
works with at least one textframe.
- Underlining for text objects. Not a lot to explain. New button "U" in
the editbuttons, and CTRL-U as hotkey toggle underlining for newly
entered characters or for the selection, just like CTRL-B/CTRL-I do for
bold/italic.
Underline height (thickness) and Underline position (vertical) can be
set in the editbuttons.
Implemented as CU_POLY polygon curves.
- The B, U and i buttons (and the corresponding CTRL-B/U/I keystrokes)
have been fixed to only affect *one* attribute at a time. Formerly,
hitting CTRL-B when no other style was active, on a text portion with
italics text, for example, would kill the italics and just apply bold.
Now, these attributes always add or substract only, but do not
replace the style.
- In the past, there were bugs with material indices uninitialized, and
thus crashes in the renderer with illegal material indices.
Even though I assume they have been fixed, I've put in a check that
checks (hah) if the material index of a character is illegal (bigger
than ob->totcol), and then sets it to zero, and spits out a warning
on stderr.
If you see such warnings, please report and link to the .blend.
- Bugfix: All alignment modes only worked if there were at least *two*
lines of text in the text object. Fixed
There's now a regression test file for text objects, please add to the
corresponding repository:
http://blender.instinctive.de/downloads/release/demo/text-regression.blend.gz
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_font.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 143 |
4 files changed, 125 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h index 9367f4816b5..ab0fcf6b994 100644 --- a/source/blender/blenkernel/BKE_font.h +++ b/source/blender/blenkernel/BKE_font.h @@ -51,7 +51,7 @@ void free_vfont(struct VFont *sc); struct VFont *load_vfont(char *name); struct chartrans *text_to_curve(struct Object *ob, int mode); -int style_to_sel(void); +int style_to_sel(int style, int toggle); int mat_to_sel(void); void font_duplilist(struct Object *par); int getselection(int *start, int *end); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index b1f8fcca6bf..9f26dc6d930 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -131,6 +131,7 @@ Curve *add_curve(int type) cu->wordspace = 1.0; cu->spacing= cu->linedist= 1.0; cu->fsize= 1.0; + cu->ulheight = 0.05; cu->texflag= CU_AUTOSPACE; cu->bb= unit_boundbox(); @@ -696,6 +697,9 @@ void makeNurbfaces(Nurb *nu, float *data, int rowstride) /* allocate and initialize */ len= nu->pntsu*nu->pntsv; if(len==0) return; + + + sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbfaces1"); resolu= nu->resolu; @@ -827,6 +831,11 @@ void makeNurbfaces(Nurb *nu, float *data, int rowstride) if (rowstride!=0) in = (float*) (((unsigned char*) in) + (rowstride - 3*nu->resolv*sizeof(*in))); } + for (i=0; i<144*3; i++) { +// fprintf(stderr, "%f %f %f\n", nu->bp[i].vec[0], nu->bp[i].vec[1], nu->bp[i].vec[2]); + fprintf(stderr, "%f ", data[i]); + } + /* free */ MEM_freeN(sum); MEM_freeN(basisu); diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 96930e78408..077060b7890 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -1138,6 +1138,7 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase) dl->parts= 1; dl->nr= len; dl->col= nu->mat_nr; + dl->charidx = nu->charidx; data= dl->verts; if(nu->flagu & 1) dl->type= DL_POLY; diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 40c62e2c407..1799f01dd30 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -151,11 +151,7 @@ static VFontData *vfont_get_data(VFont *vfont) } if (pf) { -#ifdef WITH_FREETYPE2 - vfont->data= BLI_vfontdata_from_freetypefont(pf); -#else vfont->data= BLI_vfontdata_from_psfont(pf); -#endif if (pf != vfont->packedfile) { freePackedFile(pf); } @@ -192,11 +188,7 @@ VFont *load_vfont(char *name) waitcursor(1); -#ifdef WITH_FREETYPE2 - vfd= BLI_vfontdata_from_freetypefont(pf); -#else vfd= BLI_vfontdata_from_psfont(pf); -#endif if (vfd) { vfont = alloc_libblock(&G.main->vfont, ID_VF, filename); @@ -233,6 +225,54 @@ static VFont *which_vfont(Curve *cu, CharInfo *info) } } +static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, int charidx, short mat_nr) +{ + Nurb *nu2; + BPoint *bp; + + nu2 =(Nurb*) MEM_callocN(sizeof(Nurb),"underline_nurb"); + if (nu2 == NULL) return; + nu2->resolu= cu->resolu; + nu2->bezt = NULL; + nu2->knotsu = nu2->knotsv = 0; + nu2->flag= 0; + nu2->charidx = charidx+1000; + nu2->mat_nr= mat_nr; + nu2->pntsu = 4; + nu2->pntsv = 1; + nu2->orderu = 4; + nu2->orderv = 1; + nu2->flagu = CU_CYCLIC; + + bp = (BPoint*)MEM_callocN(4 * sizeof(BPoint),"underline_bp"); + if (bp == 0){ + MEM_freeN(nu2); + return; + } + nu2->bp = bp; + + nu2->bp[0].vec[0] = x1; + nu2->bp[0].vec[1] = y1; + nu2->bp[0].vec[2] = 0; + nu2->bp[0].vec[3] = 1.0; + nu2->bp[1].vec[0] = x2; + nu2->bp[1].vec[1] = y1; + nu2->bp[1].vec[2] = 0; + nu2->bp[1].vec[3] = 1.0; + nu2->bp[2].vec[0] = x2; + nu2->bp[2].vec[1] = y2; + nu2->bp[2].vec[2] = 0; + nu2->bp[2].vec[3] = 1.0; + nu2->bp[3].vec[0] = x1; + nu2->bp[3].vec[1] = y2; + nu2->bp[3].vec[2] = 0; + nu2->bp[3].vec[3] = 1.0; + + nu2->type = CU_2D; + BLI_addtail(&(cu->nurb), nu2); + +} + static void buildchar(Curve *cu, unsigned char ascii, CharInfo *info, float ofsx, float ofsy, float rot, int charidx) { BezTriple *bezt1, *bezt2; @@ -272,7 +312,12 @@ static void buildchar(Curve *cu, unsigned char ascii, CharInfo *info, float ofsx nu2->knotsu = nu2->knotsv = 0; nu2->flag= CU_SMOOTH; nu2->charidx = charidx; - if (info->mat_nr) nu2->mat_nr= info->mat_nr-1; + if (info->mat_nr) { + nu2->mat_nr= info->mat_nr-1; + } + else { + nu2->mat_nr= 0; + } /* nu2->trim.first = 0; */ /* nu2->trim.last = 0; */ i = nu2->pntsu; @@ -363,14 +408,15 @@ struct chartrans *text_to_curve(Object *ob, int mode) struct chartrans *chartransdata, *ct; float distfac, tabfac, ctime, dtime, tvec[4], vec[4], rotvec[3], minx, maxx, miny, maxy; float cmat[3][3], timeofs, si, co, sizefac; - float *f, maxlen=0, xof, yof, xtrax, linedist, *linedata, *linedata2, *linedata3; + float *f, maxlen=0, xof, yof, xtrax, linedist, *linedata, *linedata2, *linedata3, *linedata4; int i, slen, oldflag, j; - short cnr=0, lnr=0; + short cnr=0, lnr=0, wsnr= 0; char ascii, *mem; int outta; - float vecyo[3]; + float vecyo[3], curofs; CharInfo *info; float wsfac; + float ulwidth, uloverlap; TextBox *tb; int curbox; int selstart, selend; @@ -383,9 +429,10 @@ struct chartrans *text_to_curve(Object *ob, int mode) cu= ob->data; mem= cu->str; - if (cu->str==0) return 0; slen = strlen(mem); + if (cu->ulheight == 0.0) cu->ulheight = 0.05; + if (cu->str==0) return 0; if (cu->strinfo==NULL) { /* old file */ cu->strinfo = MEM_callocN((slen+1) * sizeof(CharInfo), "strinfo compat"); } @@ -399,6 +446,7 @@ struct chartrans *text_to_curve(Object *ob, int mode) linedata= MEM_mallocN(sizeof(float)*(slen+2),"buildtext2"); linedata2= MEM_mallocN(sizeof(float)*(slen+2),"buildtext3"); linedata3= MEM_callocN(sizeof(float)*(slen+2),"buildtext4"); + linedata4= MEM_callocN(sizeof(float)*(slen+2),"buildtext5"); linedist= cu->linedist; @@ -432,9 +480,11 @@ struct chartrans *text_to_curve(Object *ob, int mode) if((tb->w != 0.0) && (ct->dobreak==0) && ((xof-(tb->x/cu->fsize)+vfd->width[ascii])*cu->fsize) > tb->w) { // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", cu->str[i], cu->str[i+1], cu->str[i+2]); for (j=i; j && (cu->str[j] != '\n') && (cu->str[j] != '\r') && (chartransdata[j].dobreak==0); j--) { - if (cu->str[j]==' ') { + if (cu->str[j]==' ' || cu->str[j]=='-') { ct -= (i-(j-1)); cnr -= (i-(j-1)); + if (cu->str[j] == ' ') wsnr--; + if (cu->str[j] == '-') wsnr++; i = j-1; xof = ct->xof; ct[1].dobreak = 1; @@ -465,6 +515,7 @@ struct chartrans *text_to_curve(Object *ob, int mode) linedata[lnr]= xof-tb->x/cu->fsize; linedata2[lnr]= cnr; linedata3[lnr]= tb->w/cu->fsize; + linedata4[lnr]= wsnr; if ( (tb->h != 0.0) && ((-(yof-(tb->y/cu->fsize))) > ((tb->h/cu->fsize)-(linedist*cu->fsize))) && @@ -478,6 +529,7 @@ struct chartrans *text_to_curve(Object *ob, int mode) xof= cu->xof + (tb->x/cu->fsize); lnr++; cnr= 0; + wsnr= 0; } else if(ascii==9) { /* TAB */ ct->xof= xof; @@ -502,7 +554,10 @@ struct chartrans *text_to_curve(Object *ob, int mode) sb->w = xof*cu->fsize; } - if (ascii==32) wsfac = cu->wordspace; else wsfac = 1.0; + if (ascii==32) { + wsfac = cu->wordspace; + wsnr++; + } else wsfac = 1.0; xof += (vfd->width[ascii]*wsfac*(1.0+(info->kern/40.0)) ) + xtrax; if (selboxes && (i>=selstart) && (i<=selend)) sb->w = (xof*cu->fsize) - sb->w; @@ -510,6 +565,8 @@ struct chartrans *text_to_curve(Object *ob, int mode) ct++; } + + cu->lines= 1; ct= chartransdata; for (i= 0; i<=slen; i++, mem++, ct++) { @@ -520,8 +577,9 @@ struct chartrans *text_to_curve(Object *ob, int mode) // linedata is now: width of line // linedata2 is now: number of characters // linedata3 is now: maxlen of that line + // linedata4 is now: number of whitespaces of line - if(cu->spacemode!=CU_LEFT && lnr>1) { + if(cu->spacemode!=CU_LEFT) { ct= chartransdata; if(cu->spacemode==CU_RIGHT) { @@ -536,7 +594,7 @@ struct chartrans *text_to_curve(Object *ob, int mode) ct->xof+= linedata[ct->linenr]; ct++; } - } else if((cu->spacemode==CU_FLUSH || cu->spacemode==CU_FORCEFLUSH) && + } else if((cu->spacemode==CU_FLUSH) && (cu->tb[0].w != 0.0)) { for(i=0;i<lnr;i++) if(linedata2[i]>1) @@ -544,12 +602,25 @@ struct chartrans *text_to_curve(Object *ob, int mode) for (i=0; i<=slen; i++) { for (j=i; (cu->str[j]) && (cu->str[j]!='\n') && (cu->str[j]!='\r') && (chartransdata[j].dobreak==0) && (j<slen); j++); - if ((cu->str[j]!='\r') && (cu->str[j]!='\n') && - (cu->spacemode==CU_FORCEFLUSH || (chartransdata[j].dobreak!=0))) { +// if ((cu->str[j]!='\r') && (cu->str[j]!='\n') && (cu->str[j])) { ct->xof+= ct->charnr*linedata[ct->linenr]; - } +// } ct++; } + } else if((cu->spacemode==CU_JUSTIFY) && + (cu->tb[0].w != 0.0)) { + curofs= 0; + for (i=0; i<=slen; i++) { + for (j=i; (cu->str[j]) && (cu->str[j]!='\n') && + (cu->str[j]!='\r') && (chartransdata[j].dobreak==0) && (j<slen); j++); + if ((cu->str[j]!='\r') && (cu->str[j]!='\n') && + ((chartransdata[j].dobreak!=0))) { + if (cu->str[i]==' ') curofs += (linedata3[ct->linenr]-linedata[ct->linenr])/linedata4[ct->linenr]; + ct->xof+= curofs; + } + if (cu->str[i]=='\n' || cu->str[i]=='\r' || chartransdata[i].dobreak) curofs= 0; + ct++; + } } } @@ -593,7 +664,7 @@ struct chartrans *text_to_curve(Object *ob, int mode) else if(cu->spacemode==CU_MIDDLE) { timeofs= (1.0f-distfac)/2.0f; } - else if(cu->spacemode==CU_FLUSH || cu->spacemode==CU_FORCEFLUSH) distfac= 1.0f; + else if(cu->spacemode==CU_FLUSH) distfac= 1.0f; } else distfac= 1.0; @@ -696,11 +767,13 @@ struct chartrans *text_to_curve(Object *ob, int mode) } + MEM_freeN(linedata); + MEM_freeN(linedata2); + MEM_freeN(linedata3); + MEM_freeN(linedata4); + if (mode == FO_SELCHANGE) { MEM_freeN(chartransdata); - MEM_freeN(linedata); - MEM_freeN(linedata2); - MEM_freeN(linedata3); return NULL; } @@ -714,7 +787,24 @@ struct chartrans *text_to_curve(Object *ob, int mode) for (i= 0; i<slen; i++) { ascii = cu->str[i]; info = &(cu->strinfo[i]); + if (info->mat_nr > (ob->totcol)) { + printf("Error: Illegal material index (%d) in text object, setting to 0\n", info->mat_nr); + info->mat_nr = 0; + } buildchar(cu, ascii, info, ct->xof, ct->yof, ct->rot, i); + if ((info->flag & CU_UNDERLINE) && (ascii != '\n') && (ascii != '\r')) { + uloverlap = 0; + if ( (i<(slen-1)) && (cu->str[i+1] != '\n') && (cu->str[i+1] != '\r') && + ((cu->str[i+1] != ' ') || (cu->strinfo[i+1].flag & CU_UNDERLINE)) && ((cu->strinfo[i+1].flag & CU_WRAP)==0) + ) { + uloverlap = xtrax + 0.1; + } + ulwidth = cu->fsize * ((vfd->width[ascii]* (1.0+(info->kern/40.0)))+uloverlap); + build_underline(cu, ct->xof*cu->fsize, ct->yof*cu->fsize + (cu->ulpos-0.05)*cu->fsize, + ct->xof*cu->fsize + ulwidth, + ct->yof*cu->fsize + (cu->ulpos-0.05)*cu->fsize - cu->ulheight*cu->fsize, + i, info->mat_nr); + } ct++; } } @@ -742,10 +832,6 @@ struct chartrans *text_to_curve(Object *ob, int mode) } } - MEM_freeN(linedata); - MEM_freeN(linedata2); - MEM_freeN(linedata3); - if(mode==FO_DUPLI) { return chartransdata; } @@ -754,7 +840,6 @@ struct chartrans *text_to_curve(Object *ob, int mode) return 0; } - /* ***************** DUPLI ***************** */ static Object *find_family_object(Object **obar, char *family, char ch) |