Пример #1
0
  FT_Face GetFont(const std::string &filename, float size, float aspect, XUTILS::auto_buffer& memoryBuf)
  {
    // don't have it yet - create it
    if (!m_library)
      FT_Init_FreeType(&m_library);
    if (!m_library)
    {
      CLog::Log(LOGERROR, "Unable to initialize freetype library");
      return NULL;
    }

    FT_Face face;

    // ok, now load the font face
    CURL realFile(CSpecialProtocol::TranslatePath(filename));
    if (realFile.GetFileName().empty())
      return NULL;

    memoryBuf.clear();
#ifndef TARGET_WINDOWS
    if (!realFile.GetProtocol().empty())
#endif // ! TARGET_WINDOWS
    {
      // load file into memory if it is not on local drive
      // in case of win32: always load file into memory as filename is in UTF-8,
      //                   but freetype expect filename in ANSI encoding
      XFILE::CFile f;
      if (f.LoadFile(realFile, memoryBuf) <= 0)
        return NULL;
      if (FT_New_Memory_Face(m_library, (const FT_Byte*)memoryBuf.get(), memoryBuf.size(), 0, &face) != 0)
        return NULL;
    }
#ifndef TARGET_WINDOWS
    else if (FT_New_Face( m_library, realFile.GetFileName().c_str(), 0, &face ))
      return NULL;
#endif // ! TARGET_WINDOWS

    unsigned int ydpi = 72; // 72 points to the inch is the freetype default
    unsigned int xdpi = (unsigned int)MathUtils::round_int(ydpi * aspect);

    // we set our screen res currently to 96dpi in both directions (windows default)
    // we cache our characters (for rendering speed) so it's probably
    // not a good idea to allow free scaling of fonts - rather, just
    // scaling to pixel ratio on screen perhaps?
    if (FT_Set_Char_Size( face, 0, (int)(size*64 + 0.5f), xdpi, ydpi ))
    {
      FT_Done_Face(face);
      return NULL;
    }

    return face;
  };
Пример #2
0
/*!
 *
 * \param data       CDT for the CEmoticon class
 * \param themedir   path to the theme directory
 * \param list       list where the results are stored
 *
 * \returns the number of loaded emoticons
 */
static unsigned loadTheme(const struct Emoticons *data,
                          const QString &themedir,
                          node_list_t &list)
{
  QDomDocument doc("doc");
  QFile file(themedir + "/emoticons.xml");
  unsigned ret = 0;

  if (file.open(IO_ReadOnly) && doc.setContent(&file))
  {
    QDomElement elem = doc.documentElement();
    QDomNode n = elem.firstChild();
    for (; !n.isNull(); n = n.nextSibling())
    {
      if (n.isElement())
      {
        elem = n.toElement();
        if (!elem.isNull() && elem.tagName() == QString::fromLatin1("emoticon"))
        {
          QString file = elem.attribute("file");
          QString f=realFile(data,themedir,file);
          if (f != QString::null)
          {
            struct node node;
            unsigned size;

            node.emoticon = loadStrings(data, n.firstChild(), &size);
	    if (size)
	    {
	      node.file = f;
	      create_regexp(node.emoticon, node.reg);
	      list.push_back(node);
	      ret += size;
	    }
          }
        }
      }
    }
  }

  file.close();
  return ret;
};
Пример #3
0
void ImageManager::ThumbnailCache::save() const
{
    m_timer->stop();
    m_unsaved = 0;

    QTemporaryFile file;
    if ( !file.open() ) {
        qWarning("Failed to create temporary file");
        return;
    }

    QDataStream stream(&file);
    stream << FILEVERSION
           << m_currentFile
           << m_currentOffset
           << m_map.count();

    for( QMap<DB::FileName,CacheFileInfo>::ConstIterator it = m_map.begin(); it != m_map.end(); ++it ) {
        const CacheFileInfo& cacheInfo = it.value();
        stream << it.key().relative()
               << cacheInfo.fileIndex
               << cacheInfo.offset
               << cacheInfo.size;
    }
    file.close();

    const QString realFileName = thumbnailPath(QString::fromLatin1("thumbnailindex"));
    QFile::remove( realFileName );
    if ( !file.copy( realFileName ) )
        qWarning("Failed to copy the temporary file %s to %s", qPrintable( file.fileName() ), qPrintable( realFileName ) );

    QFile realFile( realFileName );
    realFile.open( QIODevice::ReadOnly );
    realFile.setPermissions( QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOther );
    realFile.close();
}