Skip to content
12 changes: 12 additions & 0 deletions docs/source/techspecs/layout_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,18 @@ text
be an integer, where 0 (zero) means centred, 1 (one) means left-aligned, and
2 (two) means right-aligned. If the ``align`` attribute is absent, the text
will be centred.

You can also specify the font to use using the ``font`` attribute. This
contains a comma (``,``)-separated list of fonts to use in order of preference.
Font styles (Regular, Bold, Italic,oldItalic) are specified after the font name
separated by a vertical bar (``|``).

There are also three standard fonts available: ``serif``, ``sans-serif``
and ``monospace``; these can be given styles as above. Finally there is
``default`` as a fallback if no other fonts can be found.

A complex font specification might look like
``font="Helvetica|Regular,Arial|Bold,sans-serif|BoldItalic,default"``
led7seg
Draws a standard seven-segment (plus decimal point) digital LED/fluorescent
display in the specified colour. The low eight bits of the element’s state
Expand Down
34 changes: 23 additions & 11 deletions src/emu/rendfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ inline render_font::glyph &render_font::get_char(char32_t chnum)
// render_font - constructor
//-------------------------------------------------

render_font::render_font(render_manager &manager, const char *filename)
render_font::render_font(render_manager &manager, const char *filenames)
: m_manager(manager)
, m_format(format::UNKNOWN)
, m_height(0)
Expand All @@ -507,27 +507,39 @@ render_font::render_font(render_manager &manager, const char *filename)
memset(m_glyphs_cmd, 0, sizeof(m_glyphs_cmd));

// if this is an OSD font, we're done
if (filename)
if (filenames)
{
std::string_view remaining(filenames);
m_osdfont = manager.machine().osd().font_alloc();
if (m_osdfont && m_osdfont->open(manager.machine().options().font_path(), filename, m_height))

while (!remaining.empty())
{
m_scale = 1.0f / float(m_height);
m_format = format::OSD;
std::string::size_type const separator = remaining.find(',');
std::string filename(remaining.substr(0, separator));
LOG("Trying OSD font '%s'\n", filename);
remaining = separator != std::string::npos ? remaining.substr(separator + 1) : "";

//mamep: allocate command glyph font
render_font_command_glyph();
return;
if (m_osdfont && m_osdfont->open(manager.machine().options().font_path(), filename, m_height))
{
LOG("- Using OSD font '%s'\n", filename);
m_scale = 1.0f / float(m_height);
m_format = format::OSD;

//mamep: allocate command glyph font
render_font_command_glyph();
return;
}
}

m_osdfont.reset();
}

// if the filename is 'default' default to 'ui.bdf' for backwards compatibility
if (filename && !core_stricmp(filename, "default"))
filename = "ui.bdf";
if (filenames && !core_stricmp(filenames, "default"))
filenames = "ui.bdf";

// attempt to load an external BDF font first
if (filename && load_cached_bdf(filename))
if (filenames && load_cached_bdf(filenames))
{
//mamep: allocate command glyph font
render_font_command_glyph();
Expand Down
4 changes: 3 additions & 1 deletion src/emu/rendlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2476,20 +2476,22 @@ class layout_element::text_component : public component
{
m_string = env.get_attribute_string(compnode, "string");
m_textalign = env.get_attribute_int(compnode, "align", 0);
m_font = env.get_attribute_string(compnode, "font", "default");
}

protected:
// overrides
virtual void draw_aligned(running_machine &machine, bitmap_argb32 &dest, const rectangle &bounds, int state) override
{
auto font = machine.render().font_alloc("default");
auto font = machine.render().font_alloc(m_font.c_str());
draw_text(*font, dest, bounds, m_string, m_textalign, color(state));
}

private:
// internal state
std::string m_string; // string for text components
int m_textalign; // text alignment to box
std::string m_font; // the font to use
};


Expand Down
Loading
Loading