Esempio n. 1
0
void copyTextRunTo(const TextRun& run, UChar *word)
{
    int word_size = run.length() - run.from(), j = 0;
    for (int i = run.from(); i < run.length(); i++) {
        if (Font::treatAsSpace(run[i])) {
            word[j] = ' ';
            j++;
        } else {
            word[j] = run[i];
            j++;
        }
    }
    word[j]='\0';
}
Esempio n. 2
0
float Font::floatWidthForSimpleText(const TextRun& run, const TextStyle& style, float* startPosition, GlyphBuffer* glyphBuffer) const
{
    int     text_width;
    // FIXME: Process normal, bold, italic styles
//     if (m_fontDescription.italic()) {
//         if (m_fontDescription.bold()) {
//             // Bold && italic
//             TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_BOLD | TTF_STYLE_ITALIC);
//         } else {
//             // Only italic
//             TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_ITALIC);
//         }
//     } else if (m_fontDescription.bold()) {
//         // Only bold
//         TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_BOLD);
//     } else
//         TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_NORMAL);

    int wordSize = run.length() - run.from();
    UChar word[wordSize];
    copyTextRunTo(run, word);

    DFBCHECK(d->m_ttfFont->GetStringWidth(d->m_ttfFont, word, -1, &text_width));
    if (startPosition) {
        if (style.ltr())
            *startPosition = text_width ;
        else
            *startPosition = text_width;
    }
    return static_cast<float> (text_width);
}
Esempio n. 3
0
void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const TextStyle&, const FloatPoint& point) const
{
    // FIXME: style, run.from()/length() cut-off
    ctx->platformContext()->drawText(point, 
                                     QString::fromRawData(
                                         reinterpret_cast<const QChar*>(
                                             run.characters() + run.from()), run.length()));
}
Esempio n. 4
0
/* SDL ttf implementation may be lighter ??? */
void Font::drawSimpleText(BIGraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
{
    WebCore::Color  color = context->strokeColor();
    BCNativeImage*  text_surface = static_cast<BCNativeImage*>(context->getNativeImage())->getSurface();

    // FIXME: Process normal, bold, italic styles
//     if (m_fontDescription.italic())
//     {
//         if (m_fontDescription.bold())
//         { // Bold && italic
//             TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_BOLD | TTF_STYLE_ITALIC);
//         }
//         else
//         { // Only italic
//             TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_ITALIC);
//         }
//     }
//     else if (m_fontDescription.bold())
//     { // Only bold
//         TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_BOLD);
//     }
//     else
//     {
//         TTF_SetFontStyle(d->m_ttfFont, TTF_STYLE_NORMAL);
//     }

    DFBCHECK(text_surface->SetFont(text_surface, d->m_ttfFont));

    // Set font color
    DFBCHECK(text_surface->SetColor(text_surface, color.red(), color.green(), color.blue(), color.alpha()));

    // Draw font
    int wordSize = run.length() - run.from();
    UChar word[wordSize];
    copyTextRunTo(run, word);

    DFBCHECK(text_surface->DrawString(text_surface, word, -1, point.x(), point.y(), DSTF_TOP | DSTF_LEFT));
}
Esempio n. 5
0
float Font::floatWidthForSimpleText(const TextRun& run, const WebCore::TextStyle& style,
                                    float* startPosition, BIGlyphBuffer* glyphBuffer) const
{
    int     text_width;
    // Process normal, bold, italic styles
    if (m_fontDescription.italic()) {
        if (m_fontDescription.bold()) {
            // Bold && italic
            d->m_ttfFont->style = FT_STYLE_BOLD | FT_STYLE_ITALIC;
            d->flushCache(d->m_ttfFont);
        } else {
            // Only italic
            d->m_ttfFont->style = FT_STYLE_ITALIC;
            d->flushCache(d->m_ttfFont);
        }
    } else if (m_fontDescription.bold()) {
        // Only bold
        d->m_ttfFont->style = FT_STYLE_BOLD;
        d->flushCache(d->m_ttfFont);
    } else {
        d->m_ttfFont->style = FT_STYLE_NORMAL;
        d->flushCache(d->m_ttfFont);
    }

    int wordSize = run.length() - run.from();
    UChar word[wordSize];
    copyTextRunTo(run, word);

    d->sizeUnicode(d->m_ttfFont, word, &text_width, NULL);
    if (startPosition) {
        if (style.ltr())
            *startPosition = text_width ;
        else
            *startPosition = text_width;
    }
    return static_cast<float> (text_width);
}
Esempio n. 6
0
float Font::floatWidthForComplexText(const TextRun& run, const TextStyle&) const
{
    // FIXME: style
    QFontMetricsF metrics(primaryFont()->m_font.font());
    return metrics.width(QString::fromRawData(reinterpret_cast<const QChar*>(run.characters() + run.from()), run.length()));
}
Esempio n. 7
0
int Font::offsetForPositionForSimpleText(const TextRun& run, const TextStyle& style, int x, bool includePartialGlyphs) const
{
    return  run.to() - run.from();
}
Esempio n. 8
0
// SDL ttf implementation may be lighter ???
void Font::drawSimpleText(BIGraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
{
    WebCore::Color  text_color = context->strokeColor();
    BINativeImage*  text_surface;
    IntRect         dst_rect;
    IntPoint        intPoint;
    static int oldx = 0;
    int         text_width, text_height;
    bool        init = false;
    int         numSpaces = 0;
    int         padPerSpace = 0;
    FloatPoint	wordPoint(point);

    // Process normal, bold, italic styles
    if (m_fontDescription.italic()) {
        if (m_fontDescription.bold()) {
            // Bold && italic
            d->m_ttfFont->style = FT_STYLE_BOLD | FT_STYLE_ITALIC;
            d->flushCache(d->m_ttfFont);
        } else {
            // Only italic
            d->m_ttfFont->style = FT_STYLE_ITALIC;
            d->flushCache(d->m_ttfFont);
        }
    } else if (m_fontDescription.bold()) {
        // Only bold
        d->m_ttfFont->style = FT_STYLE_BOLD;
        d->flushCache(d->m_ttfFont);
    } else {
        d->m_ttfFont->style = FT_STYLE_NORMAL;
        d->flushCache(d->m_ttfFont);
    }

    // Draw font
    int wordSize = run.length() - run.from();
    UChar word[wordSize];
    copyTextRunTo(run, word);

    for (int i = 0; i <= wordSize; i++) {
        if (Font::treatAsSpace(word[i]))
            numSpaces++;;
    }

    if (numSpaces == 0)
        padPerSpace = 0;
    else
        padPerSpace = static_cast<int> (ceil(style.padding() / numSpaces));

    UChar text[wordSize + 1];
    int j = 0;
    for (int i = 0; i <= wordSize; i++) {
        if (Font::treatAsSpace(word[i]) || i == wordSize) {
            text[j] = ' ';
            text[++j] = '\0';

			d->sizeUnicode(d->m_ttfFont, text, &text_width, &text_height);
			text_surface = d->renderUnicodeBlended(d->m_ttfFont, text, text_color, context->alphaLayer());
			if (text_surface) {
    			intPoint.setX(static_cast<uint16_t> (wordPoint.x()));
    			intPoint.setY(static_cast<uint16_t> (wordPoint.y()) - ascent());
                dst_rect.setX(0);
                dst_rect.setY(0);
                dst_rect.setWidth(text_surface->size().width());
                dst_rect.setHeight(text_surface->size().height());
                getBIGraphicsDevice()->copy(*(context->widget()), *text_surface, dst_rect, intPoint, context->alphaLayer());
                delete text_surface;
            }
            wordPoint = wordPoint + FloatSize(padPerSpace + text_width,0);
            j = 0;
        } else {
            text[j] = word[i];
            j++;
        }
    }
}