prevent division by zero 82/209482/2
authorJoogab Yun <joogab.yun@samsung.com>
Mon, 8 Jul 2019 08:04:30 +0000 (17:04 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Wed, 10 Jul 2019 00:34:27 +0000 (09:34 +0900)
Change-Id: I97b97da610346f75c93e3fe0ee41831f1f2b8740

dali/internal/text/text-abstraction/cairo-renderer.cpp

index bf062ef..99d951d 100755 (executable)
@@ -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<int>( parameters.width ) );
+  const int strideWidth = stride / bpp;
+
   // Convert from DALi glyphs to Cairo glyphs.
   std::vector<cairo_glyph_t> 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<int>( 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 );