Example #1
0
void STBaselineTable::save(const std::string &filename)
{
  String inname(filename);
  Path path(inname);
  inname = path.expandedName();
  table_.deepCopy(inname, Table::New);
}
QString escapeFileName(QString infilename)
{
	QByteArray inname(infilename.toUtf8());
	QByteArray outname;
	for(int i = 0; i < inname.length(); i++) {
		unsigned char c = inname.at(i);
		if((c >= 'A' && c <= 'Z') ||
		   (c >= 'a' && c <= 'z') ||
		   (c >= '0' && c <= '9') ||
		   c == '-' ||
		   c == '_' ||
		   c == ' ' ||
		   c == '.') {
			outname.append(c);
		} else {
			outname.append('%');
			outname.append(QByteArray::number(c, 16));
		}
	}
	return QString::fromUtf8(outname);
}
Example #3
0
int main (int argc, char* argv[])
{
  long int headerlength = 0;     // Length of the Keyword header
  unsigned char* buffer = NULL;  // Hold the keyword
  USGSImageLib::DOQImageIFile* indoq = NULL;   // DOQ pointer
  std::string inname(argv[1]);
  std::ifstream infile;
  std::ofstream outfile;

  if (argc < 3)
  {
    std::cerr << "Usage: " << argv[0] << " keyword-doq header-file" 
	      << std::endl;
    exit(0);
  }

  try
  {
    if (!(indoq = new(std::nothrow) USGSImageLib::DOQImageIFile(inname)))
      throw std::bad_alloc();
    if (!indoq->good())
    {
      std::cerr << "Error opening " << argv[1] << ". Exiting..." << std::endl;
      delete indoq;
      exit(-1);
    }

    indoq->getByteCount(headerlength); // store it
    delete indoq; // Need to delete so we can get the header

    outfile.open(argv[2], std::ios::out);
    if (outfile.fail())
    {
      std::cerr << "Error opening " << argv[2] << " for output.  Exiting..." 
		<< std::endl;
      outfile.close();
      exit(-1);
    }


    infile.open(argv[1], std::ios::in);
    if (infile.fail())
    {
      std::cerr << "Error opening " << argv[1] << " for input.  Exiting..." 
		<< std::endl;
      infile.close();
      outfile.close();
      exit(-1);
    }

    if (!(buffer = new(std::nothrow) unsigned char[headerlength]))
      throw std::bad_alloc();

    infile.read(reinterpret_cast<char*>(buffer), headerlength);
    if (infile.fail()) // Error reading data
    {
      std::cerr << "Error occurred while reading file.  Exiting..." 
		<< std::endl;
      delete [] buffer;
      infile.close();
      outfile.close();
      exit(-1);
    }

    outfile.write(reinterpret_cast<char*>(buffer), headerlength);
    if (outfile.fail()) // error occurred while writing this
    {
      std::cerr << "Error occurred while writing file.  Exiting..." 
		<< std::endl;
      infile.close();
      outfile.close();
      delete [] buffer;
      exit(-1);
    }
    
    infile.close();
    outfile.close();
    delete [] buffer;
    
    return 0;
  }
  catch (...)
  {
    std::cerr << "An error has occurred while processing.  Exiting..."
	      << std::endl;
    delete [] buffer;
    infile.close();
    outfile.close();
    return -1;
  }
}
Example #4
0
/** return true if font with the specified font family name, style and size exists on the current system */
bool VFont::FontExists(const VString& inFontFamilyName, const VFontFace& inFace, GReal inSize, const GReal inDPI, const VGraphicContext *inGC)
{
#if VERSIONWIN
	bool exists = false;
	//JQ 21/06/2010: fixed and optimized FontExists (was not coherent with font creation)
	VFont *font = RetainFont( inFontFamilyName, inFace, inSize, inDPI, true);
	if (font)
	{
		if (!font->IsTrueTypeFont())
		{
			//not TrueType fonts are drawed with GDI
			//so return true if a valid HFONT is set

			HFONT hFont = font->GetFontRef();
			exists = hFont != NULL;
			font->Release();
			return exists;
		}
#if ENABLE_D2D
		if (inGC && inGC->IsD2DImpl())
		{
			//if DWrite font family name is not equal to inFontFamilyName
			//DWrite has returned a compatible font 
			//so return true only if DWrite font family name matches inFontFamilyName

			VTaskLock lock(&VWinD2DGraphicContext::GetMutexDWriteFactory());
			exists = false;
			if (font->GetImpl().GetDWriteTextFormat() != NULL)
			{
				UINT32 nameLength = font->GetImpl().GetDWriteTextFormat()->GetFontFamilyNameLength();
				if (nameLength+1 <= 80)
				{
					WCHAR familyName[80];
					HRESULT hr = font->GetImpl().GetDWriteTextFormat()->GetFontFamilyName( familyName, nameLength+1);
					exists = wcscmp( inFontFamilyName.GetCPointer(), familyName) == 0;
				}
				else
				{
					WCHAR *familyName = new WCHAR[nameLength+1];
					font->GetImpl().GetDWriteTextFormat()->GetFontFamilyName( familyName, nameLength+1);
					exists = wcscmp( inFontFamilyName.GetCPointer(), familyName) == 0;
					delete [] familyName;
				}
			}
			font->Release();
			return exists;
		}
#endif
		//if gdiplus font family name is not equal to inFontFamilyName
		//gdiplus has returned a compatible font 
		//so return true only if gdiplus font family name matches inFontFamilyName
		Gdiplus::FontFamily *family = new Gdiplus::FontFamily();
		Gdiplus::Status status = font->GetImpl().GetGDIPlusFont()->GetFamily(family);
		WCHAR familyName[LF_FACESIZE];
		family->GetFamilyName( familyName);
		exists = wcscmp( inFontFamilyName.GetCPointer(), familyName) == 0;
		delete family;

		font->Release();
	}
	return exists;
#else
	bool exists = false;
	VFont *font = RetainFont( inFontFamilyName, inFace, inSize, inDPI, true);
	if (font)
	{
		//ensure returned font has the requested family name (here we check only the family name but not the full name)
		//otherwise it is a font substitute
		CTFontRef ctfont = font->GetFontRef();
		CFStringRef name = CTFontCopyFamilyName(ctfont);
		VString xname;
		xname.MAC_FromCFString( name);
		CFRelease(name);
		VString inname( inFontFamilyName);
		inname.Truncate( xname.GetLength());
		return inname.EqualToString( xname);
	}
	return exists;
#endif
}