static void gst_time_overlay_init (GstTimeOverlay * overlay, GstTimeOverlayClass * klass) { PangoFontDescription *font_description; GstTextOverlay *textoverlay; PangoContext *context; textoverlay = GST_TEXT_OVERLAY (overlay); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); textoverlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; textoverlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; }
static void check_invariants (const char *text) { int len; PangoLogAttr *attrs; if (!g_utf8_validate (text, -1, NULL)) fail ("Invalid UTF-8 in test text"); len = g_utf8_strlen (text, -1); attrs = g_new0 (PangoLogAttr, len + 1); pango_get_log_attrs (text, -1, 0, pango_language_from_string ("C"), attrs, len + 1); check_line_invariants (text, attrs); check_sentence_invariants (text, attrs); check_grapheme_invariants (text, attrs); check_word_invariants (text, attrs); #if 0 print_sentences (text, attrs); #endif g_free (attrs); }
static bool pango_load (Lisp_Font *f) { PangoLanguage *language; PangoFontDescription *fontdesc; PangoFont *font; PangoFontMetrics *metrics; if (pango_context) { language = pango_context_get_language (pango_context); } else { char *langname, *p; #ifdef HAVE_PANGO_XFT pango_context = pango_xft_get_context (dpy, screen_num); #endif langname = g_strdup (setlocale (LC_CTYPE, NULL)); p = strchr (langname, '.'); if (p) *p = 0; p = strchr (langname, '@'); if (p) *p = 0; language = pango_language_from_string (langname); pango_context_set_language (pango_context, language); g_free (langname); } fontdesc = pango_font_description_from_string (rep_STR (f->name)); if (!pango_font_description_get_family (fontdesc)) pango_font_description_set_family (fontdesc, "Sans"); if (pango_font_description_get_size (fontdesc) <= 0) pango_font_description_set_size (fontdesc, 12 * PANGO_SCALE); pango_context_set_font_description (pango_context, fontdesc); font = pango_context_load_font (pango_context, fontdesc); if (!font) { pango_font_description_free(fontdesc); return FALSE; } metrics = pango_font_get_metrics (font, language); f->ascent = metrics->ascent / PANGO_SCALE; f->descent = metrics->descent / PANGO_SCALE; pango_font_metrics_unref (metrics); f->font = fontdesc; /* We save the font description, not the font itself! That's because it seems we can't recover it perfectly later, and the layout routines want a description */ return TRUE; }
static void gst_time_overlay_class_init (GstTimeOverlayClass * klass) { GstTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gsttextoverlay_class = (GstTextOverlayClass *) klass; gsttextoverlay_class->get_text = gst_time_overlay_get_text; g_mutex_lock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); }
static void measure_font(const RrInstance *inst, RrFont *f) { PangoFontMetrics *metrics; static PangoLanguage *lang = NULL; if (lang == NULL) { #if PANGO_VERSION_MAJOR > 1 || \ (PANGO_VERSION_MAJOR == 1 && PANGO_VERSION_MINOR >= 16) lang = pango_language_get_default(); #else gchar *locale, *p; /* get the default language from the locale (based on gtk_get_default_language in gtkmain.c) */ locale = g_strdup(setlocale(LC_CTYPE, NULL)); if ((p = strchr(locale, '.'))) *p = '\0'; /* strip off the . */ if ((p = strchr(locale, '@'))) *p = '\0'; /* strip off the @ */ lang = pango_language_from_string(locale); g_free(locale); #endif } /* measure the ascent and descent */ metrics = pango_context_get_metrics(inst->pango, f->font_desc, lang); f->ascent = pango_font_metrics_get_ascent(metrics); f->descent = pango_font_metrics_get_descent(metrics); pango_font_metrics_unref(metrics); }
const char * get_language_name_for_tag (guint32 tag) { hb_language_t lang; const char *s; lang = hb_ot_tag_to_language (tag); s = hb_language_to_string (lang); return get_language_name (pango_language_from_string (s)); }
static void calculate_info (CeditDocument *doc, GtkTextIter *start, GtkTextIter *end, gint *chars, gint *words, gint *white_chars, gint *bytes) { gchar *text; cedit_debug (DEBUG_PLUGINS); text = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), start, end, TRUE); *chars = g_utf8_strlen (text, -1); *bytes = strlen (text); if (*chars > 0) { PangoLogAttr *attrs; gint i; attrs = g_new0 (PangoLogAttr, *chars + 1); pango_get_log_attrs (text, -1, 0, pango_language_from_string ("C"), attrs, *chars + 1); for (i = 0; i < (*chars); i++) { if (attrs[i].is_white) ++(*white_chars); if (attrs[i].is_word_start) ++(*words); } g_free (attrs); } else { *white_chars = 0; *words = 0; } g_free (text); }
static PangoLanguage * pango_language_get_default (void) { static PangoLanguage *result = NULL; if (G_UNLIKELY (!result)) { gchar *lang = _pango_get_lc_ctype (); result = pango_language_from_string (lang); g_free (lang); } return result; }
static const gchar * get_sample_string (FT_Face face) { const gchar *text; text = pango_language_get_sample_string (NULL); if (!check_font_contain_text (face, text)) { text = pango_language_get_sample_string (pango_language_from_string ("en_US")); } return text; }
static void gst_imx_g2d_time_overlay_class_init (GstImxG2DTimeOverlayClass * klass) { GstElementClass *gstelement_class; GstImxG2DBaseTextOverlayClass *gsttextoverlay_class; GObjectClass *gobject_class; PangoContext *context; PangoFontDescription *font_description; gsttextoverlay_class = (GstImxG2DBaseTextOverlayClass *) klass; gstelement_class = (GstElementClass *) klass; gobject_class = (GObjectClass *) klass; gst_element_class_set_static_metadata (gstelement_class, "Time overlay", "Filter/Editor/Video", "Overlays buffer time stamps on a video stream", "Tim-Philipp Müller <*****@*****.**>"); gsttextoverlay_class->get_text = gst_imx_g2d_time_overlay_get_text; gobject_class->set_property = gst_imx_g2d_time_overlay_set_property; gobject_class->get_property = gst_imx_g2d_time_overlay_get_property; g_object_class_install_property (gobject_class, PROP_TIME_LINE, g_param_spec_enum ("time-mode", "Time Mode", "What time to show", GST_TYPE_IMX_G2D_TIME_OVERLAY_TIME_LINE, DEFAULT_TIME_LINE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_TIMEALIGNMENT, g_param_spec_enum ("time-alignment", "Time alignment", "Time alignment of the text", GST_TYPE_IMX_G2D_TIME_OVERLAY_TIMEALIGN, DEFAULT_PROP_TIMEALIGNMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (gsttextoverlay_class->pango_lock); context = gsttextoverlay_class->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (gsttextoverlay_class->pango_lock); }
static gboolean set_pango_sample_string (SushiFontWidget *self) { const gchar *sample_string; gboolean retval = FALSE; sample_string = pango_language_get_sample_string (pango_language_from_string (NULL)); if (check_font_contain_text (self->priv->face, sample_string)) retval = TRUE; if (!retval) { sample_string = pango_language_get_sample_string (pango_language_from_string ("C")); if (check_font_contain_text (self->priv->face, sample_string)) retval = TRUE; } if (retval) { g_free (self->priv->sample_string); self->priv->sample_string = g_strdup (sample_string); } return retval; }
void NS_GetComplexLineBreaks(const PRUnichar* aText, PRUint32 aLength, PRUint8* aBreakBefore) { NS_ASSERTION(aText, "aText shouldn't be null"); memset(aBreakBefore, PR_FALSE, aLength * sizeof(PRUint8)); nsAutoTArray<PangoLogAttr, 2000> attrBuffer; if (!attrBuffer.AppendElements(aLength + 1)) return; NS_ConvertUTF16toUTF8 aUTF8(aText, aLength); const gchar* p = aUTF8.Data(); const gchar* end = p + aUTF8.Length(); PRUint32 u16Offset = 0; static PangoLanguage* language = pango_language_from_string("en"); while (p < end) { PangoLogAttr* attr = attrBuffer.Elements(); pango_get_log_attrs(p, end - p, -1, language, attr, attrBuffer.Length()); while (p < end) { aBreakBefore[u16Offset] = attr->is_line_break; if (NS_IS_LOW_SURROGATE(aText[u16Offset])) aBreakBefore[++u16Offset] = PR_FALSE; // Skip high surrogate ++u16Offset; PRBool err; PRUint32 ch = UTF8CharEnumerator::NextChar(&p, end, &err); ++attr; if (ch == 0 || err) { // pango_break (pango 1.16.2) only analyses text before the // first NUL (but sets one extra attr). Workaround loop to call // pango_break again to analyse after the NUL is done somewhere else // (gfx/thebes/gfxPangoFonts.cpp: SetupClusterBoundaries()). // So, we do the same here for pango_get_log_attrs. break; } } } }
static void gst_clock_overlay_class_init (GstClockOverlayClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; GstBaseTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; gsttextoverlay_class = (GstBaseTextOverlayClass *) klass; gobject_class->finalize = gst_clock_overlay_finalize; gobject_class->set_property = gst_clock_overlay_set_property; gobject_class->get_property = gst_clock_overlay_get_property; gst_element_class_set_static_metadata (gstelement_class, "Clock overlay", "Filter/Editor/Video", "Overlays the current clock time on a video stream", "Tim-Philipp Müller <*****@*****.**>"); gsttextoverlay_class->get_text = gst_clock_overlay_get_text; g_object_class_install_property (gobject_class, PROP_TIMEFORMAT, g_param_spec_string ("time-format", "Date/Time Format", "Format to use for time and date value, as in strftime.", DEFAULT_PROP_TIMEFORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (gsttextoverlay_class->pango_lock); context = gsttextoverlay_class->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (gsttextoverlay_class->pango_lock); }
void initfont(DC *dc, const char *fontstr) { PangoFontMetrics *metrics; dc->pgc = pango_xft_get_context(dc->dpy, 0); dc->pfd = pango_font_description_from_string(fontstr); if(pango_font_description_get_size(dc->pfd) == 0) pango_font_description_set_size(dc->pfd, 12 * PANGO_SCALE); metrics = pango_context_get_metrics(dc->pgc, dc->pfd, pango_language_from_string("")); dc->font.ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; dc->font.descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; dc->font.height = dc->font.ascent + dc->font.descent; pango_font_metrics_unref(metrics); dc->plo = pango_layout_new(dc->pgc); pango_layout_set_font_description(dc->plo, dc->pfd); }
// -------------------------------------------------------------- // - Font services ---------------------------------------------- // -------------------------------------------------------------- // "width" feature for font is not portable: has been replaced by // horizontal scaling of device context. const VGFont* GSystemGtk::CreateVGFont( const char * faceName, int size, int properties ) const { PangoFontDescription *pangoFontDescr = pango_font_description_new(); pango_font_description_set_family( pangoFontDescr, faceName ); int myWeight = PANGO_WEIGHT_NORMAL; PangoStyle myStyle = PANGO_STYLE_NORMAL; if (properties) { if (properties & VGFont::kFontBold) myWeight = PANGO_WEIGHT_BOLD; if (properties & VGFont::kFontItalic) myStyle = PANGO_STYLE_ITALIC; } pango_font_description_set_style( pangoFontDescr, myStyle ); // pango_font_description_set_size( pangoFontDescr, height * PANGO_SCALE / 10 ); pango_font_description_set_size( pangoFontDescr, size * PANGO_SCALE / 10 ); // + underline ?? // printf( "ok... where is the font ? %s italic=%d\n", faceName, italic ); //XXX: GetThe font into the pangocontext PangoContext* pangoContext = gdk_pango_context_get(); PangoLanguage* pangoLanguage = pango_language_from_string( "en-us" ); PangoFontset *fontset = pango_context_load_fontset( pangoContext, pangoFontDescr, pangoLanguage ); GFontGtk * outFont = 0; if( fontset ) outFont = new GFontGtk( pangoFontDescr, faceName, size, properties, 0 ); else g_object_unref( G_OBJECT( pangoFontDescr) ); return outFont; }
static void gst_clock_overlay_class_init (GstClockOverlayClass * klass) { GObjectClass *gobject_class; GstTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gobject_class = (GObjectClass *) klass; gsttextoverlay_class = (GstTextOverlayClass *) klass; gobject_class->finalize = gst_clock_overlay_finalize; gobject_class->set_property = gst_clock_overlay_set_property; gobject_class->get_property = gst_clock_overlay_get_property; gsttextoverlay_class->get_text = gst_clock_overlay_get_text; g_object_class_install_property (gobject_class, PROP_TIMEFORMAT, g_param_spec_string ("time-format", "Date/Time Format", "Format to use for time and date value, as in strftime.", DEFAULT_PROP_TIMEFORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); }
/** * anaconda_apply_language: * @label: (transfer none): The widget to which to apply the language * @language: The language to apply to the widget * * Apply a Pango language attribute to a label. * * For some formatting decisions, in particular the font choice, the language * of the text being rendered needs to be known. This is especially the case * for the Chinese, Japanese and Korean translations, since Unicode uses a * single codepoint for the CJK characters across languages, even when the * particular language may render the character very differently. For example, * U+76F4 (直) shows up a good bit in the translations, it is rendered differently * in Chinese and Japanese, and it is considered unreadable between the two. * * This function applies a #PangoAttrLanguage attribute to the label so that * the underlying renderer can do the right thing. * * Since: 3.4 */ void anaconda_apply_language(GtkLabel *label, const gchar *language) { PangoLanguage *pango_language; PangoAttribute *attr; PangoAttrList *attrlist; gboolean attrlist_unref = FALSE; pango_language = pango_language_from_string(language); attr = pango_attr_language_new(pango_language); /* If the label already has an attribute list, modify it, otherwise create a new one. */ attrlist = gtk_label_get_attributes(label); if (!attrlist) { attrlist = pango_attr_list_new(); attrlist_unref = TRUE; } pango_attr_list_change(attrlist, attr); gtk_label_set_attributes(label, attrlist); /* Drop the local attrlist reference if there is one */ if (attrlist_unref) { pango_attr_list_unref(attrlist); } }
static Image *ReadCAPTIONImage(const ImageInfo *image_info, ExceptionInfo *exception) { char *caption, *property; const char *option; DrawInfo *draw_info; FT_Bitmap *canvas; Image *image; PangoAlignment align; PangoContext *context; PangoFontDescription *description; PangoFontMap *fontmap; PangoGravity gravity; PangoLayout *layout; PangoRectangle extent; PixelPacket fill_color; RectangleInfo page; register PixelPacket *q; register unsigned char *p; ssize_t y; /* 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"); /* Get context. */ fontmap=(PangoFontMap *) pango_ft2_font_map_new(); pango_ft2_font_map_set_resolution((PangoFT2FontMap *) fontmap, image->x_resolution,image->y_resolution); option=GetImageOption(image_info,"caption:hinting"); pango_ft2_font_map_set_default_substitute((PangoFT2FontMap *) fontmap, PangoSubstitute,(char *) option,NULL); context=pango_font_map_create_context(fontmap); option=GetImageOption(image_info,"caption: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 WestGravity: gravity=PANGO_GRAVITY_WEST; break; case EastGravity: 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,"caption: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,"caption:auto-dir"); if (option != (const char *) NULL) pango_layout_set_auto_dir(layout,1); option=GetImageOption(image_info,"caption: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,"caption:justify"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) pango_layout_set_justify(layout,1); option=GetImageOption(image_info,"caption:single-paragraph"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) pango_layout_set_single_paragraph_mode(layout,1); option=GetImageOption(image_info,"caption: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,"caption:indent"); if (option != (const char *) NULL) pango_layout_set_indent(layout,(StringToLong(option)*image->x_resolution* PANGO_SCALE+36)/72); switch (draw_info->align) { case CenterAlign: align=PANGO_ALIGN_CENTER; break; case RightAlign: align=PANGO_ALIGN_RIGHT; break; case LeftAlign: default: 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); description=pango_font_description_from_string(draw_info->font == (char *) NULL ? "helvetica" : draw_info->font); pango_font_description_set_size(description,PANGO_SCALE*draw_info->pointsize); pango_layout_set_font_description(layout,description); pango_font_description_free(description); property=InterpretImageProperties(image_info,image,image_info->filename); (void) SetImageProperty(image,"caption",property); property=DestroyString(property); caption=ConstantString(GetImageProperty(image,"caption")); /* Render caption. */ option=GetImageOption(image_info,"caption:markup"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) pango_layout_set_markup(layout,caption,-1); else pango_layout_set_text(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; } else { image->columns-=2*page.x; pango_layout_set_width(layout,(PANGO_SCALE*image->columns* image->x_resolution+36.0)/72.0); } if (image->rows == 0) { pango_layout_get_pixel_extents(layout,NULL,&extent); image->rows=extent.y+extent.height; } else { image->rows-=2*page.y; pango_layout_set_height(layout,(PANGO_SCALE*image->rows* image->y_resolution+36.0)/72.0); } /* Create canvas. */ canvas=(FT_Bitmap *) AcquireMagickMemory(sizeof(*canvas)); if (canvas == (FT_Bitmap *) NULL) { draw_info=DestroyDrawInfo(draw_info); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } canvas->width=image->columns; canvas->pitch=(canvas->width+3) & ~3; canvas->rows=image->rows; canvas->buffer=(unsigned char *) AcquireQuantumMemory(canvas->pitch, canvas->rows*sizeof(*canvas->buffer)); if (canvas->buffer == (unsigned char *) NULL) { draw_info=DestroyDrawInfo(draw_info); canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } canvas->num_grays=256; canvas->pixel_mode=ft_pixel_mode_grays; ResetMagickMemory(canvas->buffer,0x00,canvas->pitch*canvas->rows); pango_ft2_render_layout(canvas,layout,0,0); /* Convert caption to image. */ image->columns+=2*page.x; image->rows+=2*page.y; if (SetImageBackgroundColor(image) == MagickFalse) { draw_info=DestroyDrawInfo(draw_info); canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); caption=DestroyString(caption); image=DestroyImageList(image); return((Image *) NULL); } p=canvas->buffer; for (y=page.y; y < (ssize_t) (image->rows-page.y); y++) { register ssize_t x; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; q+=page.x; for (x=page.x; x < (ssize_t) (image->columns-page.x); x++) { MagickRealType fill_opacity; (void) GetFillColor(draw_info,x,y,&fill_color); fill_opacity=QuantumRange-(*p)/canvas->num_grays*(QuantumRange- fill_color.opacity); if (draw_info->text_antialias == MagickFalse) fill_opacity=fill_opacity >= 0.5 ? 1.0 : 0.0; MagickCompositeOver(&fill_color,fill_opacity,q,q->opacity,q); p++; q++; } for ( ; x < (ssize_t) ((canvas->width+3) & ~3); x++) p++; } /* Relinquish resources. */ draw_info=DestroyDrawInfo(draw_info); canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); caption=DestroyString(caption); return(GetFirstImageInList(image)); }
static GdkPixmap * create_text_pixmap(GtkWidget *drawing_area, FT_Face face) { gint i, pixmap_width, pixmap_height, pos_y, textlen; GdkPixmap *pixmap = NULL; const gchar *text; Display *xdisplay; Drawable xdrawable; Visual *xvisual; Colormap xcolormap; XftDraw *draw; XftColor colour; XGlyphInfo extents; XftFont *font; gint *sizes = NULL, n_sizes, alpha_size; FcCharSet *charset = NULL; cairo_t *cr; GdkWindow *window = gtk_widget_get_window (drawing_area); text = pango_language_get_sample_string(NULL); if (! check_font_contain_text (face, text)) { pango_language_get_sample_string (pango_language_from_string ("en_US")); } textlen = strlen(text); /* create the XftDraw */ xdisplay = GDK_PIXMAP_XDISPLAY(window); #if GTK_CHECK_VERSION(3, 0, 0) xvisual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window)); #else xvisual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(window)); #endif xcolormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(window)); XftColorAllocName(xdisplay, xvisual, xcolormap, "black", &colour); /* work out what sizes to render */ if (FT_IS_SCALABLE(face)) { n_sizes = 8; sizes = g_new(gint, n_sizes); sizes[0] = 8; sizes[1] = 10; sizes[2] = 12; sizes[3] = 18; sizes[4] = 24; sizes[5] = 36; sizes[6] = 48; sizes[7] = 72; alpha_size = 24; } else { /* use fixed sizes */ n_sizes = face->num_fixed_sizes; sizes = g_new(gint, n_sizes); alpha_size = 0; for (i = 0; i < face->num_fixed_sizes; i++) { sizes[i] = face->available_sizes[i].height; /* work out which font size to render */ if (face->available_sizes[i].height <= 24) alpha_size = face->available_sizes[i].height; } } /* calculate size of pixmap to use (with 4 pixels padding) ... */ pixmap_width = 8; pixmap_height = 8; font = get_font(xdisplay, face, alpha_size, charset); charset = FcCharSetCopy (font->charset); XftTextExtentsUtf8(xdisplay, font, (guchar *)lowercase_text, strlen(lowercase_text), &extents); pixmap_height += extents.height + 4; pixmap_width = MAX(pixmap_width, 8 + extents.width); XftTextExtentsUtf8(xdisplay, font, (guchar *)uppercase_text, strlen(uppercase_text), &extents); pixmap_height += extents.height + 4; pixmap_width = MAX(pixmap_width, 8 + extents.width); XftTextExtentsUtf8(xdisplay, font, (guchar *)punctuation_text, strlen(punctuation_text), &extents); pixmap_height += extents.height + 4; pixmap_width = MAX(pixmap_width, 8 + extents.width); XftFontClose(xdisplay, font); pixmap_height += 8; for (i = 0; i < n_sizes; i++) { font = get_font(xdisplay, face, sizes[i], charset); if (!font) continue; XftTextExtentsUtf8(xdisplay, font, (guchar *)text, textlen, &extents); pixmap_height += extents.height + 4; pixmap_width = MAX(pixmap_width, 8 + extents.width); XftFontClose(xdisplay, font); } /* create pixmap */ gtk_widget_set_size_request(drawing_area, pixmap_width, pixmap_height); pixmap = gdk_pixmap_new(window, pixmap_width, pixmap_height, -1); if (!pixmap) goto end; cr = gdk_cairo_create (pixmap); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); cairo_destroy (cr); xdrawable = GDK_DRAWABLE_XID(pixmap); draw = XftDrawCreate(xdisplay, xdrawable, xvisual, xcolormap); /* draw text */ pos_y = 4; font = get_font(xdisplay, face, alpha_size, charset); draw_string(xdisplay, draw, font, &colour, lowercase_text, &pos_y); draw_string(xdisplay, draw, font, &colour, uppercase_text, &pos_y); draw_string(xdisplay, draw, font, &colour, punctuation_text, &pos_y); XftFontClose(xdisplay, font); pos_y += 8; for (i = 0; i < n_sizes; i++) { font = get_font(xdisplay, face, sizes[i], charset); if (!font) continue; draw_string(xdisplay, draw, font, &colour, text, &pos_y); XftFontClose(xdisplay, font); } g_signal_connect(drawing_area, "expose-event", G_CALLBACK(expose_event), pixmap); end: g_free(sizes); FcCharSetDestroy (charset); return pixmap; }
/** * pango_ot_tag_to_language: * @language_tag: A #PangoOTTag OpenType language-system tag * * Finds a #PangoLanguage corresponding to @language_tag. * * Return value: #PangoLanguage best matching @language_tag or * #PangoLanguage corresponding to the string "xx" if none found. * * Since: 1.18 **/ PangoLanguage * pango_ot_tag_to_language (PangoOTTag language_tag) { return pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language ((hb_tag_t) language_tag))); }
WTextItem FontSupport::measureText(const WFont& font, const WString& text, double maxWidth, bool wordWrap) { PANGO_LOCK; enabledFontFormats = enabledFontFormats_; /* * Note: accurate measuring on a bitmap requires that the transformation * is applied, because hinting may push chars to boundaries e.g. when * rotated (or scaled too?) */ std::string utf8 = text.toUTF8(); const char *s = utf8.c_str(); if (wordWrap) { int utflen = g_utf8_strlen(s, -1); PangoLogAttr *attrs = new PangoLogAttr[utflen + 1]; PangoLanguage *language = pango_language_from_string("en-US"); pango_get_log_attrs(s, utf8.length(), -1, language, attrs, utflen + 1); double w = 0, nextW = -1; int current = 0; int measured = 0; int end = 0; bool maxWidthReached = false; for (int i = 0; i < utflen + 1; ++i) { if (i == utflen || attrs[i].is_line_break) { int cend = g_utf8_offset_to_pointer(s, end) - s; WTextItem ti = measureText(font, WString::fromUTF8(utf8.substr(measured, cend - measured)), -1, false); if (isEpsilonMore(w + ti.width(), maxWidth)) { nextW = ti.width(); maxWidthReached = true; break; } else { measured = cend; current = g_utf8_offset_to_pointer(s, i) - s; w += ti.width(); if (i == utflen) { w += measureText(font, WString::fromUTF8(utf8.substr(measured)), -1, false).width(); measured = utf8.length(); } } } if (!attrs[i].is_white) end = i + 1; } delete[] attrs; if (maxWidthReached) { return WTextItem(WString::fromUTF8(utf8.substr(0, current)), w, nextW); } else { /* * For some reason, the sum of the individual widths is a bit less * (for longer stretches of text), so we re-measure it ! */ w = measureText(font, WString::fromUTF8(utf8.substr(0, measured)), -1, false).width(); return WTextItem(text, w); } } else { std::vector<PangoGlyphString *> glyphs; int width; GList *items = layoutText(font, utf8, glyphs, width); double w = pangoUnitsToDouble(width); for (unsigned i = 0; i < glyphs.size(); ++i) pango_glyph_string_free(glyphs[i]); g_list_foreach(items, (GFunc) pango_item_free, nullptr); g_list_free(items); return WTextItem(text, w); } }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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; PixelInfo 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,exception); (void) ResetImagePage(image,"0x0+0+0"); /* Format caption. */ option=GetImageArtifact(image,"filename"); if (option == (const char *) NULL) property=InterpretImageProperties(image_info,image,image_info->filename, exception); else if (LocaleNCompare(option,"pango:",6) == 0) property=InterpretImageProperties(image_info,image,option+6,exception); else property=InterpretImageProperties(image_info,image,option,exception); (void) SetImageProperty(image,"caption",property,exception); property=DestroyString(property); caption=ConstantString(GetImageProperty(image,"caption",exception)); /* Get context. */ fontmap=pango_cairo_font_map_new(); pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), image->resolution.x == 0.0 ? 90.0 : image->resolution.x); font_options=cairo_font_options_create(); option=GetImageArtifact(image,"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=GetImageArtifact(image,"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=GetImageArtifact(image,"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=GetImageArtifact(image,"pango:auto-dir"); if (option != (const char *) NULL) pango_layout_set_auto_dir(layout,1); option=GetImageArtifact(image,"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=GetImageArtifact(image,"pango:justify"); if (IfMagickTrue(IsStringTrue(option))) pango_layout_set_justify(layout,1); option=GetImageArtifact(image,"pango:single-paragraph"); if (IfMagickTrue(IsStringTrue(option))) pango_layout_set_single_paragraph_mode(layout,1); option=GetImageArtifact(image,"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=GetImageArtifact(image,"pango:indent"); if (option != (const char *) NULL) pango_layout_set_indent(layout,(int) ((StringToLong(option)* (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)*PANGO_SCALE+36)/ 90.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=GetImageArtifact(image,"pango:markup"); if ((option != (const char *) NULL) && (IsStringTrue(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_extents(layout,NULL,&extent); image->columns=(extent.x+extent.width+PANGO_SCALE/2)/PANGO_SCALE+2*page.x; } else { image->columns-=2*page.x; pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns* (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)+45.0)/90.0+ 0.5)); } if (image->rows == 0) { pango_layout_get_extents(layout,NULL,&extent); image->rows=(extent.y+extent.height+PANGO_SCALE/2)/PANGO_SCALE+2*page.y; } else { image->rows-=2*page.y; pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows* (image->resolution.y == 0.0 ? 90.0 : image->resolution.y)+45.0)/90.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,exception); p=pixels; GetPixelInfo(image,&fill_color); for (y=0; y < (ssize_t) image->rows; y++) { register Quantum *q; register ssize_t x; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { double gamma; fill_color.blue=(double) ScaleCharToQuantum(*p++); fill_color.green=(double) ScaleCharToQuantum(*p++); fill_color.red=(double) ScaleCharToQuantum(*p++); fill_color.alpha=(double) ScaleCharToQuantum(*p++); /* Disassociate alpha. */ gamma=1.0-QuantumScale*fill_color.alpha; gamma=PerceptibleReciprocal(gamma); fill_color.blue*=gamma; fill_color.green*=gamma; fill_color.red*=gamma; CompositePixelOver(image,&fill_color,fill_color.alpha,q,(double) GetPixelAlpha(image,q),q); q+=GetPixelChannels(image); } 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)); }
/** * pango_script_get_sample_language: * @script: a #PangoScript * * Given a script, finds a language tag that is reasonably * representative of that script. This will usually be the * most widely spoken or used language written in that script: * for instance, the sample language for %PANGO_SCRIPT_CYRILLIC * is <literal>ru</literal> (Russian), the sample lanugage * for %PANGO_SCRIPT_ARABIC is <literal>ar</literal>. * * For some * scripts, no sample language will be returned because there * is no language that is sufficiently representative. The best * example of this is %PANGO_SCRIPT_HAN, where various different * variants of written Chinese, Japanese, and Korean all use * significantly different sets of Han characters and forms * of shared characters. No sample language can be provided * for many historical scripts as well. * * Return value: a #PangoLanguage that is representative * of the script, or %NULL if no such language exists. * * Since: 1.4 **/ PangoLanguage * pango_script_get_sample_language (PangoScript script) { /* Note that in the following, we want * pango_language_includes_script() for the sample language * to include the script, so alternate orthographies * (Shavian for English, Osmanya for Somali, etc), typically * have no sample language */ const char sample_languages[][4] = { "", /* PANGO_SCRIPT_COMMON */ "", /* PANGO_SCRIPT_INHERITED */ "ar", /* PANGO_SCRIPT_ARABIC */ "hy", /* PANGO_SCRIPT_ARMENIAN */ "bn", /* PANGO_SCRIPT_BENGALI */ /* Used primarily in Taiwan, but not part of the standard * zh-tw orthography */ "", /* PANGO_SCRIPT_BOPOMOFO */ "chr", /* PANGO_SCRIPT_CHEROKEE */ "cop", /* PANGO_SCRIPT_COPTIC */ "ru", /* PANGO_SCRIPT_CYRILLIC */ /* Deseret was used to write English */ "", /* PANGO_SCRIPT_DESERET */ "hi", /* PANGO_SCRIPT_DEVANAGARI */ "am", /* PANGO_SCRIPT_ETHIOPIC */ "ka", /* PANGO_SCRIPT_GEORGIAN */ "", /* PANGO_SCRIPT_GOTHIC */ "el", /* PANGO_SCRIPT_GREEK */ "gu", /* PANGO_SCRIPT_GUJARATI */ "pa", /* PANGO_SCRIPT_GURMUKHI */ "", /* PANGO_SCRIPT_HAN */ "ko", /* PANGO_SCRIPT_HANGUL */ "he", /* PANGO_SCRIPT_HEBREW */ "ja", /* PANGO_SCRIPT_HIRAGANA */ "kn", /* PANGO_SCRIPT_KANNADA */ "ja", /* PANGO_SCRIPT_KATAKANA */ "km", /* PANGO_SCRIPT_KHMER */ "lo", /* PANGO_SCRIPT_LAO */ "en", /* PANGO_SCRIPT_LATIN */ "ml", /* PANGO_SCRIPT_MALAYALAM */ "mn", /* PANGO_SCRIPT_MONGOLIAN */ "my", /* PANGO_SCRIPT_MYANMAR */ /* Ogham was used to write old Irish */ "", /* PANGO_SCRIPT_OGHAM */ "", /* PANGO_SCRIPT_OLD_ITALIC */ "or", /* PANGO_SCRIPT_ORIYA */ "", /* PANGO_SCRIPT_RUNIC */ "si", /* PANGO_SCRIPT_SINHALA */ "syr", /* PANGO_SCRIPT_SYRIAC */ "ta", /* PANGO_SCRIPT_TAMIL */ "te", /* PANGO_SCRIPT_TELUGU */ "dv", /* PANGO_SCRIPT_THAANA */ "th", /* PANGO_SCRIPT_THAI */ "bo", /* PANGO_SCRIPT_TIBETAN */ "iu", /* PANGO_SCRIPT_CANADIAN_ABORIGINAL */ "", /* PANGO_SCRIPT_YI */ "tl", /* PANGO_SCRIPT_TAGALOG */ /* There are no ISO-636 language codes for the following * Phillipino languages/scripts */ "", /* PANGO_SCRIPT_HANUNOO */ "", /* PANGO_SCRIPT_BUHID */ "", /* PANGO_SCRIPT_TAGBANWA */ "", /* PANGO_SCRIPT_BRAILLE */ "", /* PANGO_SCRIPT_CYPRIOT */ "", /* PANGO_SCRIPT_LIMBU */ /* Used for Somali (so) in the past */ "", /* PANGO_SCRIPT_OSMANYA */ /* The Shavian alphabet was designed for English */ "", /* PANGO_SCRIPT_SHAVIAN */ "", /* PANGO_SCRIPT_LINEAR_B */ "", /* PANGO_SCRIPT_TAI_LE */ "uga", /* PANGO_SCRIPT_UGARITIC */ "", /* PANGO_SCRIPT_NEW_TAI_LUE */ "bug", /* PANGO_SCRIPT_BUGINESE */ /* The original script for Old Church Slavonic (chu), later * written with Cyrillic */ "", /* PANGO_SCRIPT_GLAGOLITIC */ /* Used for for Berber (ber), but Arabic script is more common */ "", /* PANGO_SCRIPT_TIFINAGH */ /* Syloti Nagri is used for Sylheti, no ISO 639 code */ "", /* PANGO_SCRIPT_SYLOTI_NAGRI */ "peo", /* PANGO_SCRIPT_OLD_PERSIAN */ "", /* PANGO_SCRIPT_KHAROSHTHI */ "", /* PANGO_SCRIPT_UNKNOWN */ "", /* PANGO_SCRIPT_BALINESE */ "", /* PANGO_SCRIPT_CUNEIFORM */ "", /* PANGO_SCRIPT_PHOENICIAN */ "", /* PANGO_SCRIPT_PHAGS_PA */ "nqo" /* PANGO_SCRIPT_NKO */ }; const char *sample_language; g_return_val_if_fail (script >= 0, NULL); g_return_val_if_fail ((guint)script < G_N_ELEMENTS (sample_languages), NULL); sample_language = sample_languages[script]; if (!sample_language[0]) return NULL; else return pango_language_from_string (sample_language); }
unsigned Gosu::pango::textWidth(const std::wstring& text, const std::wstring& fontFace, unsigned fontHeight, unsigned fontFlags) { g_type_init(); int dpi_x = 100, dpi_y = 100; context = pango_ft2_get_context(dpi_x, dpi_y); pango_context_set_language(context, pango_language_from_string ("en_US")); PangoDirection init_dir = PANGO_DIRECTION_LTR; pango_context_set_base_dir(context, init_dir); // static PangoFontDescription *font_description; font_description = pango_font_description_new(); pango_font_description_set_family(font_description, g_strdup(narrow(fontFace).c_str())); pango_font_description_set_style(font_description, (fontFlags & ffItalic) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight(font_description, (fontFlags & ffBold) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL); int init_scale = int(fontHeight/2.0 + 0.5); pango_font_description_set_size(font_description, init_scale * PANGO_SCALE); pango_context_set_font_description(context, font_description); layout = pango_layout_new(context); if(fontFlags & ffUnderline) { // PangoAttribute *attr; attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr->start_index = 0; attr->end_index = text.length(); // PangoAttrList* attrList; attrList = pango_attr_list_new(); pango_attr_list_insert(attrList, attr); pango_layout_set_attributes(layout, attrList); pango_attr_list_unref(attrList); } // IMPR: Catch errors? (Last NULL-Pointer) gchar* utf8Str = g_ucs4_to_utf8((gunichar*)text.c_str(), text.length(), NULL, NULL, NULL); pango_layout_set_text(layout, utf8Str, -1); g_free(utf8Str); PangoDirection base_dir = pango_context_get_base_dir(context); pango_layout_set_alignment(layout, base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); pango_layout_set_width(layout, -1); PangoRectangle logical_rect; pango_layout_get_pixel_extents(layout, NULL, &logical_rect); height = logical_rect.height; width = logical_rect.width; return width; }
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; }
static PangoLayout * rsvg_text_create_layout (RsvgDrawingCtx * ctx, RsvgState * state, const char *text, PangoContext * context) { PangoFontDescription *font_desc; PangoLayout *layout; PangoAttrList *attr_list; PangoAttribute *attribute; if (state->lang) pango_context_set_language (context, pango_language_from_string (state->lang)); if (state->unicode_bidi == UNICODE_BIDI_OVERRIDE || state->unicode_bidi == UNICODE_BIDI_EMBED) pango_context_set_base_dir (context, state->text_dir); font_desc = pango_font_description_copy (pango_context_get_font_description (context)); if (state->font_family) pango_font_description_set_family_static (font_desc, state->font_family); pango_font_description_set_style (font_desc, state->font_style); pango_font_description_set_variant (font_desc, state->font_variant); pango_font_description_set_weight (font_desc, state->font_weight); pango_font_description_set_stretch (font_desc, state->font_stretch); pango_font_description_set_size (font_desc, _rsvg_css_normalize_font_size (state, ctx) * PANGO_SCALE / ctx->dpi_y * 72); layout = pango_layout_new (context); pango_layout_set_font_description (layout, font_desc); pango_font_description_free (font_desc); attr_list = pango_attr_list_new (); attribute = pango_attr_letter_spacing_new (_rsvg_css_normalize_length (&state->letter_spacing, ctx, 'h') * PANGO_SCALE); attribute->start_index = 0; attribute->end_index = G_MAXINT; pango_attr_list_insert (attr_list, attribute); if (state->has_font_decor && text) { if (state->font_decor & TEXT_UNDERLINE) { attribute = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } if (state->font_decor & TEXT_STRIKE) { attribute = pango_attr_strikethrough_new (TRUE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } } pango_layout_set_attributes (layout, attr_list); pango_attr_list_unref (attr_list); if (text) pango_layout_set_text (layout, text, -1); else pango_layout_set_text (layout, NULL, 0); pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR || state->text_dir == PANGO_DIRECTION_TTB_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); return layout; }
static VALUE rg_initialize(VALUE self, VALUE language) { G_INITIALIZE(self, pango_language_from_string(RVAL2CSTR(language))); return Qnil; }
static void languages_parse_start_tag (GMarkupParseContext *ctx, const char *element_name, const char **attr_names, const char **attr_values, gpointer user_data, GError **error) { const char *ccode_longB; const char *ccode_longT; const char *ccode; const char *ccode_id; const char *lang_name; char *display_name; if (!(g_str_equal (element_name, "iso_639_entry") || g_str_equal (element_name, "iso_639_3_entry")) || attr_names == NULL || attr_values == NULL) return; ccode = NULL; ccode_longB = NULL; ccode_longT = NULL; ccode_id = NULL; lang_name = NULL; while (*attr_names && *attr_values) { if (g_str_equal (*attr_names, "iso_639_1_code")) { if (**attr_values) { if (strlen (*attr_values) != 2) return; ccode = *attr_values; } } else if (g_str_equal (*attr_names, "iso_639_2B_code")) { if (**attr_values) { if (strlen (*attr_values) != 3) return; ccode_longB = *attr_values; } } else if (g_str_equal (*attr_names, "iso_639_2T_code")) { if (**attr_values) { if (strlen (*attr_values) != 3) return; ccode_longT = *attr_values; } } else if (g_str_equal (*attr_names, "id")) { if (**attr_values) { if (strlen (*attr_values) != 2 && strlen (*attr_values) != 3) return; ccode_id = *attr_values; } } else if (g_str_equal (*attr_names, "name")) { lang_name = *attr_values; } ++attr_names; ++attr_values; } if (lang_name == NULL) return; display_name = get_display_name (lang_name); if (ccode != NULL) g_hash_table_insert (language_map, pango_language_from_string (ccode), g_strdup (display_name)); if (ccode_longB != NULL) g_hash_table_insert (language_map, pango_language_from_string (ccode_longB), g_strdup (display_name)); if (ccode_longT != NULL) g_hash_table_insert (language_map, pango_language_from_string (ccode_longT), g_strdup (display_name)); if (ccode_id != NULL) g_hash_table_insert (language_map, pango_language_from_string (ccode_id), g_strdup (display_name)); g_free (display_name); }
void make_stats (t_note_page *doc) { if (! doc) return; if (! doc->text_buffer) return; gboolean selected = TRUE; gchar *text; PangoLogAttr *attrs; gint words = 0; gint chars = 0; gint white_chars = 0; gint lines = 0; gint bytes = 0; gint i; selected = doc_is_sel (GTK_TEXT_BUFFER(doc->text_buffer)); if (! selected) text = doc_get_buf (GTK_TEXT_BUFFER(doc->text_buffer)); else text = doc_get_sel (doc); if (! text) return; if (! g_utf8_validate (text, -1, NULL)) return; lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER(doc->text_buffer)); chars = g_utf8_strlen (text, -1); attrs = g_new0 (PangoLogAttr, chars + 1); pango_get_log_attrs (text, -1, 0, pango_language_from_string ("C"), attrs, chars + 1); i = 0; while (i < chars) { if (attrs [i].is_white) ++white_chars; if (attrs [i].is_word_start) ++words; ++i; } if (chars == 0) lines = 0; bytes = strlen (text); gchar *s_bytes = g_strdup_printf(_("bytes: %d\n"), bytes); gchar *s_lines = g_strdup_printf(_("lines: %d\n"), lines); gchar *s_words = g_strdup_printf(_("words: %d\n"), words); gchar *s_chars = g_strdup_printf(_("chars: %d\n"), chars); gchar *s_charsnsp = g_strdup_printf(_("chars non-space: %d\n"), chars - white_chars); gchar *result; if (! selected) result = g_strconcat (_("stats for "), doc->file_name, ":\n", s_charsnsp, s_chars, s_words, s_lines, s_bytes, NULL); else result = g_strconcat (_("stats for selected:\n"), s_charsnsp, s_chars, s_words, s_bytes, NULL); g_free (s_bytes); g_free (s_charsnsp); g_free (s_chars); g_free (s_words); g_free (s_lines); g_free (result); g_free (attrs); g_free (text); }
int main (int argc, char **argv) { char *text; GtkWidget *window; GtkWidget *scrollwin; GtkWidget *vbox, *hbox; GtkWidget *frame; GtkWidget *checkbutton; gtk_init (&argc, &argv); if (argc != 2) { fprintf (stderr, "Usage: %s FILE\n", g_get_prgname ()); exit(1); } /* Create the list of paragraphs from the supplied file */ text = read_file (argv[1]); if (!text) exit(1); context = pango_win32_get_context (); paragraphs = split_paragraphs (text); pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family(font_description, "sans"); pango_font_description_set_size(font_description, 16 * PANGO_SCALE); #if 0 /* default init ok? */ font_description.style = PANGO_STYLE_NORMAL; font_description.variant = PANGO_VARIANT_NORMAL; font_description.weight = 500; font_description.stretch = PANGO_STRETCH_NORMAL; #endif pango_context_set_font_description (context, font_description); /* Create the user interface */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); vbox = gtk_vbox_new (FALSE, 4); gtk_container_add (GTK_CONTAINER (window), vbox); hbox = make_font_selector (); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); scrollwin = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (vbox), scrollwin, TRUE, TRUE, 0); layout = gtk_layout_new (NULL, NULL); gtk_widget_set_events (layout, GDK_BUTTON_PRESS_MASK); gtk_widget_set_app_paintable (layout, TRUE); gtk_signal_connect (GTK_OBJECT (layout), "size_allocate", GTK_SIGNAL_FUNC (size_allocate), paragraphs); gtk_signal_connect (GTK_OBJECT (layout), "expose_event", GTK_SIGNAL_FUNC (expose), paragraphs); gtk_signal_connect (GTK_OBJECT (layout), "draw", GTK_SIGNAL_FUNC (draw), paragraphs); gtk_signal_connect (GTK_OBJECT (layout), "button_press_event", GTK_SIGNAL_FUNC (button_press), paragraphs); #if GTK_CHECK_VERSION (1,3,2) gtk_widget_set_double_buffered (layout, FALSE); #endif gtk_container_add (GTK_CONTAINER (scrollwin), layout); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); message_label = gtk_label_new ("Current char:"); gtk_misc_set_padding (GTK_MISC (message_label), 1, 1); gtk_misc_set_alignment (GTK_MISC (message_label), 0.0, 0.5); gtk_container_add (GTK_CONTAINER (frame), message_label); checkbutton = gtk_check_button_new_with_label ("Use RTL global direction"); gtk_signal_connect (GTK_OBJECT (checkbutton), "toggled", GTK_SIGNAL_FUNC (checkbutton_toggled), NULL); gtk_box_pack_start (GTK_BOX (vbox), checkbutton, FALSE, FALSE, 0); gtk_widget_show_all (window); gtk_main (); return 0; }