summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorscuri <scuri>2009-06-23 20:55:28 +0000
committerscuri <scuri>2009-06-23 20:55:28 +0000
commitf658209d25477c490bf1892e68a0fd1384c1dded (patch)
tree1d4a2a1088db5ad62acaa3f97f13ccc8906c33b1 /src/sim
parent0610dd4f3064220a2e8fb1d8dc120044eb6c64a8 (diff)
*** empty log message ***
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/cd_truetype.c16
-rw-r--r--src/sim/cdfontex.c25
-rw-r--r--src/sim/sim.h2
-rw-r--r--src/sim/sim_text.c29
4 files changed, 29 insertions, 43 deletions
diff --git a/src/sim/cd_truetype.c b/src/sim/cd_truetype.c
index 71593c0..be0e860 100644
--- a/src/sim/cd_truetype.c
+++ b/src/sim/cd_truetype.c
@@ -14,14 +14,6 @@
/*******************************************
Inicializa o Rasterizador
********************************************/
-static char *getCdDir(void)
-{
- static char *env = NULL;
- if (env) return env;
- env = getenv("CDDIR");
- if (!env) env = ".";
- return env;
-}
#ifdef WIN32
#include <windows.h>
@@ -77,8 +69,12 @@ int cdTT_load(cdTT_Text * tt_text, const char *font, int size, double xres, doub
else
{
/* se nao conseguiu, abre arq. no dir. do cd, */
- sprintf(filename, "%s/%s.ttf", getCdDir(), font);
- file = fopen(filename, "r");
+ char* env = getenv("CDDIR");
+ if (env)
+ {
+ sprintf(filename, "%s/%s.ttf", env, font);
+ file = fopen(filename, "r");
+ }
if (file)
fclose(file);
diff --git a/src/sim/cdfontex.c b/src/sim/cdfontex.c
index b0617a9..bafa5e7 100644
--- a/src/sim/cdfontex.c
+++ b/src/sim/cdfontex.c
@@ -620,19 +620,22 @@ static void cdFontEx(cdCanvas* canvas, const char* type_face, int style, int siz
}
}
-static void cdGetFontDimEx(int *max_width, int *line_height, int *ascent, int *descent)
+void cdgetfontdimEX(cdCtxCanvas* ctxcanvas, int *max_width, int *line_height, int *ascent, int *descent)
{
+ cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
+ cdFontEx(canvas, canvas->font_type_face, canvas->font_style, canvas->font_size);
if (line_height) *line_height = font.line_height;
if (max_width) *max_width = font.max_width;
if (ascent) *ascent = font.ascent;
if (descent) *descent = font.descent;
}
-static void cdGetTextSizeEx(const char *s, int *width, int *height)
+void cdgettextsizeEX(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height)
{
int i = 0, w = 0;
-
- while (s[i] != '\0')
+ cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
+ cdFontEx(canvas, canvas->font_type_face, canvas->font_style, canvas->font_size);
+ while (i < len)
{
w += font.CharWidth(s[i]);
i++;
@@ -641,17 +644,3 @@ static void cdGetTextSizeEx(const char *s, int *width, int *height)
if (height) *height = font.line_height;
if (width) *width = w;
}
-
-void cdgetfontdimEX(cdCtxCanvas* ctxcanvas, int *max_width, int *height, int *ascent, int *descent)
-{
- cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
- cdFontEx(canvas, canvas->font_type_face, canvas->font_style, canvas->font_size);
- cdGetFontDimEx(max_width, height, ascent, descent);
-}
-
-void cdgettextsizeEX(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height)
-{
- cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
- cdFontEx(canvas, canvas->font_type_face, canvas->font_style, canvas->font_size);
- cdGetTextSizeEx(s, width, height);
-}
diff --git a/src/sim/sim.h b/src/sim/sim.h
index 16189a1..9d96a8a 100644
--- a/src/sim/sim.h
+++ b/src/sim/sim.h
@@ -30,7 +30,7 @@ struct _cdSimulation
void simFillDrawAAPixel(cdCanvas *canvas, int x, int y, unsigned short alpha_weigth);
void simFillHorizLine(cdSimulation* simulation, int xmin, int y, int xmax);
-void simGetPenPos(cdCanvas* canvas, int x, int y, const char* s, FT_Matrix *matrix, FT_Vector *pen);
+void simGetPenPos(cdCanvas* canvas, int x, int y, const char* s, int len, FT_Matrix *matrix, FT_Vector *pen);
int simIsPointInPolyWind(cdPoint* poly, int n, int x, int y);
/* list of non-horizontal line segments */
diff --git a/src/sim/sim_text.c b/src/sim/sim_text.c
index 86821ce..afc7cde 100644
--- a/src/sim/sim_text.c
+++ b/src/sim/sim_text.c
@@ -141,11 +141,11 @@ void cdgetfontdimSIM(cdCtxCanvas* ctxcanvas, int *max_width, int *height, int *a
if(height) *height= simulation->tt_text->max_height;
}
-void cdgettextsizeSIM(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height)
+void cdgettextsizeSIM(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height)
{
cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
cdSimulation* simulation = canvas->simulation;
- int w = 0;
+ int i = 0, w = 0;
FT_Face face;
FT_GlyphSlot slot;
FT_Error error;
@@ -159,15 +159,15 @@ void cdgettextsizeSIM(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *he
/* set transformation */
FT_Set_Transform( face, NULL, NULL );
- while(*s)
+ while(i < len)
{
/* load glyph image into the slot (erase previous one) */
- error = FT_Load_Char( face, *(unsigned char*)s, FT_LOAD_DEFAULT );
- if (error) {s++; continue;} /* ignore errors */
+ error = FT_Load_Char( face, (unsigned char)s[i], FT_LOAD_DEFAULT );
+ if (error) {i++; continue;} /* ignore errors */
w += slot->advance.x;
- s++;
+ i++;
}
if (height) *height = simulation->tt_text->max_height;
@@ -299,13 +299,13 @@ static void simDrawTextBitmap(cdSimulation* simulation, FT_Bitmap* bitmap, int x
simulation->canvas->use_matrix = olduse_matrix;
}
-void simGetPenPos(cdCanvas* canvas, int x, int y, const char* s, FT_Matrix *matrix, FT_Vector *pen)
+void simGetPenPos(cdCanvas* canvas, int x, int y, const char* s, int len, FT_Matrix *matrix, FT_Vector *pen)
{
int ox = x, oy = y;
int old_invert_yaxis = canvas->invert_yaxis;
int w, h, ascent, height, baseline;
- cdgettextsizeSIM(canvas->ctxcanvas, s, &w, &h);
+ cdgettextsizeSIM(canvas->ctxcanvas, s, len, &w, &h);
cdgetfontdimSIM(canvas->ctxcanvas, NULL, &height, &ascent, NULL);
baseline = height - ascent;
@@ -364,7 +364,7 @@ void simGetPenPos(cdCanvas* canvas, int x, int y, const char* s, FT_Matrix *matr
}
-void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char * s)
+void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char* s, int len)
{
cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
cdSimulation* simulation = canvas->simulation;
@@ -373,6 +373,7 @@ void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char * s)
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
+ int i = 0;
if (!simulation->tt_text->face)
return;
@@ -385,16 +386,16 @@ void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char * s)
y = _cdInvertYAxis(canvas, y); /* y is already inverted, invert back to cartesian space */
/* move the reference point to the baseline-left */
- simGetPenPos(simulation->canvas, x, y, s, &matrix, &pen);
+ simGetPenPos(simulation->canvas, x, y, s, strlen(s), &matrix, &pen);
- while(*s)
+ while(i<len)
{
/* set transformation */
FT_Set_Transform(face, &matrix, &pen);
/* load glyph image into the slot (erase previous one) */
- error = FT_Load_Char(face, *(unsigned char*)s, FT_LOAD_RENDER);
- if (error) {s++; continue;} /* ignore errors */
+ error = FT_Load_Char(face, (unsigned char)s[i], FT_LOAD_RENDER);
+ if (error) {i++; continue;} /* ignore errors */
x = slot->bitmap_left;
y = slot->bitmap_top-slot->bitmap.rows; /* CD image reference point is at bottom-left */
@@ -409,6 +410,6 @@ void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char * s)
pen.x += slot->advance.x;
pen.y += slot->advance.y;
- s++;
+ i++;
}
}