From 27234e5bd2b8002d734ae2e78d6f9126cae72b68 Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Mon, 8 Jul 2019 17:04:30 +0900 Subject: [PATCH] prevent division by zero Change-Id: I97b97da610346f75c93e3fe0ee41831f1f2b8740 --- .../text/text-abstraction/cairo-renderer.cpp | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/dali/internal/text/text-abstraction/cairo-renderer.cpp b/dali/internal/text/text-abstraction/cairo-renderer.cpp index bf062ef..99d951d 100755 --- a/dali/internal/text/text-abstraction/cairo-renderer.cpp +++ b/dali/internal/text/text-abstraction/cairo-renderer.cpp @@ -234,6 +234,30 @@ Devel::PixelBuffer RenderTextCairo( const TextAbstraction::TextRenderer::Paramet return CreateVoidPixelBuffer( parameters ); } + // Choose the pixel format to be used. + // + // @note Behdad wrote "Upper 8 bits maps to the fourth byte in a little-endian machine like the intels." + // https://lists.cairographics.org/archives/cairo/2006-March/006563.html + // + // Here in practice Cairo's ARGB32 is like DALi's RGBA8888. + // + const bool isDstRgba = TextAbstraction::TextRenderer::Parameters::RGBA8888 == parameters.pixelFormat; + const Pixel::Format pixelFormat = isDstRgba ? Pixel::Format::RGBA8888 : Pixel::Format::A8; + const cairo_format_t cairoFormat = isDstRgba ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A8; + + const int bpp = Pixel::GetBytesPerPixel( pixelFormat ); + if( 0u == bpp ) + { + // return a pixel buffer with all pixels set to transparent. + return CreateVoidPixelBuffer( parameters ); + } + + // This function provides a stride value that will respect all alignment requirements of the + // accelerated image-rendering code within cairo. + const int stride = cairo_format_stride_for_width( cairoFormat, + static_cast( parameters.width ) ); + const int strideWidth = stride / bpp; + // Convert from DALi glyphs to Cairo glyphs. std::vector cairoGlyphs; cairoGlyphs.resize( numberOfGlyphs ); @@ -371,23 +395,6 @@ Devel::PixelBuffer RenderTextCairo( const TextAbstraction::TextRenderer::Paramet glyphRuns.push_back( currentGlyphRun ); } - // Choose the pixel format to be used. - // - // @note Behdad wrote "Upper 8 bits maps to the fourth byte in a little-endian machine like the intels." - // https://lists.cairographics.org/archives/cairo/2006-March/006563.html - // - // Here in practice Cairo's ARGB32 is like DALi's RGBA8888. - // - const bool isDstRgba = TextAbstraction::TextRenderer::Parameters::RGBA8888 == parameters.pixelFormat; - const Pixel::Format pixelFormat = isDstRgba ? Pixel::Format::RGBA8888 : Pixel::Format::A8; - const cairo_format_t cairoFormat = isDstRgba ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A8; - - // This function provides a stride value that will respect all alignment requirements of the - // accelerated image-rendering code within cairo. - const int stride = cairo_format_stride_for_width( cairoFormat, - static_cast( parameters.width ) ); - const int strideWidth = stride / Pixel::GetBytesPerPixel( pixelFormat ); - // Creates the pixel buffer and retrieves the buffer pointer used to create the Cairo's surface. Devel::PixelBuffer pixelBuffer = Devel::PixelBuffer::New( strideWidth, parameters.height, pixelFormat ); -- 2.7.4