[gimp] app: GimpTextLayout: use the unit conversion functions from gimpunit.[ch]



commit f09360ba801f5a274cbef5e092ef93745ded34b4
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 18 21:39:28 2011 +0100

    app: GimpTextLayout: use the unit conversion functions from gimpunit.[ch]
    
    instead of duplicating them. Multiply by PANGO_SCALE in the callers
    and ceil() fixed text box pixel extents so we don't cut off stuff by
    fractions of a pixel.

 app/text/gimptextlayout.c |   94 ++++++++++-----------------------------------
 1 files changed, 21 insertions(+), 73 deletions(-)
---
diff --git a/app/text/gimptextlayout.c b/app/text/gimptextlayout.c
index 95103a4..299d19b 100644
--- a/app/text/gimptextlayout.c
+++ b/app/text/gimptextlayout.c
@@ -56,13 +56,6 @@ static PangoContext * gimp_text_get_pango_context (GimpText       *text,
                                                    gdouble         xres,
                                                    gdouble         yres);
 
-static gint           gimp_text_layout_pixel_size (gdouble         value,
-                                                   GimpUnit        unit,
-                                                   gdouble         res);
-static gint           gimp_text_layout_point_size (gdouble         value,
-                                                   GimpUnit        unit,
-                                                   gdouble         res);
-
 
 G_DEFINE_TYPE (GimpTextLayout, gimp_text_layout, G_TYPE_OBJECT)
 
@@ -120,9 +113,9 @@ gimp_text_layout_new (GimpText  *text,
   font_desc = pango_font_description_from_string (text->font);
   g_return_val_if_fail (font_desc != NULL, NULL);
 
-  size = gimp_text_layout_point_size (text->font_size,
-                                      text->unit,
-                                      yres);
+  size = pango_units_from_double (gimp_units_to_points (text->font_size,
+                                                        text->unit,
+                                                        yres));
 
   pango_font_description_set_size (font_desc, MAX (1, size));
 
@@ -169,20 +162,23 @@ gimp_text_layout_new (GimpText  *text,
       break;
     case GIMP_TEXT_BOX_FIXED:
       pango_layout_set_width (layout->layout,
-                              gimp_text_layout_pixel_size (text->box_width,
-                                                           text->box_unit,
-                                                           xres));
+                              pango_units_from_double
+                              (gimp_units_to_pixels (text->box_width,
+                                                     text->box_unit,
+                                                     xres)));
       break;
     }
 
   pango_layout_set_indent (layout->layout,
-                           gimp_text_layout_pixel_size (text->indent,
-                                                        text->unit,
-                                                        xres));
+                           pango_units_from_double
+                           (gimp_units_to_pixels (text->indent,
+                                                  text->unit,
+                                                  xres)));
   pango_layout_set_spacing (layout->layout,
-                            gimp_text_layout_pixel_size (text->line_spacing,
-                                                         text->unit,
-                                                         yres));
+                            pango_units_from_double
+                            (gimp_units_to_pixels (text->line_spacing,
+                                                   text->unit,
+                                                   yres)));
 
   gimp_text_layout_position (layout);
 
@@ -191,14 +187,12 @@ gimp_text_layout_new (GimpText  *text,
     case GIMP_TEXT_BOX_DYNAMIC:
       break;
     case GIMP_TEXT_BOX_FIXED:
-      layout->extents.width =
-        PANGO_PIXELS (gimp_text_layout_pixel_size (text->box_width,
-                                                   text->box_unit,
-                                                   xres));
-      layout->extents.height =
-        PANGO_PIXELS (gimp_text_layout_pixel_size (text->box_height,
-                                                   text->box_unit,
-                                                   yres));
+      layout->extents.width  = ceil (gimp_units_to_pixels (text->box_width,
+                                                           text->box_unit,
+                                                           xres));
+      layout->extents.height = ceil (gimp_units_to_pixels (text->box_height,
+                                                           text->box_unit,
+                                                           yres));
 
 /* #define VERBOSE */
 
@@ -709,49 +703,3 @@ gimp_text_get_pango_context (GimpText *text,
 
   return context;
 }
-
-static gint
-gimp_text_layout_pixel_size (gdouble  value,
-                             GimpUnit unit,
-                             gdouble  res)
-{
-  gdouble factor;
-
-  switch (unit)
-    {
-    case GIMP_UNIT_PIXEL:
-      return PANGO_SCALE * value;
-
-    default:
-      factor = gimp_unit_get_factor (unit);
-      g_return_val_if_fail (factor > 0.0, 0);
-
-      return PANGO_SCALE * value * res / factor;
-    }
-}
-
-static gint
-gimp_text_layout_point_size (gdouble  value,
-                             GimpUnit unit,
-                             gdouble  res)
-{
-  gdouble factor;
-
-  switch (unit)
-    {
-    case GIMP_UNIT_POINT:
-      return PANGO_SCALE * value;
-
-    case GIMP_UNIT_PIXEL:
-      g_return_val_if_fail (res > 0.0, 0);
-      return (PANGO_SCALE * value *
-              gimp_unit_get_factor (GIMP_UNIT_POINT) / res);
-
-    default:
-      factor = gimp_unit_get_factor (unit);
-      g_return_val_if_fail (factor > 0.0, 0);
-
-      return (PANGO_SCALE * value *
-              gimp_unit_get_factor (GIMP_UNIT_POINT) / factor);
-    }
-}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]