When a Document uses a font that Lomse can not find it sends this request to the user application, asking for the file path for the font to use. The user application has to answer this request by invoking method RequestFont::set_font_fullname() passing as argument the path to the font to use.
class MyApp
{
public:
...
static void lomse_request_handler_method(
void* pThis,
Request* pRequest);
}
void MyApp::initialize_lomse()
{
...
m_lomse.
init_library(pixel_format, resolution, reverse_y_axis, m_lomseReporter);
}
void MyApp::lomse_request_handler_method(
void* pThis,
Request* pRequest)
{
static_cast<MyApp*>(pThis)->on_lomse_request(pRequest);
}
void MyApp::on_lomse_request(
Request* pRequest)
{
switch (type)
{
case k_dynamic_content_request:
generate_dynamic_content( dynamic_cast<RequestDynamic*>(pRequest) );
break;
get_font_filename( dynamic_cast<RequestFont*>(pRequest) );
break;
default:
LogError("Unknown request %d", type);
}
}
{
string path = "/usr/share/fonts/truetype/";
string name = fontname;
if (name == "serif")
name = "Times New Roman";
else if (name == "sans-serif")
name = "Tahoma";
else if (name == "handwritten" || name == "cursive")
name = "Monotype Corsiva";
else if (name == "monospaced")
name = "Courier New";
string fontfile;
if (name == "Times New Roman")
{
if (italic && bold)
fontfile = "freefont/FreeSerifBoldItalic.ttf";
else if (italic)
fontfile = "freefont/FreeSerifItalic.ttf";
else if (bold)
fontfile = "freefont/FreeSerifBold.ttf";
else
fontfile = "freefont/FreeSerif.ttf";
}
else if (name == "Tahoma")
{
if (bold)
fontfile = "freefont/FreeSansOblique.ttf";
else
fontfile = "freefont/FreeSans.ttf";
}
else if (name == "Monotype Corsiva")
{
fontfile = "ttf-dejavu/DejaVuSans-Oblique.ttf";
}
else if (name == "Courier New")
{
if (italic && bold)
fontfile = "freefont/FreeMonoBoldOblique.ttf";
else if (italic)
fontfile = "freefont/FreeMonoOblique.ttf";
else if (bold)
fontfile = "freefont/FreeMonoBold.ttf";
else
fontfile = "freefont/FreeMono.ttf";
}
else
fontfile = "freefont/FreeSerif.ttf";
}