static void add_connection_point (ShapeRenderer *renderer, Point *point, gboolean design_connection, gboolean main) { xmlNodePtr node; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; /* Use connection points, drop the auto ones */ if(design_connection && !renderer->design_connection) { renderer->design_connection = design_connection; node = renderer->connection_root->parent; xmlUnlinkNode(renderer->connection_root); xmlFree(renderer->connection_root); xmlNewChild(node, NULL, (const xmlChar *)"connections", NULL); } if(!design_connection && renderer->design_connection) return; node = xmlNewChild(renderer->connection_root, NULL, (const xmlChar *)"point", NULL); g_ascii_formatd(buf, sizeof(buf), "%g", point->x); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf), "%g", point->y); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) buf); if (main) { xmlSetProp(node, (const xmlChar *)"main", (xmlChar *)"yes"); } }
static void draw_string(DiaRenderer *self, const char *text, Point *pos, Alignment alignment, Color *colour) { DxfRenderer *renderer = DXF_RENDERER(self); gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; fprintf(renderer->file, " 0\nTEXT\n"); fprintf(renderer->file, " 8\n%s\n", renderer->layername); fprintf(renderer->file, " 6\n%s\n", renderer->lcurrent.style); fprintf(renderer->file, " 10\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", pos->x)); fprintf(renderer->file, " 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (-1)*pos->y)); fprintf(renderer->file, " 40\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", renderer->tcurrent.font_height)); /* Text height */ fprintf(renderer->file, " 50\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", 0.0)); /* Text rotation */ switch(alignment) { case ALIGN_LEFT : fprintf(renderer->file, " 72\n%d\n", 0); break; case ALIGN_RIGHT : fprintf(renderer->file, " 72\n%d\n", 2); break; case ALIGN_CENTER : default: fprintf(renderer->file, " 72\n%d\n", 1); break; } fprintf(renderer->file, " 7\n%s\n", "0"); /* Text style */ fprintf(renderer->file, " 1\n%s\n", text); fprintf(renderer->file, " 39\n%d\n", (int)(MAGIC_THICKNESS_FACTOR*renderer->lcurrent.width)); /* Thickness */ fprintf(renderer->file, " 62\n%d\n", dxf_color(colour)); }
/* complete overwrite, necessary code duplication */ static void draw_polygon(DiaRenderer *self, Point *points, int num_points, Color *line_colour) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); int i; xmlNodePtr node; GString *str; Point center; gchar px_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar py_buf[G_ASCII_DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"polygon", NULL); xmlSetProp(node, (const xmlChar *)"style", (xmlChar *) DIA_SVG_RENDERER_GET_CLASS(renderer)->get_draw_style(renderer, line_colour)); str = g_string_new(NULL); for (i = 0; i < num_points; i++) { g_string_append_printf(str, "%s,%s ", g_ascii_formatd(px_buf, sizeof(px_buf), "%g", points[i].x), g_ascii_formatd(py_buf, sizeof(py_buf), "%g", points[i].y) ); add_connection_point(SHAPE_RENDERER(self), &points[i], FALSE, FALSE); } for(i = 1; i < num_points; i++) { center.x = (points[i].x + points[i-1].x)/2; center.y = (points[i].y + points[i-1].y)/2; add_connection_point(SHAPE_RENDERER(self), ¢er, FALSE, FALSE); } xmlSetProp(node, (const xmlChar *)"points", (xmlChar *) str->str); g_string_free(str, TRUE); }
void hb_strfnum(gchar *outstr, gint outlen, gdouble value, guint32 kcur, gboolean minor) { gchar formatd_buf[outlen]; Currency *cur; gdouble monval; if(minor == FALSE) { cur = hb_strfmon_check(outstr, kcur); if(cur != NULL) { monval = hb_amount_round(value, cur->frac_digits); g_ascii_formatd(formatd_buf, outlen, "%.2f", monval); hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE); } } else { cur = &PREFS->minor_cur; monval = hb_amount_to_euro(value); g_ascii_formatd(formatd_buf, outlen, "%.2f", monval); hb_str_formatd(outstr, outlen, formatd_buf, cur, TRUE); } }
static void draw_arc(DiaRenderer *self, Point *center, real width, real height, real angle1, real angle2, Color *colour) { DxfRenderer *renderer = DXF_RENDERER(self); gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; /* DXF arcs are preferably counter-clockwise, so we might need to swap angles * According to my reading of the specs header section group code 70 might allow * clockwise arcs with $ANGDIR = 1 but it's not supported on the single arc level */ if (angle2 < angle1) { real tmp = angle1; angle1 = angle2; angle2 = tmp; } if(width != 0.0){ fprintf(renderer->file, " 0\nARC\n"); fprintf(renderer->file, " 8\n%s\n", renderer->layername); fprintf(renderer->file, " 6\n%s\n", renderer->lcurrent.style); fprintf(renderer->file, " 10\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", center->x)); fprintf(renderer->file, " 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (-1)*center->y)); fprintf(renderer->file, " 40\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", width/2)); /* radius */ fprintf(renderer->file, " 39\n%d\n", (int)(MAGIC_THICKNESS_FACTOR*renderer->lcurrent.width)); /* Thickness */ /* From specification: "output in degrees to DXF files". */ fprintf(renderer->file, " 100\nAcDbArc\n"); fprintf(renderer->file, " 50\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (angle1 ))); /* start angle */ fprintf(renderer->file, " 51\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (angle2 ))); /* end angle */ } fprintf(renderer->file, " 62\n%d\n", dxf_color (colour)); }
static void draw_polygon (DiaRenderer *self, Point *points, int num_points, Color *fill, Color *stroke) { Color *color = fill ? fill : stroke; DxfRenderer *renderer = DXF_RENDERER(self); /* We could emulate all polygons with multiple SOLID but it might not be * worth the effort. Following the easy part of polygons with 3 or 4 points. */ int idx3[4] = {0, 1, 2, 2}; /* repeating last point is by specification and should not be necessary but it helps limited importers */ int idx4[4] = {0, 1, 3, 2}; /* SOLID point order differs from Dia's */ int *idx; int i; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar buf2[G_ASCII_DTOSTR_BUF_SIZE]; g_return_if_fail (color != NULL); if (num_points == 3) idx = idx3; else if (num_points == 4) idx = idx4; else return; /* dont even try */ fprintf(renderer->file, " 0\nSOLID\n"); fprintf(renderer->file, " 8\n%s\n", renderer->layername); fprintf(renderer->file, " 62\n%d\n", dxf_color (color)); for (i = 0; i < 4; ++i) fprintf(renderer->file, " %d\n%s\n %d\n%s\n", 10+i, g_ascii_formatd (buf, sizeof(buf), "%g", points[idx[i]].x), 20+i, g_ascii_formatd (buf2, sizeof(buf2), "%g", -points[idx[i]].y)); }
static void draw_polyline(DiaRenderer *self, Point *points, int num_points, Color *color) { DxfRenderer *renderer = DXF_RENDERER(self); int i; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar buf2[G_ASCII_DTOSTR_BUF_SIZE]; fprintf(renderer->file, " 0\nPOLYLINE\n"); fprintf(renderer->file, " 6\n%s\n", renderer->lcurrent.style); fprintf(renderer->file, " 8\n%s\n", renderer->layername); /* start and end width are the same */ fprintf(renderer->file, " 41\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", renderer->lcurrent.width)); fprintf(renderer->file, " 42\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", renderer->lcurrent.width)); fprintf(renderer->file, " 62\n%d\n", dxf_color (color)); /* vertices-follow flag */ fprintf(renderer->file, " 66\n1\n"); for (i = 0; i < num_points; ++i) fprintf(renderer->file, " 0\nVERTEX\n 10\n%s\n 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", points[i].x), g_ascii_formatd (buf2, sizeof(buf2), "%g", -points[i].y)); fprintf(renderer->file, " 0\nSEQEND\n"); }
/*! * \brief creation of rectangles with corner radius * \memberof SvgRenderer */ static void draw_rounded_rect (DiaRenderer *self, Point *ul_corner, Point *lr_corner, Color *fill, Color *stroke, real rounding) { DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self); xmlNodePtr node; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->root, NULL, (const xmlChar *)"rect", NULL); xmlSetProp(node, (const xmlChar *)"style", (const xmlChar *)DIA_SVG_RENDERER_GET_CLASS(self)->get_draw_style (renderer, fill, stroke)); g_ascii_formatd(buf, sizeof(buf), "%g", ul_corner->x * renderer->scale); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf), "%g", ul_corner->y * renderer->scale); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf), "%g", (lr_corner->x - ul_corner->x) * renderer->scale); xmlSetProp(node, (const xmlChar *)"width", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf), "%g", (lr_corner->y - ul_corner->y) * renderer->scale); xmlSetProp(node, (const xmlChar *)"height", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf),"%g", (rounding * renderer->scale)); xmlSetProp(node, (const xmlChar *)"rx", (xmlChar *) buf); xmlSetProp(node, (const xmlChar *)"ry", (xmlChar *) buf); }
void draw_bezier_outline(DiaPsRenderer *renderer, int dpi_x, FT_Face face, FT_UInt glyph_index, double pos_x, double pos_y ) { FT_Int load_flags = FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP; FT_Glyph glyph; FT_Error error; gchar px_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar py_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar d1_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar d2_buf[G_ASCII_DTOSTR_BUF_SIZE]; /* Need to transform */ /* Output outline */ FT_Outline_Funcs outlinefunc = { paps_move_to, paps_line_to, paps_conic_to, paps_cubic_to }; OutlineInfo outline_info; outline_info.glyph_origin.x = pos_x; outline_info.glyph_origin.y = pos_y; outline_info.dpi = dpi_x; outline_info.OUT = renderer->file; fprintf(renderer->file, "gsave %s %s translate %s %s scale\n", g_ascii_formatd(px_buf, sizeof(px_buf), "%f", pos_x), g_ascii_formatd(py_buf, sizeof(py_buf), "%f", pos_y), g_ascii_formatd(d1_buf, sizeof(d1_buf), "%f", 2.54/72.0), g_ascii_formatd(d2_buf, sizeof(d2_buf), "%f", -2.54/72.0) ); fprintf(renderer->file, "start_ol\n"); if ((error=FT_Load_Glyph(face, glyph_index, load_flags))) { fprintf(stderr, "Can't load glyph: %d\n", error); return; } if ((error=FT_Get_Glyph (face->glyph, &glyph))) { fprintf(stderr, "Can't get glyph: %d\n", error); FT_Done_Glyph (glyph); return; } if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline), &outlinefunc, &outline_info); fprintf(renderer->file, "end_ol grestore \n"); FT_Done_Glyph (glyph); }
static void draw_ellipse(DiaRenderer *self, Point *center, real width, real height, Color *fill, Color *stroke) { DxfRenderer *renderer = DXF_RENDERER(self); gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; Color *color = fill ? fill : stroke; /* emulate fill by SOLID? */ /* draw a circle instead of an ellipse, if it's one */ if(width == height){ fprintf(renderer->file, " 0\nCIRCLE\n"); fprintf(renderer->file, " 8\n%s\n", renderer->layername); fprintf(renderer->file, " 6\n%s\n", renderer->lcurrent.style); fprintf(renderer->file, " 10\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", center->x)); fprintf(renderer->file, " 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (-1)*center->y)); fprintf(renderer->file, " 40\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", height/2)); fprintf(renderer->file, " 39\n%d\n", (int)(MAGIC_THICKNESS_FACTOR*renderer->lcurrent.width)); /* Thickness */ } else if(height != 0.0){ fprintf(renderer->file, " 0\nELLIPSE\n"); fprintf(renderer->file, " 8\n%s\n", renderer->layername); fprintf(renderer->file, " 6\n%s\n", renderer->lcurrent.style); fprintf(renderer->file, " 10\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", center->x)); fprintf(renderer->file, " 20\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", (-1)*center->y)); fprintf(renderer->file, " 11\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", width/2)); /* Endpoint major axis relative to center X*/ fprintf(renderer->file, " 40\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", height/width)); /*Ratio major/minor axis*/ fprintf(renderer->file, " 39\n%d\n", (int)(MAGIC_THICKNESS_FACTOR*renderer->lcurrent.width)); /* Thickness */ fprintf(renderer->file, " 41\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", 0.0)); /*Start Parameter full ellipse */ fprintf(renderer->file, " 42\n%s\n", g_ascii_formatd (buf, sizeof(buf), "%g", 2.0*3.14)); /* End Parameter full ellipse */ } fprintf(renderer->file, " 62\n%d\n", dxf_color (color)); }
static void _gradient_do (gpointer key, gpointer value, gpointer user_data) { DiaPattern *pattern = (DiaPattern *)value; GradientData *gd = (GradientData *)user_data; DiaSvgRenderer *renderer = gd->renderer; xmlNodePtr parent = gd->node; xmlNodePtr gradient; DiaPatternType pt; guint flags; Point p1, p2; gchar vbuf[DTOSTR_BUF_SIZE]; real scale = renderer->scale; dia_pattern_get_settings (pattern, &pt, &flags); if ((flags & DIA_PATTERN_USER_SPACE)==0) scale = 1.0; dia_pattern_get_points (pattern, &p1, &p2); if (pt == DIA_LINEAR_GRADIENT) { gradient = xmlNewChild (parent, parent->ns, (const xmlChar *)"linearGradient", NULL); xmlSetProp (gradient, (const xmlChar *)"x1", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p1.x * scale)); xmlSetProp (gradient, (const xmlChar *)"y1", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p1.y * scale)); xmlSetProp (gradient, (const xmlChar *)"x2", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p2.x * scale)); xmlSetProp (gradient, (const xmlChar *)"y2", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p2.y * scale)); } else if (pt == DIA_RADIAL_GRADIENT) { real r; dia_pattern_get_radius (pattern, &r); gradient = xmlNewChild (parent, parent->ns, (const xmlChar *)"radialGradient", NULL); xmlSetProp (gradient, (const xmlChar *)"cx", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p1.x * scale)); xmlSetProp (gradient, (const xmlChar *)"cy", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p1.y * scale)); xmlSetProp (gradient, (const xmlChar *)"fx", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p2.x * scale)); xmlSetProp (gradient, (const xmlChar *)"fy", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", p2.y * scale)); xmlSetProp (gradient, (const xmlChar *)"r", (const xmlChar *)g_ascii_formatd(vbuf,sizeof(vbuf),"%g", r * scale)); } else { gradient = xmlNewChild (parent, parent->ns, (const xmlChar *)"pattern", NULL); } /* don't miss to set the id */ { gchar *id = _make_pattern_key (pattern); xmlSetProp (gradient, (const xmlChar *)"id", (const xmlChar *)id); g_free (id); } if (flags & DIA_PATTERN_USER_SPACE) xmlSetProp (gradient, (const xmlChar *)"gradientUnits", (const xmlChar *)"userSpaceOnUse"); if (flags & DIA_PATTERN_EXTEND_REPEAT) xmlSetProp (gradient, (const xmlChar *)"spreadMethod", (const xmlChar *)"repeat"); else if (flags & DIA_PATTERN_EXTEND_REFLECT) xmlSetProp (gradient, (const xmlChar *)"spreadMethod", (const xmlChar *)"reflect"); else if (flags & DIA_PATTERN_EXTEND_PAD) xmlSetProp (gradient, (const xmlChar *)"spreadMethod", (const xmlChar *)"pad"); if (pt == DIA_LINEAR_GRADIENT || pt == DIA_RADIAL_GRADIENT) { dia_pattern_foreach (pattern, _color_stop_do, gradient); } else { g_warning ("SVG pattern data not implemented"); } }
void color_history_save (Gimp *gimp) { GimpConfigWriter *writer; GFile *file; gint i; g_return_if_fail (GIMP_IS_GIMP (gimp)); file = gimp_personal_rc_gfile ("colorrc"); if (gimp->be_verbose) g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file)); writer = gimp_config_writer_new_gfile (file, TRUE, "GIMP colorrc\n\n" "This file holds a list of " "recently used colors.", NULL); g_object_unref (file); if (!writer) return; if (! color_history_initialized) color_history_init (); gimp_config_writer_open (writer, "color-history"); for (i = 0; i < COLOR_HISTORY_SIZE; i++) { gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].r); g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].g); g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].b); g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].a); gimp_config_writer_open (writer, "color-rgba"); gimp_config_writer_printf (writer, "%s %s %s %s", buf[0], buf[1], buf[2], buf[3]); gimp_config_writer_close (writer); } gimp_config_writer_close (writer); gimp_config_writer_finish (writer, "end of colorrc", NULL); }
static void add_connection_point (ShapeRenderer *renderer, Point *point) { xmlNodePtr node; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; node = xmlNewChild(renderer->connection_root, NULL, (const xmlChar *)"point", NULL); g_ascii_formatd(buf, sizeof(buf), "%g", point->x); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) buf); g_ascii_formatd(buf, sizeof(buf), "%g", point->y); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) buf); }
static gchar * _str_point (const Point *point) { gchar *buffer; gchar px_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar py_buf[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd(px_buf, sizeof(px_buf), "%g", point->x); g_ascii_formatd(py_buf, sizeof(py_buf), "%g", point->y); buffer = g_strconcat(px_buf, ",", py_buf, NULL); return buffer; }
static void _string_append_point (GString *str, Point *pt, gboolean first) { gchar value[G_ASCII_DTOSTR_BUF_SIZE]; if (!first) g_string_append (str, " "); g_ascii_formatd (value, sizeof(value), "%g", pt->x); g_string_append (str, value); g_string_append (str, ","); g_ascii_formatd (value, sizeof(value), "%g", pt->y); g_string_append (str, value); }
/* the return value of this function should not be saved anywhere */ static const gchar * get_draw_style(DiaSvgRenderer *renderer, Color *fill, Color *stroke) { static GString *str = NULL; gchar linewidth_buf[DTOSTR_BUF_SIZE]; gchar alpha_buf[DTOSTR_BUF_SIZE]; if (!str) str = g_string_new(NULL); g_string_truncate(str, 0); /* we only append a semicolon with the second attribute */ if (fill) { if (renderer->active_pattern) { gchar *key = _make_pattern_key (renderer->active_pattern); g_string_printf(str, "fill:url(#%s)", key); g_free (key); } else { g_string_printf(str, "fill: #%02x%02x%02x; fill-opacity: %s", (int)(255*fill->red), (int)(255*fill->green), (int)(255*fill->blue), g_ascii_formatd(alpha_buf, sizeof(alpha_buf), "%g", fill->alpha)); } } else { g_string_printf(str, "fill: none"); } if (stroke) { g_string_append_printf(str, "; stroke-opacity: %s; stroke-width: %s", g_ascii_formatd (alpha_buf, sizeof(alpha_buf), "%g", stroke->alpha), dia_svg_dtostr(linewidth_buf, renderer->linewidth) ); if (strcmp(renderer->linecap, "butt")) g_string_append_printf(str, "; stroke-linecap: %s", renderer->linecap); if (strcmp(renderer->linejoin, "miter")) g_string_append_printf(str, "; stroke-linejoin: %s", renderer->linejoin); if (renderer->linestyle) g_string_append_printf(str, "; stroke-dasharray: %s", renderer->linestyle); g_string_append_printf(str, "; stroke: #%02x%02x%02x", (int)(255*stroke->red), (int)(255*stroke->green), (int)(255*stroke->blue)); } else { g_string_append_printf(str, "; stroke: none"); } return str->str; }
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *image_map_tool, gpointer fp) { GimpLevelsTool *tool = GIMP_LEVELS_TOOL (image_map_tool); FILE *file = fp; gint i; fprintf (file, "# GIMP Levels File\n"); for (i = 0; i < 5; i++) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; fprintf (file, "%d %d %d %d %s\n", tool->levels->low_input[i], tool->levels->high_input[i], tool->levels->low_output[i], tool->levels->high_output[i], g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", tool->levels->gamma[i])); } return TRUE; }
extern void SetMovefilterCommands ( const char *sz, movefilter aamfNew[ MAX_FILTER_PLIES ][ MAX_FILTER_PLIES ], movefilter aamfOld[ MAX_FILTER_PLIES ][ MAX_FILTER_PLIES ] ) { int i, j; char *szCmd; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; for ( i = 0; i < MAX_FILTER_PLIES; ++i ) for ( j = 0; j <= i; ++j ) { if (memcmp(&aamfNew[i][j], &aamfOld[i][j], sizeof(movefilter)) != 0) { szCmd = g_strdup_printf ( "%s %d %d %d %d %s", sz, i + 1, j, aamfNew[ i ][ j ].Accept, aamfNew[ i ][ j ].Extra, g_ascii_formatd( buf, G_ASCII_DTOSTR_BUF_SIZE, "%0.3f", (double)aamfNew[ i ][ j ].Threshold )); UserCommand ( szCmd ); g_free ( szCmd ); } } UserCommand("save settings"); }
gboolean gimp_levels_config_save_cruft (GimpLevelsConfig *config, gpointer fp, GError **error) { FILE *file = fp; gint i; g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE); g_return_val_if_fail (file != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); fprintf (file, "# GIMP Levels File\n"); for (i = 0; i < 5; i++) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; fprintf (file, "%d %d %d %d %s\n", (gint) (config->low_input[i] * 255.999), (gint) (config->high_input[i] * 255.999), (gint) (config->low_output[i] * 255.999), (gint) (config->high_output[i] * 255.999), g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", config->gamma[i])); } return TRUE; }
static void add_connection_point (ShapeRenderer *renderer, Point *point, gboolean design_connection, gboolean main) { xmlNodePtr node; xmlChar *propx, *propy; gchar bufx[G_ASCII_DTOSTR_BUF_SIZE], bufy[G_ASCII_DTOSTR_BUF_SIZE]; /* Use connection points, drop the auto ones */ if(design_connection && !renderer->design_connection) { renderer->design_connection = design_connection; node = renderer->connection_root->parent; xmlUnlinkNode(renderer->connection_root); xmlFree(renderer->connection_root); renderer->connection_root = xmlNewChild(node, NULL, (const xmlChar *)"connections", NULL); } if(!design_connection && renderer->design_connection) return; g_ascii_formatd(bufx, sizeof(bufx), "%g", point->x); g_ascii_formatd(bufy, sizeof(bufy), "%g", point->y); /* Remove duplicates */ for (node = renderer->connection_root->children; node; node = node->next) { if ((XML_ELEMENT_NODE == node->type) && xmlStrEqual((const xmlChar *)"point", node->name)) { propx = xmlGetProp(node, (const xmlChar *)"x"); propy = xmlGetProp(node, (const xmlChar *)"y"); if (xmlStrEqual((const xmlChar *)propx, (const xmlChar *)bufx) && xmlStrEqual((const xmlChar *)propy, (const xmlChar *)bufy)) { if(propx) xmlFree(propx); if(propy) xmlFree(propy); return; } if(propx) xmlFree(propx); if(propy) xmlFree(propy); } } node = xmlNewChild(renderer->connection_root, NULL, (const xmlChar *)"point", NULL); xmlSetProp(node, (const xmlChar *)"x", (xmlChar *) bufx); xmlSetProp(node, (const xmlChar *)"y", (xmlChar *) bufy); if (main) { xmlSetProp(node, (const xmlChar *)"main", (xmlChar *)"yes"); } }
static void _matrix_xml_add_val (DataNode data_node, const char* name, real val) { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd(buf, sizeof(buf), "%g", val); xmlSetProp(data_node, (const xmlChar *)name, (xmlChar *)buf); }
static void _node_set_real (xmlNodePtr node, const char *name, real v) { gchar value[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd (value, sizeof(value), "%g", v); xmlSetProp (node, (const xmlChar *)name, (xmlChar *)value); }
static void gwy_gl_material_dump_component(GString *str, const GwyRGBA *rgba) { gchar buffer[G_ASCII_DTOSTR_BUF_SIZE]; /* this is ugly. I hate locales */ g_ascii_formatd(buffer, sizeof(buffer), "%.6g", rgba->r); g_string_append(str, buffer); g_string_append_c(str, ' '); g_ascii_formatd(buffer, sizeof(buffer), "%.6g", rgba->g); g_string_append(str, buffer); g_string_append_c(str, ' '); g_ascii_formatd(buffer, sizeof(buffer), "%.6g", rgba->b); g_string_append(str, buffer); g_string_append_c(str, ' '); g_ascii_formatd(buffer, sizeof(buffer), "%g", rgba->a); g_string_append(str, buffer); g_string_append_c(str, '\n'); }
static gboolean _color_stop_do (real ofs, const Color *col, gpointer user_data) { xmlNodePtr parent = (xmlNodePtr)user_data; xmlNodePtr stop = xmlNewChild (parent, parent->ns, (const xmlChar *)"stop", NULL); gchar vbuf[DTOSTR_BUF_SIZE]; g_ascii_formatd(vbuf,sizeof(vbuf),"%g", ofs); xmlSetProp (stop, (const xmlChar *)"offset", (const xmlChar *)vbuf); g_sprintf (vbuf, "#%02x%02x%02x", (int)(255*col->red), (int)(255*col->green), (int)(255*col->blue)); xmlSetProp (stop, (const xmlChar *)"stop-color", (const xmlChar *)vbuf); g_ascii_formatd(vbuf,sizeof(vbuf),"%g", col->alpha); xmlSetProp (stop, (const xmlChar *)"stop-opacity", (const xmlChar *)vbuf); return TRUE; }
static void gimp_vectors_export_image_size (const GimpImage *image, GString *str) { GimpUnit unit; const gchar *abbrev; gchar wbuf[G_ASCII_DTOSTR_BUF_SIZE]; gchar hbuf[G_ASCII_DTOSTR_BUF_SIZE]; gdouble xres; gdouble yres; gdouble w, h; gimp_image_get_resolution (image, &xres, &yres); w = (gdouble) gimp_image_get_width (image) / xres; h = (gdouble) gimp_image_get_height (image) / yres; /* FIXME: should probably use the display unit here */ unit = gimp_image_get_unit (image); switch (unit) { case GIMP_UNIT_INCH: abbrev = "in"; break; case GIMP_UNIT_MM: abbrev = "mm"; break; case GIMP_UNIT_POINT: abbrev = "pt"; break; case GIMP_UNIT_PICA: abbrev = "pc"; break; default: abbrev = "cm"; unit = GIMP_UNIT_MM; w /= 10.0; h /= 10.0; break; } g_ascii_formatd (wbuf, sizeof (wbuf), "%g", w * _gimp_unit_get_factor (image->gimp, unit)); g_ascii_formatd (hbuf, sizeof (hbuf), "%g", h * _gimp_unit_get_factor (image->gimp, unit)); g_string_append_printf (str, "width=\"%s%s\" height=\"%s%s\"", wbuf, abbrev, hbuf, abbrev); }
static void test_number (gdouble num, gchar *fmt, gchar *str) { int l; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; for (l = 0; l < G_N_ELEMENTS (locales); l++) { g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num); g_assert (strcmp (buf, str) == 0); } }
/** * lgl_xml_set_prop_double: * @node: the libxml2 #xmlNodePtr of the node * @property: the property name * @val: the value to set * * Set a property from a double. * */ void lgl_xml_set_prop_double (xmlNodePtr node, const gchar *property, gdouble val) { gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; /* Guarantee "C" locale by use of g_ascii_formatd */ string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); }
void swfdec_system_query (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval) { SwfdecPlayer *player = SWFDEC_PLAYER (cx); SwfdecAsValue val; guint i; GString *server; if (object == NULL) { SWFDEC_WARNING ("no this object in Query()"); return; } server = g_string_new (""); for (i = 0; i < G_N_ELEMENTS (queries); i++) { queries[i].get (player, &val); swfdec_as_object_set_variable (object, queries[i].name, &val); if (queries[i].name == SWFDEC_AS_STR_screenResolutionY) { g_string_append_printf (server, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (val)); } else if (queries[i].name == SWFDEC_AS_STR_pixelAspectRatio) { char buffer[10]; g_ascii_formatd (buffer, sizeof (buffer), "%.1f", SWFDEC_AS_VALUE_GET_NUMBER (val)); g_string_append (server, "&AR="); g_string_append (server, buffer); } else if (queries[i].name == SWFDEC_AS_STR_manufacturer) { char *s = swfdec_as_string_escape (cx, player->priv->system->server_manufacturer); g_string_append_printf (server, "&M=%s", s); g_free (s); } else { g_assert (queries[i].server_string); if (i > 0) g_string_append_c (server, '&'); g_string_append (server, queries[i].server_string); g_string_append_c (server, '='); if (SWFDEC_AS_VALUE_IS_BOOLEAN (val)) { g_string_append_c (server, SWFDEC_AS_VALUE_GET_BOOLEAN (val) ? 't' : 'f'); } else if (SWFDEC_AS_VALUE_IS_NUMBER (val)) { g_string_append_printf (server, "%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (val)); } else if (SWFDEC_AS_VALUE_IS_STRING (val)) { char *s = swfdec_as_string_escape (cx, SWFDEC_AS_VALUE_GET_STRING (val)); g_string_append (server, s); g_free (s); } else { g_assert_not_reached (); } } } SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_string_free (server, FALSE))); swfdec_as_object_set_variable (object, SWFDEC_AS_STR_serverString, &val); }
/* request geotagged wikipedia entries for current map view */ void maep_geonames_entry_request(coord_t *pt1, coord_t *pt2, MaepGeonamesRequestCallback cb, gpointer obj) { request_cb_t *context; /* create ascii (dot decimal point) strings */ char str[4][16]; g_ascii_formatd(str[0], sizeof(str[0]), "%.07f", rad2deg(pt1->rlat)); g_ascii_formatd(str[1], sizeof(str[1]), "%.07f", rad2deg(pt2->rlat)); g_ascii_formatd(str[2], sizeof(str[2]), "%.07f", rad2deg(pt1->rlon)); g_ascii_formatd(str[3], sizeof(str[3]), "%.07f", rad2deg(pt2->rlon)); gchar *locale, lang[3] = { 0,0,0 }; gchar *lang_avail[] = {"de", "en", "es", "fr", "it", "nl", "pl", "pt", "ru", "zh", NULL}; int i; locale = setlocale (LC_MESSAGES, NULL); g_utf8_strncpy (lang, locale, 2); /* currently only "de" and "en" are supported by geonames.org */ /* force to "en" in any other case */ g_message("Look for entries in %s", lang); for (i = 0; lang_avail[i] && strcasecmp(lang, lang_avail[i]); i++); if (!lang_avail[i]) strncpy(lang, "en", 2); /* build complete url for request */ char *url = g_strdup_printf( GEONAMES "wikipediaBoundingBox?" "north=%s&south=%s&west=%s&east=%s&lang=%s&maxRows=%u&username="******"start asynchronous geonames download."); context = g_malloc0(sizeof(request_cb_t)); context->cb = cb; context->obj = obj; net_io_download_async(url, geonames_request_cb, context); g_free(url); }
/** Add rectangle data to an attribute node. * @param attr The attribute node. * @param rect The value to set. */ void data_add_rectangle(AttributeNode attr, const Rectangle *rect) { DataNode data_node; gchar *buffer; gchar rl_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar rr_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar rt_buf[G_ASCII_DTOSTR_BUF_SIZE]; gchar rb_buf[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd(rl_buf, sizeof(rl_buf), "%g", rect->left); g_ascii_formatd(rr_buf, sizeof(rr_buf), "%g", rect->right); g_ascii_formatd(rt_buf, sizeof(rt_buf), "%g", rect->top); g_ascii_formatd(rb_buf, sizeof(rb_buf), "%g", rect->bottom); buffer = g_strconcat(rl_buf, ",", rt_buf, ";", rr_buf, ",", rb_buf, NULL); data_node = xmlNewChild(attr, NULL, (const xmlChar *)"rectangle", NULL); xmlSetProp(data_node, (const xmlChar *)"val", (xmlChar *)buffer); g_free(buffer); }