Exemple #1
0
static void
html_render_entity(struct render_context *ctx, const struct array entity)
{
	uint32 c;

	c = html_parse_entity(entity);
	if ((uint32)-1 == c) {
		html_output_print(ctx->output, array_from_string("&"));
		html_output_print(ctx->output, array_init(entity.data, entity.size));
		html_output_print(ctx->output, array_from_string(";"));
	} else {
		size_t len;
		char buf[4];

		len = utf8_encode(c, buf);
		html_output_print(ctx->output, array_init(buf, len));
	}
}
Exemple #2
0
static void
html_output_print(struct html_output *output, const struct array *text)
{
	struct html_context *ctx;
   
	if (text->size <= 0)
		return;

	ctx = html_output_get_udata(output);
	if (ctx->title) {
		str_cat_len(ctx->title, text->data, text->size);
		return;
	}
#if GTK_CHECK_VERSION(2,0,0)
	{
		GtkTextBuffer *buffer;
		GtkTextIter iter;

		buffer = gtk_text_view_get_buffer(ctx->html_view->widget);
		gtk_text_buffer_get_end_iter(buffer, &iter);
		gtk_text_buffer_insert(buffer, &iter, text->data, text->size);
	}
#else
	{
		struct array str;
		gchar *to_free;

		if (locale_is_utf8()) {
			str = array_init(text->data, text->size);
			to_free = NULL;
		} else {
			to_free = h_strndup(text->data, text->size);
			str = array_from_string(lazy_utf8_to_ui_string(to_free));
		}
		gtk_text_insert(ctx->html_view->widget,
			NULL, NULL, NULL, str.data, str.size);
		HFREE_NULL(to_free);
	}
#endif
}
Exemple #3
0
static void
html_render_text(struct render_context *ctx, const struct array text)
{
	unsigned c_len;
	size_t i;
	bool whitespace = FALSE;
	struct array entity, current;

	entity = zero_array;
	current = zero_array;

	for (i = 0; i < text.size; i += c_len) {
		const unsigned char c = text.data[i];
		bool is_whitespace;

		is_whitespace = FALSE;
		c_len = utf8_first_byte_length_hint(c);
		if (!ctx->preformatted && is_ascii_space(c)) {
			if (whitespace)
				continue;
			is_whitespace = TRUE;
			whitespace = TRUE;
			if (0x20 == c && i > 0 && i < text.size - c_len) {
				const unsigned char next_c = text.data[i + c_len];

				if (!is_ascii_space(next_c))
					is_whitespace = FALSE;
			}
		} else {
			whitespace = FALSE;
		}
		if ('&' == c || ';' == c || is_whitespace) {
			if (current.size > 0) {
				html_output_print(ctx->output, current);
				current = zero_array;
			}
		}
		if (is_whitespace) {
			if (i > 0 || ctx->closing)
				html_output_print(ctx->output, array_from_string(" "));
		} else if ('&' == c) {
			if (entity.data) {
				html_render_entity(ctx, entity);
			}
			entity.data = deconstify_gchar(&text.data[i + c_len]);
			entity.size = 0;
			continue;
		} else if (';' == c) {
			if (entity.data) {
				html_render_entity(ctx, entity);
				entity = zero_array;
				continue;
			}
		} else if (entity.data) {
			entity.size += c_len;
		} else {
			if (!current.data)
				current.data = &text.data[i];
			current.size += c_len;
		}
	}
	if (current.size > 0) {
		html_output_print(ctx->output, current);
	}
}
Exemple #4
0
static G_GNUC_COLD void
load_faq(void)
{
	static const gchar faq_file[] = "FAQ";
	static file_path_t fp[6];
	static int initialized;
	GtkWidget *textview;
	const gchar *lang;
	guint i = 0;
	FILE *f;

	html_view_free(&faq_html_view);

	textview = gui_dlg_faq_lookup("textview_faq");
	lang = locale_get_language();

	if (initialized != 0) {
		i = initialized;
	} else {
		char *tmp;
		char *path;

		tmp = get_folder_path(PRIVLIB_PATH, NULL);
		
		if (tmp != NULL) {
			path = make_pathname(tmp, lang);
			file_path_set(&fp[i++], ostrdup(path), faq_file);
			HFREE_NULL(path);
			path = make_pathname(tmp, "en");
			file_path_set(&fp[i++], ostrdup(path), faq_file);
			HFREE_NULL(path);
		}

		HFREE_NULL(tmp);

		path = make_pathname(PRIVLIB_EXP, lang);
		file_path_set(&fp[i++], ostrdup(path), faq_file);
		HFREE_NULL(path);
		file_path_set(&fp[i++], PRIVLIB_EXP G_DIR_SEPARATOR_S "en", faq_file);
	
#ifndef OFFICIAL_BUILD
		path = make_pathname(PACKAGE_EXTRA_SOURCE_DIR, lang);
		file_path_set(&fp[i++], ostrdup(path), faq_file);
		HFREE_NULL(path);

		file_path_set(&fp[i++],
			PACKAGE_EXTRA_SOURCE_DIR G_DIR_SEPARATOR_S "en", faq_file);
#endif /* !OFFICIAL_BUILD */
		initialized = i;
	}

	g_assert(i <= G_N_ELEMENTS(fp));

	f = file_config_open_read_norename("FAQ", fp, i);
	if (f) {
		faq_html_view = html_view_load_file(textview, fileno(f));
		fclose(f);
	} else {
		static const gchar msg[] =
		N_(
			"<html>"
			"<head>"
			"<title>Frequently Asked Questions</title>"
			"</head>"
			"<body>"
			"<p>"
			"The FAQ document could not be loaded. Please read the "
			"<a href=\"http://gtk-gnutella.sourceforge.net/?page=faq\">"
			"FAQ online</a> instead."
			"</p>"
			"</body>"
			"</html>"
		);

		faq_html_view = html_view_load_memory(textview, array_from_string(msg));
	}
}