src/osd/sdl/sdlmain.c
| r9585 | r9586 | |
| 18 | 18 | #include <SDL_ttf.h> |
| 19 | 19 | #include <fontconfig/fontconfig.h> |
| 20 | 20 | #endif |
| 21 | #ifdef SDLMAME_MACOSX |
| 22 | #include <Carbon/Carbon.h> |
| 21 | 23 | #endif |
| 24 | #endif |
| 22 | 25 | |
| 23 | 26 | // standard includes |
| 24 | 27 | #ifdef MESS |
| r9585 | r9586 | |
| 623 | 626 | |
| 624 | 627 | #ifdef SDLMAME_UNIX |
| 625 | 628 | #ifdef SDLMAME_MACOSX |
| 629 | |
| 630 | #define EXTRA_HEIGHT 1.0 |
| 631 | #define EXTRA_WIDTH 1.15 |
| 632 | #define POINT_SIZE 144.0 |
| 633 | |
| 626 | 634 | //------------------------------------------------- |
| 627 | 635 | // font_open - attempt to "open" a handle to the |
| 628 | 636 | // font with the given name |
| r9585 | r9586 | |
| 630 | 638 | |
| 631 | 639 | osd_font sdl_osd_interface::font_open(const char *_name, int &height) |
| 632 | 640 | { |
| 633 | | return (osd_font)NULL; |
| 641 | CFStringRef font_name = NULL; |
| 642 | CTFontRef ct_font; |
| 643 | CTFontDescriptorRef font_descriptor; |
| 644 | CGAffineTransform affine_transform = CGAffineTransformIdentity; |
| 645 | |
| 646 | astring name(_name); |
| 647 | |
| 648 | if (name == "default") |
| 649 | { |
| 650 | name = "LucidaGrande"; |
| 651 | } |
| 652 | |
| 653 | font_name = CFStringCreateWithCString( NULL, _name, kCFStringEncodingUTF8 ); |
| 654 | |
| 655 | if( font_name != NULL ) |
| 656 | { |
| 657 | font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, POINT_SIZE ); |
| 658 | |
| 659 | if( font_descriptor != NULL ) |
| 660 | { |
| 661 | ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform ); |
| 662 | |
| 663 | CFRelease( font_descriptor ); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | CFRelease( font_name ); |
| 668 | |
| 669 | if (!ct_font) |
| 670 | { |
| 671 | printf("WARNING: Couldn't find/open font %s, using MAME default\n", name.cstr()); |
| 672 | return NULL; |
| 673 | } |
| 674 | |
| 675 | CFStringRef real_name = CTFontCopyPostScriptName( ct_font ); |
| 676 | char real_name_c_string[255]; |
| 677 | CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 ); |
| 678 | mame_printf_verbose("Matching font: %s\n", real_name_c_string); |
| 679 | CFRelease( real_name ); |
| 680 | |
| 681 | CGFloat line_height = 0.0; |
| 682 | line_height += CTFontGetAscent(ct_font); |
| 683 | line_height += CTFontGetDescent(ct_font); |
| 684 | line_height += CTFontGetLeading(ct_font); |
| 685 | height = ceilf(line_height * EXTRA_HEIGHT); |
| 686 | |
| 687 | return (osd_font)ct_font; |
| 634 | 688 | } |
| 635 | 689 | |
| 636 | 690 | //------------------------------------------------- |
| r9585 | r9586 | |
| 640 | 694 | |
| 641 | 695 | void sdl_osd_interface::font_close(osd_font font) |
| 642 | 696 | { |
| 697 | CTFontRef ct_font = (CTFontRef)font; |
| 698 | |
| 699 | if( ct_font != NULL ) |
| 700 | { |
| 701 | CFRelease( ct_font ); |
| 702 | } |
| 643 | 703 | } |
| 644 | 704 | |
| 645 | 705 | //------------------------------------------------- |
| r9585 | r9586 | |
| 652 | 712 | |
| 653 | 713 | bitmap_t *sdl_osd_interface::font_get_bitmap(osd_font font, unicode_char chnum, INT32 &width, INT32 &xoffs, INT32 &yoffs) |
| 654 | 714 | { |
| 655 | | return (bitmap_t *)NULL; |
| 715 | UniChar uni_char; |
| 716 | CGGlyph glyph; |
| 717 | bitmap_t *bitmap = (bitmap_t *)NULL; |
| 718 | CTFontRef ct_font = (CTFontRef)font; |
| 719 | const CFIndex count = 1; |
| 720 | CGRect bounding_rect, success_rect; |
| 721 | CGContextRef context_ref; |
| 722 | |
| 723 | if( chnum == ' ' ) |
| 724 | { |
| 725 | uni_char = 'n'; |
| 726 | CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); |
| 727 | success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); |
| 728 | uni_char = chnum; |
| 729 | CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | uni_char = chnum; |
| 734 | CTFontGetGlyphsForCharacters( ct_font, &uni_char, &glyph, count ); |
| 735 | success_rect = CTFontGetBoundingRectsForGlyphs( ct_font, kCTFontDefaultOrientation, &glyph, &bounding_rect, count ); |
| 736 | } |
| 737 | |
| 738 | if( CGRectEqualToRect( success_rect, CGRectNull ) == false ) |
| 739 | { |
| 740 | size_t bitmap_width; |
| 741 | size_t bitmap_height; |
| 742 | |
| 743 | bitmap_width = ceilf(bounding_rect.size.width * EXTRA_WIDTH); |
| 744 | bitmap_width = bitmap_width == 0 ? 1 : bitmap_width; |
| 745 | |
| 746 | bitmap_height = ceilf( (CTFontGetAscent(ct_font) + CTFontGetDescent(ct_font) + CTFontGetLeading(ct_font)) * EXTRA_HEIGHT); |
| 747 | |
| 748 | xoffs = yoffs = 0; |
| 749 | width = bitmap_width; |
| 750 | |
| 751 | size_t bits_per_component; |
| 752 | CGColorSpaceRef color_space; |
| 753 | CGBitmapInfo bitmap_info = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; |
| 754 | |
| 755 | color_space = CGColorSpaceCreateDeviceRGB(); |
| 756 | bits_per_component = 8; |
| 757 | |
| 758 | bitmap = auto_alloc(&machine(), bitmap_t(bitmap_width, bitmap_height, BITMAP_FORMAT_ARGB32)); |
| 759 | |
| 760 | context_ref = CGBitmapContextCreate( bitmap->base, bitmap_width, bitmap_height, bits_per_component, bitmap->rowpixels*4, color_space, bitmap_info ); |
| 761 | |
| 762 | if( context_ref != NULL ) |
| 763 | { |
| 764 | CGFontRef font_ref; |
| 765 | font_ref = CTFontCopyGraphicsFont( ct_font, NULL ); |
| 766 | CGContextSetTextPosition(context_ref, -bounding_rect.origin.x*EXTRA_WIDTH, CTFontGetDescent(ct_font)+CTFontGetLeading(ct_font) ); |
| 767 | CGContextSetRGBFillColor(context_ref, 1.0, 1.0, 1.0, 1.0); |
| 768 | CGContextSetFont( context_ref, font_ref ); |
| 769 | CGContextSetFontSize( context_ref, POINT_SIZE ); |
| 770 | CGContextShowGlyphs( context_ref, &glyph, count ); |
| 771 | CGFontRelease( font_ref ); |
| 772 | CGContextRelease( context_ref ); |
| 773 | } |
| 774 | |
| 775 | CGColorSpaceRelease( color_space ); |
| 776 | } |
| 777 | |
| 778 | return bitmap; |
| 656 | 779 | } |
| 657 | | #else |
| 780 | #else // UNIX but not OSX |
| 658 | 781 | //------------------------------------------------- |
| 659 | 782 | // font_open - attempt to "open" a handle to the |
| 660 | 783 | // font with the given name |