bool WindowsManager::addSquareFace (const char* faceNameCorba,
            const value_type* posCorba1,
            const value_type* posCorba2,
            const value_type* posCorba3,
            const value_type* posCorba4,
            const value_type* colorCorba)
    {
        std::string faceName (faceNameCorba);
        if (nodes_.find (faceName) != nodes_.end ()) {
            std::cout << "You need to chose an other name, \"" << faceName
                << "\" already exist." << std::endl;
            return false;
        }
        else {
            mtx_.lock();
            osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]);
            osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]);
            osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]);
            osgVector3 pos4 (posCorba4[0], posCorba4[1], posCorba4[2]);
            LeafNodeFacePtr_t face = LeafNodeFace::create
                (faceName, pos1, pos2, pos3, pos3, getColor (colorCorba));
            WindowsManager::initParent (faceName, face);
            addNode (faceName, face);
	    mtx_.unlock();
            return true;
        }
    }
Example #2
0
int CALLBACK
gfxGDIFontList::EnumFontFamExProc(ENUMLOGFONTEXW *lpelfe,
                                      NEWTEXTMETRICEXW *lpntme,
                                      DWORD fontType,
                                      LPARAM lParam)
{
    const LOGFONTW& lf = lpelfe->elfLogFont;

    if (lf.lfFaceName[0] == '@') {
        return 1;
    }

    nsAutoString name(lf.lfFaceName);
    BuildKeyNameFromFontName(name);

    gfxGDIFontList *fontList = PlatformFontList();

    if (!fontList->mFontFamilies.GetWeak(name)) {
        nsDependentString faceName(lf.lfFaceName);
        nsRefPtr<gfxFontFamily> family = new GDIFontFamily(faceName);
        fontList->mFontFamilies.Put(name, family);

        // if locale is such that CJK font names are the default coming from
        // GDI, then if a family name is non-ASCII immediately read in other
        // family names.  This assures that MS Gothic, MS Mincho are all found
        // before lookups begin.
        if (!IsASCII(faceName)) {
            family->ReadOtherFamilyNames(gfxPlatformFontList::PlatformFontList());
        }

        if (fontList->mBadUnderlineFamilyNames.Contains(name))
            family->SetBadUnderlineFamily();
    }

    return 1;
}
void Font::platformInit()
{
    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
    m_scriptCache = 0;
    m_scriptFontProperties = 0;
    m_isSystemFont = false;

    if (m_platformData.useGDI())
        return initGDIFont();

    if (!m_platformData.size()) {
        m_fontMetrics.reset();
        m_avgCharWidth = 0;
        m_maxCharWidth = 0;
        m_isSystemFont = false;
        m_scriptCache = 0;
        m_scriptFontProperties = 0;
        return;
    }

    HWndDC dc(0);
    SaveDC(dc);

    cairo_scaled_font_t* scaledFont = m_platformData.scaledFont();
    const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size();

    cairo_win32_scaled_font_select_font(scaledFont, dc);

    TEXTMETRIC textMetrics;
    GetTextMetrics(dc, &textMetrics);
    float ascent = textMetrics.tmAscent * metricsMultiplier;
    float descent = textMetrics.tmDescent * metricsMultiplier;
    float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
    float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;

    int faceLength = ::GetTextFace(dc, 0, 0);
    Vector<WCHAR> faceName(faceLength);
    ::GetTextFace(dc, faceLength, faceName.data());
    m_isSystemFont = !wcscmp(faceName.data(), L"Lucida Grande");

    ascent = ascentConsideringMacAscentHack(faceName.data(), ascent, descent);

    m_fontMetrics.setAscent(ascent);
    m_fontMetrics.setDescent(descent);
    m_fontMetrics.setLineGap(lineGap);
    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
    m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier;
    m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier;

    cairo_text_extents_t extents;
    cairo_scaled_font_text_extents(scaledFont, "x", &extents);
    xHeight = -extents.y_bearing;

    m_fontMetrics.setXHeight(xHeight);
    cairo_win32_scaled_font_done_font(scaledFont);

    m_scriptCache = 0;
    m_scriptFontProperties = 0;

    RestoreDC(dc, -1);
}
Example #4
0
void SimpleFontData::platformInit()
{
    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
    m_scriptCache = 0;
    m_scriptFontProperties = 0;
    m_isSystemFont = false;

    if (m_platformData.useGDI())
       return initGDIFont();

    if (!m_platformData.size()) {
        m_fontMetrics.reset();
        m_avgCharWidth = 0;
        m_maxCharWidth = 0;
        return;
    }

    HDC hdc = GetDC(0);
    SaveDC(hdc);

    cairo_scaled_font_t* scaledFont = m_platformData.scaledFont();
    const double metricsMultiplier = cairo_win32_scaled_font_get_metrics_factor(scaledFont) * m_platformData.size();

    cairo_win32_scaled_font_select_font(scaledFont, hdc);

    TEXTMETRIC textMetrics;
    GetTextMetrics(hdc, &textMetrics);
    float ascent = textMetrics.tmAscent * metricsMultiplier;
    float descent = textMetrics.tmDescent * metricsMultiplier;
    float xHeight = ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts.
    float lineGap = textMetrics.tmExternalLeading * metricsMultiplier;

    int faceLength = ::GetTextFace(hdc, 0, 0);
    Vector<WCHAR> faceName(faceLength);
    ::GetTextFace(hdc, faceLength, faceName.data());
    m_isSystemFont = !wcscmp(faceName.data(), L"Lucida Grande");
 
    ascent = ascentConsideringMacAscentHack(faceName.data(), ascent, descent);

    m_fontMetrics.setAscent(ascent);
    m_fontMetrics.setDescent(descent);
    m_fontMetrics.setLineGap(lineGap);
    m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap));
    m_avgCharWidth = textMetrics.tmAveCharWidth * metricsMultiplier;
    m_maxCharWidth = textMetrics.tmMaxCharWidth * metricsMultiplier;

    OUTLINETEXTMETRIC metrics;
    if (GetOutlineTextMetrics(hdc, sizeof(metrics), &metrics) > 0) {
        // This is a TrueType font.  We might be able to get an accurate xHeight
        GLYPHMETRICS gm;
        MAT2 mat = { 1, 0, 0, 1 };
        DWORD len = GetGlyphOutline(hdc, 'x', GGO_METRICS, &gm, 0, 0, &mat);
        if (len != GDI_ERROR && gm.gmptGlyphOrigin.y > 0)
            xHeight = gm.gmptGlyphOrigin.y * metricsMultiplier;
    }

    m_fontMetrics.setXHeight(xHeight);
    cairo_win32_scaled_font_done_font(scaledFont);

    RestoreDC(hdc, -1);
    ReleaseDC(0, hdc);
}