Esempio n. 1
0
// Get a std::string from an EXTfldval object
std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) {
	std::string retString;
	
	// Get a qchar* string
	qlong maxLength = fVal.getBinLen()+1; // Use binary length as approximation of maximum size
	qlong length = 0, stringLength = 0;
	qchar* omnisString = new qchar[maxLength];
	fVal.getChar(maxLength, omnisString, length);
	
#ifdef UNICODE
	// Translate qchar* string into UTF8 binary
	qbyte* utf8data = reinterpret_cast<qbyte*>(omnisString);
	stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data);
	char* cString = reinterpret_cast<char*> (utf8data);
#else
	stringLength = length;
	retString = std::string((char*)omnisString,stringLength);
#endif	
	
	// Clean-up
	if (omnisString != NULL){
		delete [] omnisString;
	}
	
	return retString;
}
void	oImgBitmap::setContents(EXTfldval &pContents) {
	if (mImage == NULL) {
		// really?
	} else {
		// We get the binary as is, we assume the contents is raw picture data in any format supported by STB
		qlong bitmapLen = pContents.getBinLen();
		if (bitmapLen > 0) {
			qbyte * bitmapData = (qbyte *)MEMmalloc(sizeof(qbyte) * (bitmapLen+1));
			if (bitmapData != NULL) {
				qlong	reallen;
				pContents.getBinary(bitmapLen, bitmapData, reallen);

				// and assign it to our image
				mImage->copy(bitmapData, reallen);

				// and free our memory
				MEMfree(bitmapData);
			} else {
				oBaseComponent::addToTraceLog("setContents: Couldn't allocate memory for pixel buffer");
			};
		} else {
			oBaseComponent::addToTraceLog("setContents: No image specified");
		};
	};
};
Esempio n. 3
0
// Return a C++ std::vector of unsigned char from an EXTfldval
std::vector<unsigned char> OmnisTools::getBinaryVectorFromEXTFldVal(EXTfldval& fVal) {
    std::vector<unsigned char> v;
    qlong realLength, bufferSize;
    
    bufferSize = fVal.getBinLen();
    v.resize(bufferSize);
    
    fVal.getBinary(v.size(), &v[0], realLength);
    
    return v;
}
Esempio n. 4
0
// Get a std::wstring from an EXTfldval object
std::wstring OmnisTools::getWStringFromEXTFldVal(EXTfldval& fVal) {
	std::wstring retString;
	
	// Get a qchar* string
	qlong maxLength = fVal.getBinLen()+1; // Use binary length as approximation of maximum size
	qlong length = 0, stringLength = 0;
	qchar* omnisString = new qchar[maxLength];
	fVal.getChar(maxLength, omnisString, length);
	
	wchar_t* cString;
#if MARKUP_SIZEOFWCHAR == 2
	// For 2-Byte UTF16 wchar_t* (Typically Windows)
	// Convert from UTF8 to UTF16 and set new stringLength
	
	// Translate qchar* string into UTF8 binary
	qbyte* utf8data = reinterpret_cast<qbyte*>(omnisString);
	stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data);
	
	// Translate UTF8 to UTF16
	CHRconvToUtf16 utf16conv(utf8data, stringLength);
	UChar* utf16data = utf16conv.dataPtr();
	stringLength = utf16conv.len();
	
	// Translate UTF16 binary into char* string
	cString = reinterpret_cast<wchar_t*>(utf16data);
#else
	// For 4-Byte UTF32 wchar_t* (Typically Mac and Linux)
	// Convert from UTF8 to UTF32 and set new stringLength
	stringLength = length;
	CHRconvToUtf32FromChar utf32conv(omnisString, stringLength, qfalse);
	U32Char* utf32data = utf32conv.dataPtr();
	stringLength = utf32conv.len();
	
	// Translate UTF16 binary into char* string
	cString = reinterpret_cast<wchar_t*>(utf32data);
#endif
	
	// Create standard string
	retString = std::wstring(cString,stringLength);
	
	// Clean-up
	delete [] omnisString;
	
	return retString;
}
Esempio n. 5
0
// Get a std::string from an EXTfldval object
std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) {
	std::string retString;
	
	// Get a qchar* string
	qlong maxLength = fVal.getBinLen()+1; // Use binary length as approximation of maximum size
	qlong length = 0, stringLength = 0;
	qchar* omnisString = new qchar[maxLength];
	fVal.getChar(maxLength, omnisString, length);
	
	// Translate qchar* string into UTF8 binary
	qbyte* utf8data = reinterpret_cast<qbyte*>(omnisString);
	stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data);
	
	// Translate UTF8 binary into char* string
	char* cString = reinterpret_cast<char*> (utf8data);
	
	// Create standard string
	retString = std::string(cString,stringLength);
	
	// Clean-up
	delete [] omnisString;
	
	return retString;
}