mirror of https://github.com/GNOME/gimp.git
moved new code to a utility function. Avoid use of deprecated Pango API.
2006-04-04 Sven Neumann <sven@gimp.org> * app/text/gimpfont.c: moved new code to a utility function. Avoid use of deprecated Pango API. Removed tabs and trailing whitespace.
This commit is contained in:
parent
0cd9648a49
commit
645edc9cdc
|
@ -1,3 +1,8 @@
|
||||||
|
2006-04-04 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/text/gimpfont.c: moved new code to a utility function. Avoid
|
||||||
|
use of deprecated Pango API. Removed tabs and trailing whitespace.
|
||||||
|
|
||||||
2006-04-04 Tor Lillqvist <tml@novell.com>
|
2006-04-04 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* app/text/gimpfont.c (gimp_font_get_new_preview): Provide
|
* app/text/gimpfont.c (gimp_font_get_new_preview): Provide
|
||||||
|
|
|
@ -91,6 +91,9 @@ static TempBuf * gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height);
|
||||||
|
|
||||||
|
static const gchar * gimp_font_get_sample_string (PangoContext *context,
|
||||||
|
PangoFontDescription *font_desc);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpFont, gimp_font, GIMP_TYPE_VIEWABLE);
|
G_DEFINE_TYPE (GimpFont, gimp_font, GIMP_TYPE_VIEWABLE);
|
||||||
|
|
||||||
|
@ -240,6 +243,100 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
guchar *p;
|
guchar *p;
|
||||||
guchar black = 0;
|
guchar black = 0;
|
||||||
|
|
||||||
|
if (! font->pango_context)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (! font->popup_layout ||
|
||||||
|
font->popup_width != width || font->popup_height != height)
|
||||||
|
{
|
||||||
|
PangoFontDescription *font_desc;
|
||||||
|
const gchar *name;
|
||||||
|
|
||||||
|
name = gimp_object_get_name (GIMP_OBJECT (font));
|
||||||
|
|
||||||
|
DEBUGPRINT (("%s: ", name));
|
||||||
|
|
||||||
|
font_desc = pango_font_description_from_string (name);
|
||||||
|
g_return_val_if_fail (font_desc != NULL, NULL);
|
||||||
|
|
||||||
|
pango_font_description_set_size (font_desc,
|
||||||
|
PANGO_SCALE * height * 2.0 / 3.0);
|
||||||
|
|
||||||
|
layout = pango_layout_new (font->pango_context);
|
||||||
|
|
||||||
|
pango_layout_set_font_description (layout, font_desc);
|
||||||
|
pango_layout_set_text (layout,
|
||||||
|
gimp_font_get_sample_string (font->pango_context,
|
||||||
|
font_desc),
|
||||||
|
-1);
|
||||||
|
|
||||||
|
pango_font_description_free (font_desc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
layout = g_object_ref (font->popup_layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_buf = temp_buf_new (width, height, 1, 0, 0, &black);
|
||||||
|
|
||||||
|
bitmap.width = temp_buf->width;
|
||||||
|
bitmap.rows = temp_buf->height;
|
||||||
|
bitmap.pitch = temp_buf->width;
|
||||||
|
bitmap.buffer = temp_buf_data (temp_buf);
|
||||||
|
|
||||||
|
pango_layout_get_pixel_extents (layout, &ink, &logical);
|
||||||
|
|
||||||
|
layout_width = MAX (ink.width, logical.width);
|
||||||
|
layout_height = MAX (ink.height, logical.height);
|
||||||
|
|
||||||
|
layout_x = (bitmap.width - layout_width) / 2;
|
||||||
|
layout_y = (bitmap.rows - layout_height) / 2;
|
||||||
|
|
||||||
|
if (ink.x < logical.x)
|
||||||
|
layout_x += logical.x - ink.x;
|
||||||
|
|
||||||
|
if (ink.y < logical.y)
|
||||||
|
layout_y += logical.y - ink.y;
|
||||||
|
|
||||||
|
pango_ft2_render_layout (&bitmap, layout, layout_x, layout_y);
|
||||||
|
|
||||||
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
p = temp_buf_data (temp_buf);
|
||||||
|
|
||||||
|
for (height = temp_buf->height; height; height--)
|
||||||
|
for (width = temp_buf->width; width; width--, p++)
|
||||||
|
*p = 255 - *p;
|
||||||
|
|
||||||
|
return temp_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
GimpFont *
|
||||||
|
gimp_font_get_standard (void)
|
||||||
|
{
|
||||||
|
static GimpFont *standard_font = NULL;
|
||||||
|
|
||||||
|
if (! standard_font)
|
||||||
|
standard_font = g_object_new (GIMP_TYPE_FONT,
|
||||||
|
"name", "Sans",
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return standard_font;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Guess a suitable short sample string for the font. */
|
||||||
|
static const gchar *
|
||||||
|
gimp_font_get_sample_string (PangoContext *context,
|
||||||
|
PangoFontDescription *font_desc)
|
||||||
|
{
|
||||||
|
PangoFont *font;
|
||||||
|
PangoOTInfo *ot_info;
|
||||||
|
FT_Face face;
|
||||||
|
TT_OS2 *os2;
|
||||||
|
PangoOTTableType tt;
|
||||||
|
gint i;
|
||||||
|
|
||||||
/* This is a table of scripts and corresponding short sample strings
|
/* This is a table of scripts and corresponding short sample strings
|
||||||
* to be used instead of the Latin sample string Aa. The script
|
* to be used instead of the Latin sample string Aa. The script
|
||||||
* codes are as in ISO15924 (see
|
* codes are as in ISO15924 (see
|
||||||
|
@ -264,7 +361,8 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
*
|
*
|
||||||
* Very useful link: http://www.travelphrases.info/fonts.html
|
* Very useful link: http://www.travelphrases.info/fonts.html
|
||||||
*/
|
*/
|
||||||
static struct {
|
static const struct
|
||||||
|
{
|
||||||
const gchar script[4];
|
const gchar script[4];
|
||||||
int bit;
|
int bit;
|
||||||
const gchar *sample;
|
const gchar *sample;
|
||||||
|
@ -508,44 +606,17 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int ot_alts[4];
|
gint ot_alts[4];
|
||||||
int n_ot_alts = 0;
|
gint n_ot_alts = 0;
|
||||||
int sr_alts[20];
|
gint sr_alts[20];
|
||||||
int n_sr_alts = 0;
|
gint n_sr_alts = 0;
|
||||||
|
|
||||||
if (! font->pango_context)
|
font = pango_context_load_font (context, font_desc);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (! font->popup_layout ||
|
g_return_val_if_fail (PANGO_IS_FC_FONT (font), "Aa");
|
||||||
font->popup_width != width ||
|
|
||||||
font->popup_height != height)
|
|
||||||
{
|
|
||||||
PangoFont *pango_font;
|
|
||||||
PangoOTInfo *ot_info;
|
|
||||||
PangoFontDescription *font_desc;
|
|
||||||
const gchar *name;
|
|
||||||
PangoOTTableType tt;
|
|
||||||
const gchar *short_sample = NULL;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
name = gimp_object_get_name (GIMP_OBJECT (font));
|
face = pango_fc_font_lock_face (PANGO_FC_FONT (font));
|
||||||
|
ot_info = pango_ot_info_get (face);
|
||||||
DEBUGPRINT (("%s: ", name));
|
|
||||||
|
|
||||||
font_desc = pango_font_description_from_string (name);
|
|
||||||
g_return_val_if_fail (font_desc != NULL, NULL);
|
|
||||||
|
|
||||||
pango_font_description_set_size (font_desc,
|
|
||||||
PANGO_SCALE * height * 2.0 / 3.0);
|
|
||||||
|
|
||||||
layout = pango_layout_new (font->pango_context);
|
|
||||||
pango_layout_set_font_description (layout, font_desc);
|
|
||||||
|
|
||||||
/* Guess a suitable short sample string for the font. */
|
|
||||||
|
|
||||||
pango_font = pango_context_load_font (font->pango_context,
|
|
||||||
font_desc);
|
|
||||||
ot_info = pango_ot_info_get (pango_ft2_font_get_face (pango_font));
|
|
||||||
|
|
||||||
/* First check what script(s), if any, the font has GSUB or GPOS
|
/* First check what script(s), if any, the font has GSUB or GPOS
|
||||||
* OpenType layout tables for.
|
* OpenType layout tables for.
|
||||||
|
@ -592,11 +663,8 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
/* Next check the OS/2 table for Unicode ranges the font claims
|
/* Next check the OS/2 table for Unicode ranges the font claims
|
||||||
* to cover.
|
* to cover.
|
||||||
*/
|
*/
|
||||||
if (PANGO_IS_FC_FONT (pango_font))
|
|
||||||
{
|
os2 = FT_Get_Sfnt_Table (face, ft_sfnt_os2);
|
||||||
FT_Face face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font));
|
|
||||||
TT_OS2 *os2 = FT_Get_Sfnt_Table (face, ft_sfnt_os2);
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
if (os2)
|
if (os2)
|
||||||
{
|
{
|
||||||
|
@ -613,10 +681,9 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pango_fc_font_unlock_face (PANGO_FC_FONT (pango_font));
|
pango_fc_font_unlock_face (PANGO_FC_FONT (font));
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (pango_font);
|
g_object_unref (font);
|
||||||
|
|
||||||
if (n_ot_alts > 2)
|
if (n_ot_alts > 2)
|
||||||
{
|
{
|
||||||
|
@ -629,12 +696,11 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
if (scripts[sr_alts[i]].bit == 0)
|
if (scripts[sr_alts[i]].bit == 0)
|
||||||
{
|
{
|
||||||
DEBUGPRINT (("=> several OT, also latin, use Aa\n"));
|
DEBUGPRINT (("=> several OT, also latin, use Aa\n"));
|
||||||
short_sample = "Aa";
|
return "Aa";
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! short_sample && n_ot_alts > 0 && n_sr_alts >= n_ot_alts + 3)
|
if (n_ot_alts > 0 && n_sr_alts >= n_ot_alts + 3)
|
||||||
{
|
{
|
||||||
/* At least one script with an OpenType table, but many more
|
/* At least one script with an OpenType table, but many more
|
||||||
* subranges than such scripts. If it supports Basic Latin,
|
* subranges than such scripts. If it supports Basic Latin,
|
||||||
|
@ -646,27 +712,24 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
if (scripts[sr_alts[i]].bit == 0)
|
if (scripts[sr_alts[i]].bit == 0)
|
||||||
{
|
{
|
||||||
DEBUGPRINT (("=> several SR, also latin, use Aa\n"));
|
DEBUGPRINT (("=> several SR, also latin, use Aa\n"));
|
||||||
short_sample = "Aa";
|
return "Aa";
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! short_sample)
|
|
||||||
{
|
|
||||||
DEBUGPRINT (("=> several SR, use %.4s\n", scripts[sr_alts[0]].script));
|
DEBUGPRINT (("=> several SR, use %.4s\n", scripts[sr_alts[0]].script));
|
||||||
short_sample = scripts[sr_alts[0]].sample;
|
return scripts[sr_alts[0]].sample;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! short_sample && n_ot_alts > 0)
|
if (n_ot_alts > 0)
|
||||||
{
|
{
|
||||||
/* OpenType tables for at least one script, use the
|
/* OpenType tables for at least one script, use the
|
||||||
* highest priority one
|
* highest priority one
|
||||||
*/
|
*/
|
||||||
DEBUGPRINT (("=> at least one OT, use %.4s\n", scripts[sr_alts[0]].script));
|
DEBUGPRINT (("=> at least one OT, use %.4s\n",
|
||||||
short_sample = scripts[ot_alts[0]].sample;
|
scripts[sr_alts[0]].script));
|
||||||
|
return scripts[ot_alts[0]].sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! short_sample && n_sr_alts > 0)
|
if (n_sr_alts > 0)
|
||||||
{
|
{
|
||||||
/* Use the highest priority subrange. This means that a
|
/* Use the highest priority subrange. This means that a
|
||||||
* font that supports Greek, Cyrillic and Latin (quite
|
* font that supports Greek, Cyrillic and Latin (quite
|
||||||
|
@ -676,69 +739,12 @@ gimp_font_get_new_preview (GimpViewable *viewable,
|
||||||
* doesn't give a too strong impression that the font would
|
* doesn't give a too strong impression that the font would
|
||||||
* be for Greek only.
|
* be for Greek only.
|
||||||
*/
|
*/
|
||||||
DEBUGPRINT (("=> at least one SR, use %.4s\n", scripts[sr_alts[0]].script));
|
DEBUGPRINT (("=> at least one SR, use %.4s\n",
|
||||||
short_sample = scripts[sr_alts[0]].sample;
|
scripts[sr_alts[0]].script));
|
||||||
|
return scripts[sr_alts[0]].sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Final fallback */
|
/* Final fallback */
|
||||||
if (! short_sample)
|
|
||||||
{
|
|
||||||
DEBUGPRINT (("=> fallback, use Aa\n"));
|
DEBUGPRINT (("=> fallback, use Aa\n"));
|
||||||
short_sample = "Aa";
|
return "Aa";
|
||||||
}
|
|
||||||
|
|
||||||
pango_font_description_free (font_desc);
|
|
||||||
|
|
||||||
pango_layout_set_text (layout, short_sample, -1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
layout = g_object_ref (font->popup_layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
temp_buf = temp_buf_new (width, height, 1, 0, 0, &black);
|
|
||||||
|
|
||||||
bitmap.width = temp_buf->width;
|
|
||||||
bitmap.rows = temp_buf->height;
|
|
||||||
bitmap.pitch = temp_buf->width;
|
|
||||||
bitmap.buffer = temp_buf_data (temp_buf);
|
|
||||||
|
|
||||||
pango_layout_get_pixel_extents (layout, &ink, &logical);
|
|
||||||
|
|
||||||
layout_width = MAX (ink.width, logical.width);
|
|
||||||
layout_height = MAX (ink.height, logical.height);
|
|
||||||
|
|
||||||
layout_x = (bitmap.width - layout_width) / 2;
|
|
||||||
layout_y = (bitmap.rows - layout_height) / 2;
|
|
||||||
|
|
||||||
if (ink.x < logical.x)
|
|
||||||
layout_x += logical.x - ink.x;
|
|
||||||
|
|
||||||
if (ink.y < logical.y)
|
|
||||||
layout_y += logical.y - ink.y;
|
|
||||||
|
|
||||||
pango_ft2_render_layout (&bitmap, layout, layout_x, layout_y);
|
|
||||||
|
|
||||||
g_object_unref (layout);
|
|
||||||
|
|
||||||
p = temp_buf_data (temp_buf);
|
|
||||||
|
|
||||||
for (height = temp_buf->height; height; height--)
|
|
||||||
for (width = temp_buf->width; width; width--, p++)
|
|
||||||
*p = 255 - *p;
|
|
||||||
|
|
||||||
return temp_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
GimpFont *
|
|
||||||
gimp_font_get_standard (void)
|
|
||||||
{
|
|
||||||
static GimpFont *standard_font = NULL;
|
|
||||||
|
|
||||||
if (! standard_font)
|
|
||||||
standard_font = g_object_new (GIMP_TYPE_FONT,
|
|
||||||
"name", "Sans",
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
return standard_font;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue