void pango_clutter_ensure_glyph_cache_for_layout (PangoLayout *layout) { PangoContext *context; PangoFontMap *fontmap; PangoRenderer *renderer; PangoLayoutIter *iter; g_return_if_fail (PANGO_IS_LAYOUT (layout)); context = pango_layout_get_context (layout); fontmap = pango_context_get_font_map (context); g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap)); renderer = _pango_clutter_font_map_get_renderer (PANGO_CLUTTER_FONT_MAP (fontmap)); if ((iter = pango_layout_get_iter (layout)) == NULL) return; do { PangoLayoutLine *line; GSList *l; line = pango_layout_iter_get_line_readonly (iter); for (l = line->runs; l; l = l->next) { PangoLayoutRun *run = l->data; PangoGlyphString *glyphs = run->glyphs; int i; for (i = 0; i < glyphs->num_glyphs; i++) { PangoGlyphInfo *gi = &glyphs->glyphs[i]; if (!run->item->analysis.font) /* Font not found */ continue; pango_clutter_renderer_get_cached_glyph (renderer, run->item->analysis.font, gi->glyph); } } } while (pango_layout_iter_next_line (iter)); pango_layout_iter_free (iter); }
void pangox_layout_list_fonts(FILE *fp, PangoLayout *layout) { PangoContext *context; PangoFontMap *fontmap; PangoFontFamily **families; int n, i; context = pango_layout_get_context(layout); fontmap = pango_context_get_font_map(context); pango_font_map_list_families(fontmap, &families, &n); fprintf(fp, "Found %d fonts\n", n); for (i = 0; i < n; i++) { fprintf(fp, " %s\n", pango_font_family_get_name(families[i])); } g_free(families); }
void pango_clutter_render_layout_line (PangoLayoutLine *line, int x, int y, ClutterColor *color) { PangoContext *context; PangoFontMap *font_map; PangoRenderer *renderer; PangoClutterRenderer *priv; context = pango_layout_get_context (line->layout); font_map = pango_context_get_font_map (context); g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map)); renderer = _pango_clutter_font_map_get_renderer (PANGO_CLUTTER_FONT_MAP (font_map)); priv = PANGO_CLUTTER_RENDERER (renderer); priv->color = *color; pango_renderer_draw_layout_line (renderer, line, x, y); }
int unicodeGetFontList(char *str, int strLength) { PangoFontMap *fontMap; PangoFontFamily **fontFomilies; int count, i; str[0] = '\0'; if (cachedLayout == NULL) { cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1); cairo_t *cr = cairo_create(surface); cachedLayout = pango_cairo_create_layout(cr); } fontMap = pango_context_get_font_map(pango_layout_get_context(cachedLayout)); pango_font_map_list_families(fontMap, &fontFomilies, &count); for (i = 0; i < count; i++) { strncat(str, pango_font_family_get_name(fontFomilies[i]), strLength); strncat(str, "\n", strLength); } g_free(fontFomilies); return strlen(str); }
weed_plant_t *weed_setup(weed_bootstrap_f weed_boot) { weed_plant_t *plugin_info=weed_plugin_info_init(weed_boot,num_versions,api_versions); if (plugin_info!=NULL) { weed_plant_t *in_params[P_END+1],*gui; weed_plant_t *filter_class; PangoContext *ctx; const char *modes[]= {"Spiral text","Spinning letters","Letter starfield","Word coalesce",NULL}; char *rfx_strings[]= {"special|fileread|0|"}; char *deftextfile; int palette_list[2]; weed_plant_t *in_chantmpls[2]; weed_plant_t *out_chantmpls[2]; int flags,error; if (is_big_endian()) palette_list[0]=WEED_PALETTE_ARGB32; else palette_list[0]=WEED_PALETTE_BGRA32; palette_list[1]=WEED_PALETTE_END; in_chantmpls[0]=weed_channel_template_init("in channel 0",0,palette_list); in_chantmpls[1]=NULL; out_chantmpls[0]=weed_channel_template_init("out channel 0",WEED_CHANNEL_CAN_DO_INPLACE,palette_list); out_chantmpls[1]=NULL; init_unal(); // this section contains code // for configure fonts available num_fonts_available = 0; fonts_available = NULL; ctx = gdk_pango_context_get(); if (ctx) { PangoFontMap *pfm = pango_context_get_font_map(ctx); if (pfm) { int num = 0; PangoFontFamily **pff = NULL; pango_font_map_list_families(pfm, &pff, &num); if (num > 0) { // we should reserve num+1 for a final NULL pointer fonts_available = (char **)weed_malloc((num+1)*sizeof(char *)); if (fonts_available) { register int i; num_fonts_available = num; for (i = 0; i < num; ++i) { fonts_available[i] = strdup(pango_font_family_get_name(pff[i])); } // don't forget this thing fonts_available[num] = NULL; } } g_free(pff); } g_object_unref(ctx); } deftextfile=g_build_filename(g_get_home_dir(), "livestext.txt", NULL); in_params[P_TEXT]=weed_text_init("textfile","_Text file",deftextfile); gui=weed_parameter_template_get_gui(in_params[P_TEXT]); weed_set_int_value(gui,"maxchars",80); // for display only - fileread will override this flags=0; if (weed_plant_has_leaf(in_params[P_TEXT],"flags")) flags=weed_get_int_value(in_params[P_TEXT],"flags",&error); flags|=WEED_PARAMETER_REINIT_ON_VALUE_CHANGE; weed_set_int_value(in_params[P_TEXT],"flags",flags); in_params[P_MODE]=weed_string_list_init("mode","Effect _mode",0,modes); flags=0; if (weed_plant_has_leaf(in_params[P_MODE],"flags")) flags=weed_get_int_value(in_params[P_MODE],"flags",&error); flags|=WEED_PARAMETER_REINIT_ON_VALUE_CHANGE; weed_set_int_value(in_params[P_MODE],"flags",flags); in_params[P_END]=NULL; g_free(deftextfile); filter_class=weed_filter_class_init("puretext","Salsaman & Aleksej Penkov",1,0,&puretext_init,&puretext_process,NULL, in_chantmpls,out_chantmpls,in_params,NULL); gui=weed_filter_class_get_gui(filter_class); weed_set_string_value(gui,"layout_scheme","RFX"); weed_set_string_value(gui,"rfx_delim","|"); weed_set_string_array(gui,"rfx_strings",1,rfx_strings); weed_plugin_info_add_filter_class(plugin_info,filter_class); weed_set_int_value(plugin_info,"version",package_version); } return plugin_info; }
int mozilla_decoders_init(void) { static PRBool initialized = PR_FALSE; if (initialized) return 0; PangoContext* context = gdk_pango_context_get (); PangoFontMap* fontmap = pango_context_get_font_map (context); g_object_unref (context); if (!PANGO_IS_FC_FONT_MAP (fontmap)) return -1; encoder_hash = g_hash_table_new(g_str_hash, g_str_equal); cmap_hash = g_hash_table_new(g_str_hash, g_str_equal); wide_hash = g_hash_table_new(g_str_hash, g_str_equal); PRBool dumb = PR_FALSE; nsCOMPtr<nsIPersistentProperties> props; nsCOMPtr<nsISimpleEnumerator> encodeEnum; NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(props), NS_LITERAL_CSTRING("resource://gre/res/fonts/pangoFontEncoding.properties")); if (!props) goto loser; // Enumerate the properties in this file and figure out all of the // fonts for which we have custom encodings. props->Enumerate(getter_AddRefs(encodeEnum)); if (!encodeEnum) goto loser; while (encodeEnum->HasMoreElements(&dumb), dumb) { nsCOMPtr<nsIPropertyElement> prop; encodeEnum->GetNext(getter_AddRefs(prop)); if (!prop) goto loser; nsCAutoString name; prop->GetKey(name); nsAutoString value; prop->GetValue(value); if (!StringBeginsWith(name, NS_LITERAL_CSTRING("encoding."))) { printf("string doesn't begin with encoding?\n"); continue; } name = Substring(name, 9); if (StringEndsWith(name, NS_LITERAL_CSTRING(".ttf"))) { name = Substring(name, 0, name.Length() - 4); // Strip off a .wide if it's there. if (StringEndsWith(value, NS_LITERAL_STRING(".wide"))) { g_hash_table_insert(wide_hash, g_strdup(name.get()), g_strdup("wide")); value = Substring(value, 0, name.Length() - 5); } g_hash_table_insert(encoder_hash, g_strdup(name.get()), g_strdup(NS_ConvertUTF16toUTF8(value).get())); } else if (StringEndsWith(name, NS_LITERAL_CSTRING(".ftcmap"))) { name = Substring(name, 0, name.Length() - 7); g_hash_table_insert(cmap_hash, g_strdup(name.get()), g_strdup(NS_ConvertUTF16toUTF8(value).get())); } else { printf("unknown suffix used for mapping\n"); } } pango_fc_font_map_add_decoder_find_func(PANGO_FC_FONT_MAP(fontmap), mozilla_find_decoder, NULL, NULL); initialized = PR_TRUE; #ifdef DEBUG_CUSTOM_ENCODER printf("*** encoders\n"); g_hash_table_foreach(encoder_hash, (GHFunc)dump_hash, NULL); printf("*** cmaps\n"); g_hash_table_foreach(cmap_hash, (GHFunc)dump_hash, NULL); #endif return 0; loser: return -1; }
gboolean text_to_path (const Text *text, GArray *points) { cairo_t *cr; cairo_surface_t *surface; PangoLayout *layout; PangoRectangle ink_rect; char *str; gboolean ret = FALSE; if (!PANGO_IS_CAIRO_FONT_MAP (pango_context_get_font_map (dia_font_get_context()))) return FALSE; layout = pango_layout_new(dia_font_get_context()); pango_layout_set_font_description (layout, dia_font_get_description (text->font)); pango_layout_set_indent (layout, 0); pango_layout_set_justify (layout, FALSE); pango_layout_set_alignment (layout, text->alignment == ALIGN_LEFT ? PANGO_ALIGN_LEFT : text->alignment == ALIGN_RIGHT ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_CENTER); str = text_get_string_copy (text); pango_layout_set_text (layout, str, -1); g_free (str); pango_layout_get_extents (layout, &ink_rect, NULL); /* any surface should do - this one is always available */ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ink_rect.width / PANGO_SCALE, ink_rect.height / PANGO_SCALE); cr = cairo_create (surface); cairo_surface_destroy (surface); pango_cairo_layout_path (cr, layout); /* convert the path */ if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) { cairo_path_t *path; int i; path = cairo_copy_path (cr); for (i=0; i < path->num_data; i += path->data[i].header.length) { cairo_path_data_t *data = &path->data[i]; BezPoint bp; switch (data->header.type) { case CAIRO_PATH_MOVE_TO : bp.type = BEZ_MOVE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; break; case CAIRO_PATH_LINE_TO : bp.type = BEZ_LINE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; break; case CAIRO_PATH_CURVE_TO : bp.type = BEZ_CURVE_TO; bp.p1.x = data[1].point.x; bp.p1.y = data[1].point.y; bp.p2.x = data[2].point.x; bp.p2.y = data[2].point.y; bp.p3.x = data[3].point.x; bp.p3.y = data[3].point.y; break; case CAIRO_PATH_CLOSE_PATH : /* can't do anything */ default : continue; } g_array_append_val (points, bp); } ret = (path->status == CAIRO_STATUS_SUCCESS); cairo_path_destroy (path); } /* finally scale it ? */ /* clean up */ g_object_unref (layout); cairo_destroy (cr); return ret; }