[INTERPRETER]

* NEW: A new interpreter API to get temporary file names.
* NEW: A new interpreter API to copy a file.
* NEW: Rename the GB.GetTempDir() function to GB.TempDir(), and fix all 
  components using it.

[GB.GTK]
* NEW: SvgImage is a new class that allows to generate SVG files by 
  painting on it. But it cannot render them.


git-svn-id: svn://localhost/gambas/trunk@2583 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2010-01-01 18:45:35 +00:00
parent d81bda1c5b
commit 05fe8d8446
15 changed files with 688 additions and 479 deletions

View File

@ -1,5 +1,5 @@
# Gambas Project File 3.0 # Gambas Project File 3.0
# Compiled with Gambas 2.99.0 # Compiled with Gambas 2.99.0 (r2578)
Title=Gambas 3 Title=Gambas 3
Startup=Project Startup=Project
StackTrace=1 StackTrace=1

View File

@ -395,7 +395,7 @@ static char *FindDatabase (const char *name, const char *hostName)
} }
#endif #endif
GB.NewString(&fullpath, GB.GetTempDir(), 0); GB.NewString(&fullpath, GB.TempDir(), 0);
GB.AddString(&fullpath, "/sqlite/", 0); GB.AddString(&fullpath, "/sqlite/", 0);
GB.AddString(&fullpath, name, 0); GB.AddString(&fullpath, name, 0);
@ -431,7 +431,7 @@ static char *GetDatabaseHome()
} }
*/ */
sprintf(dbhome, "%s/sqlite", GB.GetTempDir()); sprintf(dbhome, "%s/sqlite", GB.TempDir());
} }
else { else {
strcpy(dbhome, env); strcpy(dbhome, env);

View File

@ -469,7 +469,7 @@ static char *FindDatabase(const char *name, const char *hostName)
} }
#endif #endif
GB.NewString(&fullpath, GB.GetTempDir(), 0); GB.NewString(&fullpath, GB.TempDir(), 0);
GB.AddString(&fullpath, "/sqlite/", 0); GB.AddString(&fullpath, "/sqlite/", 0);
GB.AddString(&fullpath, name, 0); GB.AddString(&fullpath, name, 0);
@ -507,7 +507,7 @@ static char *GetDatabaseHome()
} }
*/ */
sprintf(dbhome, "%s/sqlite", GB.GetTempDir()); sprintf(dbhome, "%s/sqlite", GB.TempDir());
} }
else else
{ {

View File

@ -57,6 +57,7 @@ gb_gtk_la_SOURCES = \
CScrollView.h CScrollView.cpp \ CScrollView.h CScrollView.cpp \
CMenu.h CMenu.cpp CTrayIcon.h CTrayIcon.cpp CWindow.h CWindow.cpp \ CMenu.h CMenu.cpp CTrayIcon.h CTrayIcon.cpp CWindow.h CWindow.cpp \
cprinter.h cprinter.cpp \ cprinter.h cprinter.cpp \
csvgimage.h csvgimage.cpp \
main.h main.cpp \ main.h main.cpp \
gkey.h \ gkey.h \
gcursor.h \ gcursor.h \

View File

@ -35,6 +35,7 @@
#include "CPicture.h" #include "CPicture.h"
#include "CImage.h" #include "CImage.h"
#include "cprinter.h" #include "cprinter.h"
#include "csvgimage.h"
#include "CFont.h" #include "CFont.h"
#include "CDraw.h" #include "CDraw.h"
#include "cpaint_impl.h" #include "cpaint_impl.h"
@ -190,6 +191,14 @@ static int Begin(GB_PAINT *d)
rx = (int)gtk_print_context_get_dpi_x(context); rx = (int)gtk_print_context_get_dpi_x(context);
ry = (int)gtk_print_context_get_dpi_y(context); ry = (int)gtk_print_context_get_dpi_y(context);
} }
else if (GB.Is(device, CLASS_SvgImage))
{
CSVGIMAGE *svgimage = ((CSVGIMAGE *)device);
target = svgimage->surface;
cairo_surface_reference(target);
w = svgimage->width;
h = svgimage->height;
}
else else
return TRUE; return TRUE;
@ -210,6 +219,11 @@ static void End(GB_PAINT *d)
if (wid->cached()) if (wid->cached())
wid->setCache(); wid->setCache();
} }
else if (GB.Is(device, CLASS_SvgImage))
{
CSVGIMAGE *svgimage = ((CSVGIMAGE *)device);
cairo_surface_finish(svgimage->surface);
}
} }
static void Save(GB_PAINT *d) static void Save(GB_PAINT *d)

108
gb.gtk/src/csvgimage.cpp Normal file
View File

@ -0,0 +1,108 @@
/***************************************************************************
csvgimage.cpp
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#define __CSVGIMAGE_CPP
#include <cairo.h>
#include <cairo-svg.h>
#include "main.h"
#include "gambas.h"
#include "widgets.h"
#include "cpaint_impl.h"
#include "csvgimage.h"
#define MM_TO_PT(_mm) ((int)((_mm) * 72 / 25.4 + 0.5))
#define PT_TO_MM(_pt) ((_pt) / 72 * 25.4)
static void init(CSVGIMAGE *_object)
{
GB.NewString(&THIS->file, GB.TempFile(NULL), 0);
THIS->surface = cairo_svg_surface_create(THIS->file, THIS->width, THIS->height);
}
static void release(CSVGIMAGE *_object)
{
cairo_surface_destroy(THIS->surface);
unlink(THIS->file);
GB.FreeString(&THIS->file);
}
BEGIN_METHOD(SvgImage_new, GB_FLOAT width; GB_FLOAT height)
THIS->width = MM_TO_PT(VARG(width));
THIS->height = MM_TO_PT(VARG(height));
init(THIS);
END_METHOD
BEGIN_METHOD_VOID(SvgImage_free)
release(THIS);
END_METHOD
BEGIN_PROPERTY(SvgImage_Width)
GB.ReturnInteger(PT_TO_MM(THIS->width));
END_PROPERTY
BEGIN_PROPERTY(SvgImage_Height)
GB.ReturnInteger(PT_TO_MM(THIS->height));
END_PROPERTY
BEGIN_METHOD(SvgImage_Save, GB_STRING file)
GB.CopyFile(THIS->file, GB.FileName(STRING(file), LENGTH(file)));
END_METHOD
BEGIN_METHOD_VOID(SvgImage_Clear)
release(THIS);
init(THIS);
END_METHOD
GB_DESC SvgImageDesc[] =
{
GB_DECLARE("SvgImage", sizeof(CSVGIMAGE)),
GB_METHOD("_new", 0, SvgImage_new, "(Width)f(Height)f"),
GB_METHOD("_free", 0, SvgImage_free, 0),
GB_PROPERTY_READ("Width", "f", SvgImage_Width),
GB_PROPERTY_READ("Height", "f", SvgImage_Height),
//GB_STATIC_METHOD("Load", "Picture", CPICTURE_load, "(Path)s"),
GB_METHOD("Save", 0, SvgImage_Save, "(Path)s"),
GB_METHOD("Clear", 0, SvgImage_Clear, 0),
GB_INTERFACE("Paint", &PAINT_Interface),
GB_END_DECLARE
};

52
gb.gtk/src/csvgimage.h Normal file
View File

@ -0,0 +1,52 @@
/***************************************************************************
csvgimage.h
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#ifndef __CSVGIMAGE_H
#define __CSVGIMAGE_H
#include "gambas.h"
#include "widgets.h"
#include <cairo.h>
typedef
struct
{
GB_BASE ob;
cairo_surface_t *surface;
char *file;
int width;
int height;
}
CSVGIMAGE;
#ifndef __CSVGIMAGE_CPP
extern GB_DESC SvgImageDesc[];
#else
#define THIS OBJECT(CSVGIMAGE)
#define SURFACE (THIS->surface)
#endif
#endif

View File

@ -69,6 +69,7 @@
#include "CGridView.h" #include "CGridView.h"
#include "CSeparator.h" #include "CSeparator.h"
#include "cprinter.h" #include "cprinter.h"
#include "csvgimage.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <string.h> #include <string.h>
@ -79,6 +80,7 @@ GB_CLASS CLASS_DrawingArea;
GB_CLASS CLASS_Menu; GB_CLASS CLASS_Menu;
GB_CLASS CLASS_Window; GB_CLASS CLASS_Window;
GB_CLASS CLASS_Printer; GB_CLASS CLASS_Printer;
GB_CLASS CLASS_SvgImage;
static void my_lang(char *lang,int rtl1); static void my_lang(char *lang,int rtl1);
static void my_error(int code,char *error,char *where); static void my_error(int code,char *error,char *where);
@ -196,6 +198,7 @@ extern "C"
CGridViewDesc, CGridViewDesc,
CStockDesc, CStockDesc,
PrinterDesc, PrinterDesc,
SvgImageDesc,
NULL NULL
}; };
@ -253,8 +256,8 @@ extern "C"
//CLASS_Drawing = GB.FindClass("Drawing"); //CLASS_Drawing = GB.FindClass("Drawing");
CLASS_DrawingArea = GB.FindClass("DrawingArea"); CLASS_DrawingArea = GB.FindClass("DrawingArea");
CLASS_Printer = GB.FindClass("Printer"); CLASS_Printer = GB.FindClass("Printer");
//CLASS_ScrollView = GB.FindClass("ScrollView");
CLASS_Image = GB.FindClass("Image"); CLASS_Image = GB.FindClass("Image");
CLASS_SvgImage = GB.FindClass("SvgImage");
return TRUE; return TRUE;
} }

View File

@ -38,6 +38,7 @@ extern GB_CLASS CLASS_DrawingArea;
extern GB_CLASS CLASS_Menu; extern GB_CLASS CLASS_Menu;
extern GB_CLASS CLASS_Window; extern GB_CLASS CLASS_Window;
extern GB_CLASS CLASS_Printer; extern GB_CLASS CLASS_Printer;
extern GB_CLASS CLASS_SvgImage;
#endif #endif

View File

@ -165,7 +165,9 @@ void *GAMBAS_Api[] =
(void *)GB_LoadFile, (void *)GB_LoadFile,
(void *)STREAM_unmap, (void *)STREAM_unmap,
(void *)FILE_exist, (void *)FILE_exist,
(void *)GB_GetTempDir, (void *)GB_TempDir,
(void *)GB_TempFile,
(void *)GB_CopyFile,
(void *)GB_Store, (void *)GB_Store,
(void *)GB_StoreString, (void *)GB_StoreString,
@ -1639,11 +1641,35 @@ int GB_toupper(int c)
return toupper(c); return toupper(c);
} }
char *GB_GetTempDir(void) char *GB_TempDir(void)
{ {
return FILE_make_temp(NULL, NULL); return FILE_make_temp(NULL, NULL);
} }
char *GB_TempFile(const char *pattern)
{
int len;
return FILE_make_temp(&len, pattern);
}
int GB_CopyFile(const char *src, const char *dst)
{
int ret = 0;
TRY
{
FILE_copy(src, dst);
}
CATCH
{
ret = 1;
GAMBAS_Error = TRUE;
}
END_TRY
return ret;
}
char *GB_RealFileName(const char *name, int len) char *GB_RealFileName(const char *name, int len)
{ {
char *path = STRING_conv_file_name(name, len); char *path = STRING_conv_file_name(name, len);

View File

@ -85,8 +85,10 @@ char *GB_ToZeroString(GB_STRING *src);
int GB_LoadFile(const char *path, int lenp, char **addr, int *len); int GB_LoadFile(const char *path, int lenp, char **addr, int *len);
//void GB_ReleaseFile(char **addr, int len); //void GB_ReleaseFile(char **addr, int len);
#define GB_ReleaseFile STREAM_unmap #define GB_ReleaseFile STREAM_unmap
char *GB_GetTempDir(void);
char *GB_RealFileName(const char *path, int len); char *GB_RealFileName(const char *path, int len);
char *GB_TempDir(void);
char *GB_TempFile(const char *pattern);
int GB_CopyFile(const char *src, const char *dst);
int GB_IsMissing(int param); int GB_IsMissing(int param);

View File

@ -129,7 +129,7 @@ static char *FindDatabase(char *name, char *hostName)
} }
} }
GB.NewString(&fullpath, GB.GetTempDir(), 0); GB.NewString(&fullpath, GB.TempDir(), 0);
GB.AddString(&fullpath, "/sqlite/", 0); GB.AddString(&fullpath, "/sqlite/", 0);
GB.AddString(&fullpath, name, 0); GB.AddString(&fullpath, name, 0);

View File

@ -825,7 +825,9 @@ typedef
int (*LoadFile)(const char *, int, char **, int *); int (*LoadFile)(const char *, int, char **, int *);
void (*ReleaseFile)(char *, int); void (*ReleaseFile)(char *, int);
int (*ExistFile)(char *); int (*ExistFile)(char *);
char *(*GetTempDir)(void); char *(*TempDir)(void);
char *(*TempFile)(const char *);
int (*CopyFile)(const char *, const char *);
void (*Store)(GB_TYPE, GB_VALUE *, void *); void (*Store)(GB_TYPE, GB_VALUE *, void *);
void (*StoreString)(GB_STRING *, char **); void (*StoreString)(GB_STRING *, char **);

View File

@ -116,7 +116,7 @@ void FILE_copy(const char *src, const char *dst);
bool FILE_access(const char *path, int mode); bool FILE_access(const char *path, int mode);
void FILE_link(const char *src, const char *dst); void FILE_link(const char *src, const char *dst);
char *FILE_make_temp(int *len, char *pattern); char *FILE_make_temp(int *len, const char *pattern);
void FILE_recursive_dir(const char *dir, void (*found)(const char *), void (*afterfound)(const char *), int attr); void FILE_recursive_dir(const char *dir, void (*found)(const char *), void (*afterfound)(const char *), int attr);

File diff suppressed because it is too large Load Diff