コード例 #1
0
String DefaultLocalizationStrategy::imageTitle(const String& filename, const IntSize& size)
{
#if USE(CF)
#if !defined(BUILDING_ON_LEOPARD)
    RetainPtr<CFStringRef> filenameCFString(AdoptCF, filename.createCFString());
    RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCopyCurrent());
    RetainPtr<CFNumberFormatterRef> formatter(AdoptCF, CFNumberFormatterCreate(0, locale.get(), kCFNumberFormatterDecimalStyle));

    int widthInt = size.width();
    RetainPtr<CFNumberRef> width(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &widthInt));
    RetainPtr<CFStringRef> widthString(AdoptCF, CFNumberFormatterCreateStringWithNumber(0, formatter.get(), width.get()));

    int heightInt = size.height();
    RetainPtr<CFNumberRef> height(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &heightInt));
    RetainPtr<CFStringRef> heightString(AdoptCF, CFNumberFormatterCreateStringWithNumber(0, formatter.get(), height.get()));

    return formatLocalizedString(WEB_UI_STRING("%@ %@�~%@ pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filenameCFString.get(), widthString.get(), heightString.get());
#else
    RetainPtr<CFStringRef> filenameCFString(AdoptCF, filename.createCFString());
    return formatLocalizedString(WEB_UI_STRING("%@ %d�~%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filenameCFString.get(), size.width(), size.height());
#endif
#else
    return formatLocalizedString(WEB_UI_STRING("<filename> %d�~%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), size.width(), size.height()).replace("<filename>", filename);
#endif
}
コード例 #2
0
String imageTitle(const String& filename, const IntSize& size)
{
#if USE(CF)
#if !PLATFORM(MAC) || PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
    RetainPtr<CFStringRef> filenameCFString(AdoptCF, filename.createCFString());
    RetainPtr<CFLocaleRef> locale(AdoptCF, CFLocaleCopyCurrent());
    RetainPtr<CFNumberFormatterRef> formatter(AdoptCF, CFNumberFormatterCreate(0, locale.get(), kCFNumberFormatterDecimalStyle));

    int widthInt = size.width();
    RetainPtr<CFNumberRef> width(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &widthInt));
    RetainPtr<CFStringRef> widthString(AdoptCF, CFNumberFormatterCreateStringWithNumber(0, formatter.get(), width.get()));

    int heightInt = size.height();
    RetainPtr<CFNumberRef> height(AdoptCF, CFNumberCreate(0, kCFNumberIntType, &heightInt));
    RetainPtr<CFStringRef> heightString(AdoptCF, CFNumberFormatterCreateStringWithNumber(0, formatter.get(), height.get()));

    return formatLocalizedString(WEB_UI_STRING("%@ %@×%@ pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filenameCFString.get(), widthString.get(), heightString.get());
#else
    RetainPtr<CFStringRef> filenameCFString(AdoptCF, filename.createCFString());
    return formatLocalizedString(WEB_UI_STRING("%@ %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filenameCFString.get(), size.width(), size.height());
#endif
#else
    return formatLocalizedString(WEB_UI_STRING("<filename> %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), size.width(), size.height()).replace("<filename>", filename);
#endif
}
コード例 #3
0
CFStringRef CreateLocalizedStringForParameterValue ( double					inParameterValue,
													 const CAAUParameter *	inParameter,
													 UInt32					inDigits,
													 UInt32					minDigits) {	
	if (!inParameter) return nil;

	AudioUnitParameterInfo info = inParameter->ParamInfo();
	int pow10;

	switch (info.unit) {
		case kAudioUnitParameterUnit_Hertz:
			// number of significant digits based on value
			pow10 = int(log10(fmax(inParameterValue, .000001)));
			break;
		default:
			// number of significant digits based on parameter range
			pow10 = int(log10(fmax(double(info.maxValue - info.minValue), .000001)));
			break;
	}

	// pow10	range			nDigitsAfterDecimal
	//	-2		.0100-.0999		4
	//	-1		.100-.999		3
	//	0		1.00-9.99		2
	//	1		10.0-99.9		1
	//	2		100-999			0
	//	3		1000-9990		-1
	//	4		10000-99900		-2
	
	int nDigitsAfterDecimal = inDigits - (pow10 + 1);
	if (nDigitsAfterDecimal < 0)
		nDigitsAfterDecimal = 0;	// the least number of digits possible is zero

	if (info.flags & kAudioUnitParameterFlag_IsHighResolution)
		nDigitsAfterDecimal = 4;
	
	CFLocaleRef currentLocale = CFLocaleCopyCurrent(); 
	CFNumberFormatterRef numberFormatter = CFNumberFormatterCreate (NULL, currentLocale, kCFNumberFormatterDecimalStyle);
	
	CFNumberRef maxFractionDigits = CFNumberCreate (NULL, kCFNumberIntType, &nDigitsAfterDecimal);
	
	if (nDigitsAfterDecimal > 0)
		nDigitsAfterDecimal = minDigits;
		
	CFNumberRef minFractionDigits = CFNumberCreate (NULL, kCFNumberIntType, &nDigitsAfterDecimal); 

	CFNumberFormatterSetProperty (numberFormatter, kCFNumberFormatterMinFractionDigits, minFractionDigits); 
	CFNumberFormatterSetProperty (numberFormatter, kCFNumberFormatterMaxFractionDigits, maxFractionDigits); 
	CFStringRef formattedNumberString = CFNumberFormatterCreateStringWithValue (NULL, numberFormatter, kCFNumberDoubleType, &inParameterValue); 

	CFRelease(currentLocale); 
	CFRelease(numberFormatter); 
	CFRelease(maxFractionDigits);
	CFRelease(minFractionDigits);

	return formattedNumberString;
}
コード例 #4
0
ファイル: CFLocale.c プロジェクト: AbhinavBansal/opencflite
// ICU does not reliably set up currency info for other than Currency-type formatters,
// so we have to have another routine here which creates a Currency number formatter.
static bool __CFLocaleCopyNumberFormat2(CFLocaleRef locale, bool user, CFTypeRef *cf, CFStringRef context) {
    CFStringRef str = NULL;
    CFNumberFormatterRef nf = CFNumberFormatterCreate(kCFAllocatorSystemDefault, locale, kCFNumberFormatterCurrencyStyle);
    str = nf ? (CFStringRef)CFNumberFormatterCopyProperty(nf, context) : NULL;
    if (nf) CFRelease(nf);
    if (str) {
	*cf = str;
	return true;
    }
    return false;
}
コード例 #5
0
double ValueForLocalizedParameterString (CFStringRef string, const CAAUParameter * inParameter) {
	CFLocaleRef currentLocale = CFLocaleCopyCurrent(); 
	CFNumberFormatterRef numberFormatter = CFNumberFormatterCreate (NULL, currentLocale, kCFNumberFormatterDecimalStyle);

	double value = 0;
	Boolean worked = CFNumberFormatterGetValueFromString (numberFormatter, string, NULL, kCFNumberDoubleType, &value);
	
	CFRelease(currentLocale);
	CFRelease(numberFormatter);
	
	if (worked)
		return value;
	else {
		AudioUnitParameterInfo info = inParameter->ParamInfo();
		return info.defaultValue;
	}
}
コード例 #6
0
String imageTitle(const String& filename, const IntSize& size)
{
#if USE(CF)
    RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCopyCurrent());
    RetainPtr<CFNumberFormatterRef> formatter = adoptCF(CFNumberFormatterCreate(0, locale.get(), kCFNumberFormatterDecimalStyle));

    int widthInt = size.width();
    RetainPtr<CFNumberRef> width = adoptCF(CFNumberCreate(0, kCFNumberIntType, &widthInt));
    RetainPtr<CFStringRef> widthString = adoptCF(CFNumberFormatterCreateStringWithNumber(0, formatter.get(), width.get()));

    int heightInt = size.height();
    RetainPtr<CFNumberRef> height = adoptCF(CFNumberCreate(0, kCFNumberIntType, &heightInt));
    RetainPtr<CFStringRef> heightString = adoptCF(CFNumberFormatterCreateStringWithNumber(0, formatter.get(), height.get()));

    return formatLocalizedString(WEB_UI_STRING("%@ %@×%@ pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename.createCFString().get(), widthString.get(), heightString.get());
#else
    return formatLocalizedString(WEB_UI_STRING("<filename> %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), size.width(), size.height()).replace("<filename>", filename);
#endif
}
コード例 #7
0
ファイル: testCairo.cpp プロジェクト: edconnor/TestCairo
Boolean equalValues(CFStringRef number, CFNumberRef expected, CFNumberFormatterStyle style, CFNumberFormatterOptionFlags option)
{
   //CFStringRef enLocaleIdentifier = CFSTR("en_US");
   //CFLocaleRef curLocale = CFLocaleCreate(NULL, enLocaleIdentifier);
   
   CFLocaleRef curLocale = CFLocaleCopyCurrent();
   CFStringRef identifier = CFLocaleGetIdentifier(curLocale);
   CFNumberFormatterRef fmt;
   CFNumberRef val;

   show(CFSTR("Make a Number from : %@"), number);
   
   fmt = CFNumberFormatterCreate (0, curLocale, style);
   val = CFNumberFormatterCreateNumberFromString(0, fmt, number, 0, option);
   
   show(CFSTR("val=%@, should be=%@\n"), val, expected);
   
   if (!val)
      return false;
   
   return (0 == CFNumberCompare(val, expected, 0));
}
コード例 #8
0
CFStringRef getBuffer()
{
	kern_return_t kernResult;
	bufferStruct myBufStruct;
	IOByteCount structSize = sizeof(myBufStruct);

    kernResult = IOConnectMethodScalarIStructureO(userClient,
													 klogKextBuffer,	
													 0,					// input count
													 &structSize,
													 &myBufStruct);

	CFDataRef result = CFDataCreate(kCFAllocatorDefault,myBufStruct.buffer,myBufStruct.bufLen);
	CFMutableStringRef decodedData = CFStringCreateMutable(kCFAllocatorDefault,0);
	
	if (!keymap)
		return decodedData;
	
	CFDictionaryRef flagsDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Flags"));
	if (!flagsDict)
		return decodedData;
	CFDictionaryRef ucDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Uppercase"));
	if (!ucDict)
		return decodedData;
	CFDictionaryRef lcDict = (CFDictionaryRef)CFDictionaryGetValue(keymap,CFSTR("Lowercase"));
	if (!lcDict)
		return decodedData;

	CFNumberFormatterRef myNF = CFNumberFormatterCreate(kCFAllocatorDefault,CFLocaleCopyCurrent(),kCFNumberFormatterNoStyle);
	
	for (int i=0; i<CFDataGetLength(result);i+=2)
	{
		u_int16_t curChar;
		CFDataGetBytes(result,CFRangeMake(i,2),(UInt8*)&curChar);
		bool isUpper = false;
		
		if (CFBooleanGetValue(showMods))
		{
			char flagTmp = (curChar >> 11);
			
			if (flagTmp & 0x01)
				CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x01")));

			if (flagTmp & 0x02)
				CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x02")));

			if (flagTmp & 0x04)
				CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x04")));

			if (flagTmp & 0x08)
				CFStringAppend(decodedData,(CFStringRef)CFDictionaryGetValue(flagsDict,CFSTR("0x08")));
				
			if (flagTmp & 0x10)
				isUpper = true;
		}

		curChar &= 0x07ff;		
		CFStringRef keyChar = CFNumberFormatterCreateStringWithValue(kCFAllocatorDefault,myNF,kCFNumberShortType,&curChar);
		CFStringRef text;

		if (isUpper)
			text = (CFStringRef)CFDictionaryGetValue(ucDict,keyChar);
		else
			text = (CFStringRef)CFDictionaryGetValue(lcDict,keyChar);		
		
		if (text)
		{
			if (CFStringCompare(text,CFSTR("\\n"),0)==kCFCompareEqualTo)
				text = CFSTR("\n");

			CFStringAppend(decodedData,text);
		}
		else
			syslog(LOG_ERR,"Unmapped key %d",curChar);		
	}

	return decodedData;
}