示例#1
0
ATSUFontID coretext_font_to_atsufontid(void *p_font)
{
    bool t_success;
    t_success = true;
    
    CTFontRef t_ctfont;
    t_ctfont = NULL;
    if (t_success)
    {
        t_ctfont = (CTFontRef)p_font;
        t_success = t_ctfont != NULL;
    }
    
    char t_name[256];
    if (t_success)
    {
        CFStringRef t_cfname;
        t_cfname = CTFontCopyPostScriptName(t_ctfont);
        t_success = t_cfname != NULL && CFStringGetCString(t_cfname, t_name, 256, kCFStringEncodingMacRoman);
        if (t_cfname != NULL)
            CFRelease(t_cfname);
    }
    
    ATSUFontID t_font_id;
    t_font_id = 0;
    if (t_success)
    {
        uint32_t t_name_length;
        t_name_length = MCCStringLength(t_name);
        t_success = ATSUFindFontFromName(t_name, t_name_length, kFontPostscriptName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &t_font_id) == noErr;
    }
    
    return t_font_id;
}
示例#2
0
文件: sdlmain.c 项目: j4y4r/j4ymame
void sdl_osd_interface::init(running_machine &machine)
{
	// call our parent
	osd_interface::init(machine);

	sdl_options &options = downcast<sdl_options &>(machine.options());
	const char *stemp;
	// Switchres
	if (machine.options().modeline())
		switchres_modeline_setup(machine);

	// determine if we are benchmarking, and adjust options appropriately
	int bench = options.bench();
	astring error_string;
	if (bench > 0)
	{
		options.set_value(OPTION_THROTTLE, false, OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(OPTION_SOUND, false, OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(SDLOPTION_VIDEO, "none", OPTION_PRIORITY_MAXIMUM, error_string);
		options.set_value(OPTION_SECONDS_TO_RUN, bench, OPTION_PRIORITY_MAXIMUM, error_string);
		assert(!error_string);
	}

	// Some driver options - must be before audio init!
	stemp = options.audio_driver();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp);
		osd_setenv(SDLENV_AUDIODRIVER, stemp, 1);
	}

	stemp = options.video_driver();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp);
		osd_setenv(SDLENV_VIDEODRIVER, stemp, 1);
	}

#if (SDLMAME_SDL2)
		stemp = options.render_driver();
		if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
		{
			mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp);
			//osd_setenv(SDLENV_RENDERDRIVER, stemp, 1);
			SDL_SetHint(SDL_HINT_RENDER_DRIVER, stemp);
		}
#endif

	/* Set the SDL environment variable for drivers wanting to load the
     * lib at startup.
     */
#if USE_OPENGL
	/* FIXME: move lib loading code from drawogl.c here */

	stemp = options.gl_lib();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0)
	{
		osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1);
		mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp);
	}
#endif

	/* get number of processors */
	stemp = options.numprocessors();

    osd_num_processors = 0;

	if (strcmp(stemp, "auto") != 0)
	{
		osd_num_processors = atoi(stemp);
		if (osd_num_processors < 1)
		{
			mame_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n");
			osd_num_processors = 0;
		}
	}

	/* Initialize SDL */

	if (!SDLMAME_INIT_IN_WORKER_THREAD)
	{
#if (SDLMAME_SDL2)
		if (SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
#else
		if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) {
#endif
			mame_printf_error("Could not initialize SDL %s\n", SDL_GetError());
			exit(-1);
		}
		osd_sdl_info();
	}
	// must be before sdlvideo_init!
	machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_exit), &machine));

	defines_verbose();

	if (!SDLMAME_HAS_DEBUGGER)
		if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)
		{
			mame_printf_error("sdlmame: -debug not supported on X11-less builds\n\n");
			osd_exit(machine);
			exit(-1);
		}

	if (sdlvideo_init(machine))
	{
		osd_exit(machine);
		mame_printf_error("sdlvideo_init: Initialization failed!\n\n\n");
		fflush(stderr);
		fflush(stdout);
		exit(-1);
	}

	sdlinput_init(machine);
	sdlaudio_init(machine);
	sdloutput_init(machine);

#ifdef SDLMAME_NETWORK
	sdlnetdev_init(machine);
#endif

	if (options.oslog())
		machine.add_logerror_callback(output_oslog);

	/* now setup watchdog */

	int watchdog_timeout = options.watchdog();
	int str = options.seconds_to_run();

	/* only enable watchdog if seconds_to_run is enabled *and* relatively short (time taken from ui.c) */
	if ((watchdog_timeout != 0) && (str > 0) && (str < 60*5 ))
	{
		m_watchdog = auto_alloc(machine, watchdog);
		m_watchdog->setTimeout(watchdog_timeout);
	}

#if (SDLMAME_SDL2)
	SDL_EventState(SDL_TEXTINPUT, SDL_TRUE);
#else
	SDL_EnableUNICODE(SDL_TRUE);
#endif
}

#ifdef SDLMAME_UNIX
#define POINT_SIZE 144.0

#ifdef SDLMAME_MACOSX

#define EXTRA_HEIGHT 1.0
#define EXTRA_WIDTH 1.15

//-------------------------------------------------
//  font_open - attempt to "open" a handle to the
//  font with the given name
//-------------------------------------------------

osd_font sdl_osd_interface::font_open(const char *_name, int &height)
{
	CFStringRef font_name = NULL;
	CTFontRef ct_font = NULL;
	CTFontDescriptorRef font_descriptor;
	CGAffineTransform affine_transform = CGAffineTransformIdentity;

	astring name(_name);

	if (name == "default")
	{
		name = "LucidaGrande";
	}

	/* handle bdf fonts in the core */
	if (name.len() > 4)
		if (name.makeupper().substr(name.len()-4,4) == ".BDF" )
			return NULL;

	font_name = CFStringCreateWithCString( NULL, _name, kCFStringEncodingUTF8 );

	if( font_name != NULL )
	{
      font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, POINT_SIZE );

      if( font_descriptor != NULL )
      {
         ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform );

         CFRelease( font_descriptor );
      }
   }

   CFRelease( font_name );

   if (!ct_font)
	{
		printf("WARNING: Couldn't find/open font %s, using MAME default\n", name.cstr());
		return NULL;
	}

   CFStringRef real_name = CTFontCopyPostScriptName( ct_font );
   char real_name_c_string[255];
   CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 );
   mame_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);

   return (osd_font)ct_font;
}
示例#3
0
CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont, FX_BOOL bVert, FX_BOOL bTranslateName)
{
    CTFontRef font = (CTFontRef)pFont;
    CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(font);
    if (descriptor == NULL) {
        return NULL;
    }
    CFX_ByteString basefont;
    FX_BOOL bCJK = FALSE;
    int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, bbox[4];
    FXSYS_memset32(bbox, 0, sizeof(int) * 4);
    CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontLanguagesAttribute);
    if (languages == NULL) {
        CFRelease(descriptor);
        return NULL;
    }
    CFX_DWordArray charSets;
    charSets.Add(FXFONT_CHINESEBIG5_CHARSET);
    charSets.Add(FXFONT_GB2312_CHARSET);
    charSets.Add(FXFONT_HANGEUL_CHARSET);
    charSets.Add(FXFONT_SHIFTJIS_CHARSET);
    if (IsHasCharSet(languages, charSets)) {
        bCJK = TRUE;
    }
    CFRelease(descriptor);
    CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font);
    if (traits == NULL) {
        CFRelease(languages);
        return NULL;
    }
    CFNumberRef sybolicTrait = (CFNumberRef)CFDictionaryGetValue(traits, kCTFontSymbolicTrait);
    CTFontSymbolicTraits trait = 0;
    CFNumberGetValue(sybolicTrait, kCFNumberSInt32Type, &trait);
    if (trait & kCTFontItalicTrait) {
        flags |= PDFFONT_ITALIC;
    }
    if (trait & kCTFontMonoSpaceTrait) {
        flags |= PDFFONT_FIXEDPITCH;
    }
    if (trait & kCTFontModernSerifsClass) {
        flags |= PDFFONT_SERIF;
    }
    if (trait & kCTFontScriptsClass) {
        flags |= PDFFONT_SCRIPT;
    }
    CFNumberRef weightTrait = (CFNumberRef)CFDictionaryGetValue(traits, kCTFontWeightTrait);
    Float32 weight = 0;
    CFNumberGetValue(weightTrait, kCFNumberFloat32Type, &weight);
    italicangle = CTFontGetSlantAngle(font);
    ascend      = CTFontGetAscent(font);
    descend     = CTFontGetDescent(font);
    capheight   = CTFontGetCapHeight(font);
    CGRect box  = CTFontGetBoundingBox(font);
    bbox[0]     = box.origin.x;
    bbox[1]     = box.origin.y;
    bbox[2]     = box.origin.x + box.size.width;
    bbox[3]     = box.origin.y + box.size.height;
    if (bTranslateName && bCJK) {
        CFStringRef postName = CTFontCopyPostScriptName(font);
        _CFString2CFXByteString(postName, basefont);
        CFRelease(postName);
    }
    if (basefont.IsEmpty()) {
        CFStringRef fullName = CTFontCopyFullName(font);
        _CFString2CFXByteString(fullName, basefont);
        CFRelease(fullName);
    }
    basefont.Replace(" ", "");
    CPDF_Dictionary* pFontDict = NULL;
    CPDF_Dictionary* pBaseDict = FX_NEW CPDF_Dictionary;
    pFontDict = pBaseDict;
    if (!bCJK) {
        charSets.RemoveAll();
        charSets.Add(FXFONT_ANSI_CHARSET);
        charSets.Add(FXFONT_DEFAULT_CHARSET);
        charSets.Add(FXFONT_SYMBOL_CHARSET);
        if (IsHasCharSet(languages, charSets)) {
            charSets.RemoveAll();
            charSets.Add(FXFONT_SYMBOL_CHARSET);
            if (IsHasCharSet(languages, charSets)) {
                flags |= PDFFONT_SYMBOLIC;
            } else {
                flags |= PDFFONT_NONSYMBOLIC;
            }
            pBaseDict->SetAtName(FX_BSTRC("Encoding"), "WinAnsiEncoding");
        } else {
            flags |= PDFFONT_NONSYMBOLIC;
            int i;
            for (i = 0; i < sizeof g_FX_CharsetUnicodes / sizeof(FX_CharsetUnicodes); i ++) {
                charSets.RemoveAll();
                charSets.Add(g_FX_CharsetUnicodes[i].m_Charset);
                if (IsHasCharSet(languages, charSets)) {
                    break;
                }
            }
            if (i < sizeof g_FX_CharsetUnicodes / sizeof(FX_CharsetUnicodes)) {
                CPDF_Dictionary* pEncoding = FX_NEW CPDF_Dictionary;
                pEncoding->SetAtName(FX_BSTRC("BaseEncoding"), "WinAnsiEncoding");
                CPDF_Array* pArray = FX_NEW CPDF_Array;
                pArray->AddInteger(128);
                const FX_WCHAR* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes;
                for (int j = 0; j < 128; j ++) {
                    CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]);
                    if (name.IsEmpty()) {
                        pArray->AddName(FX_BSTRC(".notdef"));
                    } else {
                        pArray->AddName(name);
                    }
                }
                pEncoding->SetAt(FX_BSTRC("Differences"), pArray);
                AddIndirectObject(pEncoding);
                pBaseDict->SetAtReference(FX_BSTRC("Encoding"), this, pEncoding);
            }
        }
        if (weight > 0.0 && trait & kCTFontItalicTrait) {
            basefont += ",BoldItalic";
        } else if (weight > 0.0) {
            basefont += ",Bold";
        } else if (trait & kCTFontItalicTrait) {
            basefont += ",Italic";
        }
        pBaseDict->SetAtName("Subtype", "TrueType");
        pBaseDict->SetAtName("BaseFont", basefont);
        pBaseDict->SetAtNumber("FirstChar", 32);
        pBaseDict->SetAtNumber("LastChar", 255);
        int char_widths[224];
        FX_GetCharWidth(font, 32, 255, char_widths);
        CPDF_Array* pWidths = FX_NEW CPDF_Array;
        for (int i = 0; i < 224; i ++) {
            pWidths->AddInteger(char_widths[i]);
        }
        pBaseDict->SetAt("Widths", pWidths);
    }  else {
        flags |= PDFFONT_NONSYMBOLIC;
        CPDF_Array* pArray = NULL;
        pFontDict = FX_NEW CPDF_Dictionary;
        CFX_ByteString cmap;
        CFX_ByteString ordering;
        int supplement;
        FX_BOOL bFound = FALSE;
        CPDF_Array* pWidthArray = FX_NEW CPDF_Array;
        charSets.RemoveAll();
        charSets.Add(FXFONT_CHINESEBIG5_CHARSET);
        if (IsHasCharSet(languages, charSets)) {
            cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
            ordering = "CNS1";
            supplement = 4;
            pWidthArray->AddInteger(1);
            _InsertWidthArray(font, 0x20, 0x7e, pWidthArray);
            bFound = TRUE;
        }
        charSets.RemoveAll();
        charSets.Add(FXFONT_GB2312_CHARSET);
        if (!bFound && IsHasCharSet(languages, charSets)) {
            cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
            ordering = "GB1", supplement = 2;
            pWidthArray->AddInteger(7716);
            _InsertWidthArray(font, 0x20, 0x20, pWidthArray);
            pWidthArray->AddInteger(814);
            _InsertWidthArray(font, 0x21, 0x7e, pWidthArray);
            bFound = TRUE;
        }
        charSets.RemoveAll();
        charSets.Add(FXFONT_HANGEUL_CHARSET);
        if (!bFound && IsHasCharSet(languages, charSets)) {
            cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
            ordering = "Korea1";
            supplement = 2;
            pWidthArray->AddInteger(1);
            _InsertWidthArray(font, 0x20, 0x7e, pWidthArray);
            bFound = TRUE;
        }
        charSets.RemoveAll();
        charSets.Add(FXFONT_SHIFTJIS_CHARSET);
        if (!bFound && IsHasCharSet(languages, charSets)) {
            cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
            ordering = "Japan1";
            supplement = 5;
            pWidthArray->AddInteger(231);
            _InsertWidthArray(font, 0x20, 0x7d, pWidthArray);
            pWidthArray->AddInteger(326);
            _InsertWidthArray(font, 0xa0, 0xa0, pWidthArray);
            pWidthArray->AddInteger(327);
            _InsertWidthArray(font, 0xa1, 0xdf, pWidthArray);
            pWidthArray->AddInteger(631);
            _InsertWidthArray(font, 0x7e, 0x7e, pWidthArray);
        }
        pBaseDict->SetAtName("Subtype", "Type0");
        pBaseDict->SetAtName("BaseFont", basefont);
        pBaseDict->SetAtName("Encoding", cmap);
        pFontDict->SetAt("W", pWidthArray);
        pFontDict->SetAtName("Type", "Font");
        pFontDict->SetAtName("Subtype", "CIDFontType2");
        pFontDict->SetAtName("BaseFont", basefont);
        CPDF_Dictionary* pCIDSysInfo = FX_NEW CPDF_Dictionary;
        pCIDSysInfo->SetAtString("Registry", "Adobe");
        pCIDSysInfo->SetAtString("Ordering", ordering);
        pCIDSysInfo->SetAtInteger("Supplement", supplement);
        pFontDict->SetAt("CIDSystemInfo", pCIDSysInfo);
        pArray = FX_NEW CPDF_Array;
        pBaseDict->SetAt("DescendantFonts", pArray);
        AddIndirectObject(pFontDict);
        pArray->AddReference(this, pFontDict);
    }
    AddIndirectObject(pBaseDict);
    CPDF_Dictionary* pFontDesc = FX_NEW CPDF_Dictionary;
    pFontDesc->SetAtName("Type", "FontDescriptor");
    pFontDesc->SetAtName("FontName", basefont);
    pFontDesc->SetAtInteger("Flags", flags);
    CPDF_Array* pBBox = FX_NEW CPDF_Array;
    for (int i = 0; i < 4; i ++) {
        pBBox->AddInteger(bbox[i]);
    }
    pFontDesc->SetAt("FontBBox", pBBox);
    pFontDesc->SetAtInteger("ItalicAngle", italicangle);
    pFontDesc->SetAtInteger("Ascent", ascend);
    pFontDesc->SetAtInteger("Descent", descend);
    pFontDesc->SetAtInteger("CapHeight", capheight);
    CGFloat fStemV = 0;
    int16_t min_width = SHRT_MAX;
    static const UniChar stem_chars[] = {'i', 'I', '!', '1'};
    const size_t count = sizeof(stem_chars) / sizeof(stem_chars[0]);
    CGGlyph glyphs[count];
    CGRect boundingRects[count];
    if (CTFontGetGlyphsForCharacters(font, stem_chars, glyphs, count)) {
        CTFontGetBoundingRectsForGlyphs(font, kCTFontHorizontalOrientation,
                                        glyphs, boundingRects, count);
        for (size_t i = 0; i < count; i++) {
            int16_t width = boundingRects[i].size.width;
            if (width > 0 && width < min_width) {
                min_width = width;
                fStemV = min_width;
            }
        }
    }
    pFontDesc->SetAtInteger("StemV", fStemV);
    AddIndirectObject(pFontDesc);
    pFontDict->SetAtReference("FontDescriptor", this, pFontDesc);
    CFRelease(traits);
    CFRelease(languages);
    return LoadFont(pBaseDict);
}