static gboolean export_render_eps(DiaPsRenderer *renderer, DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { FILE *outfile; outfile = g_fopen(filename, "w"); if (outfile == NULL) { dia_context_add_message_with_errno (ctx, errno, _("Can't open output file %s"), dia_context_get_filename(ctx)); return FALSE; } renderer->file = outfile; renderer->scale = 28.346 * data->paper.scaling; renderer->extent = data->extents; renderer->pstype = (guint)user_data; if (renderer->pstype & PSTYPE_EPSI) { /* Must store the diagram for making a preview */ renderer->diagram = data; } if (renderer->file) { renderer->title = g_strdup (diafilename); data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL); } fclose(outfile); return TRUE; }
gboolean PyDia_export_data(DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { DiaPyRenderer *renderer; { FILE *file; file = g_fopen(filename, "w"); /* "wb" for binary! */ if (file == NULL) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't open '%s' for writing.\n"), dia_context_get_filename(ctx)); return FALSE; } else fclose (file); } renderer = g_object_new (DIA_TYPE_PY_RENDERER, NULL); renderer->filename = g_strdup (filename); renderer->diagram_data = PyDiaDiagramData_New(data); /* The Python Renderer object was created at PyDia_Register */ renderer->self = (PyObject*)user_data; /* this will call the required callback functions above */ data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL); g_object_unref(renderer); return TRUE; }
static int fig_read_n_points(FILE *file, int n, Point **points, DiaContext *ctx) { int i; GArray *points_list = g_array_sized_new(FALSE, FALSE, sizeof(Point), n); for (i = 0; i < n; i++) { int x,y; Point p; if (fscanf(file, " %d %d ", &x, &y) != 2) { dia_context_add_message_with_errno (ctx, errno, _("Error while reading %dth of %d points"), i, n); g_array_free(points_list, TRUE); return FALSE; } p.x = x/FIG_UNIT; p.y = y/FIG_UNIT; g_array_append_val(points_list, p); } if (fscanf(file, "\n") == EOF) dia_context_add_message (ctx, _("Unexpected end of file.")); *points = (Point *)points_list->data; g_array_free(points_list, FALSE); return TRUE; }
/* dia export funtion */ static gboolean export_data(DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { WpgRenderer *renderer; FILE *file; Rectangle *extent; real width, height; file = g_fopen(filename, "wb"); /* "wb" for binary! */ if (file == NULL) { dia_context_add_message_with_errno (ctx, errno, _("Can't open output file %s"), dia_context_get_filename(ctx)); return FALSE; } renderer = g_object_new (WPG_TYPE_RENDERER, NULL); renderer->file = file; renderer->ctx = ctx; extent = &data->extents; /* use extents */ DIAG_NOTE(g_message("export_data extents %f,%f -> %f,%f", extent->left, extent->top, extent->right, extent->bottom)); width = extent->right - extent->left; height = extent->bottom - extent->top; #if 0 /* extend to use full range */ renderer->Scale = 0.001; if (width > height) while (renderer->Scale * width < 3276.7) renderer->Scale *= 10.0; else while (renderer->Scale * height < 3276.7) renderer->Scale *= 10.0; #else /* scale from Dia's cm to WPU (1/1200 inch) */ renderer->Scale = WPU_PER_DCM; /* avoid int16 overflow */ if (width > height) while (renderer->Scale * width > 32767) renderer->Scale /= 10.0; else while (renderer->Scale * height > 32767) renderer->Scale /= 10.0; renderer->XOffset = - extent->left; renderer->YOffset = extent->bottom; #endif renderer->Box.Width = width * renderer->Scale; renderer->Box.Height = height * renderer->Scale; renderer->Box.Flag = 0; renderer->Box.Version = 0; data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL); g_object_unref(renderer); return TRUE; }
static void end_render(DiaRenderer *self) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HENHMETAFILE hEmf; W32::UINT nSize; W32::BYTE* pData = NULL; FILE* f; DIAG_NOTE(renderer, "end_render\n"); hEmf = W32::CloseEnhMetaFile(renderer->hFileDC); #if !defined DIRECT_WMF && defined G_OS_WIN32 /* the later offers both */ /* Don't do it when printing */ if (renderer->sFileName && strlen (renderer->sFileName)) { W32::HDC hdc = W32::GetDC(NULL); f = g_fopen(renderer->sFileName, "wb"); if (renderer->target_emf) { nSize = W32::GetEnhMetaFileBits (hEmf, 0, NULL); pData = g_new(W32::BYTE, nSize); nSize = W32::GetEnhMetaFileBits (hEmf, nSize, pData); } else { /* write the placeable header */ fwrite(&renderer->pmh, 1, 22 /* NOT: sizeof(PLACEABLEMETAHEADER) */, f); /* get size */ nSize = W32::GetWinMetaFileBits(hEmf, 0, NULL, MM_ANISOTROPIC, hdc); pData = g_new(W32::BYTE, nSize); /* get data */ nSize = W32::GetWinMetaFileBits(hEmf, nSize, pData, MM_ANISOTROPIC, hdc); } /* write file */ if (fwrite(pData,1,nSize,f) != nSize) dia_context_add_message_with_errno(renderer->ctx, errno, _("Couldn't write file %s\n%s"), dia_context_get_filename (renderer->ctx)); fclose(f); g_free(pData); W32::ReleaseDC(NULL, hdc); } else { W32::PlayEnhMetaFile (renderer->hPrintDC, hEmf, &renderer->margins); } #endif g_free(renderer->sFileName); if (hEmf) W32::DeleteEnhMetaFile(hEmf); if (renderer->hFont) W32::DeleteObject(renderer->hFont); if (renderer->pango_context) g_object_unref (renderer->pango_context); }
/* plug-in interface : export function */ static gboolean export_data(DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { HpglRenderer *renderer; FILE *file; Rectangle *extent; real width, height; file = g_fopen(filename, "w"); /* "wb" for binary! */ if (!file) { dia_context_add_message_with_errno(ctx, errno, _("Can't open output file %s."), dia_context_get_filename(ctx)); return FALSE; } renderer = g_object_new(HPGL_TYPE_RENDERER, NULL); renderer->file = file; extent = &data->extents; /* use extents */ DIAG_NOTE(g_message("export_data extents %f,%f -> %f,%f", extent->left, extent->top, extent->right, extent->bottom)); width = extent->right - extent->left; height = extent->bottom - extent->top; renderer->scale = 0.001; if (width > height) while (renderer->scale * width < 3276.7) renderer->scale *= 10.0; else while (renderer->scale * height < 3276.7) renderer->scale *= 10.0; renderer->offset = 0.0; /* just to have one */ renderer->size.x = width * renderer->scale; renderer->size.y = height * renderer->scale; #if 0 /* OR: set page size and scale */ fprintf(renderer->file, "PS0;SC%d,%d,%d,%d;\n", hpgl_scale(renderer, extent->left), hpgl_scale(renderer, extent->right), hpgl_scale(renderer, extent->bottom), hpgl_scale(renderer, extent->top)); #endif data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL); g_object_unref(renderer); return TRUE; }
static int fig_read_paper_size(FILE *file, DiagramData *dia, DiaContext *ctx) { char buf[BUFLEN]; int paper; if (!fgets(buf, BUFLEN, file)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading paper size.")); return FALSE; } buf[strlen(buf)-1] = 0; /* Remove trailing newline */ g_strstrip(buf); /* And any other whitespace */ if ((paper = find_paper(buf)) != -1) { get_paper_info(&dia->paper, paper, NULL); return TRUE; } dia_context_add_message(ctx, _("Unknown paper size `%s', using default\n"), buf); return TRUE; }
static DiaObject * fig_read_text(FILE *file, DiaContext *ctx) { GPtrArray *props = NULL; TextProperty *tprop; DiaObject *newobj = NULL; int sub_type; int color; int depth; int pen_style; int font; real font_size; real angle; int font_flags; real height; real length; int x, y; char *text_buf = NULL; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, " %d %d %d %d %d %lf %lf %d %lf %lf %d %d", &sub_type, &color, &depth, &pen_style, &font, &font_size, &angle, &font_flags, &height, &length, &x, &y) != 12) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read text info.")); setlocale(LC_NUMERIC, old_locale); return NULL; } /* Skip one space exactly */ text_buf = fig_read_text_line(file); newobj = create_standard_text(x/FIG_UNIT, y/FIG_UNIT); if (newobj == NULL) goto exit; props = prop_list_from_descs(xfig_text_descs,pdtpp_true); tprop = g_ptr_array_index(props,0); tprop->text_data = g_strdup(text_buf); /*g_free(text_buf); */ tprop->attr.alignment = sub_type; tprop->attr.position.x = x/FIG_UNIT; tprop->attr.position.y = y/FIG_UNIT; if ((font_flags & 4) == 0) { switch (font) { case 0: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 1: tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); break; case 2: tprop->attr.font = dia_font_new_from_legacy_name("Times-Bold"); break; case 3: tprop->attr.font = dia_font_new_from_legacy_name("Times-Italic"); break; case 4: tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); break; case 5: tprop->attr.font = dia_font_new_from_legacy_name("Courier"); break; default: dia_context_add_message(ctx, _("Can't find LaTeX font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } } else { if (font == -1) { /* "Default font" - wazzat? */ tprop->attr.font = dia_font_new_from_legacy_name("Times-Roman"); } else if (font < 0 || font >= num_fig_fonts()) { dia_context_add_message(ctx, _("Can't find Postscript font nr. %d, using sans"), font); tprop->attr.font = dia_font_new_from_legacy_name("Helvetica"); } else { tprop->attr.font = dia_font_new_from_legacy_name(fig_fonts[font]); } } tprop->attr.height = font_size*2.54/72.0; tprop->attr.color = fig_color(color, ctx); newobj->ops->set_props(newobj, props); /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); if (text_buf != NULL) g_free(text_buf); if (props != NULL) prop_list_free(props); return newobj; }
static DiaObject * fig_read_arc(FILE *file, DiaContext *ctx) { int sub_type; int line_style; int thickness; int pen_color; int fill_color; int depth; int pen_style; int area_fill; real style_val; int cap_style; int direction; int forward_arrow, backward_arrow; Arrow *forward_arrow_info = NULL, *backward_arrow_info = NULL; DiaObject *newobj = NULL; real center_x, center_y; int x1, y1; int x2, y2; int x3, y3; char* old_locale; Point p2, pm; real distance; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%d %d %d %d %d %d %d %d %lf %d %d %d %d %lf %lf %d %d %d %d %d %d\n", &sub_type, &line_style, &thickness, &pen_color, &fill_color, &depth, &pen_style, &area_fill, &style_val, &cap_style, &direction, &forward_arrow, &backward_arrow, ¢er_x, ¢er_y, &x1, &y1, &x2, &y2, &x3, &y3) != 21) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read arc info.")); goto exit; } if (forward_arrow == 1) { forward_arrow_info = fig_read_arrow(file, ctx); } if (backward_arrow == 1) { backward_arrow_info = fig_read_arrow(file, ctx); } p2.x = x2/FIG_UNIT; p2.y = y2/FIG_UNIT; pm.x = (x1+x3)/(2*FIG_UNIT); pm.y = (y1+y3)/(2*FIG_UNIT); distance = distance_point_point (&p2, &pm); switch (sub_type) { case 0: case 1: case 2: /* We can't do pie-wedge properly yet */ newobj = create_standard_arc(x1/FIG_UNIT, y1/FIG_UNIT, x3/FIG_UNIT, y3/FIG_UNIT, direction ? distance : -distance, forward_arrow_info, backward_arrow_info); if (newobj == NULL) goto exit; if (sub_type == 2) { /* set new fill property on arc? */ dia_context_add_message(ctx, _("Filled arc treated as unfilled")); } break; default: dia_context_add_message(ctx, _("Unknown polyline arc: %d\n"), sub_type); goto exit; } fig_simple_properties(newobj, line_style, style_val, thickness, pen_color, fill_color, area_fill, ctx); /* Pen style field (not used) */ /* Style_val (size of dots and dashes) in 1/80 inch*/ /* Join style */ /* Cap style */ /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); g_free(forward_arrow_info); g_free(backward_arrow_info); return newobj; }
static DiaObject * fig_read_spline(FILE *file, DiaContext *ctx) { int sub_type; int line_style; int thickness; int pen_color; int fill_color; int depth; int pen_style; int area_fill; real style_val; int cap_style; int forward_arrow, backward_arrow; Arrow *forward_arrow_info = NULL, *backward_arrow_info = NULL; int npoints; Point *points = NULL; GPtrArray *props = g_ptr_array_new(); DiaObject *newobj = NULL; BezPoint *bezpoints; int i; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%d %d %d %d %d %d %d %d %lf %d %d %d %d\n", &sub_type, &line_style, &thickness, &pen_color, &fill_color, &depth, &pen_style, &area_fill, &style_val, &cap_style, &forward_arrow, &backward_arrow, &npoints) != 13) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read spline info.")); goto exit; } if (forward_arrow == 1) { forward_arrow_info = fig_read_arrow(file, ctx); } if (backward_arrow == 1) { backward_arrow_info = fig_read_arrow(file, ctx); } if (!fig_read_n_points(file, npoints, &points, ctx)) { goto exit; } switch (sub_type) { case 0: /* Open approximated spline */ case 1: /* Closed approximated spline */ dia_context_add_message(ctx, _("Cannot convert approximated spline yet.")); goto exit; case 2: /* Open interpolated spline */ case 3: /* Closed interpolated spline */ /* Despite what the Fig description says, interpolated splines now also have the line with spline info from the X-spline */ case 4: /* Open X-spline */ case 5: /* Closed X-spline */ { double f; gboolean interpolated = TRUE; for (i = 0; i < npoints; i++) { if (fscanf(file, " %lf ", &f) != 1) { dia_context_add_message_with_errno(ctx, errno,_("Couldn't read spline info.")); goto exit; } if (f != -1.0 && f != 0.0) { dia_context_add_message(ctx, _("Cannot convert approximated spline yet.")); interpolated = FALSE; } } if (!interpolated) goto exit; /* Matrix-based conversion not ready yet. */ #if 0 if (sub_type%2 == 0) { bezpoints = fig_transform_spline(npoints, points, FALSE, f); newobj = create_standard_bezierline(npoints, bezpoints, forward_arrow_info, backward_arrow_info); } else { points = g_renew(Point, points, npoints+1); points[npoints] = points[0]; npoints++; bezpoints = fig_transform_spline(npoints, points, TRUE, f); newobj = create_standard_beziergon(npoints, bezpoints); } #else if (sub_type%2 == 0) { bezpoints = transform_spline(npoints, points, FALSE); newobj = create_standard_bezierline(npoints, bezpoints, forward_arrow_info, backward_arrow_info); } else { points = g_renew(Point, points, npoints+1); points[npoints] = points[0]; npoints++; bezpoints = transform_spline(npoints, points, TRUE); newobj = create_standard_beziergon(npoints, bezpoints); } #endif } if (newobj == NULL) goto exit; break; default: dia_context_add_message(ctx, _("Unknown spline subtype: %d\n"), sub_type); goto exit; } fig_simple_properties(newobj, line_style, style_val, thickness, pen_color, fill_color, area_fill, ctx); /* Pen style field (not used) */ /* Style_val (size of dots and dashes) in 1/80 inch*/ /* Cap style */ /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); prop_list_free(props); g_free(forward_arrow_info); g_free(backward_arrow_info); g_free(points); return newobj; }
static DiaObject * fig_read_polyline(FILE *file, DiaContext *ctx) { int sub_type; int line_style; int thickness; int pen_color; int fill_color; int depth; int pen_style; int area_fill; real style_val; int join_style; int cap_style; int radius; int forward_arrow, backward_arrow; Arrow *forward_arrow_info = NULL, *backward_arrow_info = NULL; int npoints; Point *points; GPtrArray *props = g_ptr_array_new(); DiaObject *newobj = NULL; int flipped = 0; char *image_file = NULL; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%d %d %d %d %d %d %d %d %lf %d %d %d %d %d %d\n", &sub_type, &line_style, &thickness, &pen_color, &fill_color, &depth, &pen_style, &area_fill, &style_val, &join_style, &cap_style, &radius, &forward_arrow, &backward_arrow, &npoints) != 15) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read polyline info.\n")); goto exit; } if (forward_arrow == 1) { forward_arrow_info = fig_read_arrow(file, ctx); } if (backward_arrow == 1) { backward_arrow_info = fig_read_arrow(file, ctx); } if (sub_type == 5) { /* image has image name before npoints */ /* Despite what the specs say */ if (fscanf(file, " %d", &flipped) != 1) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read flipped bit.")); goto exit; } image_file = fig_read_text_line(file); } if (!fig_read_n_points(file, npoints, &points, ctx)) { goto exit; } switch (sub_type) { case 4: { RealProperty *rprop = (RealProperty *)make_new_prop("corner_radius", PROP_TYPE_REAL,PROP_FLAG_DONT_SAVE); if (radius < 0) { dia_context_add_message(ctx, _("Negative corner radius; negating")); rprop->real_data = -radius/FIG_ALT_UNIT; } else { rprop->real_data = radius/FIG_ALT_UNIT; } g_ptr_array_add(props,rprop); } /* Notice fallthrough */ case 2: /* box */ if (points[0].x > points[2].x) { real tmp = points[0].x; points[0].x = points[2].x; points[2].x = tmp; } if (points[0].y > points[2].y) { real tmp = points[0].y; points[0].y = points[2].y; points[2].y = tmp; } newobj = create_standard_box(points[0].x, points[0].y, points[2].x-points[0].x, points[2].y-points[0].y); if (newobj == NULL) goto exit; newobj->ops->set_props(newobj, props); break; case 5: /* imported-picture bounding-box) */ newobj = create_standard_image(points[0].x, points[0].y, points[2].x-points[0].x, points[2].y-points[0].y, image_file); if (newobj == NULL) goto exit; break; case 1: /* polyline */ newobj = create_standard_polyline(npoints, points, forward_arrow_info, backward_arrow_info); if (newobj == NULL) goto exit; break; case 3: /* polygon */ newobj = create_standard_polygon(npoints, points); if (newobj == NULL) goto exit; break; default: dia_context_add_message(ctx, _("Unknown polyline subtype: %d\n"), sub_type); goto exit; } fig_simple_properties(newobj, line_style, style_val, thickness, pen_color, fill_color, area_fill, ctx); /* Pen style field (not used) */ /* Style_val (size of dots and dashes) in 1/80 inch*/ /* Join style */ /* Cap style */ /* Depth field */ add_at_depth(newobj, depth, ctx); exit: setlocale(LC_NUMERIC, old_locale); prop_list_free(props); g_free(forward_arrow_info); g_free(backward_arrow_info); g_free(image_file); return newobj; }
static DiaObject * fig_read_ellipse(FILE *file, DiaContext *ctx) { int sub_type; int line_style; int thickness; int pen_color; int fill_color; int depth; int pen_style; int area_fill; real style_val; int direction; real angle; int center_x, center_y; int radius_x, radius_y; int start_x, start_y; int end_x, end_y; DiaObject *newobj = NULL; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%d %d %d %d %d %d %d %d %lf %d %lf %d %d %d %d %d %d %d %d\n", &sub_type, &line_style, &thickness, &pen_color, &fill_color, &depth, &pen_style, &area_fill, &style_val, &direction, &angle, ¢er_x, ¢er_y, &radius_x, &radius_y, &start_x, &start_y, &end_x, &end_y) < 19) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read ellipse info.")); setlocale(LC_NUMERIC, old_locale); return NULL; } setlocale(LC_NUMERIC, old_locale); /* Curiously, the sub_type doesn't matter, as all info can be extracted this way */ newobj = create_standard_ellipse((center_x-radius_x)/FIG_UNIT, (center_y-radius_y)/FIG_UNIT, (2*radius_x)/FIG_UNIT, (2*radius_y)/FIG_UNIT); if (newobj == NULL) return NULL; fig_simple_properties(newobj, line_style, style_val, thickness, pen_color, fill_color, area_fill, ctx); /* Pen style field (not used) */ /* Style_val (size of dots and dashes) in 1/80 inch */ /* Direction (not used) */ /* Angle -- can't rotate yet */ /* Depth field */ add_at_depth(newobj, depth, ctx); return newobj; }
/* imports the given fig-file, returns TRUE if successful */ static gboolean import_fig(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data) { FILE *figfile; char buf[BUFLEN]; int figmajor, figminor; int i; for (i = 0; i < FIG_MAX_USER_COLORS; i++) { fig_colors[i] = color_black; } for (i = 0; i < FIG_MAX_DEPTHS; i++) { depths[i] = NULL; } figfile = g_fopen(filename,"r"); if (figfile == NULL) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't open: '%s' for reading.\n"), dia_context_get_filename(ctx)); return FALSE; } /* First check magic bytes */ if (fgets(buf, BUFLEN, figfile) == NULL || sscanf(buf, "#FIG %d.%d\n", &figmajor, &figminor) != 2) { dia_context_add_message_with_errno(ctx, errno, _("Doesn't look like a Fig file")); fclose(figfile); return FALSE; } if (figmajor != 3 || figminor != 2) { dia_context_add_message(ctx, _("This is a Fig version %d.%d file.\n It may not be importable."), figmajor, figminor); } figversion = figmajor*100+figminor; if (!skip_comments(figfile)) { if (!feof(figfile)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { dia_context_add_message(ctx, _("Premature end of Fig file")); } fclose(figfile); return FALSE; } if (!fig_read_meta_data(figfile, dia, ctx)) { fclose(figfile); return FALSE; } compound_stack = NULL; do { if (!skip_comments(figfile)) { if (!feof(figfile)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { break; } } if (! fig_read_object(figfile, ctx)) { fclose(figfile); break; } } while (TRUE); /* Now we can reorder for the depth fields */ for (i = 0; i < FIG_MAX_DEPTHS; i++) { if (depths[i] != NULL) layer_add_objects_first(dia->active_layer, depths[i]); } return TRUE; }
static int fig_read_meta_data(FILE *file, DiagramData *dia, DiaContext *ctx) { if (figversion >= 300) { /* Might exist earlier */ int portrait; if ((portrait = fig_read_line_choice(file, "Portrait", "Landscape", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading paper orientation.")); return FALSE; } dia->paper.is_portrait = portrait; } if (figversion >= 300) { /* Might exist earlier */ int justify; if ((justify = fig_read_line_choice(file, "Center", "Flush Left", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading justification.")); return FALSE; } /* Don't know what to do with this */ } if (figversion >= 300) { /* Might exist earlier */ int units; if ((units = fig_read_line_choice(file, "Metric", "Inches", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading units.")); return FALSE; } /* Don't know what to do with this */ } if (figversion >= 302) { if (!fig_read_paper_size(file, dia, ctx)) return FALSE; } { real mag; char* old_locale; old_locale = setlocale(LC_NUMERIC, "C"); if (fscanf(file, "%lf\n", &mag) != 1) { dia_context_add_message_with_errno(ctx, errno, _("Error reading magnification.")); setlocale(LC_NUMERIC, old_locale); return FALSE; } setlocale(LC_NUMERIC, old_locale); dia->paper.scaling = mag/100; } if (figversion >= 302) { int multiple; if ((multiple = fig_read_line_choice(file, "Single", "Multiple", ctx)) == -1) { dia_context_add_message(ctx, _("Error reading multipage indicator.")); return FALSE; } /* Don't know what to do with this */ } { int transparent; if (fscanf(file, "%d\n", &transparent) != 1) { dia_context_add_message_with_errno(ctx, errno, _("Error reading transparent color.")); return FALSE; } /* Don't know what to do with this */ } if (!skip_comments(file)) { if (!feof(file)) { dia_context_add_message_with_errno(ctx, errno, _("Error reading Fig file.")); } else { dia_context_add_message(ctx, _("Premature end of Fig file\n")); } return FALSE; } { int resolution, coord_system; if (fscanf(file, "%d %d\n", &resolution, &coord_system) != 2) { dia_context_add_message_with_errno(ctx, errno, _("Error reading resolution.")); return FALSE; } /* Don't know what to do with this */ } return TRUE; }
static gboolean fig_read_object(FILE *file, DiaContext *ctx) { int objecttype; DiaObject *item = NULL; if (fscanf(file, "%d ", &objecttype) != 1) { if (!feof(file)) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't identify Fig object.")); } return FALSE; } switch (objecttype) { case -6: { /* End of compound */ if (compound_stack == NULL) { dia_context_add_message(ctx, _("Compound end outside compound\n")); return FALSE; } /* Make group item with these items */ if (g_list_length((GList*)compound_stack->data) > 1) item = create_standard_group((GList*)compound_stack->data); else /* a single item needs no group */ item = (DiaObject *)((GList*)compound_stack->data)->data; compound_stack = g_slist_remove(compound_stack, compound_stack->data); if (compound_stack == NULL) { depths[compound_depth] = g_list_append(depths[compound_depth], item); } break; } case 0: { /* Color pseudo-object. */ int colornumber; int colorvalues; Color color; if (fscanf(file, " %d #%xd", &colornumber, &colorvalues) != 2) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read color\n")); return FALSE; } if (colornumber < 32 || colornumber > FIG_MAX_USER_COLORS) { dia_context_add_message(ctx, _("Color number %d out of range 0..%d. Discarding color.\n"), colornumber, FIG_MAX_USER_COLORS); return FALSE; } color.red = ((colorvalues & 0x00ff0000)>>16) / 255.0; color.green = ((colorvalues & 0x0000ff00)>>8) / 255.0; color.blue = (colorvalues & 0x000000ff) / 255.0; color.alpha = 1.0; fig_colors[colornumber-32] = color; break; } case 1: { /* Ellipse which is a generalization of circle. */ item = fig_read_ellipse(file, ctx); if (item == NULL) { return FALSE; } break; } case 2: /* Polyline which includes polygon and box. */ item = fig_read_polyline(file, ctx); if (item == NULL) { return FALSE; } break; case 3: /* Spline which includes closed/open control/interpolated spline. */ item = fig_read_spline(file, ctx); if (item == NULL) { return FALSE; } break; case 4: /* Text. */ item = fig_read_text(file, ctx); if (item == NULL) { return FALSE; } break; case 5: /* Arc. */ item = fig_read_arc(file, ctx); if (item == NULL) { return FALSE; } break; case 6: {/* Compound object which is composed of one or more objects. */ int dummy; if (fscanf(file, " %d %d %d %d\n", &dummy, &dummy, &dummy, &dummy) != 4) { dia_context_add_message_with_errno(ctx, errno, _("Couldn't read group extent.")); return FALSE; } /* Group extends don't really matter */ if (compound_stack == NULL) compound_depth = FIG_MAX_DEPTHS - 1; compound_stack = g_slist_append(compound_stack, NULL); return TRUE; break; } default: dia_context_add_message(ctx, _("Unknown object type %d\n"), objecttype); return FALSE; break; } if (compound_stack != NULL && item != NULL) { /* We're building a compound */ GList *compound = (GList *)compound_stack->data; compound = g_list_append(compound, item); compound_stack->data = compound; } return TRUE; }
static gboolean export_dxf(DiagramData *data, DiaContext *ctx, const gchar *filename, const gchar *diafilename, void* user_data) { DxfRenderer *renderer; FILE *file; int i; Layer *layer; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar buf2[G_ASCII_DTOSTR_BUF_SIZE]; file = g_fopen(filename, "w"); if (file == NULL) { dia_context_add_message_with_errno (ctx, errno, _("Can't open output file %s"), dia_context_get_filename(ctx)); return FALSE; } renderer = g_object_new(DXF_TYPE_RENDERER, NULL); renderer->file = file; /* drawing limits */ fprintf(file, " 0\nSECTION\n 2\nHEADER\n"); fprintf(file, " 9\n$EXTMIN\n 10\n%s\n 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", data->extents.left), g_ascii_formatd (buf2, sizeof(buf2), "%g", -data->extents.bottom)); fprintf(file, " 9\n$EXTMAX\n 10\n%s\n 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", data->extents.right), g_ascii_formatd (buf2, sizeof(buf2), "%g", -data->extents.top)); fprintf(file, " 0\nENDSEC\n"); /* write layer description */ fprintf(file," 0\nSECTION\n 2\nTABLES\n 0\nTABLE\n"); /* some dummy entry to make it work for more DXF viewers */ fprintf(file," 2\nLAYER\n 70\n255\n"); for (i=0; i<data->layers->len; i++) { layer = (Layer *) g_ptr_array_index(data->layers, i); fprintf(file," 0\nLAYER\n 2\n%s\n",layer->name); if(layer->visible) fprintf(file," 62\n%d\n",i+1); else fprintf(file," 62\n%d\n",(-1)*(i+1)); } fprintf(file, " 0\nENDTAB\n 0\nENDSEC\n"); /* write graphics */ fprintf(file," 0\nSECTION\n 2\nENTITIES\n"); init_attributes(renderer); DIA_RENDERER_GET_CLASS(renderer)->begin_render(DIA_RENDERER(renderer), NULL); for (i=0; i<data->layers->len; i++) { layer = (Layer *) g_ptr_array_index(data->layers, i); renderer->layername = layer->name; layer_render(layer, DIA_RENDERER(renderer), NULL, NULL, data, 0); } DIA_RENDERER_GET_CLASS(renderer)->end_render(DIA_RENDERER(renderer)); g_object_unref(renderer); return TRUE; }