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);
615 logToFileOption = FALSE;
616 logToFileFilename = NULL;
618 log_array_tmp = g_array_new (TRUE, FALSE,
sizeof (
struct log_struct));
619 g_log_set_handler (NULL,
620 G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK,
621 callbacks_temporary_handle_log_messages, NULL);
625 unit_flag_counter = 0;
627 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options,
628 longopts, &longopt_idx))) {
636 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
637 GERB_COMPILE_WARNING(
638 _(
"Unrecognized length unit \"%s\" in command line"),
648 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options,
649 longopts, &longopt_idx))) {
651 #ifdef HAVE_GETOPT_LONG
654 switch (longopt_val) {
656 GERB_COMPILE_WARNING(
657 _(
"Not handled option \"%s\" in command line"),
658 longopts[longopt_idx].name);
662 req_width = (int)strtol(optarg, &rest, 10);
668 fprintf(stderr, _(
"Split X and Y parameters with an x\n"));
673 req_height = (int)strtol(rest, &rest, 10);
709 if (optarg == NULL) {
710 fprintf(stderr, _(
"You must specify the border in the format <alpha>.\n"));
713 if (strlen (optarg) > 10) {
714 fprintf(stderr, _(
"Specified border is not recognized.\n"));
717 sscanf (optarg,
"%f",&userSuppliedBorder);
718 if (userSuppliedBorder < 0) {
719 fprintf(stderr, _(
"Specified border is smaller than zero!\n"));
722 userSuppliedBorder/=100.0;
725 if (optarg == NULL) {
726 fprintf(stderr, _(
"You must give an resolution in the format <DPI_XxDPI_Y> or <DPI_X_and_Y>.\n"));
729 if (strlen (optarg) > 20) {
730 fprintf(stderr, _(
"Specified resolution is not recognized.\n"));
733 if(strchr(optarg,
'x')!=NULL){
734 sscanf (optarg,
"%fx%f",&userSuppliedDpiX,&userSuppliedDpiY);
736 sscanf (optarg,
"%f",&userSuppliedDpiX);
737 userSuppliedDpiY = userSuppliedDpiX;
739 if ((userSuppliedDpiX <= 0) || (userSuppliedDpiY <= 0)) {
740 fprintf(stderr, _(
"Specified resolution should be greater than 0.\n"));
743 userSuppliedDpi=TRUE;
746 if (optarg == NULL) {
747 fprintf(stderr, _(
"You must give an origin in the format "
748 "<XxY> or <X;Y>.\n"));
751 if (strlen (optarg) > 20) {
752 fprintf(stderr, _(
"Specified origin is not recognized.\n"));
756 care_for_x_in_cords(optarg);
757 sscanf(optarg,
"%f;%f", &userSuppliedOriginX, &userSuppliedOriginY);
758 userSuppliedOriginX /= input_divisor;
759 userSuppliedOriginY /= input_divisor;
760 userSuppliedOrigin=TRUE;
763 printf(_(
"gerbv version %s\n"), VERSION);
764 printf(_(
"Copyright (C) 2001-2008 by Stefan Petersen\n"
765 "and the respective original authors listed in the source files.\n"));
768 userSuppliedAntiAlias = TRUE;
771 if (optarg == NULL) {
772 fprintf(stderr, _(
"You must give an background color "
773 "in the hex-format <#RRGGBB>.\n"));
776 if ((strlen (optarg) != 7)||(optarg[0]!=
'#')) {
777 fprintf(stderr, _(
"Specified color format "
778 "is not recognized.\n"));
782 sscanf (optarg,
"#%2x%2x%2x",&r,&g,&b);
783 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)) {
785 fprintf(stderr, _(
"Specified color values should be "
786 "between 00 and FF.\n"));
790 screen.background_is_from_cmdline = TRUE;
797 if (optarg == NULL) {
798 fprintf(stderr, _(
"You must give an foreground color in the hex-format <#RRGGBB> or <#RRGGBBAA>.\n"));
801 if (((strlen (optarg) != 7)&&(strlen (optarg) != 9))||(optarg[0]!=
'#')) {
802 fprintf(stderr, _(
"Specified color format is not recognized.\n"));
806 if(strlen(optarg)==7){
807 sscanf (optarg,
"#%2x%2x%2x",&r,&g,&b);
811 sscanf (optarg,
"#%2x%2x%2x%2x",&r,&g,&b,&a);
814 if ( (r<0)||(r>255)||(g<0)||(g>255)||(b<0)||(b>255)||(a<0)||(a>255) ) {
816 fprintf(stderr, _(
"Specified color values should be between 0x00 (0) and 0xFF (255).\n"));
819 mainDefaultColors[layerctr].red = r;
820 mainDefaultColors[layerctr].green = g;
821 mainDefaultColors[layerctr].blue = b;
822 mainDefaultColors[layerctr].alpha = a;
825 if (layerctr == NUMBER_OF_DEFAULT_COLORS)
829 if (optarg == NULL) {
830 fprintf(stderr, _(
"You must give the initial rotation angle\n"));
834 initial_rotation = (gdouble)strtod(optarg, &rest);
840 fprintf(stderr, _(
"Failed parsing rotate value\n"));
845 if (optarg == NULL) {
846 fprintf(stderr, _(
"You must give the axis to mirror about\n"));
849 if (strchr(optarg,
'x') != NULL || strchr(optarg,
'X') != NULL) {
850 initial_mirror_x = TRUE;
852 if (strchr(optarg,
'y') != NULL || strchr(optarg,
'Y') != NULL) {
853 initial_mirror_y = TRUE;
855 if (!(initial_mirror_x || initial_mirror_y)) {
856 fprintf(stderr, _(
"Failed parsing mirror axis\n"));
861 if (optarg == NULL) {
862 fprintf(stderr, _(
"You must give a filename to send log to\n"));
865 logToFileOption = TRUE;
866 logToFileFilename = optarg;
869 if (optarg == NULL) {
870 fprintf(stderr, _(
"You must give a filename to export to.\n"));
873 exportFilename = optarg;
876 if (optarg == NULL) {
877 fprintf(stderr, _(
"You must give a project filename\n"));
880 project_filename = optarg;
883 if (optarg == NULL) {
884 fprintf(stderr, _(
"You must give a filename to read the tools from.\n"));
887 if (!gerbv_process_tools_file(optarg)) {
888 fprintf(stderr, _(
"*** ERROR processing tools file \"%s\".\n"), optarg);
889 fprintf(stderr, _(
"Make sure all lines of the file are formatted like this:\n"
890 "T01 0.024\nT02 0.032\nT03 0.040\n...\n"
891 "*** EXITING to prevent erroneous display.\n"));
896 if (optarg == NULL) {
897 fprintf(stderr, _(
"You must give a translation in the format "
898 "<XxY> or <X;Y>.\n"));
901 if (strlen (optarg) > 30) {
902 fprintf(stderr, _(
"The translation format is not recognized.\n"));
906 float transX = 0, transY = 0, rotate = 0;
908 care_for_x_in_cords(optarg);
909 sscanf(optarg,
"%f;%fr%f", &transX, &transY, &rotate);
910 transX /= input_divisor;
911 transY /= input_divisor;
912 mainDefaultTransformations[transformCount].
translateX = transX;
913 mainDefaultTransformations[transformCount].
translateY = transY;
914 mainDefaultTransformations[transformCount].
rotation = DEG2RAD(rotate);
917 if (transformCount == NUMBER_OF_DEFAULT_TRANSFORMATIONS)
921 if (unit_flag_counter == 1)
926 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
927 GERB_COMPILE_WARNING(
928 _(
"Unrecognized length unit \"%s\" in command line"),
934 userSuppliedWindowInPixels = TRUE;
937 if (optarg == NULL) {
938 fprintf(stderr, _(
"You must give a window size in the format <width x height>.\n"));
941 if (strlen (optarg) > 20) {
942 fprintf(stderr, _(
"Specified window size is not recognized.\n"));
945 sscanf (optarg,
"%fx%f", &userSuppliedWidth, &userSuppliedHeight);
946 if (((userSuppliedWidth < 0.001) || (userSuppliedHeight < 0.001)) ||
947 ((userSuppliedWidth > 2000) || (userSuppliedHeight > 2000))) {
948 fprintf(stderr, _(
"Specified window size is out of bounds.\n"));
951 userSuppliedWindow = TRUE;
954 if (optarg == NULL) {
955 fprintf(stderr, _(
"You must supply an export type.\n"));
959 for (i = 0; export_type_names[i] != NULL; i++) {
960 if (strcmp (optarg, export_type_names[i]) == 0) {
966 if (exportType == EXP_TYPE_NONE) {
967 fprintf(stderr, _(
"Unrecognized \"%s\" export type.\n"),
973 screen.dump_parsed_image = 1;
986 GERB_COMPILE_WARNING(_(
"Not handled option '%c' in command line"),
991 if (logToFileOption) {
992 logFile = g_fopen(logToFileFilename,
"w");
994 int saved_errno = errno;
995 fprintf(stderr,
"error: cannot open log file '%s': %s\n",
996 logToFileFilename, strerror(saved_errno));
1004 if ( !project_filename &&
1005 optind == (argc-1) &&
1007 project_filename = argv[optind];
1017 if (project_filename) {
1018 DPRINTF(_(
"Loading project %s...\n"), project_filename);
1022 if (!g_path_is_absolute(project_filename)) {
1023 gchar *currentDir = g_get_current_dir ();
1024 gchar *fullName = g_build_filename (currentDir,
1025 project_filename, NULL);
1026 main_open_project_from_filename (
mainProject, fullName);
1029 g_free (currentDir);
1031 main_open_project_from_filename (
mainProject, project_filename);
1035 gint loadedIndex = 0;
1036 for(i = optind ; i < argc; i++) {
1037 gchar *arg = argv[i];
1040 if (!g_path_is_absolute(arg)) {
1041 gchar *currentDir = g_get_current_dir();
1042 absArg = g_build_filename(currentDir, arg, NULL);
1045 absArg = g_strdup(arg);
1048 if (g_file_test(absArg, G_FILE_TEST_IS_DIR)) {
1049 GList *files = scan_directory(absArg);
1052 _(
"No loadable files found in \"%s\"\n"), arg);
1054 for (GList *l = files; l != NULL; l = l->next) {
1058 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
1059 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
1060 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
1061 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
1065 g_list_free_full(files, g_free);
1069 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red*257,
1070 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green*257,
1071 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue*257,
1072 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha*257);
1080 if (initial_rotation != 0.0) {
1083 gdouble initial_radians = DEG2RAD(initial_rotation);
1085 DPRINTF(
"Rotating all layers by %.0f degrees\n", (
float) initial_rotation);
1092 if (initial_mirror_x || initial_mirror_y) {
1095 if (initial_mirror_x) {
1096 DPRINTF(
"Mirroring all layers about x axis\n");
1098 if (initial_mirror_y) {
1099 DPRINTF(
"Mirroring all layers about y axis\n");
1110 if (exportType != EXP_TYPE_NONE) {
1113 if (!exportFilename)
1114 exportFilename = export_def_file_names[exportType];
1119 if(!userSuppliedOrigin){
1120 userSuppliedOriginX = bb.
left;
1121 userSuppliedOriginY = bb.
top;
1124 float width = bb.
right - userSuppliedOriginX + 0.001;
1125 float height = bb.
bottom - userSuppliedOriginY + 0.001;
1127 if(!userSuppliedWindow){
1128 userSuppliedWidth = width;
1129 userSuppliedHeight = height;
1132 if( (!userSuppliedDpi)&& userSuppliedWindowInPixels){
1133 userSuppliedDpiX = MIN((userSuppliedWidth-0.5)/width,
1134 (userSuppliedHeight-0.5)/height);
1135 userSuppliedDpiY = userSuppliedDpiX;
1136 userSuppliedOriginX -= 0.5/userSuppliedDpiX;
1137 userSuppliedOriginY -= 0.5/userSuppliedDpiY;
1142 if(userSuppliedBorder!=0){
1144 if(!userSuppliedWindowInPixels){
1145 userSuppliedOriginX -= (userSuppliedWidth*userSuppliedBorder)/2.0;
1146 userSuppliedOriginY -= (userSuppliedHeight*userSuppliedBorder)/2.0;
1147 userSuppliedWidth += userSuppliedWidth*userSuppliedBorder;
1148 userSuppliedHeight += userSuppliedHeight*userSuppliedBorder;
1152 userSuppliedOriginX -= ((userSuppliedWidth/userSuppliedDpiX)*userSuppliedBorder)/2.0;
1153 userSuppliedOriginY -= ((userSuppliedHeight/userSuppliedDpiX)*userSuppliedBorder)/2.0;
1154 userSuppliedDpiX -= (userSuppliedDpiX*userSuppliedBorder);
1155 userSuppliedDpiY -= (userSuppliedDpiY*userSuppliedBorder);
1159 if(!userSuppliedWindowInPixels){
1160 userSuppliedWidth *= userSuppliedDpiX;
1161 userSuppliedHeight *= userSuppliedDpiY;
1166 if(userSuppliedWidth <=0)
1167 userSuppliedWidth = 1;
1168 if(userSuppliedHeight <=0)
1169 userSuppliedHeight = 1;
1173 userSuppliedOriginX, userSuppliedOriginY,
1175 userSuppliedWidth,userSuppliedHeight };
1177 switch (exportType) {
1180 &renderInfo, exportFilename);
1184 &renderInfo, exportFilename);
1188 &renderInfo, exportFilename, svgLayers);
1192 &renderInfo, exportFilename);
1194 case EXP_TYPE_RS274X:
1195 case EXP_TYPE_DRILL:
1196 case EXP_TYPE_IDRILL:
1199 fprintf(stderr, _(
"A valid file was not loaded.\n"));
1207 &mainDefaultTransformations[0]);
1213 &mainDefaultTransformations[i], exportImage);
1216 switch (exportType) {
1217 case EXP_TYPE_RS274X:
1221 case EXP_TYPE_DRILL:
1225 case EXP_TYPE_IDRILL:
1240 fprintf(stderr, _(
"A valid file was not loaded.\n"));
1251 gtk_init (&argc, &argv);
1252 interface_create_gui (req_width, req_height);
1255 render_free_screen_resources();
1263 getopt_configured(
int argc,
char *
const argv[],
const char *optstring,
1264 const struct option *longopts,
int *longindex)
1266 #ifdef HAVE_GETOPT_LONG
1267 return getopt_long(argc, argv, optstring, longopts, longindex);
1269 return getopt(argc, argv, optstring);
1274 getopt_lengh_unit(
const char *optarg,
double *input_div, gerbv_screen_t *screen)
1276 if (strncasecmp(optarg,
"mm", 2) == 0) {
1278 screen->unit = GERBV_MMS;
1279 screen->unit_is_from_cmdline = TRUE;
1280 }
else if (strncasecmp(optarg,
"mil", 3) == 0) {
1281 *input_div = 1000.0;
1282 screen->unit = GERBV_MILS;
1283 screen->unit_is_from_cmdline = TRUE;
1284 }
else if (strncasecmp(optarg,
"inch", 4) == 0) {
1286 screen->unit = GERBV_INS;
1287 screen->unit_is_from_cmdline = TRUE;
1296 gerbv_print_help(
void)
1299 "Usage: gerbv [OPTIONS...] [FILE...]\n"
1301 "Available options:\n"));
1303 #ifdef HAVE_GETOPT_LONG
1305 " -B, --border=<b> Border around the image in percent of the\n"
1306 " width/height. Defaults to %d%%.\n"),
1307 (
int)(100*GERBV_DEFAULT_BORDER_COEFF));
1310 " -B<b> Border around the image in percent of the\n"
1311 " width/height. Defaults to %d%%.\n"),
1312 (
int)(100*GERBV_DEFAULT_BORDER_COEFF));
1315 #ifdef HAVE_GETOPT_LONG
1317 " -D, --dpi=<XxY|R> Resolution (Dots per inch) for the output\n"
1318 " bitmap. With the format <XxY>, different\n"
1319 " resolutions for X- and Y-direction are used.\n"
1320 " With the format <R>, both are the same.\n"));
1323 " -D<XxY|R> Resolution (Dots per inch) for the output\n"
1324 " bitmap. With the format <XxY>, different\n"
1325 " resolutions for X- and Y-direction are used.\n"
1326 " With the format <R>, both are the same.\n"));
1329 #ifdef HAVE_GETOPT_LONG
1331 " -O, --origin=<XxY|X;Y> Use the specified coordinates (in inches)\n"
1332 " for the lower left corner.\n"));
1335 " -O<XxY|X;Y> Use the specified coordinates (in inches)\n"
1336 " for the lower left corner.\n"));
1339 #ifdef HAVE_GETOPT_LONG
1341 " -V, --version Print version of Gerbv.\n"));
1344 " -V Print version of Gerbv.\n"));
1347 #ifdef HAVE_GETOPT_LONG
1349 " -a, --antialias Use antialiasing for generated bitmap output.\n"));
1352 " -a Use antialiasing for generated bitmap output.\n"));
1355 #ifdef HAVE_GETOPT_LONG
1357 " -b, --background=<hex> Use background color <hex> (like #RRGGBB).\n"));
1360 " -b<hexcolor> Use background color <hexcolor> (like #RRGGBB).\n"));
1363 #ifdef HAVE_GETOPT_LONG
1365 " -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB or\n"
1366 " #RRGGBBAA for setting the alpha).\n"
1367 " Use multiple -f flags to set the color for\n"
1368 " multiple layers.\n"));
1371 " -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB or\n"
1372 " #RRGGBBAA for setting the alpha).\n"
1373 " Use multiple -f flags to set the color for\n"
1374 " multiple layers.\n"));
1377 #ifdef HAVE_GETOPT_LONG
1379 " -r, --rotate=<degree> Set initial orientation for all layers.\n"));
1382 " -r<degree> Set initial orientation for all layers.\n"));
1385 #ifdef HAVE_GETOPT_LONG
1387 " -m, --mirror=<axis> Set initial mirroring axis (X or Y).\n"));
1390 " -m<axis> Set initial mirroring axis (X or Y).\n"));
1393 #ifdef HAVE_GETOPT_LONG
1395 " -h, --help Print this help message.\n"));
1398 " -h Print this help message.\n"));
1401 #ifdef HAVE_GETOPT_LONG
1403 " -l, --log=<logfile> Send error messages to <logfile>.\n"));
1406 " -l<logfile> Send error messages to <logfile>.\n"));
1409 #ifdef HAVE_GETOPT_LONG
1411 " -q, --quiet Suppress note-level messages.\n"));
1414 " -q Suppress note-level messages.\n"));
1417 #ifdef HAVE_GETOPT_LONG
1419 " -o, --output=<filename> Export to <filename>.\n"));
1422 " -o<filename> Export to <filename>.\n"));
1425 #ifdef HAVE_GETOPT_LONG
1427 " -p, --project=<prjfile> Load project file <prjfile>.\n"));
1430 " -p<prjfile> Load project file <prjfile>.\n"));
1433 #ifdef HAVE_GETOPT_LONG
1435 " -u, --units=<inch|mm|mil>\n"
1436 " Use given unit for coordinates.\n"
1437 " Default to inch.\n"));
1440 " -u<inch|mm|mil> Use given unit for coordinates.\n"
1441 " Default to inch.\n"));
1444 #ifdef HAVE_GETOPT_LONG
1446 " -W, --window_inch=<WxH> Window size in inches <WxH> for the exported image.\n"));
1449 " -W<WxH> Window size in inches <WxH> for the exported image.\n"));
1452 #ifdef HAVE_GETOPT_LONG
1454 " -w, --window=<WxH> Window size in pixels <WxH> for the exported image.\n"
1455 " Autoscales to fit if no resolution is specified.\n"
1456 " If a resolution is specified, it will clip\n"
1457 " exported image.\n"));
1460 " -w<WxH> Window size in pixels <WxH> for the exported image.\n"
1461 " Autoscales to fit if no resolution is specified.\n"
1462 " If a resolution is specified, it will clip\n"
1463 " exported image.\n"));
1466 #ifdef HAVE_GETOPT_LONG
1468 " -t, --tools=<toolfile> Read Excellon tools from file <toolfile>.\n"));
1471 " -t<toolfile> Read Excellon tools from file <toolfile>\n"));
1474 #ifdef HAVE_GETOPT_LONG
1476 " -T, --translate=<XxYrR| Translate image by X and Y and rotate by R degree.\n"
1477 " X;YrR> Useful for arranging panels.\n"
1478 " Use multiple -T flags for multiple layers.\n"
1479 " Only evaluated when exporting as RS274X or drill.\n"));
1482 " -T<XxYrR|X;YrR> Translate image by X and Y and rotate by R degree.\n"
1483 " Useful for arranging panels.\n"
1484 " Use multiple -T flags for multiple files.\n"
1485 " Only evaluated when exporting as RS274X or drill.\n"));
1488 #ifdef HAVE_GETOPT_LONG
1490 " -x, --export=<png|pdf|ps|svg|rs274x|drill|idrill|dxf>\n"
1491 " Export a rendered picture to a file with\n"
1492 " the specified format.\n"));
1494 " --svg-layers Export visible layers as Inkscape SVG layers.\n"
1495 " Only used with --export=svg.\n"));
1497 " --svg-cairo Use Cairo SVG surface (legacy, larger output).\n"
1498 " Only used with --export=svg.\n"));
1501 " -x<png|pdf|ps|svg| Export a rendered picture to a file with\n"
1502 " rs274x|drill| the specified format.\n"
1506 " --svg-layers Export visible layers as Inkscape SVG layers.\n"
1507 " Only used with -xsvg.\n"));
1509 " --svg-cairo Use Cairo SVG surface (legacy, larger output).\n"
1510 " 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