TEST(FontPlatformDataTest, AhemSpaceLigatureHasNoSpaceWithoutFontFeatures)
{
    Font font = createTestFont("AhemSpaceLigature", fontPath("AhemSpaceLigature.woff"));
    const FontPlatformData& platformData = font.primaryFont()->platformData();
    TypesettingFeatures features = 0;

    EXPECT_FALSE(platformData.hasSpaceInLigaturesOrKerning(features));
}
Example #2
0
void TPaths::createFontFile() {
    logger()->debug("createFontFile");

    QString output = fontConfigFilename();
    QString fontDir = fontPath();

    // Check if the WZPlayer font config file already exists
    // and uses the current font dir
	if (QFile::exists(output)) {
		QFile i(output);
		if (i.open(QIODevice::ReadOnly | QIODevice::Text)) {
			QString text = i.readAll();
            if (text.contains("<dir>" + fontDir + "</dir>")) {
                logger()->info("createFontFile: reusing existing font config"
                             " file '%1' which uses font directory '%2'",
                             output, fontDir);
				return;
			}
		}
	}

    // Use the font file from the selected font dir
    QString input = fontDir + "/fonts.conf";
    if (!QFile::exists(input)) {
        logger()->warn("createFontFile: font.conf '%1' not found", input);
        return;
	}

	QFile infile(input);
	if (infile.open(QIODevice::ReadOnly | QIODevice::Text)) {
		QString text = infile.readAll();
		text = text.replace("<!-- <dir>WINDOWSFONTDIR</dir> -->", "<dir>WINDOWSFONTDIR</dir>");
		text = text.replace("<dir>WINDOWSFONTDIR</dir>", "<dir>" + fontPath() + "</dir>");

        logger()->info("createFontFile: saving '%1'", output);
		QFile outfile(output);
		if (outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
			outfile.write(text.toUtf8());
			outfile.close();
		}
    } else {
       logger()->warn("createFontFile: failed to open '%1'", input);
    }
}
Example #3
0
std::string Font::getDefaultPath()
{
	const int fontCount = 4;

#ifdef WIN32
	std::string fonts[] = {"DejaVuSerif.ttf",
		"Arial.ttf",
		"Verdana.ttf",
		"Tahoma.ttf" };

	//build full font path
	TCHAR winDir[MAX_PATH];
	GetWindowsDirectory(winDir, MAX_PATH);
#ifdef UNICODE
	char winDirChar[MAX_PATH*2];
	char DefChar = ' ';
    WideCharToMultiByte(CP_ACP, 0, winDir, -1, winDirChar, MAX_PATH, &DefChar, NULL);
	std::string fontPath(winDirChar);
#else
	std::string fontPath(winDir);
#endif
	fontPath += "\\Fonts\\";
	//prepend to font file names
	for(int i = 0; i < fontCount; i++)
	{
		fonts[i] = fontPath + fonts[i];
	}
#else
	std::string fonts[] = {"/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf",
		"/usr/share/fonts/TTF/DejaVuSerif.ttf",
		"/usr/share/fonts/dejavu/DejaVuSerif.ttf",
		"font.ttf" };
#endif

	for(int i = 0; i < fontCount; i++)
	{
		if(boost::filesystem::exists(fonts[i]))
			return fonts[i];
	}

	LOG(LogError) << "Error - could not find a font!";

	return "";
}
void pawsConfigShortcut::PickText( const char * fontName, int size )
{
    csString    fontPath( "/planeshift/data/ttf/");
    fontPath += fontName;
    fontPath += ".ttf";

    if( loaded )
    {
        MenuBar->LayoutButtons();
        MenuBar->OnResize();
        ((pawsShortcutWindow*)ShortcutMenu)->SetFont( fontPath, size );
        MenuBar->SetFont( fontPath, size );
        MenuBar->SetButtonFont( fontPath, size );

        ((pawsShortcutWindow*)ShortcutMenu)->Draw();
        SaveConfig();    
    }
}
Example #5
0
static QFontEngine::FaceId fontFile(const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
{
    *freetype = 0;
    *synth = 0;

    QByteArray xname = _xname.toLower();

    int pos = 0;
    int minus = 0;
    while (minus < 5 && (pos = xname.indexOf('-', pos + 1)))
        ++minus;
    QByteArray searchname = xname.left(pos);
    while (minus < 12 && (pos = xname.indexOf('-', pos + 1)))
        ++minus;
    QByteArray encoding = xname.mid(pos + 1);
    //qDebug("xname='%s', searchname='%s', encoding='%s'", xname.data(), searchname.data(), encoding.data());
    QStringList fontpath = fontPath();
    QFontEngine::FaceId face_id;
    face_id.index = 0;

    QByteArray best_mapping;

    for (QStringList::ConstIterator it = fontpath.constBegin(); it != fontpath.constEnd(); ++it) {
        if (!(*it).startsWith(QLatin1Char('/')))
            continue; // not a path name, a font server
        QString fontmapname;
        int num = 0;
        // search font.dir and font.scale for the right file
        while (num < 2) {
            if (num == 0)
                fontmapname = (*it) + QLatin1String("/fonts.scale");
            else
                fontmapname = (*it) + QLatin1String("/fonts.dir");
            ++num;
            //qWarning(fontmapname);
            QFile fontmap(fontmapname);
            if (!fontmap.open(QIODevice::ReadOnly))
                continue;
            while (!fontmap.atEnd()) {
                QByteArray mapping = fontmap.readLine();
                QByteArray lmapping = mapping.toLower();

                //qWarning(xfontname);
                //qWarning(mapping);
                if (!lmapping.contains(searchname))
                    continue;
                int index = mapping.indexOf(' ');
                QByteArray ffn = mapping.mid(0,index);
                // remove bitmap formats freetype can't handle
                if (ffn.contains(".spd") || ffn.contains(".phont"))
                    continue;
                bool best_match = false;
                if (!best_mapping.isEmpty()) {
                    if (lmapping.contains("-0-0-0-0-")) { // scalable font
                        best_match = true;
                        goto found;
                    }
                    if (lmapping.contains(encoding) && !best_mapping.toLower().contains(encoding))
                        goto found;
                    continue;
                }

            found:
                int colon = ffn.lastIndexOf(':');
                if (colon != -1) {
                    QByteArray s = ffn.left(colon);
                    ffn = ffn.mid(colon + 1);
                    if (s.contains("ds="))
                        *synth |= QFontEngine::SynthesizedBold;
                    if (s.contains("ai="))
                        *synth |= QFontEngine::SynthesizedItalic;
                }
                face_id.filename = (*it).toLocal8Bit() + '/' + ffn;
                best_mapping = mapping;
                if (best_match)
                    goto end;
            }
        }
    }
end:
//     qDebug("fontfile for %s is from '%s'\n    got %s synth=%d", xname.data(),
//            best_mapping.data(), face_id.filename.data(), *synth);
    *freetype = QFreetypeFace::getFace(face_id);
    if (!*freetype) {
        face_id.index = 0;
        face_id.filename = QByteArray();
    }
    return face_id;
}
Example #6
0
void initializeFontConfigSetting()
{
    if (g_getenv("WEBKIT_SKIP_WEBKITTESTRUNNER_FONTCONFIG_INITIALIZATION"))
        return;

    FcInit();

    // If a test resulted a font being added or removed via the @font-face rule, then
    // we want to reset the FontConfig configuration to prevent it from affecting other tests.
    static int numFonts = 0;
    FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication);
    if (appFontSet && numFonts && appFontSet->nfont == numFonts)
        return;

    // Load our configuration file, which sets up proper aliases for family
    // names like sans, serif and monospace.
    FcConfig* config = FcConfigCreate();
    GUniquePtr<gchar> fontConfigFilename(g_build_filename(FONTS_CONF_DIR, "fonts.conf", nullptr));
    if (!g_file_test(fontConfigFilename.get(), G_FILE_TEST_IS_REGULAR))
        g_error("Cannot find fonts.conf at %s\n", fontConfigFilename.get());
    if (!FcConfigParseAndLoad(config, reinterpret_cast<FcChar8*>(fontConfigFilename.get()), true))
        g_error("Couldn't load font configuration file from: %s", fontConfigFilename.get());

    CString fontsPath = getFontsPath();
    if (fontsPath.isNull())
        g_error("Could not locate test fonts at %s. Is WEBKIT_TOP_LEVEL set?", fontsPath.data());

    GUniquePtr<GDir> fontsDirectory(g_dir_open(fontsPath.data(), 0, nullptr));
    while (const char* directoryEntry = g_dir_read_name(fontsDirectory.get())) {
        if (!g_str_has_suffix(directoryEntry, ".ttf") && !g_str_has_suffix(directoryEntry, ".otf"))
            continue;
        GUniquePtr<gchar> fontPath(g_build_filename(fontsPath.data(), directoryEntry, nullptr));
        if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(fontPath.get())))
            g_error("Could not load font at %s!", fontPath.get());
    }

    // Ahem is used by many layout tests.
    GUniquePtr<gchar> ahemFontFilename(g_build_filename(FONTS_CONF_DIR, "AHEM____.TTF", nullptr));
    if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(ahemFontFilename.get())))
        g_error("Could not load font at %s!", ahemFontFilename.get()); 

    static const char* fontFilenames[] = {
        "WebKitWeightWatcher100.ttf",
        "WebKitWeightWatcher200.ttf",
        "WebKitWeightWatcher300.ttf",
        "WebKitWeightWatcher400.ttf",
        "WebKitWeightWatcher500.ttf",
        "WebKitWeightWatcher600.ttf",
        "WebKitWeightWatcher700.ttf",
        "WebKitWeightWatcher800.ttf",
        "WebKitWeightWatcher900.ttf",
        0
    };

    for (size_t i = 0; fontFilenames[i]; ++i) {
        GUniquePtr<gchar> fontFilename(g_build_filename(FONTS_CONF_DIR, "..", "..", "fonts", fontFilenames[i], nullptr));
        if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontFilename.get())))
            g_error("Could not load font at %s!", fontFilename.get()); 
    }

    // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452
    GUniquePtr<gchar> fontWithNoValidEncodingFilename(g_build_filename(FONTS_CONF_DIR, "FontWithNoValidEncoding.fon", nullptr));
    if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontWithNoValidEncodingFilename.get())))
        g_error("Could not load font at %s!", fontWithNoValidEncodingFilename.get()); 

    if (!FcConfigSetCurrent(config))
        g_error("Could not set the current font configuration!");

    numFonts = FcConfigGetFonts(config, FcSetApplication)->nfont;
}
Example #7
0
std::string FontSupport::drawingFontPath() const
{
  return fontPath(currentFont_);
}
bool pawsActiveMagicWindow::LoadSetting()
{
    csRef<iDocument> doc;
    csRef<iDocumentNode> root,
                         mainNode,
                         optionNode,
                         optionNode2;
    csString fileName;
    fileName = "/planeshift/userdata/options/configactivemagic.xml";

    if(!vfs->Exists(fileName))
    {
       return true; //no saved config to load. Use default values.
    }

    doc = ParseFile(PawsManager::GetSingleton().GetObjectRegistry(), fileName);
    if(doc == NULL)
    {
        Error2("pawsActiveMagicWindow::LoadUserPrefs Failed to parse file %s", fileName.GetData());
        return false;
    }
    root = doc->GetRoot();
    if(root == NULL)
    {
        Error2("pawsActiveMagicWindow::LoadUserPrefs : %s has no XML root",fileName.GetData());
        return false;
    }
    mainNode = root->GetNode("activemagic");
    if(mainNode == NULL)
    {
        Error2("pawsActiveMagicWindow::LoadUserPrefs %s has no <activemagic> tag",fileName.GetData());
        return false;
    }

    optionNode = mainNode->GetNode("useImages");
    if(optionNode != NULL)
    {
        if( strcasecmp( "yes",  optionNode->GetAttributeValue("on") )==0 )
        {
            SetUseImages( true );
        }
        else
        {
            SetUseImages( false );
        }
    }

    optionNode = mainNode->GetNode("autoResize");
    if(optionNode != NULL)
    {
        if( strcasecmp( "yes",  optionNode->GetAttributeValue("on") )==0 )
        {
            SetAutoResize( true );
        }
        else
        {
            SetAutoResize( false );
        }
    }

    optionNode = mainNode->GetNode("showEffects");
    if(optionNode != NULL)
    {
        if( strcasecmp( "itemAndSpell",  optionNode->GetAttributeValue("active") )==0 )
        {
            SetShowEffects( true );
        }
        else
        {
            SetShowEffects( false );
        }
    }

    optionNode = mainNode->GetNode("showWindow");
    if(optionNode != NULL)
    {
        if( strcasecmp( "yes",  optionNode->GetAttributeValue("on") )==0 )
        {
            SetShowWindow( true );
        }
        else
        {
            SetShowWindow( false );
        }
    }

    optionNode = mainNode->GetNode("buttonHeight");
    if(optionNode != NULL)
        buffList->SetButtonHeight( optionNode->GetAttributeValueAsInt("value", true));
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve buttonHeight node");
    }

    optionNode = mainNode->GetNode("buttonWidthMode");
    if(optionNode != NULL)
    {
        if( strcasecmp( "buttonWidthAutomatic", optionNode->GetAttributeValue("active") )==0 )
        {
            buffList->SetButtonWidth( 0 );
        }
        else
        {
            optionNode = mainNode->GetNode("buttonWidth");
            if(optionNode != NULL)
                buffList->SetButtonWidth( optionNode->GetAttributeValueAsInt("value", true));
            else
            {
                Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve buttonWidth");
                return false;
            }
        }
    }
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve buttonWidthMode");
    }

    optionNode = mainNode->GetNode("textSize");
    if(optionNode == NULL)
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve textSize node");
    }

    optionNode2 = mainNode->GetNode("textFont");
    if(optionNode2 == NULL)
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve textFont node");
    }

    if( optionNode != NULL && optionNode2 != NULL )
    {
        fontName = csString( optionNode2->GetAttributeValue("value") );

        csString    fontPath( "/planeshift/data/ttf/");
        fontPath += fontName.GetData();
        fontPath += ".ttf"; 
        SetFont( fontPath, optionNode->GetAttributeValueAsInt("value", true) );
        buffList->SetFont( fontPath, optionNode->GetAttributeValueAsInt("value", true) );
    }
    //else use default.

    optionNode = mainNode->GetNode("textSpacing");
    if(optionNode != NULL)
        buffList->SetButtonPaddingWidth( optionNode->GetAttributeValueAsInt("value", true));
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve textSpacing node");
    }

    optionNode = mainNode->GetNode("warnLevel");
    if(optionNode != NULL)
    {
        warnLevel=optionNode->GetAttributeValueAsFloat("value", true);
    }
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve warnLevel node");
        warnLevel = 100;
    }
    optionNode = mainNode->GetNode("warnMode");
    if(optionNode != NULL)
    {
        if( strcasecmp( "warnModeSeconds",  optionNode->GetAttributeValue("active") )==0 )
        {
            warnMode=1;
        }
        else
        {
            warnMode=0;
        }
    }
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve warnMode node");
        warnMode=0;
    }

    optionNode = mainNode->GetNode("dangerLevel");
    if(optionNode != NULL)
        dangerLevel = optionNode->GetAttributeValueAsFloat("value", true);
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve dangerLevel node");
        dangerLevel = 100;
    }
    optionNode = mainNode->GetNode("dangerMode");
    if(optionNode != NULL)
    {
        if( strcasecmp( "dangerModeSeconds",  optionNode->GetAttributeValue("active") )==0 )
        {
            dangerMode=1;
        }
        else
        {
            dangerMode=0;
        }
    }
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve dangerMode node");
        dangerMode=0;
    }

    optionNode = mainNode->GetNode("flashLevel");
    if(optionNode != NULL)
        flashLevel = optionNode->GetAttributeValueAsFloat("value", true);
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve flashLevel node");
        flashLevel=100;
    }
    optionNode = mainNode->GetNode("flashMode");
    if(optionNode != NULL)
    {
        if( strcasecmp( "flashModeSeconds",  optionNode->GetAttributeValue("active") )==0 )
        {
            flashMode=1;
        }
        else
        {
            flashMode=0;
        }
    }
    else
    {
        Error1("pawsActiveMagicWindow::LoadUserPrefs unable to retrieve FlashMode node");
        flashMode=0;
    }


    return true;
}
Example #9
0
bool CCImage::initWithString(
        const char * pText,
        int nWidth/* = 0*/,
        int nHeight/* = 0*/,
        ETextAlign eAlignMask/* = kAlignCenter*/,
        const char * pFontName/* = nil*/,
        int nSize/* = 0*/)
{
    if (!pText)
    {
        return false;
    }

    QString fontPath(CCFileUtils::fullPathFromRelativePath(pFontName));

    QString fontFamily = pFontName;
    QString fontStyle = "Normal";

    // font already loaded?
    QMap<QString, QString>::iterator fontIter = loadedFontMap.find(fontPath);
    if(fontIter == loadedFontMap.end())
    {
        int fontID = QFontDatabase::addApplicationFont(fontPath);
        if(fontID != -1)
        {
            QStringList familyList = QFontDatabase::applicationFontFamilies(fontID);

            if(familyList.size() > 0)
                fontFamily = familyList.at(0);
        }

        loadedFontMap.insert(fontPath, fontFamily);
    }
    else
    {
        fontFamily = fontIter.value();
    }

    QFontDatabase fd;
    QFont f = fd.font(fontFamily, fontStyle, nSize);
    f.setPixelSize(nSize);

    QFontMetrics fm(f);

    if (nWidth)
    {
        m_nWidth = (short)nWidth;
    }
    else
    {
        m_nWidth = fm.width(QString(pText));
    }

    if (nHeight)
    {
        m_nHeight = (short)nHeight;
    }
    else
    {
        m_nHeight = fm.height();
    }

    m_bHasAlpha = true;
    m_bPreMulti = false;
    m_pData = new unsigned char[m_nWidth * m_nHeight * 4];
    memset(m_pData, 0, m_nWidth * m_nHeight * 4);
    m_nBitsPerComponent = 8;

    QImage image(m_pData, m_nWidth, m_nHeight, QImage::Format_ARGB32_Premultiplied);
    QPainter painter(&image);
    painter.setFont(f);
    painter.setPen(Qt::white);

    int flags = 0;
    switch (eAlignMask)
    {
    case kAlignCenter: // Horizontal center and vertical center.
        flags |= Qt::AlignHCenter;
        flags |= Qt::AlignVCenter;
        break;
    case kAlignTop: // Horizontal center and vertical top.
        flags |= Qt::AlignHCenter;
        flags |= Qt::AlignTop;
        break;
    case kAlignTopRight: // Horizontal right and vertical top.
        flags |= Qt::AlignRight;
        flags |= Qt::AlignTop;
        break;
    case kAlignRight: // Horizontal right and vertical center.
        flags |= Qt::AlignRight;
        flags |= Qt::AlignVCenter;
        break;
    case kAlignBottomRight: // Horizontal right and vertical bottom.
        flags |= Qt::AlignRight;
        flags |= Qt::AlignBottom;
        break;
    case kAlignBottom: // Horizontal center and vertical bottom.
        flags |= Qt::AlignHCenter;
        flags |= Qt::AlignBottom;
        break;
    case kAlignBottomLeft: // Horizontal left and vertical bottom.
        flags |= Qt::AlignLeft;
        flags |= Qt::AlignBottom;
        break;
    case kAlignLeft: // Horizontal left and vertical center.
        flags |= Qt::AlignLeft;
        flags |= Qt::AlignVCenter;
        break;
    case kAlignTopLeft: // Horizontal left and vertical top.
        flags |= Qt::AlignLeft;
        flags |= Qt::AlignTop;
        break;
    }

    painter.drawText(QRect(0, 0, m_nWidth, m_nHeight), flags, QString(pText));
    painter.end();

    return true;
}