From f658209d25477c490bf1892e68a0fd1384c1dded Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 23 Jun 2009 20:55:28 +0000 Subject: *** empty log message *** --- html/en/history.html | 8 +- include/cd_private.h | 13 +-- mak.vc9/cdpdf.vcproj | 2 +- src/cd_text.c | 96 +++++++++--------- src/cd_util.c | 16 +++ src/cd_vectortext.c | 259 +++++++++++++++++++++--------------------------- src/drv/cdcgm.c | 12 +-- src/drv/cddebug.c | 12 ++- src/drv/cddgn.c | 37 +++---- src/drv/cddxf.c | 10 +- src/drv/cdirgb.c | 19 ++-- src/drv/cdmf.c | 8 +- src/drv/cdpdf.c | 12 +-- src/drv/cdpicture.c | 12 +-- src/drv/cdps.c | 8 +- src/drv/cgm.c | 75 +++++++------- src/drv/cgm.h | 2 +- src/gdiplus/cdwinp.cpp | 17 ++-- src/sim/cd_truetype.c | 16 ++- src/sim/cdfontex.c | 25 ++--- src/sim/sim.h | 2 +- src/sim/sim_text.c | 29 +++--- src/win32/cdwclp.c | 35 +++---- src/win32/cdwin.c | 32 +++--- src/win32/cdwin.h | 4 +- src/win32/wmf_emf.c | 84 ++++++++-------- src/x11/cdx11.c | 19 ++-- src/x11/xvertex.c | 69 ++++++------- src/x11/xvertex.h | 4 +- src/xrender/cdxrender.c | 12 +-- test/simple/simple.c | 12 ++- 31 files changed, 472 insertions(+), 489 deletions(-) diff --git a/html/en/history.html b/html/en/history.html index 25355fc..0a2ecf7 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -16,16 +16,16 @@ CanvasGetVectorTextBox, CanvasGetVectorFontSize and CanvasVectorFontSize.
  • Changed: - CD_DBUFFER now activates the buffered canvas before creating the image - canvas. If size is 0 then uses 1 and avoid to fail during creation.
  • -
  • Changed: the functions CanvasVectorText, CanvasText and CanvasGetTextSize now supports line breaks using '\n'. CanvasMultiLineVectorText is now deprecated but kept for compatibility. IMPORTANT - VectorTextSize now - includes the full line size.
  • + uses the full line size. +
  • Changed: + CD_DBUFFER now activates the buffered canvas before creating the image + canvas. If size is 0 then uses 1 and avoid to fail during creation.
  • Fixed: CanvasText for CD_IMAGERGB driver when the foreground color has alpha.
  • diff --git a/include/cd_private.h b/include/cd_private.h index 14db96e..c45359f 100644 --- a/include/cd_private.h +++ b/include/cd_private.h @@ -92,7 +92,7 @@ struct _cdCanvas void (*cxArc)(cdCtxCanvas* ctxcanvas, int xc, int yc, int w, int h, double angle1, double angle2); void (*cxSector)(cdCtxCanvas* ctxcanvas, int xc, int yc, int w, int h, double angle1, double angle2); void (*cxChord)(cdCtxCanvas* ctxcanvas, int xc, int yc, int w, int h, double angle1, double angle2); - void (*cxText)(cdCtxCanvas* ctxcanvas, int x, int y, const char *s); + void (*cxText)(cdCtxCanvas* ctxcanvas, int x, int y, const char *s, int len); void (*cxKillCanvas)(cdCtxCanvas* ctxcanvas); int (*cxFont)(cdCtxCanvas* ctxcanvas, const char *type_face, int style, int size); void (*cxPutImageRectMap)(cdCtxCanvas* ctxcanvas, int iw, int ih, const unsigned char *index, const long *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax); @@ -100,7 +100,7 @@ struct _cdCanvas /* default implementation uses the simulation driver */ void (*cxGetFontDim)(cdCtxCanvas* ctxcanvas, int *max_width, int *height, int *ascent, int *descent); - void (*cxGetTextSize)(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height); + void (*cxGetTextSize)(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height); /* all the following function pointers can be NULL */ @@ -114,7 +114,7 @@ struct _cdCanvas void (*cxFArc)(cdCtxCanvas* ctxcanvas, double xc, double yc, double w, double h, double angle1, double angle2); void (*cxFSector)(cdCtxCanvas* ctxcanvas, double xc, double yc, double w, double h, double angle1, double angle2); void (*cxFChord)(cdCtxCanvas* ctxcanvas, double xc, double yc, double w, double h, double angle1, double angle2); - void (*cxFText)(cdCtxCanvas* ctxcanvas, double x, double y, const char *s); + void (*cxFText)(cdCtxCanvas* ctxcanvas, double x, double y, const char *s, int len); int (*cxClip)(cdCtxCanvas* ctxcanvas, int mode); void (*cxClipArea)(cdCtxCanvas* ctxcanvas, int xmin, int xmax, int ymin, int ymax); @@ -270,6 +270,7 @@ int cdGetFileName(const char* strdata, char* filename); int cdStrEqualNoCase(const char* str1, const char* str2); int cdStrLineCount(const char* str); char* cdStrDup(const char* str); +char* cdStrDupN(const char* str, int len); #define _cdCheckCanvas(_canvas) (_canvas!=NULL && ((unsigned char*)_canvas)[0] == 'C' && ((unsigned char*)_canvas)[1] == 'D') #define _cdInvertYAxis(_canvas, _y) (_canvas->h - (_y) - 1) @@ -335,10 +336,10 @@ void cdchordSIM(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, d void cdpolySIM(cdCtxCanvas* ctxcanvas, int mode, cdPoint* points, int n); /* Replacements for Text and Font using FreeType library */ -void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char *s); +void cdtextSIM(cdCtxCanvas* ctxcanvas, int x, int y, const char *s, int len); int cdfontSIM(cdCtxCanvas* ctxcanvas, const char *type_face, int style, int size); void cdgetfontdimSIM(cdCtxCanvas* ctxcanvas, int *max_width, int *height, int *ascent, int *descent); -void cdgettextsizeSIM(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height); +void cdgettextsizeSIM(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height); /* Simulation functions that are independent of the simulation base driver */ void cdSimMark(cdCanvas* canvas, int x, int y); @@ -356,7 +357,7 @@ void cdfSimArc(cdCtxCanvas *ctxcanvas, double xc, double yc, double width, doubl /* Replacements for Font using estimation */ void cdgetfontdimEX(cdCtxCanvas* ctxcanvas, int *max_width, int *height, int *ascent, int *descent); -void cdgettextsizeEX(cdCtxCanvas* ctxcanvas, const char *s, int *width, int *height); +void cdgettextsizeEX(cdCtxCanvas* ctxcanvas, const char *s, int len, int *width, int *height); #ifdef __cplusplus diff --git a/mak.vc9/cdpdf.vcproj b/mak.vc9/cdpdf.vcproj index d705199..da0e4bf 100644 --- a/mak.vc9/cdpdf.vcproj +++ b/mak.vc9/cdpdf.vcproj @@ -50,7 +50,7 @@ ProgramDataBaseFileName="..\obj\cdpdf/" WarningLevel="4" SuppressStartupBanner="true" - Detect64BitPortabilityProblems="true" + Detect64BitPortabilityProblems="false" DebugInformationFormat="1" CompileAs="0" /> diff --git a/src/cd_text.c b/src/cd_text.c index 8a5ff81..4b3e839 100644 --- a/src/cd_text.c +++ b/src/cd_text.c @@ -32,21 +32,20 @@ void cdCanvasText(cdCanvas* canvas, int x, int y, const char *s) y += canvas->origin.y; } - if (canvas->invert_yaxis) - y = _cdInvertYAxis(canvas, y); - num_line = cdStrLineCount(s); if (num_line == 1) - canvas->cxText(canvas->ctxcanvas, x, y, s); + { + if (canvas->invert_yaxis) + y = _cdInvertYAxis(canvas, y); + + canvas->cxText(canvas->ctxcanvas, x, y, s, strlen(s)); + } else { - int i, line_height; - char *p, *q, *new_s; + int yr, i, line_height, len; + const char *p, *q; double cos_theta = 0, sin_theta = 0; - new_s = cdStrDup(s); - p = new_s; - canvas->cxGetFontDim(canvas->ctxcanvas, NULL, &line_height, NULL, NULL); if (canvas->text_orientation) @@ -86,13 +85,19 @@ void cdCanvasText(cdCanvas* canvas, int x, int y, const char *s) y += ((num_line-1)*line_height)/2; } + p = s; for(i = 0; i < num_line; i++) { q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ + if (q) len = (int)(q-p); /* Cut the string to contain only one line */ + else len = strlen(p); /* Draw the line */ - canvas->cxText(canvas->ctxcanvas, x, y, p); + if (canvas->invert_yaxis) + yr = _cdInvertYAxis(canvas, y); + else + yr = y; + canvas->cxText(canvas->ctxcanvas, x, yr, p, len); /* Advance the string */ if (q) p = q + 1; @@ -103,8 +108,6 @@ void cdCanvasText(cdCanvas* canvas, int x, int y, const char *s) else y -= line_height; } - - free(new_s); } } @@ -125,25 +128,22 @@ void cdfCanvasText(cdCanvas* canvas, double x, double y, const char *s) y += canvas->forigin.y; } - if (canvas->invert_yaxis) - y = _cdInvertYAxis(canvas, y); - num_line = cdStrLineCount(s); if (num_line == 1) { + if (canvas->invert_yaxis) + y = _cdInvertYAxis(canvas, y); + if (canvas->cxFText) - canvas->cxFText(canvas->ctxcanvas, x, y, s); + canvas->cxFText(canvas->ctxcanvas, x, y, s, strlen(s)); else - canvas->cxText(canvas->ctxcanvas, _cdRound(x), _cdRound(y), s); + canvas->cxText(canvas->ctxcanvas, _cdRound(x), _cdRound(y), s, strlen(s)); } else { - int i, line_height; - char *p, *q, *new_s; - double cos_theta = 0, sin_theta = 0; - - new_s = cdStrDup(s); - p = new_s; + int i, line_height, len; + const char *p, *q; + double yr, cos_theta = 0, sin_theta = 0; canvas->cxGetFontDim(canvas->ctxcanvas, NULL, &line_height, NULL, NULL); @@ -167,16 +167,22 @@ void cdfCanvasText(cdCanvas* canvas, double x, double y, const char *s) cdfMovePoint(&x, &y, 0, (num_line-1)*line_height/2.0, sin_theta, cos_theta); } + p = s; for(i = 0; i < num_line; i++) { q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ + if (q) len = (int)(q-p); /* Cut the string to contain only one line */ + else len = strlen(p); /* Draw the line */ + if (canvas->invert_yaxis) + yr = _cdInvertYAxis(canvas, y); + else + yr = y; if (canvas->cxFText) - canvas->cxFText(canvas->ctxcanvas, x, y, p); + canvas->cxFText(canvas->ctxcanvas, x, yr, p, len); else - canvas->cxText(canvas->ctxcanvas, _cdRound(x), _cdRound(y), p); + canvas->cxText(canvas->ctxcanvas, _cdRound(x), _cdRound(yr), p, len); /* Advance the string */ if (q) p = q + 1; @@ -187,8 +193,6 @@ void cdfCanvasText(cdCanvas* canvas, double x, double y, const char *s) else y -= line_height; } - - free(new_s); } } @@ -375,34 +379,32 @@ void cdCanvasGetTextSize(cdCanvas* canvas, const char *s, int *width, int *heigh num_line = cdStrLineCount(s); if (num_line == 1) - canvas->cxGetTextSize(canvas->ctxcanvas, s, width, height); + canvas->cxGetTextSize(canvas->ctxcanvas, s, strlen(s), width, height); else { - int i, line_height, max_w = 0, w; - char *p, *q, *new_s; + int i, line_height, max_w = 0, w, len; + const char *p, *q; - new_s = cdStrDup(s); - p = new_s; + p = s; canvas->cxGetFontDim(canvas->ctxcanvas, NULL, &line_height, NULL, NULL); for(i = 0; i < num_line; i++) { q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ + if (q) len = (int)(q-p); /* Cut the string to contain only one line */ + else len = strlen(p); /* Calculate line width */ - canvas->cxGetTextSize(canvas->ctxcanvas, p, &w, NULL); + canvas->cxGetTextSize(canvas->ctxcanvas, p, len, &w, NULL); if (w > max_w) max_w = w; /* Advance the string */ - if (q) p = q + 1; + if (q) p = q + 1; /* skip line break */ } if (width) *width = max_w; if (height) *height = num_line*line_height; - - free(new_s); } } @@ -468,9 +470,9 @@ void cdTextTranslatePoint(cdCanvas* canvas, int x, int y, int w, int h, int base void cdCanvasGetTextBounds(cdCanvas* canvas, int x, int y, const char *s, int *rect) { - int w, h, ascent, height, baseline; + int w, h, ascent, line_height, baseline; int xmin, xmax, ymin, ymax; - int old_invert_yaxis = canvas->invert_yaxis; + int old_invert_yaxis, num_lin; assert(canvas); assert(s); @@ -480,10 +482,14 @@ void cdCanvasGetTextBounds(cdCanvas* canvas, int x, int y, const char *s, int *r return; cdCanvasGetTextSize(canvas, s, &w, &h); - cdCanvasGetFontDim(canvas, NULL, &height, &ascent, NULL); - baseline = height - ascent; - - /* in this case we are always upwards */ + cdCanvasGetFontDim(canvas, NULL, &line_height, &ascent, NULL); + baseline = line_height - ascent; + num_lin = h/line_height; + if (num_lin > 1) + baseline += (num_lin-1)*line_height; + + /* from here we are always upwards */ + old_invert_yaxis = canvas->invert_yaxis; canvas->invert_yaxis = 0; /* move to bottom-left */ diff --git a/src/cd_util.c b/src/cd_util.c index dadb6f4..1767ac4 100644 --- a/src/cd_util.c +++ b/src/cd_util.c @@ -333,3 +333,19 @@ char* cdStrDup(const char *str) } return NULL; } + +char* cdStrDupN(const char *str, int len) +{ + if (str) + { + int size = len+1; + char *newstr = malloc(size); + if (newstr) + { + memcpy(newstr, str, len); + newstr[len]=0; + } + return newstr; + } + return NULL; +} diff --git a/src/cd_vectortext.c b/src/cd_vectortext.c index 0be62af..4e196b6 100644 --- a/src/cd_vectortext.c +++ b/src/cd_vectortext.c @@ -4259,7 +4259,7 @@ static int vf_readfontfile(FILE *file, cdVectorFont *vector_font) return 1; } -static int vf_readfontstring(const char* file, cdVectorFont *vector_font) +static int vf_readfontstring(const char* strdata, cdVectorFont *vector_font) { int c, right, center, operations; @@ -4271,33 +4271,33 @@ static int vf_readfontstring(const char* file, cdVectorFont *vector_font) return 0; /* try to read without a name */ - if (sscanf(file,"%d%d%d%d",&vector_font->top,&vector_font->cap,&vector_font->half,&vector_font->bottom) != 4) + if (sscanf(strdata,"%d%d%d%d",&vector_font->top,&vector_font->cap,&vector_font->half,&vector_font->bottom) != 4) { - if (sscanf(file, "%[^\n]", vector_font->name) != 1) + if (sscanf(strdata, "%[^\n]", vector_font->name) != 1) return 0; - file = strstr(file, "\n")+1; /* goto next line */ - if (file == (void*)1) return 0; + strdata = strstr(strdata, "\n")+1; /* goto next line */ + if (strdata == (void*)1) return 0; - if (sscanf(file,"%d%d%d%d",&vector_font->top,&vector_font->cap,&vector_font->half,&vector_font->bottom)!=4) + if (sscanf(strdata,"%d%d%d%d",&vector_font->top,&vector_font->cap,&vector_font->half,&vector_font->bottom)!=4) return 0; - file = strstr(file, "\n"); /* goto next line */ - if (file == (void*)1) return 0; + strdata = strstr(strdata, "\n"); /* goto next line */ + if (strdata == (void*)1) return 0; } else { - file = strstr(file, "\n")+1; /* goto next line */ + strdata = strstr(strdata, "\n")+1; /* goto next line */ sprintf(vector_font->name, "Unknown"); } /* skip 2 blank lines */ - file = strstr(file, "\n")+1; /* goto next line */ - file = strstr(file, "\n")+1; /* goto next line */ + strdata = strstr(strdata, "\n")+1; /* goto next line */ + strdata = strstr(strdata, "\n")+1; /* goto next line */ /* for each font character */ - while (sscanf(file, "%d%d%d%d", &c, &right, ¢er, &operations) == 4) + while (sscanf(strdata, "%d%d%d%d", &c, &right, ¢er, &operations) == 4) { - file = strstr(file, "\n")+1; /* goto next line */ - if (file == (void*)1) return 0; + strdata = strstr(strdata, "\n")+1; /* goto next line */ + if (strdata == (void*)1) return 0; vector_font->chars[c].right = right; vector_font->chars[c].center = center; @@ -4312,10 +4312,10 @@ static int vf_readfontstring(const char* file, cdVectorFont *vector_font) char operation; int x, y; - if (sscanf(file, "%c%d%d", &operation, &x, &y) != 3) + if (sscanf(strdata, "%c%d%d", &operation, &x, &y) != 3) return 0; - file = strstr(file, "\n")+1; /* goto next line */ - if (file == (void*)1) return 0; + strdata = strstr(strdata, "\n")+1; /* goto next line */ + if (strdata == (void*)1) return 0; vector_font->chars[c].op[i].operation = operation; vector_font->chars[c].op[i].x = (signed char)x; @@ -4324,18 +4324,18 @@ static int vf_readfontstring(const char* file, cdVectorFont *vector_font) } /* skip 1 blank line */ - file = strstr(file, "\n")+1; /* goto next line */ - if (file == (void*)1) return 1; + strdata = strstr(strdata, "\n")+1; /* goto next line */ + if (strdata == (void*)1) return 1; } return 1; } -static int vf_textwidth(cdVectorFont *vector_font, const char* s) +static int vf_textwidth(cdVectorFont *vector_font, const char* str) { int width = 0; - while (*s) - width += vector_font->chars[(unsigned char)(*(s++))].right; + while (*str && *str!='\n') + width += vector_font->chars[(unsigned char)(*(str++))].right; if (width==0) width = 1; return width; } @@ -4418,7 +4418,7 @@ static void vf_wdraw_char(cdVectorFont *vector_font, char c, double *x, double * if (m) cdCanvasEnd(vector_font->canvas); } -static void vf_move_to_base(cdVectorFont *vector_font, int *x, int *y, int width) +static void vf_move_to_base(cdVectorFont *vector_font, int *x, int *y, const char* str, int width) { /* move point to baseline/left according to alignment */ int align = vector_font->canvas->text_alignment; @@ -4440,6 +4440,7 @@ static void vf_move_to_base(cdVectorFont *vector_font, int *x, int *y, int width if (align == CD_EAST || align == CD_NORTH_EAST || align == CD_SOUTH_EAST || align == CD_BASE_RIGHT) { + if (str) width = vf_textwidth(vector_font, str); vf_move_dir(vector_font, x, y, -width*vector_font->size_x, 0); } else if (align == CD_WEST || align == CD_NORTH_WEST || align == CD_SOUTH_WEST || align == CD_BASE_LEFT) @@ -4448,11 +4449,12 @@ static void vf_move_to_base(cdVectorFont *vector_font, int *x, int *y, int width } else /* CD_CENTER || CD_NORTH || CD_SOUTH */ { + if (str) width = vf_textwidth(vector_font, str); vf_move_dir(vector_font, x, y, -(width*vector_font->size_x)/2.0, 0); } } -static void vf_wmove_to_base(cdVectorFont *vector_font, double *x, double *y, int width) +static void vf_wmove_to_base(cdVectorFont *vector_font, double *x, double *y, const char* str, int width) { /* move point to baseline/left according to alignment */ int align = vector_font->canvas->text_alignment; @@ -4474,6 +4476,7 @@ static void vf_wmove_to_base(cdVectorFont *vector_font, double *x, double *y, in if (align == CD_EAST || align == CD_NORTH_EAST || align == CD_SOUTH_EAST || align == CD_BASE_RIGHT) { + if (str) width = vf_textwidth(vector_font, str); vf_wmove_dir(vector_font, x, y, -width*vector_font->size_x, 0); } else if (align == CD_WEST || align == CD_NORTH_WEST || align == CD_SOUTH_WEST || align == CD_BASE_LEFT) @@ -4482,31 +4485,32 @@ static void vf_wmove_to_base(cdVectorFont *vector_font, double *x, double *y, in } else /* CD_CENTER || CD_NORTH || CD_SOUTH */ { + if (str) width = vf_textwidth(vector_font, str); vf_wmove_dir(vector_font, x, y, -(width*vector_font->size_x)/2.0, 0); } } -static void vf_draw_text(cdVectorFont* vector_font, int x, int y, const char* s, int width) +static void vf_draw_text(cdVectorFont* vector_font, int x, int y, const char* str) { - vf_move_to_base(vector_font, &x, &y, width); + vf_move_to_base(vector_font, &x, &y, str, 0); - while (*s) + while (*str && *str!='\n') { - vf_draw_char(vector_font, *s, &x, &y); - vf_move_dir(vector_font, &x, &y, (vector_font->chars[(unsigned char)*s].right)*vector_font->size_x, 0); - s++; + vf_draw_char(vector_font, *str, &x, &y); + vf_move_dir(vector_font, &x, &y, (vector_font->chars[(unsigned char)*str].right)*vector_font->size_x, 0); + str++; } } -static void vf_wdraw_text(cdVectorFont* vector_font, double x, double y, const char* s, int width) +static void vf_wdraw_text(cdVectorFont* vector_font, double x, double y, const char* str) { - vf_wmove_to_base(vector_font, &x, &y, width); + vf_wmove_to_base(vector_font, &x, &y, str, 0); - while (*s) + while (*str && *str!='\n') { - vf_wdraw_char(vector_font, *s, &x, &y); - vf_wmove_dir(vector_font, &x, &y, (vector_font->chars[(unsigned char)*s].right)*vector_font->size_x, 0); - s++; + vf_wdraw_char(vector_font, *str, &x, &y); + vf_wmove_dir(vector_font, &x, &y, (vector_font->chars[(unsigned char)*str].right)*vector_font->size_x, 0); + str++; } } @@ -4540,42 +4544,38 @@ static void vf_wcalc_point(cdVectorFont *vector_font, double start_x, double sta } } -static int vf_gettextmaxwidth(cdVectorFont* vector_font, const char* s, int num_lin) +static int vf_gettextmaxwidth(cdVectorFont* vector_font, const char* str, int num_lin) { int i, max_w = 0, w; - char *p, *q, *new_s; + const char *p_str, *q; - new_s = cdStrDup(s); - p = new_s; + p_str = str; for(i = 0; i < num_lin; i++) { - q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ - /* Calculate line width */ - w = vf_textwidth(vector_font, p); + w = vf_textwidth(vector_font, p_str); if (w > max_w) max_w = w; /* Advance the string */ - if (q) p = q + 1; + q = strchr(p_str, '\n'); + if (q) p_str = q + 1; /* skip line break */ } - free(new_s); return max_w; } -static void vf_gettextsize(cdVectorFont* vector_font, const char* s, int *width, int *height) +static void vf_gettextsize(cdVectorFont* vector_font, const char* str, int *width, int *height) { - int num_lin = cdStrLineCount(s); + int num_lin = cdStrLineCount(str); if (num_lin == 1) { - *width = vf_textwidth(vector_font, s); + *width = vf_textwidth(vector_font, str); *height = vector_font->top - vector_font->bottom; } else { - *width = vf_gettextmaxwidth(vector_font, s, num_lin); + *width = vf_gettextmaxwidth(vector_font, str, num_lin); *height = num_lin*(vector_font->top - vector_font->bottom); } } @@ -4612,15 +4612,6 @@ static void vf_wmove_to_first(cdVectorFont* vector_font, int align, double *x, d vf_wmove_dir(vector_font, x, y, 0, (num_lin-1)*line_height/2.0); } -static char *cd_getCDDIR(void) -{ - static char *env = NULL; - if (env) return env; - env = getenv("CDDIR"); - if (!env) env = "."; - return env; -} - /******************************************************/ /* vector text */ /******************************************************/ @@ -4681,6 +4672,7 @@ char *cdCanvasVectorFont(cdCanvas* canvas, const char *file) { FILE *font = NULL; int read_ok; + char *env; /* se arquivo foi o mesmo que o arq. corrente, entao retorna */ if (strcmp (file, vector_font->file_name) == 0) @@ -4690,10 +4682,11 @@ char *cdCanvasVectorFont(cdCanvas* canvas, const char *file) font = fopen(file, "r"); /* se nao conseguiu, abre arq. no dir. do cd, */ - if (!font && (strlen(file) < 10240 - strlen(cd_getCDDIR()))) + env = getenv("CDDIR"); + if (!font && env && strlen(file)<10240) { char filename[10240]; - sprintf(filename, "%s/%s", cd_getCDDIR(), file); + sprintf(filename, "%str/%str", env, file); font = fopen(filename, "r"); } @@ -4826,46 +4819,46 @@ int cdCanvasVectorCharSize(cdCanvas* canvas, int size) return old_size; } -void cdCanvasVectorTextSize(cdCanvas* canvas, int s_width, int s_height, const char* s) +void cdCanvasVectorTextSize(cdCanvas* canvas, int s_width, int s_height, const char* str) { int width, height; cdVectorFont* vector_font; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); vector_font->size_x = (double)s_width/(double)width; vector_font->size_y = (double)s_height/(double)height; } -void cdCanvasGetVectorTextSize(cdCanvas* canvas, const char *s, int *x, int *y) +void cdCanvasGetVectorTextSize(cdCanvas* canvas, const char *str, int *x, int *y) { int width, height; cdVectorFont* vector_font; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); if (x) *x = cdRound(width*vector_font->size_x); if (y) *y = cdRound(height*vector_font->size_y); } -void cdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, int x, int y, int *rect) +void cdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *str, int x, int y, int *rect) { cdVectorFont* vector_font; int sx, sy; @@ -4873,15 +4866,15 @@ void cdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, int x, int y, double line_height; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); num_lin = height/(vector_font->top - vector_font->bottom); sx = cdRound(width*vector_font->size_x); @@ -4897,7 +4890,7 @@ void cdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, int x, int y, } /* move to bottom/left corner */ - vf_move_to_base(vector_font, &x, &y, width); + vf_move_to_base(vector_font, &x, &y, NULL, width); vf_move_dir(vector_font, &x, &y, 0, vector_font->bottom*vector_font->size_y); /* from base/left to bottom/left of the first line */ if (num_lin > 1) vf_move_dir(vector_font, &x, &y, 0, -(height*vector_font->size_y - line_height)); /* from bottom/left to the bottom of the last line */ @@ -4908,12 +4901,12 @@ void cdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, int x, int y, vf_calc_point(vector_font, x, y, &rect[6], &rect[7], 0, sy); } -void cdCanvasGetVectorTextBox(cdCanvas* canvas, int x, int y, const char *s, int *xmin, int *xmax, int *ymin, int *ymax) +void cdCanvasGetVectorTextBox(cdCanvas* canvas, int x, int y, const char *str, int *xmin, int *xmax, int *ymin, int *ymax) { int rect[8]; int _xmin, _xmax, _ymin, _ymax; - cdCanvasGetVectorTextBounds(canvas, s, x, y, rect); + cdCanvasGetVectorTextBounds(canvas, str, x, y, rect); _xmin = rect[0]; _ymin = rect[1]; @@ -4942,66 +4935,52 @@ void cdCanvasGetVectorTextBox(cdCanvas* canvas, int x, int y, const char *s, int if (ymax) *ymax = _ymax; } -void cdCanvasVectorText(cdCanvas* canvas, int x, int y, const char* s) +void cdCanvasVectorText(cdCanvas* canvas, int x, int y, const char* str) { cdVectorFont* vector_font; - int num_lin, align, width = 0; + int num_lin; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - align = canvas->text_alignment; - num_lin = cdStrLineCount(s); + num_lin = cdStrLineCount(str); if (num_lin == 1) - { - if (align != CD_WEST && align != CD_NORTH_WEST && align != CD_SOUTH_WEST && align != CD_BASE_LEFT) - width = vf_textwidth(vector_font, s); /* only necessary for some alignments */ - - vf_draw_text(vector_font, x, y, s, width); - } + vf_draw_text(vector_font, x, y, str); else { - char *p, *q, *new_s; + const char *p_str, *q; double line_height = (vector_font->top - vector_font->bottom) * vector_font->size_y; int i; - if (align != CD_WEST && align != CD_NORTH_WEST && align != CD_SOUTH_WEST && align != CD_BASE_LEFT) - width = vf_gettextmaxwidth(vector_font, s, num_lin); /* only necessary for some alignments */ - /* position vertically at the first line */ - vf_move_to_first(vector_font, align, &x, &y, num_lin, line_height); + vf_move_to_first(vector_font, canvas->text_alignment, &x, &y, num_lin, line_height); - new_s = cdStrDup(s); - p = new_s; + p_str = str; for(i = 0; i < num_lin; i++) { - q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ - /* Draw the line */ - vf_draw_text(vector_font, x, y, p, width); + vf_draw_text(vector_font, x, y, p_str); /* Advance the string */ - if (q) p = q + 1; + q = strchr(p_str, '\n'); + if (q) p_str = q + 1; /* skip line break */ /* Advance a line */ vf_move_dir(vector_font, &x, &y, 0, -line_height); } - - free(new_s); } } -void cdCanvasMultiLineVectorText(cdCanvas* canvas, int x, int y, const char* s) +void cdCanvasMultiLineVectorText(cdCanvas* canvas, int x, int y, const char* str) { - cdCanvasVectorText(canvas, x, y, s); + cdCanvasVectorText(canvas, x, y, str); } /******************************************************/ @@ -5045,61 +5024,61 @@ double wdCanvasVectorCharSize(cdCanvas* canvas, double size) return old_size; } -void wdCanvasVectorTextSize(cdCanvas* canvas, double s_width, double s_height, const char* s) +void wdCanvasVectorTextSize(cdCanvas* canvas, double s_width, double s_height, const char* str) { int width, height; cdVectorFont* vector_font; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); vector_font->size_x = s_width/(double)width; vector_font->size_y = s_height/(double)height; } -void wdCanvasGetVectorTextSize(cdCanvas* canvas, const char *s, double *x, double *y) +void wdCanvasGetVectorTextSize(cdCanvas* canvas, const char *str, double *x, double *y) { int width, height; cdVectorFont* vector_font; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); if (x) *x = width*vector_font->size_x; if (y) *y = height*vector_font->size_y; } -void wdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, double x, double y, double *rect) +void wdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *str, double x, double y, double *rect) { cdVectorFont* vector_font; double sx, sy, line_height; int width, height, num_lin; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - vf_gettextsize(vector_font, s, &width, &height); + vf_gettextsize(vector_font, str, &width, &height); num_lin = height/(vector_font->top - vector_font->bottom); sx = width*vector_font->size_x; @@ -5115,7 +5094,7 @@ void wdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, double x, doub } /* move to bottom/left corner */ - vf_wmove_to_base(vector_font, &x, &y, width); + vf_wmove_to_base(vector_font, &x, &y, NULL, width); vf_wmove_dir(vector_font, &x, &y, 0, vector_font->bottom*vector_font->size_y); /* from base/left to bottom/left of the first line */ if (num_lin > 1) vf_wmove_dir(vector_font, &x, &y, 0, -(height*vector_font->size_y - line_height)); /* from bottom/left to the bottom of the last line */ @@ -5126,12 +5105,12 @@ void wdCanvasGetVectorTextBounds(cdCanvas* canvas, const char *s, double x, doub vf_wcalc_point(vector_font, x, y, &rect[6], &rect[7], 0, sy); } -void wdCanvasGetVectorTextBox(cdCanvas* canvas, double x, double y, const char *s, double *xmin, double *xmax, double *ymin, double *ymax) +void wdCanvasGetVectorTextBox(cdCanvas* canvas, double x, double y, const char *str, double *xmin, double *xmax, double *ymin, double *ymax) { double rect[8]; double _xmin, _xmax, _ymin, _ymax; - wdCanvasGetVectorTextBounds(canvas, s, x, y, rect); + wdCanvasGetVectorTextBounds(canvas, str, x, y, rect); _xmin = rect[0]; _ymin = rect[1]; @@ -5160,65 +5139,51 @@ void wdCanvasGetVectorTextBox(cdCanvas* canvas, double x, double y, const char * if (ymax) *ymax = _ymax; } -void wdCanvasVectorText(cdCanvas* canvas, double x, double y, const char* s) +void wdCanvasVectorText(cdCanvas* canvas, double x, double y, const char* str) { cdVectorFont* vector_font; - int num_lin, align, width = 0; + int num_lin; assert(canvas); - assert(s); + assert(str); if (!_cdCheckCanvas(canvas)) return; - if (s[0] == 0) + if (str[0] == 0) return; vector_font = canvas->vector_font; - align = canvas->text_alignment; - num_lin = cdStrLineCount(s); + num_lin = cdStrLineCount(str); if (num_lin == 1) - { - if (align != CD_WEST && align != CD_NORTH_WEST && align != CD_SOUTH_WEST && align != CD_BASE_LEFT) - width = vf_textwidth(vector_font, s); /* only necessary for some alignments */ - - vf_wdraw_text(vector_font, x, y, s, width); - } + vf_wdraw_text(vector_font, x, y, str); else { - char *p, *q, *new_s; + const char *p_str, *q; double line_height = (vector_font->top - vector_font->bottom) * vector_font->size_y; int i; - if (align != CD_WEST && align != CD_NORTH_WEST && align != CD_SOUTH_WEST && align != CD_BASE_LEFT) - width = vf_gettextmaxwidth(vector_font, s, num_lin); /* only necessary for some alignments */ - /* position vertically at the first line */ - vf_wmove_to_first(vector_font, align, &x, &y, num_lin, line_height); + vf_wmove_to_first(vector_font, canvas->text_alignment, &x, &y, num_lin, line_height); - new_s = cdStrDup(s); - p = new_s; + p_str = str; for(i = 0; i < num_lin; i++) { - q = strchr(p, '\n'); - if (q) *q = 0; /* Cut the string to contain only one line */ - /* Draw the line */ - vf_wdraw_text(vector_font, x, y, p, width); + vf_wdraw_text(vector_font, x, y, p_str); /* Advance the string */ - if (q) p = q + 1; + q = strchr(p_str, '\n'); + if (q) p_str = q + 1; /* skip line break */ /* Advance a line */ vf_wmove_dir(vector_font, &x, &y, 0, -line_height); } - - free(new_s); } } -void wdCanvasMultiLineVectorText(cdCanvas* canvas, double x, double y, const char* s) +void wdCanvasMultiLineVectorText(cdCanvas* canvas, double x, double y, const char* str) { - wdCanvasVectorText(canvas, x, y, s); + wdCanvasVectorText(canvas, x, y, str); } 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(ibitmap_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; ifile); @@ -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; icl += 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; icl += 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; icl += 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 * ); diff --git a/src/gdiplus/cdwinp.cpp b/src/gdiplus/cdwinp.cpp index d91ef6c..1cbed3c 100644 --- a/src/gdiplus/cdwinp.cpp +++ b/src/gdiplus/cdwinp.cpp @@ -792,10 +792,9 @@ static int cdwpCompensateHeight(int height) return (int)floor(height/10. + 0.5); /* 10% */ } -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) { RectF boundingBox; - int len = strlen(s); ctxcanvas->graphics->MeasureString(cdwpString2Unicode(s, len), len, ctxcanvas->font, PointF(0,0), @@ -830,7 +829,7 @@ static void sTextBox(cdCtxCanvas* ctxcanvas, WCHAR *ws, int len, int x, int y, i *ymin += ydir * (*h); } -static void cdwpCanvasGetTextHeight(cdCanvas* canvas, int x, int y, const char *s, int w, int h, int *hbox) +static void cdwpCanvasGetTextHeight(cdCanvas* canvas, int x, int y, int w, int h, int *hbox) { int xmin, xmax, ymin, ymax; @@ -866,13 +865,13 @@ static void cdwpCanvasGetTextHeight(cdCanvas* canvas, int x, int y, const char * *hbox = ymax-ymin+1; } -static void cdwpTextTransform(cdCtxCanvas* ctxcanvas, const char* s, int *x, int *y, int w, int h, Matrix &transformMatrix) +static void cdwpTextTransform(cdCtxCanvas* ctxcanvas, int *x, int *y, int w, int h, Matrix &transformMatrix) { int hbox; double* matrix = ctxcanvas->canvas->matrix; Matrix m1; - cdwpCanvasGetTextHeight(ctxcanvas->canvas, *x, *y, s, w, h, &hbox); + cdwpCanvasGetTextHeight(ctxcanvas->canvas, *x, *y, w, h, &hbox); // configure a bottom-up coordinate system m1.SetElements((REAL)1, (REAL)0, (REAL)0, (REAL)-1, (REAL)0, (REAL)(ctxcanvas->canvas->h-1)); @@ -894,10 +893,10 @@ static void cdwpTextTransform(cdCtxCanvas* ctxcanvas, const char* s, int *x, int *y = 0; } -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) { Matrix transformMatrix; - int len = strlen(s), use_transform = 0, w, h; + int use_transform = 0, w, h; WCHAR* ws = cdwpString2Unicode(s, len); if (ctxcanvas->canvas->text_orientation) @@ -913,7 +912,7 @@ static void cdtext(cdCtxCanvas* ctxcanvas, int x, int y, const char *s) if (ctxcanvas->canvas->use_matrix) { - cdwpTextTransform(ctxcanvas, s, &x, &y, w, h, transformMatrix); + cdwpTextTransform(ctxcanvas, &x, &y, w, h, transformMatrix); use_transform = 1; } else if (cdwpSetTransform(ctxcanvas, transformMatrix, NULL)) @@ -2160,6 +2159,7 @@ static cdAttribute hdc_attrib = static char* get_gdiplus_attrib(cdCtxCanvas* ctxcanvas) { + (void)ctxcanvas; return "1"; } @@ -2255,6 +2255,7 @@ static ULONG_PTR cd_gdiplusToken = NULL; static void __stdcall DebugEvent(DebugEventLevel level, char* msg) { + (void)level; MessageBox(NULL, msg, "GDI+ Debug", 0); } 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 @@ -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(ibitmap_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++; } } diff --git a/src/win32/cdwclp.c b/src/win32/cdwclp.c index e39cb7f..a62e9e8 100644 --- a/src/win32/cdwclp.c +++ b/src/win32/cdwclp.c @@ -41,7 +41,8 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void HANDLE hFile; DWORD dwSize, nBytesWrite; int err; - char* buffer; + unsigned char* buffer; + (void)data; if (IsClipboardFormatAvailable(CF_TEXT)) { @@ -58,8 +59,8 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void return CD_ERROR; } - buffer = (char*)GlobalLock(Handle); - dwSize = (DWORD)strlen(buffer); + buffer = (unsigned char*)GlobalLock(Handle); + dwSize = (DWORD)GlobalSize(Handle); hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, buffer, dwSize, &nBytesWrite, NULL); @@ -94,7 +95,7 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void dwSize = GetEnhMetaFileBits(Handle, 0, NULL); - buffer = (char*)malloc(dwSize); + buffer = (unsigned char*)malloc(dwSize); GetEnhMetaFileBits(Handle, dwSize, buffer); @@ -132,7 +133,7 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void lpMFP = (METAFILEPICT*) GlobalLock(Handle); dwSize = GetMetaFileBitsEx(lpMFP->hMF, 0, NULL); - buffer = (char*)malloc(dwSize); + buffer = (unsigned char*)malloc(dwSize); GetMetaFileBitsEx(lpMFP->hMF, dwSize, buffer); @@ -194,11 +195,11 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -210,10 +211,10 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -280,11 +281,11 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -296,10 +297,10 @@ static int cdplay(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); diff --git a/src/win32/cdwin.c b/src/win32/cdwin.c index ab8d63e..371bb6d 100644 --- a/src/win32/cdwin.c +++ b/src/win32/cdwin.c @@ -25,7 +25,7 @@ typedef BOOL (CALLBACK* AlphaBlendFunc)( HDC hdcDest, BLENDFUNCTION ftn); static AlphaBlendFunc cdwAlphaBlend = NULL; -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); /* %F Libera memoria e handles alocados pelo driver Windows. @@ -959,7 +959,7 @@ static void cdtransform(cdCtxCanvas *ctxcanvas, const double* matrix) } } -static void sTextOutBlt(cdCtxCanvas* ctxcanvas, int px, int py, const char* s, int n) +static void sTextOutBlt(cdCtxCanvas* ctxcanvas, int px, int py, const char* s, int len) { HDC hBitmapDC; HBITMAP hBitmap, hOldBitmap; @@ -969,7 +969,7 @@ static void sTextOutBlt(cdCtxCanvas* ctxcanvas, int px, int py, const char* s, i double cos_teta = cos(teta); double sin_teta = sin(teta); - cdgettextsize(ctxcanvas, s, &w, &h); + cdgettextsize(ctxcanvas, s, len, &w, &h); wt = w; ht = h; @@ -1133,7 +1133,7 @@ static void sTextOutBlt(cdCtxCanvas* ctxcanvas, int px, int py, const char* s, i SetTextAlign(hBitmapDC, TA_CENTER | TA_BASELINE); hOldFont = SelectObject(hBitmapDC, ctxcanvas->hFont); - TextOut(hBitmapDC, x, y, s, n); + TextOut(hBitmapDC, x, y, s, len); if (ctxcanvas->canvas->invert_yaxis) BitBlt(ctxcanvas->hDC, px, py, w, h, hBitmapDC, 0, 0, ctxcanvas->RopBlt); @@ -1147,11 +1147,11 @@ static void sTextOutBlt(cdCtxCanvas* ctxcanvas, int px, int py, const char* s, i DeleteDC(hBitmapDC); } -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) { SIZE size; - GetTextExtentPoint32(ctxcanvas->hDC, s, (int)strlen(s), &size); + GetTextExtentPoint32(ctxcanvas->hDC, s, len, &size); if (width) *width = size.cx; @@ -1160,12 +1160,12 @@ static void cdgettextsize (cdCtxCanvas* ctxcanvas, const char *s, int *width, in *height = size.cy; } -static void cdwCanvasGetTextHeight(cdCanvas* canvas, int x, int y, const char *s, int *hbox, int *hoff) +static void cdwCanvasGetTextHeight(cdCanvas* canvas, int x, int y, const char *s, int len, int *hbox, int *hoff) { int w, h, ascent, height, baseline; int xmin, xmax, ymin, ymax; - cdgettextsize(canvas->ctxcanvas, s, &w, &h); + cdgettextsize(canvas->ctxcanvas, s, len, &w, &h); cdCanvasGetFontDim(canvas, NULL, &height, &ascent, NULL); baseline = height - ascent; @@ -1202,12 +1202,12 @@ static void cdwCanvasGetTextHeight(cdCanvas* canvas, int x, int y, const char *s *hbox = ymax-ymin+1; } -static void cdwTextTransform(cdCtxCanvas* ctxcanvas, const char* s, int *x, int *y) +static void cdwTextTransform(cdCtxCanvas* ctxcanvas, const char* s, int len, int *x, int *y) { XFORM xForm; int hoff, h; - cdwCanvasGetTextHeight(ctxcanvas->canvas, *x, *y, s, &h, &hoff); + cdwCanvasGetTextHeight(ctxcanvas->canvas, *x, *y, s, len, &h, &hoff); /* move to (x,y) and remove a vertical offset since text reference point is top-left */ xForm.eM11 = (FLOAT)1; @@ -1231,10 +1231,8 @@ static void cdwTextTransform(cdCtxCanvas* ctxcanvas, const char* s, int *x, int *y = 0; } -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 n = (int)strlen(s); - if (ctxcanvas->canvas->write_mode == CD_REPLACE || ctxcanvas->wtype == CDW_EMF || ctxcanvas->wtype == CDW_WMF || @@ -1249,7 +1247,7 @@ static void cdtext(cdCtxCanvas* ctxcanvas, int x, int y, const char *s) { /* compensa deficiencia do alinhamento no windows */ int off; - cdgettextsize(ctxcanvas, s, NULL, &h); + cdgettextsize(ctxcanvas, s, len, NULL, &h); off = h/2 - ctxcanvas->font.descent; if (ctxcanvas->canvas->text_orientation != 0) @@ -1268,9 +1266,9 @@ static void cdtext(cdCtxCanvas* ctxcanvas, int x, int y, const char *s) BeginPath(ctxcanvas->hDC); if (ctxcanvas->canvas->use_matrix) - cdwTextTransform(ctxcanvas, s, &x, &y); + cdwTextTransform(ctxcanvas, s, len, &x, &y); - TextOut(ctxcanvas->hDC, x, y+1, s, n); /* compensa erro de desenho com +1 */ + TextOut(ctxcanvas->hDC, x, y+1, s, len); /* compensa erro de desenho com +1 */ if (ctxcanvas->canvas->use_matrix) cdtransform(ctxcanvas, ctxcanvas->canvas->matrix); @@ -1288,7 +1286,7 @@ static void cdtext(cdCtxCanvas* ctxcanvas, int x, int y, const char *s) SetBkMode(ctxcanvas->hDC, OPAQUE); } else - sTextOutBlt(ctxcanvas, x, y+1, s, n); + sTextOutBlt(ctxcanvas, x, y+1, s, len); } static int cdtextalignment(cdCtxCanvas* ctxcanvas, int text_align) diff --git a/src/win32/cdwin.h b/src/win32/cdwin.h index 1f4434f..a8230e7 100644 --- a/src/win32/cdwin.h +++ b/src/win32/cdwin.h @@ -125,8 +125,8 @@ void cdwKillCanvas(cdCtxCanvas* canvas); /* implemented in the wmfmeta.c module */ -void wmfMakePlaceableMetafile(HMETAFILE hmf, char* filename, int w, int h); -void wmfWritePlacebleFile(HANDLE hFile, char* buffer, DWORD dwSize, LONG mm, LONG xExt, LONG yExt); +void wmfMakePlaceableMetafile(HMETAFILE hmf, const char* filename, int w, int h); +void wmfWritePlacebleFile(HANDLE hFile, unsigned char* buffer, DWORD dwSize, LONG mm, LONG xExt, LONG yExt); /* implemented in the wmf_emf.c module */ int cdplayWMF(cdCanvas* canvas, int xmin, int xmax, int ymin, int ymax, void *data); diff --git a/src/win32/wmf_emf.c b/src/win32/wmf_emf.c index 36aeed0..d876874 100644 --- a/src/win32/wmf_emf.c +++ b/src/win32/wmf_emf.c @@ -1083,11 +1083,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1099,10 +1099,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -1137,11 +1137,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1153,10 +1153,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -1191,11 +1191,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1207,10 +1207,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -1239,11 +1239,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1255,10 +1255,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -1285,11 +1285,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1301,10 +1301,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -1549,11 +1549,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1623,11 +1623,11 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC if (dib.type == 0) { - char *r, *g, *b; + unsigned char *r, *g, *b; - r = (char*)malloc(size); - g = (char*)malloc(size); - b = (char*)malloc(size); + r = (unsigned char*)malloc(size); + g = (unsigned char*)malloc(size); + b = (unsigned char*)malloc(size); cdwDIBDecodeRGB(&dib, r, g, b); @@ -1640,10 +1640,10 @@ static int CALLBACK EMFEnumProc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETAREC } else { - char *index; + unsigned char *index; long *colors; - index = (char*)malloc(size); + index = (unsigned char*)malloc(size); colors = (long*)malloc(256*sizeof(long)); cdwDIBDecodeMap(&dib, index, colors); @@ -2058,7 +2058,7 @@ Aldus placeable metafile format /* %F Cria um APM em arquivo a partir de um WMF em memoria. */ -void wmfMakePlaceableMetafile(HMETAFILE hmf, char* filename, int w, int h) +void wmfMakePlaceableMetafile(HMETAFILE hmf, const char* filename, int w, int h) { int fh, nSize; LPSTR lpData; @@ -2090,7 +2090,7 @@ void wmfMakePlaceableMetafile(HMETAFILE hmf, char* filename, int w, int h) close(fh); } -void wmfWritePlacebleFile(HANDLE hFile, char* buffer, DWORD dwSize, LONG mm, LONG xExt, LONG yExt) +void wmfWritePlacebleFile(HANDLE hFile, unsigned char* buffer, DWORD dwSize, LONG mm, LONG xExt, LONG yExt) { DWORD nBytesWrite; APMFILEHEADER APMHeader; diff --git a/src/x11/cdx11.c b/src/x11/cdx11.c index 62e81ed..4f427e3 100644 --- a/src/x11/cdx11.c +++ b/src/x11/cdx11.c @@ -1224,9 +1224,9 @@ static int cd2xvertex [12] = {XR_TCENTRE, XR_BCENTRE, XR_MCENTRE, XR_LEFT, XR_CENTRE, XR_RIGHT}; -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 w, h, n, dir = -1; + int w, h, dir = -1; if (ctxcanvas->canvas->text_orientation != 0) { @@ -1239,13 +1239,13 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s) { sPrepareRegion(ctxcanvas); XRotDrawString(ctxcanvas->dpy, ctxcanvas->font, ctxcanvas->canvas->text_orientation, - ctxcanvas->region_aux, ctxcanvas->region_aux_gc, x, y, s, + ctxcanvas->region_aux, ctxcanvas->region_aux_gc, x, y, s, len, cd2xvertex[ctxcanvas->canvas->text_alignment], 0); sCombineRegion(ctxcanvas); } else XRotDrawString(ctxcanvas->dpy, ctxcanvas->font, ctxcanvas->canvas->text_orientation, - ctxcanvas->wnd, ctxcanvas->gc, x, y, s, + ctxcanvas->wnd, ctxcanvas->gc, x, y, s, len, cd2xvertex[ctxcanvas->canvas->text_alignment], 0); cdxCheckSolidStyle(ctxcanvas, 0); @@ -1253,8 +1253,7 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s) return; } - n = strlen(s); - w = XTextWidth(ctxcanvas->font, s, n); + w = XTextWidth(ctxcanvas->font, s, len); h = ctxcanvas->font->ascent + ctxcanvas->font->descent; switch (ctxcanvas->canvas->text_alignment) @@ -1315,19 +1314,19 @@ static void cdtext(cdCtxCanvas *ctxcanvas, int x, int y, const char *s) { sPrepareRegion(ctxcanvas); XSetFont(ctxcanvas->dpy, ctxcanvas->region_aux_gc, ctxcanvas->font->fid); - XDrawString(ctxcanvas->dpy, ctxcanvas->region_aux, ctxcanvas->region_aux_gc, x, y+1, s, n); + XDrawString(ctxcanvas->dpy, ctxcanvas->region_aux, ctxcanvas->region_aux_gc, x, y+1, s, len); sCombineRegion(ctxcanvas); } else - XDrawString(ctxcanvas->dpy, ctxcanvas->wnd, ctxcanvas->gc, x, y+1, s, n); + XDrawString(ctxcanvas->dpy, ctxcanvas->wnd, ctxcanvas->gc, x, y+1, s, len); cdxCheckSolidStyle(ctxcanvas, 0); } -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) return; - if (width) *width = XTextWidth(ctxcanvas->font, s, strlen(s)); + if (width) *width = XTextWidth(ctxcanvas->font, s, len); if (height) *height = ctxcanvas->font->ascent + ctxcanvas->font->descent; } diff --git a/src/x11/xvertex.c b/src/x11/xvertex.c index d58af13..e1ca7ee 100644 --- a/src/x11/xvertex.c +++ b/src/x11/xvertex.c @@ -122,7 +122,7 @@ static struct style_template { /* ---------------------------------------------------------------------- */ -static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, double angle, char *text, int align); +static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, double angle, const char *text, int len, int align); static void XRotAddToLinkedList(Display *dpy, RotatedTextItem *item); static XImage *XRotMagnifyImage(Display *dpy, XImage *ximage); static void XRotFreeTextItem(Display *dpy, RotatedTextItem *item); @@ -133,18 +133,19 @@ static void XRotFreeTextItem(Display *dpy, RotatedTextItem *item); /* Routine to mimic `my_strdup()' (some machines don't have it) */ /**************************************************************************/ -static char *my_strdup(const char *str) +static char *my_strdup(const char *str, int len) { char *s; - int len; if(str==NULL) return NULL; - len = (int)strlen(str); s=(char *)malloc((unsigned)(len+1)); - if(s!=NULL) - memcpy(s, str, len+1); + if(s!=NULL) + { + memcpy(s, str, len); + s[len]=0; + } return s; } @@ -157,7 +158,7 @@ static char *my_strdup(const char *str) static char *my_strtok(char *str1, const char *str2) { char *ret; - int i, j, stop; + int i, j, stop, len2; static int start, len; static char *stext; @@ -176,12 +177,14 @@ static char *my_strtok(char *str1, const char *str2) if(start>=len) return NULL; + len2 = strlen(str2); + /* loop through characters */ for(i=start; itext=my_strdup(text); + item->text=my_strdup(text, len); /* fontname or ID */ if(font_name!=NULL) { - item->font_name=my_strdup(font_name); + item->font_name=my_strdup(font_name, strlen(font_name)); item->fid=0; } else @@ -477,7 +480,7 @@ static RotatedTextItem *XRotRetrieveFromCache(Display *dpy, XFontStruct *font, d /* Create a rotated text item */ /**************************************************************************/ -static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, double angle, char *text, int align) +static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, double angle, const char *text, int len, int align) { RotatedTextItem *item=NULL; Pixmap canvas; @@ -507,7 +510,7 @@ static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, doub /* count number of sections in string */ item->nl=1; if(align!=XR_LEFT) - for(i=0; inl++; @@ -518,7 +521,7 @@ static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, doub str2=str2_b; /* find width of longest section */ - str1=my_strdup(text); + str1=my_strdup(text, len); if(str1==NULL) return NULL; @@ -535,8 +538,7 @@ static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, doub if(str3!=NULL) { - XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc, - &overall); + XTextExtents(font, str3, strlen(str3), &dir, &asc, &desc, &overall); if(overall.rbearing>item->max_width) item->max_width=overall.rbearing; @@ -590,7 +592,7 @@ static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, doub /* start at top of bitmap */ yp=font->ascent; - str1=my_strdup(text); + str1=my_strdup(text, len); if(str1==NULL) return NULL; @@ -641,8 +643,7 @@ static RotatedTextItem *XRotCreateTextItem(Display *dpy, XFontStruct *font, doub return NULL; /* extract horizontal text */ - XGetSubImage(dpy, canvas, 0, 0, item->cols_in, item->rows_in, - 1, XYPixmap, I_in, 0, 0); + XGetSubImage(dpy, canvas, 0, 0, item->cols_in, item->rows_in, 1, XYPixmap, I_in, 0, 0); I_in->format=XYBitmap; /* magnify horizontal text */ @@ -1073,7 +1074,7 @@ void XRotSetBoundingBoxPad(int p) /* Calculate the bounding box some text will have when painted */ /**************************************************************************/ -XPoint *XRotTextExtents(Display* dpy, XFontStruct* font, double angle, int x, int y, const char* text, int align) +XPoint *XRotTextExtents(Display* dpy, XFontStruct* font, double angle, int x, int y, const char* text, int len, int align) { register int i; char *str1, *str2, *str3; @@ -1099,7 +1100,7 @@ XPoint *XRotTextExtents(Display* dpy, XFontStruct* font, double angle, int x, in /* count number of sections in string */ nl=1; if(align!=XR_LEFT) - for(i=0; ictxplus->font->descent; } -static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *text, int *width, int *height) +static void cdgettextsize(cdCtxCanvas *ctxcanvas, const char *text, int len, int *width, int *height) { XGlyphInfo extents; if (!ctxcanvas->ctxplus->font) return; if (ctxcanvas->canvas->text_orientation) - XftTextExtents8(ctxcanvas->dpy, ctxcanvas->ctxplus->flat_font, (XftChar8*)text, strlen(text), &extents); + XftTextExtents8(ctxcanvas->dpy, ctxcanvas->ctxplus->flat_font, (XftChar8*)text, len, &extents); else - XftTextExtents8(ctxcanvas->dpy, ctxcanvas->ctxplus->font, (XftChar8*)text, strlen(text), &extents); + XftTextExtents8(ctxcanvas->dpy, ctxcanvas->ctxplus->font, (XftChar8*)text, len, &extents); if (width) *width = extents.width+extents.x; if (height) *height = extents.height+extents.y; } -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) { XGlyphInfo extents; - int ox, oy, w, h, len, descent, dir = -1; + int ox, oy, w, h, descent, dir = -1; if (!ctxcanvas->ctxplus->font) return; - len = strlen(text); - if (ctxcanvas->canvas->text_orientation) XftTextExtents8(ctxcanvas->dpy, ctxcanvas->ctxplus->flat_font, (XftChar8*)text, len, &extents); else diff --git a/test/simple/simple.c b/test/simple/simple.c index c9ba361..c75398b 100644 --- a/test/simple/simple.c +++ b/test/simple/simple.c @@ -978,10 +978,12 @@ int SimpleDrawTextAlign(void) use_vector = 0; - //if (use_vector) - // cdVectorTextDirection(0, 0, 1, 1); - //else - // cdTextOrientation(45); +#if 0 + if (use_vector) + cdVectorTextDirection(0, 0, 1, 1); + else + cdTextOrientation(45); +#endif xoff = w/4; yoff = h/7; @@ -991,7 +993,7 @@ int SimpleDrawTextAlign(void) else { //cdFont(CD_TIMES_ROMAN, CD_PLAIN, 14); - cdFont(CD_HELVETICA, CD_PLAIN, 18); + cdFont(CD_HELVETICA, CD_PLAIN, 24); } for (i = 0; i < 12; i++) -- cgit v1.2.3