Merge "Fix for multi-language support." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / text-typesetter.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/font-client.h>
23 #include <memory.h>
24 #include <dali/public-api/common/constants.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/rendering/view-model.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Text
36 {
37
38 namespace
39 {
40
41 /**
42  * @brief Data struct used to set the buffer of the glyph's bitmap into the final bitmap's buffer.
43  */
44 struct GlyphData
45 {
46   Devel::PixelBuffer                           bitmapBuffer;     ///< The buffer of the whole bitmap. The format is RGBA8888.
47   Vector2*                                     position;         ///< The position of the glyph.
48   TextAbstraction::FontClient::GlyphBufferData glyphBitmap;      ///< The glyph's bitmap.
49   unsigned int                                 width;            ///< The bitmap's width.
50   unsigned int                                 height;           ///< The bitmap's height.
51   int                                          horizontalOffset; ///< The horizontal offset to be added to the 'x' glyph's position.
52   int                                          verticalOffset;   ///< The vertical offset to be added to the 'y' glyph's position.
53 };
54
55 /**
56  * @brief Sets the glyph's buffer into the bitmap's buffer.
57  *
58  * @param[in] data Struct which contains the glyph's data and the bitmap's data.
59  * @param[in] position The position of the glyph.
60  * @param[in] color The color of the glyph.
61  * @param[in] style The style of the text.
62  */
63 void TypesetGlyph( GlyphData& data,
64                    const Vector2* const position,
65                    const Vector4* const color,
66                    Typesetter::Style style)
67 {
68   if( ( 0u == data.glyphBitmap.width ) || ( 0u == data.glyphBitmap.height ) )
69   {
70     // Nothing to do if the width or height of the buffer is zero.
71     return;
72   }
73
74   const int widthMinusOne = static_cast<int>( data.width - 1u );
75   const int heightMinusOne = static_cast<int>( data.height - 1u );
76
77   // Whether the given glyph is a color one.
78   const bool isColorGlyph = Pixel::BGRA8888 == data.glyphBitmap.format;
79
80   // Pointer to the color glyph if there is one.
81   const uint32_t* const colorGlyphBuffer = isColorGlyph ? reinterpret_cast<uint32_t*>( data.glyphBitmap.buffer ) : NULL;
82
83   // Pack the given color into a 32bit buffer. The alpha channel will be updated later for each pixel.
84   // The format is RGBA8888.
85   uint32_t packedColor = 0u;
86   uint8_t* packedColorBuffer = reinterpret_cast<uint8_t*>( &packedColor );
87   *( packedColorBuffer + 2 ) = static_cast<uint8_t>( color->b * 255.f );
88   *( packedColorBuffer + 1 ) = static_cast<uint8_t>( color->g * 255.f );
89     *packedColorBuffer       = static_cast<uint8_t>( color->r * 255.f );
90
91   // Initial vertical offset.
92   const int yOffset = data.verticalOffset + position->y;
93
94   // Traverse the pixels of the glyph line per line.
95   for( int lineIndex = 0, glyphHeight = static_cast<int>( data.glyphBitmap.height ); lineIndex < glyphHeight; ++lineIndex )
96   {
97     const int yOffsetIndex = yOffset + lineIndex;
98     if( ( 0 > yOffsetIndex ) || ( yOffsetIndex > heightMinusOne ) )
99     {
100       // Do not write out of bounds.
101       break;
102     }
103
104     const int verticalOffset = yOffsetIndex * data.width;
105     const int xOffset = data.horizontalOffset + position->x;
106     const int glyphBufferOffset = lineIndex * static_cast<int>( data.glyphBitmap.width );
107     for( int index = 0, glyphWidth = static_cast<int>( data.glyphBitmap.width ); index < glyphWidth; ++index )
108     {
109       const int xOffsetIndex = xOffset + index;
110       if( ( 0 > xOffsetIndex ) || ( xOffsetIndex > widthMinusOne ) )
111       {
112         // Don't write out of bounds.
113         break;
114       }
115
116       uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( data.bitmapBuffer.GetBuffer() );
117
118       if( isColorGlyph )
119       {
120         // Retrieves the color from the color glyph. The format is BGRA8888.
121         uint32_t packedColorGlyph = *( colorGlyphBuffer + glyphBufferOffset + index );
122         uint8_t* packedColorGlyphBuffer = reinterpret_cast<uint8_t*>( &packedColorGlyph );
123
124         if( Typesetter::STYLE_SHADOW == style )
125         {
126           // The shadow of color glyph needs to have the shadow color.
127           *( packedColorGlyphBuffer + 2 ) = static_cast<uint8_t>( color->b * 255.f );
128           *( packedColorGlyphBuffer + 1 ) = static_cast<uint8_t>( color->g * 255.f );
129             *packedColorGlyphBuffer       = static_cast<uint8_t>( color->r * 255.f );
130         }
131         else
132         {
133           std::swap( *packedColorGlyphBuffer, *( packedColorGlyphBuffer + 2u ) ); // Swap B and R.
134         }
135
136         // Update the alpha channel.
137         if( Typesetter::STYLE_MASK == style )
138         {
139           // Create an alpha mask for color glyph.
140           *( packedColorGlyphBuffer + 3u ) = 0u;
141         }
142         else
143         {
144           *( packedColorGlyphBuffer + 3u ) = static_cast<uint8_t>( color->a * static_cast<float>( *( packedColorGlyphBuffer + 3u ) ) );
145         }
146
147         // Set the color into the final pixel buffer.
148         *( bitmapBuffer + verticalOffset + xOffsetIndex ) = packedColorGlyph;
149       }
150       else
151       {
152         // Update the alpha channel.
153         const uint8_t alpha = *( data.glyphBitmap.buffer + glyphBufferOffset + index );
154         *( packedColorBuffer + 3u ) = static_cast<uint8_t>( color->a * static_cast<float>( alpha ) );
155
156         // Set the color into the final pixel buffer.
157         *( bitmapBuffer + verticalOffset + xOffsetIndex ) = packedColor;
158       }
159     }
160   }
161 }
162
163 bool IsGlyphUnderlined( GlyphIndex index,
164                          const Vector<GlyphRun>& underlineRuns )
165 {
166   for( Vector<GlyphRun>::ConstIterator it = underlineRuns.Begin(),
167          endIt = underlineRuns.End();
168          it != endIt;
169        ++it )
170   {
171     const GlyphRun& run = *it;
172
173     if( ( run.glyphIndex <= index ) && ( index < run.glyphIndex + run.numberOfGlyphs ) )
174     {
175       return true;
176     }
177   }
178
179   return false;
180 }
181
182 } // namespace
183
184 TypesetterPtr Typesetter::New( const ModelInterface* const model )
185 {
186   return TypesetterPtr( new Typesetter( model ) );
187 }
188
189 ViewModel* Typesetter::GetViewModel()
190 {
191   return mModel;
192 }
193
194 PixelData Typesetter::Render( const Vector2& size, RenderBehaviour behaviour, bool ignoreHorizontalAlignment )
195 {
196   // @todo. This initial implementation for a TextLabel has only one visible page.
197
198   // Elides the text if needed.
199   mModel->ElideGlyphs();
200
201   // Retrieves the layout size.
202   const Size& layoutSize = mModel->GetLayoutSize();
203
204   // Set the offset for the vertical alignment.
205   int penY = 0u;
206
207   switch( mModel->GetVerticalAlignment() )
208   {
209     case Layout::VERTICAL_ALIGN_TOP:
210     {
211       // No offset to add.
212       break;
213     }
214     case Layout::VERTICAL_ALIGN_CENTER:
215     {
216       penY = static_cast<int>( 0.5f * ( size.height - layoutSize.height ) );
217       break;
218     }
219     case Layout::VERTICAL_ALIGN_BOTTOM:
220     {
221       penY = static_cast<int>( size.height - layoutSize.height );
222       break;
223     }
224   }
225
226   // Generate the image buffers of the text for each different style first,
227   // then combine all of them together as one final image buffer. We try to
228   // do all of these in CPU only, so that once the final texture is generated,
229   // no calculation is needed in GPU during each frame.
230
231   const unsigned int bufferWidth = static_cast<unsigned int>( size.width );
232   const unsigned int bufferHeight = static_cast<unsigned int>( size.height );
233
234   const unsigned int bufferSizeInt = bufferWidth * bufferHeight;
235   const unsigned int bufferSizeChar = 4u * bufferSizeInt;
236
237   Length numberOfGlyphs = mModel->GetNumberOfGlyphs();
238
239   Devel::PixelBuffer imageBuffer;
240
241   if( RENDER_MASK == behaviour )
242   {
243     // Generate the image buffer as an alpha mask for color glyphs.
244     imageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_MASK, ignoreHorizontalAlignment, penY, 0u, numberOfGlyphs - 1 );
245   }
246   else if( RENDER_NO_TEXT == behaviour )
247   {
248     // Generate an empty image buffer so that it can been combined with the image buffers for styles
249     imageBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, Pixel::RGBA8888 );
250     memset( imageBuffer.GetBuffer(), 0u, bufferSizeChar );
251   }
252   else
253   {
254     // Generate the image buffer for the text with no style.
255     imageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_NONE, ignoreHorizontalAlignment, penY, 0u, numberOfGlyphs -1 );
256   }
257
258   if ( ( RENDER_NO_STYLES != behaviour ) && ( RENDER_MASK != behaviour ) )
259   {
260     // @todo. Support shadow and underline for partial text later on.
261
262     // Generate the shadow if enabled
263     const Vector2& shadowOffset = mModel->GetShadowOffset();
264     if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
265     {
266       // Create the image buffer for shadow
267       Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, penY, 0u, numberOfGlyphs - 1 );
268
269       // Combine the two buffers
270       imageBuffer = CombineImageBuffer( imageBuffer, shadowImageBuffer, bufferWidth, bufferHeight );
271     }
272
273     // Generate the underline if enabled
274     const bool underlineEnabled = mModel->IsUnderlineEnabled();
275     if ( underlineEnabled )
276     {
277       // Create the image buffer for underline
278       Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, penY, 0u, numberOfGlyphs - 1 );
279
280       // Combine the two buffers
281       imageBuffer = CombineImageBuffer( imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight );
282     }
283   }
284
285   // Create the final PixelData for the combined image buffer
286   PixelData pixelData = Devel::PixelBuffer::Convert( imageBuffer );
287
288   return pixelData;
289 }
290
291 Devel::PixelBuffer Typesetter::CreateImageBuffer( const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, int verticalOffset, GlyphIndex fromGlyphIndex, GlyphIndex toGlyphIndex )
292 {
293   // Retrieve lines, glyphs, positions and colors from the view model.
294   const Length modelNumberOfLines = mModel->GetNumberOfLines();
295   const LineRun* const modelLinesBuffer = mModel->GetLines();
296   const Length numberOfGlyphs = mModel->GetNumberOfGlyphs();
297   const GlyphInfo* const glyphsBuffer = mModel->GetGlyphs();
298   const Vector2* const positionBuffer = mModel->GetLayout();
299   const Vector4* const colorsBuffer = mModel->GetColors();
300   const ColorIndex* const colorIndexBuffer = mModel->GetColorIndices();
301
302   // Whether to use the default color.
303   const bool useDefaultColor = ( NULL == colorsBuffer );
304   const Vector4& defaultColor = mModel->GetDefaultColor();
305
306   // Create and initialize the pixel buffer.
307   GlyphData glyphData;
308   glyphData.verticalOffset = verticalOffset;
309
310   glyphData.width = bufferWidth;
311   glyphData.height = bufferHeight;
312   const unsigned int bufferSizeInt = bufferWidth * bufferHeight;
313   const unsigned int bufferSizeChar = 4u * bufferSizeInt;
314   glyphData.bitmapBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, Pixel::RGBA8888 );
315   memset( glyphData.bitmapBuffer.GetBuffer(), 0u, bufferSizeChar );
316
317   // Get a handle of the font client. Used to retrieve the bitmaps of the glyphs.
318   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
319
320   // Traverses the lines of the text.
321   for( LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex )
322   {
323     const LineRun& line = *( modelLinesBuffer + lineIndex );
324
325     // Sets the horizontal offset of the line.
326     glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast<int>( line.alignmentOffset );
327
328     // Increases the vertical offset with the line's ascender.
329     glyphData.verticalOffset += static_cast<int>( line.ascender );
330
331     if ( style == Typesetter::STYLE_SHADOW )
332     {
333       const Vector2& shadowOffset = mModel->GetShadowOffset();
334       glyphData.horizontalOffset += shadowOffset.x;
335       if ( lineIndex == 0u )
336       {
337         // Only need to add the vertical shadow offset for once
338         glyphData.verticalOffset += shadowOffset.y;
339       }
340     }
341
342     const bool underlineEnabled = mModel->IsUnderlineEnabled();
343     const Vector4& underlineColor = mModel->GetUnderlineColor();
344     const float underlineHeight = mModel->GetUnderlineHeight();
345
346     // Get the underline runs.
347     const Length numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns();
348     Vector<GlyphRun> underlineRuns;
349     underlineRuns.Resize( numberOfUnderlineRuns );
350     mModel->GetUnderlineRuns( underlineRuns.Begin(), 0u, numberOfUnderlineRuns );
351
352     bool thereAreUnderlinedGlyphs = false;
353
354     float currentUnderlinePosition = 0.0f;
355     float currentUnderlineThickness = underlineHeight;
356     float maxUnderlineThickness = currentUnderlineThickness;
357
358     FontId lastUnderlinedFontId = 0;
359
360     float lineExtentLeft = bufferWidth;
361     float lineExtentRight = 0.0f;
362     float baseline = 0.0f;
363
364     // Traverses the glyphs of the line.
365     const GlyphIndex endGlyphIndex = std::min( numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs );
366     for( GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex )
367     {
368       if ( glyphIndex < fromGlyphIndex || glyphIndex > toGlyphIndex )
369       {
370         // Ignore any glyph that out of the specified range
371         continue;
372       }
373
374       // Retrieve the glyph's info.
375       const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex;
376
377       if( ( glyphInfo->width < Math::MACHINE_EPSILON_1000 ) ||
378           ( glyphInfo->height < Math::MACHINE_EPSILON_1000 ) )
379       {
380         // Nothing to do if the glyph's width or height is zero.
381         continue;
382       }
383
384       const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( glyphIndex, underlineRuns );
385       thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph;
386
387       // Are we still using the same fontId as previous
388       if( underlineGlyph && ( glyphInfo->fontId != lastUnderlinedFontId ) )
389       {
390         // We need to fetch fresh font underline metrics
391         FontMetrics fontMetrics;
392         fontClient.GetFontMetrics( glyphInfo->fontId, fontMetrics );
393         currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
394         const float descender = ceil( fabsf( fontMetrics.descender ) );
395
396         if( fabsf( underlineHeight ) < Math::MACHINE_EPSILON_1000 )
397         {
398           currentUnderlineThickness = fontMetrics.underlineThickness;
399
400           // Ensure underline will be at least a pixel high
401           if ( currentUnderlineThickness < 1.0f )
402           {
403             currentUnderlineThickness = 1.0f;
404           }
405           else
406           {
407             currentUnderlineThickness = ceil( currentUnderlineThickness );
408           }
409         }
410
411         // The underline thickness should be the max underline thickness of all glyphs of the line.
412         if ( currentUnderlineThickness > maxUnderlineThickness )
413         {
414           maxUnderlineThickness = currentUnderlineThickness;
415         }
416
417         // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
418         if( currentUnderlinePosition > descender )
419         {
420           currentUnderlinePosition = descender;
421         }
422
423         if( fabsf( currentUnderlinePosition ) < Math::MACHINE_EPSILON_1000 )
424         {
425           // Move offset down by one ( EFL behavior )
426           currentUnderlinePosition = 1.0f;
427         }
428
429         lastUnderlinedFontId = glyphInfo->fontId;
430       } // underline
431
432       // Retrieves the glyph's position.
433       const Vector2* const position = positionBuffer + glyphIndex;
434       if ( baseline < position->y + glyphInfo->yBearing )
435       {
436         baseline = position->y + glyphInfo->yBearing;
437       }
438
439       // Calculate the positions of leftmost and rightmost glyphs in the current line
440       if ( position->x < lineExtentLeft)
441       {
442         lineExtentLeft = position->x;
443       }
444
445       if ( position->x + glyphInfo->width > lineExtentRight)
446       {
447         lineExtentRight = position->x + glyphInfo->width;
448       }
449
450       // Retrieves the glyph's color.
451       const ColorIndex colorIndex = *( colorIndexBuffer + glyphIndex );
452
453       const Vector4* color;
454       if ( style == Typesetter::STYLE_SHADOW )
455       {
456         color = &( mModel->GetShadowColor() );
457       }
458       else
459       {
460         color = ( useDefaultColor || ( 0u == colorIndex ) ) ? &defaultColor : colorsBuffer + ( colorIndex - 1u );
461       }
462
463       // Retrieves the glyph's bitmap.
464       glyphData.glyphBitmap.buffer = NULL;
465       glyphData.glyphBitmap.width = glyphInfo->width;   // Desired width and height.
466       glyphData.glyphBitmap.height = glyphInfo->height;
467       fontClient.CreateBitmap( glyphInfo->fontId,
468                                glyphInfo->index,
469                                glyphData.glyphBitmap );
470
471       // Sets the glyph's bitmap into the bitmap of the whole text.
472       if( NULL != glyphData.glyphBitmap.buffer )
473       {
474         TypesetGlyph( glyphData,
475                       position,
476                       color,
477                       style );
478         // delete the glyphBitmap.buffer as it is now copied into glyphData.bitmapBuffer
479         delete []glyphData.glyphBitmap.buffer;
480         glyphData.glyphBitmap.buffer = NULL;
481       }
482     }
483
484     // Draw the underline from the leftmost glyph to the rightmost glyph
485     if ( thereAreUnderlinedGlyphs && style == Typesetter::STYLE_UNDERLINE )
486     {
487       int underlineYOffset = glyphData.verticalOffset + baseline + currentUnderlinePosition;
488
489       for( unsigned int y = underlineYOffset; y < underlineYOffset + maxUnderlineThickness; y++ )
490       {
491         if( ( y < 0 ) || ( y > bufferHeight - 1 ) )
492         {
493           // Do not write out of bounds.
494           break;
495         }
496
497         for( unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++ )
498         {
499           if( ( x < 0 ) || ( x > bufferWidth - 1 ) )
500           {
501             // Do not write out of bounds.
502             break;
503           }
504
505           uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( glyphData.bitmapBuffer.GetBuffer() );
506           uint32_t underlinePixel = *( bitmapBuffer + y * glyphData.width + x );
507           uint8_t* underlinePixelBuffer = reinterpret_cast<uint8_t*>( &underlinePixel );
508
509           // Write the underline color to the pixel buffer
510           *( underlinePixelBuffer ) = static_cast<uint8_t>( underlineColor.r * 255.f );
511           *( underlinePixelBuffer + 1u ) = static_cast<uint8_t>( underlineColor.g * 255.f );
512           *( underlinePixelBuffer + 2u ) = static_cast<uint8_t>( underlineColor.b * 255.f );
513           *( underlinePixelBuffer + 3u ) = static_cast<uint8_t>( underlineColor.a * 255.f );
514
515           *( bitmapBuffer + y * glyphData.width + x ) = underlinePixel;
516         }
517       }
518     }
519
520     // Increases the vertical offset with the line's descender.
521     glyphData.verticalOffset += static_cast<int>( -line.descender );
522   }
523
524   return glyphData.bitmapBuffer;
525 }
526
527 Devel::PixelBuffer Typesetter::CombineImageBuffer( Devel::PixelBuffer topPixelBuffer, Devel::PixelBuffer bottomPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight )
528 {
529   unsigned char* topBuffer = topPixelBuffer.GetBuffer();
530   unsigned char* bottomBuffer = bottomPixelBuffer.GetBuffer();
531
532   Devel::PixelBuffer combinedPixelBuffer;
533
534   if ( topBuffer == NULL && bottomBuffer == NULL )
535   {
536     // Nothing to do if both buffers are empty.
537     return combinedPixelBuffer;
538   }
539
540   if ( topBuffer == NULL )
541   {
542     // Nothing to do if topBuffer is empty.
543     return bottomPixelBuffer;
544   }
545
546   if ( bottomBuffer == NULL )
547   {
548     // Nothing to do if bottomBuffer is empty.
549     return topPixelBuffer;
550   }
551
552   const unsigned int bufferSizeInt = bufferWidth * bufferHeight;
553   const unsigned int bufferSizeChar = 4u * bufferSizeInt;
554
555   combinedPixelBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, Pixel::RGBA8888 );
556   uint8_t* combinedBuffer = reinterpret_cast< uint8_t* >( combinedPixelBuffer.GetBuffer() );
557   memset( combinedBuffer, 0u, bufferSizeChar );
558
559   for (unsigned int pixelIndex = 0; pixelIndex < bufferSizeInt; pixelIndex++)
560   {
561     // If the alpha of the pixel in either buffer is not fully opaque, blend the two pixels.
562     // Otherwise, copy pixel from topBuffer to combinedBuffer.
563
564     unsigned int alphaBuffer1 = topBuffer[pixelIndex*4+3];
565     unsigned int alphaBuffer2 = bottomBuffer[pixelIndex*4+3];
566
567     if ( alphaBuffer1 != 255 || alphaBuffer2 != 255 )
568     {
569       // At least one pixel is not fully opaque
570       // "Over" blend the the pixel from topBuffer with the pixel in bottomBuffer
571       combinedBuffer[pixelIndex*4] = ( topBuffer[pixelIndex*4] * topBuffer[pixelIndex*4+3] / 255 ) + ( bottomBuffer[pixelIndex*4] * bottomBuffer[pixelIndex*4+3] * ( 255 - topBuffer[pixelIndex*4+3] ) / ( 255*255 ) );
572       combinedBuffer[pixelIndex*4+1] = ( topBuffer[pixelIndex*4+1] * topBuffer[pixelIndex*4+3] / 255 ) + ( bottomBuffer[pixelIndex*4+1] * bottomBuffer[pixelIndex*4+3] * ( 255 - topBuffer[pixelIndex*4+3] ) / ( 255*255 ) );
573       combinedBuffer[pixelIndex*4+2] = ( topBuffer[pixelIndex*4+2] * topBuffer[pixelIndex*4+3] / 255 ) + ( bottomBuffer[pixelIndex*4+2] * bottomBuffer[pixelIndex*4+3] * ( 255 - topBuffer[pixelIndex*4+3] ) / ( 255*255 ) );
574       combinedBuffer[pixelIndex*4+3] = topBuffer[pixelIndex*4+3] + ( bottomBuffer[pixelIndex*4+3] * ( 255 - topBuffer[pixelIndex*4+3] ) / 255 );
575     }
576     else
577     {
578       // Copy the pixel from topBuffer to combinedBuffer
579       combinedBuffer[pixelIndex*4] = topBuffer[pixelIndex*4];
580       combinedBuffer[pixelIndex*4+1] = topBuffer[pixelIndex*4+1];
581       combinedBuffer[pixelIndex*4+2] = topBuffer[pixelIndex*4+2];
582       combinedBuffer[pixelIndex*4+3] = topBuffer[pixelIndex*4+3];
583     }
584   }
585
586   return combinedPixelBuffer;
587 }
588
589 Typesetter::Typesetter( const ModelInterface* const model )
590 : mModel( new ViewModel( model ) )
591 {
592 }
593
594 Typesetter::~Typesetter()
595 {
596   delete mModel;
597 }
598
599 } // namespace Text
600
601 } // namespace Toolkit
602
603 } // namespace Dali