Ejemplo n.º 1
0
EDEFont fl_font_dialog(EDEFont current_font) 
{
	EDEFont return_font;

	create_the_forms();
	int numfonts = fl_list_fonts(all_fonts);

	// populate list of fonts
	Fl_String currentname = current_font.font->name();
	for(int i = 0; i < numfonts; i++) {
		Fl_String fontname = all_fonts[i]->name();
		fontobj->add(fontname);
 		if (currentname.lower_case().pos(fontname.lower_case())==0) // it's a substring
			fontobj->value(i);
	}

	// set bold, italic
	if (currentname.pos(" bold italic") == currentname.length()-12) {
		bold_button->value(true);
		italic_button->value(true);
	} else if (currentname.pos(" italic") == currentname.length()-7) {
		italic_button->value(true);
	} else if (currentname.pos(" bold") == currentname.length()-5) {
		bold_button->value(true);
	}

	// populate other lists
	textobj->encoding = current_font.encoding; // TODO: what if we're using XFT?
	font_cb(fontobj,0);
	for (int i=0; i < sizeobj->children(); i++) {
		if (atoi(sizeobj->text(i)) == current_font.size) {
			sizeobj->value(i);
			size_cb(sizeobj,0);
		}
	}

	form->exec();
	form->show();

	// we have to construct a proper EDEFont to return
	return_font.defined = false;
	if (return_value)
	{
		return_font.font = fl_find_font(fontobj->text(fontobj->value()));
		if (bold_button->value()) return_font.font = return_font.font->bold();
		if (italic_button->value()) return_font.font = return_font.font->italic();

		int size = atoi(sizeobj->text(sizeobj->value()));
		return_font.size = find_best_size(return_font.font, size);

		// on XFT encoding is always Unicode, so this field can be blank
		if (encobj->children() > 0) 
			return_font.encoding = encobj->text(encobj->value());
		else
			return_font.encoding = "";
		
		return_font.defined = true;
	}
	return return_font;
}