summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/font
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-01-28 09:20:10 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2015-01-28 09:20:10 +0100
commit26e7a17b6326aa5a75a6276e52cf84a94c16d7a0 (patch)
treebab4468226c59d590688e0ece892f5bfbca58736 /src/osd/modules/font
parent13b862c4fae88f0f819c2c4416d49249e4de45b9 (diff)
Cleanups and version bumpmame0158
Diffstat (limited to 'src/osd/modules/font')
-rw-r--r--src/osd/modules/font/font_module.h4
-rw-r--r--src/osd/modules/font/font_none.c29
-rw-r--r--src/osd/modules/font/font_osx.c266
-rw-r--r--src/osd/modules/font/font_sdl.c512
-rw-r--r--src/osd/modules/font/font_windows.c406
5 files changed, 607 insertions, 610 deletions
diff --git a/src/osd/modules/font/font_module.h b/src/osd/modules/font/font_module.h
index e5e5499a2f5..816b6fc839b 100644
--- a/src/osd/modules/font/font_module.h
+++ b/src/osd/modules/font/font_module.h
@@ -18,8 +18,8 @@
class font_module
{
public:
- virtual ~font_module() { }
- virtual osd_font *font_alloc() = 0;
+ virtual ~font_module() { }
+ virtual osd_font *font_alloc() = 0;
};
diff --git a/src/osd/modules/font/font_none.c b/src/osd/modules/font/font_none.c
index 4d6cdbe48c9..8f19e448be1 100644
--- a/src/osd/modules/font/font_none.c
+++ b/src/osd/modules/font/font_none.c
@@ -14,17 +14,17 @@
class osd_font_none : public osd_font
{
public:
- virtual ~osd_font_none() {};
+ virtual ~osd_font_none() {};
- virtual bool open(const char *font_path, const char *name, int &height);
- virtual void close();
- virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
+ virtual bool open(const char *font_path, const char *name, int &height);
+ virtual void close();
+ virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
private:
};
bool osd_font_none::open(const char *font_path, const char *_name, int &height)
{
- return false;
+ return false;
}
//-------------------------------------------------
@@ -46,22 +46,21 @@ void osd_font_none::close()
bool osd_font_none::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs)
{
- return false;
+ return false;
}
class font_none : public osd_module, public font_module
{
public:
- font_none()
- : osd_module(OSD_FONT_PROVIDER, "none"), font_module()
- {
- }
+ font_none()
+ : osd_module(OSD_FONT_PROVIDER, "none"), font_module()
+ {
+ }
- osd_font *font_alloc()
- {
- return global_alloc(osd_font_none);
- }
+ osd_font *font_alloc()
+ {
+ return global_alloc(osd_font_none);
+ }
};
MODULE_DEFINITION(FONT_NONE, font_none)
-
diff --git a/src/osd/modules/font/font_osx.c b/src/osd/modules/font/font_osx.c
index 6e7e62acedf..e7e58b35ad9 100644
--- a/src/osd/modules/font/font_osx.c
+++ b/src/osd/modules/font/font_osx.c
@@ -26,71 +26,71 @@
class osd_font_osx : public osd_font
{
public:
- virtual ~osd_font_osx() {};
+ virtual ~osd_font_osx() {};
- virtual bool open(const char *font_path, const char *name, int &height);
- virtual void close();
- virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
+ virtual bool open(const char *font_path, const char *name, int &height);
+ virtual void close();
+ virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
private:
- CTFontRef m_font;
+ CTFontRef m_font;
};
bool osd_font_osx::open(const char *font_path, const char *_name, int &height)
{
- CFStringRef font_name = NULL;
- CTFontRef ct_font = NULL;
- CTFontDescriptorRef font_descriptor;
- CGAffineTransform affine_transform = CGAffineTransformIdentity;
-
- m_font = NULL;
- astring name(_name);
- printf("FONT NAME %s\n", _name);
+ CFStringRef font_name = NULL;
+ CTFontRef ct_font = NULL;
+ CTFontDescriptorRef font_descriptor;
+ CGAffineTransform affine_transform = CGAffineTransformIdentity;
+
+ m_font = NULL;
+ astring name(_name);
+ printf("FONT NAME %s\n", _name);
#if 0
- if (name == "default")
- {
- name = "LucidaGrande";
- }
+ if (name == "default")
+ {
+ name = "LucidaGrande";
+ }
#endif
- /* handle bdf fonts in the core */
- if (name.len() > 4)
- if (name.makeupper().substr(name.len()-4,4) == ".BDF" )
- return false;
-
- font_name = CFStringCreateWithCString( NULL, name.cstr(), kCFStringEncodingUTF8 );
- if( font_name != NULL )
- {
- font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, 0.0); //POINT_SIZE );
-
- if( font_descriptor != NULL )
- {
- ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform );
-
- CFRelease( font_descriptor );
- }
- }
-
- CFRelease( font_name );
-
- if (!ct_font)
- {
- osd_printf_verbose("Couldn't find/open font %s, using MAME default\n", name.cstr());
- return false;
- }
-
- CFStringRef real_name = CTFontCopyPostScriptName( ct_font );
- char real_name_c_string[255];
- CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 );
- osd_printf_verbose("Matching font: %s\n", real_name_c_string);
- CFRelease( real_name );
-
- CGFloat line_height = 0.0;
- line_height += CTFontGetAscent(ct_font);
- line_height += CTFontGetDescent(ct_font);
- line_height += CTFontGetLeading(ct_font);
- height = ceilf(line_height * EXTRA_HEIGHT);
-
- m_font = ct_font;
- return true;
+ /* handle bdf fonts in the core */
+ if (name.len() > 4)
+ if (name.makeupper().substr(name.len()-4,4) == ".BDF" )
+ return false;
+
+ font_name = CFStringCreateWithCString( NULL, name.cstr(), kCFStringEncodingUTF8 );
+ if( font_name != NULL )
+ {
+ font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, 0.0); //POINT_SIZE );
+
+ if( font_descriptor != NULL )
+ {
+ ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform );
+
+ CFRelease( font_descriptor );
+ }
+ }
+
+ CFRelease( font_name );
+
+ if (!ct_font)
+ {
+ osd_printf_verbose("Couldn't find/open font %s, using MAME default\n", name.cstr());
+ return false;
+ }
+
+ CFStringRef real_name = CTFontCopyPostScriptName( ct_font );
+ char real_name_c_string[255];
+ CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 );
+ osd_printf_verbose("Matching font: %s\n", real_name_c_string);
+ CFRelease( real_name );
+
+ CGFloat line_height = 0.0;
+ line_height += CTFontGetAscent(ct_font);
+ line_height += CTFontGetDescent(ct_font);
+ line_height += CTFontGetLeading(ct_font);
+ height = ceilf(line_height * EXTRA_HEIGHT);
+
+ m_font = ct_font;
+ return true;
}
//-------------------------------------------------
@@ -100,10 +100,10 @@ bool osd_font_osx::open(const char *font_path, const char *_name, int &height)
void osd_font_osx::close()
{
- if( m_font != NULL )
- {
- CFRelease( m_font );
- }
+ if( m_font != NULL )
+ {
+ CFRelease( m_font );
+ }
}
//-------------------------------------------------
@@ -116,88 +116,88 @@ void osd_font_osx::close()
bool osd_font_osx::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs)
{
- UniChar uni_char;
- CGGlyph glyph;
- CTFontRef ct_font = m_font;
- const CFIndex count = 1;
- CGRect bounding_rect, success_rect;
- CGContextRef context_ref;
-
- if( chnum == ' ' )
- {
- uni_char = 'n';
- CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
- success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count );
- uni_char = chnum;
- CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
- }
- else
- {
- uni_char = chnum;
- CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
- success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count );
- }
-
- if( CGRectEqualToRect( success_rect, CGRectNull ) == false )
- {
- size_t bitmap_width;
- size_t bitmap_height;
-
- bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH);
- bitmap_width = bitmap_width == 0 ? 1 : bitmap_width;
-
- bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT);
-
- xoffs = yoffs = 0;
- width = bitmap_width;
-
- size_t bits_per_component;
- CGColorSpaceRef color_space;
- CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
-
- color_space = CGColorSpaceCreateDeviceRGB();
- bits_per_component = 8;
-
- bitmap.allocate(bitmap_width, bitmap_height);
-
- context_ref = CGBitmapContextCreate( bitmap.raw_pixptr(0), bitmap_width, bitmap_height, bits_per_component, bitmap.rowpixels()*4, color_space, bitmap_info );
-
- if( context_ref != NULL )
- {
- CGFontRef font_ref;
- font_ref = CTFontCopyGraphicsFont( ct_font, NULL );
- CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) );
- CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0);
- CGContextSetFont( context_ref, font_ref );
- CGContextSetFontSize( context_ref, POINT_SIZE );
- CGContextShowGlyphs( context_ref, &glyph, count );
- CGFontRelease( font_ref );
- CGContextRelease( context_ref );
- }
-
- CGColorSpaceRelease( color_space );
- }
-
- return bitmap.valid();
+ UniChar uni_char;
+ CGGlyph glyph;
+ CTFontRef ct_font = m_font;
+ const CFIndex count = 1;
+ CGRect bounding_rect, success_rect;
+ CGContextRef context_ref;
+
+ if( chnum == ' ' )
+ {
+ uni_char = 'n';
+ CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
+ success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count );
+ uni_char = chnum;
+ CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
+ }
+ else
+ {
+ uni_char = chnum;
+ CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count );
+ success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count );
+ }
+
+ if( CGRectEqualToRect( success_rect, CGRectNull ) == false )
+ {
+ size_t bitmap_width;
+ size_t bitmap_height;
+
+ bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH);
+ bitmap_width = bitmap_width == 0 ? 1 : bitmap_width;
+
+ bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT);
+
+ xoffs = yoffs = 0;
+ width = bitmap_width;
+
+ size_t bits_per_component;
+ CGColorSpaceRef color_space;
+ CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst;
+
+ color_space = CGColorSpaceCreateDeviceRGB();
+ bits_per_component = 8;
+
+ bitmap.allocate(bitmap_width, bitmap_height);
+
+ context_ref = CGBitmapContextCreate( bitmap.raw_pixptr(0), bitmap_width, bitmap_height, bits_per_component, bitmap.rowpixels()*4, color_space, bitmap_info );
+
+ if( context_ref != NULL )
+ {
+ CGFontRef font_ref;
+ font_ref = CTFontCopyGraphicsFont( ct_font, NULL );
+ CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) );
+ CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0);
+ CGContextSetFont( context_ref, font_ref );
+ CGContextSetFontSize( context_ref, POINT_SIZE );
+ CGContextShowGlyphs( context_ref, &glyph, count );
+ CGFontRelease( font_ref );
+ CGContextRelease( context_ref );
+ }
+
+ CGColorSpaceRelease( color_space );
+ }
+
+ return bitmap.valid();
}
class font_osx : public osd_module, public font_module
{
public:
- font_osx()
- : osd_module(OSD_FONT_PROVIDER, "osx"), font_module()
- {
- }
+ font_osx()
+ : osd_module(OSD_FONT_PROVIDER, "osx"), font_module()
+ {
+ }
- osd_font *font_alloc()
- {
- return global_alloc(osd_font_osx);
- }
+ osd_font *font_alloc()
+ {
+ return global_alloc(osd_font_osx);
+ }
};
#else /* SDLMAME_UNIX */
- MODULE_NOT_SUPPORTED(font_osx, OSD_FONT_PROVIDER, "osx")
+ MODULE_NOT_SUPPORTED(font_osx, OSD_FONT_PROVIDER, "osx")
#endif
MODULE_DEFINITION(FONT_OSX, font_osx)
diff --git a/src/osd/modules/font/font_sdl.c b/src/osd/modules/font/font_sdl.c
index 6ae72ca4fb3..d10f7209ab1 100644
--- a/src/osd/modules/font/font_sdl.c
+++ b/src/osd/modules/font/font_sdl.c
@@ -32,95 +32,95 @@
class osd_font_sdl : public osd_font
{
public:
- virtual ~osd_font_sdl() {};
+ virtual ~osd_font_sdl() {};
- virtual bool open(const char *font_path, const char *name, int &height);
- virtual void close();
- virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
+ virtual bool open(const char *font_path, const char *name, int &height);
+ virtual void close();
+ virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
private:
#ifndef SDLMAME_HAIKU
- TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles);
+ TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles);
#endif
- bool BDF_Check_Magic(astring name);
- TTF_Font * TTF_OpenFont_Magic(astring name, int fsize);
- TTF_Font *m_font;
+ bool BDF_Check_Magic(astring name);
+ TTF_Font * TTF_OpenFont_Magic(astring name, int fsize);
+ TTF_Font *m_font;
};
bool osd_font_sdl::open(const char *font_path, const char *_name, int &height)
{
- TTF_Font *font = (TTF_Font *)NULL;
- bool bakedstyles = false;
- int style = 0;
-
- // accept qualifiers from the name
- astring name(_name);
-
- if (name == "default")
- {
- name = "Liberation Sans";
- }
-
- bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0);
- bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0);
- bool underline = (name.replace(0, "[U]", "") + name.replace(0, "[u]", "") > 0);
- bool strike = (name.replace(0, "[S]", "") + name.replace(0, "[s]", "") > 0);
-
- // first up, try it as a filename
- font = TTF_OpenFont_Magic(name, POINT_SIZE);
-
- // if no success, try the font path
-
- if (!font)
- {
- osd_printf_verbose("Searching font %s in -%s\n", name.cstr(), OPTION_FONTPATH);
- //emu_file file(options().font_path(), OPEN_FLAG_READ);
- emu_file file(font_path, OPEN_FLAG_READ);
- if (file.open(name) == FILERR_NONE)
- {
- astring full_name = file.fullpath();
- font = TTF_OpenFont_Magic(full_name, POINT_SIZE);
- if (font)
- osd_printf_verbose("Found font %s\n", full_name.cstr());
- }
- }
-
- // if that didn't work, crank up the FontConfig database
+ TTF_Font *font = (TTF_Font *)NULL;
+ bool bakedstyles = false;
+ int style = 0;
+
+ // accept qualifiers from the name
+ astring name(_name);
+
+ if (name == "default")
+ {
+ name = "Liberation Sans";
+ }
+
+ bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0);
+ bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0);
+ bool underline = (name.replace(0, "[U]", "") + name.replace(0, "[u]", "") > 0);
+ bool strike = (name.replace(0, "[S]", "") + name.replace(0, "[s]", "") > 0);
+
+ // first up, try it as a filename
+ font = TTF_OpenFont_Magic(name, POINT_SIZE);
+
+ // if no success, try the font path
+
+ if (!font)
+ {
+ osd_printf_verbose("Searching font %s in -%s\n", name.cstr(), OPTION_FONTPATH);
+ //emu_file file(options().font_path(), OPEN_FLAG_READ);
+ emu_file file(font_path, OPEN_FLAG_READ);
+ if (file.open(name) == FILERR_NONE)
+ {
+ astring full_name = file.fullpath();
+ font = TTF_OpenFont_Magic(full_name, POINT_SIZE);
+ if (font)
+ osd_printf_verbose("Found font %s\n", full_name.cstr());
+ }
+ }
+
+ // if that didn't work, crank up the FontConfig database
#ifndef SDLMAME_HAIKU
- if (!font)
- {
- font = search_font_config(name, bold, italic, underline, bakedstyles);
- }
+ if (!font)
+ {
+ font = search_font_config(name, bold, italic, underline, bakedstyles);
+ }
#endif
- if (!font)
- {
- if (!BDF_Check_Magic(name))
- {
- osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.cstr());
- }
- return NULL;
- }
-
- // apply styles
- if (!bakedstyles)
- {
- style |= bold ? TTF_STYLE_BOLD : 0;
- style |= italic ? TTF_STYLE_ITALIC : 0;
- }
- style |= underline ? TTF_STYLE_UNDERLINE : 0;
- // SDL_ttf 2.0.9 and earlier does not define TTF_STYLE_STRIKETHROUGH
+ if (!font)
+ {
+ if (!BDF_Check_Magic(name))
+ {
+ osd_printf_verbose("font %s is not TrueType or BDF, using MAME default\n", name.cstr());
+ }
+ return NULL;
+ }
+
+ // apply styles
+ if (!bakedstyles)
+ {
+ style |= bold ? TTF_STYLE_BOLD : 0;
+ style |= italic ? TTF_STYLE_ITALIC : 0;
+ }
+ style |= underline ? TTF_STYLE_UNDERLINE : 0;
+ // SDL_ttf 2.0.9 and earlier does not define TTF_STYLE_STRIKETHROUGH
#if SDL_VERSIONNUM(TTF_MAJOR_VERSION, TTF_MINOR_VERSION, TTF_PATCHLEVEL) > SDL_VERSIONNUM(2,0,9)
- style |= strike ? TTF_STYLE_STRIKETHROUGH : 0;
+ style |= strike ? TTF_STYLE_STRIKETHROUGH : 0;
#else
- if (strike)
- osd_printf_warning("Ignoring strikethrough for SDL_TTF older than 2.0.10\n");
+ if (strike)
+ osd_printf_warning("Ignoring strikethrough for SDL_TTF older than 2.0.10\n");
#endif // PATCHLEVEL
- TTF_SetFontStyle(font, style);
+ TTF_SetFontStyle(font, style);
- height = TTF_FontLineSkip(font);
+ height = TTF_FontLineSkip(font);
- m_font = font;
- return true;
+ m_font = font;
+ return true;
}
//-------------------------------------------------
@@ -130,7 +130,7 @@ bool osd_font_sdl::open(const char *font_path, const char *_name, int &height)
void osd_font_sdl::close()
{
- TTF_CloseFont(this->m_font);
+ TTF_CloseFont(this->m_font);
}
//-------------------------------------------------
@@ -143,184 +143,184 @@ void osd_font_sdl::close()
bool osd_font_sdl::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs)
{
- TTF_Font *ttffont;
- SDL_Surface *drawsurf;
- SDL_Color fcol = { 0xff, 0xff, 0xff };
- UINT16 ustr[16];
+ TTF_Font *ttffont;
+ SDL_Surface *drawsurf;
+ SDL_Color fcol = { 0xff, 0xff, 0xff };
+ UINT16 ustr[16];
- ttffont = m_font;
+ ttffont = m_font;
- memset(ustr,0,sizeof(ustr));
- ustr[0] = (UINT16)chnum;
- drawsurf = TTF_RenderUNICODE_Solid(ttffont, ustr, fcol);
+ memset(ustr,0,sizeof(ustr));
+ ustr[0] = (UINT16)chnum;
+ drawsurf = TTF_RenderUNICODE_Solid(ttffont, ustr, fcol);
- // was nothing returned?
- if (drawsurf)
- {
- // allocate a MAME destination bitmap
- bitmap.allocate(drawsurf->w, drawsurf->h);
+ // was nothing returned?
+ if (drawsurf)
+ {
+ // allocate a MAME destination bitmap
+ bitmap.allocate(drawsurf->w, drawsurf->h);
- // copy the rendered character image into it
- for (int y = 0; y < bitmap.height(); y++)
- {
- UINT32 *dstrow = &bitmap.pix32(y);
- UINT8 *srcrow = (UINT8 *)drawsurf->pixels;
+ // copy the rendered character image into it
+ for (int y = 0; y < bitmap.height(); y++)
+ {
+ UINT32 *dstrow = &bitmap.pix32(y);
+ UINT8 *srcrow = (UINT8 *)drawsurf->pixels;
- srcrow += (y * drawsurf->pitch);
+ srcrow += (y * drawsurf->pitch);
- for (int x = 0; x < drawsurf->w; x++)
- {
- dstrow[x] = srcrow[x] ? rgb_t(0xff,0xff,0xff,0xff) : rgb_t(0x00,0xff,0xff,0xff);
- }
- }
+ for (int x = 0; x < drawsurf->w; x++)
+ {
+ dstrow[x] = srcrow[x] ? rgb_t(0xff,0xff,0xff,0xff) : rgb_t(0x00,0xff,0xff,0xff);
+ }
+ }
- // what are these?
- xoffs = yoffs = 0;
- width = drawsurf->w;
+ // what are these?
+ xoffs = yoffs = 0;
+ width = drawsurf->w;
- SDL_FreeSurface(drawsurf);
- }
+ SDL_FreeSurface(drawsurf);
+ }
- return bitmap.valid();
+ return bitmap.valid();
}
TTF_Font * osd_font_sdl::TTF_OpenFont_Magic(astring name, int fsize)
{
- emu_file file(OPEN_FLAG_READ);
- if (file.open(name) == FILERR_NONE)
- {
- unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
- unsigned char magic[5] = { 0x00, 0x01, 0x00, 0x00, 0x00 };
- file.read(buffer,5);
- if (memcmp(buffer, magic, 5))
- return NULL;
- }
- return TTF_OpenFont(name.cstr(), POINT_SIZE);
+ emu_file file(OPEN_FLAG_READ);
+ if (file.open(name) == FILERR_NONE)
+ {
+ unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
+ unsigned char magic[5] = { 0x00, 0x01, 0x00, 0x00, 0x00 };
+ file.read(buffer,5);
+ if (memcmp(buffer, magic, 5))
+ return NULL;
+ }
+ return TTF_OpenFont(name.cstr(), POINT_SIZE);
}
bool osd_font_sdl::BDF_Check_Magic(astring name)
{
- emu_file file(OPEN_FLAG_READ);
- if (file.open(name) == FILERR_NONE)
- {
- unsigned char buffer[9];
- unsigned char magic[9] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' };
- file.read(buffer, 9);
- file.close();
- if (!memcmp(buffer, magic, 9))
- return true;
- }
-
- return false;
+ emu_file file(OPEN_FLAG_READ);
+ if (file.open(name) == FILERR_NONE)
+ {
+ unsigned char buffer[9];
+ unsigned char magic[9] = { 'S', 'T', 'A', 'R', 'T', 'F', 'O', 'N', 'T' };
+ file.read(buffer, 9);
+ file.close();
+ if (!memcmp(buffer, magic, 9))
+ return true;
+ }
+
+ return false;
}
#ifndef SDLMAME_HAIKU
TTF_Font *osd_font_sdl::search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles)
{
- TTF_Font *font = (TTF_Font *)NULL;
- FcConfig *config;
- FcPattern *pat;
- FcObjectSet *os;
- FcFontSet *fontset;
- FcValue val;
-
- config = FcConfigGetCurrent();
- pat = FcPatternCreate();
- os = FcObjectSetCreate();
- FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr());
-
- // try and get a font with the requested styles baked-in
- if (bold)
- {
- if (italic)
- {
- FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold Italic");
- }
- else
- {
- FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold");
- }
- }
- else if (italic)
- {
- FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Italic");
- }
- else
- {
- FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular");
- }
-
- FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType");
-
- FcObjectSetAdd(os, FC_FILE);
- fontset = FcFontList(config, pat, os);
-
- for (int i = 0; i < fontset->nfont; i++)
- {
- if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch)
- {
- continue;
- }
-
- if (val.type != FcTypeString)
- {
- continue;
- }
-
- osd_printf_verbose("Matching font: %s\n", val.u.s);
- {
- astring match_name((const char*)val.u.s);
- font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
- }
-
- if (font)
- {
- bakedstyles = true;
- break;
- }
- }
-
- // didn't get a font above? try again with no baked-in styles
- if (!font)
- {
- FcPatternDestroy(pat);
- FcFontSetDestroy(fontset);
-
- pat = FcPatternCreate();
- FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr());
- FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular");
- FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType");
- fontset = FcFontList(config, pat, os);
-
- for (int i = 0; i < fontset->nfont; i++)
- {
- if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch)
- {
- continue;
- }
-
- if (val.type != FcTypeString)
- {
- continue;
- }
-
- osd_printf_verbose("Matching unstyled font: %s\n", val.u.s);
- {
- astring match_name((const char*)val.u.s);
- font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
- }
-
- if (font)
- {
- break;
- }
- }
- }
-
- FcPatternDestroy(pat);
- FcObjectSetDestroy(os);
- FcFontSetDestroy(fontset);
- return font;
+ TTF_Font *font = (TTF_Font *)NULL;
+ FcConfig *config;
+ FcPattern *pat;
+ FcObjectSet *os;
+ FcFontSet *fontset;
+ FcValue val;
+
+ config = FcConfigGetCurrent();
+ pat = FcPatternCreate();
+ os = FcObjectSetCreate();
+ FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr());
+
+ // try and get a font with the requested styles baked-in
+ if (bold)
+ {
+ if (italic)
+ {
+ FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold Italic");
+ }
+ else
+ {
+ FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold");
+ }
+ }
+ else if (italic)
+ {
+ FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Italic");
+ }
+ else
+ {
+ FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular");
+ }
+
+ FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType");
+
+ FcObjectSetAdd(os, FC_FILE);
+ fontset = FcFontList(config, pat, os);
+
+ for (int i = 0; i < fontset->nfont; i++)
+ {
+ if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch)
+ {
+ continue;
+ }
+
+ if (val.type != FcTypeString)
+ {
+ continue;
+ }
+
+ osd_printf_verbose("Matching font: %s\n", val.u.s);
+ {
+ astring match_name((const char*)val.u.s);
+ font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
+ }
+
+ if (font)
+ {
+ bakedstyles = true;
+ break;
+ }
+ }
+
+ // didn't get a font above? try again with no baked-in styles
+ if (!font)
+ {
+ FcPatternDestroy(pat);
+ FcFontSetDestroy(fontset);
+
+ pat = FcPatternCreate();
+ FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr());
+ FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular");
+ FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType");
+ fontset = FcFontList(config, pat, os);
+
+ for (int i = 0; i < fontset->nfont; i++)
+ {
+ if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch)
+ {
+ continue;
+ }
+
+ if (val.type != FcTypeString)
+ {
+ continue;
+ }
+
+ osd_printf_verbose("Matching unstyled font: %s\n", val.u.s);
+ {
+ astring match_name((const char*)val.u.s);
+ font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
+ }
+
+ if (font)
+ {
+ break;
+ }
+ }
+ }
+
+ FcPatternDestroy(pat);
+ FcObjectSetDestroy(os);
+ FcFontSetDestroy(fontset);
+ return font;
}
#endif
@@ -328,35 +328,33 @@ TTF_Font *osd_font_sdl::search_font_config(astring name, bool bold, bool italic,
class font_sdl : public osd_module, public font_module
{
public:
- font_sdl()
- : osd_module(OSD_FONT_PROVIDER, "sdl"), font_module()
- {
- }
-
- osd_font *font_alloc()
- {
- return global_alloc(osd_font_sdl);
- }
-
- int init()
- {
- if (TTF_Init() == -1)
- {
- osd_printf_error("SDL_ttf failed: %s\n", TTF_GetError());
- return -1;
- }
- return 0;
- }
-
- virtual void exit()
- {
- TTF_Quit();
- }
+ font_sdl()
+ : osd_module(OSD_FONT_PROVIDER, "sdl"), font_module()
+ {
+ }
+
+ osd_font *font_alloc()
+ {
+ return global_alloc(osd_font_sdl);
+ }
+
+ int init()
+ {
+ if (TTF_Init() == -1)
+ {
+ osd_printf_error("SDL_ttf failed: %s\n", TTF_GetError());
+ return -1;
+ }
+ return 0;
+ }
+
+ virtual void exit()
+ {
+ TTF_Quit();
+ }
};
#else /* SDLMAME_UNIX */
- MODULE_NOT_SUPPORTED(font_sdl, OSD_FONT_PROVIDER, "sdl")
+ MODULE_NOT_SUPPORTED(font_sdl, OSD_FONT_PROVIDER, "sdl")
#endif
MODULE_DEFINITION(FONT_SDL, font_sdl)
-
-
diff --git a/src/osd/modules/font/font_windows.c b/src/osd/modules/font/font_windows.c
index 054ef077148..458534f3a74 100644
--- a/src/osd/modules/font/font_windows.c
+++ b/src/osd/modules/font/font_windows.c
@@ -34,72 +34,72 @@
class osd_font_windows : public osd_font
{
public:
- virtual ~osd_font_windows() {};
+ virtual ~osd_font_windows() {};
- virtual bool open(const char *font_path, const char *name, int &height);
- virtual void close();
- virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
+ virtual bool open(const char *font_path, const char *name, int &height);
+ virtual void close();
+ virtual bool get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs);
private:
- HGDIOBJ m_font;
+ HGDIOBJ m_font;
};
bool osd_font_windows::open(const char *font_path, const char *_name, int &height)
{
- // accept qualifiers from the name
- astring name(_name);
- if (name == "default") name = "Tahoma";
- bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0);
- bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0);
-
- // build a basic LOGFONT description of what we want
- LOGFONT logfont;
- logfont.lfHeight = DEFAULT_FONT_HEIGHT;
- logfont.lfWidth = 0;
- logfont.lfEscapement = 0;
- logfont.lfOrientation = 0;
- logfont.lfWeight = bold ? FW_BOLD : FW_MEDIUM;
- logfont.lfItalic = italic;
- logfont.lfUnderline = FALSE;
- logfont.lfStrikeOut = FALSE;
- logfont.lfCharSet = ANSI_CHARSET;
- logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
- logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
- logfont.lfQuality = NONANTIALIASED_QUALITY;
- logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
-
- // copy in the face name
- TCHAR *face = tstring_from_utf8(name);
- _tcsncpy(logfont.lfFaceName, face, sizeof(logfont.lfFaceName) / sizeof(TCHAR));
- logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0;
- osd_free(face);
-
- // create the font
- height = logfont.lfHeight;
- m_font = CreateFontIndirect(&logfont);
- if (m_font == NULL)
- return false;
-
- // select it into a temp DC and get the real font name
- HDC dummyDC = CreateCompatibleDC(NULL);
- HGDIOBJ oldfont = SelectObject(dummyDC, m_font);
- TCHAR realname[100];
- GetTextFace(dummyDC, ARRAY_LENGTH(realname), realname);
- SelectObject(dummyDC, oldfont);
- DeleteDC(dummyDC);
-
- // if it doesn't match our request, fail
- char *utf = utf8_from_tstring(realname);
- int result = core_stricmp(utf, name);
- osd_free(utf);
-
- // if we didn't match, nuke our font and fall back
- if (result != 0)
- {
- DeleteObject(m_font);
- m_font = NULL;
- return false;
- }
- return true;
+ // accept qualifiers from the name
+ astring name(_name);
+ if (name == "default") name = "Tahoma";
+ bool bold = (name.replace(0, "[B]", "") + name.replace(0, "[b]", "") > 0);
+ bool italic = (name.replace(0, "[I]", "") + name.replace(0, "[i]", "") > 0);
+
+ // build a basic LOGFONT description of what we want
+ LOGFONT logfont;
+ logfont.lfHeight = DEFAULT_FONT_HEIGHT;
+ logfont.lfWidth = 0;
+ logfont.lfEscapement = 0;
+ logfont.lfOrientation = 0;
+ logfont.lfWeight = bold ? FW_BOLD : FW_MEDIUM;
+ logfont.lfItalic = italic;
+ logfont.lfUnderline = FALSE;
+ logfont.lfStrikeOut = FALSE;
+ logfont.lfCharSet = ANSI_CHARSET;
+ logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
+ logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ logfont.lfQuality = NONANTIALIASED_QUALITY;
+ logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+
+ // copy in the face name
+ TCHAR *face = tstring_from_utf8(name);
+ _tcsncpy(logfont.lfFaceName, face, sizeof(logfont.lfFaceName) / sizeof(TCHAR));
+ logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0;
+ osd_free(face);
+
+ // create the font
+ height = logfont.lfHeight;
+ m_font = CreateFontIndirect(&logfont);
+ if (m_font == NULL)
+ return false;
+
+ // select it into a temp DC and get the real font name
+ HDC dummyDC = CreateCompatibleDC(NULL);
+ HGDIOBJ oldfont = SelectObject(dummyDC, m_font);
+ TCHAR realname[100];
+ GetTextFace(dummyDC, ARRAY_LENGTH(realname), realname);
+ SelectObject(dummyDC, oldfont);
+ DeleteDC(dummyDC);
+
+ // if it doesn't match our request, fail
+ char *utf = utf8_from_tstring(realname);
+ int result = core_stricmp(utf, name);
+ osd_free(utf);
+
+ // if we didn't match, nuke our font and fall back
+ if (result != 0)
+ {
+ DeleteObject(m_font);
+ m_font = NULL;
+ return false;
+ }
+ return true;
}
//-------------------------------------------------
@@ -109,9 +109,9 @@ bool osd_font_windows::open(const char *font_path, const char *_name, int &heigh
void osd_font_windows::close()
{
- // delete the font ojbect
- if (m_font != NULL)
- DeleteObject(m_font);
+ // delete the font ojbect
+ if (m_font != NULL)
+ DeleteObject(m_font);
}
@@ -125,155 +125,155 @@ void osd_font_windows::close()
bool osd_font_windows::get_bitmap(unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs)
{
- // create a dummy DC to work with
- HDC dummyDC = CreateCompatibleDC(NULL);
- HGDIOBJ oldfont = SelectObject(dummyDC, m_font);
-
- // get the text metrics
- TEXTMETRIC metrics = { 0 };
- GetTextMetrics(dummyDC, &metrics);
-
- // get the width of this character
- ABC abc;
- if (!GetCharABCWidths(dummyDC, chnum, chnum, &abc))
- {
- abc.abcA = 0;
- abc.abcC = 0;
- GetCharWidth32(dummyDC, chnum, chnum, reinterpret_cast<LPINT>(&abc.abcB));
- }
- width = abc.abcA + abc.abcB + abc.abcC;
-
- // determine desired bitmap size
- int bmwidth = (50 + abc.abcA + abc.abcB + abc.abcC + 50 + 31) & ~31;
- int bmheight = 50 + metrics.tmHeight + 50;
-
- // describe the bitmap we want
- BYTE bitmapinfodata[sizeof(BITMAPINFOHEADER)+2 * sizeof(RGBQUAD)] = { 0 };
- BITMAPINFO &info = *reinterpret_cast<BITMAPINFO *>(bitmapinfodata);
- info.bmiHeader.biSize = sizeof(info.bmiHeader);
- info.bmiHeader.biWidth = bmwidth;
- info.bmiHeader.biHeight = -bmheight;
- info.bmiHeader.biPlanes = 1;
- info.bmiHeader.biBitCount = 1;
- info.bmiHeader.biCompression = BI_RGB;
- info.bmiHeader.biSizeImage = 0;
- info.bmiHeader.biXPelsPerMeter = GetDeviceCaps(dummyDC, HORZRES) / GetDeviceCaps(dummyDC, HORZSIZE);
- info.bmiHeader.biYPelsPerMeter = GetDeviceCaps(dummyDC, VERTRES) / GetDeviceCaps(dummyDC, VERTSIZE);
- info.bmiHeader.biClrUsed = 0;
- info.bmiHeader.biClrImportant = 0;
- RGBQUAD col1 = info.bmiColors[0];
- RGBQUAD col2 = info.bmiColors[1];
- col1.rgbBlue = col1.rgbGreen = col1.rgbRed = 0x00;
- col2.rgbBlue = col2.rgbGreen = col2.rgbRed = 0xff;
-
- // create a DIB to render to
- BYTE *bits;
- HBITMAP dib = CreateDIBSection(dummyDC, &info, DIB_RGB_COLORS, reinterpret_cast<VOID **>(&bits), NULL, 0);
- HGDIOBJ oldbitmap = SelectObject(dummyDC, dib);
-
- // clear the bitmap
- int rowbytes = bmwidth / 8;
- memset(bits, 0, rowbytes * bmheight);
-
- // now draw the character
- WCHAR tempchar = chnum;
- SetTextColor(dummyDC, RGB(0xff, 0xff, 0xff));
- SetBkColor(dummyDC, RGB(0x00, 0x00, 0x00));
- ExtTextOutW(dummyDC, 50 + abc.abcA, 50, ETO_OPAQUE, NULL, &tempchar, 1, NULL);
-
- // characters are expected to be full-height
- rectangle actbounds;
- actbounds.min_y = 50;
- actbounds.max_y = 50 + metrics.tmHeight - 1;
-
- // determine the actual left of the character
- for (actbounds.min_x = 0; actbounds.min_x < rowbytes; actbounds.min_x++)
- {
- BYTE *offs = bits + actbounds.min_x;
- UINT8 summary = 0;
- for (int y = 0; y < bmheight; y++)
- summary |= offs[y * rowbytes];
- if (summary != 0)
- {
- actbounds.min_x *= 8;
- if (!(summary & 0x80)) actbounds.min_x++;
- if (!(summary & 0xc0)) actbounds.min_x++;
- if (!(summary & 0xe0)) actbounds.min_x++;
- if (!(summary & 0xf0)) actbounds.min_x++;
- if (!(summary & 0xf8)) actbounds.min_x++;
- if (!(summary & 0xfc)) actbounds.min_x++;
- if (!(summary & 0xfe)) actbounds.min_x++;
- break;
- }
- }
-
- // determine the actual right of the character
- for (actbounds.max_x = rowbytes - 1; actbounds.max_x >= 0; actbounds.max_x--)
- {
- BYTE *offs = bits + actbounds.max_x;
- UINT8 summary = 0;
- for (int y = 0; y < bmheight; y++)
- summary |= offs[y * rowbytes];
- if (summary != 0)
- {
- actbounds.max_x *= 8;
- if (summary & 0x7f) actbounds.max_x++;
- if (summary & 0x3f) actbounds.max_x++;
- if (summary & 0x1f) actbounds.max_x++;
- if (summary & 0x0f) actbounds.max_x++;
- if (summary & 0x07) actbounds.max_x++;
- if (summary & 0x03) actbounds.max_x++;
- if (summary & 0x01) actbounds.max_x++;
- break;
- }
- }
-
- // allocate a new bitmap
- if (actbounds.max_x >= actbounds.min_x && actbounds.max_y >= actbounds.min_y)
- {
- bitmap.allocate(actbounds.max_x + 1 - actbounds.min_x, actbounds.max_y + 1 - actbounds.min_y);
-
- // copy the bits into it
- for (int y = 0; y < bitmap.height(); y++)
- {
- UINT32 *dstrow = &bitmap.pix32(y);
- UINT8 *srcrow = &bits[(y + actbounds.min_y) * rowbytes];
- for (int x = 0; x < bitmap.width(); x++)
- {
- int effx = x + actbounds.min_x;
- dstrow[x] = ((srcrow[effx / 8] << (effx % 8)) & 0x80) ? rgb_t(0xff, 0xff, 0xff, 0xff) : rgb_t(0x00, 0xff, 0xff, 0xff);
- }
- }
-
- // set the final offset values
- xoffs = actbounds.min_x - (50 + abc.abcA);
- yoffs = actbounds.max_y - (50 + metrics.tmAscent);
- }
-
- // de-select the font and release the DC
- SelectObject(dummyDC, oldbitmap);
- DeleteObject(dib);
- SelectObject(dummyDC, oldfont);
- DeleteDC(dummyDC);
- return bitmap.valid();
+ // create a dummy DC to work with
+ HDC dummyDC = CreateCompatibleDC(NULL);
+ HGDIOBJ oldfont = SelectObject(dummyDC, m_font);
+
+ // get the text metrics
+ TEXTMETRIC metrics = { 0 };
+ GetTextMetrics(dummyDC, &metrics);
+
+ // get the width of this character
+ ABC abc;
+ if (!GetCharABCWidths(dummyDC, chnum, chnum, &abc))
+ {
+ abc.abcA = 0;
+ abc.abcC = 0;
+ GetCharWidth32(dummyDC, chnum, chnum, reinterpret_cast<LPINT>(&abc.abcB));
+ }
+ width = abc.abcA + abc.abcB + abc.abcC;
+
+ // determine desired bitmap size
+ int bmwidth = (50 + abc.abcA + abc.abcB + abc.abcC + 50 + 31) & ~31;
+ int bmheight = 50 + metrics.tmHeight + 50;
+
+ // describe the bitmap we want
+ BYTE bitmapinfodata[sizeof(BITMAPINFOHEADER)+2 * sizeof(RGBQUAD)] = { 0 };
+ BITMAPINFO &info = *reinterpret_cast<BITMAPINFO *>(bitmapinfodata);
+ info.bmiHeader.biSize = sizeof(info.bmiHeader);
+ info.bmiHeader.biWidth = bmwidth;
+ info.bmiHeader.biHeight = -bmheight;
+ info.bmiHeader.biPlanes = 1;
+ info.bmiHeader.biBitCount = 1;
+ info.bmiHeader.biCompression = BI_RGB;
+ info.bmiHeader.biSizeImage = 0;
+ info.bmiHeader.biXPelsPerMeter = GetDeviceCaps(dummyDC, HORZRES) / GetDeviceCaps(dummyDC, HORZSIZE);
+ info.bmiHeader.biYPelsPerMeter = GetDeviceCaps(dummyDC, VERTRES) / GetDeviceCaps(dummyDC, VERTSIZE);
+ info.bmiHeader.biClrUsed = 0;
+ info.bmiHeader.biClrImportant = 0;
+ RGBQUAD col1 = info.bmiColors[0];
+ RGBQUAD col2 = info.bmiColors[1];
+ col1.rgbBlue = col1.rgbGreen = col1.rgbRed = 0x00;
+ col2.rgbBlue = col2.rgbGreen = col2.rgbRed = 0xff;
+
+ // create a DIB to render to
+ BYTE *bits;
+ HBITMAP dib = CreateDIBSection(dummyDC, &info, DIB_RGB_COLORS, reinterpret_cast<VOID **>(&bits), NULL, 0);
+ HGDIOBJ oldbitmap = SelectObject(dummyDC, dib);
+
+ // clear the bitmap
+ int rowbytes = bmwidth / 8;
+ memset(bits, 0, rowbytes * bmheight);
+
+ // now draw the character
+ WCHAR tempchar = chnum;
+ SetTextColor(dummyDC, RGB(0xff, 0xff, 0xff));
+ SetBkColor(dummyDC, RGB(0x00, 0x00, 0x00));
+ ExtTextOutW(dummyDC, 50 + abc.abcA, 50, ETO_OPAQUE, NULL, &tempchar, 1, NULL);
+
+ // characters are expected to be full-height
+ rectangle actbounds;
+ actbounds.min_y = 50;
+ actbounds.max_y = 50 + metrics.tmHeight - 1;
+
+ // determine the actual left of the character
+ for (actbounds.min_x = 0; actbounds.min_x < rowbytes; actbounds.min_x++)
+ {
+ BYTE *offs = bits + actbounds.min_x;
+ UINT8 summary = 0;
+ for (int y = 0; y < bmheight; y++)
+ summary |= offs[y * rowbytes];
+ if (summary != 0)
+ {
+ actbounds.min_x *= 8;
+ if (!(summary & 0x80)) actbounds.min_x++;
+ if (!(summary & 0xc0)) actbounds.min_x++;
+ if (!(summary & 0xe0)) actbounds.min_x++;
+ if (!(summary & 0xf0)) actbounds.min_x++;
+ if (!(summary & 0xf8)) actbounds.min_x++;
+ if (!(summary & 0xfc)) actbounds.min_x++;
+ if (!(summary & 0xfe)) actbounds.min_x++;
+ break;
+ }
+ }
+
+ // determine the actual right of the character
+ for (actbounds.max_x = rowbytes - 1; actbounds.max_x >= 0; actbounds.max_x--)
+ {
+ BYTE *offs = bits + actbounds.max_x;
+ UINT8 summary = 0;
+ for (int y = 0; y < bmheight; y++)
+ summary |= offs[y * rowbytes];
+ if (summary != 0)
+ {
+ actbounds.max_x *= 8;
+ if (summary & 0x7f) actbounds.max_x++;
+ if (summary & 0x3f) actbounds.max_x++;
+ if (summary & 0x1f) actbounds.max_x++;
+ if (summary & 0x0f) actbounds.max_x++;
+ if (summary & 0x07) actbounds.max_x++;
+ if (summary & 0x03) actbounds.max_x++;
+ if (summary & 0x01) actbounds.max_x++;
+ break;
+ }
+ }
+
+ // allocate a new bitmap
+ if (actbounds.max_x >= actbounds.min_x && actbounds.max_y >= actbounds.min_y)
+ {
+ bitmap.allocate(actbounds.max_x + 1 - actbounds.min_x, actbounds.max_y + 1 - actbounds.min_y);
+
+ // copy the bits into it
+ for (int y = 0; y < bitmap.height(); y++)
+ {
+ UINT32 *dstrow = &bitmap.pix32(y);
+ UINT8 *srcrow = &bits[(y + actbounds.min_y) * rowbytes];
+ for (int x = 0; x < bitmap.width(); x++)
+ {
+ int effx = x + actbounds.min_x;
+ dstrow[x] = ((srcrow[effx / 8] << (effx % 8)) & 0x80) ? rgb_t(0xff, 0xff, 0xff, 0xff) : rgb_t(0x00, 0xff, 0xff, 0xff);
+ }
+ }
+
+ // set the final offset values
+ xoffs = actbounds.min_x - (50 + abc.abcA);
+ yoffs = actbounds.max_y - (50 + metrics.tmAscent);
+ }
+
+ // de-select the font and release the DC
+ SelectObject(dummyDC, oldbitmap);
+ DeleteObject(dib);
+ SelectObject(dummyDC, oldfont);
+ DeleteDC(dummyDC);
+ return bitmap.valid();
}
class font_win : public osd_module, public font_module
{
public:
- font_win()
- : osd_module(OSD_FONT_PROVIDER, "win"), font_module()
- {
- }
+ font_win()
+ : osd_module(OSD_FONT_PROVIDER, "win"), font_module()
+ {
+ }
- osd_font *font_alloc()
- {
- return global_alloc(osd_font_windows);
- }
+ osd_font *font_alloc()
+ {
+ return global_alloc(osd_font_windows);
+ }
};
#else /* SDLMAME_UNIX */
- MODULE_NOT_SUPPORTED(font_win, OSD_FONT_PROVIDER, "win")
+ MODULE_NOT_SUPPORTED(font_win, OSD_FONT_PROVIDER, "win")
#endif
MODULE_DEFINITION(FONT_WINDOWS, font_win)