X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Ftext-typesetter.cpp;h=faac5ef079a0b8bef3695d34255ef260df4a9b07;hb=edbdf42bbfda9c87246d8142574ce15b36ccd6a8;hp=901c4775a1b4bcebe496b83519e80c15ba475448;hpb=cbe6a1281bbd60ad8722af8123451adb591a0a1a;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp index 901c477..faac5ef 100755 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -423,6 +423,16 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec // Combine the two buffers imageBuffer = CombineImageBuffer( imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight ); } + + // Generate the background if enabled + const bool backgroundEnabled = mModel->IsBackgroundEnabled(); + if ( backgroundEnabled ) + { + Devel::PixelBuffer backgroundImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs -1 ); + + // Combine the two buffers + imageBuffer = CombineImageBuffer( imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight ); + } } // Create the final PixelData for the combined image buffer @@ -705,6 +715,43 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer( const unsigned int bufferWidth } } + // Draw the background color from the leftmost glyph to the rightmost glyph + if ( style == Typesetter::STYLE_BACKGROUND ) + { + Vector4 backgroundColor = mModel->GetBackgroundColor(); + + for( int y = glyphData.verticalOffset + baseline - line.ascender; y < glyphData.verticalOffset + baseline - line.descender; y++ ) + { + if( ( y < 0 ) || ( y > static_cast(bufferHeight - 1) ) ) + { + // Do not write out of bounds. + continue; + } + + for( int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++ ) + { + if( ( x < 0 ) || ( x > static_cast(bufferWidth - 1) ) ) + { + // Do not write out of bounds. + continue; + } + + // Always RGBA image for text with styles + uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( glyphData.bitmapBuffer.GetBuffer() ); + uint32_t backgroundPixel = *( bitmapBuffer + y * glyphData.width + x ); + uint8_t* backgroundPixelBuffer = reinterpret_cast( &backgroundPixel ); + + // Write the background color to the pixel buffer + *( backgroundPixelBuffer ) = static_cast( backgroundColor.r * 255.f ); + *( backgroundPixelBuffer + 1u ) = static_cast( backgroundColor.g * 255.f ); + *( backgroundPixelBuffer + 2u ) = static_cast( backgroundColor.b * 255.f ); + *( backgroundPixelBuffer + 3u ) = static_cast( backgroundColor.a * 255.f ); + + *( bitmapBuffer + y * glyphData.width + x ) = backgroundPixel; + } + } + } + // Increases the vertical offset with the line's descender. glyphData.verticalOffset += static_cast( -line.descender ); }