From ae0e3fbf570a3eda623c4c729fce78684b190dd3 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Wed, 3 Aug 2016 14:54:28 +1000 Subject: [PATCH] quick fixes to some more stuff that isn't supplementary plane clean --- src/emu/rendfont.cpp | 24 +++++++++++++++--------- src/emu/rendfont.h | 4 ++-- src/frontend/mame/ui/menu.cpp | 1 - src/frontend/mame/ui/text.cpp | 22 ++++++++++++---------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/emu/rendfont.cpp b/src/emu/rendfont.cpp index 2f27fd0e506..7aebe9d9b35 100644 --- a/src/emu/rendfont.cpp +++ b/src/emu/rendfont.cpp @@ -18,6 +18,10 @@ #include "ui/cmdrender.h" +#include +#include + + const UINT64 render_font::CACHED_BDF_HASH_SIZE; //************************************************************************** @@ -55,6 +59,8 @@ inline render_font::glyph &render_font::get_char(unicode_char chnum) static glyph dummy_glyph; // grab the table; if none, return the dummy character + if ((chnum / 256) >= ARRAY_LENGTH(m_glyphs)) + return dummy_glyph; if (!m_glyphs[chnum / 256] && m_format == FF_OSD) m_glyphs[chnum / 256] = new glyph[256]; if (!m_glyphs[chnum / 256]) @@ -444,19 +450,19 @@ float render_font::string_width(float height, float aspect, const char *string) float render_font::utf8string_width(float height, float aspect, const char *utf8string) { - int length = strlen(utf8string); + std::size_t const length = std::strlen(utf8string); // loop over the string and accumulate widths int count; - int totwidth = 0; - for (int offset = 0; offset < length; offset += count) + INT32 totwidth = 0; + for (std::size_t offset = 0U; offset < length; offset += unsigned(count)) { unicode_char uchar; count = uchar_from_utf8(&uchar, utf8string + offset, length - offset); - if (count == -1) + if (count < 0) break; - if (uchar < 0x10000) - totwidth += get_char(uchar).width; + + totwidth += get_char(uchar).width; } // scale the final result based on height @@ -617,7 +623,7 @@ bool render_font::load_bdf() } // if we have everything, allocate a new character - if (charnum >= 0 && charnum < 65536 && rawdata != nullptr && bmwidth >= 0 && bmheight >= 0) + if (charnum >= 0 && charnum < (256 * ARRAY_LENGTH(m_glyphs)) && rawdata != nullptr && bmwidth >= 0 && bmheight >= 0) { // if we don't have a subtable yet, make one if (!m_glyphs[charnum / 256]) @@ -741,7 +747,7 @@ bool render_font::save_cached(const char *filename, UINT32 hash) // determine the number of characters int numchars = 0; - for (int chnum = 0; chnum < 65536; chnum++) + for (int chnum = 0; chnum < (256 * ARRAY_LENGTH(m_glyphs)); chnum++) { if (m_glyphs[chnum / 256]) { @@ -789,7 +795,7 @@ bool render_font::save_cached(const char *filename, UINT32 hash) // loop over all characters int tableindex = 0; - for (int chnum = 0; chnum < 65536; chnum++) + for (int chnum = 0; chnum < (256 * ARRAY_LENGTH(m_glyphs)); chnum++) { glyph &gl = get_char(chnum); if (gl.width > 0) diff --git a/src/emu/rendfont.h b/src/emu/rendfont.h index 88445510a45..52a65527282 100644 --- a/src/emu/rendfont.h +++ b/src/emu/rendfont.h @@ -96,14 +96,14 @@ private: int m_height; // height of the font, from ascent to descent int m_yoffs; // y offset from baseline to descent float m_scale; // 1 / height precomputed - glyph *m_glyphs[256]; // array of glyph subtables + glyph *m_glyphs[17*256]; // array of glyph subtables std::vector m_rawdata; // pointer to the raw data for the font UINT64 m_rawsize; // size of the raw font data std::unique_ptr m_osdfont; // handle to the OSD font int m_height_cmd; // height of the font, from ascent to descent int m_yoffs_cmd; // y offset from baseline to descent - glyph *m_glyphs_cmd[256]; // array of glyph subtables + EQUIVALENT_ARRAY(m_glyphs, glyph *) m_glyphs_cmd; // array of glyph subtables std::vector m_rawdata_cmd; // pointer to the raw data for the font // constants diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index 154fda55e31..32039886450 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -53,7 +53,6 @@ menu::global_state_ptr menu::get_global_state(running_machine &machine) std::lock_guard guard(s_global_state_guard); auto const it(s_global_states.find(&machine)); return (it != s_global_states.end()) ? it->second : global_state_ptr(); - } //------------------------------------------------- diff --git a/src/frontend/mame/ui/text.cpp b/src/frontend/mame/ui/text.cpp index ea6ebc743df..50e7cf6bbfe 100644 --- a/src/frontend/mame/ui/text.cpp +++ b/src/frontend/mame/ui/text.cpp @@ -12,6 +12,10 @@ #include "rendfont.h" #include "render.h" +#include +#include + + namespace ui { /*************************************************************************** INLINE FUNCTIONS @@ -111,10 +115,10 @@ text_layout::~text_layout() void text_layout::add_text(const char *text, const char_style &style) { - int position = 0; - int text_length = strlen(text); + std::size_t position = 0; + std::size_t const text_length = std::strlen(text); - while(position < text_length) + while (position < text_length) { // adding a character - we might change the width invalidate_calculated_actual_width(); @@ -124,16 +128,15 @@ void text_layout::add_text(const char *text, const char_style &style) { // get the current character unicode_char schar; - int scharcount; - scharcount = uchar_from_utf8(&schar, &text[position], text_length - position); - if (scharcount == -1) + int const scharcount = uchar_from_utf8(&schar, &text[position], text_length - position); + if (scharcount < 0) break; // if the line starts with a tab character, center it regardless text_justify line_justify = justify(); if (schar == '\t') { - position += scharcount; + position += unsigned(scharcount); line_justify = text_layout::CENTER; } @@ -142,12 +145,11 @@ void text_layout::add_text(const char *text, const char_style &style) } // get the current character - int scharcount; unicode_char ch; - scharcount = uchar_from_utf8(&ch, &text[position], text_length - position); + int const scharcount = uchar_from_utf8(&ch, &text[position], text_length - position); if (scharcount < 0) break; - position += scharcount; + position += unsigned(scharcount); // set up source information source_info source = { 0, };