Changed the Font editing panel so it displays the Postscript name of the font.

Also supplied tooltip information for the buttons in the Font panel.
This commit is contained in:
2004-01-15 20:34:54 +00:00
parent 3b1b0f3ef5
commit 50ad38cf56
3 changed files with 158 additions and 161 deletions

View File

@@ -49,6 +49,7 @@ typedef struct VFontData {
float resol[MAX_VF_CHARS];
float width[MAX_VF_CHARS];
float *points[MAX_VF_CHARS];
char name[128];
} VFontData;
/**

View File

@@ -23,10 +23,14 @@
* The Original Code is written by Rob Haarsma (phase)
* All rights reserved.
*
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
* This code parses the Freetype font outline data to chains of Blender's beziertriples.
* Additional information can be found at the bottom of this file.
*
* Code that uses exotic character maps is present but commented out.
*/
#ifdef WITH_FREETYPE2
@@ -48,126 +52,18 @@
#include "BIF_toolbox.h"
#include "BKE_utildefines.h"
#include "DNA_packedFile_types.h"
#include "DNA_curve_types.h"
// increased max to 255, including extended charset (ton)
#define myMIN_ASCII 32
#define myMAX_ASCII 255
// should come from arithb.c
#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
/* local variables */
static FT_Library library;
static FT_Error err;
#if 0
// Freetype2 Outline struct
typedef struct FT_Outline_
{
short n_contours; /* number of contours in glyph */
short n_points; /* number of points in the glyph */
FT_Vector* points; /* the outline's points */
char* tags; /* the points flags */
short* contours; /* the contour end points */
int flags; /* outline masks */
} FT_Outline;
#endif
/***//*
from: http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-1
Vectorial representation of Freetype glyphs
The source format of outlines is a collection of closed paths called "contours". Each contour is
made of a series of line segments and bezier arcs. Depending on the file format, these can be
second-order or third-order polynomials. The former are also called quadratic or conic arcs, and
they come from the TrueType format. The latter are called cubic arcs and mostly come from the
Type1 format.
Each arc is described through a series of start, end and control points. Each point of the outline
has a specific tag which indicates wether it is used to describe a line segment or an arc.
The following rules are applied to decompose the contour's points into segments and arcs :
# two successive "on" points indicate a line segment joining them.
# one conic "off" point amidst two "on" points indicates a conic bezier arc, the "off" point being
the control point, and the "on" ones the start and end points.
# Two successive cubic "off" points amidst two "on" points indicate a cubic bezier arc. There must
be exactly two cubic control points and two on points for each cubic arc (using a single cubic
"off" point between two "on" points is forbidden, for example).
# finally, two successive conic "off" points forces the rasterizer to create (during the scan-line
conversion process exclusively) a virtual "on" point amidst them, at their exact middle. This
greatly facilitates the definition of successive conic bezier arcs. Moreover, it's the way
outlines are described in the TrueType specification.
Note that it is possible to mix conic and cubic arcs in a single contour, even though no current
font driver produces such outlines.
* # on
* off
__---__
#-__ _-- -_
--__ _- -
--__ # \
--__ #
-#
Two "on" points
Two "on" points and one "conic" point
between them
*
# __ Two "on" points with two "conic"
\ - - points between them. The point
\ / \ marked '0' is the middle of the
- 0 \ "off" points, and is a 'virtual'
-_ _- # "on" point where the curve passes.
-- It does not appear in the point
list.
*
* # on
* * off
__---__
_-- -_
_- -
# \
#
Two "on" points
and two "cubic" point
between them
Each glyph's original outline points are located on a grid of indivisible units. The points are stored
in the font file as 16-bit integer grid coordinates, with the grid origin's being at (0,0); they thus
range from -16384 to 16383.
Convert conic to bezier arcs:
Conic P0 P1 P2
Bezier B0 B1 B2 B3
B0=P0
B1=(P0+2*P1)/3
B2=(P2+2*P1)/3
B3=P2
*//****/
static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
{
@@ -188,15 +84,11 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
FT_UShort my_encoding_id = TT_MS_ID_UNICODE_CS;
int n;
*/
float scale= 1. / 1024.; //needs text_height from metrics to make a standard linedist
//scale needs text_height from freetype metrics to make a standard linedist,
//is currently set to generic value
float scale= 1. / 1024.;
float dx, dy;
int i, j, k, l, m; /* uhoh, kiddie C loops */
/* i = characters, j = curves/contours, k = points, l = curvepoint, m = first point on curve */
// test is used for BIF_printf
char test[2];
int i, j, k, l, m;
// load the freetype font
err = FT_New_Memory_Face( library,
@@ -227,22 +119,20 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
// allocate blender font
vfd= MEM_callocN(sizeof(*vfd), "FTVFontData");
strcpy(vfd->name, FT_Get_Postscript_Name(face));
// extract generic ascii character range (needs international support, dynamic loading of chars, etcetc)
// extract generic ascii character range
for(i = myMIN_ASCII; i <= myMAX_ASCII; i++) {
int *npoints; //total points of each contour
int *onpoints; //num points on curve
test[0] = i;
test[1] = '\0'; //to print character
glyph_index = FT_Get_Char_Index( face, i );
err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP);
glyph = face->glyph;
ftoutline = glyph->outline;
vfd->width[i] = glyph->advance.x* scale;
// BIF_printf("sx %d sy %d", glyph->advance.x, face->glyph->metrics->text_height);
npoints = (int *)MEM_callocN((ftoutline.n_contours)* sizeof(int),"endpoints") ;
onpoints = (int *)MEM_callocN((ftoutline.n_contours)* sizeof(int),"onpoints") ;
@@ -261,8 +151,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
for(k = 0; k < npoints[j]; k++) {
if(j > 0) l = k + ftoutline.contours[j - 1] + 1; else l = k;
// if(i == 67) BIF_printf("%d->%s : |k %2d|l %2d|t %2d|", i, test, k, l, ftoutline.n_points);
if(ftoutline.tags[l] == FT_Curve_Tag_On)
onpoints[j]++;
@@ -273,12 +161,13 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
}
}
//final contour loop, bezier & conic styles merged
//contour loop, bezier & conic styles merged
for(j = 0; j < ftoutline.n_contours; j++) {
// add new curve
nu = (Nurb*)MEM_callocN(sizeof(struct Nurb),"objfnt_nurb");
bezt = (BezTriple*)MEM_callocN((onpoints[j])* sizeof(BezTriple),"objfnt_bezt") ;
BLI_addtail(&vfd->nurbsbase[i], nu);
nu->type= CU_BEZIER+CU_2D;
nu->pntsu = onpoints[j];
nu->resolu= 8;
@@ -301,8 +190,8 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
bezt->vec[0][1] = (dy + (2 * ftoutline.points[l].y)* scale) / 3.0;
//midpoint (virtual on-curve point)
bezt->vec[1][0] = (ftoutline.points[l].x + ftoutline.points[l+1].x)* scale / 2.0;
bezt->vec[1][1] = (ftoutline.points[l].y + ftoutline.points[l+1].y)* scale / 2.0;
bezt->vec[1][0] = dx;
bezt->vec[1][1] = dy;
//right handle
bezt->vec[2][0] = (dx + (2 * ftoutline.points[l+1].x)* scale) / 3.0;
@@ -366,7 +255,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf)
}
} else { //last point on curve
if(ftoutline.tags[m] == FT_Curve_Tag_Cubic) {
// okee("hhuh");
bezt->vec[2][0] = ftoutline.points[m].x* scale;
bezt->vec[2][1] = ftoutline.points[m].y* scale;
bezt->h2= HD_FREE;
@@ -475,7 +363,7 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
//init Freetype
err = FT_Init_FreeType( &library);
if(err) {
error("Failed loading Freetype font library");
error("Failed to load the Freetype font library");
return 0;
}
@@ -492,3 +380,112 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
}
#endif // WITH_FREETYPE2
#if 0
// Freetype2 Outline struct
typedef struct FT_Outline_
{
short n_contours; /* number of contours in glyph */
short n_points; /* number of points in the glyph */
FT_Vector* points; /* the outline's points */
char* tags; /* the points flags */
short* contours; /* the contour end points */
int flags; /* outline masks */
} FT_Outline;
#endif
/***//*
from: http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-1
Vectorial representation of Freetype glyphs
The source format of outlines is a collection of closed paths called "contours". Each contour is
made of a series of line segments and bezier arcs. Depending on the file format, these can be
second-order or third-order polynomials. The former are also called quadratic or conic arcs, and
they come from the TrueType format. The latter are called cubic arcs and mostly come from the
Type1 format.
Each arc is described through a series of start, end and control points. Each point of the outline
has a specific tag which indicates wether it is used to describe a line segment or an arc.
The following rules are applied to decompose the contour's points into segments and arcs :
# two successive "on" points indicate a line segment joining them.
# one conic "off" point amidst two "on" points indicates a conic bezier arc, the "off" point being
the control point, and the "on" ones the start and end points.
# Two successive cubic "off" points amidst two "on" points indicate a cubic bezier arc. There must
be exactly two cubic control points and two on points for each cubic arc (using a single cubic
"off" point between two "on" points is forbidden, for example).
# finally, two successive conic "off" points forces the rasterizer to create (during the scan-line
conversion process exclusively) a virtual "on" point amidst them, at their exact middle. This
greatly facilitates the definition of successive conic bezier arcs. Moreover, it's the way
outlines are described in the TrueType specification.
Note that it is possible to mix conic and cubic arcs in a single contour, even though no current
font driver produces such outlines.
* # on
* off
__---__
#-__ _-- -_
--__ _- -
--__ # \
--__ #
-#
Two "on" points
Two "on" points and one "conic" point
between them
*
# __ Two "on" points with two "conic"
\ - - points between them. The point
\ / \ marked '0' is the middle of the
- 0 \ "off" points, and is a 'virtual'
-_ _- # "on" point where the curve passes.
-- It does not appear in the point
list.
*
* # on
* * off
__---__
_-- -_
_- -
# \
#
Two "on" points
and two "cubic" point
between them
Each glyph's original outline points are located on a grid of indivisible units. The points are stored
in the font file as 16-bit integer grid coordinates, with the grid origin's being at (0,0); they thus
range from -16384 to 16383.
Convert conic to bezier arcs:
Conic P0 P1 P2
Bezier B0 B1 B2 B3
B0=P0
B1=(P0+2*P1)/3
B2=(P2+2*P1)/3
B3=P2
*//****/

View File

@@ -81,6 +81,7 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_vfontdata.h"
#include "BSE_filesel.h"
@@ -642,57 +643,55 @@ void do_fontbuts(unsigned short event)
}
}
static void editing_panel_font_type(Object *ob, Curve *cu)
{
uiBlock *block;
char *strp;
static int packdummy = 0;
VFontData *vfd;
block= uiNewBlock(&curarea->uiblocks, "editing_panel_font_type", UI_EMBOSS, UI_HELV, curarea->win);
if(uiNewPanel(curarea, block, "Font", "Editing", 640, 0, 318, 204)==0) return;
uiBlockBeginAlign(block);
uiDefButS(block, ROW,B_MAKEFONT, "Left", 484,139,53,18, &cu->spacemode, 0.0,0.0, 0, 0, "");
uiDefButS(block, ROW,B_MAKEFONT, "Right", 540,139,62,18, &cu->spacemode, 0.0,2.0, 0, 0, "");
uiDefButS(block, ROW,B_MAKEFONT, "Middle", 604,139,61,18, &cu->spacemode, 0.0,1.0, 0, 0, "");
uiDefButS(block, ROW,B_MAKEFONT, "Flush", 665,139,61,18, &cu->spacemode, 0.0,3.0, 0, 0, "");
uiBlockEndAlign(block);
uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:", 484,115,243,19, &cu->textoncurve, "");
uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 484,85,243,19, cu->family, 0.0, 20.0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButF(block, NUM,B_MAKEFONT, "Size:", 482,56,121,19, &cu->fsize, 0.1,10.0, 10, 0, "");
uiDefButF(block, NUM,B_MAKEFONT, "Linedist:", 605,56,121,19, &cu->linedist, 0.0,10.0, 10, 0, "");
uiDefButF(block, NUM,B_MAKEFONT, "Spacing:", 482,34,121,19, &cu->spacing, 0.0,10.0, 10, 0, "");
uiDefButF(block, NUM,B_MAKEFONT, "Y offset:", 605,34,121,19, &cu->yof, -50.0,50.0, 10, 0, "");
uiDefButF(block, NUM,B_MAKEFONT, "Shear:", 482,12,121,19, &cu->shear, -1.0,1.0, 10, 0, "");
uiDefButF(block, NUM,B_MAKEFONT, "X offset:", 605,12,121,19, &cu->xof, -50.0,50.0, 10, 0, "");
uiBlockEndAlign(block);
uiDefBut(block, BUT, B_TOUPPER, "ToUpper", 623,163,103,23, 0, 0, 0, 0, 0, "");
G.buts->texnr= give_vfontnr(cu->vfont);
strp= give_vfontbutstr();
vfd= cu->vfont->data;
uiDefButS(block, MENU, B_SETFONT, strp, 484,191,220,20, &G.buts->texnr, 0, 0, 0, 0, "");
uiDefBut(block, BUT,B_LOADFONT, "Load", 480,188,68,20, 0, 0, 0, 0, 0, "Load a new font");
uiDefButS(block, MENU, B_SETFONT, strp, 550,188,220,20, &G.buts->texnr, 0, 0, 0, 0, "Change font for object");
if (cu->vfont->packedfile) {
packdummy = 1;
} else {
packdummy = 0;
}
uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE, 706,191,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this Vectorfont");
uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE, 772,188,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this font");
uiDefBut(block, LABEL, 0, vfd->name, 480, 165,314,20, 0, 0, 0, 0, 0, "Postscript name of the font");
MEM_freeN(strp);
uiDefBut(block, BUT,B_LOADFONT, "Load Font", 484,163,103,23, 0, 0, 0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButS(block, ROW,B_MAKEFONT, "Left", 480,135,53,20, &cu->spacemode, 0.0,0.0, 0, 0, "Align text from the left of the object centre");
uiDefButS(block, ROW,B_MAKEFONT, "Middle", 535,135,55,20, &cu->spacemode, 0.0,1.0, 0, 0, "Align text from the middle of the object centre");
uiDefButS(block, ROW,B_MAKEFONT, "Right", 592,135,53,20, &cu->spacemode, 0.0,2.0, 0, 0, "Align text from the right of the object centre");
uiDefButS(block, ROW,B_MAKEFONT, "Flush", 647,135,53,20, &cu->spacemode, 0.0,3.0, 0, 0, "Fill characters to maximum linewidth. (Multiple lines required)");
uiDefBut(block, BUT, B_TOUPPER, "ToUpper", 715,135,78,20, 0, 0, 0, 0, 0, "Toggle between upper and lower case in editmode");
uiBlockEndAlign(block);
uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:", 480,105,220,19, &cu->textoncurve, "Apply a deforming curve to the text");
uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 480,84,220,19, cu->family, 0.0, 20.0, 0, 0, "Blender uses font from selfmade objects");
uiBlockBeginAlign(block);
uiDefButF(block, NUM,B_MAKEFONT, "Size:", 480,56,155,20, &cu->fsize, 0.1,10.0, 10, 0, "Size of the text");
uiDefButF(block, NUM,B_MAKEFONT, "Linedist:", 640,56,155,20, &cu->linedist, 0.0,10.0, 10, 0, "Distance between text lines");
uiDefButF(block, NUM,B_MAKEFONT, "Spacing:", 480,34,155,20, &cu->spacing, 0.0,10.0, 10, 0, "Spacing of individual characters");
uiDefButF(block, NUM,B_MAKEFONT, "X offset:", 640,34,155,20, &cu->xof, -50.0,50.0, 10, 0, "Horizontal position from object centre");
uiDefButF(block, NUM,B_MAKEFONT, "Shear:", 480,12,155,20, &cu->shear, -1.0,1.0, 10, 0, "Italic angle of the characters");
uiDefButF(block, NUM,B_MAKEFONT, "Y offset:", 640,12,155,20, &cu->yof, -50.0,50.0, 10, 0, "Vertical position from object centre");
uiBlockEndAlign(block);
}
/* *************************** CURVE ******************************** */