DPRINTF may not be the ideal define ... use something more RRDish ... like RRDPRINTF
[rrdtool.git] / src / rrd_gfx.c
index f4c04ef..9c204f3 100644 (file)
@@ -1,16 +1,21 @@
 /****************************************************************************
- * RRDtool 1.2.9  Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.19  Copyright by Tobi Oetiker, 1997-2007
  ****************************************************************************
  * rrd_gfx.c  graphics wrapper for rrdtool
   **************************************************************************/
 
 /* #define DEBUG */
 
-#ifdef DEBUG
-# define DPRINTF(...)  fprintf(stderr, __VA_ARGS__);
-#else
-# define DPRINTF(...)
-#endif
+/* stupid MSVC doesnt support variadic macros = no debug for now! */
+#ifdef _MSC_VER
+# define RRDPRINTF()
+#else 
+# ifdef DEBUG
+#  define RRDPRINTF(...)  fprintf(stderr, __VA_ARGS__);
+# else
+#  define RRDPRINTF(...)
+# endif /* DEBUG */
+#endif /* _MSC_VER */
 #include "rrd_tool.h"
 #include <png.h>
 #include <ft2build.h>
@@ -303,10 +308,15 @@ double gfx_get_text_width_libart (
 
   FT_Init_FreeType( &library );
   error = FT_New_Face( library, font, 0, &face );
-  if ( error ) return -1;
+  if ( error ) {
+    FT_Done_FreeType(library);
+    return -1;
+  }
   error = FT_Set_Char_Size(face,  size*64,size*64,  100,100);
-  if ( error ) return -1;
-
+  if ( error ) {
+    FT_Done_FreeType(library);
+    return -1;
+  }
   string = gfx_string_create( canvas, face, text, rotation, tabwidth, size );
   text_width = string->width;
   gfx_string_destroy(string);
@@ -456,12 +466,12 @@ gfx_string gfx_string_create(gfx_canvas_t *canvas, FT_Face face,const char *text
                             canvas->aa_type == AA_LIGHT ? FT_LOAD_TARGET_LIGHT :
                             FT_LOAD_TARGET_MONO : FT_LOAD_TARGET_MONO);
     if (error) {
-      DPRINTF("couldn't load glyph:  %c\n", letter)
+      RRDPRINTF("couldn't load glyph:  %c\n", letter)
       continue;
     }
     error = FT_Get_Glyph (slot, &glyph->image);
     if (error) {
-      DPRINTF("couldn't get glyph %c from slot %d\n", letter, (int)slot)
+      RRDPRINTF("couldn't get glyph %c from slot %d\n", letter, (int)slot)
       continue;
     }
     /* if we are in tabbing mode, we replace the tab with a space and shift the position
@@ -483,7 +493,7 @@ gfx_string gfx_string_create(gfx_canvas_t *canvas, FT_Face face,const char *text
     FT_Vector_Transform (&vec, &string->transform);
     error = FT_Glyph_Transform (glyph->image, &string->transform, &vec);
     if (error) {
-      DPRINTF("couldn't transform glyph id %d\n", letter)
+      RRDPRINTF("couldn't transform glyph id %d\n", letter)
       continue;
     }
 
@@ -493,7 +503,7 @@ gfx_string gfx_string_create(gfx_canvas_t *canvas, FT_Face face,const char *text
                             canvas->aa_type == AA_LIGHT ? FT_RENDER_MODE_LIGHT :
                             FT_RENDER_MODE_MONO : FT_RENDER_MODE_MONO, 0, 1);
     if (error) {
-      DPRINTF("couldn't convert glyph id %d to bitmap\n", letter)
+      RRDPRINTF("couldn't convert glyph id %d to bitmap\n", letter)
       continue;
     }
 
@@ -602,6 +612,7 @@ int           gfx_render_png (gfx_canvas_t *canvas,
                                  &face );
            if ( error ) {
                rrd_set_error("failed to load %s",node->filename);
+               
                break;
            }
             error = FT_Set_Char_Size(face,   /* handle to face object            */
@@ -647,12 +658,12 @@ int           gfx_render_png (gfx_canvas_t *canvas,
                /* long buf_x,comp_n; */
                /* make copy to transform */
                 if (! glyph->image) {
-                  DPRINTF("no image\n")
+                  RRDPRINTF("no image\n")
                   continue;
                 }
                 error = FT_Glyph_Copy (glyph->image, &image);
                 if (error) {
-                  DPRINTF("couldn't copy image\n")
+                  RRDPRINTF("couldn't copy image\n")
                   continue;
                 }
 
@@ -1056,7 +1067,9 @@ static void svg_write_text(FILE *fp, const char *text)
        text_count = mbstowcs(cstr, "Enc-Err", 6);
     p = cstr;
 #else
-    const unsigned char *p = text, ch;
+    unsigned char *p = text;
+    unsigned char *cstr;
+    char ch;
     if (!p)
        return;
 #endif
@@ -1065,7 +1078,7 @@ static void svg_write_text(FILE *fp, const char *text)
     ch = afm_fix_osx_charset(ch); /* unsafe macro */
     switch (ch) {
     case 0:
-#ifdef HAVE_MBSTOWCS     
+#ifdef HAVE_MBSTOWCS
     free(cstr);
 #endif
     return;
@@ -1075,9 +1088,11 @@ static void svg_write_text(FILE *fp, const char *text)
     case '"': fputs("&quot;", fp); break;
     default:
         if (ch == 32) {
+#ifdef HAVE_MBSTOWCS
             if (p <= cstr + 1 || !*p || *p == 32)
                 fputs("&#160;", fp); /* non-breaking space in unicode */
             else
+#endif
                 fputc(32, fp);
         } else if (ch < 32 || ch >= 127)
        fprintf(fp, "&#%d;", (int)ch);
@@ -1434,9 +1449,9 @@ int       gfx_render_svg (gfx_canvas_t *canvas,
 "-->\n", fp);
    svg_start_tag(fp, "svg");
    fputs(" width=\"", fp);
-  svg_write_number(fp, width * canvas->zoom);
+   svg_write_number(fp, width * canvas->zoom);
    fputs("\" height=\"", fp);
-  svg_write_number(fp, height * canvas->zoom);
+   svg_write_number(fp, height * canvas->zoom);
    fputs("\" x=\"0\" y=\"0\" viewBox=\"", fp);
    svg_write_number(fp, -LINEOFFSET);
    fputs(" ", fp);
@@ -1446,8 +1461,10 @@ int       gfx_render_svg (gfx_canvas_t *canvas,
    fputs(" ", fp);
    svg_write_number(fp, height - LINEOFFSET);
    fputs("\" preserveAspectRatio=\"xMidYMid\"", fp);
-  fprintf(fp, " font-family=\"%s\"", svg_default_font); /* default font */
-  fputs(" stroke-linecap=\"round\" stroke-linejoin=\"round\"", fp);
+   fprintf(fp, " font-family=\"%s\"", svg_default_font); /* default font */
+   fputs(" stroke-linecap=\"round\" stroke-linejoin=\"round\"", fp);
+   fputs(" xmlns=\"http://www.w3.org/2000/svg\"", fp);
+   fputs(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"", fp);
    svg_close_tag(fp);
    svg_start_tag(fp, "rect");
    fprintf(fp, " x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", width, height);
@@ -1737,7 +1754,8 @@ static void eps_write_text(eps_state *state, gfx_node_t *node)
        text_count = mbstowcs(cstr, "Enc-Err", 6);
     p = cstr;
 #else
-    const unsigned char *p = node->text, ch;
+    const unsigned char *p = node->text;
+    unsigned char ch;
     if (!p)
        return;
 #endif
@@ -2024,9 +2042,9 @@ static void pdf_put_string_contents_wide(pdf_buffer *buf, const afm_char *text)
            default:
                if (ch > 255) {
                    pdf_put_char(buf, '?');
-               } else if (ch >= 126 || ch < 32) {
+               } else if (ch > 125 || ch < 32) {
                    pdf_put_char(buf, ch);
-               } else if (ch >= 0 && ch <= 255) {
+               } else {
                    char tmp[10];
                    snprintf(tmp, sizeof(tmp), "\\%03o", (int)ch);
                    pdf_puts(buf, tmp);