Пример #1
0
bool InflectRule::IsApplicable(const char *string) const {
  for (int i=0; i<nEndings; i++) {
    const int n = strlen(Ending(i));
    const char *ending, *stringEnd;
    if (Ending(i)[0] == '^') {
      ending = Ending(i) + 1;
      stringEnd = string;
    }
    else
    {
	ending = Ending(i);
#if 0   /* jbfix: len - n may be < 0! */
	stringEnd = string + strlen(string) - n;
#else
	int index = strlen(string) - n;
	if(index < 0)
	    index = 0;
	stringEnd = string + index;
#endif
    }
    if (!strncmp(stringEnd, ending, n) || 
	(ending[0] == 'V' &&
	 IsVowel(stringEnd[0]) &&
	 !strncmp(stringEnd+1, ending+1, n-1)) ||
	(ending[0] == 'C' &&
	 IsConsonant(stringEnd[0]) &&
	 !strncmp(stringEnd+1, ending+1, n-1)))
      return true;
  }
  return false;
}
Пример #2
0
BOOL SGThumbs::LoadThumbnailIntoSlot(UINT32 Slot, UINT32 ID, PathName *ActualFile)
{
/*	String_256 P(ActualFile->GetPath());
	ERROR3_PF(("Actual file: %s", (TCHAR *)P));*/

	PORTNOTETRACE("dialog","SGThumbs::LoadThumbnailIntoSlot - do nothing");
#ifndef EXCLUDE_FROM_XARALX
	if(Directory == NULL || ActualFile == NULL)
	{
		ERROR3("SGThumbs::LoadThumbnailIntoSlot Directory == NULL || ActualFile == NULL");
		return FALSE;
	}

	// Return any memory that would otherwise go down the toilet, and block the drains
	if(Thumbnails[Slot].Valid && Thumbnails[Slot].buffer)
	{
		delete Thumbnails[Slot].buffer;
		Thumbnails[Slot].buffer=NULL;
	}

	// Just in case we jump out in a state of unhappy rampantness
	Thumbnails[Slot].Valid = FALSE;

	BOOL CheckFilenameBmp = TRUE;
	BOOL CheckFilenamePng = TRUE;
	BOOL CheckFilenameReversed = TRUE;
	BOOL CheckFilenameTif = TRUE;
	BOOL CheckEncodedBmp = TRUE;
	BOOL CheckEncodedPng = TRUE;
	BOOL CheckEncodedTif = TRUE;

	BOOL UseActualFile = FALSE;

	BOOL IsRIFFTypeFile = FALSE;
	BOOL IsPCDTypeFile = FALSE;

	// Get lowercase filetype
	String_256 Type(ActualFile->GetType());
	Type.toLower();

	// Bodge to speed galleries up for art files - doesn't check or use external previews
	if( (Type.Sub((String_8)"art") != -1) ||
		(Type.Sub((String_8)"xar") != -1) )
	{
		UseActualFile = TRUE;
		CheckFilenameReversed = FALSE;
	}
	else if ( (Type.Sub((String_8)"web") != -1) ||
			  (Type.Sub((String_8)"cxw") != -1) ||
			  (Type.Sub((String_8)"cxn") != -1) )
	{
		// Check for our new version 2 native and web files
		//WEBSTER-Martin-23/01/97
		//force us to look for previews
		UseActualFile = TRUE;
		CheckFilenameReversed = FALSE;
	}
	else if ( (Type.Sub((String_8)"cdr") != -1) ||
			  (Type.Sub((String_8)"cmx") != -1) )
	{
		IsRIFFTypeFile = TRUE;
		UseActualFile = TRUE;
		CheckFilenameReversed = FALSE;
	}
	else if( Type.Sub((String_8)"ttf") != -1 ||
			 Type.Sub((String_8)"pfb") != -1)
	{
		// Bodge to speed font gallery up a bit - only checks encoded bmp file thumbnails
		CheckFilenamePng = 
			CheckFilenameBmp = 
			CheckFilenameReversed = 
			CheckFilenameTif = 
			CheckEncodedTif = FALSE;

		CheckEncodedBmp = TRUE;
		CheckEncodedPng = TRUE;

		UseActualFile = FALSE;
	}
	else if( Type.Sub((String_8)"pcd") != -1 )
	{
		IsPCDTypeFile = TRUE;
		UseActualFile = TRUE;
	}

	// Read the file into the bm yet ?
	BOOL Found = FALSE;
	CWxBitmap *pCWxBitmap = NULL;
	BOOL ReadOK = FALSE;

	// Don't error, just set exceptions... (changed 2/10/2000 by Jonathan to use
	// errors rather than exceptions to avoid a pile of messy first-change exceptions
	// when fills were not being found)
    CCDiskFile File(1024, FALSE, FALSE);

	// internal preview
	if(UseActualFile)
	{
		// Open file and check if it exists at the same time
		Found = OpenThumbnailFile( &File, *ActualFile );

		if(Found)
		{

			// Create an OILy bitmap object
			pCWxBitmap = new CWxBitmap;
			if (pCWxBitmap == NULL)
			{
				ERROR3("Problem creating thumbnail bitmap");
				return FALSE;
			}
		
			// files with internal preveiws
			// WEBSTER-Martin-08/01/97
			if(IsRIFFTypeFile)
			{
#ifndef WEBSTER //WEBSTER-Martin-21/01/97
				if ( AccusoftFilters::GetVersionNumber() > 0)
				{
					// search to see if we can find a thumbnail in this file
					if ( CMXImportFilter::SkipToPreviewBitmap(&File) )
					{
						TRACEUSER( "Martin", _T("Accusoft read RIFF preview\n"));
						ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
					}
				}
				else
				{
					TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
					ReadOK = FALSE;
				}
#endif //WEBSTER
			}
			else if(IsPCDTypeFile)
			{
#ifndef WEBSTER //WEBSTER-Martin-21/01/97
				if ( AccusoftFilters::GetVersionNumber() > 0)
				{
					TRACEUSER( "Martin", _T("Accusoft read PCD preview\n"));
					// Use the tiny preview... (we're a friend of AccusoftFilters by the way)
					AccusoftFilters::ImagePageToRead = 2;
					ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
				}
				else
				{
					TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
					ReadOK = FALSE;
				}
#endif //WEBSTER
			}
			else // new native file
			{
				// First, check that we have a CX2/XaraX format file, and
				// try to extract its preview bitmap at the same time.
				BOOL IsNewFormat = FALSE;
				UINT32 FilterId = FILTERID_NONE;
				if (BaseCamelotFilter::SkipToPreviewBitmap(&File, &IsNewFormat, &FilterId))
				{
					// Get the preview!
					if (FilterId != FILTERID_NONE)
					{
						Filter* pFilter = Filter::FindFilterFromID(FilterId);
						if (pFilter != NULL)
						{
							ERROR3IF( !pFilter->IS_KIND_OF(BaseBitmapFilter), "Preview filter is not a BaseBitmapFilter\n" );
							ReadOK = ((BaseBitmapFilter *)pFilter)->ReadFromFile( pCWxBitmap, NULL, &File, FALSE );
						}
					}
					
					// Couldn't find a preview bitmap, so we'll make a note to
					// check for an external preview file instead.
					else
					{
						UseActualFile	= FALSE;
						Found			= FALSE;
						File.close();

						delete pCWxBitmap;
						pCWxBitmap = NULL;
					}
				}

				// SkipToPreviewBitmap failed, so we'll assume that it's an old-format file.
				// In that case, we must try to load in its TIFF preview.
				else
				{
					if (AccusoftFilters::GetVersionNumber() > 0)
						ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );
					else
						ReadOK = FALSE;
				}
			}
		}
		else
		{
			TRACEUSER( "Martin", _T("Failed to find original file %s\n"), (const TCHAR *)ActualFile->GetFileName(TRUE));
		 	Error::ClearError();
			// didn't find original so look for external preview
			UseActualFile = FALSE;
		}
	}

	//we test this again cos we can change our mind about UseActualFile
	if(!UseActualFile)
	{

#ifdef THUMB_CHECK_FILENAME_WITH_PNG
		if(CheckFilenamePng && !Found)
		{
			// Check for c:\clipart\sublib\xarainfo\picture.png files (from picture.tif or whatever)
			String_256 FAP;
		
			FAP = Directory->GetPath(TRUE);
			FAP += ActualFile->GetFileName(FALSE);
			FAP += TEXT(".png");

// 			ERROR3_PF(("Looking for: %s", (TCHAR *)FAP));

			PathName ThumbPath(FAP);

			// <Filename>.png
			Found = OpenThumbnailFile( &File, ThumbPath );

			if(Found)
			{
				// Create an OILy bitmap object
				pCWxBitmap = new CWxBitmap;
				if (pCWxBitmap == NULL)
				{
					ERROR3("Problem creating bitmap");
					return FALSE;
				}

				// PNGs
				INT32 TransColour;	// ignore value returned into this
				ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour );
			}
		}
#endif

#ifdef THUMB_CHECK_FILENAME_WITH_BMP
		if(CheckFilenameBmp && !Found)
		{
			// Check for c:\clipart\sublib\xarainfo\picture.bmp files (from picture.tif or whatever)
			String_256 FAP;
		
			FAP = Directory->GetPath(TRUE);
			FAP += ActualFile->GetFileName(FALSE);
			FAP += TEXT(".bmp");

			PathName ThumbPath(FAP);

			// <Filename>.bmp
			Found = OpenThumbnailFile( &File, ThumbPath );

			if(Found)
			{
				// Create an OILy bitmap object
				pCWxBitmap = new CWxBitmap;
				if (pCWxBitmap == NULL)
				{
					ERROR3("Problem creating bitmap");
					return FALSE;
				}

				// BMPs
				ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );

				if ( !ReadOK )
				{
					delete pCWxBitmap;
					pCWxBitmap = NULL;
					Found = FALSE;
					Error::ClearError();
		
					// Er, well, it might be monochrome, so use accusoft then...
					// <Filename>.bmp
					File.close();
					Found = OpenThumbnailFile( &File, ThumbPath );
				}
			}
		}
#endif

#ifdef THUMB_CHECK_REVERSED_FILENAME
		if( CheckFilenameReversed && !Found )
		{
			// Check for c:\clipart\sublib\xarainfo\picture.fit file from picture.tif, etc...
			String_256 FAP;
		
			FAP = Directory->GetPath(TRUE);
			FAP += ActualFile->GetFileName(FALSE);
			String_256 Ending(ActualFile->GetType());
			_tcsrev((TCHAR *)Ending);		// reverse the bmp to pmb
			FAP += TEXT(".");
			FAP += (TCHAR *)Ending;

			//ERROR3_PF(("Looking for: %s", (TCHAR *)FAP));

			PathName ThumbPath(FAP);

			// <Filename>.fit <Filename>.pmb etc.
			Found = OpenThumbnailFile( &File, ThumbPath );

			if(Found)
			{
				// Create an OILy bitmap object
				pCWxBitmap = new CWxBitmap;
				if (pCWxBitmap == NULL)
				{
					return FALSE;
				}

				// BMPs
				ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );

				if ( ReadOK )
				{
					// Set the name to the filename (without the .bmp)	
					String_256 Name(ActualFile->GetFileName(FALSE));
					pCWxBitmap->SetName(Name);
				}
				else
				{
					delete pCWxBitmap;
					pCWxBitmap = NULL;
					Found = FALSE;
					Error::ClearError();

					// Er, well, it might be monochrome, so use accusoft then...
					// <Filename>.pmb
					File.close();
					Found = OpenThumbnailFile( &File, ThumbPath );
				}
			}
		}

#endif

#ifdef THUMB_CHECK_FILENAME_WITH_TIF
		if( CheckFilenameTif && !Found )
		{
			// Check for normal tiff thumbnail file of the form <Filename>.TIF
			// Construct a full pathname for actual filename with a tif extension
			String_256 FullThumbnailPath(Directory->GetPath(TRUE));
			FullThumbnailPath += ActualFile->GetFileName(FALSE);
			FullThumbnailPath += TEXT(".tif");

			TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);

			PathName FileAndPath(FullThumbnailPath);

			// <Filename>.tif
			Found = OpenThumbnailFile( &File, FileAndPath );
		}
#endif

		// Work out the encoded thumbnail name for use in multiple places below
		String_256 FullThumbnailPathWithoutExtension;
		if(!Found)
		{
			String_8 EncodedThumbnail;
	
			// Find encoded thumbnail path
			if(!GetThumbnailName(ID, &EncodedThumbnail))
				return FALSE;

			// Construct a full pathname for the encoded thumbnail file
			FullThumbnailPathWithoutExtension =  Directory->GetPath(TRUE);
			FullThumbnailPathWithoutExtension += EncodedThumbnail;
		}


#ifdef THUMB_CHECKBMPS
		if(CheckEncodedBmp && !Found)
		{
			// Check for standard bitmap thumbnail file of the form X00000X.BMP
			// And load it using internal Xara code rather than Accusoft

			// Construct a full pathname for the encoded thumbnail file
			String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
			FullThumbnailPath += TEXT(".bmp");
			TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);

			PathName FileAndPath(FullThumbnailPath);

			// <Filename>.bmp
			Found = OpenThumbnailFile( &File, FileAndPath );

			if(Found)
			{
				// Create an OILy bitmap object
				pCWxBitmap = new CWxBitmap;
				if (pCWxBitmap == NULL)
				{
					ERROR3("Problem creating bitmap");
					return FALSE;
				}

				// Set the name to the thumbID name (without the .bmp)	
				String_256 Name(FileAndPath.GetFileName(FALSE));
				pCWxBitmap->SetName(Name);

				// BMPs
				ReadOK = DIBUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE );

				if(!ReadOK)
				{
					delete pCWxBitmap;
					pCWxBitmap = NULL;
					Found = FALSE;
					Error::ClearError();

					// Er, well, it might be monochrome, so use accusoft then...
					// <Filename>.bmp
					File.close();
					Found = OpenThumbnailFile( &File, FileAndPath );
				}
			}
		}
#endif

#ifdef THUMB_CHECKPNGS
		if(CheckEncodedPng && !Found)
		{
			// Check for downloaded thumbnail file of the form X00000X.PNG
			// And load it using internal Xara code rather than Accusoft

			// Construct a full pathname for the encoded thumbnail file
			String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
			FullThumbnailPath += TEXT(".png");
			TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);

			PathName FileAndPath(FullThumbnailPath);

			// <Filename>.png
			Found = OpenThumbnailFile( &File, FileAndPath );

			if(Found)
			{
				// Create an OILy bitmap object
				pCWxBitmap = new CWxBitmap;
				if (pCWxBitmap == NULL)
				{
					ERROR3("Problem creating bitmap");
					return FALSE;
				}

				// Set the name to the thumbID name (without the .png)	
				String_256 Name(FileAndPath.GetFileName(FALSE));
				pCWxBitmap->SetName(Name);

				// PNGs
				INT32 TransColour;	// ignore value returned into this
				ReadOK = PNGUtil::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, &TransColour );
			}
		}
#endif

#ifdef THUMB_CHECKTIFS
		if(CheckEncodedTif && !Found)
		{
			// Check for encoded tiff thumbnail file of the form X00000X.TIF

			// Construct a full pathname for the encoded thumbnail file
			String_256 FullThumbnailPath(FullThumbnailPathWithoutExtension);
			FullThumbnailPath += TEXT(".tif");
			TRACEUSER( "Richard", _T("Filename: %s\n"), (TCHAR *)FullThumbnailPath);

			PathName FileAndPath(FullThumbnailPath);

			// X00000X.tif
			Found = OpenThumbnailFile( &File, FileAndPath );
		}
#endif

#ifndef WEBSTER //WEBSTER-Martin-21/01/97
		if ( Found && !ReadOK )
		{
			// this is Accusoft's last chance
			if ( AccusoftFilters::GetVersionNumber() > 0)
			{
				ReadOK = AccusoftFilters::ReadFromFile( &File, &pCWxBitmap->BMInfo, &pCWxBitmap->BMBytes, TRUE, NULL, NULL, TRUE );
			}
			else
			{
				TRACEUSER( "Martin", _T("Accusoft filter not loaded\n"));
				ReadOK = FALSE;
			}
		}
#endif //WEBSTER
	}

	if(!ReadOK || pCWxBitmap == NULL)
	{
		// Problems somewhere above
		TRACEUSER( "Richard", _T("Can't find/load thumbnail"));

		// We don't want error boxes popping up every time we can't find a thumbnail
		Error::ClearError();

		if(pCWxBitmap != NULL)
		{
			delete pCWxBitmap;
			pCWxBitmap = NULL;
		}
		return FALSE;
	}

	// Set the name to the file's name (without the .art .xar etc)	
	String_256 Name(ActualFile->GetFileName(FALSE));
	pCWxBitmap->SetName(Name);

	// create the kernel bitmap, attaching the OILy bitmap to it
	Thumbnails[Slot].buffer = new KernelBitmap(pCWxBitmap, TRUE);
	if (Thumbnails[Slot].buffer == NULL)
	{
		ERROR3("Problem creating kernel bitmap for thumbnail");
		delete pCWxBitmap;
		pCWxBitmap = NULL;
		return FALSE;
	}

	// Set the rest of the entries to sensible values
	Thumbnails[Slot].Valid = TRUE;
	Thumbnails[Slot].ID = ID;
	Thumbnails[Slot].Usage = 0;
	Thumbnails[Slot].Size = ThumbnailsSize;

	Error::ClearError();
#endif
	// Well, looks like we got ourselves a thumbnail...
	return TRUE;
}