summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/font/font_sdl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/font/font_sdl.cpp')
-rw-r--r--src/osd/modules/font/font_sdl.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/osd/modules/font/font_sdl.cpp b/src/osd/modules/font/font_sdl.cpp
index 62a97d39149..514e0cc0784 100644
--- a/src/osd/modules/font/font_sdl.cpp
+++ b/src/osd/modules/font/font_sdl.cpp
@@ -6,20 +6,17 @@
*/
#include "font_module.h"
-#include "modules/osdmodule.h"
#if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX) && !defined(SDLMAME_HAIKU) && !defined(SDLMAME_ANDROID)
#include "corestr.h"
-#include "corealloc.h"
+#include "emucore.h"
#include "fileio.h"
#include "unicode.h"
+#include "osdcore.h"
-#ifdef SDLMAME_EMSCRIPTEN
-#include <SDL_ttf.h>
-#else
#include <SDL2/SDL_ttf.h>
-#endif
+
#if !defined(SDLMAME_HAIKU) && !defined(SDLMAME_EMSCRIPTEN)
#include <fontconfig/fontconfig.h>
#endif
@@ -88,15 +85,15 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
// if no success, try the font path
if (!font)
{
- osd_printf_verbose("Searching font %s in -%s path/s\n", family.c_str(), font_path.c_str());
+ osd_printf_verbose("Searching font %s in -%s path/s\n", family, font_path);
//emu_file file(options().font_path(), OPEN_FLAG_READ);
- emu_file file(font_path.c_str(), OPEN_FLAG_READ);
- if (file.open(family.c_str()) == osd_file::error::NONE)
+ emu_file file(font_path, OPEN_FLAG_READ);
+ if (!file.open(family))
{
std::string full_name = file.fullpath();
font = TTF_OpenFont_Magic(full_name, POINT_SIZE, 0);
if (font)
- osd_printf_verbose("Found font %s\n", full_name.c_str());
+ osd_printf_verbose("Found font %s\n", full_name);
}
}
@@ -112,7 +109,7 @@ bool osd_font_sdl::open(std::string const &font_path, std::string const &_name,
{
if (!BDF_Check_Magic(name))
{
- osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.c_str());
+ osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name);
}
return false;
}
@@ -162,7 +159,7 @@ bool osd_font_sdl::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_
{
SDL_Color const fcol = { 0xff, 0xff, 0xff };
char ustr[16];
- ustr[utf8_from_uchar(ustr, ARRAY_LENGTH(ustr), chnum)] = '\0';
+ ustr[utf8_from_uchar(ustr, std::size(ustr), chnum)] = '\0';
std::unique_ptr<SDL_Surface, void (*)(SDL_Surface *)> const drawsurf(TTF_RenderUTF8_Solid(m_font.get(), ustr, fcol), &SDL_FreeSurface);
// was nothing returned?
@@ -174,7 +171,7 @@ bool osd_font_sdl::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_
// copy the rendered character image into it
for (int y = 0; y < bitmap.height(); y++)
{
- std::uint32_t *const dstrow = &bitmap.pix32(y);
+ std::uint32_t *const dstrow = &bitmap.pix(y);
std::uint8_t const *const srcrow = reinterpret_cast<std::uint8_t const *>(drawsurf->pixels) + (y * drawsurf->pitch);
for (int x = 0; x < drawsurf->w; x++)
@@ -194,14 +191,13 @@ bool osd_font_sdl::get_bitmap(char32_t chnum, bitmap_argb32 &bitmap, std::int32_
osd_font_sdl::TTF_Font_ptr osd_font_sdl::TTF_OpenFont_Magic(std::string const &name, int fsize, long index)
{
emu_file file(OPEN_FLAG_READ);
- if (file.open(name.c_str()) == osd_file::error::NONE)
+ if (!file.open(name))
{
unsigned char const ttf_magic[] = { 0x00, 0x01, 0x00, 0x00, 0x00 };
unsigned char const ttc1_magic[] = { 0x74, 0x74, 0x63, 0x66, 0x00, 0x01, 0x00, 0x00 };
unsigned char const ttc2_magic[] = { 0x74, 0x74, 0x63, 0x66, 0x00, 0x02, 0x00, 0x00 };
- auto buffer_size = std::max({ sizeof(ttf_magic), sizeof(ttc1_magic), sizeof(ttc2_magic) });
- unsigned char buffer[buffer_size];
- auto const bytes_read = file.read(buffer, buffer_size);
+ unsigned char buffer[std::max({ sizeof(ttf_magic), sizeof(ttc1_magic), sizeof(ttc2_magic) })];
+ auto const bytes_read = file.read(buffer, std::size(buffer));
file.close();
if (((bytes_read >= sizeof(ttf_magic)) && !std::memcmp(buffer, ttf_magic, sizeof(ttf_magic))) ||
@@ -215,7 +211,7 @@ osd_font_sdl::TTF_Font_ptr osd_font_sdl::TTF_OpenFont_Magic(std::string const &n
bool osd_font_sdl::BDF_Check_Magic(std::string const &name)
{
emu_file file(OPEN_FLAG_READ);
- if (file.open(name.c_str()) == osd_file::error::NONE)
+ if (!file.open(name))
{
unsigned char const magic[] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' };
unsigned char buffer[sizeof(magic)];
@@ -304,7 +300,7 @@ public:
return std::make_unique<osd_font_sdl>();
}
- virtual int init(const osd_options &options) override
+ virtual int init(osd_interface &osd, const osd_options &options) override
{
if (TTF_Init() == -1)
{
@@ -350,10 +346,10 @@ bool font_sdl::get_font_families(std::string const &font_path, std::vector<std::
{
auto const compare_fonts = [](std::pair<std::string, std::string> const &a, std::pair<std::string, std::string> const &b) -> bool
{
- int const second = core_stricmp(a.second.c_str(), b.second.c_str());
+ int const second = core_stricmp(a.second, b.second);
if (second < 0) return true;
else if (second > 0) return false;
- else return core_stricmp(b.first.c_str(), b.first.c_str()) < 0;
+ else return core_stricmp(b.first, b.first) < 0;
};
std::string config((const char *)val.u.s);
std::string display(config);