summaryrefslogtreecommitdiff
path: root/src/drv
diff options
context:
space:
mode:
Diffstat (limited to 'src/drv')
-rw-r--r--src/drv/cdcgm.c12
-rw-r--r--src/drv/cddebug.c12
-rw-r--r--src/drv/cddgn.c37
-rw-r--r--src/drv/cddxf.c10
-rw-r--r--src/drv/cdirgb.c19
-rw-r--r--src/drv/cdmf.c8
-rw-r--r--src/drv/cdpdf.c12
-rw-r--r--src/drv/cdpicture.c12
-rw-r--r--src/drv/cdps.c8
-rw-r--r--src/drv/cgm.c75
-rw-r--r--src/drv/cgm.h2
11 files changed, 108 insertions, 99 deletions
diff --git a/src/drv/cdcgm.c b/src/drv/cdcgm.c
index 2791c24..3049818 100644
--- a/src/drv/cdcgm.c
+++ b/src/drv/cdcgm.c
@@ -513,24 +513,24 @@ static void settextbbox (cdCtxCanvas *ctxcanvas, double x, double y, int width,
}
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
int width, height;
- cgm_text( ctxcanvas->cgm, 1 /* final */ , (double)x, (double)y, s );
+ cgm_text( ctxcanvas->cgm, 1 /* final */ , (double)x, (double)y, s, len );
- cdgettextsizeEX(ctxcanvas, s, &width, &height);
+ cdgettextsizeEX(ctxcanvas, s, len, &width, &height);
settextbbox (ctxcanvas, (double) x, (double) y, width, height );
}
-static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s)
+static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, int len)
{
int width, height;
- cgm_text( ctxcanvas->cgm, 1 /* final */ , x, y, s );
+ cgm_text( ctxcanvas->cgm, 1 /* final */ , x, y, s, len);
- cdgettextsizeEX(ctxcanvas, s, &width, &height);
+ cdgettextsizeEX(ctxcanvas, s, len, &width, &height);
settextbbox (ctxcanvas, x, y, width, height );
}
diff --git a/src/drv/cddebug.c b/src/drv/cddebug.c
index 5532568..23d8446 100644
--- a/src/drv/cddebug.c
+++ b/src/drv/cddebug.c
@@ -208,20 +208,24 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
fprintf(ctxcanvas->file, "%s(%g, %g, %g, %g, %g, %g)\n", CDDBG_FCHORD, xc, yc, w, h, a1, a2);
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text, int len)
{
+ text = cdStrDupN(text, len);
if (ctxcanvas->canvas->new_region)
fprintf(ctxcanvas->file, "%sRegion(%d, %d, \"%s\", %s)\n", CDDBG_TEXT, x, y, text, get_region_mode(ctxcanvas->canvas->combine_mode));
else
fprintf(ctxcanvas->file, "%s(%d, %d, \"%s\")\n", CDDBG_TEXT, x, y, text);
+ free((char*)text);
}
-static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text)
+static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text, int len)
{
+ text = cdStrDupN(text, len);
if (ctxcanvas->canvas->new_region)
fprintf(ctxcanvas->file, "%sRegion(%g, %g, \"%s\", %s)\n", CDDBG_FTEXT, x, y, text, get_region_mode(ctxcanvas->canvas->combine_mode));
else
fprintf(ctxcanvas->file, "%s(%g, %g, \"%s\")\n", CDDBG_FTEXT, x, y, text);
+ free((char*)text);
}
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
@@ -585,12 +589,12 @@ static void cdgetfontdim(cdCtxCanvas* ctxcanvas, int *max_width, int *height, in
fprintf(ctxcanvas->file, "%d, %d, %d, %d = GetFontDim()\n", *max_width, *height, *ascent, *descent);
}
-static void cdgettextsize(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height)
+static void cdgettextsize(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height)
{
int tmp_width, tmp_height;
if (!width) width = &tmp_width;
if (!height) height = &tmp_height;
- cdgettextsizeEX(ctxcanvas, s, width, height);
+ cdgettextsizeEX(ctxcanvas, s, len, width, height);
fprintf(ctxcanvas->file, "%d, %d = GetTextSize(\"%s\")\n", *width, *height, s);
}
diff --git a/src/drv/cddgn.c b/src/drv/cddgn.c
index 32435b9..d7dd5f9 100644
--- a/src/drv/cddgn.c
+++ b/src/drv/cddgn.c
@@ -164,13 +164,12 @@ static void endComplexElement(cdCtxCanvas*);
* Obtem o descent do texto (para letras como q,p,g etc) *
*********************************************************/
-static long get_descent(const char *text, int size_pixel)
+static long get_descent(const char *text, int len, int size_pixel)
{
char *descent="jgyqp";
long a=0;
- long length = strlen(text);
- while(a < length)
+ while(a < len)
{
if(strchr(descent, text[a]))
return size_pixel/2;
@@ -184,11 +183,10 @@ static long get_descent(const char *text, int size_pixel)
* Calcula a largura da string no MicroStation *
***********************************************/
-static long gettextwidth(cdCtxCanvas* ctxcanvas, const char *s, int size_pixel)
+static long gettextwidth(cdCtxCanvas* ctxcanvas, const char *s, int len, int size_pixel)
{
long a=0,
- width=0,
- length = strlen(s);
+ width=0;
short default_size=0;
@@ -239,7 +237,7 @@ static long gettextwidth(cdCtxCanvas* ctxcanvas, const char *s, int size_pixel)
else
default_size=4;
- for(a=0,width=0;a < length; a++)
+ for(a=0,width=0;a < len; a++)
{
static short size_number;
static char letter;
@@ -806,9 +804,8 @@ static void cdsector (cdCtxCanvas* ctxcanvas, int xc, int yc, int w, int h, doub
endComplexElement(ctxcanvas);
}
-static void cdtext (cdCtxCanvas* ctxcanvas, int x, int y, const char *s)
+static void cdtext (cdCtxCanvas* ctxcanvas, int x, int y, const char *s, int len)
{
- long n=0;
long descent=0;
short w=0;
long hc=0,wc=0;
@@ -818,16 +815,14 @@ static void cdtext (cdCtxCanvas* ctxcanvas, int x, int y, const char *s)
Elm_hdr ehdr;
Disp_hdr dhdr;
- n = strlen(s);
+ if(len > 255)
+ len=255;
- if(n > 255)
- n=255;
-
- w = (short)((n/2)+(n%2));
+ w = (short)((len/2)+(len%2));
size_pixel = cdGetFontSizePixels(ctxcanvas->canvas, ctxcanvas->canvas->font_size);
- descent=get_descent(s, size_pixel);
+ descent=get_descent(s, len, size_pixel);
hc = size_pixel+descent;
- wc = gettextwidth(ctxcanvas, s, size_pixel);
+ wc = gettextwidth(ctxcanvas, s, len, size_pixel);
y+=descent;
@@ -877,8 +872,8 @@ static void cdtext (cdCtxCanvas* ctxcanvas, int x, int y, const char *s)
put_long(ctxcanvas, 0);
put_long(ctxcanvas, x);
put_long(ctxcanvas, y);
- put_word(ctxcanvas, (unsigned short) n);
- writec(ctxcanvas, s, (short)(n+(n%2))); /* deve escrever sempre um numero par de caracteres */
+ put_word(ctxcanvas, (unsigned short)len);
+ writec(ctxcanvas, s, (short)(len+(len%2))); /* deve escrever sempre um numero par de caracteres */
if(italic)
{
@@ -1251,11 +1246,11 @@ static void cdgetfontdim (cdCtxCanvas* ctxcanvas, int *max_width, int *height, i
if(descent) *descent = size_pixel/2;
}
-static void cdgettextsize (cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height)
+static void cdgettextsize (cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height)
{
int size_pixel = cdGetFontSizePixels(ctxcanvas->canvas, ctxcanvas->canvas->font_size);
- if(height) *height = size_pixel + get_descent(s, size_pixel);
- if(width) *width = gettextwidth(ctxcanvas, s, size_pixel);
+ if(height) *height = size_pixel + get_descent(s, len, size_pixel);
+ if(width) *width = gettextwidth(ctxcanvas, s, len, size_pixel);
}
static int cdtextalignment (cdCtxCanvas* ctxcanvas, int alignment)
diff --git a/src/drv/cddxf.c b/src/drv/cddxf.c
index b5c8854..b4dc875 100644
--- a/src/drv/cddxf.c
+++ b/src/drv/cddxf.c
@@ -563,7 +563,7 @@ static void cdsector (cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, doub
fprintf ( ctxcanvas->file, "SEQEND\n" );
}
-static void cdtext (cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void cdtext (cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
fprintf ( ctxcanvas->file, "0\n" );
fprintf ( ctxcanvas->file, "TEXT\n" );
@@ -592,7 +592,10 @@ static void cdtext (cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
fprintf ( ctxcanvas->file, "73\n" );
fprintf ( ctxcanvas->file, "%3d\n", ctxcanvas->tva ); /* text vertical alignment */
fprintf ( ctxcanvas->file, "1\n" );
+
+ s = cdStrDupN(s, len);
fprintf ( ctxcanvas->file, "%s\n", s ); /* text */
+ free((char*)s);
}
@@ -774,13 +777,14 @@ static void cdgetfontdim (cdCtxCanvas *ctxcanvas, int *max_width, int *height, i
}
}
-static void cdgettextsize (cdCtxCanvas *ctxcanvas, const char *s, int *width, int *height)
+static void cdgettextsize (cdCtxCanvas *ctxcanvas, const char *s, int len, int *width, int *height)
{
int i;
double tangent_ta;
double pixel_th;
+ (void)s;
- i = (int)strlen(s);
+ i = len;
tangent_ta = tan(ctxcanvas->toa*CD_DEG2RAD);
pixel_th = (ctxcanvas->th*ctxcanvas->canvas->xres)/CD_MM2PT; /* points to pixels */
diff --git a/src/drv/cdirgb.c b/src/drv/cdirgb.c
index c590dcf..2666a5a 100644
--- a/src/drv/cdirgb.c
+++ b/src/drv/cdirgb.c
@@ -475,7 +475,7 @@ static void irgbClipTextBitmap(FT_Bitmap* bitmap, int x, int y, int w, unsigned
}
}
-static void irgbClipText(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void irgbClipText(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
cdCanvas* canvas = ctxcanvas->canvas;
cdSimulation* simulation = canvas->simulation;
@@ -484,6 +484,7 @@ static void irgbClipText(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;
@@ -492,16 +493,16 @@ static void irgbClipText(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
slot = face->glyph;
/* 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 */
@@ -513,7 +514,7 @@ static void irgbClipText(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
pen.x += slot->advance.x;
pen.y += slot->advance.y;
- s++;
+ i++;
}
if (canvas->combine_mode == CD_INTERSECT)
@@ -992,15 +993,15 @@ static void cdchord(cdCtxCanvas *ctxcanvas, int xc, int yc, int w, int h, double
cdchordSIM(ctxcanvas, xc, yc, w, h, a1, a2);
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
if (ctxcanvas->canvas->new_region)
{
- irgbClipText(ctxcanvas, x, y, s);
+ irgbClipText(ctxcanvas, x, y, s, len);
return;
}
- cdtextSIM(ctxcanvas, x, y, s);
+ cdtextSIM(ctxcanvas, x, y, s, len);
}
static void cdpoly(cdCtxCanvas* ctxcanvas, int mode, cdPoint* poly, int n)
diff --git a/src/drv/cdmf.c b/src/drv/cdmf.c
index 6c2e711..d44bb5e 100644
--- a/src/drv/cdmf.c
+++ b/src/drv/cdmf.c
@@ -216,14 +216,18 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
fprintf(ctxcanvas->file, "%d %g %g %g %g %g %g\n", CDMF_FCHORD, xc, yc, w, h, a1, a2);
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text, int len)
{
+ text = cdStrDupN(text, len);
fprintf(ctxcanvas->file, "%d %d %d %s\n", CDMF_TEXT, x, y, text);
+ free((char*)text);
}
-static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text)
+static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text, int len)
{
+ text = cdStrDupN(text, len);
fprintf(ctxcanvas->file, "%d %g %g %s\n", CDMF_FTEXT, x, y, text);
+ free((char*)text);
}
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
diff --git a/src/drv/cdpdf.c b/src/drv/cdpdf.c
index 24509f6..79ce28f 100644
--- a/src/drv/cdpdf.c
+++ b/src/drv/cdpdf.c
@@ -474,15 +474,15 @@ static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, in
if (max_width) *max_width = (int)(PDF_info_textline(ctxcanvas->pdf, "W", 0, "width", "")/ctxcanvas->scale);
}
-static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *s, int *width, int *height)
+static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *s, int len, int *width, int *height)
{
if (ctxcanvas->font<0)
return;
if (height) cdgetfontdim(ctxcanvas, NULL, height, NULL, NULL);
- if (width) *width = (int)(PDF_info_textline(ctxcanvas->pdf, s, 0, "width", "")/ctxcanvas->scale);
+ if (width) *width = (int)(PDF_info_textline(ctxcanvas->pdf, s, len, "width", "")/ctxcanvas->scale);
}
-static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s)
+static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, int len)
{
char temp[200], options[200];
@@ -557,12 +557,12 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s)
break;
}
- PDF_fit_textline(ctxcanvas->pdf, s, 0, x, y, options);
+ PDF_fit_textline(ctxcanvas->pdf, s, len, x, y, options);
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
- cdftext(ctxcanvas, (double)x, (double)y, s);
+ cdftext(ctxcanvas, (double)x, (double)y, s, len);
}
static void cdpoly(cdCtxCanvas *ctxcanvas, int mode, cdPoint* poly, int n)
diff --git a/src/drv/cdpicture.c b/src/drv/cdpicture.c
index 3f5598e..ff4f532 100644
--- a/src/drv/cdpicture.c
+++ b/src/drv/cdpicture.c
@@ -569,32 +569,32 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
}
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *text, int len)
{
int xmin, xmax, ymin, ymax;
tPrimNode *prim = primCreate(CDPIC_TEXT);
primAddAttrib_Text(prim, ctxcanvas->canvas);
prim->param.text.x = x;
prim->param.text.y = y;
- prim->param.text.s = cdStrDup(text);
+ prim->param.text.s = cdStrDupN(text, len);
prim->param_buffer = prim->param.text.s;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetTextBox(ctxcanvas->canvas, x, y, text, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetTextBox(ctxcanvas->canvas, x, y, prim->param.text.s, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
}
-static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text)
+static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *text, int len)
{
int xmin, xmax, ymin, ymax;
tPrimNode *prim = primCreate(CDPIC_FTEXT);
primAddAttrib_Text(prim, ctxcanvas->canvas);
prim->param.textf.x = x;
prim->param.textf.y = y;
- prim->param.textf.s = cdStrDup(text);
+ prim->param.textf.s = cdStrDupN(text, len);
prim->param_buffer = prim->param.textf.s;
picAddPrim(ctxcanvas, prim);
- cdCanvasGetTextBox(ctxcanvas->canvas, _cdRound(x), _cdRound(y), text, &xmin, &xmax, &ymin, &ymax);
+ cdCanvasGetTextBox(ctxcanvas->canvas, _cdRound(x), _cdRound(y), prim->param.text.s, &xmin, &xmax, &ymin, &ymax);
picUpdateBBox(ctxcanvas, xmin, ymin, 0);
picUpdateBBox(ctxcanvas, xmax, ymax, 0);
}
diff --git a/src/drv/cdps.c b/src/drv/cdps.c
index 0d23608..d5d62fe 100644
--- a/src/drv/cdps.c
+++ b/src/drv/cdps.c
@@ -871,9 +871,9 @@ static void cdfchord(cdCtxCanvas *ctxcanvas, double xc, double yc, double w, dou
static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix);
-static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
+static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s, int len)
{
- int i, length;
+ int i;
int ascent, height, baseline;
update_fill(ctxcanvas, 0);
@@ -889,7 +889,7 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
fprintf(ctxcanvas->file, "N 0 0 M\n");
putc('(', ctxcanvas->file);
- for (length = (int)strlen(s), i=0; i<length; i++)
+ for (i=0; i<len; i++)
{
if (s[i]=='(' || s[i]==')')
putc('\\', ctxcanvas->file);
@@ -975,7 +975,9 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s)
if (ctxcanvas->eps)
{
int xmin, xmax, ymin, ymax;
+ s = cdStrDupN(s, len);
cdCanvasGetTextBox(ctxcanvas->canvas, x, y, s, &xmin, &xmax, &ymin, &ymax);
+ free((char*)s);
bbox(ctxcanvas, xmin, ymin);
bbox(ctxcanvas, xmax, ymax);
}
diff --git a/src/drv/cgm.c b/src/drv/cgm.c
index 55461cb..e86baaf 100644
--- a/src/drv/cgm.c
+++ b/src/drv/cgm.c
@@ -46,7 +46,7 @@ struct _cgmFunc
void (*r)( CGM *, double );
/* put string */
- void (*s)( CGM *, const char * );
+ void (*s)( CGM *, const char *, int );
/* put VDC at VDC mode and precision */
void (*vdc)( CGM *, double );
@@ -365,7 +365,7 @@ static void cgmb_e ( CGM *, int, const char *l[] ); /* put enum ( int*2 )
static void cgmb_i ( CGM *, long ); /* put int ( integer precision ) */
static void cgmb_u ( CGM *, unsigned long ); /* put unsigned int ( integer precision ) */
static void cgmb_r ( CGM *, double ); /* put real ( real precision ) */
-static void cgmb_s ( CGM *, const char * ); /* put string */
+static void cgmb_s ( CGM *, const char *, int ); /* put string */
static void cgmb_vdc ( CGM *, double ); /* put VDC at VDC mode and precision */
static void cgmb_p ( CGM *, double, double ); /* put point at VDC mode and precision */
static void cgmb_co ( CGM *, const void * ); /* put colour at colour mode and precision */
@@ -401,11 +401,11 @@ static void cgmt_ci ( CGM *, unsigned long ); /* put colour index at c
static void cgmt_cd ( CGM *, double ); /* put color direct at colour direct precision */
static void cgmt_rgb ( CGM *, double, double, double ); /* put color direct (rgb) at colour direct precision */
static void cgmt_ix ( CGM *, long ); /* put index at index precision */
-static void cgmt_e ( CGM *, int, const char *l[] ); /* put enum ( int*2 ) */
+static void cgmt_e ( CGM *, int, const char *l[] ); /* put enum ( int*2 ) */
static void cgmt_i ( CGM *, long ); /* put int ( integer precision ) */
static void cgmt_u ( CGM *, unsigned long ); /* put unsigned int ( integer precision ) */
static void cgmt_r ( CGM *, double ); /* put real ( real precision ) */
-static void cgmt_s ( CGM *, const char * ); /* put string */
+static void cgmt_s ( CGM *, const char *, int ); /* put string */
static void cgmt_vdc ( CGM *, double ); /* put VDC at VDC mode and precision */
static void cgmt_p ( CGM *, double, double ); /* put point at VDC mode and precision */
static void cgmt_co ( CGM *, const void * ); /* put colour at colour mode and precision */
@@ -441,11 +441,11 @@ static void cgmc_ci ( CGM *, unsigned long ); /* put colour index at c
static void cgmc_cd ( CGM *, double ); /* put color direct at colour direct precision */
static void cgmc_rgb ( CGM *, double, double, double ); /* put color direct (rgb) at colour direct precision */
static void cgmc_ix ( CGM *, long ); /* put index at index precision */
-static void cgmc_e ( CGM *, int, const char *l[] ); /* put enum ( int*2 ) */
+static void cgmc_e ( CGM *, int, const char *l[] ); /* put enum ( int*2 ) */
static void cgmc_i ( CGM *, long ); /* put int ( integer precision ) */
static void cgmc_u ( CGM *, unsigned long ); /* put unsigned int ( integer precision ) */
static void cgmc_r ( CGM *, double ); /* put real ( real precision ) */
-static void cgmc_s ( CGM *, const char * ); /* put string */
+static void cgmc_s ( CGM *, const char *, int ); /* put string */
static void cgmc_vdc ( CGM *, double ); /* put VDC at VDC mode and precision */
static void cgmc_p ( CGM *, double, double ); /* put point at VDC mode and precision */
static void cgmc_co ( CGM *, const void * ); /* put colour at colour mode and precision */
@@ -725,10 +725,10 @@ static void cgmb_r ( CGM *cgm, double func )
}
}
-static void cgmb_s ( CGM *cgm, const char *s )
+static void cgmb_s ( CGM *cgm, const char *s, int len )
{
register unsigned i;
- unsigned l = strlen(s);
+ unsigned l = len;
int bc = 0;
if ( l > 254 )
@@ -743,7 +743,7 @@ static void cgmb_s ( CGM *cgm, const char *s )
else
cgmb_putu8(cgm,l);
- for ( i=0; s[i]; s++ )
+ for ( i=0; i<len; s++ )
{
if ( (i + bc) == 32766 )
{
@@ -909,12 +909,12 @@ static void cgmt_r ( CGM *cgm, double func )
cgm->cl += fprintf ( unit, " %g", func );
}
-static void cgmt_s ( CGM *cgm, const char *s )
+static void cgmt_s ( CGM *cgm, const char *s, int len )
{
register unsigned i;
fputc ( 34, unit );
- for ( i=0; s[i]; i++ )
+ for ( i=0; i<len; i++ )
{
if ( s[i] == 34 )
{
@@ -925,7 +925,7 @@ static void cgmt_s ( CGM *cgm, const char *s )
}
fputc ( 34, unit );
- cgm->cl += strlen (s) + 2;
+ cgm->cl += len + 2;
}
static void cgmt_vdc ( CGM *cgm, double vdc)
@@ -1049,12 +1049,12 @@ static void cgmc_r ( CGM *cgm, double func )
cgm->cl += fprintf ( unit, " %g", func );
}
-static void cgmc_s ( CGM *cgm, const char *s )
+static void cgmc_s ( CGM *cgm, const char *s, int len )
{
register unsigned i;
fputc ( 34, unit );
- for ( i=0; s[i]; i++ )
+ for ( i=0; i<len; i++ )
{
if ( s[i] == 34 )
{
@@ -1065,7 +1065,7 @@ static void cgmc_s ( CGM *cgm, const char *s )
}
fputc ( 34, unit );
- cgm->cl += strlen (s) + 2;
+ cgm->cl += len + 2;
}
static void cgmc_vdc ( CGM *cgm, double vdc)
@@ -1168,6 +1168,7 @@ static const char *offon[] = { "OFF", "ON" };
CGM *cgm_begin_metafile ( char *file, int mode, char *header )
{
CGM *cgm;
+ int len;
if ( (cgm = (CGM *)malloc ( sizeof (CGM) ) ) == NULL )
return NULL;
@@ -1227,9 +1228,10 @@ CGM *cgm_begin_metafile ( char *file, int mode, char *header )
cgm->op = -1;
- cgm->func->wch ( cgm, 0, 1, strlen ( header ) + 1 );
+ len = strlen(header);
+ cgm->func->wch ( cgm, 0, 1, len+1 );
- cgm->func->s ( cgm, header );
+ cgm->func->s ( cgm, header, len );
cgm->func->term ( cgm );
@@ -1258,8 +1260,9 @@ int cgm_end_metafile ( CGM *cgm )
int cgm_begin_picture (CGM *cgm, const char *s )
{
- cgm->func->wch ( cgm, 0, 3, strlen(s)+1 );
- cgm->func->s ( cgm, s );
+ int len = strlen(s);
+ cgm->func->wch ( cgm, 0, 3, len+1 );
+ cgm->func->s ( cgm, s, len );
return cgm->func->term(cgm);
}
@@ -1290,8 +1293,9 @@ int cgm_metafile_version ( CGM *cgm, long version )
int cgm_metafile_description ( CGM *cgm, const char *s )
{
- cgm->func->wch ( cgm, 1, 2, 1+strlen(s) );
- cgm->func->s ( cgm, s );
+ int len = strlen(s);
+ cgm->func->wch ( cgm, 1, 2, 1+len);
+ cgm->func->s ( cgm, s, len );
return cgm->func->term(cgm);
}
@@ -1520,7 +1524,7 @@ int cgm_font_list ( CGM *cgm, const char *fl[] )
{
cgm->func->nl ( cgm );
cgm->func->align ( cgm, 10 );
- cgm->func->s ( cgm, fl[i] );
+ cgm->func->s ( cgm, fl[i], strlen(fl[i]) );
}
return cgm->func->term(cgm);
@@ -1757,39 +1761,34 @@ int cgm_polymarker ( CGM *cgm, int n, const double *p )
return _cgm_point_list ( cgm, 3, n, p );
}
-static int _cgm_text_piece ( CGM *cgm, int t, const char *s)
+static int _cgm_text_piece ( CGM *cgm, int t, const char *s, int len)
{
static const char *tt[] = { "NOT_FINAL", " FINAL" };
cgm->func->e ( cgm, t, tt );
- cgm->func->s ( cgm, s );
+ cgm->func->s ( cgm, s , len);
return cgm->func->term(cgm);
}
-int cgm_text ( CGM *cgm, int tt, double x, double y, const char *s )
+int cgm_text ( CGM *cgm, int tt, double x, double y, const char *s, int len )
{
- cgm->func->wch ( cgm, 4, 4, 2 * cgm->vdc_size + strlen(s) + 3 );
+ cgm->func->wch ( cgm, 4, 4, 2 * cgm->vdc_size + len + 3 );
cgm->func->p ( cgm, x, y );
cgm->func->nl ( cgm );
cgm->func->align ( cgm, 10 );
if ( cgm->mode == 2 ) /* clear text */
{
- while ( strlen (s) > 50 )
+ while ( len > 50 )
{
- char s1[51];
-
- strncpy ( s1, s, 50 );
- s1[50] = 0;
-
- _cgm_text_piece ( cgm, 0, s1 );
-
+ _cgm_text_piece ( cgm, 0, s, 50);
s += 50;
- cgm->func->wch ( cgm, 4, 6, 2 * cgm->vdc_size + strlen(s) + 1 );
- }
+ len -= 50;
+ cgm->func->wch ( cgm, 4, 6, 2 * cgm->vdc_size + len + 1 );
+ }
}
- return _cgm_text_piece ( cgm, tt, s );
+ return _cgm_text_piece ( cgm, tt, s, len );
}
int cgm_polygon ( CGM *cgm, int n, const double *p )
@@ -2276,6 +2275,6 @@ int cgm_message ( CGM *cgm, int action, const char *s)
static const char *ac[] = { "NOACTION", "ACTION" };
cgm->func->wch ( cgm, 7, 2, 2 + strlen(s)+1 );
cgm->func->e ( cgm, action, ac );
- cgm->func->s ( cgm, s );
+ cgm->func->s ( cgm, s, strlen(s) );
return cgm->func->term(cgm);
}
diff --git a/src/drv/cgm.h b/src/drv/cgm.h
index 0404604..632ebeb 100644
--- a/src/drv/cgm.h
+++ b/src/drv/cgm.h
@@ -84,7 +84,7 @@ int cgm_clip_rectangle ( CGM *, double, double, double, double );
int cgm_clip_indicator ( CGM *, int );
int cgm_polyline ( CGM *, int, const double * );
int cgm_polymarker ( CGM *, int, const double * );
-int cgm_text ( CGM *, int, double, double, const char * );
+int cgm_text ( CGM *, int, double, double, const char *, int);
int cgm_polygon ( CGM *, int, const double * );
int cgm_cell_array ( CGM *, const double *, long, long, int, const void * );
int cgm_rectangle ( CGM *, const double * );