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.
This commit is contained in:
@ -56,13 +56,6 @@ static PangoContext * gimp_text_get_pango_context (GimpText *text,
|
|||||||
gdouble xres,
|
gdouble xres,
|
||||||
gdouble yres);
|
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)
|
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);
|
font_desc = pango_font_description_from_string (text->font);
|
||||||
g_return_val_if_fail (font_desc != NULL, NULL);
|
g_return_val_if_fail (font_desc != NULL, NULL);
|
||||||
|
|
||||||
size = gimp_text_layout_point_size (text->font_size,
|
size = pango_units_from_double (gimp_units_to_points (text->font_size,
|
||||||
text->unit,
|
text->unit,
|
||||||
yres);
|
yres));
|
||||||
|
|
||||||
pango_font_description_set_size (font_desc, MAX (1, size));
|
pango_font_description_set_size (font_desc, MAX (1, size));
|
||||||
|
|
||||||
@ -169,20 +162,23 @@ gimp_text_layout_new (GimpText *text,
|
|||||||
break;
|
break;
|
||||||
case GIMP_TEXT_BOX_FIXED:
|
case GIMP_TEXT_BOX_FIXED:
|
||||||
pango_layout_set_width (layout->layout,
|
pango_layout_set_width (layout->layout,
|
||||||
gimp_text_layout_pixel_size (text->box_width,
|
pango_units_from_double
|
||||||
|
(gimp_units_to_pixels (text->box_width,
|
||||||
text->box_unit,
|
text->box_unit,
|
||||||
xres));
|
xres)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pango_layout_set_indent (layout->layout,
|
pango_layout_set_indent (layout->layout,
|
||||||
gimp_text_layout_pixel_size (text->indent,
|
pango_units_from_double
|
||||||
|
(gimp_units_to_pixels (text->indent,
|
||||||
text->unit,
|
text->unit,
|
||||||
xres));
|
xres)));
|
||||||
pango_layout_set_spacing (layout->layout,
|
pango_layout_set_spacing (layout->layout,
|
||||||
gimp_text_layout_pixel_size (text->line_spacing,
|
pango_units_from_double
|
||||||
|
(gimp_units_to_pixels (text->line_spacing,
|
||||||
text->unit,
|
text->unit,
|
||||||
yres));
|
yres)));
|
||||||
|
|
||||||
gimp_text_layout_position (layout);
|
gimp_text_layout_position (layout);
|
||||||
|
|
||||||
@ -191,12 +187,10 @@ gimp_text_layout_new (GimpText *text,
|
|||||||
case GIMP_TEXT_BOX_DYNAMIC:
|
case GIMP_TEXT_BOX_DYNAMIC:
|
||||||
break;
|
break;
|
||||||
case GIMP_TEXT_BOX_FIXED:
|
case GIMP_TEXT_BOX_FIXED:
|
||||||
layout->extents.width =
|
layout->extents.width = ceil (gimp_units_to_pixels (text->box_width,
|
||||||
PANGO_PIXELS (gimp_text_layout_pixel_size (text->box_width,
|
|
||||||
text->box_unit,
|
text->box_unit,
|
||||||
xres));
|
xres));
|
||||||
layout->extents.height =
|
layout->extents.height = ceil (gimp_units_to_pixels (text->box_height,
|
||||||
PANGO_PIXELS (gimp_text_layout_pixel_size (text->box_height,
|
|
||||||
text->box_unit,
|
text->box_unit,
|
||||||
yres));
|
yres));
|
||||||
|
|
||||||
@ -709,49 +703,3 @@ gimp_text_get_pango_context (GimpText *text,
|
|||||||
|
|
||||||
return context;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user