JSBool pango::JSContext::Constructor(::JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } pango::JSContext * myNewObject = 0; NATIVE * newNative = 0; if (argc == 0) { PangoContext * myContext = pango_context_new(); newNative = new NATIVE(myContext, false); } else { JS_ReportError(cx,"Constructor for %s: bad number of arguments: expected none () %d",ClassName(), argc); return JS_FALSE; } myNewObject = new pango::JSContext(OWNERPTR(newNative), newNative); if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); return JS_TRUE; } JS_ReportError(cx,"pango::JSContext::Constructor: bad parameters"); return JS_FALSE; }
PangoLayout * VwGraphicsCairo::GetPangoLayoutHelper() { if (m_fontMap == NULL) m_fontMap = pango_cairo_font_map_get_default(); if (m_context == NULL) { m_context = pango_context_new(); pango_context_set_font_map(m_context, m_fontMap); } if (m_layout == NULL) { m_layout = pango_layout_new(m_context); PangoAttrList* list = pango_attr_list_new(); PangoAttribute * fallbackAttrib = pango_attr_fallback_new(true); pango_attr_list_insert(list, fallbackAttrib); pango_layout_set_attributes(m_layout, list); pango_attr_list_unref(list); pango_layout_set_single_paragraph_mode(m_layout, true); } return m_layout; }
/* Create/get a pango context * * On windows we use the win32 context creator, on everything else we * use the cairo one. */ PangoContext * splitter_create_pango_context(void) { #ifdef _WIN32 return pango_win32_get_context(); #else return pango_context_new(); #endif }
// Returns the PangoFont structure corresponding to the closest available font // in the font map. Note that if the font is wholly missing, this could // correspond to a completely different font family and face. PangoFont* PangoFontInfo::ToPangoFont() const { InitFontconfig(); PangoFontMap* font_map = pango_cairo_font_map_get_default(); PangoContext* context = pango_context_new(); pango_cairo_context_set_resolution(context, resolution_); pango_context_set_font_map(context, font_map); PangoFont* font = NULL; { DISABLE_HEAP_LEAK_CHECK; font = pango_font_map_load_font(font_map, context, desc_); } g_object_unref(context); return font; }
static PangoFontMetrics * pango_cairo_win32_font_get_metrics (PangoFont *font, PangoLanguage *language) { PangoWin32Font *win32font = PANGO_WIN32_FONT (font); PangoCairoWin32Font *cwfont = PANGO_CAIRO_WIN32_FONT (font); PangoWin32MetricsInfo *info = NULL; /* Quiet gcc */ GSList *tmp_list; const char *sample_str = pango_language_get_sample_string (language); tmp_list = cwfont->metrics_by_lang; while (tmp_list) { info = tmp_list->data; if (info->sample_str == sample_str) /* We _don't_ need strcmp */ break; tmp_list = tmp_list->next; } if (!tmp_list) { PangoContext *context; if (!win32font->fontmap) return pango_font_metrics_new (); info = g_slice_new0 (PangoWin32MetricsInfo); cwfont->metrics_by_lang = g_slist_prepend (cwfont->metrics_by_lang, info); info->sample_str = sample_str; context = pango_context_new (); pango_context_set_font_map (context, win32font->fontmap); pango_context_set_language (context, language); pango_cairo_context_set_font_options (context, cwfont->options); info->metrics = create_metrics_for_context (font, context); g_object_unref (context); } return pango_font_metrics_ref (info->metrics); }
MapPainterSVG::MapPainterSVG(const StyleConfigRef& styleConfig) : MapPainter(styleConfig, new CoordBufferImpl<Vertex2D>()), coordBuffer((CoordBufferImpl<Vertex2D>*)transBuffer.buffer), stream(NULL), typeConfig(NULL) { #if defined(OSMSCOUT_MAP_SVG_HAVE_LIB_PANGO) #if !defined(GLIB_VERSION_2_36) /* Compatibility call for glibc versions prior to 2.36 */ g_type_init(); #endif pangoContext=pango_context_new(); pangoFontMap=pango_ft2_font_map_new(); pango_context_set_font_map(pangoContext, pangoFontMap); #endif }
/* static */ bool FontUtils::IsAvailableFont(const char* input_query_desc) { string query_desc(input_query_desc); if (PANGO_VERSION <= 12005) { // Strip commas and any ' Medium' substring in the name. query_desc.erase(std::remove(query_desc.begin(), query_desc.end(), ','), query_desc.end()); const string kMediumStr = " Medium"; std::size_t found = query_desc.find(kMediumStr); if (found != std::string::npos) { query_desc.erase(found, kMediumStr.length()); } } PangoFontDescription *desc = pango_font_description_from_string( query_desc.c_str()); PangoFont* selected_font = NULL; { InitFontconfig(); PangoFontMap* font_map = pango_cairo_font_map_get_default(); PangoContext* context = pango_context_new(); pango_context_set_font_map(context, font_map); { DISABLE_HEAP_LEAK_CHECK; selected_font = pango_font_map_load_font(font_map, context, desc); } g_object_unref(context); } PangoFontDescription* selected_desc = pango_font_describe(selected_font); bool equal = pango_font_description_equal(desc, selected_desc); tlog(3, "query weight = %d \t selected weight =%d\n", pango_font_description_get_weight(desc), pango_font_description_get_weight(selected_desc)); char* selected_desc_str = pango_font_description_to_string(selected_desc); tlog(2, "query_desc: '%s' Selected: 's'\n", query_desc.c_str(), selected_desc_str); g_free(selected_desc_str); pango_font_description_free(selected_desc); pango_font_description_free(desc); return equal; }
bool PangoFontInfo::CanRenderString(const char* utf8_word, int len, vector<string>* graphemes) const { if (graphemes) graphemes->clear(); // We check for font coverage of the text first, as otherwise Pango could // (undesirably) fall back to another font that does have the required // coverage. if (!CoversUTF8Text(utf8_word, len)) { return false; } // U+25CC dotted circle character that often (but not always) gets rendered // when there is an illegal grapheme sequence. const char32 kDottedCircleGlyph = 9676; bool bad_glyph = false; PangoFontMap* font_map = pango_cairo_font_map_get_default(); PangoContext* context = pango_context_new(); pango_context_set_font_map(context, font_map); PangoLayout* layout; { // Pango is not relasing the cached layout. DISABLE_HEAP_LEAK_CHECK; layout = pango_layout_new(context); } if (desc_) { pango_layout_set_font_description(layout, desc_); } else { PangoFontDescription *desc = pango_font_description_from_string( DescriptionName().c_str()); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); } pango_layout_set_text(layout, utf8_word, len); PangoLayoutIter* run_iter = NULL; { // Fontconfig caches some information here that is not freed before exit. DISABLE_HEAP_LEAK_CHECK; run_iter = pango_layout_get_iter(layout); } do { PangoLayoutRun* run = pango_layout_iter_get_run_readonly(run_iter); if (!run) { tlog(2, "Found end of line NULL run marker\n"); continue; } PangoGlyph dotted_circle_glyph; PangoFont* font = run->item->analysis.font; dotted_circle_glyph = pango_fc_font_get_glyph( reinterpret_cast<PangoFcFont*>(font), kDottedCircleGlyph); if (TLOG_IS_ON(2)) { PangoFontDescription* desc = pango_font_describe(font); char* desc_str = pango_font_description_to_string(desc); tlog(2, "Desc of font in run: %s\n", desc_str); g_free(desc_str); pango_font_description_free(desc); } PangoGlyphItemIter cluster_iter; gboolean have_cluster; for (have_cluster = pango_glyph_item_iter_init_start(&cluster_iter, run, utf8_word); have_cluster && !bad_glyph; have_cluster = pango_glyph_item_iter_next_cluster(&cluster_iter)) { const int start_byte_index = cluster_iter.start_index; const int end_byte_index = cluster_iter.end_index; int start_glyph_index = cluster_iter.start_glyph; int end_glyph_index = cluster_iter.end_glyph; string cluster_text = string(utf8_word + start_byte_index, end_byte_index - start_byte_index); if (graphemes) graphemes->push_back(cluster_text); if (IsUTF8Whitespace(cluster_text.c_str())) { tlog(2, "Skipping whitespace\n"); continue; } if (TLOG_IS_ON(2)) { printf("start_byte=%d end_byte=%d start_glyph=%d end_glyph=%d ", start_byte_index, end_byte_index, start_glyph_index, end_glyph_index); } for (int i = start_glyph_index, step = (end_glyph_index > start_glyph_index) ? 1 : -1; !bad_glyph && i != end_glyph_index; i+= step) { const bool unknown_glyph = (cluster_iter.glyph_item->glyphs->glyphs[i].glyph & PANGO_GLYPH_UNKNOWN_FLAG); const bool illegal_glyph = (cluster_iter.glyph_item->glyphs->glyphs[i].glyph == dotted_circle_glyph); bad_glyph = unknown_glyph || illegal_glyph; if (TLOG_IS_ON(2)) { printf("(%d=%d)", cluster_iter.glyph_item->glyphs->glyphs[i].glyph, bad_glyph ? 1 : 0); } } if (TLOG_IS_ON(2)) { printf(" '%s'\n", cluster_text.c_str()); } if (bad_glyph) tlog(1, "Found illegal glyph!\n"); } } while (!bad_glyph && pango_layout_iter_next_run(run_iter)); pango_layout_iter_free(run_iter); g_object_unref(context); g_object_unref(layout); if (bad_glyph && graphemes) graphemes->clear(); return !bad_glyph; }