Fix issues while rendering RTL text in Text Visual 38/146238/4
authorRichard Huang <r.huang@samsung.com>
Fri, 25 Aug 2017 10:35:26 +0000 (11:35 +0100)
committerRichard Huang <r.huang@samsung.com>
Fri, 25 Aug 2017 13:11:23 +0000 (14:11 +0100)
This patch fixes two issue:

1. Overlapped glyph is cut.
2. Small gap between joint glyphs.

The solution is:

1. When we copy glyphs to the big image buffer, we should only copy
   non-transparent pixels, and this will prevent overlapped glyphs
   from being cut.

2. For any pixel overlapped with the pixel in previous glyphs,
   make sure we don't overwrite a previous bigger alpha with a smaller
   alpha, so that we can avoid semi-transparent gaps between joint
   glyphs with overlapped pixels, which could happen e.g. in the RTL
   text when we copy glyphs from right to left.

Change-Id: Id4d9d028999612e0545aa47b5bf66e410fc7ee91

dali-toolkit/internal/text/rendering/text-typesetter.cpp

index 11cde00..1821db4 100644 (file)
@@ -151,10 +151,26 @@ void TypesetGlyph( GlyphData& data,
       {
         // Update the alpha channel.
         const uint8_t alpha = *( data.glyphBitmap.buffer + glyphBufferOffset + index );
-        *( packedColorBuffer + 3u ) = static_cast<uint8_t>( color->a * static_cast<float>( alpha ) );
 
-        // Set the color into the final pixel buffer.
-        *( bitmapBuffer + verticalOffset + xOffsetIndex ) = packedColor;
+        // Copy non-transparent pixels only
+        if ( alpha > 0u )
+        {
+          // Check alpha of overlapped pixels
+          uint32_t& currentColor = *( bitmapBuffer + verticalOffset + xOffsetIndex );
+          uint8_t* packedCurrentColorBuffer = reinterpret_cast<uint8_t*>( &currentColor );
+
+          uint8_t currentAlpha = *( packedCurrentColorBuffer + 3u );
+          uint8_t newAlpha = static_cast<uint8_t>( color->a * static_cast<float>( alpha ) );
+
+          // For any pixel overlapped with the pixel in previous glyphs, make sure we don't
+          // overwrite a previous bigger alpha with a smaller alpha (in order to avoid
+          // semi-transparent gaps between joint glyphs with overlapped pixels, which could
+          // happen, for example, in the RTL text when we copy glyphs from right to left).
+          *( packedColorBuffer + 3u ) = std::max( currentAlpha, newAlpha );
+
+          // Set the color into the final pixel buffer.
+          currentColor = packedColor;
+        }
       }
     }
   }