Skip to content
Snippets Groups Projects
Commit dea907f8 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

sanitize TeX strings in an "intelligent" way
parent dcb316dd
No related branches found
No related tags found
No related merge requests found
// $Id: Opengl.cpp,v 1.47 2004-12-29 17:48:47 geuzaine Exp $ // $Id: Opengl.cpp,v 1.48 2004-12-31 22:02:26 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -66,6 +66,28 @@ void Draw(void) ...@@ -66,6 +66,28 @@ void Draw(void)
WID->redraw_opengl(); WID->redraw_opengl();
} }
void SanitizeTexString(char *in, char *out)
{
// if there is a '$' or a '\' in the string, assume the author knows
// what he's doing:
if(strstr(in, "$") || strstr(in, "\\")){
strcpy(out, in);
return;
}
// otherwise, escape the following special characters:
char bad[8] = { '%', '^', '#', '%', '&', '_', '{', '}' };
while(*in){
for(unsigned int i = 0; i < sizeof(bad); i++){
if(*in == bad[i]){
*out++ = '\\';
break;
}
}
*out++ = *in++;
}
*out = '\0';
}
void Draw_String(char *s, char *font_name, int font_enum, int font_size, int align) void Draw_String(char *s, char *font_name, int font_enum, int font_size, int align)
{ {
if(align > 0){ if(align > 0){
...@@ -94,11 +116,14 @@ void Draw_String(char *s, char *font_name, int font_enum, int font_size, int ali ...@@ -94,11 +116,14 @@ void Draw_String(char *s, char *font_name, int font_enum, int font_size, int ali
if(CTX.print.format == FORMAT_JPEGTEX || if(CTX.print.format == FORMAT_JPEGTEX ||
CTX.print.format == FORMAT_PNGTEX) CTX.print.format == FORMAT_PNGTEX)
return; return;
if(CTX.print.format == FORMAT_TEX) if(CTX.print.format == FORMAT_TEX){
gl2psTextOpt(s, font_name, font_size, char tmp[1024];
SanitizeTexString(s, tmp);
gl2psTextOpt(tmp, font_name, font_size,
(align == 0) ? GL2PS_TEXT_BL : (align == 0) ? GL2PS_TEXT_BL :
(align == 1) ? GL2PS_TEXT_B : (align == 1) ? GL2PS_TEXT_B :
GL2PS_TEXT_BR, 0.); GL2PS_TEXT_BR, 0.);
}
else else
gl2psText(s, font_name, font_size); gl2psText(s, font_name, font_size);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment