Пример #1
0
void BBoxDeviceContext::DrawMusicText(const std::wstring& text, int x, int y)
{
    assert( m_fontStack.top() );

    int g_x, g_y, g_w, g_h;
    int lastCharWidth = 0;

    for (unsigned int i = 0; i < text.length(); i++)
    {
        wchar_t c = text[i];
        Glyph *glyph = Resources::GetGlyph(c);
        if (!glyph) {
            continue;
        }
        glyph->GetBoundingBox(&g_x, &g_y, &g_w, &g_h);

        int x_off = x + g_x * m_fontStack.top()->GetPointSize() / glyph->GetUnitsPerEm();
        // because we are in the drawing context, y position are already flipped
        int y_off = y - g_y * m_fontStack.top()->GetPointSize() / glyph->GetUnitsPerEm();

        UpdateBB(x_off, y_off,
                 x_off + g_w * m_fontStack.top()->GetPointSize() / glyph->GetUnitsPerEm(),
                 // idem, y position are flipped
                 y_off - g_h * m_fontStack.top()->GetPointSize() / glyph->GetUnitsPerEm());

        lastCharWidth = g_w * m_fontStack.top()->GetPointSize() / glyph->GetUnitsPerEm();
        x += lastCharWidth; // move x to next char

    }
}