62 printf("%s(): ", __FUNCTION__); \
70 #define NUMBER_OF_DEFAULT_COLORS 18
71 #define NUMBER_OF_DEFAULT_TRANSFORMATIONS 20
73 static void gerbv_print_help(
void);
76 getopt_configured(
int argc,
char*
const argv[],
const char* optstring,
const struct option* longopts,
int* longindex);
77 static int getopt_lengh_unit(
const char* optarg,
double* input_div, gerbv_screen_t* screen);
101 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
102 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
103 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
104 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
105 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
106 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
107 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
108 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
109 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
110 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
111 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
112 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
113 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
114 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
115 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
116 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
117 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
118 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
119 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
120 {0, 0, 1, 1, 0, FALSE, FALSE, FALSE},
123 #ifdef HAVE_GETOPT_LONG
126 const struct option longopts[] = {
128 {
"border", required_argument, NULL,
'B'},
129 {
"dpi", required_argument, NULL,
'D'},
130 {
"version", no_argument, NULL,
'V'},
131 {
"origin", required_argument, NULL,
'O'},
132 {
"window_inch", required_argument, NULL,
'W'},
133 {
"antialias", no_argument, NULL,
'a'},
134 {
"background", required_argument, NULL,
'b'},
135 {
"dump", no_argument, NULL,
'd'},
136 {
"foreground", required_argument, NULL,
'f'},
137 {
"rotate", required_argument, NULL,
'r'},
138 {
"mirror", required_argument, NULL,
'm'},
139 {
"help", no_argument, NULL,
'h'},
140 {
"log", required_argument, NULL,
'l'},
141 {
"output", required_argument, NULL,
'o'},
142 {
"project", required_argument, NULL,
'p'},
143 {
"tools", required_argument, NULL,
't'},
144 {
"translate", required_argument, NULL,
'T'},
145 {
"units", required_argument, NULL,
'u'},
146 {
"window", required_argument, NULL,
'w'},
147 {
"export", required_argument, NULL,
'x'},
148 {
"geometry", required_argument, &longopt_val, 1},
150 {
"gtk-module", required_argument, &longopt_val, 2},
151 {
"g-fatal-warnings", no_argument, &longopt_val, 2},
152 {
"gtk-debug", required_argument, &longopt_val, 2},
153 {
"gtk-no-debug", required_argument, &longopt_val, 2},
154 {
"gdk-debug", required_argument, &longopt_val, 2},
155 {
"gdk-no-debug", required_argument, &longopt_val, 2},
156 {
"display", required_argument, &longopt_val, 2},
157 {
"sync", no_argument, &longopt_val, 2},
158 {
"no-xshm", no_argument, &longopt_val, 2},
159 {
"name", required_argument, &longopt_val, 2},
160 {
"class", required_argument, &longopt_val, 2},
164 const char* opt_options =
"VadhB:D:O:W:b:f:r:m:l:o:p:t:T:u:w:x:";
170 gerbv_screen_t screen;
172 gboolean logToFileOption;
173 gchar* logToFileFilename;
178 care_for_x_in_cords(
char*
string) {
180 found = strchr(
string,
'x');
182 found = strchr(
string,
'X');
189 main_open_project_from_filename(
gerbv_project_t* gerbvProject, gchar* filename) {
190 project_list_t * list, *plist;
191 gint i, max_layer_num = -1;
194 dprintf(
"Opening project = %s\n", (gchar*)filename);
198 GERB_COMPILE_WARNING(_(
"Could not read \"%s\" (loaded %d)"), (gchar*)filename, gerbvProject->
last_loaded);
206 if (plist->layerno > max_layer_num)
207 max_layer_num = plist->layerno;
214 for (i = -1; i <= max_layer_num; i++) {
217 if (plist->layerno != i) {
222 GdkColor colorTemplate = { 0, plist->rgb[0], plist->rgb[1], plist->rgb[2] };
224 screen.background_is_from_project = TRUE;
230 gchar* fullName = NULL;
231 gchar* dirName = NULL;
234 if (!g_path_is_absolute(plist->filename)) {
236 dirName = g_path_get_dirname(filename);
237 fullName = g_build_filename(dirName, plist->filename, NULL);
239 fullName = g_strdup(plist->filename);
242 if (gerbv_open_image(gerbvProject, fullName, fileIndex, FALSE, plist->attr_list, plist->n_attr, TRUE)
244 GERB_MESSAGE(_(
"could not read file: %s"), fullName);
253 file_info = gerbvProject->
file[fileIndex];
254 file_info->
color = colorTemplate;
255 file_info->
alpha = plist->alpha;
270 project_destroy_project_list(list);
277 gerbvProject->
project = g_strdup(filename);
278 if (gerbvProject->
project == NULL)
279 GERB_FATAL_ERROR(
"malloc gerbvProject->project failed in %s()", __FUNCTION__);
284 main_save_project_from_filename(
gerbv_project_t* gerbvProject, gchar* filename) {
285 project_list_t * list, *plist;
286 gchar* dirName = g_path_get_dirname(filename);
290 list = g_new0(project_list_t, 1);
293 list->filename = g_strdup(gerbvProject->
path);
295 list->rgb[1] = gerbvProject->
background.green;
299 for (idx = 0; idx <= gerbvProject->
last_loaded; idx++) {
300 if (gerbvProject->
file[idx]) {
301 plist = g_new0(project_list_t, 1);
303 plist->layerno = idx;
307 if (strncmp(dirName, gerbvProject->
file[idx]->
fullPathname, strlen(dirName)) == 0) {
309 plist->filename = g_strdup(gerbvProject->
file[idx]->
fullPathname + strlen(dirName) + 1);
315 file_info = gerbvProject->
file[idx];
316 plist->rgb[0] = file_info->
color.red;
317 plist->rgb[1] = file_info->
color.green;
318 plist->rgb[2] = file_info->
color.blue;
319 plist->alpha = file_info->
alpha;
333 if (write_project_file(gerbvProject, gerbvProject->
project, list)) {
334 GERB_MESSAGE(_(
"Failed to write project"));
336 project_destroy_project_list(list);
342 main_save_as_project_from_filename(
gerbv_project_t* gerbvProject, gchar* filename) {
351 gerbvProject->
project = g_strdup(filename);
352 if (gerbvProject->
project == NULL)
353 GERB_FATAL_ERROR(
"malloc gerbvProject->project failed in %s()", __FUNCTION__);
354 main_save_project_from_filename(gerbvProject, filename);
357 GArray* log_array_tmp = NULL;
362 callbacks_temporary_handle_log_messages(
363 const gchar* log_domain, GLogLevelFlags log_level,
const gchar* message, gpointer user_data
365 struct log_struct item;
367 item.domain = g_strdup(log_domain);
368 item.level = log_level;
369 item.message = g_strdup(message);
370 g_array_append_val(log_array_tmp, item);
372 g_log_default_handler(log_domain, log_level, message, user_data);
377 wait_console_for_win(
void) {
378 FILE* console = fopen(
"CONOUT$",
"w");
380 fprintf(console, _(
"\n*** Press Enter to continue ***"));
386 attach_console_for_win(
void) {
387 if (((HANDLE)_get_osfhandle(fileno(stdout)) == INVALID_HANDLE_VALUE
388 || (HANDLE)_get_osfhandle(fileno(stderr)) == INVALID_HANDLE_VALUE)
389 && AttachConsole(ATTACH_PARENT_PROCESS)) {
391 if ((HANDLE)_get_osfhandle(fileno(stdout)) == INVALID_HANDLE_VALUE)
392 freopen(
"CONOUT$",
"w", stdout);
394 if ((HANDLE)_get_osfhandle(fileno(stderr)) == INVALID_HANDLE_VALUE)
395 freopen(
"CONOUT$",
"w", stderr);
397 atexit(wait_console_for_win);
402 attach_console_for_win(
void) {}
407 main(
int argc,
char* argv[]) {
410 int req_width = -1, req_height = -1;
411 #ifdef HAVE_GETOPT_LONG
414 char* project_filename = NULL;
415 gboolean userSuppliedOrigin = FALSE, userSuppliedWindow = FALSE, userSuppliedAntiAlias = FALSE,
416 userSuppliedWindowInPixels = FALSE, userSuppliedDpi = FALSE;
417 gint layerctr = 0, transformCount = 0;
418 gdouble initial_rotation = 0.0;
419 gdouble input_divisor = 1.0;
420 int unit_flag_counter;
421 gboolean initial_mirror_x = FALSE;
422 gboolean initial_mirror_y = FALSE;
423 const gchar* exportFilename = NULL;
424 gfloat userSuppliedOriginX = 0.0, userSuppliedOriginY = 0.0, userSuppliedDpiX = 72.0, userSuppliedDpiY = 72.0,
425 userSuppliedWidth = 0, userSuppliedHeight = 0, userSuppliedBorder = GERBV_DEFAULT_BORDER_COEFF;
439 enum exp_type exportType = EXP_TYPE_NONE;
440 const char* export_type_names[] = {
"png",
"pdf",
"svg",
"ps",
"rs274x",
"drill",
"idrill", NULL };
441 const gchar* export_def_file_names[] = {
"output.png",
"output.pdf",
"output.svg",
"output.ps",
442 "output.gbx",
"output.cnc",
"output.ncp", NULL };
444 const gchar* settings_schema_env =
"GSETTINGS_SCHEMA_DIR";
447 const gchar* settings_schema_fallback_dir =
448 "share/glib-2.0/schemas" G_SEARCHPATH_SEPARATOR_S
"../share/glib-2.0/schemas";
450 const gchar* settings_schema_fallback_dir =
"../share/glib-2.0/schemas";
455 setlocale(LC_ALL,
"");
456 bindtextdomain(PACKAGE, LOCALEDIR);
458 bind_textdomain_codeset(PACKAGE,
"UTF-8");
463 attach_console_for_win();
469 memset((
void*)&screen, 0,
sizeof(gerbv_screen_t));
470 screen.state = NORMAL;
471 screen.unit = GERBV_DEFAULT_UNIT;
479 if (NULL == g_getenv(settings_schema_env))
481 env_val = g_strconcat(
mainProject->
execpath, G_DIR_SEPARATOR_S, settings_schema_fallback_dir, NULL);
484 env_val = g_strconcat(
485 g_getenv(settings_schema_env), G_SEARCHPATH_SEPARATOR_S,
mainProject->
execpath, G_DIR_SEPARATOR_S,
486 settings_schema_fallback_dir, NULL
488 g_setenv(settings_schema_env, env_val, TRUE);
499 logToFileOption = FALSE;
500 logToFileFilename = NULL;
502 log_array_tmp = g_array_new(TRUE, FALSE,
sizeof(
struct log_struct));
504 NULL, G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK, callbacks_temporary_handle_log_messages, NULL
508 unit_flag_counter = 0;
510 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options, longopts, &longopt_idx))) {
515 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
516 GERB_COMPILE_WARNING(_(
"Unrecognized length unit \"%s\" in command line"), optarg);
525 while (-1 != (read_opt = getopt_configured(argc, argv, opt_options, longopts, &longopt_idx))) {
527 #ifdef HAVE_GETOPT_LONG
530 switch (longopt_val) {
532 GERB_COMPILE_WARNING(
533 _(
"Not handled option \"%s\" in command line"), longopts[longopt_idx].name
538 req_width = (int)strtol(optarg, &rest, 10);
543 if (rest[0] !=
'x') {
544 fprintf(stderr, _(
"Split X and Y parameters with an x\n"));
549 req_height = (int)strtol(rest, &rest, 10);
578 if (optarg == NULL) {
579 fprintf(stderr, _(
"You must specify the border in the format <alpha>.\n"));
582 if (strlen(optarg) > 10) {
583 fprintf(stderr, _(
"Specified border is not recognized.\n"));
586 sscanf(optarg,
"%f", &userSuppliedBorder);
587 if (userSuppliedBorder < 0) {
588 fprintf(stderr, _(
"Specified border is smaller than zero!\n"));
591 userSuppliedBorder /= 100.0;
594 if (optarg == NULL) {
595 fprintf(stderr, _(
"You must give an resolution in the format <DPI_XxDPI_Y> or <DPI_X_and_Y>.\n"));
598 if (strlen(optarg) > 20) {
599 fprintf(stderr, _(
"Specified resolution is not recognized.\n"));
602 if (strchr(optarg,
'x') != NULL) {
603 sscanf(optarg,
"%fx%f", &userSuppliedDpiX, &userSuppliedDpiY);
605 sscanf(optarg,
"%f", &userSuppliedDpiX);
606 userSuppliedDpiY = userSuppliedDpiX;
608 if ((userSuppliedDpiX <= 0) || (userSuppliedDpiY <= 0)) {
609 fprintf(stderr, _(
"Specified resolution should be greater than 0.\n"));
612 userSuppliedDpi = TRUE;
615 if (optarg == NULL) {
617 stderr, _(
"You must give an origin in the format "
622 if (strlen(optarg) > 20) {
623 fprintf(stderr, _(
"Specified origin is not recognized.\n"));
627 care_for_x_in_cords(optarg);
628 sscanf(optarg,
"%f;%f", &userSuppliedOriginX, &userSuppliedOriginY);
629 userSuppliedOriginX /= input_divisor;
630 userSuppliedOriginY /= input_divisor;
631 userSuppliedOrigin = TRUE;
634 printf(_(
"gerbv version %s\n"), VERSION);
636 _(
"Copyright (C) 2001-2008 by Stefan Petersen\n"
637 "and the respective original authors listed in the source files.\n")
640 case 'a': userSuppliedAntiAlias = TRUE;
break;
642 if (optarg == NULL) {
644 stderr, _(
"You must give an background color "
645 "in the hex-format <#RRGGBB>.\n")
649 if ((strlen(optarg) != 7) || (optarg[0] !=
'#')) {
651 stderr, _(
"Specified color format "
652 "is not recognized.\n")
657 sscanf(optarg,
"#%2x%2x%2x", &r, &g, &b);
658 if ((r < 0) || (r > 255) || (g < 0) || (g > 255) || (b < 0) || (b > 255)) {
661 stderr, _(
"Specified color values should be "
662 "between 00 and FF.\n")
667 screen.background_is_from_cmdline = TRUE;
674 if (optarg == NULL) {
676 stderr, _(
"You must give an foreground color in the hex-format <#RRGGBB> or <#RRGGBBAA>.\n")
680 if (((strlen(optarg) != 7) && (strlen(optarg) != 9)) || (optarg[0] !=
'#')) {
681 fprintf(stderr, _(
"Specified color format is not recognized.\n"));
685 if (strlen(optarg) == 7) {
686 sscanf(optarg,
"#%2x%2x%2x", &r, &g, &b);
689 sscanf(optarg,
"#%2x%2x%2x%2x", &r, &g, &b, &a);
692 if ((r < 0) || (r > 255) || (g < 0) || (g > 255) || (b < 0) || (b > 255) || (a < 0) || (a > 255)) {
694 fprintf(stderr, _(
"Specified color values should be between 0x00 (0) and 0xFF (255).\n"));
697 mainDefaultColors[layerctr].red = r;
698 mainDefaultColors[layerctr].green = g;
699 mainDefaultColors[layerctr].blue = b;
700 mainDefaultColors[layerctr].alpha = a;
703 if (layerctr == NUMBER_OF_DEFAULT_COLORS)
707 if (optarg == NULL) {
708 fprintf(stderr, _(
"You must give the initial rotation angle\n"));
712 initial_rotation = (gdouble)strtod(optarg, &rest);
718 fprintf(stderr, _(
"Failed parsing rotate value\n"));
723 if (optarg == NULL) {
724 fprintf(stderr, _(
"You must give the axis to mirror about\n"));
727 if (strchr(optarg,
'x') != NULL || strchr(optarg,
'X') != NULL) {
728 initial_mirror_x = TRUE;
730 if (strchr(optarg,
'y') != NULL || strchr(optarg,
'Y') != NULL) {
731 initial_mirror_y = TRUE;
733 if (!(initial_mirror_x || initial_mirror_y)) {
734 fprintf(stderr, _(
"Failed parsing mirror axis\n"));
739 if (optarg == NULL) {
740 fprintf(stderr, _(
"You must give a filename to send log to\n"));
743 logToFileOption = TRUE;
744 logToFileFilename = optarg;
747 if (optarg == NULL) {
748 fprintf(stderr, _(
"You must give a filename to export to.\n"));
751 exportFilename = optarg;
754 if (optarg == NULL) {
755 fprintf(stderr, _(
"You must give a project filename\n"));
758 project_filename = optarg;
761 if (optarg == NULL) {
762 fprintf(stderr, _(
"You must give a filename to read the tools from.\n"));
765 if (!gerbv_process_tools_file(optarg)) {
766 fprintf(stderr, _(
"*** ERROR processing tools file \"%s\".\n"), optarg);
768 stderr, _(
"Make sure all lines of the file are formatted like this:\n"
769 "T01 0.024\nT02 0.032\nT03 0.040\n...\n"
770 "*** EXITING to prevent erroneous display.\n")
776 if (optarg == NULL) {
778 stderr, _(
"You must give a translation in the format "
783 if (strlen(optarg) > 30) {
784 fprintf(stderr, _(
"The translation format is not recognized.\n"));
788 float transX = 0, transY = 0, rotate = 0;
790 care_for_x_in_cords(optarg);
791 sscanf(optarg,
"%f;%fr%f", &transX, &transY, &rotate);
792 transX /= input_divisor;
793 transY /= input_divisor;
794 mainDefaultTransformations[transformCount].
translateX = transX;
795 mainDefaultTransformations[transformCount].
translateY = transY;
796 mainDefaultTransformations[transformCount].
rotation = DEG2RAD(rotate);
799 if (transformCount == NUMBER_OF_DEFAULT_TRANSFORMATIONS)
803 if (unit_flag_counter == 1)
808 if (!getopt_lengh_unit(optarg, &input_divisor, &screen))
809 GERB_COMPILE_WARNING(_(
"Unrecognized length unit \"%s\" in command line"), optarg);
813 case 'w': userSuppliedWindowInPixels = TRUE;
815 if (optarg == NULL) {
816 fprintf(stderr, _(
"You must give a window size in the format <width x height>.\n"));
819 if (strlen(optarg) > 20) {
820 fprintf(stderr, _(
"Specified window size is not recognized.\n"));
823 sscanf(optarg,
"%fx%f", &userSuppliedWidth, &userSuppliedHeight);
824 if (((userSuppliedWidth < 0.001) || (userSuppliedHeight < 0.001))
825 || ((userSuppliedWidth > 2000) || (userSuppliedHeight > 2000))) {
826 fprintf(stderr, _(
"Specified window size is out of bounds.\n"));
829 userSuppliedWindow = TRUE;
832 if (optarg == NULL) {
833 fprintf(stderr, _(
"You must supply an export type.\n"));
837 for (i = 0; export_type_names[i] != NULL; i++) {
838 if (strcmp(optarg, export_type_names[i]) == 0) {
844 if (exportType == EXP_TYPE_NONE) {
845 fprintf(stderr, _(
"Unrecognized \"%s\" export type.\n"), optarg);
849 case 'd': screen.dump_parsed_image = 1;
break;
858 GERB_COMPILE_WARNING(_(
"Not handled option '%c' in command line"), read_opt);
865 if (!project_filename &&
866 optind == (argc - 1) &&
868 project_filename = argv[optind];
878 if (project_filename) {
879 dprintf(_(
"Loading project %s...\n"), project_filename);
883 if (!g_path_is_absolute(project_filename)) {
884 gchar* currentDir = g_get_current_dir();
885 gchar* fullName = g_build_filename(currentDir, project_filename, NULL);
886 main_open_project_from_filename(
mainProject, fullName);
891 main_open_project_from_filename(
mainProject, project_filename);
895 gint loadedIndex = 0;
896 for (i = optind; i < argc; i++) {
898 if (!g_path_is_absolute(argv[i])) {
899 gchar* currentDir = g_get_current_dir();
900 gchar* fullName = g_build_filename(currentDir, argv[i], NULL);
902 mainProject, fullName, mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red * 257,
903 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green * 257,
904 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue * 257,
905 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha * 257
912 mainProject, argv[i], mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].red * 257,
913 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].green * 257,
914 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].blue * 257,
915 mainDefaultColors[loadedIndex % NUMBER_OF_DEFAULT_COLORS].alpha * 257
923 if (initial_rotation != 0.0) {
926 gdouble initial_radians = DEG2RAD(initial_rotation);
928 dprintf(
"Rotating all layers by %.0f degrees\n", (
float)initial_rotation);
935 if (initial_mirror_x || initial_mirror_y) {
938 if (initial_mirror_x) {
939 dprintf(
"Mirroring all layers about x axis\n");
941 if (initial_mirror_y) {
942 dprintf(
"Mirroring all layers about y axis\n");
953 if (exportType != EXP_TYPE_NONE) {
957 exportFilename = export_def_file_names[exportType];
962 if (!userSuppliedOrigin) {
963 userSuppliedOriginX = bb.
left;
964 userSuppliedOriginY = bb.
top;
967 float width = bb.
right - userSuppliedOriginX + 0.001;
968 float height = bb.
bottom - userSuppliedOriginY + 0.001;
970 if (!userSuppliedWindow) {
971 userSuppliedWidth = width;
972 userSuppliedHeight = height;
975 if ((!userSuppliedDpi) && userSuppliedWindowInPixels) {
976 userSuppliedDpiX = MIN((userSuppliedWidth - 0.5) / width, (userSuppliedHeight - 0.5) / height);
977 userSuppliedDpiY = userSuppliedDpiX;
978 userSuppliedOriginX -= 0.5 / userSuppliedDpiX;
979 userSuppliedOriginY -= 0.5 / userSuppliedDpiY;
984 if (userSuppliedBorder != 0) {
986 if (!userSuppliedWindowInPixels) {
987 userSuppliedOriginX -= (userSuppliedWidth * userSuppliedBorder) / 2.0;
988 userSuppliedOriginY -= (userSuppliedHeight * userSuppliedBorder) / 2.0;
989 userSuppliedWidth += userSuppliedWidth * userSuppliedBorder;
990 userSuppliedHeight += userSuppliedHeight * userSuppliedBorder;
994 userSuppliedOriginX -= ((userSuppliedWidth / userSuppliedDpiX) * userSuppliedBorder) / 2.0;
995 userSuppliedOriginY -= ((userSuppliedHeight / userSuppliedDpiX) * userSuppliedBorder) / 2.0;
996 userSuppliedDpiX -= (userSuppliedDpiX * userSuppliedBorder);
997 userSuppliedDpiY -= (userSuppliedDpiY * userSuppliedBorder);
1001 if (!userSuppliedWindowInPixels) {
1002 userSuppliedWidth *= userSuppliedDpiX;
1003 userSuppliedHeight *= userSuppliedDpiY;
1008 if (userSuppliedWidth <= 0)
1009 userSuppliedWidth = 1;
1010 if (userSuppliedHeight <= 0)
1011 userSuppliedHeight = 1;
1015 userSuppliedOriginX,
1016 userSuppliedOriginY,
1020 userSuppliedHeight };
1022 switch (exportType) {
1029 case EXP_TYPE_RS274X:
1030 case EXP_TYPE_DRILL:
1031 case EXP_TYPE_IDRILL:
1033 fprintf(stderr, _(
"A valid file was not loaded.\n"));
1047 switch (exportType) {
1048 case EXP_TYPE_RS274X:
1053 case EXP_TYPE_DRILL:
1058 case EXP_TYPE_IDRILL:
1068 default: fprintf(stderr, _(
"A valid file was not loaded.\n")); exit(1);
1074 gtk_init(&argc, &argv);
1075 interface_create_gui(req_width, req_height);
1078 render_free_screen_resources();
1084 getopt_configured(
int argc,
char*
const argv[],
const char* optstring,
const struct option* longopts,
int* longindex) {
1085 #ifdef HAVE_GETOPT_LONG
1086 return getopt_long(argc, argv, optstring, longopts, longindex);
1088 return getopt(argc, argv, optstring);
1093 getopt_lengh_unit(
const char* optarg,
double* input_div, gerbv_screen_t* screen) {
1094 if (strncasecmp(optarg,
"mm", 2) == 0) {
1096 screen->unit = GERBV_MMS;
1097 screen->unit_is_from_cmdline = TRUE;
1098 }
else if (strncasecmp(optarg,
"mil", 3) == 0) {
1099 *input_div = 1000.0;
1100 screen->unit = GERBV_MILS;
1101 screen->unit_is_from_cmdline = TRUE;
1102 }
else if (strncasecmp(optarg,
"inch", 4) == 0) {
1104 screen->unit = GERBV_INS;
1105 screen->unit_is_from_cmdline = TRUE;
1114 gerbv_print_help(
void) {
1116 _(
"Usage: gerbv [OPTIONS...] [FILE...]\n"
1118 "Available options:\n")
1121 #ifdef HAVE_GETOPT_LONG
1123 _(
" -B, --border=<b> Border around the image in percent of the\n"
1124 " width/height. Defaults to %d%%.\n"),
1125 (
int)(100 * GERBV_DEFAULT_BORDER_COEFF)
1129 _(
" -B<b> Border around the image in percent of the\n"
1130 " width/height. Defaults to %d%%.\n"),
1131 (
int)(100 * GERBV_DEFAULT_BORDER_COEFF)
1135 #ifdef HAVE_GETOPT_LONG
1137 _(
" -D, --dpi=<XxY|R> Resolution (Dots per inch) for the output\n"
1138 " bitmap. With the format <XxY>, different\n"
1139 " resolutions for X- and Y-direction are used.\n"
1140 " With the format <R>, both are the same.\n")
1144 _(
" -D<XxY|R> Resolution (Dots per inch) for the output\n"
1145 " bitmap. With the format <XxY>, different\n"
1146 " resolutions for X- and Y-direction are used.\n"
1147 " With the format <R>, both are the same.\n")
1151 #ifdef HAVE_GETOPT_LONG
1153 _(
" -O, --origin=<XxY|X;Y> Use the specified coordinates (in inches)\n"
1154 " for the lower left corner.\n")
1158 _(
" -O<XxY|X;Y> Use the specified coordinates (in inches)\n"
1159 " for the lower left corner.\n")
1163 #ifdef HAVE_GETOPT_LONG
1164 printf(_(
" -V, --version Print version of Gerbv.\n"));
1166 printf(_(
" -V Print version of Gerbv.\n"));
1169 #ifdef HAVE_GETOPT_LONG
1170 printf(_(
" -a, --antialias Use antialiasing for generated bitmap output.\n"));
1172 printf(_(
" -a Use antialiasing for generated bitmap output.\n"));
1175 #ifdef HAVE_GETOPT_LONG
1176 printf(_(
" -b, --background=<hex> Use background color <hex> (like #RRGGBB).\n"));
1178 printf(_(
" -b<hexcolor> Use background color <hexcolor> (like #RRGGBB).\n"));
1181 #ifdef HAVE_GETOPT_LONG
1183 _(
" -f, --foreground=<hex> Use foreground color <hex> (like #RRGGBB or\n"
1184 " #RRGGBBAA for setting the alpha).\n"
1185 " Use multiple -f flags to set the color for\n"
1186 " multiple layers.\n")
1190 _(
" -f<hexcolor> Use foreground color <hexcolor> (like #RRGGBB or\n"
1191 " #RRGGBBAA for setting the alpha).\n"
1192 " Use multiple -f flags to set the color for\n"
1193 " multiple layers.\n")
1197 #ifdef HAVE_GETOPT_LONG
1198 printf(_(
" -r, --rotate=<degree> Set initial orientation for all layers.\n"));
1200 printf(_(
" -r<degree> Set initial orientation for all layers.\n"));
1203 #ifdef HAVE_GETOPT_LONG
1204 printf(_(
" -m, --mirror=<axis> Set initial mirroring axis (X or Y).\n"));
1206 printf(_(
" -m<axis> Set initial mirroring axis (X or Y).\n"));
1209 #ifdef HAVE_GETOPT_LONG
1210 printf(_(
" -h, --help Print this help message.\n"));
1212 printf(_(
" -h Print this help message.\n"));
1215 #ifdef HAVE_GETOPT_LONG
1216 printf(_(
" -l, --log=<logfile> Send error messages to <logfile>.\n"));
1218 printf(_(
" -l<logfile> Send error messages to <logfile>.\n"));
1221 #ifdef HAVE_GETOPT_LONG
1222 printf(_(
" -o, --output=<filename> Export to <filename>.\n"));
1224 printf(_(
" -o<filename> Export to <filename>.\n"));
1227 #ifdef HAVE_GETOPT_LONG
1228 printf(_(
" -p, --project=<prjfile> Load project file <prjfile>.\n"));
1230 printf(_(
" -p<prjfile> Load project file <prjfile>.\n"));
1233 #ifdef HAVE_GETOPT_LONG
1235 _(
" -u, --units=<inch|mm|mil>\n"
1236 " Use given unit for coordinates.\n"
1237 " Default to inch.\n")
1241 _(
" -u<inch|mm|mil> Use given unit for coordinates.\n"
1242 " Default to inch.\n")
1246 #ifdef HAVE_GETOPT_LONG
1247 printf(_(
" -W, --window_inch=<WxH> Window size in inches <WxH> for the exported image.\n"));
1249 printf(_(
" -W<WxH> Window size in inches <WxH> for the exported image.\n"));
1252 #ifdef HAVE_GETOPT_LONG
1254 _(
" -w, --window=<WxH> Window size in pixels <WxH> for the exported image.\n"
1255 " Autoscales to fit if no resolution is specified.\n"
1256 " If a resolution is specified, it will clip\n"
1257 " exported image.\n")
1261 _(
" -w<WxH> Window size in pixels <WxH> for the exported image.\n"
1262 " Autoscales to fit if no resolution is specified.\n"
1263 " If a resolution is specified, it will clip\n"
1264 " exported image.\n")
1268 #ifdef HAVE_GETOPT_LONG
1269 printf(_(
" -t, --tools=<toolfile> Read Excellon tools from file <toolfile>.\n"));
1271 printf(_(
" -t<toolfile> Read Excellon tools from file <toolfile>\n"));
1274 #ifdef HAVE_GETOPT_LONG
1276 _(
" -T, --translate=<XxYrR| Translate image by X and Y and rotate by R degree.\n"
1277 " X;YrR> Useful for arranging panels.\n"
1278 " Use multiple -T flags for multiple layers.\n"
1279 " Only evaluated when exporting as RS274X or drill.\n")
1283 _(
" -T<XxYrR|X;YrR> Translate image by X and Y and rotate by R degree.\n"
1284 " Useful for arranging panels.\n"
1285 " Use multiple -T flags for multiple files.\n"
1286 " Only evaluated when exporting as RS274X or drill.\n")
1290 #ifdef HAVE_GETOPT_LONG
1292 _(
" -x, --export=<png|pdf|ps|svg|rs274x|drill|idrill>\n"
1293 " Export a rendered picture to a file with\n"
1294 " the specified format.\n")
1298 _(
" -x<png|pdf|ps|svg| Export a rendered picture to a file with\n"
1299 " rs274x|drill| the specified format.\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.
void gerbv_export_png_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a PNG file using user-specified render info.
void gerbv_export_pdf_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a PDF file using user-specified render info.
void gerbv_export_svg_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a file using user-specified render info.
void gerbv_export_postscript_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a Postscript 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.
void gerbv_destroy_project(gerbv_project_t *gerbvProject)
Free a project and all related variables.
gerbv_project_t * gerbv_create_project(void)
Create a new project structure and initialize some important variables.
void gerbv_open_layer_from_filename_with_color(gerbv_project_t *gerbvProject, const gchar *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...
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(const char *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