FLTK logo

[fltk/fltk] fl_font(...) performance issue (#147)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

[fltk/fltk] fl_font(...) performance issue (#147) David Freese Oct 22, 2020  
 

I have need for a font browser that can selectively show all, fixed, or proportional fonts. To test for fixed vice proportional I am using the boolean (fl_width('.') == fl_width('W'), which requires that fl_font(font_nbr, font_size) be executed before the fl_width call. My fresh Debian 20.x with LibreOffice and Gimp has >2500 fonts on the system.

This test program demonstrates the problem.:
// ================================
// font test program
// ================================

#include
#include
#include <time.h>
#include <sys/time.h>

#include <FL/Fl.H>
#include <FL/fl_draw.H>

int numfonts;

void find_fonts(int find_fixed, bool print)
{
std::string fntname_old;
std::string fntname;
for (int i = 0; i < numfonts; i++) {
fntname = Fl::get_font_name((Fl_Font)i);
if (fntname_old == fntname) {
if (print)
std::cout << "DUPLICATE: " << fntname << std::endl;
} else {
if (find_fixed > 0) {
if (find_fixed == 2) {
fl_font(i, 14);
if (fl_width('.') == fl_width('W'))
if (print)
std::cout << "fixed: " << fntname << std::endl;
else
if (print)
std::cout << "proportional: " << fntname << std::endl;
} else {
if (print)
std::cout << "font name: " << fntname << std::endl;
}
} else {
if (print)
std::cout << "font name: " << fntname << std::endl;
}
}
fntname_old = fntname;
}
}

int main (int argc, char *argv[]) {
struct tm ztm, ltm;
time_t t_temp;
struct timeval now_val;
char ztbuf[100];

int print = 0;

if (argc == 2 && std::string(argv[1]) == "-p") print = 1;

numfonts = Fl::set_fonts(0);

gettimeofday(&now_val, NULL);
t_temp = (time_t)now_val.tv_sec;
gmtime_r(&t_temp, &ztm);
strftime(ztbuf, sizeof(ztbuf), "%H:%M:%S", &ztm);

std::cout << numfonts << " fonts recognized" << std::endl;
std::cout << "Start pass 0: " << ztbuf << std::endl;
find_fonts(0, print);
gettimeofday(&now_val, NULL);
t_temp = (time_t)now_val.tv_sec;
gmtime_r(&t_temp, &ztm);
strftime(ztbuf, sizeof(ztbuf), "%H:%M:%S", &ztm);

std::cout << "End Pass   0: " << ztbuf << std::endl;
if (print) std::cout << std::endl;

std::cout << "Start pass 1: " << ztbuf << std::endl;
find_fonts(1, print);
gettimeofday(&now_val, NULL);
t_temp = (time_t)now_val.tv_sec;
gmtime_r(&t_temp, &ztm);
strftime(ztbuf, sizeof(ztbuf), "%H:%M:%S", &ztm);
std::cout << "End Pass   1: " << ztbuf << std::endl;

std::cout << "Start pass 2: " << ztbuf << std::endl;
if (print) std::cout << std::endl;

find_fonts(2, print);
gettimeofday(&now_val, NULL);
t_temp = (time_t)now_val.tv_sec;
gmtime_r(&t_temp, &ztm);
strftime(ztbuf, sizeof(ztbuf), "%H:%M:%S", &ztm);
std::cout << "End Pass   2: " << ztbuf << std::endl;

return 0;

}

Build with $ fltk-config --compile find_fonts.cxx
Running find_fonts produces:
$ ./find_fonts
2650 fonts recognized
Start pass 0: 19:11:56
End Pass 0: 19:11:56
Start pass 1: 19:11:56
End Pass 1: 19:11:56
Start pass 2: 19:11:56
End Pass 2: 19:12:19

Simply adding the fl_font(...) adds 23 seconds to the process. This on a high end i5 processor.

Execute as "find_fonts -p" to print the font names and whether fixed or proportional. The program also tags adjacent duplicate fonts. That is probably a font data base issue.

fltk was built with libxft.

Any help would be appreciated.

Thank you. David


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.