53 #include <glib/gstdio.h>
64 #define DPRINTF(...) do { if (DEBUG) printf(__VA_ARGS__); } while (0)
66 #define NUMBER_OF_DEFAULT_COLORS 18
67 #define NUMBER_OF_DEFAULT_TRANSFORMATIONS 20
70 gerbv_print_help(
void);
73 getopt_configured(
int argc,
char *
const argv[],
const char *optstring,
74 const struct option *longopts,
int *longindex);
76 getopt_lengh_unit(
const char *optarg,
double *input_div,
77 gerbv_screen_t *screen);
80 compare_strings(gconstpointer a, gconstpointer b)
82 return g_ascii_strcasecmp((
const char *)a, (
const char *)b);
86 scan_directory(
const char *dirpath)
88 GDir *dir = g_dir_open(dirpath, 0, NULL);
94 while ((entry = g_dir_read_name(dir)) != NULL) {
95 gchar *fullpath = g_build_filename(dirpath, entry, NULL);
96 if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR)
98 files = g_list_prepend(files, fullpath);
105 return g_list_sort(files, compare_strings);
130 {0,0,1,1,0,FALSE,FALSE,FALSE},
131 {0,0,1,1,0,FALSE,FALSE,FALSE},
132 {0,0,1,1,0,FALSE,FALSE,FALSE},
133 {0,0,1,1,0,FALSE,FALSE,FALSE},
134 {0,0,1,1,0,FALSE,FALSE,FALSE},
135 {0,0,1,1,0,FALSE,FALSE,FALSE},
136 {0,0,1,1,0,FALSE,FALSE,FALSE},
137 {0,0,1,1,0,FALSE,FALSE,FALSE},
138 {0,0,1,1,0,FALSE,FALSE,FALSE},
139 {0,0,1,1,0,FALSE,FALSE,FALSE},
140 {0,0,1,1,0,FALSE,FALSE,FALSE},
141 {0,0,1,1,0,FALSE,FALSE,FALSE},
142 {0,0,1,1,0,FALSE,FALSE,FALSE},
143 {0,0,1,1,0,FALSE,FALSE,FALSE},
144 {0,0,1,1,0,FALSE,FALSE,FALSE},
145 {0,0,1,1,0,FALSE,FALSE,FALSE},
146 {0,0,1,1,0,FALSE,FALSE,FALSE},
147 {0,0,1,1,0,FALSE,FALSE,FALSE},
148 {0,0,1,1,0,FALSE,FALSE,FALSE},
149 {0,0,1,1,0,FALSE,FALSE,FALSE},
152 #ifdef HAVE_GETOPT_LONG
155 const struct option longopts[] = {
157 {
"border", required_argument, NULL,
'B'},
158 {
"dpi", required_argument, NULL,
'D'},
159 {
"version", no_argument, NULL,
'V'},
160 {
"origin", required_argument, NULL,
'O'},
161 {
"window_inch", required_argument, NULL,
'W'},
162 {
"antialias", no_argument, NULL,
'a'},
163 {
"background", required_argument, NULL,
'b'},
164 {
"dump", no_argument, NULL,
'd'},
165 {
"foreground", required_argument, NULL,
'f'},
166 {
"rotate", required_argument, NULL,
'r'},
167 {
"mirror", required_argument, NULL,
'm'},
168 {
"help", no_argument, NULL,
'h'},
169 {
"quiet", no_argument, NULL,
'q'},
170 {
"log", required_argument, NULL,
'l'},
171 {
"output", required_argument, NULL,
'o'},
172 {
"project", required_argument, NULL,
'p'},
173 {
"tools", required_argument, NULL,
't'},
174 {
"translate", required_argument, NULL,
'T'},
175 {
"units", required_argument, NULL,
'u'},
176 {
"window", required_argument, NULL,
'w'},
177 {
"export", required_argument, NULL,
'x'},
178 {
"svg-layers", no_argument, &longopt_val, 3},
179 {
"svg-cairo", no_argument, &longopt_val, 4},
180 {
"geometry", required_argument, &longopt_val, 1},
182 {
"gtk-module", required_argument, &longopt_val, 2},
183 {
"g-fatal-warnings",no_argument, &longopt_val, 2},
184 {
"gtk-debug", required_argument, &longopt_val, 2},
185 {
"gtk-no-debug", required_argument, &longopt_val, 2},
186 {
"gdk-debug", required_argument, &longopt_val, 2},
187 {
"gdk-no-debug", required_argument, &longopt_val, 2},
188 {
"display", required_argument, &longopt_val, 2},
189 {
"sync", no_argument, &longopt_val, 2},
190 {
"no-xshm", no_argument, &longopt_val, 2},
191 {
"name", required_argument, &longopt_val, 2},
192 {
"class", required_argument, &longopt_val, 2},
196 const char *opt_options =
"VadqhB:D:O:W:b:f:r:m:l:o:p:t:T:u:w:x:";
202 gerbv_screen_t screen;
204 gboolean logToFileOption;
205 gchar *logToFileFilename;
206 static gboolean quietMode = FALSE;
207 static FILE *logFile = NULL;
212 care_for_x_in_cords(
char *
string)
215 found = strchr(
string,
'x');
217 found = strchr(
string,
'X');
224 main_open_project_from_filename(
gerbv_project_t *gerbvProject, gchar *filename)
226 project_list_t *list, *plist;
227 gint i, max_layer_num = -1;
230 DPRINTF(
"Opening project = %s\n", (gchar *) filename);
234 GERB_COMPILE_WARNING(_(
"Could not read \"%s\" (loaded %d)"),
243 if (plist->layerno > max_layer_num)
244 max_layer_num = plist->layerno;
251 for (i = -1; i <= max_layer_num; i++) {
254 if (plist->layerno != i) {
259 GdkColor colorTemplate = {0,
260 plist->rgb[0], plist->rgb[1], plist->rgb[2]};
262 screen.background_is_from_project= TRUE;
268 gchar *fullName = NULL;
269 gchar *dirName = NULL;
272 if (!g_path_is_absolute (plist->filename)) {
274 dirName = g_path_get_dirname (filename);
275 fullName = g_build_filename (dirName,
276 plist->filename, NULL);
278 fullName = g_strdup (plist->filename);
284 plist->n_attr, TRUE) == -1) {
285 GERB_MESSAGE(_(
"could not read file: %s"),
295 file_info = gerbvProject->
file[fileIndex];
296 file_info->
color = colorTemplate;
297 file_info->
alpha = plist->alpha;
312 project_destroy_project_list(list);
319 gerbvProject->
project = g_strdup(filename);
320 if (gerbvProject->
project == NULL)
321 GERB_FATAL_ERROR(
"malloc gerbvProject->project failed in %s()",
327 main_save_project_from_filename(
gerbv_project_t *gerbvProject, gchar *filename)
329 project_list_t *list, *plist;
330 gchar *dirName = g_path_get_dirname (filename);
334 list = g_new0 (project_list_t, 1);
337 list->filename = g_strdup(gerbvProject->
path);
339 list->rgb[1] = gerbvProject->
background.green;
343 for (idx = 0; idx <= gerbvProject->
last_loaded; idx++) {
344 if (gerbvProject->
file[idx]) {
345 plist = g_new0 (project_list_t, 1);
347 plist->layerno = idx;
351 if (strncmp (dirName, gerbvProject->
file[idx]->
fullPathname, strlen(dirName)) == 0) {
353 plist->filename = g_strdup(gerbvProject->
file[idx]->
fullPathname + strlen(dirName) + 1);
359 file_info = gerbvProject->
file[idx];
360 plist->rgb[0] = file_info->
color.red;
361 plist->rgb[1] = file_info->
color.green;
362 plist->rgb[2] = file_info->
color.blue;
363 plist->alpha = file_info->
alpha;
377 if (write_project_file(gerbvProject, gerbvProject->
project, list)) {
378 GERB_MESSAGE(_(
"Failed to write project"));
380 project_destroy_project_list(list);
386 main_save_as_project_from_filename(
gerbv_project_t *gerbvProject, gchar *filename)
396 gerbvProject->
project = g_strdup(filename);
397 if (gerbvProject->
project == NULL)
398 GERB_FATAL_ERROR(
"malloc gerbvProject->project failed in %s()",
400 main_save_project_from_filename (gerbvProject, filename);
403 GArray *log_array_tmp = NULL;
409 callbacks_temporary_handle_log_messages(
const gchar *log_domain,
410 GLogLevelFlags log_level,
411 const gchar *message, gpointer user_data) {
412 struct log_struct item;
413 GLogLevelFlags level = log_level & G_LOG_LEVEL_MASK;
416 item.domain = g_strdup (log_domain);
417 item.level = log_level;
418 item.message = g_strdup (message);
419 g_array_append_val (log_array_tmp, item);
422 if (!(quietMode && (level & (G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG)))) {
426 case G_LOG_LEVEL_ERROR: prefix =
"fatal";
break;
427 case G_LOG_LEVEL_CRITICAL: prefix =
"error";
break;
428 case G_LOG_LEVEL_WARNING: prefix =
"warning";
break;
429 case G_LOG_LEVEL_MESSAGE: prefix =
"info";
break;
430 case G_LOG_LEVEL_INFO: prefix =
"note";
break;
431 case G_LOG_LEVEL_DEBUG: prefix =
"debug";
break;
432 default: prefix =
"log";
break;
435 fprintf(stderr,
"%s: %s\n", prefix, message);
438 fprintf(logFile,
"%s: %s\n", prefix, message);
442 if (log_level & G_LOG_FLAG_FATAL)
443 g_log_default_handler (log_domain, log_level, message, user_data);
448 wait_console_for_win(
void)
450 FILE *console = fopen(
"CONOUT$",
"w");
452 fprintf(console, _(
"\n*** Press Enter to continue ***"));
458 attach_console_for_win(
void)
460 if (((HANDLE)_get_osfhandle(fileno(stdout)) == INVALID_HANDLE_VALUE
461 || (HANDLE)_get_osfhandle(fileno(stderr)) == INVALID_HANDLE_VALUE)
462 && AttachConsole(ATTACH_PARENT_PROCESS)) {
464 if ((HANDLE)_get_osfhandle(fileno (stdout)) == INVALID_HANDLE_VALUE)
465 freopen(
"CONOUT$",
"w", stdout);
467 if ((HANDLE)_get_osfhandle(fileno (stderr)) == INVALID_HANDLE_VALUE)
468 freopen(
"CONOUT$",
"w", stderr);
470 atexit(wait_console_for_win);
475 attach_console_for_win(
void) {}
480 main(
int argc,
char *argv[])
484 int req_width = -1, req_height = -1;
485 #ifdef HAVE_GETOPT_LONG
488 char *project_filename = NULL;
489 gboolean userSuppliedOrigin=FALSE, userSuppliedWindow=FALSE,
490 userSuppliedAntiAlias=FALSE, userSuppliedWindowInPixels=FALSE, userSuppliedDpi=FALSE;
491 gint layerctr =0, transformCount = 0;
492 gdouble initial_rotation = 0.0;
493 gdouble input_divisor = 1.0;
494 int unit_flag_counter;
495 gboolean initial_mirror_x = FALSE;
496 gboolean initial_mirror_y = FALSE;
497 gboolean svgLayers = FALSE;
498 const gchar *exportFilename = NULL;
499 gfloat userSuppliedOriginX=0.0,userSuppliedOriginY=0.0,userSuppliedDpiX=72.0, userSuppliedDpiY=72.0,
500 userSuppliedWidth=0, userSuppliedHeight=0,
501 userSuppliedBorder = GERBV_DEFAULT_BORDER_COEFF;
516 enum exp_type exportType = EXP_TYPE_NONE;
517 const char *export_type_names[] = {
528 const gchar *export_def_file_names[] = {
540 const gchar *settings_schema_env =
"GSETTINGS_SCHEMA_DIR";
543 const gchar *settings_schema_fallback_dir =
544 "share/glib-2.0/schemas" G_SEARCHPATH_SEPARATOR_S
545 "../share/glib-2.0/schemas";
547 const gchar *settings_schema_fallback_dir =
"../share/glib-2.0/schemas";
552 setlocale(LC_ALL,
"");
553 bindtextdomain(PACKAGE, GERBV_LOCALEDIR);
555 bind_textdomain_codeset(PACKAGE,
"UTF-8");
560 attach_console_for_win();
569 for (i = 0; i < argc; i++) {
570 gchar *utf8_arg = g_locale_to_utf8(argv[i], -1, NULL, NULL, NULL);
581 memset((
void *)&screen, 0,
sizeof(gerbv_screen_t));
582 screen.state = NORMAL;
583 screen.unit = GERBV_DEFAULT_UNIT;
591 if (NULL == g_getenv(settings_schema_env))
593 env_val = g_strconcat(
595 settings_schema_fallback_dir,
599 env_val = g_strconcat(g_getenv(settings_schema_env),
600 G_SEARCHPATH_SEPARATOR_S,
602 settings_schema_fallback_dir,
604 g_setenv(settings_schema_env, env_val, TRUE);
613 if (!g_getenv(
"GDK_PIXBUF_MODULE_FILE")) {
614 gchar *cache_dir = g_build_filename(
615 g_get_user_cache_dir(),
"gerbv", NULL);
616 g_mkdir_with_parents(cache_dir, 0755);
617 gchar *cache_path = g_build_filename(
618 cache_dir,
"loaders.cache", NULL);
620 if (!g_file_test(cache_path, G_FILE_TEST_EXISTS)) {
621 g_file_set_contents(cache_path,
622 "# GdkPixbuf Image Loader Modules file\n"
623 "# Intentionally empty — gerbv uses no loaders\n",
627 g_setenv(
"GDK_PIXBUF_MODULE_FILE", cache_path, FALSE);
641 logToFileOption = FALSE;
642 logToFileFilename = NULL;
644 log_array_tmp = g_array_new (TRUE, FALSE,
sizeof (
struct log_struct));
645 g_log_set_handler (NULL,
646 G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK,
647 callbacks_temporary_handle_log_messages, NULL);
651 unit_flag_counter = 0;
653 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options,
654 longopts, &longopt_idx))) {
662 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
663 GERB_COMPILE_WARNING(
664 _(
"Unrecognized length unit \"%s\" in command line"),
674 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options,
675 longopts, &longopt_idx))) {
677 #ifdef HAVE_GETOPT_LONG
680 switch (longopt_val) {
682 GERB_COMPILE_WARNING(
683 _(
"Not handled option \"%s\" in command line"),
684 longopts[longopt_idx].name);
688 req_width = (int)strtol(optarg, &rest, 10);
694 fprintf(stderr, _(
"Split X and Y parameters with an x\n"));
699 req_height = (int)strtol(rest, &rest, 10);
735 if (optarg == NULL) {
736 fprintf(stderr, _(
"You must specify the border in the format <alpha>.\n"));
739 if (strlen (optarg) > 10) {
740 fprintf(stderr, _(
"Specified border is not recognized.\n"));
743 sscanf (optarg,
"%f",&userSuppliedBorder);
744 if (userSuppliedBorder < 0) {
745 fprintf(stderr, _(
"Specified border is smaller than zero!\n"));
748 userSuppliedBorder/=100.0;
751 if (optarg == NULL) {
752 fprintf(stderr, _(
"You must give an resolution in the format <DPI_XxDPI_Y> or <DPI_X_and_Y>.\n"));
755 if (strlen (optarg) > 20) {
756 fprintf(stderr, _(
"Specified resolution is not recognized.\n"));
759 if(strchr(optarg,
'x')!=NULL){
760 sscanf (optarg,
"%fx%f",&userSuppliedDpiX,&userSuppliedDpiY);
762 sscanf (optarg,
"%f",&userSuppliedDpiX);
763 userSuppliedDpiY = userSuppliedDpiX;
765 if ((userSuppliedDpiX <= 0) || (userSuppliedDpiY <= 0)) {
766 fprintf(stderr, _(
"Specified resolution should be greater than 0.\n"));
769 userSuppliedDpi=TRUE;
772 if (optarg == NULL) {
773 fprintf(stderr, _(
"You must give an origin in the format "
774 "<XxY> or <X;Y>.\n"));
777 if (strlen (optarg) > 20) {
778 fprintf(stderr, _(
"Specified origin is not recognized.\n"));
782 care_for_x_in_cords(optarg);
783 sscanf(optarg,
"%f;%f", &userSuppliedOriginX, &userSuppliedOriginY);
784 userSuppliedOriginX /= input_divisor;
785 userSuppliedOriginY /= input_divisor;
786 userSuppliedOrigin=TRUE;
789 printf(_(
"gerbv version %s\n"), VERSION);
790 printf(_(
"Copyright (C) 2001-2008 by Stefan Petersen\n"
791 "and the respective original authors listed in the source files.\n"));
794 userSuppliedAntiAlias = TRUE;
797 if (optarg == NULL) {
798 fprintf(stderr, _(
"You must give an background color "
799 "in the hex-format <#RRGGBB>.\n"));
802 if ((strlen (optarg) != 7)||(optarg[0]!=
'#')) {
803 fprintf(stderr, _(
"Specified color format "
804 "is not recognized.\n"));
808 sscanf (optarg,
"#%2x%2x%2x",&r,&g,&b);
809 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)) {
811 fprintf(stderr, _(
"Specified color values should be "
812 "between 00 and FF.\n"));
816 screen.background_is_from_cmdline = TRUE;
823 if (optarg == NULL) {
824 fprintf(stderr, _(
"You must give an foreground color in the hex-format <#RRGGBB> or <#RRGGBBAA>.\n"));
827 if (((strlen (optarg) != 7)&&(strlen (optarg) != 9))||(optarg[0]!=
'#')) {
828 fprintf(stderr, _(
"Specified color format is not recognized.\n"));
832 if(strlen(optarg)==7){
833 sscanf (optarg,
"#%2x%2x%2x",&r,&g,&b);
837 sscanf (optarg,
"#%2x%2x%2x%2x",&r,&g,&b,&a);
840 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)||(a<0)||(a>255) ) {
842 fprintf(stderr, _(
"Specified color values should be between 0x00 (0) and 0xFF (255).\n"));
845 mainDefaultColors[layerctr].red = r;
846 mainDefaultColors[layerctr].green = g;
847 mainDefaultColors[layerctr].blue = b;
848 mainDefaultColors[layerctr].alpha = a;
851 if (layerctr == NUMBER_OF_DEFAULT_COLORS)
855 if (optarg == NULL) {
856 fprintf(stderr, _(
"You must give the initial rotation angle\n"));
860 initial_rotation = (gdouble)strtod(optarg, &rest);
866 fprintf(stderr, _(
"Failed parsing rotate value\n"));
871 if (optarg == NULL) {
872 fprintf(stderr, _(
"You must give the axis to mirror about\n"));
875 if (strchr(optarg,
'x') != NULL || strchr(optarg,
'X') != NULL) {
876 initial_mirror_x = TRUE;
878 if (strchr(optarg,
'y') != NULL || strchr(optarg,
'Y') != NULL) {
879 initial_mirror_y = TRUE;
881 if (!(initial_mirror_x || initial_mirror_y)) {
882 fprintf(stderr, _(
"Failed parsing mirror axis\n"));
887 if (optarg == NULL) {
888 fprintf(stderr, _(
"You must give a filename to send log to\n"));
891 logToFileOption = TRUE;
892 logToFileFilename = optarg;
895 if (optarg == NULL) {
896 fprintf(stderr, _(
"You must give a filename to export to.\n"));
899 exportFilename = optarg;
902 if (optarg == NULL) {
903 fprintf(stderr, _(
"You must give a project filename\n"));
906 project_filename = optarg;
909 if (optarg == NULL) {
910 fprintf(stderr, _(
"You must give a filename to read the tools from.\n"));
913 if (!gerbv_process_tools_file(optarg)) {
914 fprintf(stderr, _(
"*** ERROR processing tools file \"%s\".\n"), optarg);
915 fprintf(stderr, _(
"Make sure all lines of the file are formatted like this:\n"
916 "T01 0.024\nT02 0.032\nT03 0.040\n...\n"
917 "*** EXITING to prevent erroneous display.\n"));
922 if (optarg == NULL) {
923 fprintf(stderr, _(
"You must give a translation in the format "
924 "<XxY> or <X;Y>.\n"));
927 if (strlen (optarg) > 30) {
928 fprintf(stderr, _(
"The translation format is not recognized.\n"));
932 float transX = 0, transY = 0, rotate = 0;
934 care_for_x_in_cords(optarg);
935 sscanf(optarg,
"%f;%fr%f", &transX, &transY, &rotate);
936 transX /= input_divisor;
937 transY /= input_divisor;
938 mainDefaultTransformations[transformCount].
translateX = transX;
939 mainDefaultTransformations[transformCount].
translateY = transY;
940 mainDefaultTransformations[transformCount].
rotation = DEG2RAD(rotate);
943 if (transformCount == NUMBER_OF_DEFAULT_TRANSFORMATIONS)
947 if (unit_flag_counter == 1)
952 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
953 GERB_COMPILE_WARNING(
954 _(
"Unrecognized length unit \"%s\" in command line"),
960 userSuppliedWindowInPixels = TRUE;
963 if (optarg == NULL) {
964 fprintf(stderr, _(
"You must give a window size in the format <width x height>.\n"));
967 if (strlen (optarg) > 20) {
968 fprintf(stderr, _(
"Specified window size is not recognized.\n"));
971 sscanf (optarg,
"%fx%f", &userSuppliedWidth, &userSuppliedHeight);
972 if (((userSuppliedWidth < 0.001) || (userSuppliedHeight < 0.001)) ||
973 ((userSuppliedWidth > 2000) || (userSuppliedHeight > 2000))) {
974 fprintf(stderr, _(
"Specified window size is out of bounds.\n"));
977 userSuppliedWindow = TRUE;
980 if (optarg == NULL) {
981 fprintf(stderr, _(
"You must supply an export type.\n"));
985 for (i = 0; export_type_names[i] != NULL; i++) {
986 if (strcmp (optarg, export_type_names[i]) == 0) {
992 if (exportType == EXP_TYPE_NONE) {
993 fprintf(stderr, _(
"Unrecognized \"%s\" export type.\n"),
999 screen.dump_parsed_image = 1;
1012 GERB_COMPILE_WARNING(_(
"Not handled option '%c' in command line"),
1017 if (logToFileOption) {
1018 logFile = g_fopen(logToFileFilename,
"w");
1020 int saved_errno = errno;
1021 fprintf(stderr,
"error: cannot open log file '%s': %s\n",
1022 logToFileFilename, strerror(saved_errno));
1030 if ( !project_filename &&
1031 optind == (argc-1) &&
1033 project_filename = argv[optind];
1043 if (project_filename) {
1044 DPRINTF(_(
"Loading project %s...\n"), project_filename);
1048 if (!g_path_is_absolute(project_filename)) {
1049 gchar *currentDir = g_get_current_dir ();
1050 gchar *fullName = g_build_filename (currentDir,
1051 project_filename, NULL);
1052 main_open_project_from_filename (
mainProject, fullName);
1055 g_free (currentDir);
1057 main_open_project_from_filename (
mainProject, project_filename);
1061 gint loadedIndex = 0;
1062 for(i = optind ; i < argc; i++) {
1063 gchar *arg = argv[i];
1066 if (!g_path_is_absolute(arg)) {
1067 gchar *currentDir = g_get_current_dir();
1068 absArg = g_build_filename(currentDir, arg, NULL);
1071 absArg = g_strdup(arg);
1074 if (g_file_test(absArg, G_FILE_TEST_IS_DIR)) {
1075 GList *files = scan_directory(absArg);
1078 _(
"No loadable files found in \"%s\"\n"), arg);
1080 for (GList *l = files; l != NULL; l = l->next) {
1084 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
1085 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
1086 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
1087 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
1091 g_list_free_full(files, g_free);
1095 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
1096 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
1097 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
1098 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
1106 if (initial_rotation != 0.0) {
1109 gdouble initial_radians = DEG2RAD(initial_rotation);
1111 DPRINTF(
"Rotating all layers by %.0f degrees\n", (
float) initial_rotation);
1118 if (initial_mirror_x || initial_mirror_y) {
1121 if (initial_mirror_x) {
1122 DPRINTF(
"Mirroring all layers about x axis\n");
1124 if (initial_mirror_y) {
1125 DPRINTF(
"Mirroring all layers about y axis\n");
1136 if (exportType != EXP_TYPE_NONE) {
1139 if (!exportFilename)
1140 exportFilename = export_def_file_names[exportType];
1145 if(!userSuppliedOrigin){
1146 userSuppliedOriginX = bb.
left;
1147 userSuppliedOriginY = bb.
top;
1150 float width = bb.
right - userSuppliedOriginX + 0.001;
1151 float height = bb.
bottom - userSuppliedOriginY + 0.001;
1153 if(!userSuppliedWindow){
1154 userSuppliedWidth = width;
1155 userSuppliedHeight = height;
1158 if( (!userSuppliedDpi)&& userSuppliedWindowInPixels){
1159 userSuppliedDpiX = MIN((userSuppliedWidth-0.5)/width,
1160 (userSuppliedHeight-0.5)/height);
1161 userSuppliedDpiY = userSuppliedDpiX;
1162 userSuppliedOriginX -= 0.5/userSuppliedDpiX;
1163 userSuppliedOriginY -= 0.5/userSuppliedDpiY;
1168 if(userSuppliedBorder!=0){
1170 if(!userSuppliedWindowInPixels){
1171 userSuppliedOriginX -= (userSuppliedWidth*userSuppliedBorder)/2.0;
1172 userSuppliedOriginY -= (userSuppliedHeight*userSuppliedBorder)/2.0;
1173 userSuppliedWidth += userSuppliedWidth*userSuppliedBorder;
1174 userSuppliedHeight += userSuppliedHeight*userSuppliedBorder;
1178 userSuppliedOriginX -= ((userSuppliedWidth/userSuppliedDpiX)*userSuppliedBorder)/2.0;
1179 userSuppliedOriginY -= ((userSuppliedHeight/userSuppliedDpiX)*userSuppliedBorder)/2.0;
1180 userSuppliedDpiX -= (userSuppliedDpiX*userSuppliedBorder);
1181 userSuppliedDpiY -= (userSuppliedDpiY*userSuppliedBorder);
1185 if(!userSuppliedWindowInPixels){
1186 userSuppliedWidth *= userSuppliedDpiX;
1187 userSuppliedHeight *= userSuppliedDpiY;
1192 if(userSuppliedWidth <=0)
1193 userSuppliedWidth = 1;
1194 if(userSuppliedHeight <=0)
1195 userSuppliedHeight = 1;
1199 userSuppliedOriginX, userSuppliedOriginY,
1201 userSuppliedWidth,userSuppliedHeight };
1203 switch (exportType) {
1206 &renderInfo, exportFilename);
1210 &renderInfo, exportFilename);
1214 &renderInfo, exportFilename, svgLayers);
1218 &renderInfo, exportFilename);
1220 case EXP_TYPE_RS274X:
1221 case EXP_TYPE_DRILL:
1222 case EXP_TYPE_IDRILL:
1225 fprintf(stderr, _(
"A valid file was not loaded.\n"));
1233 &mainDefaultTransformations[0]);
1239 &mainDefaultTransformations[i], exportImage);
1242 switch (exportType) {
1243 case EXP_TYPE_RS274X:
1247 case EXP_TYPE_DRILL:
1251 case EXP_TYPE_IDRILL:
1266 fprintf(stderr, _(
"A valid file was not loaded.\n"));
1277 gtk_init (&argc, &argv);
1278 interface_create_gui (req_width, req_height);
1281 render_free_screen_resources();
1289 getopt_configured(
int argc,
char *
const argv[],
const char *optstring,
1290 const struct option *longopts,
int *longindex)
1292 #ifdef HAVE_GETOPT_LONG
1293 return getopt_long(argc, argv, optstring, longopts, longindex);
1295 return getopt(argc, argv, optstring);
1300 getopt_lengh_unit(
const char *optarg,
double *input_div, gerbv_screen_t *screen)
1302 if (strncasecmp(optarg,
"mm", 2) == 0) {
1304 screen->unit = GERBV_MMS;
1305 screen->unit_is_from_cmdline = TRUE;
1306 }
else if (strncasecmp(optarg,
"mil", 3) == 0) {
1307 *input_div = 1000.0;
1308 screen->unit = GERBV_MILS;
1309 screen->unit_is_from_cmdline = TRUE;
1310 }
else if (strncasecmp(optarg,
"inch", 4) == 0) {
1312 screen->unit = GERBV_INS;
1313 screen->unit_is_from_cmdline = TRUE;
1322 gerbv_print_help(
void)
1325 "Usage: gerbv [OPTIONS...] [FILE...]\n"
1327 "Available options:\n"));
1329 #ifdef HAVE_GETOPT_LONG
1331 " -B, --border=<b> Border around the image in percent of the\n"
1332 " width/height. Defaults to %d%%.\n"),
1333 (
int)(100*GERBV_DEFAULT_BORDER_COEFF));
1336 " -B<b> Border around the image in percent of the\n"
1337 " width/height. Defaults to %d%%.\n"),
1338 (
int)(100*GERBV_DEFAULT_BORDER_COEFF));
1341 #ifdef HAVE_GETOPT_LONG
1343 " -D, --dpi=<XxY|R> Resolution (Dots per inch) for the output\n"
1344 " bitmap. With the format <XxY>, different\n"
1345 " resolutions for X- and Y-direction are used.\n"
1346 " With the format <R>, both are the same.\n"));
1349 " -D<XxY|R> Resolution (Dots per inch) for the output\n"
1350 " bitmap. With the format <XxY>, different\n"
1351 " resolutions for X- and Y-direction are used.\n"
1352 " With the format <R>, both are the same.\n"));
1355 #ifdef HAVE_GETOPT_LONG
1357 " -O, --origin=<XxY|X;Y> Use the specified coordinates (in inches)\n"
1358 " for the lower left corner.\n"));
1361 " -O<XxY|X;Y> Use the specified coordinates (in inches)\n"
1362 " for the lower left corner.\n"));
1365 #ifdef HAVE_GETOPT_LONG
1367 " -V, --version Print version of Gerbv.\n"));
1370 " -V Print version of Gerbv.\n"));
1373 #ifdef HAVE_GETOPT_LONG
1375 " -a, --antialias Use antialiasing for generated bitmap output.\n"));
1378 " -a Use antialiasing for generated bitmap output.\n"));
1381 #ifdef HAVE_GETOPT_LONG
1383 " -b, --background=<hex> Use background color <hex> (like #RRGGBB).\n"));
1386 " -b<hexcolor> Use background color <hexcolor> (like #RRGGBB).\n"));
1389 #ifdef HAVE_GETOPT_LONG
1391 " -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB or\n"
1392 " #RRGGBBAA for setting the alpha).\n"
1393 " Use multiple -f flags to set the color for\n"
1394 " multiple layers.\n"));
1397 " -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB or\n"
1398 " #RRGGBBAA for setting the alpha).\n"
1399 " Use multiple -f flags to set the color for\n"
1400 " multiple layers.\n"));
1403 #ifdef HAVE_GETOPT_LONG
1405 " -r, --rotate=<degree> Set initial orientation for all layers.\n"));
1408 " -r<degree> Set initial orientation for all layers.\n"));
1411 #ifdef HAVE_GETOPT_LONG
1413 " -m, --mirror=<axis> Set initial mirroring axis (X or Y).\n"));
1416 " -m<axis> Set initial mirroring axis (X or Y).\n"));
1419 #ifdef HAVE_GETOPT_LONG
1421 " -h, --help Print this help message.\n"));
1424 " -h Print this help message.\n"));
1427 #ifdef HAVE_GETOPT_LONG
1429 " -l, --log=<logfile> Send error messages to <logfile>.\n"));
1432 " -l<logfile> Send error messages to <logfile>.\n"));
1435 #ifdef HAVE_GETOPT_LONG
1437 " -q, --quiet Suppress note-level messages.\n"));
1440 " -q Suppress note-level messages.\n"));
1443 #ifdef HAVE_GETOPT_LONG
1445 " -o, --output=<filename> Export to <filename>.\n"));
1448 " -o<filename> Export to <filename>.\n"));
1451 #ifdef HAVE_GETOPT_LONG
1453 " -p, --project=<prjfile> Load project file <prjfile>.\n"));
1456 " -p<prjfile> Load project file <prjfile>.\n"));
1459 #ifdef HAVE_GETOPT_LONG
1461 " -u, --units=<inch|mm|mil>\n"
1462 " Use given unit for coordinates.\n"
1463 " Default to inch.\n"));
1466 " -u<inch|mm|mil> Use given unit for coordinates.\n"
1467 " Default to inch.\n"));
1470 #ifdef HAVE_GETOPT_LONG
1472 " -W, --window_inch=<WxH> Window size in inches <WxH> for the exported image.\n"));
1475 " -W<WxH> Window size in inches <WxH> for the exported image.\n"));
1478 #ifdef HAVE_GETOPT_LONG
1480 " -w, --window=<WxH> Window size in pixels <WxH> for the exported image.\n"
1481 " Autoscales to fit if no resolution is specified.\n"
1482 " If a resolution is specified, it will clip\n"
1483 " exported image.\n"));
1486 " -w<WxH> Window size in pixels <WxH> for the exported image.\n"
1487 " Autoscales to fit if no resolution is specified.\n"
1488 " If a resolution is specified, it will clip\n"
1489 " exported image.\n"));
1492 #ifdef HAVE_GETOPT_LONG
1494 " -t, --tools=<toolfile> Read Excellon tools from file <toolfile>.\n"));
1497 " -t<toolfile> Read Excellon tools from file <toolfile>\n"));
1500 #ifdef HAVE_GETOPT_LONG
1502 " -T, --translate=<XxYrR| Translate image by X and Y and rotate by R degree.\n"
1503 " X;YrR> Useful for arranging panels.\n"
1504 " Use multiple -T flags for multiple layers.\n"
1505 " Only evaluated when exporting as RS274X or drill.\n"));
1508 " -T<XxYrR|X;YrR> Translate image by X and Y and rotate by R degree.\n"
1509 " Useful for arranging panels.\n"
1510 " Use multiple -T flags for multiple files.\n"
1511 " Only evaluated when exporting as RS274X or drill.\n"));
1514 #ifdef HAVE_GETOPT_LONG
1516 " -x, --export=<png|pdf|ps|svg|rs274x|drill|idrill|dxf>\n"
1517 " Export a rendered picture to a file with\n"
1518 " the specified format.\n"));
1520 " --svg-layers Export visible layers as Inkscape SVG layers.\n"
1521 " Only used with --export=svg.\n"));
1523 " --svg-cairo Use Cairo SVG surface (legacy, larger output).\n"
1524 " Only used with --export=svg.\n"));
1527 " -x<png|pdf|ps|svg| Export a rendered picture to a file with\n"
1528 " rs274x|drill| the specified format.\n"
1532 " --svg-layers Export visible layers as Inkscape SVG layers.\n"
1533 " Only used with -xsvg.\n"));
1535 " --svg-cairo Use Cairo SVG surface (legacy, larger output).\n"
1536 " Only used with -xsvg.\n"));
Header info for the GUI callback functions.
gboolean gerbv_export_drill_file_from_image(const gchar *filename, gerbv_image_t *inputImage, gerbv_user_transformation_t *transform)
Export an image to a new file in Excellon drill format.
gboolean gerbv_export_dxf_file_from_image(const gchar *file_name, gerbv_image_t *input_img, gerbv_user_transformation_t *trans)
Export an image to a new file in DXF format.
void gerbv_export_png_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, gchar const *filename)
Render a project to a PNG file using user-specified render info.
void gerbv_export_postscript_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, gchar const *filename)
Render a project to a Postscript file using user-specified render info.
void gerbv_export_svg_file_from_project_with_options(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, gchar const *filename, gboolean exportLayersAsSvgLayers)
Render a project to a SVG file using user-specified render info and export options.
void gerbv_export_pdf_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, gchar const *filename)
Render a project to a PDF file using user-specified render info.
gboolean gerbv_export_isel_drill_file_from_image(const gchar *filename, gerbv_image_t *inputImage, gerbv_user_transformation_t *transform)
Export an image to a new file in ISEL NCP drill format.
gboolean gerbv_export_rs274x_file_from_image(const gchar *filename, gerbv_image_t *inputImage, gerbv_user_transformation_t *transform)
Export an image to a new file in RS274X format.
void gerbv_destroy_image(gerbv_image_t *image)
Free an image structure.
void gerbv_image_copy_image(gerbv_image_t *sourceImage, gerbv_user_transformation_t *transform, gerbv_image_t *destinationImage)
Copy an image into an existing image, effectively merging the two together.
gerbv_image_t * gerbv_image_duplicate_image(gerbv_image_t *sourceImage, gerbv_user_transformation_t *transform)
Duplicate an existing image and return the new copy.
int gerbv_open_image(gerbv_project_t *gerbvProject, gchar const *filename, int idx, int reload, gerbv_HID_Attribute *fattr, int n_fattr, gboolean forceLoadFile)
void gerbv_destroy_project(gerbv_project_t *gerbvProject)
Free a project and all related variables.
void gerbv_open_layer_from_filename_with_color(gerbv_project_t *gerbvProject, gchar const *filename, guint16 red, guint16 green, guint16 blue, guint16 alpha)
Open a file, parse the contents, and add a new layer to an existing project while setting the color o...
gerbv_project_t * gerbv_create_project(void)
Create a new project structure and initialize some important variables.
gboolean gerbv_is_loadable_file(const char *filename)
gboolean gerbv_endswith(const char *path, const char *ext)
The main header file for the libgerbv library.
@ GERBV_RENDER_TYPE_CAIRO_HIGH_QUALITY
@ GERBV_RENDER_TYPE_CAIRO_NORMAL
Header info for the GUI building functions for Gerber Viewer.
gerbv_project_t * mainProject
Global state variable to keep track of what's happening on the screen.
Header info for common structs and functions used for the GUI application.
project_list_t * read_project_file(char const *filename)
Reads the content of a project file.
Header info for loading and saving project files.
Header info for the rendering support functions for gerbv.
gerbv_user_transformation_t transform
gerbv_render_types_t renderType