Exemplo n.º 1
0
void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* bitmap,
        uint32_t bitmapWidth, uint32_t bitmapHeight, Rect* bounds, const float* pos) {
    int dstX = x + glyph->mBitmapLeft;
    int dstY = y + glyph->mBitmapTop;

    CacheTexture* cacheTexture = glyph->mCacheTexture;
    PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer();

    uint32_t formatSize = PixelBuffer::formatSize(pixelBuffer->getFormat());
    uint32_t alpha_channel_offset = PixelBuffer::formatAlphaOffset(pixelBuffer->getFormat());
    uint32_t cacheWidth = cacheTexture->getWidth();
    uint32_t srcStride = formatSize * cacheWidth;
    uint32_t startY = glyph->mStartY * srcStride;
    uint32_t endY = startY + (glyph->mBitmapHeight * srcStride);

    const uint8_t* cacheBuffer = pixelBuffer->map();

    for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY;
            cacheY += srcStride, bitmapY += bitmapWidth) {

        if (formatSize == 1) {
            memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth);
        } else {
            for (uint32_t i = 0; i < glyph->mBitmapWidth; ++i) {
                bitmap[bitmapY + dstX + i] = cacheBuffer[cacheY + (glyph->mStartX + i)*formatSize + alpha_channel_offset];
            }
        }
    }

}
Exemplo n.º 2
0
void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* bitmap,
        uint32_t bitmapWidth, uint32_t bitmapHeight, Rect* bounds, const float* pos) {
    int dstX = x + glyph->mBitmapLeft;
    int dstY = y + glyph->mBitmapTop;

    CacheTexture* cacheTexture = glyph->mCacheTexture;

    uint32_t cacheWidth = cacheTexture->getWidth();
    uint32_t startY = glyph->mStartY * cacheWidth;
    uint32_t endY = startY + (glyph->mBitmapHeight * cacheWidth);

    PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer();
    const uint8_t* cacheBuffer = pixelBuffer->map();

    for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY;
            cacheY += cacheWidth, bitmapY += bitmapWidth) {
        memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth);
    }
}
Exemplo n.º 3
0
void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y,
                                 uint8_t* bitmap, uint32_t bitmapW, uint32_t bitmapH, Rect* bounds, const float* pos) {
    int nPenX = x + glyph->mBitmapLeft;
    int nPenY = y + glyph->mBitmapTop;

    /** Mediatek: Fix incorrect shadow for long text **/
    if ((uint32_t)nPenX >= bitmapW || (uint32_t)nPenY >= bitmapH) {
#if DEBUG_FONT_RENDERER
        if (g_HWUI_debug_font_renderer) {
            ALOGE("nPen(%d, %d) exceed bitmap size %dx%d", nPenX, nPenY, bitmapW, bitmapH);
        }
#endif
        return;
    }

    uint32_t endX = glyph->mStartX + glyph->mBitmapWidth;
    uint32_t endY = glyph->mStartY + glyph->mBitmapHeight;

    CacheTexture* cacheTexture = glyph->mCacheTexture;
    uint32_t cacheWidth = cacheTexture->getWidth();
    const uint8_t* cacheBuffer = cacheTexture->getTexture();

    uint32_t cacheX = 0, cacheY = 0;
    int32_t bX = 0, bY = 0;
    for (cacheX = glyph->mStartX, bX = nPenX; cacheX < endX; cacheX++, bX++) {
        for (cacheY = glyph->mStartY, bY = nPenY; cacheY < endY; cacheY++, bY++) {
            if (bX < 0 || bY < 0 || bX >= (int32_t) bitmapW || bY >= (int32_t) bitmapH) {
#if DEBUG_FONT_RENDERER
                if (g_HWUI_debug_font_renderer) {
                    ALOGE("Skipping invalid index");
                }
#endif
                continue;
            }
            uint8_t tempCol = cacheBuffer[cacheY * cacheWidth + cacheX];
            bitmap[bY * bitmapW + bX] = tempCol;
        }
    }
}