Пример #1
0
static void
gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
                                    GtkWidget           *label,
                                    gdouble              size)
{
    gchar *format = g_strdup_printf ("%%.%df %%s",
                                     gimp_unit_get_digits (gre->unit));
    gchar *text = g_strdup_printf (format,
                                   size * gimp_unit_get_factor (gre->unit),
                                   gimp_unit_get_plural (gre->unit));
    g_free (format);

    gtk_label_set_text (GTK_LABEL (label), text);
    g_free (text);
}
Пример #2
0
/**
 * gimp_unit_format_string:
 * @format: A printf-like format string which is used to create the unit
 *          string.
 * @unit:   A unit.
 *
 * The @format string supports the following percent expansions:
 *
 * <informaltable pgwide="1" frame="none" role="enum">
 *   <tgroup cols="2"><colspec colwidth="1*"/><colspec colwidth="8*"/>
 *     <tbody>
 *       <row>
 *         <entry>% f</entry>
 *         <entry>Factor (how many units make up an inch)</entry>
 *        </row>
 *       <row>
 *         <entry>% y</entry>
 *         <entry>Symbol (e.g. "''" for GIMP_UNIT_INCH)</entry>
 *       </row>
 *       <row>
 *         <entry>% a</entry>
 *         <entry>Abbreviation</entry>
 *       </row>
 *       <row>
 *         <entry>% s</entry>
 *         <entry>Singular</entry>
 *       </row>
 *       <row>
 *         <entry>% p</entry>
 *         <entry>Plural</entry>
 *       </row>
 *       <row>
 *         <entry>%%</entry>
 *         <entry>Literal percent</entry>
 *       </row>
 *     </tbody>
 *   </tgroup>
 * </informaltable>
 *
 * Returns: A newly allocated string with above percent expressions
 *          replaced with the resp. strings for @unit.
 *
 * Since: 2.8
 **/
gchar *
gimp_unit_format_string (const gchar *format,
                         GimpUnit     unit)
{
    gchar buffer[1024];
    gint  i = 0;

    g_return_val_if_fail (format != NULL, NULL);
    g_return_val_if_fail (unit == GIMP_UNIT_PERCENT ||
                          (unit >= GIMP_UNIT_PIXEL &&
                           unit < gimp_unit_get_number_of_units ()), NULL);

    while (i < (sizeof (buffer) - 1) && *format)
    {
        switch (*format)
        {
        case '%':
            format++;
            switch (*format)
            {
            case 0:
                g_warning ("%s: unit-menu-format string ended within %%-sequence",
                           G_STRFUNC);
                break;

            case '%':
                buffer[i++] = '%';
                break;

            case 'f': /* factor (how many units make up an inch) */
                i += print (buffer, sizeof (buffer), i, "%f",
                            gimp_unit_get_factor (unit));
                break;

            case 'y': /* symbol ("''" for inch) */
                i += print (buffer, sizeof (buffer), i, "%s",
                            gimp_unit_get_symbol (unit));
                break;

            case 'a': /* abbreviation */
                i += print (buffer, sizeof (buffer), i, "%s",
                            gimp_unit_get_abbreviation (unit));
                break;

            case 's': /* singular */
                i += print (buffer, sizeof (buffer), i, "%s",
                            gimp_unit_get_singular (unit));
                break;

            case 'p': /* plural */
                i += print (buffer, sizeof (buffer), i, "%s",
                            gimp_unit_get_plural (unit));
                break;

            default:
                g_warning ("%s: unit-menu-format contains unknown format "
                           "sequence '%%%c'", G_STRFUNC, *format);
                break;
            }
            break;

        default:
            buffer[i++] = *format;
            break;
        }

        format++;
    }

    buffer[MIN (i, sizeof (buffer) - 1)] = 0;

    return g_strdup (buffer);
}
Пример #3
0
static void
gimp_image_prop_view_update (GimpImagePropView *view)
{
  GimpImage         *image = view->image;
  GimpImageBaseType  type;
  GimpPrecision      precision;
  GimpUnit           unit;
  gdouble            unit_factor;
  gint               unit_digits;
  const gchar       *desc;
  gchar              format_buf[32];
  gchar              buf[256];
  gdouble            xres;
  gdouble            yres;

  gimp_image_get_resolution (image, &xres, &yres);

  /*  pixel size  */
  g_snprintf (buf, sizeof (buf), ngettext ("%d × %d pixel",
                                           "%d × %d pixels",
                                           gimp_image_get_height (image)),
              gimp_image_get_width  (image),
              gimp_image_get_height (image));
  gtk_label_set_text (GTK_LABEL (view->pixel_size_label), buf);

  /*  print size  */
  unit = gimp_get_default_unit ();

  unit_digits = gimp_unit_get_digits (unit);

  g_snprintf (format_buf, sizeof (format_buf), "%%.%df × %%.%df %s",
              unit_digits + 1, unit_digits + 1,
              gimp_unit_get_plural (unit));
  g_snprintf (buf, sizeof (buf), format_buf,
              gimp_pixels_to_units (gimp_image_get_width  (image), unit, xres),
              gimp_pixels_to_units (gimp_image_get_height (image), unit, yres));
  gtk_label_set_text (GTK_LABEL (view->print_size_label), buf);

  /*  resolution  */
  unit        = gimp_image_get_unit (image);
  unit_factor = gimp_unit_get_factor (unit);

  g_snprintf (format_buf, sizeof (format_buf), _("pixels/%s"),
              gimp_unit_get_abbreviation (unit));
  g_snprintf (buf, sizeof (buf), _("%g × %g %s"),
              xres / unit_factor,
              yres / unit_factor,
              unit == GIMP_UNIT_INCH ? _("ppi") : format_buf);
  gtk_label_set_text (GTK_LABEL (view->resolution_label), buf);

  /*  color type  */
  type = gimp_image_get_base_type (image);

  gimp_enum_get_value (GIMP_TYPE_IMAGE_BASE_TYPE, type,
                       NULL, NULL, &desc, NULL);

  switch (type)
    {
    case GIMP_RGB:
    case GIMP_GRAY:
      g_snprintf (buf, sizeof (buf), "%s", desc);
      break;
    case GIMP_INDEXED:
      g_snprintf (buf, sizeof (buf),
                  "%s (%d %s)", desc, gimp_image_get_colormap_size (image),
                  _("colors"));
      break;
    }

  gtk_label_set_text (GTK_LABEL (view->colorspace_label), buf);

  /*  precision  */
  precision = gimp_image_get_precision (image);

  gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
                       NULL, NULL, &desc, NULL);

  gtk_label_set_text (GTK_LABEL (view->precision_label), desc);

  /*  size in memory  */
  gimp_image_prop_view_label_set_memsize (view->memsize_label,
                                          GIMP_OBJECT (image));

  /*  undo / redo  */
  gimp_image_prop_view_label_set_undo (view->undo_label,
                                       gimp_image_get_undo_stack (image));
  gimp_image_prop_view_label_set_undo (view->redo_label,
                                       gimp_image_get_redo_stack (image));

  /*  number of layers  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_width  (image) *
              gimp_image_get_height (image));
  gtk_label_set_text (GTK_LABEL (view->pixels_label), buf);

  /*  number of layers  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_layers (image));
  gtk_label_set_text (GTK_LABEL (view->layers_label), buf);

  /*  number of channels  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_channels (image));
  gtk_label_set_text (GTK_LABEL (view->channels_label), buf);

  /*  number of vectors  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_vectors (image));
  gtk_label_set_text (GTK_LABEL (view->vectors_label), buf);
}
Пример #4
0
static void
print_size_info_set_page_setup (PrintSizeInfo *info)
{
  GtkPageSetup *setup;
  PrintData    *data = info->data;
  gdouble       page_width;
  gdouble       page_height;
  gdouble       x;
  gdouble       y;

  setup = gtk_print_operation_get_default_page_setup (data->operation);

  print_size_info_get_page_dimensions (info,
                                       &page_width, &page_height,
                                       GTK_UNIT_INCH);

  page_width  *= gimp_unit_get_factor (data->unit);
  page_height *= gimp_unit_get_factor (data->unit);

  if (info->area_label)
    {
      gchar *format;
      gchar *text;

      format = g_strdup_printf ("%%.%df x %%.%df %s",
                                gimp_unit_get_digits (data->unit),
                                gimp_unit_get_digits (data->unit),
                                gimp_unit_get_plural (data->unit));
      text = g_strdup_printf (format, page_width, page_height);
      g_free (format);

      gtk_label_set_text (GTK_LABEL (info->area_label), text);
      g_free (text);
    }

  x = page_width;
  y = page_height;

  if (info->chain && gimp_chain_button_get_active (info->chain))
    {
      gdouble ratio_x = page_width  / (gdouble) info->image_width;
      gdouble ratio_y = page_height / (gdouble) info->image_height;

      if (ratio_x < ratio_y)
        y = (gdouble) info->image_height * ratio_x;
      else
        x = (gdouble) info->image_width  * ratio_y;
    }

  gimp_size_entry_set_value_boundaries (info->size_entry, WIDTH,
                                        page_width  / 100.0, x);
  gimp_size_entry_set_value_boundaries (info->size_entry, HEIGHT,
                                        page_height / 100.0, y);

  print_size_info_get_page_dimensions (info,
                                       &page_width, &page_height,
                                       GTK_UNIT_POINTS);

  x = (gdouble) info->image_width  / page_width  * 72.0;
  y = (gdouble) info->image_height / page_height * 72.0;

  if (info->chain && gimp_chain_button_get_active (info->chain))
    {
      gdouble max = MAX (x, y);

      x = y = max;
    }

  gimp_size_entry_set_refval_boundaries (info->resolution_entry, 0,
                                         x, GIMP_MAX_RESOLUTION);
  gimp_size_entry_set_refval_boundaries (info->resolution_entry, 1,
                                         y, GIMP_MAX_RESOLUTION);
}