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; }
int main (int argc, char** argv){ Fl_scheme(NULL); Fl_args(argc,argv); Fl_get_system_colors(); create_the_forms(); int i = 0; int k = Fl_set_fonts("-*"); sizes = malloc(sizeof(int*) * k); numsizes = malloc(sizeof(int) * k); i = 0; for (; i < k; i++) { int t; const char *name = Fl_get_font_name_with_attributes((Fl_Font)i,&t); char buffer[128]; if (t) { char *p = buffer; if (t & FL_BOLD) {*p++ = '@'; *p++ = 'b';} if (t & FL_ITALIC) {*p++ = '@'; *p++ = 'i';} *p++ = '@'; *p++ = '.'; // Suppress subsequent formatting - some MS fonts have '@' in their name strcpy(p,name); name = buffer; } Fl_Hold_Browser_add(fontobj,name); int s; int* _s = &s; int n = Fl_get_font_sizes((Fl_Font)i, _s); numsizes[i] = n; if (n) { sizes[i] = malloc(sizeof(int) * n); int j = 0; for (; j<n; j++){sizes[i][j] = _s[j];} } } Fl_Hold_Browser_set_value(fontobj,1); font_cb(fontobj,0); Fl_Double_Window_show_with_args(form,argc,argv); return Fl_run(); }
EDEFont font_chooser(EDEFont current_font) { EDEFont return_font; create_the_forms(); if(!numfonts) numfonts = fltk::list_fonts(all_fonts); // populate list of fonts fontobj->clear(); for(int i = 0; i < numfonts; i++) { fontobj->add(all_fonts[i]->name()); if (current_font.font && (strcasecmp(current_font.font->name(),all_fonts[i]->name())==0)) // it's a substring fontobj->value(i); } /*char* currentname = strdup(current_font.font->name()); fsor(int i = 0; i < numfonts; i++) { char* fontname = strdup(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->child(i)->label()) == current_font.size) { sizeobj->value(i); size_cb(sizeobj,0); } } // form->show(); form->exec(); // we have to construct a proper EDEFont to return return_font.defined = false; if (return_value) { return_font.font = fltk::font(fontobj->child(fontobj->value())->label()); //Style.h 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->child(sizeobj->value())->label()); 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() > 1) return_font.encoding = strdup(encobj->child(encobj->value())->label()); else return_font.encoding = 0; return_font.defined = true; } return return_font; }