static void pkg_graph_2d_paint (PkgGraph2d *graph) { PkgGraph2dPrivate *priv = graph->priv; cairo_t *cr; gfloat w, h; gdouble x0, x1, x2; gdouble y0, y1, y2; gdouble dashes[] = {1., 2.}; gdouble *epochs = NULL; gdouble tmp; gsize n_epochs = 0; gint i; clutter_cairo_texture_clear(CLUTTER_CAIRO_TEXTURE(priv->texture)); clutter_actor_get_size(CLUTTER_ACTOR(graph), &w, &h); /* * Create cairo context and set defaults. */ cr = clutter_cairo_texture_create(CLUTTER_CAIRO_TEXTURE(priv->texture)); cairo_set_line_width(cr, 1.); cairo_set_dash(cr, dashes, 2, 0.); /* * Get coordinates for drawing primary extends. */ pkg_graph_2d_get_primary_extents(graph, &x0, &x1, &x2, &y0, &y1, &y2); /* * Draw the background color. */ cairo_set_source_rgb(cr, 1., 1., 1.); cairo_rectangle(cr, x1, y2, x2 - x1, y1); cairo_fill(cr); /* * Draw the bounding box. */ cairo_set_source_rgb(cr, 0., 0., 0.); cairo_move_to(cr, x0, y2); cairo_line_to(cr, x2, y2); cairo_line_to(cr, x2, y0); cairo_move_to(cr, x0, y1); cairo_line_to(cr, x2, y1); cairo_move_to(cr, x1, y0 - .5); cairo_line_to(cr, x1, y2); cairo_stroke(cr); /* * Draw the x-scale epochs. */ if (pkg_scale_get_epochs(priv->x_scale, &epochs, &n_epochs)) { if (n_epochs > 0) { for (i = 0; i < n_epochs; i++) { if (pkg_scale_translate(priv->x_scale, epochs[i], &tmp)) { PangoFontDescription *font_desc; PangoLayout *layout; gchar *format, *markup; gint pw, ph; /* * Only draw the line if it isn't right near the end of * the visiable region of the graph. */ if (tmp + 5. < floor(w)) { cairo_move_to(cr, tmp, y0 - .5); cairo_line_to(cr, tmp, y2); } /* * Draw the y-scale grid-line value. */ format = pkg_scale_format_string(priv->x_scale, epochs[i]); if (format != NULL) { font_desc = pango_font_description_from_string("Bold Sans 8"); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_desc); markup = g_strdup_printf("<span size=\"smaller\">%s</span>", format); pango_layout_set_markup(layout, markup, -1); pango_layout_get_pixel_size(layout, &pw, &ph); if (i == 0) { cairo_move_to(cr, tmp + 2., y1 + 2.); } else { cairo_move_to(cr, tmp - pw - 2., y1 + 2.); } pango_cairo_show_layout(cr, layout); g_object_unref(layout); pango_font_description_free(font_desc); g_free(format); g_free(markup); } } } cairo_stroke(cr); } } /* * Draw the y-scale epochs. */ if (pkg_scale_get_epochs(priv->y_scale, &epochs, &n_epochs)) { if (n_epochs > 0) { for (i = 0; i < n_epochs; i++) { if (pkg_scale_translate(priv->y_scale, epochs[i], &tmp)) { PangoFontDescription *font_desc; PangoLayout *layout; gchar *format, *markup; gint pw, ph; cairo_move_to(cr, x0, floor(y1 - tmp) + .5); cairo_line_to(cr, x2, floor(y1 - tmp) + .5); /* * Draw the y-scale grid-line value. */ format = pkg_scale_format_string(priv->y_scale, epochs[i]); if (format != NULL) { font_desc = pango_font_description_from_string("Bold Sans 8"); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_desc); markup = g_strdup_printf("<span size=\"smaller\">%s</span>", format); pango_layout_set_markup(layout, markup, -1); pango_layout_get_pixel_size(layout, &pw, &ph); if (i == 0) { cairo_move_to(cr, x1 - pw - 2., y1 - tmp - ph - 2.); } else { cairo_move_to(cr, x1 - pw - 2., y1 - tmp + 2.); } pango_cairo_show_layout(cr, layout); g_object_unref(layout); pango_font_description_free(font_desc); g_free(markup); g_free(format); } } } cairo_stroke(cr); } } priv->x_label = "X Label Here"; priv->y_label = "Y Label Here"; /* * Draw the X scale label. */ if (priv->x_label) { PangoFontDescription *font_desc; PangoLayout *layout; gchar *markup; gint pw, ph; font_desc = pango_font_description_from_string("Bold Sans 10"); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_desc); markup = g_strdup_printf("<span size=\"smaller\">%s</span>", priv->x_label); pango_layout_set_markup(layout, markup, -1); pango_layout_get_pixel_size(layout, &pw, &ph); cairo_move_to(cr, ((w - pw) / 2.), h - ph); pango_cairo_show_layout(cr, layout); g_object_unref(layout); pango_font_description_free(font_desc); g_free(markup); } /* * Draw the Y scale label. */ if (priv->x_label) { PangoFontDescription *font_desc; PangoLayout *layout; gchar *markup; gint pw, ph; font_desc = pango_font_description_from_string("Bold Sans 10"); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_desc); markup = g_strdup_printf("<span size=\"smaller\">%s</span>", priv->y_label); pango_layout_set_markup(layout, markup, -1); pango_layout_get_pixel_size(layout, &pw, &ph); cairo_move_to(cr, 0., h - ((h - pw) / 2.)); cairo_rotate(cr, M_PI / -2.); pango_cairo_show_layout(cr, layout); g_object_unref(layout); pango_font_description_free(font_desc); g_free(markup); } /* * Free cairo context and resources. */ cairo_destroy(cr); /* * Render the children data points. */ pkg_graph_2d_paint_children(graph); }
PangoFontMetrics * _pango_cairo_font_get_metrics (PangoFont *font, PangoLanguage *language) { PangoCairoFont *cfont = (PangoCairoFont *) font; PangoCairoFontPrivate *cf_priv = PANGO_CAIRO_FONT_PRIVATE (font); PangoCairoFontMetricsInfo *info = NULL; /* Quiet gcc */ GSList *tmp_list; const char *sample_str = pango_language_get_sample_string (language); tmp_list = cf_priv->metrics_by_lang; while (tmp_list) { info = tmp_list->data; if (info->sample_str == sample_str) /* We _don't_ need strcmp */ break; tmp_list = tmp_list->next; } if (!tmp_list) { PangoFontMap *fontmap; PangoContext *context; cairo_font_options_t *font_options; PangoLayout *layout; PangoRectangle extents; PangoFontDescription *desc; cairo_scaled_font_t *scaled_font; cairo_matrix_t cairo_matrix; PangoMatrix pango_matrix; PangoMatrix identity = PANGO_MATRIX_INIT; int height, shift; /* XXX this is racy. need a ref'ing getter... */ fontmap = pango_font_get_font_map (font); if (!fontmap) return pango_font_metrics_new (); fontmap = g_object_ref (fontmap); info = g_slice_new0 (PangoCairoFontMetricsInfo); cf_priv->metrics_by_lang = g_slist_prepend (cf_priv->metrics_by_lang, info); info->sample_str = sample_str; scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv); context = pango_font_map_create_context (fontmap); pango_context_set_language (context, language); font_options = cairo_font_options_create (); cairo_scaled_font_get_font_options (scaled_font, font_options); pango_cairo_context_set_font_options (context, font_options); cairo_font_options_destroy (font_options); info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_base_metrics_for_context) (cfont, context); /* We now need to adjust the base metrics for ctm */ cairo_scaled_font_get_ctm (scaled_font, &cairo_matrix); pango_matrix.xx = cairo_matrix.xx; pango_matrix.yx = cairo_matrix.yx; pango_matrix.xy = cairo_matrix.xy; pango_matrix.yy = cairo_matrix.yy; pango_matrix.x0 = 0; pango_matrix.y0 = 0; if (G_UNLIKELY (0 != memcmp (&identity, &pango_matrix, 4 * sizeof (double)))) { double xscale = pango_matrix_get_font_scale_factor (&pango_matrix); if (xscale) xscale = 1 / xscale; info->metrics->ascent *= xscale; info->metrics->descent *= xscale; info->metrics->underline_position *= xscale; info->metrics->underline_thickness *= xscale; info->metrics->strikethrough_position *= xscale; info->metrics->strikethrough_thickness *= xscale; } /* Set the matrix on the context so we don't have to adjust the derived * metrics. */ pango_context_set_matrix (context, &pango_matrix); /* Update approximate_*_width now */ layout = pango_layout_new (context); desc = pango_font_describe_with_absolute_size (font); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_text (layout, sample_str, -1); pango_layout_get_extents (layout, NULL, &extents); info->metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str); pango_layout_set_text (layout, "0123456789", -1); info->metrics->approximate_digit_width = max_glyph_width (layout); g_object_unref (layout); /* We may actually reuse ascent/descent we got from cairo here. that's * in cf_priv->font_extents. */ height = info->metrics->ascent + info->metrics->descent; switch (cf_priv->gravity) { default: case PANGO_GRAVITY_AUTO: case PANGO_GRAVITY_SOUTH: break; case PANGO_GRAVITY_NORTH: info->metrics->ascent = info->metrics->descent; break; case PANGO_GRAVITY_EAST: case PANGO_GRAVITY_WEST: { int ascent = height / 2; if (cf_priv->is_hinted) ascent = PANGO_UNITS_ROUND (ascent); info->metrics->ascent = ascent; } } shift = (height - info->metrics->ascent) - info->metrics->descent; info->metrics->descent += shift; info->metrics->underline_position -= shift; info->metrics->strikethrough_position -= shift; info->metrics->ascent = height - info->metrics->descent; g_object_unref (context); g_object_unref (fontmap); } return pango_font_metrics_ref (info->metrics); }
cairo_scaled_font_t * _pango_cairo_font_private_get_scaled_font (PangoCairoFontPrivate *cf_priv) { cairo_font_face_t *font_face; if (G_LIKELY (cf_priv->scaled_font)) return cf_priv->scaled_font; /* need to create it */ if (G_UNLIKELY (cf_priv->data == NULL)) { /* we have tried to create and failed before */ return NULL; } font_face = (* PANGO_CAIRO_FONT_GET_IFACE (cf_priv->cfont)->create_font_face) (cf_priv->cfont); if (G_UNLIKELY (font_face == NULL)) goto done; cf_priv->scaled_font = cairo_scaled_font_create (font_face, &cf_priv->data->font_matrix, &cf_priv->data->ctm, cf_priv->data->options); cairo_font_face_destroy (font_face); done: if (G_UNLIKELY (cf_priv->scaled_font == NULL || cairo_scaled_font_status (cf_priv->scaled_font) != CAIRO_STATUS_SUCCESS)) { cairo_scaled_font_t *scaled_font = cf_priv->scaled_font; PangoFont *font = PANGO_FONT (cf_priv->cfont); static GQuark warned_quark = 0; /* MT-safe */ if (!warned_quark) warned_quark = g_quark_from_static_string ("pangocairo-scaledfont-warned"); if (!g_object_get_qdata (G_OBJECT (font), warned_quark)) { PangoFontDescription *desc; char *s; desc = pango_font_describe (font); s = pango_font_description_to_string (desc); pango_font_description_free (desc); g_warning ("failed to create cairo %s, expect ugly output. the offending font is '%s'", font_face ? "scaled font" : "font face", s); if (!font_face) g_warning ("font_face is NULL"); else g_warning ("font_face status is: %s", cairo_status_to_string (cairo_font_face_status (font_face))); if (!scaled_font) g_warning ("scaled_font is NULL"); else g_warning ("scaled_font status is: %s", cairo_status_to_string (cairo_scaled_font_status (scaled_font))); g_free (s); g_object_set_qdata_full (G_OBJECT (font), warned_quark, GINT_TO_POINTER (1), NULL); } } _pango_cairo_font_private_scaled_font_data_destroy (cf_priv->data); cf_priv->data = NULL; return cf_priv->scaled_font; }
static void file_list_ready_cb (GList *files, gpointer user_data) { CajaFileConflictDialog *fcd = user_data; CajaFile *src, *dest, *dest_dir; time_t src_mtime, dest_mtime; GtkDialog *dialog; gboolean source_is_dir, dest_is_dir, should_show_type; CajaFileConflictDialogDetails *details; char *primary_text, *message, *secondary_text; const gchar *message_extra; char *src_name, *dest_name, *dest_dir_name, *edit_name; char *label_text; char *size, *date, *type = NULL; GdkPixbuf *pixbuf; GtkWidget *label; GString *str; PangoFontDescription *desc; dialog = GTK_DIALOG (fcd); details = fcd->details; details->handle = NULL; dest_dir = g_list_nth_data (files, 0); dest = g_list_nth_data (files, 1); src = g_list_nth_data (files, 2); src_mtime = caja_file_get_mtime (src); dest_mtime = caja_file_get_mtime (dest); src_name = caja_file_get_display_name (src); dest_name = caja_file_get_display_name (dest); dest_dir_name = caja_file_get_display_name (dest_dir); source_is_dir = caja_file_is_directory (src); dest_is_dir = caja_file_is_directory (dest); type = caja_file_get_mime_type (dest); should_show_type = !caja_file_is_mime_type (src, type); g_free (type); type = NULL; /* Set up the right labels */ if (dest_is_dir) { if (source_is_dir) { primary_text = g_strdup_printf (_("Merge folder \"%s\"?"), dest_name); message_extra = _("Merging will ask for confirmation before replacing any files in " "the folder that conflict with the files being copied."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older folder with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer folder with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { message_extra = _("Replacing it will remove all files in the folder."); primary_text = g_strdup_printf (_("Replace folder \"%s\"?"), dest_name); message = g_strdup_printf (_("A folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { primary_text = g_strdup_printf (_("Replace file \"%s\"?"), dest_name); message_extra = _("Replacing it will overwrite its content."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older file with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer file with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another file with the same name already exists in \"%s\"."), dest_dir_name); } } secondary_text = g_strdup_printf ("%s\n%s", message, message_extra); g_free (message); label = gtk_label_new (primary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR); gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_modify_font (label, NULL); desc = pango_font_description_new (); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); pango_font_description_set_size (desc, pango_font_description_get_size (gtk_widget_get_style (label)->font_desc) * PANGO_SCALE_LARGE); gtk_widget_modify_font (label, desc); pango_font_description_free (desc); gtk_widget_show (label); label = gtk_label_new (secondary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (primary_text); g_free (secondary_text); /* Set up file icons */ pixbuf = caja_file_get_icon_pixbuf (dest, CAJA_ICON_SIZE_LARGE, TRUE, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS); details->dest_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->first_hbox), details->dest_image, FALSE, FALSE, 0); gtk_widget_show (details->dest_image); g_object_unref (pixbuf); pixbuf = caja_file_get_icon_pixbuf (src, CAJA_ICON_SIZE_LARGE, TRUE, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS); details->src_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->second_hbox), details->src_image, FALSE, FALSE, 0); gtk_widget_show (details->src_image); g_object_unref (pixbuf); /* Set up labels */ label = gtk_label_new (NULL); date = caja_file_get_string_attribute (dest, "date_modified"); size = caja_file_get_string_attribute (dest, "size"); if (should_show_type) { type = caja_file_get_string_attribute (dest, "type"); } str = g_string_new (NULL); g_string_append_printf (str, "<b>%s</b>\n", _("Original file")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = str->str; gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->first_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (type); g_free (date); g_string_erase (str, 0, -1); /* Second label */ label = gtk_label_new (NULL); date = caja_file_get_string_attribute (src, "date_modified"); size = caja_file_get_string_attribute (src, "size"); if (should_show_type) { type = caja_file_get_string_attribute (src, "type"); } g_string_append_printf (str, "<b>%s</b>\n", _("Replace with")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = g_string_free (str, FALSE); gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->second_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (date); g_free (type); g_free (label_text); /* Populate the entry */ edit_name = caja_file_get_edit_name (dest); details->conflict_name = edit_name; gtk_entry_set_text (GTK_ENTRY (details->entry), edit_name); if (source_is_dir && dest_is_dir) { gtk_button_set_label (GTK_BUTTON (details->replace_button), _("Merge")); } /* If meld is installed, and source and destination arent binary * files, show the diff button */ gtk_widget_hide (details->diff_button); if (!source_is_dir && !dest_is_dir) { if (g_find_program_in_path ("meld")) { gboolean src_is_binary; gboolean dest_is_binary; src_is_binary = caja_file_is_binary (details->source); dest_is_binary = caja_file_is_binary (details->destination); if (!src_is_binary && !dest_is_binary) gtk_widget_show (details->diff_button); } } caja_file_monitor_add (src, fcd, CAJA_FILE_ATTRIBUTES_FOR_ICON); caja_file_monitor_add (dest, fcd, CAJA_FILE_ATTRIBUTES_FOR_ICON); details->src_handler_id = g_signal_connect (src, "changed", G_CALLBACK (file_icons_changed), fcd); details->dest_handler_id = g_signal_connect (dest, "changed", G_CALLBACK (file_icons_changed), fcd); }
static PangoLayout* create_layout(HippoCanvasText *text, int allocation_width) { HippoCanvasBox *box = HIPPO_CANVAS_BOX(text); PangoLayout *layout; HippoCanvasStyle *style = hippo_canvas_context_get_style(HIPPO_CANVAS_CONTEXT(text)); g_return_val_if_fail(box->context != NULL, NULL); layout = hippo_canvas_context_create_layout(box->context); if (box->font_desc) { PangoFontDescription *merged = pango_font_description_copy(hippo_canvas_style_get_font(style)); pango_font_description_merge(merged, box->font_desc, TRUE); pango_layout_set_font_description(layout, merged); pango_font_description_free(merged); } else { pango_layout_set_font_description(layout, hippo_canvas_style_get_font(style)); } { PangoAttrList *attrs; HippoTextDecoration decoration = hippo_canvas_style_get_text_decoration(style); if (text->attributes) attrs = pango_attr_list_copy(text->attributes); else attrs = pango_attr_list_new(); if (ABS(1.0 - text->font_scale) > .000001) { PangoAttribute *attr = pango_attr_scale_new(text->font_scale); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } if ((decoration & HIPPO_TEXT_DECORATION_UNDERLINE) != 0) { PangoAttribute *attr = pango_attr_underline_new(TRUE); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } if ((decoration & HIPPO_TEXT_DECORATION_LINE_THROUGH) != 0) { PangoAttribute *attr = pango_attr_strikethrough_new(TRUE); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } pango_layout_set_attributes(layout, attrs); pango_attr_list_unref(attrs); } if (text->text != NULL) { pango_layout_set_text(layout, text->text, -1); } if (allocation_width >= 0) { int layout_width, layout_height; pango_layout_get_size(layout, &layout_width, &layout_height); layout_width /= PANGO_SCALE; layout_height /= PANGO_SCALE; /* Force layout smaller if required, but we don't want to make * the layout _wider_ because it breaks alignment, so only do * this if required. */ if (layout_width > allocation_width) { pango_layout_set_width(layout, allocation_width * PANGO_SCALE); /* If we set ellipsize, then it overrides wrapping. If we get * too-small allocation for HIPPO_CANVAS_SIZE_FULL_WIDTH, then * we want to ellipsize instead of wrapping. */ if (text->size_mode == HIPPO_CANVAS_SIZE_WRAP_WORD) { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); } else { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); } /* For now if we say ellipsize end, we always just want one line. * Maybe this should be an orthogonal property? */ if (text->size_mode == HIPPO_CANVAS_SIZE_ELLIPSIZE_END) { pango_layout_set_single_paragraph_mode(layout, TRUE); /* Pango's line separator character in this case is ugly, so we * fix it. Not a very efficient approach, but oh well. */ if (text->text != NULL) { char *new_text = remove_newlines(text->text); /* avoid making the layout recompute everything * if we didn't have newlines anyhow */ if (strcmp(text->text, new_text) != 0) { pango_layout_set_text(layout, new_text, -1); } g_free(new_text); } } } } return layout; }
int main(int argc, char **argv) { int nResponse, i, nKeyWordGroup = 0; GtkTextBuffer *buffer; GtkBuilder *builder; PangoFontDescription *font_desc; JJGui *jibber_ui; // allocate the memory needed by our structure jibber_ui = g_slice_new(JJGui); // init the gtk toolkit gtk_init(&argc, &argv); // get a new interface builder builder = gtk_builder_new(); // read the GUI definitions from the XML file gtk_builder_add_from_file(builder, "jibber.glade", NULL); // point the structure members to the UI elements we need to control jibber_ui->window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); jibber_ui->edit_field = GTK_ENTRY (gtk_builder_get_object (builder, "text_field")); jibber_ui->text_view = GTK_WIDGET (gtk_builder_get_object (builder, "textview1")); // connect the signal handlers gtk_builder_connect_signals(builder, jibber_ui); // release the builder memory g_object_unref(G_OBJECT (builder)); // set the desired font font_desc = pango_font_description_from_string("monospace 10"); gtk_widget_override_font(jibber_ui->text_view, font_desc); pango_font_description_free(font_desc); // get a handle on the buffer from the text window buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (jibber_ui->text_view)); // create some style tags gtk_text_buffer_create_tag(buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL); gtk_text_buffer_create_tag(buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL); // intialise the SQLite library sqlite3_initialize( ); // Initialize random number generator srand(time(NULL)); // don't show the internal workings bShow = false; // open the database nResponse = sqlite3_open_v2( "worldview.sl3", &knowledgeDB, SQLITE_OPEN_READWRITE, NULL ); // if it didn't open OK, shutdown and exit if ( nResponse != SQLITE_OK) { printf("Couldn't open world view database.\n"); sqlite3_close( knowledgeDB ); exit (-1); } // set all the position flags to 'never been used' for (i=0; i<1000; i++) nGroupPositionFlags[ i ] = (-2); // record the KeyWordGroups for the categories that need special processing nProcessCategories[ TIME_HANDLER ] = GetGroupFromTriggerPhrase("WHAT TIME IS IT", jibber_ui); nProcessCategories[ DATE_HANDLER ] = GetGroupFromTriggerPhrase("WHAT DATE IS IT", jibber_ui); nProcessCategories[ DAY_HANDLER ] = GetGroupFromTriggerPhrase("WHAT DAY IS IT", jibber_ui); nProcessCategories[ YEAR_HANDLER ] = GetGroupFromTriggerPhrase("WHAT YEAR IS IT", jibber_ui); nProcessCategories[ MONTH_HANDLER ] = GetGroupFromTriggerPhrase("WHAT MONTH IS IT", jibber_ui); nProcessCategories[ END_MARKER ] = (-1); // no topics in the linked list yet Root = End = NULL; // Announce ourselves AppendText(jibber_ui, DIR_SYSTEM, "Jibber Jabber %s :: Compiled on %s at %s.", JJ_VERSION, __DATE__, __TIME__); AppendText(jibber_ui, DIR_BLANK, "" ); nKeyWordGroup = GetGroupFromTriggerPhrase("JJOPENINGLINES", jibber_ui); // get response from this keywordgroup if ( nKeyWordGroup ) GetResponseFromGroup( nKeyWordGroup, "", 0, jibber_ui ); // display the window gtk_widget_show(jibber_ui->window); // enter the UI event handler loop gtk_main(); // shut down and exit sqlite3_close( knowledgeDB ); sqlite3_shutdown( ); // flag exit code to OS return (0); } // end of main
static void gtk_plot_cairo_draw_string (GtkPlotPC *pc, gint tx, gint ty, gint angle, const GdkColor *fg, const GdkColor *bg, gboolean transparent, gint border, gint border_space, gint border_width, gint shadow_width, const gchar *font_name, gint font_height, GtkJustification just, const gchar *text) { cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; GList *family = NULL; gint x0, y0; gint old_width, old_height; gboolean bold, italic; gint fontsize; gint ascent, descent; gint numf; gint width, height; gint x, y; gint i; PangoFontDescription *font = NULL, *latin_font = NULL; GtkPSFont *psfont, *base_psfont, *latin_psfont; gchar subs[2], insert_char; const gchar *aux = text; const gchar *lastchar = text; const gchar *wtext = text; const gchar *xaux = text; gchar *new_text; /* Support Tiny C compiler : Original : gchar new_text[strlen(text)+1];*/ gchar num[4]; PangoRectangle rect; PangoLayout *layout = NULL; gint real_x, real_y, real_width, real_height; GdkColor real_fg = *fg; GdkColor real_bg = *bg; gint sign_x = 1, sign_y = 0; gint old_tx = tx, old_ty = ty; if (!cairo) return; layout = GTK_PLOT_CAIRO(pc)->layout; cairo_save(cairo); gtk_plot_cairo_set_color(pc, fg); /* font_name = "sans"; desc = pango_font_description_from_string(font_name); // Since the name does not contain the size yet... Also there is some // factor that I have to figure out... pango_font_description_set_size (desc, font_height *0.9 * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, text, -1); cairo_save(cairo); cairo_translate(cairo, tx, ty); cairo_rotate(cairo, angle * G_PI / 180); gtk_plot_cairo_set_color(pc, fg); pango_cairo_update_layout(cairo, layout); PangoFontMetrics *metrics = NULL; metrics = pango_context_get_metrics(pango_layout_get_context(layout), desc, gtk_get_default_language()); pango_layout_get_size (layout, &width, &height); ascent = pango_font_metrics_get_ascent(metrics); descent = pango_font_metrics_get_descent(metrics); if (just == GTK_JUSTIFY_RIGHT) cairo_move_to(cairo, -PANGO_PIXELS(width), -PANGO_PIXELS(ascent) ); else if (just == GTK_JUSTIFY_CENTER) cairo_move_to(cairo, -PANGO_PIXELS(width)/2.0, -PANGO_PIXELS(ascent) ); else if (just == GTK_JUSTIFY_LEFT) cairo_move_to(cairo, 0, -PANGO_PIXELS(ascent) ); pango_cairo_show_layout(cairo, layout); cairo_restore(cairo); */ gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent); if(height == 0 || width == 0) return; old_width = width; old_height = height; if(angle == 90 || angle == 270) { old_width = height; old_height = width; } switch(angle){ case 90: sign_x = 0; sign_y = -1; break; case 180: sign_x = -1; sign_y = 0; break; case 270: sign_x = 0; sign_y = 1; break; case 0: default: sign_x = 1; sign_y = 0; break; } switch(just){ case GTK_JUSTIFY_LEFT: switch(angle){ case 0: ty -= ascent; break; case 90: ty -= height; tx -= ascent; break; case 180: tx -= width; ty -= descent; break; case 270: tx -= descent; break; } old_tx = tx; old_ty = ty; break; case GTK_JUSTIFY_RIGHT: switch(angle){ case 0: tx -= width; ty -= ascent; old_tx -= width; old_ty -= ascent; break; case 90: tx -= ascent; ty += height; old_tx -= ascent; break; case 180: tx += width; ty -= descent; old_ty -= descent; break; case 270: tx -= descent; old_tx -= descent; old_ty -= height; break; } break; case GTK_JUSTIFY_CENTER: default: switch(angle){ case 0: tx -= width / 2.; ty -= ascent; old_tx -= width / 2.; old_ty -= ascent; break; case 90: tx -= ascent; ty += height / 2.; old_tx -= ascent; old_ty -= height / 2.; break; case 180: tx += width / 2.; ty -= descent; old_tx -= width / 2.; old_ty -= descent; break; case 270: tx -= descent; ty -= height / 2.; old_tx -= descent; old_ty -= height / 2.; break; } } real_x = tx; real_y = ty; real_width = width; real_height = height; if(!transparent){ gtk_plot_cairo_set_color(pc, &real_bg); gtk_plot_cairo_draw_rectangle(pc, TRUE, old_tx, old_ty, old_width, old_height); } gtk_psfont_get_families(&family, &numf); base_psfont = psfont = gtk_psfont_get_by_name(font_name); font = gtk_psfont_get_font_description(psfont, font_height); italic = psfont->italic; bold = psfont->bold; fontsize = font_height; x0 = x = 0; y0 = y = 0; if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } else { latin_psfont = NULL; latin_font = NULL; } gtk_plot_cairo_set_color(pc, &real_fg); aux = text; while(aux && *aux != '\0' && *aux != '\n'){ if(*aux == '\\'){ aux = g_utf8_next_char(aux); switch(*aux){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '9': psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case '8': case 'g': psfont = gtk_psfont_get_by_family("Symbol", italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case 'B': bold = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(latin_font){ latin_font = NULL; } if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'x': xaux = aux + 1; for (i=0; i<3; i++){ if (xaux[i] >= '0' && xaux[i] <= '9') num[i] = xaux[i]; else break; } if (i < 3){ aux = g_utf8_next_char(aux); break; } num[3] = '\0'; insert_char = (gchar)atoi(num); subs[0] = insert_char; subs[1] = '\0'; pango_layout_set_font_description(layout, font); pango_layout_set_text(layout, subs, 1); pango_layout_get_extents(layout, NULL, &rect); x += sign_x*PANGO_PIXELS(rect.width); y += sign_y*PANGO_PIXELS(rect.width); aux += 4; lastchar = aux - 1; break; case 'i': italic = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'S': case '^': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } if(angle == 180) y = y0 + fontsize; else if(angle == 270) x = x0 + sign_y*fontsize; aux = g_utf8_next_char(aux); break; case 's': case '_': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(angle == 0) y = y0 + fontsize; else if(angle == 90) x = x0 - sign_y*fontsize; if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '+': fontsize += 3; y -= sign_x*3; x += sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '-': fontsize -= 3; y += sign_x*3; x -= sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'N': psfont = base_psfont; fontsize = font_height; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(angle == 0 || angle == 180) y = y0; else x = x0; italic = psfont->italic; bold = psfont->bold; aux = g_utf8_next_char(aux); break; case 'b': if (lastchar) { const gchar *aux2 = lastchar; gint i = g_utf8_prev_char(lastchar) != --aux2 ? 2 : 1; pango_layout_set_text(layout, lastchar, i); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); if (lastchar == wtext) lastchar = NULL; else lastchar = g_utf8_prev_char(lastchar); } else { pango_layout_set_text(layout, "X", 1); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); } aux = g_utf8_next_char(aux); break; default: if(aux && *aux != '\0' && *aux !='\n'){ gint new_width = 0; new_width = drawstring(pc, angle, tx+x, ty+y, psfont, fontsize, aux); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; aux = g_utf8_next_char(aux); } break; } } else { gint new_len = 0; gint new_width = 0; lastchar = aux; while(aux && *aux != '\0' && *aux !='\n' && *aux != '\\'){ xaux = aux; new_len += g_utf8_next_char(aux) != ++xaux ? 2 : 1; aux = g_utf8_next_char(aux); } xaux = lastchar; new_text = (gchar *) g_new0(gchar , strlen(text)+1); /* Tiny C Compiler support */ for(i = 0; i < new_len; i++) new_text[i] = *xaux++; new_text[new_len] = '\0'; new_width = drawstring(pc, angle, tx+x, ty+y, psfont, fontsize, new_text); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; g_free (new_text); } } if(latin_font) pango_font_description_free(latin_font); /* border */ gtk_plot_cairo_set_color(pc, &real_fg); gtk_plot_pc_set_dash(pc, 0, NULL, 0); gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0); switch(border){ case GTK_PLOT_BORDER_SHADOW: gtk_plot_pc_draw_rectangle(pc, TRUE, old_tx - border_space + shadow_width, old_ty + height + border_space, width + 2 * border_space, shadow_width); gtk_plot_pc_draw_rectangle(pc, TRUE, old_tx + width + border_space, old_ty - border_space + shadow_width, shadow_width, height + 2 * border_space); case GTK_PLOT_BORDER_LINE: gtk_plot_pc_draw_rectangle(pc, FALSE, old_tx - border_space, old_ty - border_space, width + 2*border_space, height + 2*border_space); case GTK_PLOT_BORDER_NONE: default: break; } cairo_restore(cairo); return; }
static gboolean span_parse_func (MarkupData *md, OpenTag *tag, const gchar **names, const gchar **values, GMarkupParseContext *context, GError **error) { int line_number, char_number; int i; const char *family = NULL; const char *size = NULL; const char *style = NULL; const char *weight = NULL; const char *variant = NULL; const char *stretch = NULL; const char *desc = NULL; const char *foreground = NULL; const char *background = NULL; const char *underline = NULL; const char *underline_color = NULL; const char *strikethrough = NULL; const char *strikethrough_color = NULL; const char *rise = NULL; const char *letter_spacing = NULL; const char *lang = NULL; const char *fallback = NULL; const char *gravity = NULL; const char *gravity_hint = NULL; g_markup_parse_context_get_position (context, &line_number, &char_number); #define CHECK_DUPLICATE(var) G_STMT_START{ \ if ((var) != NULL) { \ g_set_error (error, G_MARKUP_ERROR, \ G_MARKUP_ERROR_INVALID_CONTENT, \ _("Attribute '%s' occurs twice on <span> tag " \ "on line %d char %d, may only occur once"), \ names[i], line_number, char_number); \ return FALSE; \ }}G_STMT_END #define CHECK_ATTRIBUTE2(var, name) \ if (attr_strcmp (names[i], (name)) == 0) { \ CHECK_DUPLICATE (var); \ (var) = values[i]; \ found = TRUE; \ break; \ } #define CHECK_ATTRIBUTE(var) CHECK_ATTRIBUTE2 (var, G_STRINGIFY (var)) i = 0; while (names[i]) { gboolean found = FALSE; switch (names[i][0]) { case 'f': CHECK_ATTRIBUTE (fallback); CHECK_ATTRIBUTE2(desc, "font"); CHECK_ATTRIBUTE2(desc, "font_desc"); CHECK_ATTRIBUTE2(family, "face"); CHECK_ATTRIBUTE2(family, "font_family"); CHECK_ATTRIBUTE2(size, "font_size"); CHECK_ATTRIBUTE2(stretch, "font_stretch"); CHECK_ATTRIBUTE2(style, "font_style"); CHECK_ATTRIBUTE2(variant, "font_variant"); CHECK_ATTRIBUTE2(weight, "font_weight"); CHECK_ATTRIBUTE (foreground); CHECK_ATTRIBUTE2 (foreground, "fgcolor"); break; case 's': CHECK_ATTRIBUTE (size); CHECK_ATTRIBUTE (stretch); CHECK_ATTRIBUTE (strikethrough); CHECK_ATTRIBUTE (strikethrough_color); CHECK_ATTRIBUTE (style); break; case 'g': CHECK_ATTRIBUTE (gravity); CHECK_ATTRIBUTE (gravity_hint); break; case 'l': CHECK_ATTRIBUTE (lang); CHECK_ATTRIBUTE (letter_spacing); break; case 'u': CHECK_ATTRIBUTE (underline); CHECK_ATTRIBUTE (underline_color); break; default: CHECK_ATTRIBUTE (background); CHECK_ATTRIBUTE2 (background, "bgcolor"); CHECK_ATTRIBUTE2(foreground, "color"); CHECK_ATTRIBUTE (rise); CHECK_ATTRIBUTE (variant); CHECK_ATTRIBUTE (weight); break; } if (!found) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE, _("Attribute '%s' is not allowed on the <span> tag " "on line %d char %d"), names[i], line_number, char_number); return FALSE; } ++i; } /* Parse desc first, then modify it with other font-related attributes. */ if (G_UNLIKELY (desc)) { PangoFontDescription *parsed; parsed = pango_font_description_from_string (desc); if (parsed) { add_attribute (tag, pango_attr_font_desc_new (parsed)); if (tag) open_tag_set_absolute_font_size (tag, pango_font_description_get_size (parsed)); pango_font_description_free (parsed); } } if (G_UNLIKELY (family)) { add_attribute (tag, pango_attr_family_new (family)); } if (G_UNLIKELY (size)) { if (g_ascii_isdigit (*size)) { const char *end; gint n; /* cap size from the top at an arbitrary 2048 */ #define MAX_SIZE (2048 * PANGO_SCALE) if ((end = size, !pango_scan_int (&end, &n)) || *end != '\0' || n < 0 || n > MAX_SIZE) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Value of 'size' attribute on <span> tag on line %d " "could not be parsed; should be an integer less than %d, or a " "string such as 'small', not '%s'"), line_number, MAX_SIZE+1, size); goto error; } add_attribute (tag, pango_attr_size_new (n)); if (tag) open_tag_set_absolute_font_size (tag, n); } else if (strcmp (size, "smaller") == 0) { if (tag) { tag->scale_level_delta -= 1; tag->scale_level -= 1; } } else if (strcmp (size, "larger") == 0) { if (tag) { tag->scale_level_delta += 1; tag->scale_level += 1; } } else if (parse_absolute_size (tag, size)) ; /* nothing */ else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Value of 'size' attribute on <span> tag on line %d " "could not be parsed; should be an integer, or a " "string such as 'small', not '%s'"), line_number, size); goto error; } } if (G_UNLIKELY (style)) { PangoStyle pango_style; if (pango_parse_style (style, &pango_style, FALSE)) add_attribute (tag, pango_attr_style_new (pango_style)); else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("'%s' is not a valid value for the 'style' attribute " "on <span> tag, line %d; valid values are " "'normal', 'oblique', 'italic'"), style, line_number); goto error; } } if (G_UNLIKELY (weight)) { PangoWeight pango_weight; if (pango_parse_weight (weight, &pango_weight, FALSE)) add_attribute (tag, pango_attr_weight_new (pango_weight)); else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("'%s' is not a valid value for the 'weight' " "attribute on <span> tag, line %d; valid " "values are for example 'light', 'ultrabold' or a number"), weight, line_number); goto error; } } if (G_UNLIKELY (variant)) { PangoVariant pango_variant; if (pango_parse_variant (variant, &pango_variant, FALSE)) add_attribute (tag, pango_attr_variant_new (pango_variant)); else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("'%s' is not a valid value for the 'variant' " "attribute on <span> tag, line %d; valid values are " "'normal', 'smallcaps'"), variant, line_number); goto error; } } if (G_UNLIKELY (stretch)) { PangoStretch pango_stretch; if (pango_parse_stretch (stretch, &pango_stretch, FALSE)) add_attribute (tag, pango_attr_stretch_new (pango_stretch)); else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("'%s' is not a valid value for the 'stretch' " "attribute on <span> tag, line %d; valid " "values are for example 'condensed', " "'ultraexpanded', 'normal'"), stretch, line_number); goto error; } } if (G_UNLIKELY (foreground)) { PangoColor color; if (!span_parse_color ("foreground", foreground, &color, line_number, error)) goto error; add_attribute (tag, pango_attr_foreground_new (color.red, color.green, color.blue)); } if (G_UNLIKELY (background)) { PangoColor color; if (!span_parse_color ("background", background, &color, line_number, error)) goto error; add_attribute (tag, pango_attr_background_new (color.red, color.green, color.blue)); } if (G_UNLIKELY (underline)) { PangoUnderline ul = PANGO_UNDERLINE_NONE; if (!span_parse_enum ("underline", underline, PANGO_TYPE_UNDERLINE, &ul, line_number, error)) goto error; add_attribute (tag, pango_attr_underline_new (ul)); } if (G_UNLIKELY (underline_color)) { PangoColor color; if (!span_parse_color ("underline_color", underline_color, &color, line_number, error)) goto error; add_attribute (tag, pango_attr_underline_color_new (color.red, color.green, color.blue)); } if (G_UNLIKELY (gravity)) { PangoGravity gr = PANGO_GRAVITY_SOUTH; if (!span_parse_enum ("gravity", gravity, PANGO_TYPE_GRAVITY, &gr, line_number, error)) goto error; add_attribute (tag, pango_attr_gravity_new (gr)); } if (G_UNLIKELY (gravity_hint)) { PangoGravityHint hint = PANGO_GRAVITY_HINT_NATURAL; if (!span_parse_enum ("gravity_hint", gravity_hint, PANGO_TYPE_GRAVITY_HINT, &hint, line_number, error)) goto error; add_attribute (tag, pango_attr_gravity_hint_new (hint)); } if (G_UNLIKELY (strikethrough)) { gboolean b = FALSE; if (!span_parse_boolean ("strikethrough", strikethrough, &b, line_number, error)) goto error; add_attribute (tag, pango_attr_strikethrough_new (b)); } if (G_UNLIKELY (strikethrough_color)) { PangoColor color; if (!span_parse_color ("strikethrough_color", strikethrough_color, &color, line_number, error)) goto error; add_attribute (tag, pango_attr_strikethrough_color_new (color.red, color.green, color.blue)); } if (G_UNLIKELY (fallback)) { gboolean b = FALSE; if (!span_parse_boolean ("fallback", fallback, &b, line_number, error)) goto error; add_attribute (tag, pango_attr_fallback_new (b)); } if (G_UNLIKELY (rise)) { gint n = 0; if (!span_parse_int ("rise", rise, &n, line_number, error)) goto error; add_attribute (tag, pango_attr_rise_new (n)); } if (G_UNLIKELY (letter_spacing)) { gint n = 0; if (!span_parse_int ("letter_spacing", letter_spacing, &n, line_number, error)) goto error; add_attribute (tag, pango_attr_letter_spacing_new (n)); } if (G_UNLIKELY (lang)) { add_attribute (tag, pango_attr_language_new (pango_language_from_string (lang))); } return TRUE; error: return FALSE; }
// it will update the new_font_name and page_data->font_name gchar *get_resize_font(GtkWidget *vte, Font_Name_Type type) { #ifdef DETAIL g_debug("! Launch get_resize_font() for vte %p with type %d", vte, type); #endif #ifdef SAFEMODE if (vte==NULL) return NULL; #endif // we must insure that vte!=NULL struct Page *page_data = (struct Page *)g_object_get_data(G_OBJECT(vte), "Page_Data"); #ifdef SAFEMODE if (page_data==NULL) return NULL; #endif struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(page_data->window), "Win_Data"); #ifdef SAFEMODE if (win_data==NULL) return NULL; #endif // g_debug("Get win_data = %d when get resize font!", win_data); // type 0, FONT_NAME_DEFAULT: restore font to default_font_name // type 1, FONT_NAME_SYSTEM: restore font to system_font_name // type 2, FONT_NAME_RESTORE: restore font to restore_font_name // type 3, FONT_NAME_UPDATE: do nothing but only update new_font_name // type 4, FONT_NAME_ZOOM_OUT: increase window by *1.1 or +1 // type 5, FONT_NAME_ZOOM_IN: decrease window by /1.1 or -1 // type 6, FONT_NAME_INCREASE: increase font by *1.1 or +1 // type 7, FONT_NAME_DECREASE: decrease font by /1.1 or -1 if (win_data->restore_font_name == NULL) { // win_data->restore_font_name = g_strdup(page_data->font_name); win_data->restore_font_name = g_strdup(win_data->default_font_name); // g_debug("Restore the font to %s!", win_data->restore_font_name); if (type==FONT_NAME_RESTORE) return g_strdup(page_data->font_name); } switch (type) { case FONT_NAME_DEFAULT: case FONT_NAME_SYSTEM: case FONT_NAME_RESTORE: g_free(page_data->font_name); break; default: break; } // we use font_size to save current font size // font_size = (the size in font_name) * PANGO_SCALE // if font_size == 0 -> use the data in font_name switch (type) { case FONT_NAME_DEFAULT: // restore font to default_font_name page_data->font_name = g_strdup(win_data->default_font_name); page_data->font_size = 0; break; case FONT_NAME_SYSTEM: // restore font to default_font_name page_data->font_name = g_strdup(SYSTEM_FONT_NAME); page_data->font_size = 0; break; case FONT_NAME_RESTORE: // restore font to default_font_name page_data->font_name = g_strdup(win_data->restore_font_name); page_data->font_size = 0; break; case FONT_NAME_UPDATE: break; case FONT_NAME_ZOOM_OUT: case FONT_NAME_ZOOM_IN: case FONT_NAME_INCREASE: case FONT_NAME_DECREASE: { #ifdef SAFEMODE if (page_data->font_name==NULL) break; #endif gint oldfontsize=0, fontsize=0; // g_debug("old font name: %s", page_data->font_name); PangoFontDescription *font_desc = pango_font_description_from_string( page_data->font_name); // increase/decrease font oldfontsize = (pango_font_description_get_size(font_desc)/PANGO_SCALE); if (page_data->font_size==0) page_data->font_size = pango_font_description_get_size(font_desc); switch (type) { // g_debug("window_resize_ratio = %f", win_data->window_resize_ratio); case FONT_NAME_ZOOM_OUT: if (win_data->window_resize_ratio) page_data->font_size = page_data->font_size * win_data->window_resize_ratio + 0.5; else page_data->font_size = page_data->font_size + PANGO_SCALE; break; case FONT_NAME_ZOOM_IN: if (win_data->window_resize_ratio) page_data->font_size = page_data->font_size / win_data->window_resize_ratio + 0.5; else page_data->font_size = page_data->font_size - PANGO_SCALE; break; case FONT_NAME_INCREASE: if (win_data->font_resize_ratio) page_data->font_size = page_data->font_size * win_data->font_resize_ratio + 0.5; else page_data->font_size = page_data->font_size + PANGO_SCALE; break; case FONT_NAME_DECREASE: if (win_data->font_resize_ratio) page_data->font_size = page_data->font_size / win_data->font_resize_ratio + 0.5; else page_data->font_size = page_data->font_size - PANGO_SCALE; break; default: break; } // g_debug("font_size = %d", page_data->font_size); fontsize = (page_data->font_size)/PANGO_SCALE; // to avoid the fontsize is unchanged or = 0 switch (type) { case FONT_NAME_ZOOM_OUT: case FONT_NAME_INCREASE: if (oldfontsize==fontsize) fontsize++; break; case FONT_NAME_ZOOM_IN: case FONT_NAME_DECREASE: if (oldfontsize==fontsize) fontsize--; if (fontsize<1) fontsize=1; break; default: break; } // g_debug("Trying to change the font size to %d.", fontsize); pango_font_description_set_size(font_desc, fontsize*PANGO_SCALE); g_free(page_data->font_name); page_data->font_name = pango_font_description_to_string(font_desc); pango_font_description_free(font_desc); break; default: #ifdef FATAL print_switch_out_of_range_error_dialog("get_resize_font", "type", type); #endif return NULL; } } // g_debug("new font name: %s", page_data->font_name); switch (type) { case FONT_NAME_DEFAULT: case FONT_NAME_SYSTEM: case FONT_NAME_UPDATE: case FONT_NAME_ZOOM_OUT: case FONT_NAME_ZOOM_IN: // if not using <Ctrl><+ - enter> to change the font size. g_free(win_data->restore_font_name); win_data->restore_font_name = g_strdup(page_data->font_name); break; case FONT_NAME_INCREASE: case FONT_NAME_DECREASE: // Check if we can specify page_data->font_size = 0 if ( ! compare_strings(page_data->font_name, win_data->restore_font_name, TRUE)) { page_data->font_size = 0; // g_debug("The font is restored to win_data->restore_font_name"); } break; default: break; } return g_strdup(page_data->font_name); }
int l_klient_imp(const char *imaf, GtkWidget *wpredok) { char strsql[500]; iceb_u_spisok repl_s; class l_klient_imp_data data; data.imafz.new_plus(imaf); data.window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_modal(GTK_WINDOW(data.window),TRUE); gtk_window_set_position( GTK_WINDOW(data.window),ICEB_POS_CENTER); gtk_window_set_default_size (GTK_WINDOW (data.window),400,-1); sprintf(strsql,"%s %s",name_system,gettext("Импорт карточек из файла")); gtk_window_set_title(GTK_WINDOW(data.window),strsql); gtk_signal_connect(GTK_OBJECT(data.window),"delete_event",GTK_SIGNAL_FUNC(gtk_widget_destroy),NULL); gtk_signal_connect(GTK_OBJECT(data.window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL); gtk_signal_connect_after(GTK_OBJECT(data.window),"key_press_event",GTK_SIGNAL_FUNC(l_klient_imp_key_press),&data); if(wpredok != NULL) { gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR_GDITE)); //Удерживать окно над породившем его окном всегда gtk_window_set_transient_for(GTK_WINDOW(data.window),GTK_WINDOW(wpredok)); //Закрыть окно если окно предок удалено gtk_window_set_destroy_with_parent(GTK_WINDOW(data.window),TRUE); } GtkWidget *vbox=gtk_vbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(data.window), vbox); data.label=gtk_label_new(gettext("Ждите !!!")); gtk_box_pack_start(GTK_BOX(vbox),data.label,FALSE,FALSE,0); GtkWidget *label=NULL; label=gtk_label_new(gettext("Импорт карточек из файла")); gtk_box_pack_start(GTK_BOX(vbox),label,FALSE,FALSE,0); data.view=gtk_text_view_new(); gtk_widget_set_usize(GTK_WIDGET(data.view),450,300); gtk_text_view_set_editable(GTK_TEXT_VIEW(data.view),FALSE); //Запрет на редактирование текста //PangoFontDescription *font_pango=pango_font_description_from_string("Nimbus Mono L, Bold 12"); PangoFontDescription *font_pango=pango_font_description_from_string(shrift_ravnohir.ravno()); gtk_widget_modify_font(GTK_WIDGET(data.view),font_pango); pango_font_description_free(font_pango); data.buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(data.view)); GtkWidget *sw=gtk_scrolled_window_new(NULL,NULL); //gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); //gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS); gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(sw),data.view); data.bar=gtk_progress_bar_new(); gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(data.bar),GTK_PROGRESS_CONTINUOUS); gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(data.bar),GTK_PROGRESS_LEFT_TO_RIGHT); gtk_box_pack_start (GTK_BOX (vbox), data.bar, FALSE, FALSE, 2); sprintf(strsql,"F10 %s",gettext("Выход")); data.knopka=gtk_button_new_with_label(strsql); GtkTooltips *tooltops=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltops,data.knopka,gettext("Завершение работы в этом окне"),NULL); gtk_signal_connect(GTK_OBJECT(data.knopka),"clicked",GTK_SIGNAL_FUNC(l_klient_imp_v_knopka),&data); gtk_object_set_user_data(GTK_OBJECT(data.knopka),(gpointer)0); gtk_box_pack_start (GTK_BOX (vbox), data.knopka, FALSE, FALSE, 2); gtk_widget_set_sensitive(GTK_WIDGET(data.knopka),FALSE);//Недоступна gtk_widget_show_all(data.window); //gtk_window_set_decorated(GTK_WINDOW(data.window),FALSE); //Убирает рамку вокруг окна //gtk_widget_set_sensitive(GTK_WIDGET(data.knopka),FALSE);//Недоступна gtk_idle_add((GtkFunction)l_klient_imp1,&data); gtk_main(); if(wpredok != NULL) gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR)); return(data.voz); }
static gboolean gcal_week_view_draw_hours (GcalWeekView *self, cairo_t *cr, GtkWidget *widget) { GtkStyleContext *context; GtkStateFlags state; GtkBorder padding; GdkRGBA color; gboolean ltr; gint i, width, height; gint font_width; PangoLayout *layout; PangoFontDescription *font_desc; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL; gtk_style_context_save (context); gtk_style_context_add_class (context, "hours"); gtk_style_context_get_color (context, state, &color); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_get (context, state, "font", &font_desc, NULL); layout = pango_cairo_create_layout (cr); pango_layout_set_font_description (layout, font_desc); gdk_cairo_set_source_rgba (cr, &color); /* Gets the size of the widget */ width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); /* Draws the hours in the sidebar */ for (i = 0; i < 24; i++) { gchar *hours; if (self->use_24h_format) { hours = g_strdup_printf ("%02d:00", i); } else { hours = g_strdup_printf ("%d %s", i % 12 == 0 ? 12 : i % 12, i > 12 ? _("PM") : _("AM")); } pango_layout_set_text (layout, hours, -1); pango_layout_get_pixel_size (layout, &font_width, NULL); gtk_render_layout (context, cr, ltr ? padding.left : width - font_width - padding.right, (height / 24) * i + padding.top, layout); g_free (hours); } gtk_style_context_restore (context); gtk_style_context_save (context); gtk_style_context_add_class (context, "lines"); gtk_style_context_get_color (context, state, &color); gdk_cairo_set_source_rgba (cr, &color); cairo_set_line_width (cr, 0.65); if (!ltr) { cairo_move_to (cr, 0.5, 0); cairo_rel_line_to (cr, 0, height); } /* Draws the horizontal complete lines */ for (i = 1; i < 24; i++) { cairo_move_to (cr, 0, (height / 24) * i + 0.4); cairo_rel_line_to (cr, width, 0); } cairo_stroke (cr); cairo_set_dash (cr, dashed, 2, 0); /* Draws the horizontal dashed lines */ for (i = 0; i < 24; i++) { cairo_move_to (cr, 0, (height / 24) * i + (height / 48) + 0.4); cairo_rel_line_to (cr, width, 0); } cairo_stroke (cr); gtk_style_context_restore (context); pango_font_description_free (font_desc); g_object_unref (layout); return FALSE; }
static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_lowlight_gui_data_t *c = (dt_iop_lowlight_gui_data_t *)self->gui_data; dt_iop_lowlight_params_t p = *(dt_iop_lowlight_params_t *)self->params; dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); const int inset = DT_IOP_LOWLIGHT_INSET; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int width = allocation.width, height = allocation.height; cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); cairo_set_source_rgb(cr, .2, .2, .2); cairo_paint(cr); cairo_translate(cr, inset, inset); width -= 2 * inset; height -= 2 * inset; cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0)); cairo_set_source_rgb(cr, .1, .1, .1); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); cairo_set_source_rgb(cr, .3, .3, .3); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); // draw grid cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(.4)); cairo_set_source_rgb(cr, .1, .1, .1); dt_draw_grid(cr, 8, 0, 0, width, height); if(c->mouse_y > 0 || c->dragging) { // draw min/max curves: dt_iop_lowlight_get_params(&p, c->mouse_x, 1., c->mouse_radius); dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_min_xs, c->draw_min_ys); p = *(dt_iop_lowlight_params_t *)self->params; dt_iop_lowlight_get_params(&p, c->mouse_x, .0, c->mouse_radius); dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_max_xs, c->draw_max_ys); } cairo_save(cr); // draw x positions cairo_set_source_rgb(cr, 0.6, 0.6, 0.6); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); const float arrw = DT_PIXEL_APPLY_DPI(7.0f); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { cairo_move_to(cr, width * p.transition_x[k], height + inset - DT_PIXEL_APPLY_DPI(1)); cairo_rel_line_to(cr, -arrw * .5f, 0); cairo_rel_line_to(cr, arrw * .5f, -arrw); cairo_rel_line_to(cr, arrw * .5f, arrw); cairo_close_path(cr); if(c->x_move == k) cairo_fill(cr); else cairo_stroke(cr); } // draw selected cursor cairo_translate(cr, 0, height); // cairo_set_operator(cr, CAIRO_OPERATOR_ADD); // cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.)); cairo_set_source_rgba(cr, .7, .7, .7, 1.0); p = *(dt_iop_lowlight_params_t *)self->params; dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_xs, c->draw_ys); cairo_move_to(cr, 0 * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_ys[0]); for(int k = 1; k < DT_IOP_LOWLIGHT_RES; k++) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_ys[k]); cairo_stroke(cr); // draw dots on knots cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { cairo_arc(cr, width * p.transition_x[k], -height * p.transition_y[k], DT_PIXEL_APPLY_DPI(3.0), 0.0, 2.0 * M_PI); if(c->x_move == k) cairo_fill(cr); else cairo_stroke(cr); } if(c->mouse_y > 0 || c->dragging) { // draw min/max, if selected cairo_set_source_rgba(cr, .7, .7, .7, .6); cairo_move_to(cr, 0, -height * c->draw_min_ys[0]); for(int k = 1; k < DT_IOP_LOWLIGHT_RES; k++) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_min_ys[k]); for(int k = DT_IOP_LOWLIGHT_RES - 1; k >= 0; k--) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_max_ys[k]); cairo_close_path(cr); cairo_fill(cr); // draw mouse focus circle cairo_set_source_rgba(cr, .9, .9, .9, .5); const float pos = DT_IOP_LOWLIGHT_RES * c->mouse_x; int k = (int)pos; const float f = k - pos; if(k >= DT_IOP_LOWLIGHT_RES - 1) k = DT_IOP_LOWLIGHT_RES - 2; float ht = -height * (f * c->draw_ys[k] + (1 - f) * c->draw_ys[k + 1]); cairo_arc(cr, c->mouse_x * width, ht, c->mouse_radius * width, 0, 2. * M_PI); cairo_stroke(cr); } cairo_restore(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); // draw labels: PangoLayout *layout; PangoRectangle ink; PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(desc,(.06 * height) * PANGO_SCALE); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, desc); cairo_set_source_rgb(cr, .1, .1, .1); pango_layout_set_text(layout, _("dark"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .02 * width - ink.y, .5 * (height + ink.width)); cairo_save(cr); cairo_rotate(cr, -M_PI * .5f); pango_cairo_show_layout(cr, layout); cairo_restore(cr); pango_layout_set_text(layout, _("bright"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .98 * width - ink.height, .5 * (height + ink.width)); cairo_save(cr); cairo_rotate(cr, -M_PI * .5f); pango_cairo_show_layout(cr, layout); cairo_restore(cr); pango_layout_set_text(layout, _("day vision"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .5 * (width - ink.width), .08 * height - ink.height); pango_cairo_show_layout(cr, layout); pango_layout_set_text(layout, _("night vision"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .5 * (width - ink.width), .97 * height - ink.height); pango_cairo_show_layout(cr, layout); pango_font_description_free(desc); g_object_unref(layout); cairo_destroy(cr); cairo_set_source_surface(crf, cst, 0, 0); cairo_paint(crf); cairo_surface_destroy(cst); return TRUE; }
void validate_menu(GtkTreeIter * iter) { struct validate *validate; GtkWidget *scrolled_window; GtkWidget *text_view; GtkTextBuffer *text_buffer; gboolean updated = FALSE; gdouble scroll_hvalue = 0; gdouble scroll_vvalue = 0; gtk_tree_model_get(GTK_TREE_MODEL(debr.ui_menu.model), iter, MENU_VALIDATE_POINTER, &validate, -1); if (validate != NULL) { updated = TRUE; validate->menu_iter = *iter; scroll_hvalue = gtk_adjustment_get_value(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(validate->widget))); scroll_vvalue = gtk_adjustment_get_value(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(validate->widget))); gtk_text_buffer_set_text(validate->text_buffer, "", 0); goto out; } scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_end(GTK_BOX(debr.ui_validate.text_view_vbox), scrolled_window, TRUE, TRUE, 0); text_buffer = gtk_text_buffer_new(NULL); text_view = gtk_text_view_new_with_buffer(text_buffer); gtk_widget_show(text_view); gtk_container_add(GTK_CONTAINER(scrolled_window), text_view); g_object_set(G_OBJECT(text_view), "editable", FALSE, "cursor-visible", FALSE, NULL); PangoFontDescription *font = pango_font_description_new(); pango_font_description_set_family(font, "monospace"); gtk_widget_modify_font(text_view, font); pango_font_description_free(font); GebrGeoXmlValidateOperations operations; operations.append_text = (void(*)(gpointer,const gchar*,...))validate_append_text; operations.append_text_emph = (void(*)(gpointer,const gchar*,...))validate_append_text_emph; operations.append_text_error = NULL; operations.append_text_error_with_paths = (void(*)(gpointer, gint, const gchar *, const gchar *, GebrValidateCaseName, const gchar *, ...))validate_append_text_error; GebrGeoXmlValidateOptions options; options.all = TRUE; options.ehelp = -1; validate = g_new(struct validate, 1); validate->widget = scrolled_window; validate->text_view = text_view; validate->text_buffer = text_buffer; validate->menu_iter = *iter; validate->geoxml_validate = gebr_geoxml_validate_new(validate, operations, options); gtk_list_store_append(debr.ui_validate.list_store, &validate->iter); out: gtk_tree_store_set(debr.ui_menu.model, iter, MENU_VALIDATE_NEED_UPDATE, FALSE, MENU_VALIDATE_POINTER, validate, -1); GebrGeoXmlFlow * menu = menu_get_xml_pointer(iter); gint error_count = gebr_geoxml_validate_report_menu(validate->geoxml_validate, menu); gtk_list_store_set(debr.ui_validate.list_store, &validate->iter, VALIDATE_ICON, !error_count ? debr.pixmaps.stock_apply : debr.pixmaps.stock_warning, VALIDATE_FILENAME, gebr_geoxml_document_get_filename(GEBR_GEOXML_DOCUMENT(menu)), VALIDATE_POINTER, validate, -1); validate_set_selected(&validate->iter); if (updated) { gtk_adjustment_set_value(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(validate->widget)), scroll_hvalue); gtk_adjustment_set_value(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(validate->widget)), scroll_vvalue); } }
void calendar_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint npage, gpointer user_data) { PangoLayout *layout; PangoFontDescription *month_name_font, *day_name_font, *day_num_font, *event_font; cairo_t *cr; GDate *date; gdouble page_width, page_height, day_width, day_height; gint text_width, text_height, header_height, event_height, mnf_height, dnf_height, duf_height; gint day, month, i, j; guint32 julian; gboolean monday, actual; gchar buffer[BUFFER_SIZE]; gint padding = config.cal_print_padding; GUI *appGUI = (GUI *) user_data; date = g_date_new_julian (g_date_get_julian (appGUI->cal->date)); g_return_if_fail (date != NULL); cr = gtk_print_context_get_cairo_context (context); layout = gtk_print_context_create_pango_layout (context); month_name_font = pango_font_description_from_string (config.cal_print_month_name_font); day_name_font = pango_font_description_from_string (config.cal_print_day_name_font); day_num_font = pango_font_description_from_string (config.cal_print_day_num_font); event_font = pango_font_description_from_string (config.cal_print_event_font); pango_layout_set_text (layout, "Aj", -1); pango_layout_set_font_description (layout, month_name_font); pango_layout_get_pixel_size (layout, NULL, &mnf_height); mnf_height *= 1.2; pango_layout_set_font_description (layout, day_name_font); pango_layout_get_pixel_size (layout, NULL, &dnf_height); dnf_height *= 1.2; pango_layout_set_font_description (layout, day_num_font); pango_layout_get_pixel_size (layout, NULL, &duf_height); page_width = gtk_print_context_get_width (context); day_width = page_width / 7; page_height = gtk_print_context_get_height (context); header_height = mnf_height + dnf_height; day_height = (page_height - header_height) / 6; event_height = day_height - duf_height - padding * 3; cairo_set_line_width (cr, 1); monday = (config.display_options & GUI_CALENDAR_WEEK_START_MONDAY) ? TRUE : FALSE; /* Month and year */ pango_layout_set_font_description (layout, month_name_font); g_date_strftime (buffer, BUFFER_SIZE, "%B %Y", date); pango_layout_set_text (layout, buffer, -1); pango_layout_get_pixel_size (layout, &text_width, NULL); cairo_move_to (cr, (page_width - text_width) / 2, 0); pango_cairo_show_layout (cr, layout); /* Day names */ pango_layout_set_font_description (layout, day_name_font); for (i = 0; i < 7; i++) { g_snprintf (buffer, BUFFER_SIZE, "%s", utl_get_day_name (i + 7 + monday, FALSE)); pango_layout_set_text (layout, buffer, -1); pango_layout_get_pixel_size (layout, &text_width, NULL); cairo_move_to (cr, day_width * i + (day_width - text_width) / 2, mnf_height); pango_cairo_show_layout (cr, layout); } /* Day */ g_date_set_day (date, 1); day = g_date_get_weekday (date); month = g_date_get_month (date); day = monday ? day - 1 : day % 7; if (day > 0) g_date_subtract_days (date, day); day = g_date_get_day (date); julian = g_date_get_julian (date); pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_width (layout, (day_width - padding * 2) * PANGO_SCALE); pango_layout_set_height (layout, event_height * PANGO_SCALE); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); pango_layout_set_indent (layout, -4 * PANGO_SCALE); for (i = 0; i < 6; i++) { for (j = 0; j < 7; j++) { actual = (month == g_date_get_month (date)) ? TRUE : FALSE; day = g_date_get_day (date); cairo_rectangle (cr, day_width * j, header_height + day_height * i, day_width, day_height); if (actual) { cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); } else { cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); } cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); pango_layout_set_font_description (layout, day_num_font); if (actual) { cairo_move_to (cr, day_width * j + padding, header_height + day_height * i + padding); if ((j == 0 && !monday) || (j == 5 && monday) || j == 6) { g_snprintf (buffer, BUFFER_SIZE, "<span color=\"red\">%d</span>", day); } else { g_snprintf (buffer, BUFFER_SIZE, "%d", day); } pango_layout_set_markup (layout, buffer, -1); pango_cairo_show_layout (cr, layout); cal_print_get_events (buffer, julian, appGUI); pango_layout_set_markup (layout, "", -1); pango_layout_set_text (layout, buffer, -1); pango_layout_set_font_description (layout, event_font); pango_layout_get_pixel_size (layout, NULL, &text_height); cairo_move_to (cr, day_width * j + padding, header_height + day_height * (i + 1) - text_height - padding); pango_cairo_show_layout (cr, layout); } else { cairo_move_to (cr, day_width * j + padding, header_height + day_height * i + padding); g_snprintf (buffer, BUFFER_SIZE, "<span color=\"white\">%d</span>", day); pango_layout_set_markup (layout, buffer, -1); pango_cairo_show_layout (cr, layout); } g_date_add_days (date, 1); julian++; } } g_date_free (date); pango_font_description_free (month_name_font); pango_font_description_free (day_name_font); pango_font_description_free (day_num_font); pango_font_description_free (event_font); g_object_unref (layout); }
static void file_info_box_build() { GtkWidget *hbox1, *vbox1; GtkWidget *info_exit, *info_mute; GtkWidget *info_unmute, *info_about; GtkWidget *scrw1; GtkWidget *expander; GdkVisual *visual; PangoFontDescription *desc; info_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_object_set_data(GTK_OBJECT(info_window), "info_window", info_window); gtk_window_set_title(GTK_WINDOW(info_window),"Extended Module Player"); gtk_window_set_policy(GTK_WINDOW(info_window), FALSE, FALSE, TRUE); gtk_signal_connect(GTK_OBJECT(info_window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &info_window); gtk_container_border_width(GTK_CONTAINER(info_window), 0); gtk_widget_realize (info_window); vbox1 = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(info_window), vbox1); gtk_object_set_data(GTK_OBJECT(vbox1), "vbox1", vbox1); gtk_container_border_width(GTK_CONTAINER(vbox1), 4); visual = gdk_visual_get_system(); /* * Image */ frame1 = gtk_event_box_new(); gtk_object_set_data(GTK_OBJECT(frame1), "frame1", frame1); gtk_widget_set_size_request(frame1, 300, 128); gtk_box_pack_start(GTK_BOX(vbox1), frame1, FALSE, FALSE, 0); image = gdk_image_new(GDK_IMAGE_FASTEST, visual, 300, 128); ximage = GDK_IMAGE_XIMAGE(image); image1 = gtk_image_new_from_image(image, NULL); gtk_object_set_data(GTK_OBJECT(image1), "image1", image1); gtk_container_add (GTK_CONTAINER(frame1), image1); gtk_widget_set_events (frame1, GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (frame1), "button_press_event", (GtkSignalFunc)image1_clicked, NULL); /* * Buttons */ hbox1 = gtk_hbox_new (TRUE, 0); gtk_object_set_data(GTK_OBJECT(hbox1), "hbox1", hbox1); gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, FALSE, 0); info_mute = gtk_button_new_with_label("Mute"); gtk_signal_connect (GTK_OBJECT (info_mute), "clicked", (GtkSignalFunc) button_mute, NULL); gtk_object_set_data(GTK_OBJECT(info_mute), "info_mute", info_mute); gtk_box_pack_start(GTK_BOX(hbox1), info_mute, TRUE, TRUE, 0); info_unmute = gtk_button_new_with_label("Unmute"); gtk_signal_connect (GTK_OBJECT (info_unmute), "clicked", (GtkSignalFunc) button_unmute, NULL); gtk_object_set_data(GTK_OBJECT(info_unmute), "info_unmute", info_unmute); gtk_box_pack_start(GTK_BOX(hbox1), info_unmute, TRUE, TRUE, 0); info_about = gtk_button_new_with_label("About"); gtk_signal_connect_object(GTK_OBJECT(info_about), "clicked", (GtkSignalFunc) aboutbox, NULL); gtk_object_set_data(GTK_OBJECT(info_about), "info_about", info_about); gtk_box_pack_start(GTK_BOX(hbox1), info_about, TRUE, TRUE, 0); info_exit = gtk_button_new_with_label("Close"); gtk_signal_connect_object(GTK_OBJECT(info_exit), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(info_window)); gtk_object_set_data(GTK_OBJECT(info_exit), "info_exit", info_exit); gtk_box_pack_start(GTK_BOX(hbox1), info_exit, TRUE, TRUE, 0); /* * Info area */ expander = gtk_expander_new("Module information"); scrw1 = gtk_scrolled_window_new(NULL, NULL); gtk_object_set_data(GTK_OBJECT(scrw1), "scrw1", scrw1); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrw1), GTK_POLICY_ALWAYS, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(expander), scrw1); gtk_box_pack_start(GTK_BOX(vbox1), expander, TRUE, TRUE, 0); gtk_widget_set_size_request(scrw1, 290, 200); text1b = gtk_text_buffer_new(NULL); text1 = gtk_text_view_new_with_buffer(text1b); desc = pango_font_description_new(); pango_font_description_set_family(desc, "Monospace"); gtk_widget_modify_font(text1, desc); pango_font_description_free(desc); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text1), GTK_WRAP_NONE); gtk_object_set_data(GTK_OBJECT(text1), "text1", text1); gtk_container_add(GTK_CONTAINER(scrw1), text1); gtk_widget_realize(text1); gtk_widget_realize(image1); display = GDK_WINDOW_XDISPLAY(info_window->window); window = GDK_WINDOW_XWINDOW(info_window->window); colormap = gdk_colormap_get_system(); gdk_color_black(colormap, color_black); gdk_color_white(colormap, color_white); init_visual(visual); set_palette(); clear_screen(); ii->wresult = 0; panel_setup(); gtk_timeout_add(50, (GtkFunction)panel_loop, NULL); }
void l_prov_usl(short dd,short md,short gd, int podr, int tipz, const char *nomdok, const char *nomdokp, const char *kontr, const char *kodop, int lnds, double sumad,//Сумма по документа double sumkor, //Сумма корректировки к документа float pnds, GtkWidget *wpredok) { class prov_usl_data data; char strsql[512]; SQL_str row; SQLCURSOR cur; iceb_u_str shet_suma; sprintf(data.imaf_prot,"uslpr%d.tmp",getpid()); prosprusw(1,podr,dd,md,gd,nomdok,tipz,lnds,kodop,pnds,NULL,wpredok); prosprusw(2,podr,dd,md,gd,nomdok,tipz,lnds,kodop,pnds,&shet_suma,wpredok); data.tipz=tipz; data.dd=dd; data.md=md; data.gd=gd; data.nomdok.plus(nomdok); data.podr=podr; strcpy(data.metkasys,gettext("УСЛ")); data.kontr.plus(kontr); data.kodop.plus(kodop); data.lnds=lnds; data.nomdokp.plus(nomdokp); data.sumkor=sumkor; data.pnds=pnds; //Читаем наименование склада sprintf(strsql,"select naik from Sklad where kod=%d",podr); if(iceb_sql_readkey(strsql,&row,&cur,wpredok) == 1) data.naim_podr.new_plus(row[0]); //Читаем наименование операции if(tipz == 1) sprintf(strsql,"select naik from Usloper1 where kod='%s'",kodop); if(tipz == 2) sprintf(strsql,"select naik from Usloper2 where kod='%s'",kodop); if(iceb_sql_readkey(strsql,&row,&cur,wpredok) == 1) data.naim_kodop.new_plus(row[0]); //Читаем наименование контрагента sprintf(strsql,"select naikon from Kontragent where kodkon='%s'",kontr); if(iceb_sql_readkey(strsql,&row,&cur,wpredok) == 1) data.naim_kontr.new_plus(row[0]); data.window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_position( GTK_WINDOW(data.window),ICEB_POS_CENTER); gtk_window_set_modal(GTK_WINDOW(data.window),TRUE); sprintf(strsql,"%s %s",name_system, gettext("Работа с проводками (учёт услуг)")); gtk_window_set_title (GTK_WINDOW (data.window),iceb_u_toutf(strsql)); gtk_container_set_border_width (GTK_CONTAINER (data.window), 5); gtk_signal_connect(GTK_OBJECT(data.window),"delete_event",GTK_SIGNAL_FUNC(gtk_widget_destroy),NULL); gtk_signal_connect(GTK_OBJECT(data.window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL); if(wpredok != NULL) { gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR_GDITE)); //Удерживать окно над породившем его окном всегда gtk_window_set_transient_for(GTK_WINDOW(data.window),GTK_WINDOW(wpredok)); //Закрыть окно если окно предок удалено gtk_window_set_destroy_with_parent(GTK_WINDOW(data.window),TRUE); } gtk_signal_connect_after(GTK_OBJECT(data.window),"key_press_event",GTK_SIGNAL_FUNC(prov_usl_key_press),&data); gtk_signal_connect_after(GTK_OBJECT(data.window),"key_release_event",GTK_SIGNAL_FUNC(iceb_key_release),&data.kl_shift); GtkWidget *hbox = gtk_hbox_new (FALSE, 1); gtk_container_add (GTK_CONTAINER (data.window), hbox); GtkWidget *vbox1 = gtk_vbox_new (FALSE, 1); GtkWidget *vbox2 = gtk_vbox_new (FALSE, 1); data.label_sheta=gtk_label_new (shet_suma.ravno_toutf()); PangoFontDescription *font_pango=pango_font_description_from_string(shrift_ravnohir.ravno()); gtk_widget_modify_font(GTK_WIDGET(data.label_sheta),font_pango); pango_font_description_free(font_pango); gtk_box_pack_start (GTK_BOX (hbox), vbox1, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox),data.label_sheta,FALSE, FALSE, 0); gtk_widget_show_all(hbox); data.label_kolstr=gtk_label_new (""); iceb_u_str stroka; prov_usl_sapka_menu(&data); gtk_box_pack_start (GTK_BOX (vbox2),data.label_kolstr,FALSE, FALSE, 0); gtk_widget_show(vbox1); gtk_widget_show(vbox2); data.sw = gtk_scrolled_window_new (NULL, NULL); gtk_widget_set_usize(GTK_WIDGET(data.sw),400,300); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (data.sw),GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (data.sw),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); //gtk_box_pack_start (GTK_BOX (vbox2), data.sw, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox2), data.sw, TRUE, TRUE, 0); GtkWidget *hboxradio = gtk_hbox_new (TRUE, 0); //Вставляем радиокнопки GSList *group; data.radiobutton[0]=gtk_radio_button_new_with_label(NULL,gettext("Дебет")); // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data.radiobutton[0]),TRUE); //Устанавливем активной кнопку gtk_box_pack_start (GTK_BOX (hboxradio),data.radiobutton[0], TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT(data.radiobutton[0]), "clicked",GTK_SIGNAL_FUNC(prov_usl_radio0),&data); //gtk_object_set_user_data(GTK_OBJECT(data.radiobutton0),(gpointer)"0"); group=gtk_radio_button_group(GTK_RADIO_BUTTON(data.radiobutton[0])); sprintf(strsql,"%s",gettext("Кредит")); data.radiobutton[1]=gtk_radio_button_new_with_label(group,strsql); // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data.radiobutton[1]),TRUE); //Устанавливем активной кнопку gtk_signal_connect(GTK_OBJECT(data.radiobutton[1]), "clicked",GTK_SIGNAL_FUNC(prov_usl_radio1),&data); gtk_box_pack_start (GTK_BOX (hboxradio),data.radiobutton[1], TRUE, TRUE, 0); group=gtk_radio_button_group(GTK_RADIO_BUTTON(data.radiobutton[1])); sprintf(strsql,"%s",gettext("Все")); data.radiobutton[2]=gtk_radio_button_new_with_label(group,strsql); // gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data.radiobutton[2]),TRUE); //Устанавливем активной кнопку gtk_signal_connect(GTK_OBJECT(data.radiobutton[2]), "clicked",GTK_SIGNAL_FUNC(prov_usl_radio2),&data); gtk_box_pack_start (GTK_BOX (hboxradio),data.radiobutton[2], TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX (vbox2), hboxradio, FALSE,FALSE, 0); gtk_widget_show_all(hboxradio); //Кнопки GtkTooltips *tooltips[KOL_F_KL]; sprintf(strsql,"F2 %s",gettext("Ввести")); data.knopka[FK2]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[FK2]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK2],TRUE,TRUE, 0); tooltips[FK2]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK2],data.knopka[FK2],gettext("Ввод новой проводки"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK2]),(gpointer)FK2); gtk_widget_show(data.knopka[FK2]); sprintf(strsql,"%sF2 %s",RFK,gettext("Корректировать")); data.knopka[SFK2]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[SFK2]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[SFK2],TRUE,TRUE, 0); tooltips[SFK2]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[SFK2],data.knopka[SFK2],gettext("Корректировка выбранной записи"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[SFK2]),(gpointer)SFK2); gtk_widget_show(data.knopka[SFK2]); sprintf(strsql,"F3 %s",gettext("Удалить")); data.knopka[FK3]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[FK3]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK3],TRUE,TRUE, 0); tooltips[FK3]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK3],data.knopka[FK3],gettext("Удалить выбранную запись"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK3]),(gpointer)FK3); gtk_widget_show(data.knopka[FK3]); sprintf(strsql,"%sF3 %s",RFK,gettext("Удалить")); data.knopka[SFK3]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[SFK3]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[SFK3],TRUE,TRUE, 0); tooltips[SFK3]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[SFK3],data.knopka[SFK3],gettext("Удалить все проводки"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[SFK3]),(gpointer)SFK3); gtk_widget_show(data.knopka[SFK3]); sprintf(strsql,"F4 %s",gettext("Проводки")); data.knopka[FK4]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[FK4]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK4],TRUE,TRUE, 0); tooltips[FK4]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK4],data.knopka[FK4],gettext("Автоматическое выполнение проводок с использованием табличной настройки"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK4]),(gpointer)FK4); gtk_widget_show(data.knopka[FK4]); sprintf(strsql,"%sF4 %s",RFK,gettext("Просмотр")); data.knopka[SFK4]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[SFK4]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[SFK4],TRUE,TRUE, 0); tooltips[SFK4]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[SFK4],data.knopka[SFK4],gettext("Просмотр протокола хода автоматичного виконання проводок"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[SFK4]),(gpointer)SFK4); gtk_widget_show(data.knopka[SFK4]); sprintf(strsql,"F5 %s",gettext("Настройка")); data.knopka[FK5]=gtk_button_new_with_label(strsql); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK5],TRUE,TRUE, 0); gtk_signal_connect(GTK_OBJECT(data.knopka[FK5]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); tooltips[FK5]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK5],data.knopka[FK5],gettext("Насторойка автоматического выполнения проводок"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK5]),(gpointer)FK5); gtk_widget_show(data.knopka[FK5]); sprintf(strsql,"%sF5 %s",RFK,gettext("Печать")); data.knopka[SFK5]=gtk_button_new_with_label(strsql); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[SFK5],TRUE,TRUE, 0); gtk_signal_connect(GTK_OBJECT(data.knopka[SFK5]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); tooltips[SFK5]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[SFK5],data.knopka[SFK5],gettext("Распечатка проводок"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[SFK5]),(gpointer)SFK5); gtk_widget_show(data.knopka[SFK5]); sprintf(strsql,"F6 %s",gettext("Проводки")); data.knopka[FK6]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[FK6]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK6],TRUE,TRUE, 0); tooltips[FK6]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK6],data.knopka[FK6],gettext("Автоматическое выполнение проводок с использованием списка настройки"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK6]),(gpointer)FK6); gtk_widget_show(data.knopka[FK6]); sprintf(strsql,"F9 %s",gettext("Оплата")); data.knopka[FK9]=gtk_button_new_with_label(strsql); gtk_signal_connect(GTK_OBJECT(data.knopka[FK9]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_box_pack_start(GTK_BOX(vbox1), data.knopka[FK9],TRUE,TRUE, 0); tooltips[FK9]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK9],data.knopka[FK9],gettext("Переход в режим ввода и корректировки оплат к документу"),NULL); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK9]),(gpointer)FK9); gtk_widget_show(data.knopka[FK9]); sprintf(strsql,"F10 %s",gettext("Выход")); data.knopka[FK10]=gtk_button_new_with_label(strsql); gtk_box_pack_start(GTK_BOX(vbox1),data.knopka[FK10],TRUE,TRUE, 0); tooltips[FK10]=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips[FK10],data.knopka[FK10],gettext("Завершение работы в этом окне"),NULL); gtk_signal_connect(GTK_OBJECT(data.knopka[FK10]), "clicked",GTK_SIGNAL_FUNC(prov_usl_knopka),&data); gtk_object_set_user_data(GTK_OBJECT(data.knopka[FK10]),(gpointer)FK10); gtk_widget_show(data.knopka[FK10]); gtk_widget_realize(data.window); gdk_window_set_cursor(data.window->window,gdk_cursor_new(ICEB_CURSOR)); gtk_widget_grab_focus(data.knopka[FK10]); prov_usl_create_list(&data); //gtk_window_maximize(GTK_WINDOW(data.window)); //gtk_window_fullscreen(GTK_WINDOW(data.window)); gtk_widget_show(data.window); gtk_main(); if(wpredok != NULL) gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR)); }
gint display_manpage_dbox() { GtkBuilder *builder; GError* error = NULL; GtkWidget *dbox; GtkTextBuffer *txtbuf; GtkWidget *text; FILE *fd; gchar *filename; gchar buffer[32768]; gint len = 0; struct stat stbuf; gint result; PangoFontDescription *font_desc; filename = g_strconcat(inst_paths.manpage_dir, "Manpage.txt", NULL); if (access(filename, F_OK) == 0) { if (stat(filename, &stbuf) != -1) { len = stbuf.st_size; len -= 2; } if ((fd = fopen(filename, "r")) != NULL) { memset(buffer, 0, sizeof(buffer)); len = fread(buffer, 1, len, fd); fclose(fd); } } builder = gtk_builder_new(); if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("manpage.ui"), &error)) { g_warning (_("Couldn't load builder file: %s\n"), error->message); g_error_free (error); return 0; // THIS RETURNS ! } gtk_builder_connect_signals(builder, NULL); dbox = GTK_WIDGET (gtk_builder_get_object (builder, "manpage_dbox")); text = GTK_WIDGET (gtk_builder_get_object (builder, "textview1")); // Change font font_desc = pango_font_description_from_string ("Courier"); gtk_widget_modify_font (text, font_desc); pango_font_description_free (font_desc); // Set text txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); gtk_text_buffer_set_text(txtbuf, buffer, len); result = gtk_dialog_run(GTK_DIALOG(dbox)); switch (result) { case GTK_RESPONSE_OK: break; default: break; } gtk_widget_destroy(dbox); return 0; }
int main (int argc, char **argv) { GtkStyleContext *style; PangoFontDescription *font_desc; GtkWidget *window; GtkWidget *collection; GError *err; clock_t start, end; GtkWidget *notebook; int i; bindtextdomain (GETTEXT_PACKAGE, MUTTER_LOCALEDIR); textdomain(GETTEXT_PACKAGE); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); run_position_expression_tests (); #if 0 run_position_expression_timings (); #endif gtk_init (&argc, &argv); if (g_getenv ("MUTTER_DEBUG") != NULL) { meta_set_debugging (TRUE); meta_set_verbose (TRUE); } start = clock (); err = NULL; if (argc == 1) global_theme = meta_theme_load ("Atlanta", &err); else if (argc == 2) global_theme = meta_theme_load (argv[1], &err); else { g_printerr (_("Usage: metacity-theme-viewer [THEMENAME]\n")); exit (1); } end = clock (); if (global_theme == NULL) { g_printerr (_("Error loading theme: %s\n"), err->message); g_error_free (err); exit (1); } g_print (_("Loaded theme \"%s\" in %g seconds\n"), global_theme->name, (end - start) / (double) CLOCKS_PER_SEC); run_theme_benchmark (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); if (strcmp (global_theme->name, global_theme->readable_name)==0) gtk_window_set_title (GTK_WINDOW (window), global_theme->readable_name); else { /* The theme directory name is different from the name the theme * gives itself within its file. Display both, directory name first. */ gchar *title = g_strconcat (global_theme->name, " - ", global_theme->readable_name, NULL); gtk_window_set_title (GTK_WINDOW (window), title); g_free (title); } g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_realize (window); style = meta_theme_create_style_context (gtk_widget_get_screen (window), NULL); gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); g_assert (style); g_assert (font_desc); notebook = gtk_notebook_new (); gtk_container_add (GTK_CONTAINER (window), notebook); collection = preview_collection (FONT_SIZE_NORMAL, font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Normal Title Font"))); collection = preview_collection (FONT_SIZE_SMALL, font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Small Title Font"))); collection = preview_collection (FONT_SIZE_LARGE, font_desc); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Large Title Font"))); collection = previews_of_button_layouts (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Button Layouts"))); collection = benchmark_summary (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), collection, gtk_label_new (_("Benchmark"))); pango_font_description_free (font_desc); i = 0; while (i < (int) G_N_ELEMENTS (previews)) { /* preview widget likes to be realized before its size request. * it's lame that way. */ gtk_widget_realize (previews[i]); ++i; } gtk_widget_show_all (window); gtk_main (); return 0; }
static void terminal_profile_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { TerminalProfile *profile = TERMINAL_PROFILE (object); TerminalProfilePrivate *priv = profile->priv; GValue *prop_value; if (prop_id == 0 || prop_id >= LAST_PROP) { G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); return; } prop_value = g_value_array_get_nth (priv->properties, prop_id); /* Preprocessing */ switch (prop_id) { #if 0 case PROP_FONT: { PangoFontDescription *font_desc, *new_font_desc; font_desc = g_value_get_boxed (prop_value); new_font_desc = g_value_get_boxed (value); if (font_desc && new_font_desc) { /* Merge in case the new string isn't complete enough to load a font */ pango_font_description_merge (font_desc, new_font_desc, TRUE); pango_font_description_free (new_font_desc); break; } /* fall-through */ } #endif default: g_value_copy (value, prop_value); break; } /* Postprocessing */ switch (prop_id) { case PROP_NAME: { const char *name = g_value_get_string (value); g_assert (name != NULL); priv->profile_dir = g_strdup (name); if (priv->settings != NULL) { g_signal_handlers_disconnect_by_func (priv->settings, G_CALLBACK(terminal_profile_gsettings_notify_cb), profile); g_object_unref (priv->settings); priv->settings = g_settings_new_with_path (CONF_PROFILE_SCHEMA, g_strconcat (CONF_PROFILE_PREFIX, priv->profile_dir, "/", NULL)); g_signal_connect (priv->settings, g_strconcat("changed::", priv->profile_dir, "/", NULL), G_CALLBACK(terminal_profile_gsettings_notify_cb), profile); } break; } case PROP_BACKGROUND_IMAGE_FILE: /* Clear the cached image */ g_value_set_object (g_value_array_get_nth (priv->properties, PROP_BACKGROUND_IMAGE), NULL); priv->background_load_failed = FALSE; g_object_notify (object, TERMINAL_PROFILE_BACKGROUND_IMAGE); break; default: break; } }
gint display_manpage_dbox() { GladeXML *xml; GtkWidget *dbox; GtkTextBuffer *txtbuf; GtkWidget *text; FILE *fd; gchar *filename; gchar buffer[32768]; gint len = 0; struct stat stbuf; gint result; PangoFontDescription *font_desc; filename = g_strconcat(inst_paths.manpage_dir, "Manpage.txt", NULL); if (access(filename, F_OK) == 0) { if (stat(filename, &stbuf) != -1) { len = stbuf.st_size; len -= 2; } if ((fd = fopen(filename, "r")) != NULL) { memset(buffer, 0, sizeof(buffer)); len = fread(buffer, 1, len, fd); fclose(fd); } } xml = glade_xml_new(tilp_paths_build_glade("manpage-2.glade"), "manpage_dbox", PACKAGE); if (!xml) g_error("GUI loading failed !\n"); glade_xml_signal_autoconnect(xml); dbox = glade_xml_get_widget(xml, "manpage_dbox"); text = glade_xml_get_widget(xml, "textview1"); // Change font font_desc = pango_font_description_from_string ("Courier"); gtk_widget_modify_font (text, font_desc); pango_font_description_free (font_desc); // Set text txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); gtk_text_buffer_set_text(txtbuf, buffer, len); result = gtk_dialog_run(GTK_DIALOG(dbox)); switch (result) { case GTK_RESPONSE_OK: break; default: break; } gtk_widget_destroy(dbox); return 0; }
static void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { PrintData *data = (PrintData *)user_data; cairo_t *cr; PangoLayout *layout; gint text_width, text_height; gdouble width; gint line, i; PangoFontDescription *desc; gchar *page_str; cr = gtk_print_context_get_cairo_context (context); width = gtk_print_context_get_width (context); cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT); cairo_set_source_rgb (cr, 0.8, 0.8, 0.8); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 1); cairo_stroke (cr); layout = gtk_print_context_create_pango_layout (context); desc = pango_font_description_from_string ("sans 14"); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_text (layout, data->filename, -1); pango_layout_get_pixel_size (layout, &text_width, &text_height); if (text_width > width) { pango_layout_set_width (layout, width); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START); pango_layout_get_pixel_size (layout, &text_width, &text_height); } cairo_move_to (cr, (width - text_width) / 2, (HEADER_HEIGHT - text_height) / 2); pango_cairo_show_layout (cr, layout); page_str = g_strdup_printf ("%d/%d", page_nr + 1, data->num_pages); pango_layout_set_text (layout, page_str, -1); g_free (page_str); pango_layout_set_width (layout, -1); pango_layout_get_pixel_size (layout, &text_width, &text_height); cairo_move_to (cr, width - text_width - 4, (HEADER_HEIGHT - text_height) / 2); pango_cairo_show_layout (cr, layout); g_object_unref (layout); layout = gtk_print_context_create_pango_layout (context); desc = pango_font_description_from_string ("monospace"); pango_font_description_set_size (desc, data->font_size * PANGO_SCALE); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); cairo_move_to (cr, 0, HEADER_HEIGHT + HEADER_GAP); line = page_nr * data->lines_per_page; for (i = 0; i < data->lines_per_page && line < data->num_lines; i++) { pango_layout_set_text (layout, data->lines[line], -1); pango_cairo_show_layout (cr, layout); cairo_rel_move_to (cr, 0, data->font_size); line++; } g_object_unref (layout); }
static GtkWidget* preview_collection (int font_size, PangoFontDescription *base_desc) { GtkWidget *box; GtkWidget *sw; GdkColor desktop_color; int i; GtkWidget *eventbox; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); box = gtk_vbox_new (FALSE, 0); gtk_box_set_spacing (GTK_BOX (box), 20); gtk_container_set_border_width (GTK_CONTAINER (box), 20); eventbox = gtk_event_box_new (); gtk_container_add (GTK_CONTAINER (eventbox), box); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), eventbox); desktop_color.red = 0x5144; desktop_color.green = 0x75D6; desktop_color.blue = 0xA699; gtk_widget_modify_bg (eventbox, GTK_STATE_NORMAL, &desktop_color); i = 0; while (i < META_FRAME_TYPE_LAST) { const char *title = NULL; GtkWidget *contents; GtkWidget *align; double xalign, yalign; GtkWidget *eventbox2; GtkWidget *preview; PangoFontDescription *font_desc; double scale; eventbox2 = gtk_event_box_new (); preview = meta_preview_new (); gtk_container_add (GTK_CONTAINER (eventbox2), preview); meta_preview_set_frame_type (META_PREVIEW (preview), i); meta_preview_set_frame_flags (META_PREVIEW (preview), get_window_flags (i)); meta_preview_set_theme (META_PREVIEW (preview), global_theme); contents = get_window_contents (i, &title); meta_preview_set_title (META_PREVIEW (preview), title); gtk_container_add (GTK_CONTAINER (preview), contents); if (i == META_FRAME_TYPE_MENU) { xalign = 0.0; yalign = 0.0; } else { xalign = 0.5; yalign = 0.5; } align = gtk_alignment_new (0.0, 0.0, xalign, yalign); gtk_container_add (GTK_CONTAINER (align), eventbox2); gtk_box_pack_start (GTK_BOX (box), align, TRUE, TRUE, 0); switch (font_size) { case FONT_SIZE_SMALL: scale = PANGO_SCALE_XX_SMALL; break; case FONT_SIZE_LARGE: scale = PANGO_SCALE_XX_LARGE; break; default: scale = 1.0; break; } if (scale != 1.0) { font_desc = pango_font_description_new (); pango_font_description_set_size (font_desc, MAX (pango_font_description_get_size (base_desc) * scale, 1)); gtk_widget_modify_font (preview, font_desc); pango_font_description_free (font_desc); } previews[font_size*META_FRAME_TYPE_LAST + i] = preview; ++i; } return sw; }
static void init_tree() { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeStore *store; int i; PangoFontDescription *font_desc = pango_font_description_from_string(prefs.divelist_font); gtk_widget_modify_font(yearly_tree, font_desc); pango_font_description_free(font_desc); renderer = gtk_cell_renderer_text_new (); /* don't use empty strings "" - they confuse gettext */ char *columnstop[] = { N_("Year"), N_("#"), N_("Duration"), " ", " ", " ", N_("Depth"), " ", " ", N_("SAC"), " ", " ", N_("Temperature"), " ", " " }; const char *columnsbot[15]; columnsbot[0] = C_("Stats", " > Month"); columnsbot[1] = " "; columnsbot[2] = C_("Duration","Total"); columnsbot[3] = C_("Duration","Average"); columnsbot[4] = C_("Duration","Shortest"); columnsbot[5] = C_("Duration","Longest"); columnsbot[6] = C_("Depth", "Average"); columnsbot[7] = C_("Depth","Minimum"); columnsbot[8] = C_("Depth","Maximum"); columnsbot[9] = C_("SAC","Average"); columnsbot[10]= C_("SAC","Minimum"); columnsbot[11]= C_("SAC","Maximum"); columnsbot[12]= C_("Temp","Average"); columnsbot[13]= C_("Temp","Minimum"); columnsbot[14]= C_("Temp","Maximum"); /* Add all the columns to the tree view */ for (i = 0; i < N_COLUMNS; ++i) { char buf[256]; column = gtk_tree_view_column_new(); snprintf(buf, sizeof(buf), "%s\n%s", _(columnstop[i]), columnsbot[i]); gtk_tree_view_column_set_title(column, buf); gtk_tree_view_append_column(GTK_TREE_VIEW(yearly_tree), column); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_add_attribute(column, renderer, "text", i); gtk_tree_view_column_set_resizable(column, TRUE); } /* Field types */ store = gtk_tree_store_new ( N_COLUMNS, // Columns in structure G_TYPE_STRING, // Period (year or month) G_TYPE_STRING, // Number of dives G_TYPE_STRING, // Total duration G_TYPE_STRING, // Average dive duation G_TYPE_STRING, // Shortest dive G_TYPE_STRING, // Longest dive G_TYPE_STRING, // Average depth G_TYPE_STRING, // Shallowest dive G_TYPE_STRING, // Deepest dive G_TYPE_STRING, // Average air consumption (SAC) G_TYPE_STRING, // Minimum SAC G_TYPE_STRING, // Maximum SAC G_TYPE_STRING, // Average temperature G_TYPE_STRING, // Minimum temperature G_TYPE_STRING // Maximum temperature ); gtk_tree_view_set_model (GTK_TREE_VIEW (yearly_tree), GTK_TREE_MODEL (store)); g_object_unref (store); }
FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) : m_context(0) , m_font(0) , m_size(fontDescription.computedSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_scaledFont(0) { FontPlatformData::init(); CString stored_family = familyName.string().utf8(); char const* families[] = { stored_family.data(), NULL }; switch (fontDescription.genericFamily()) { case FontDescription::SerifFamily: families[1] = "serif"; break; case FontDescription::SansSerifFamily: families[1] = "sans"; break; case FontDescription::MonospaceFamily: families[1] = "monospace"; break; case FontDescription::NoFamily: case FontDescription::StandardFamily: default: families[1] = "sans"; break; } PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE); // FIXME: Map all FontWeight values to Pango font weights. if (fontDescription.weight() >= FontWeight600) pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); if (fontDescription.italic()) pango_font_description_set_style(description, PANGO_STYLE_ITALIC); #if PANGO_VERSION_CHECK(1,21,5) // deprecated in 1.21 m_context = pango_font_map_create_context(m_fontMap); #else m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap)); #endif for (unsigned int i = 0; !m_font && i < G_N_ELEMENTS(families); i++) { pango_font_description_set_family(description, families[i]); pango_context_set_font_description(m_context, description); m_font = pango_font_map_load_font(m_fontMap, m_context, description); } #if PANGO_VERSION_CHECK(1,18,0) if (m_font) m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font))); #else // This compatibility code for older versions of Pango is not well-tested. if (m_font) { PangoFcFont* fcfont = PANGO_FC_FONT(m_font); cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern); double size; if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) size = 12.0; cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_font_options_t* fontOptions; if (pango_cairo_context_get_font_options(m_context)) fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context)); else fontOptions = cairo_font_options_create(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); cairo_font_face_destroy(face); } #endif pango_font_description_free(description); }
static void rotated_text_draw (GtkDrawingArea *da, cairo_t *cr, int width, int height, gpointer data) { #define RADIUS 150 #define N_WORDS 5 #define FONT "Serif 18" PangoContext *context; PangoLayout *layout; PangoFontDescription *desc; cairo_pattern_t *pattern; PangoAttrList *attrs; double device_radius; int i; /* Create a cairo context and set up a transformation matrix so that the user * space coordinates for the centered square where we draw are [-RADIUS, RADIUS], * [-RADIUS, RADIUS]. * We first center, then change the scale. */ device_radius = MIN (width, height) / 2.; cairo_translate (cr, device_radius + (width - 2 * device_radius) / 2, device_radius + (height - 2 * device_radius) / 2); cairo_scale (cr, device_radius / RADIUS, device_radius / RADIUS); /* Create and a subtle gradient source and use it. */ pattern = cairo_pattern_create_linear (-RADIUS, -RADIUS, RADIUS, RADIUS); cairo_pattern_add_color_stop_rgb (pattern, 0., .5, .0, .0); cairo_pattern_add_color_stop_rgb (pattern, 1., .0, .0, .5); cairo_set_source (cr, pattern); /* Create a PangoContext and set up our shape renderer */ context = gtk_widget_create_pango_context (GTK_WIDGET (da)); pango_cairo_context_set_shape_renderer (context, fancy_shape_renderer, NULL, NULL); /* Create a PangoLayout, set the text, font, and attributes */ layout = pango_layout_new (context); pango_layout_set_text (layout, text, -1); desc = pango_font_description_from_string (FONT); pango_layout_set_font_description (layout, desc); attrs = create_fancy_attr_list_for_layout (layout); pango_layout_set_attributes (layout, attrs); pango_attr_list_unref (attrs); /* Draw the layout N_WORDS times in a circle */ for (i = 0; i < N_WORDS; i++) { int width, height; /* Inform Pango to re-layout the text with the new transformation matrix */ pango_cairo_update_layout (cr, layout); pango_layout_get_pixel_size (layout, &width, &height); cairo_move_to (cr, - width / 2, - RADIUS * .9); pango_cairo_show_layout (cr, layout); /* Rotate for the next turn */ cairo_rotate (cr, G_PI*2 / N_WORDS); } /* free the objects we created */ pango_font_description_free (desc); g_object_unref (layout); g_object_unref (context); cairo_pattern_destroy (pattern); }
static boolean pango_textlayout(textspan_t * span, char **fontpath) { static char buf[1024]; /* returned in fontpath, only good until next call */ static PangoFontMap *fontmap; static PangoContext *context; static PangoFontDescription *desc; static char *fontname; static double fontsize; static gv_font_map* gv_fmap; char *fnt, *psfnt = NULL; PangoLayout *layout; PangoRectangle logical_rect; cairo_font_options_t* options; PangoFont *font; #ifdef ENABLE_PANGO_MARKUP PangoAttrList *attrs; GError *error = NULL; int flags; #endif char *text; double textlayout_scale; PostscriptAlias *pA; if (!context) { fontmap = pango_cairo_font_map_new(); gv_fmap = get_font_mapping(fontmap); #ifdef HAVE_PANGO_FONT_MAP_CREATE_CONTEXT context = pango_font_map_create_context (fontmap); #else context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap)); #endif options=cairo_font_options_create(); cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); pango_cairo_context_set_font_options(context, options); pango_cairo_context_set_resolution(context, FONT_DPI); cairo_font_options_destroy(options); g_object_unref(fontmap); } if (!fontname || strcmp(fontname, span->font->name) != 0 || fontsize != span->font->size) { fontname = span->font->name; fontsize = span->font->size; pango_font_description_free (desc); pA = span->font->postscript_alias; if (pA) { psfnt = fnt = gv_fmap[pA->xfig_code].gv_font; if(!psfnt) psfnt = fnt = pango_psfontResolve (pA); } else fnt = fontname; desc = pango_font_description_from_string(fnt); /* all text layout is done at a scale of FONT_DPI (nominaly 96.) */ pango_font_description_set_size (desc, (gint)(fontsize * PANGO_SCALE)); if (fontpath && (font = pango_font_map_load_font(fontmap, context, desc))) { /* -v support */ const char *fontclass; fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font)); buf[0] = '\0'; if (psfnt) { strcat(buf, "(ps:pango "); strcat(buf, psfnt); strcat(buf, ") "); } strcat(buf, "("); strcat(buf, fontclass); strcat(buf, ") "); #ifdef HAVE_PANGO_FC_FONT_LOCK_FACE if (strcmp(fontclass, "PangoCairoFcFont") == 0) { FT_Face face; PangoFcFont *fcfont; FT_Stream stream; FT_StreamDesc streamdesc; fcfont = PANGO_FC_FONT(font); face = pango_fc_font_lock_face(fcfont); if (face) { strcat(buf, "\""); strcat(buf, face->family_name); strcat(buf, ", "); strcat(buf, face->style_name); strcat(buf, "\" "); stream = face->stream; if (stream) { streamdesc = stream->pathname; if (streamdesc.pointer) strcat(buf, (char*)streamdesc.pointer); else strcat(buf, "*no pathname available*"); } else strcat(buf, "*no stream available*"); } pango_fc_font_unlock_face(fcfont); } else #endif { PangoFontDescription *tdesc; char *tfont; tdesc = pango_font_describe(font); tfont = pango_font_description_to_string(tdesc); strcat(buf, "\""); strcat(buf, tfont); strcat(buf, "\" "); g_free(tfont); } *fontpath = buf; } } #ifdef ENABLE_PANGO_MARKUP if ((span->font) && (flags = span->font->flags)) { unsigned char buf[BUFSIZ]; agxbuf xb; agxbinit(&xb, BUFSIZ, buf); agxbput(&xb,"<span"); if (flags & HTML_BF) agxbput(&xb," weight=\"bold\""); if (flags & HTML_IF) agxbput(&xb," style=\"italic\""); if (flags & HTML_UL) agxbput(&xb," underline=\"single\""); if (flags & HTML_S) agxbput(&xb," strikethrough=\"true\""); agxbput (&xb,">"); if (flags & HTML_SUP) agxbput(&xb,"<sup>"); if (flags & HTML_SUB) agxbput(&xb,"<sub>"); agxbput (&xb,xml_string0(span->str, TRUE)); if (flags & HTML_SUB) agxbput(&xb,"</sub>"); if (flags & HTML_SUP) agxbput(&xb,"</sup>"); agxbput (&xb,"</span>"); if (!pango_parse_markup (agxbuse(&xb), -1, 0, &attrs, &text, NULL, &error)) { fprintf (stderr, "Error - pango_parse_markup: %s\n", error->message); text = span->str; attrs = NULL; } agxbfree (&xb); } else { text = span->str; attrs = NULL; } #else text = span->str; #endif layout = pango_layout_new (context); span->layout = (void *)layout; /* layout free with textspan - see labels.c */ span->free_layout = pango_free_layout; /* function for freeing pango layout */ pango_layout_set_text (layout, text, -1); pango_layout_set_font_description (layout, desc); #ifdef ENABLE_PANGO_MARKUP if (attrs) pango_layout_set_attributes (layout, attrs); #endif pango_layout_get_extents (layout, NULL, &logical_rect); /* if pango doesn't like the font then it sets width=0 but height = garbage */ if (logical_rect.width == 0) logical_rect.height = 0; textlayout_scale = POINTS_PER_INCH / (FONT_DPI * PANGO_SCALE); span->size.x = (int)(logical_rect.width * textlayout_scale + 1); /* round up so that width/height are never too small */ span->size.y = (int)(logical_rect.height * textlayout_scale + 1); /* FIXME -- Horrible kluge !!! */ /* For now we are using pango for single line blocks only. * The logical_rect.height seems to be too high from the font metrics on some platforms. * Use an assumed height based on the point size. */ span->size.y = (int)(span->font->size * 1.1 + .5); /* The y offset from baseline to 0,0 of the bitmap representation */ #if !defined(WIN32) && defined PANGO_VERSION_MAJOR && (PANGO_VERSION_MAJOR >= 1) span->yoffset_layout = pango_layout_get_baseline (layout) * textlayout_scale; #else { /* do it the hard way on rhel5/centos5 */ PangoLayoutIter *iter = pango_layout_get_iter (layout); span->yoffset_layout = pango_layout_iter_get_baseline (iter) * textlayout_scale; } #endif /* The distance below midline for y centering of text strings */ span->yoffset_centerline = 0.2 * span->font->size; if (logical_rect.width == 0) return FALSE; return TRUE; }
static PangoCairoFontHexBoxInfo * _pango_cairo_font_private_get_hex_box_info (PangoCairoFontPrivate *cf_priv) { const char hexdigits[] = "0123456789ABCDEF"; char c[2] = {0, 0}; PangoFont *mini_font; PangoCairoFontHexBoxInfo *hbi; /* for metrics hinting */ double scale_x = 1., scale_x_inv = 1., scale_y = 1., scale_y_inv = 1.; gboolean is_hinted; int i; int rows; double pad; double width = 0; double height = 0; cairo_font_options_t *font_options; cairo_font_extents_t font_extents; double size, mini_size; PangoFontDescription *desc; cairo_scaled_font_t *scaled_font, *scaled_mini_font; PangoMatrix pango_ctm; cairo_matrix_t cairo_ctm; /*PangoGravity gravity;*/ if (!cf_priv) return NULL; if (cf_priv->hbi) return cf_priv->hbi; scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv); if (G_UNLIKELY (scaled_font == NULL || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS)) return NULL; is_hinted = cf_priv->is_hinted; font_options = cairo_font_options_create (); desc = pango_font_describe_with_absolute_size ((PangoFont *)cf_priv->cfont); size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE); /*gravity = pango_font_description_get_gravity (desc);*/ cairo_scaled_font_get_ctm (scaled_font, &cairo_ctm); cairo_scaled_font_get_font_options (scaled_font, font_options); /* I started adding support for vertical hexboxes here, but it's too much * work. Easier to do with cairo user fonts and vertical writing mode * support in cairo. */ /*cairo_matrix_rotate (&cairo_ctm, pango_gravity_to_rotation (gravity));*/ pango_ctm.xx = cairo_ctm.xx; pango_ctm.yx = cairo_ctm.yx; pango_ctm.xy = cairo_ctm.xy; pango_ctm.yy = cairo_ctm.yy; pango_ctm.x0 = cairo_ctm.x0; pango_ctm.y0 = cairo_ctm.y0; size /= pango_matrix_get_font_scale_factor (&pango_ctm); if (is_hinted) { /* prepare for some hinting */ double x, y; x = 1.; y = 0.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_x = sqrt (x*x + y*y); scale_x_inv = 1 / scale_x; x = 0.; y = 1.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_y = sqrt (x*x + y*y); scale_y_inv = 1 / scale_y; } /* we hint to the nearest device units */ #define HINT(value, scale, scale_inv) (ceil ((value-1e-5) * scale) * scale_inv) #define HINT_X(value) HINT ((value), scale_x, scale_x_inv) #define HINT_Y(value) HINT ((value), scale_y, scale_y_inv) /* create mini_font description */ { PangoFontMap *fontmap; PangoContext *context; /* XXX this is racy. need a ref'ing getter... */ fontmap = pango_font_get_font_map ((PangoFont *)cf_priv->cfont); if (!fontmap) return NULL; fontmap = g_object_ref (fontmap); /* we inherit most font properties for the mini font. just * change family and size. means, you get bold hex digits * in the hexbox for a bold font. */ /* We should rotate the box, not glyphs */ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY); pango_font_description_set_family_static (desc, "monospace"); rows = 2; mini_size = size / 2.2; if (is_hinted) { mini_size = HINT_Y (mini_size); if (mini_size < 6.0) { rows = 1; mini_size = MIN (MAX (size - 1, 0), 6.0); } } pango_font_description_set_absolute_size (desc, pango_units_from_double (mini_size)); /* load mini_font */ context = pango_font_map_create_context (fontmap); pango_context_set_matrix (context, &pango_ctm); pango_context_set_language (context, pango_script_get_sample_language (PANGO_SCRIPT_LATIN)); pango_cairo_context_set_font_options (context, font_options); mini_font = pango_font_map_load_font (fontmap, context, desc); g_object_unref (context); g_object_unref (fontmap); } pango_font_description_free (desc); cairo_font_options_destroy (font_options); scaled_mini_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *) mini_font); if (G_UNLIKELY (scaled_mini_font == NULL || cairo_scaled_font_status (scaled_mini_font) != CAIRO_STATUS_SUCCESS)) return NULL; for (i = 0 ; i < 16 ; i++) { cairo_text_extents_t extents; c[0] = hexdigits[i]; cairo_scaled_font_text_extents (scaled_mini_font, c, &extents); width = MAX (width, extents.width); height = MAX (height, extents.height); } cairo_scaled_font_extents (scaled_font, &font_extents); if (font_extents.ascent + font_extents.descent <= 0) { font_extents.ascent = PANGO_UNKNOWN_GLYPH_HEIGHT; font_extents.descent = 0; } pad = (font_extents.ascent + font_extents.descent) / 43; pad = MIN (pad, mini_size); hbi = g_slice_new (PangoCairoFontHexBoxInfo); hbi->font = (PangoCairoFont *) mini_font; hbi->rows = rows; hbi->digit_width = width; hbi->digit_height = height; hbi->pad_x = pad; hbi->pad_y = pad; if (is_hinted) { hbi->digit_width = HINT_X (hbi->digit_width); hbi->digit_height = HINT_Y (hbi->digit_height); hbi->pad_x = HINT_X (hbi->pad_x); hbi->pad_y = HINT_Y (hbi->pad_y); } hbi->line_width = MIN (hbi->pad_x, hbi->pad_y); hbi->box_height = 3 * hbi->pad_y + rows * (hbi->pad_y + hbi->digit_height); if (rows == 1 || hbi->box_height <= font_extents.ascent) { hbi->box_descent = 2 * hbi->pad_y; } else if (hbi->box_height <= font_extents.ascent + font_extents.descent - 2 * hbi->pad_y) { hbi->box_descent = 2 * hbi->pad_y + hbi->box_height - font_extents.ascent; } else { hbi->box_descent = font_extents.descent * hbi->box_height / (font_extents.ascent + font_extents.descent); } if (is_hinted) { hbi->box_descent = HINT_Y (hbi->box_descent); } cf_priv->hbi = hbi; return hbi; }
static gboolean gtk_switch_draw (GtkWidget *widget, cairo_t *cr) { GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkStyleContext *context; GdkRectangle handle; PangoLayout *layout; PangoFontDescription *desc; const PangoFontDescription *style_desc; PangoRectangle rect; gint label_x, label_y; GtkStateFlags state; GtkBorder padding; gint focus_width, focus_pad; gint x, y, width, height; gint font_size, style_font_size; gtk_widget_style_get (widget, "focus-line-width", &focus_width, "focus-padding", &focus_pad, NULL); context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); if (priv->is_active) state |= GTK_STATE_FLAG_ACTIVE; gtk_style_context_save (context); gtk_style_context_set_state (context, state); gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER); gtk_style_context_get_padding (context, state, &padding); gtk_style_context_restore (context); x = 0; y = 0; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); if (gtk_widget_has_focus (widget)) gtk_render_focus (context, cr, x, y, width, height); x += focus_width + focus_pad; y += focus_width + focus_pad; width -= 2 * (focus_width + focus_pad); height -= 2 * (focus_width + focus_pad); gtk_style_context_save (context); gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); gtk_style_context_set_state (context, state); gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); width -= padding.left + padding.right; height -= padding.top + padding.bottom; x += padding.left; y += padding.top; handle.y = y; handle.width = width / 2; handle.height = height; /* Translators: if the "on" state label requires more than three * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for * the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON")); /* FIXME: this should be really done in the theme, but overriding font size * from it doesn't currently work. So we have to hardcode this here and * below for the "OFF" label. */ desc = pango_font_description_new (); style_desc = gtk_style_context_get_font (context, state); style_font_size = pango_font_description_get_size (style_desc); font_size = MAX (style_font_size - 1 * PANGO_SCALE, ceil (style_font_size * PANGO_SCALE_SMALL)); pango_font_description_set_size (desc, font_size); pango_layout_set_font_description (layout, desc); pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); label_x = x + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_render_layout (context, cr, label_x, label_y, layout); g_object_unref (layout); /* Translators: if the "off" state label requires more than three * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF")); pango_layout_set_font_description (layout, desc); pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); label_x = x + (width / 2) + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_render_layout (context, cr, label_x, label_y, layout); g_object_unref (layout); if (priv->is_dragging) handle.x = x + priv->handle_x; else if (priv->is_active) handle.x = x + width - handle.width; else handle.x = x; gtk_style_context_restore (context); gtk_switch_paint_handle (widget, cr, &handle); pango_font_description_free (desc); return FALSE; }
void gc_help_start (GcomprisBoard *gcomprisBoard) { gchar *item_id = "#UP"; GooCanvasItem *item; gint y = 0; gint y_start = 0; gint x_start = 0; gchar *name = NULL; gchar *text_to_display = NULL; if(rootitem) return; gc_board_pause(TRUE); caller_cursor = gc_cursor_get(); gc_cursor_set(GCOMPRIS_DEFAULT_CURSOR); item_selected = NULL; item_selected_text = NULL; name = gcomprisBoard->title; gc_help_has_board(gcomprisBoard); rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#DIALOG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); GooCanvasBounds bounds; guint pixmap_width = 40; goo_canvas_item_get_bounds(item, &bounds); x_start = bounds.x1; y_start = bounds.y1; y = bounds.y2 - 26; y_start += 15; if(gcomprisBoard->section && gcomprisBoard->name) { text_to_display = g_strdup_printf("%s/%s", gcomprisBoard->section, gcomprisBoard->name); goo_canvas_text_new (rootitem, text_to_display, BOARDWIDTH*0.10, y_start, -1, GTK_ANCHOR_NW, "font", gc_skin_font_board_tiny, "fill-color-rgba", gc_skin_color_title, NULL); g_free(text_to_display); } y_start += 30; goo_canvas_text_new (rootitem, name, BOARDWIDTH/2, y_start, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); y_start += 80; // Prerequisite Button if(prerequisite) { item_prerequisite = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_prerequisite, (BOARDWIDTH*0.2) - pixmap_width/2, y_start - 10) g_signal_connect(item_prerequisite, "button_press_event", (GCallback) item_event_help, "prerequisite"); gc_item_focus_init(item_prerequisite, NULL); item_prerequisite_text = \ goo_canvas_text_new (rootitem, _("Prerequisite"), BOARDWIDTH*0.20, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_prerequisite_text, "button_press_event", (GCallback) item_event_help, "prerequisite"); } // Goal Button if(goal) { item_goal = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_goal, (BOARDWIDTH*0.4) - pixmap_width/2, y_start - 10); g_signal_connect(item_goal, "button_press_event", (GCallback) item_event_help, "goal"); gc_item_focus_init(item_goal, NULL); item_goal_text = goo_canvas_text_new (rootitem, _("Goal"), BOARDWIDTH*0.4, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_goal_text, "button_press_event", (GCallback) item_event_help, "goal"); } // Manual Button if(manual) { item_manual = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_manual, (BOARDWIDTH*0.6) - pixmap_width/2, y_start - 10); g_signal_connect(item_manual, "button_press_event", (GCallback) item_event_help, "manual"); gc_item_focus_init(item_manual, NULL); item_manual_text = goo_canvas_text_new (rootitem, _("Manual"), BOARDWIDTH*0.6, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_manual_text, "button_press_event", (GCallback) item_event_help, "manual"); } // Credit Button if(credit) { item_credit = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_credit, (BOARDWIDTH*0.8) - pixmap_width/2, y_start - 10); g_signal_connect(item_credit, "button_press_event", (GCallback) item_event_help, "credit"); gc_item_focus_init(item_credit, NULL); item_credit_text = goo_canvas_text_new (rootitem, _("Credit"), BOARDWIDTH*0.8, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_credit_text, "button_press_event", (GCallback) item_event_help, "credit"); } // CONTENT // default text to display if(prerequisite) { text_to_display = prerequisite; select_item(item_prerequisite, item_prerequisite_text); } else if(goal) { text_to_display = goal; select_item(item_goal, item_goal_text); } else if(manual) { text_to_display = manual; select_item(item_manual, item_manual_text); } else if(credit) { text_to_display = credit; select_item(item_credit, item_credit_text); } y_start += 45; /* Create a scrolled area for the text content */ GtkWidget *view; GtkWidget *sw; view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); gtk_text_view_set_editable(GTK_TEXT_VIEW (view), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (view), FALSE); g_signal_connect(GTK_OBJECT(view), "button-press-event", (GCallback) event_disable_right_click_popup, NULL); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string (gc_skin_font_content); gtk_widget_modify_font (view, font_desc); pango_font_description_free (font_desc); GdkColor fg_color; GdkColor bg_color; gc_skin_get_gdkcolor("gcompris/helpfg", &fg_color); gc_skin_get_gdkcolor("gcompris/helpbg", &bg_color); gtk_widget_modify_base(view, GTK_STATE_NORMAL, &bg_color); gtk_widget_modify_text(view, GTK_STATE_NORMAL, &fg_color); buffer_content = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), view); goo_canvas_widget_new (rootitem, sw, x_start + 40, y_start, 618.0, 280.0, NULL); gtk_widget_show_all (sw); set_content(text_to_display); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 0.5, y, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_help, "ok"); gc_bar_hide(TRUE); help_displayed = TRUE; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d P A N G O I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadPANGOImage() reads an image in the Pango Markup Language Format. % % The format of the ReadPANGOImage method is: % % Image *ReadPANGOImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadPANGOImage(const ImageInfo *image_info, ExceptionInfo *exception) { cairo_font_options_t *font_options; cairo_surface_t *surface; char *caption, *property; cairo_t *cairo_image; const char *option; DrawInfo *draw_info; Image *image; MagickBooleanType status; PangoAlignment align; PangoContext *context; PangoFontMap *fontmap; PangoGravity gravity; PangoLayout *layout; PangoRectangle extent; PixelPacket fill_color; RectangleInfo page; register unsigned char *p; size_t stride; ssize_t y; unsigned char *pixels; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); (void) ResetImagePage(image,"0x0+0+0"); /* Format caption. */ option=GetImageOption(image_info,"filename"); if (option == (const char *) NULL) property=InterpretImageProperties(image_info,image,image_info->filename); else if (LocaleNCompare(option,"pango:",6) == 0) property=InterpretImageProperties(image_info,image,option+6); else property=InterpretImageProperties(image_info,image,option); (void) SetImageProperty(image,"caption",property); property=DestroyString(property); caption=ConstantString(GetImageProperty(image,"caption")); /* Get context. */ fontmap=pango_cairo_font_map_new(); pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), image->x_resolution); font_options=cairo_font_options_create(); option=GetImageOption(image_info,"pango:hinting"); if (option != (const char *) NULL) { if (LocaleCompare(option,"none") != 0) cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_NONE); if (LocaleCompare(option,"full") != 0) cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_FULL); } context=pango_font_map_create_context(fontmap); pango_cairo_context_set_font_options(context,font_options); cairo_font_options_destroy(font_options); option=GetImageOption(image_info,"pango:language"); if (option != (const char *) NULL) pango_context_set_language(context,pango_language_from_string(option)); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); pango_context_set_base_dir(context,draw_info->direction == RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR); switch (draw_info->gravity) { case NorthGravity: { gravity=PANGO_GRAVITY_NORTH; break; } case NorthWestGravity: case WestGravity: case SouthWestGravity: { gravity=PANGO_GRAVITY_WEST; break; } case NorthEastGravity: case EastGravity: case SouthEastGravity: { gravity=PANGO_GRAVITY_EAST; break; } case SouthGravity: { gravity=PANGO_GRAVITY_SOUTH; break; } default: { gravity=PANGO_GRAVITY_AUTO; break; } } pango_context_set_base_gravity(context,gravity); option=GetImageOption(image_info,"pango:gravity-hint"); if (option != (const char *) NULL) { if (LocaleCompare(option,"line") == 0) pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_LINE); if (LocaleCompare(option,"natural") == 0) pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_NATURAL); if (LocaleCompare(option,"strong") == 0) pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_STRONG); } /* Configure layout. */ layout=pango_layout_new(context); option=GetImageOption(image_info,"pango:auto-dir"); if (option != (const char *) NULL) pango_layout_set_auto_dir(layout,1); option=GetImageOption(image_info,"pango:ellipsize"); if (option != (const char *) NULL) { if (LocaleCompare(option,"end") == 0) pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_END); if (LocaleCompare(option,"middle") == 0) pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_MIDDLE); if (LocaleCompare(option,"none") == 0) pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_NONE); if (LocaleCompare(option,"start") == 0) pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START); } option=GetImageOption(image_info,"pango:justify"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) pango_layout_set_justify(layout,1); option=GetImageOption(image_info,"pango:single-paragraph"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) pango_layout_set_single_paragraph_mode(layout,1); option=GetImageOption(image_info,"pango:wrap"); if (option != (const char *) NULL) { if (LocaleCompare(option,"char") == 0) pango_layout_set_wrap(layout,PANGO_WRAP_CHAR); if (LocaleCompare(option,"word") == 0) pango_layout_set_wrap(layout,PANGO_WRAP_WORD); if (LocaleCompare(option,"word-char") == 0) pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR); } option=GetImageOption(image_info,"pango:indent"); if (option != (const char *) NULL) pango_layout_set_indent(layout,(int) ((StringToLong(option)* image->x_resolution*PANGO_SCALE+36)/72.0+0.5)); switch (draw_info->align) { case CenterAlign: align=PANGO_ALIGN_CENTER; break; case RightAlign: align=PANGO_ALIGN_RIGHT; break; case LeftAlign: align=PANGO_ALIGN_LEFT; break; default: { if (draw_info->gravity == CenterGravity) { align=PANGO_ALIGN_CENTER; break; } align=PANGO_ALIGN_LEFT; break; } } if ((align != PANGO_ALIGN_CENTER) && (draw_info->direction == RightToLeftDirection)) align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align); pango_layout_set_alignment(layout,align); if (draw_info->font != (char *) NULL) { PangoFontDescription *description; /* Set font. */ description=pango_font_description_from_string(draw_info->font); pango_font_description_set_size(description,(int) (PANGO_SCALE* draw_info->pointsize+0.5)); pango_layout_set_font_description(layout,description); pango_font_description_free(description); } option=GetImageOption(image_info,"pango:markup"); if ((option != (const char *) NULL) && (IsMagickTrue(option) == MagickFalse)) pango_layout_set_text(layout,caption,-1); else { GError *error; error=(GError *) NULL; if (pango_parse_markup(caption,-1,0,NULL,NULL,NULL,&error) == 0) (void) ThrowMagickException(exception,GetMagickModule(),CoderError, error->message,"`%s'",image_info->filename); pango_layout_set_markup(layout,caption,-1); } pango_layout_context_changed(layout); page.x=0; page.y=0; if (image_info->page != (char *) NULL) (void) ParseAbsoluteGeometry(image_info->page,&page); if (image->columns == 0) { pango_layout_get_pixel_extents(layout,NULL,&extent); image->columns=extent.x+extent.width+2*page.x; } else { image->columns-=2*page.x; pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns* image->x_resolution+36.0)/72.0+0.5)); } if (image->rows == 0) { pango_layout_get_pixel_extents(layout,NULL,&extent); image->rows=extent.y+extent.height+2*page.y; } else { image->rows-=2*page.y; pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows* image->y_resolution+36.0)/72.0+0.5)); } /* Render markup. */ stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, image->columns); pixels=(unsigned char *) AcquireQuantumMemory(image->rows,stride* sizeof(*pixels)); if (pixels == (unsigned char *) NULL) { draw_info=DestroyDrawInfo(draw_info); caption=DestroyString(caption); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32, image->columns,image->rows,stride); cairo_image=cairo_create(surface); cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR); cairo_paint(cairo_image); cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER); cairo_translate(cairo_image,page.x,page.y); pango_cairo_show_layout(cairo_image,layout); cairo_destroy(cairo_image); cairo_surface_destroy(surface); g_object_unref(layout); g_object_unref(fontmap); /* Convert surface to image. */ (void) SetImageBackgroundColor(image); p=pixels; for (y=0; y < (ssize_t) image->rows; y++) { register PixelPacket *q; register ssize_t x; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { double gamma; fill_color.blue=ScaleCharToQuantum(*p++); fill_color.green=ScaleCharToQuantum(*p++); fill_color.red=ScaleCharToQuantum(*p++); fill_color.opacity=QuantumRange-ScaleCharToQuantum(*p++); /* Disassociate alpha. */ gamma=1.0-QuantumScale*fill_color.opacity; gamma=MagickEpsilonReciprocal(gamma); fill_color.blue*=gamma; fill_color.green*=gamma; fill_color.red*=gamma; MagickCompositeOver(&fill_color,fill_color.opacity,q,(MagickRealType) q->opacity,q); q++; } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; if (image->previous == (Image *) NULL) { status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } } /* Relinquish resources. */ pixels=(unsigned char *) RelinquishMagickMemory(pixels); draw_info=DestroyDrawInfo(draw_info); caption=DestroyString(caption); return(GetFirstImageInList(image)); }