コード例 #1
0
bool IniReader::ReadKeyword(const std::string &section, const std::string &key, bool *value, bool defaultv) const
{
	int v = defaultv ? 1 : 0;
	bool ret = ReadKeyword(section, key, &v, defaultv ? 1 : 0);
	*value = v != 0;
	return ret;
}
コード例 #2
0
///////////////////
// Read a keyword from a file (bool version)
bool ReadKeyword(const std::string& filename, const std::string& section, const std::string& key, bool *value, bool defaultv)
{
	int v = defaultv ? 1 : 0;
	bool ret = ReadKeyword(filename, section, key, &v, defaultv ? 1 : 0);
	*value = v != 0;
	return ret;
}
コード例 #3
0
/*!
  Handle a picture in the current group
  \return false if failed
  \desc Once the \\pict has been read, hande the picture contained in
  the current group. Calls LoadPictData
  \see IE_Imp_RTF::LoadPictData
  \fixme TODO handle image size and other options in the future
*/
bool IE_Imp_RTF::HandlePicture()
{
	// this method loads a picture from the file
	// and insert it in the document.

	unsigned char ch1;
	bool bPictProcessed = false;
	PictFormat format = picNone;

	unsigned char keyword[MAX_KEYWORD_LEN];
	UT_sint32 parameter = 0;
	bool parameterUsed = false;
	RTFProps_ImageProps imageProps;

	bool isBinary = false;
	long binaryLen = 0;
	RTF_KEYWORD_ID keywordID;

	do {
		if (!ReadCharFromFile(&ch1))
			return false;

		switch (ch1)
		{
		case '\\':
			UT_return_val_if_fail(!bPictProcessed, false);
			// Process keyword

			if (!ReadKeyword(keyword, &parameter, &parameterUsed, MAX_KEYWORD_LEN))
			{
				UT_DEBUGMSG(("Unexpected EOF during RTF import?\n"));
			}
			UT_DEBUGMSG(("Doing standard picture stuff with keyword %s \n",keyword));
			keywordID = KeywordToID(reinterpret_cast<char *>(keyword));
			UT_ASSERT(RTF_KW_cell  != keywordID);
			switch (keywordID)
			{
			case RTF_KW_pngblip:
				format = picPNG;
				break;
			case RTF_KW_jpegblip:
				format = picJPEG;
				break;
			case RTF_KW_wmetafile:
				format = picWMF;
				break;
			case RTF_KW_svgblip:
				format = picSVG;
				break;
			case RTF_KW_picwgoal:
				if (parameterUsed)
				{
					if ((imageProps.sizeType == RTFProps_ImageProps::ipstNone)) {
						imageProps.sizeType = RTFProps_ImageProps::ipstGoal;
					}
					imageProps.wGoal = parameter;
				}
				break;
			case RTF_KW_pichgoal:
				if (parameterUsed)
				{
					if ((imageProps.sizeType == RTFProps_ImageProps::ipstNone)) {
						imageProps.sizeType = RTFProps_ImageProps::ipstGoal;
					}
					imageProps.hGoal = parameter;
				}
				break;
			case RTF_KW_picscalex:
				if ((parameterUsed) && (parameter != 100))       // scale the image if one of these two keywords appear
				{
					imageProps.sizeType = RTFProps_ImageProps::ipstScale;
					imageProps.scaleX = static_cast<unsigned short>(parameter);
				}
				break;
			case RTF_KW_picscaley:
				if ((parameterUsed) && (parameter != 100))
				{
					imageProps.sizeType = RTFProps_ImageProps::ipstScale;
					imageProps.scaleY = static_cast<unsigned short>(parameter);
				}
				break;
			case RTF_KW_piccropt:
				imageProps.cropt = parameter;
				imageProps.bCrop = true;
				break;
			case RTF_KW_piccropb:
				imageProps.cropb = parameter;
				imageProps.bCrop = true;
				break;
			case RTF_KW_piccropl:
				imageProps.cropl = parameter;
				imageProps.bCrop = true;
				break;
			case RTF_KW_piccropr:
				imageProps.cropr = parameter;
				imageProps.bCrop = true;
				break;
			case RTF_KW_bin:
				/* this code is completely broken. 
				   if we encounter the \bin keyboard, then we must
				   immediately read the binary stream....
				   skip the first space after the keyword.
				 */
				UT_ASSERT_HARMLESS(parameterUsed);
				if (parameterUsed) {
					isBinary = true;
					binaryLen = parameter;
					UT_UTF8String image_name;
					UT_UTF8String_sprintf(image_name,"%d",getDoc()->getUID(UT_UniqueId::Image));

					unsigned char ch;
					if(ReadCharFromFileWithCRLF(&ch)) {
						if(ch != ' ') {
							SkipBackChar(ch);
						}
						else {
							UT_DEBUGMSG(("Skipped space after \\bin keyword \n"));
						}
					}
					
					if (!LoadPictData(format, image_name.utf8_str(), imageProps, isBinary, binaryLen)) {
						return false;
					}
					bPictProcessed = true;
				}
				break;
			default:
				UT_DEBUGMSG(("Unhandled keyword in \\pict group: %s\n", keyword));
			}
			break;
		case '{':
			UT_return_val_if_fail(!bPictProcessed, false);

			// We won't handle nested groups, at least in this version,
			// we just skip them
			SkipCurrentGroup(true);
			break;
		case '}':
			// check if a pict was found ( and maybe inserted )
			// as this would be the last iteration
			if (!bPictProcessed)
			{
				UT_DEBUGMSG(("Bogus RTF: \\pict group without a picture\n"));
				return false;
			}
			break;
		default:
			if (!bPictProcessed) {
				// It this a conforming rtf, this should be the pict data
				// if we know how to handle this format, we insert the picture
				// But we'll skip this if this is a binary data because we found
				// a \binN keyword a processed the picture.
				UT_DEBUGMSG(("Inserting Image data now \n"));
				UT_UTF8String image_name;
				UT_UTF8String_sprintf(image_name,"%d",getDoc()->getUID(UT_UniqueId::Image));

				// the first char belongs to the picture too
				SkipBackChar(ch1);

				if (!LoadPictData(format, image_name.utf8_str(), imageProps, isBinary, binaryLen))
					if (!SkipCurrentGroup(false))
						return false;

				bPictProcessed = true;
			}
		}
	} while (ch1 != '}');

	// The last brace is put back on the stream, so that the states stack
	// doesn't get corrupted
	SkipBackChar(ch1);

	return true;
}