X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Ftext-typesetter.cpp;h=500a08179fb46362f0c1f9caaaada5775fb8be8d;hp=0e149d7af0bba8d1f739ffc2181fba3d0945e794;hb=a5167c61104580ae0ab724f904537a3a01ea3061;hpb=95faa4c96dcfcc76207eace1d6a00ba0aef714f0 diff --git a/dali-toolkit/internal/text/rendering/text-typesetter.cpp b/dali-toolkit/internal/text/rendering/text-typesetter.cpp old mode 100755 new mode 100644 index 0e149d7..500a081 --- a/dali-toolkit/internal/text/rendering/text-typesetter.cpp +++ b/dali-toolkit/internal/text/rendering/text-typesetter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -19,26 +19,28 @@ #include // EXTERNAL INCLUDES -#include #include #include +#include // INTERNAL INCLUDES -#include #include +#include +#include +#include +#include +#include namespace Dali { - namespace Toolkit { - namespace Text { - namespace { - +const float HALF(0.5f); +const float ONE_AND_A_HALF(1.5f); /** * @brief Data struct used to set the buffer of the glyph's bitmap into the final bitmap's buffer. */ @@ -62,125 +64,138 @@ struct GlyphData * @param[in] style The style of the text. * @param[in] pixelFormat The format of the pixel in the image that the text is rendered as (i.e. either Pixel::BGRA8888 or Pixel::L8). */ -void TypesetGlyph( GlyphData& data, - const Vector2* const position, - const Vector4* const color, - Typesetter::Style style, - Pixel::Format pixelFormat ) +void TypesetGlyph(GlyphData& data, + const Vector2* const position, + const Vector4* const color, + Typesetter::Style style, + Pixel::Format pixelFormat) { - if( ( 0u == data.glyphBitmap.width ) || ( 0u == data.glyphBitmap.height ) ) + if((0u == data.glyphBitmap.width) || (0u == data.glyphBitmap.height)) { // Nothing to do if the width or height of the buffer is zero. return; } - const int widthMinusOne = static_cast( data.width - 1u ); - const int heightMinusOne = static_cast( data.height - 1u ); + const int widthMinusOne = static_cast(data.width - 1u); + const int heightMinusOne = static_cast(data.height - 1u); - if ( Pixel::RGBA8888 == pixelFormat ) + if(Pixel::RGBA8888 == pixelFormat) { // Whether the given glyph is a color one. - const bool isColorGlyph = Pixel::BGRA8888 == data.glyphBitmap.format; + const bool isColorGlyph = data.glyphBitmap.isColorEmoji || data.glyphBitmap.isColorBitmap; + const uint32_t glyphPixelSize = Pixel::GetBytesPerPixel(data.glyphBitmap.format); + const uint32_t alphaIndex = glyphPixelSize - 1u; + const bool swapChannelsBR = Pixel::BGRA8888 == data.glyphBitmap.format; // Pointer to the color glyph if there is one. - const uint32_t* const colorGlyphBuffer = isColorGlyph ? reinterpret_cast( data.glyphBitmap.buffer ) : NULL; + const uint32_t* const colorGlyphBuffer = isColorGlyph ? reinterpret_cast(data.glyphBitmap.buffer) : NULL; // Initial vertical offset. const int yOffset = data.verticalOffset + position->y; + uint32_t* bitmapBuffer = reinterpret_cast(data.bitmapBuffer.GetBuffer()); + // Traverse the pixels of the glyph line per line. - for( int lineIndex = 0, glyphHeight = static_cast( data.glyphBitmap.height ); lineIndex < glyphHeight; ++lineIndex ) + for(int lineIndex = 0, glyphHeight = static_cast(data.glyphBitmap.height); lineIndex < glyphHeight; ++lineIndex) { const int yOffsetIndex = yOffset + lineIndex; - if( ( 0 > yOffsetIndex ) || ( yOffsetIndex > heightMinusOne ) ) + if((0 > yOffsetIndex) || (yOffsetIndex > heightMinusOne)) { // Do not write out of bounds. continue; } - const int verticalOffset = yOffsetIndex * data.width; - const int xOffset = data.horizontalOffset + position->x; - const int glyphBufferOffset = lineIndex * static_cast( data.glyphBitmap.width ); - for( int index = 0, glyphWidth = static_cast( data.glyphBitmap.width ); index < glyphWidth; ++index ) + const int verticalOffset = yOffsetIndex * data.width; + const int xOffset = data.horizontalOffset + position->x; + const int glyphBufferOffset = lineIndex * static_cast(data.glyphBitmap.width); + for(int index = 0, glyphWidth = static_cast(data.glyphBitmap.width); index < glyphWidth; ++index) { const int xOffsetIndex = xOffset + index; - if( ( 0 > xOffsetIndex ) || ( xOffsetIndex > widthMinusOne ) ) + if((0 > xOffsetIndex) || (xOffsetIndex > widthMinusOne)) { // Don't write out of bounds. continue; } - uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( data.bitmapBuffer.GetBuffer() ); - - if( isColorGlyph ) + if(isColorGlyph) { - // Retrieves the color from the color glyph. The format is BGRA8888. - uint32_t packedColorGlyph = *( colorGlyphBuffer + glyphBufferOffset + index ); - uint8_t* packedColorGlyphBuffer = reinterpret_cast( &packedColorGlyph ); + // Retrieves the color from the color glyph. + uint32_t packedColorGlyph = *(colorGlyphBuffer + glyphBufferOffset + index); + uint8_t* packedColorGlyphBuffer = reinterpret_cast(&packedColorGlyph); // Update the alpha channel. - if( Typesetter::STYLE_MASK == style || Typesetter::STYLE_OUTLINE == style ) // Outline not shown for color glyph + if(Typesetter::STYLE_MASK == style || Typesetter::STYLE_OUTLINE == style) // Outline not shown for color glyph { // Create an alpha mask for color glyph. - *( packedColorGlyphBuffer + 3u ) = 0u; - *( packedColorGlyphBuffer + 2u ) = 0u; - *( packedColorGlyphBuffer + 1u ) = 0u; - *packedColorGlyphBuffer = 0u; + *(packedColorGlyphBuffer + 3u) = 0u; + *(packedColorGlyphBuffer + 2u) = 0u; + *(packedColorGlyphBuffer + 1u) = 0u; + *packedColorGlyphBuffer = 0u; } else { - uint8_t colorAlpha = static_cast( color->a * static_cast( *( packedColorGlyphBuffer + 3u ) ) ); - *( packedColorGlyphBuffer + 3u ) = colorAlpha; + const uint8_t colorAlpha = static_cast(color->a * static_cast(*(packedColorGlyphBuffer + 3u))); + *(packedColorGlyphBuffer + 3u) = colorAlpha; - if( Typesetter::STYLE_SHADOW == style ) + if(Typesetter::STYLE_SHADOW == style) { // The shadow of color glyph needs to have the shadow color. - *( packedColorGlyphBuffer + 2u ) = static_cast( color->b * colorAlpha ); - *( packedColorGlyphBuffer + 1u ) = static_cast( color->g * colorAlpha ); - *packedColorGlyphBuffer = static_cast( color->r * colorAlpha ); + *(packedColorGlyphBuffer + 2u) = static_cast(color->b * colorAlpha); + *(packedColorGlyphBuffer + 1u) = static_cast(color->g * colorAlpha); + *packedColorGlyphBuffer = static_cast(color->r * colorAlpha); } else { - std::swap( *packedColorGlyphBuffer, *( packedColorGlyphBuffer + 2u ) ); // Swap B and R. - - *( packedColorGlyphBuffer + 2u ) = ( *( packedColorGlyphBuffer + 2u ) * colorAlpha / 255 ); - *( packedColorGlyphBuffer + 1u ) = ( *( packedColorGlyphBuffer + 1u ) * colorAlpha / 255 ); - *packedColorGlyphBuffer = ( *( packedColorGlyphBuffer ) * colorAlpha / 255 ); + if(swapChannelsBR) + { + std::swap(*packedColorGlyphBuffer, *(packedColorGlyphBuffer + 2u)); // Swap B and R. + } + + *(packedColorGlyphBuffer + 2u) = (*(packedColorGlyphBuffer + 2u) * colorAlpha / 255); + *(packedColorGlyphBuffer + 1u) = (*(packedColorGlyphBuffer + 1u) * colorAlpha / 255); + *packedColorGlyphBuffer = (*(packedColorGlyphBuffer)*colorAlpha / 255); + + if(data.glyphBitmap.isColorBitmap) + { + *(packedColorGlyphBuffer + 2u) = static_cast(*(packedColorGlyphBuffer + 2u) * color->b); + *(packedColorGlyphBuffer + 1u) = static_cast(*(packedColorGlyphBuffer + 1u) * color->g); + *packedColorGlyphBuffer = static_cast(*packedColorGlyphBuffer * color->r); + } } } // Set the color into the final pixel buffer. - *( bitmapBuffer + verticalOffset + xOffsetIndex ) = packedColorGlyph; + *(bitmapBuffer + verticalOffset + xOffsetIndex) = packedColorGlyph; } else { // Pack the given color into a 32bit buffer. The alpha channel will be updated later for each pixel. // The format is RGBA8888. - uint32_t packedColor = 0u; - uint8_t* packedColorBuffer = reinterpret_cast( &packedColor ); + uint32_t packedColor = 0u; + uint8_t* packedColorBuffer = reinterpret_cast(&packedColor); // Update the alpha channel. - const uint8_t alpha = *( data.glyphBitmap.buffer + glyphBufferOffset + index ); + const uint8_t alpha = *(data.glyphBitmap.buffer + glyphPixelSize * (glyphBufferOffset + index) + alphaIndex); // Copy non-transparent pixels only - if ( alpha > 0u ) + if(alpha > 0u) { // Check alpha of overlapped pixels - uint32_t& currentColor = *( bitmapBuffer + verticalOffset + xOffsetIndex ); - uint8_t* packedCurrentColorBuffer = reinterpret_cast( ¤tColor ); + uint32_t& currentColor = *(bitmapBuffer + verticalOffset + xOffsetIndex); + uint8_t* packedCurrentColorBuffer = reinterpret_cast(¤tColor); // 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). - uint8_t currentAlpha = *( packedCurrentColorBuffer + 3u ); - currentAlpha = std::max( currentAlpha, alpha ); + uint8_t currentAlpha = *(packedCurrentColorBuffer + 3u); + currentAlpha = std::max(currentAlpha, alpha); // Color is pre-muliplied with its alpha. - *( packedColorBuffer + 3u ) = static_cast( color->a * currentAlpha ); - *( packedColorBuffer + 2u ) = static_cast( color->b * currentAlpha ); - *( packedColorBuffer + 1u ) = static_cast( color->g * currentAlpha ); - *( packedColorBuffer ) = static_cast( color->r * currentAlpha ); + *(packedColorBuffer + 3u) = static_cast(color->a * currentAlpha); + *(packedColorBuffer + 2u) = static_cast(color->b * currentAlpha); + *(packedColorBuffer + 1u) = static_cast(color->g * currentAlpha); + *(packedColorBuffer) = static_cast(color->r * currentAlpha); // Set the color into the final pixel buffer. currentColor = packedColor; @@ -192,51 +207,53 @@ void TypesetGlyph( GlyphData& data, else { // Whether the given glyph is a color one. - const bool isColorGlyph = Pixel::BGRA8888 == data.glyphBitmap.format; + const bool isColorGlyph = data.glyphBitmap.isColorEmoji || data.glyphBitmap.isColorBitmap; + const uint32_t glyphPixelSize = Pixel::GetBytesPerPixel(data.glyphBitmap.format); + const uint32_t alphaIndex = glyphPixelSize - 1u; // Initial vertical offset. const int yOffset = data.verticalOffset + position->y; + uint8_t* bitmapBuffer = reinterpret_cast(data.bitmapBuffer.GetBuffer()); + // Traverse the pixels of the glyph line per line. - for( int lineIndex = 0, glyphHeight = static_cast( data.glyphBitmap.height ); lineIndex < glyphHeight; ++lineIndex ) + for(int lineIndex = 0, glyphHeight = static_cast(data.glyphBitmap.height); lineIndex < glyphHeight; ++lineIndex) { const int yOffsetIndex = yOffset + lineIndex; - if( ( 0 > yOffsetIndex ) || ( yOffsetIndex > heightMinusOne ) ) + if((0 > yOffsetIndex) || (yOffsetIndex > heightMinusOne)) { // Do not write out of bounds. continue; } - const int verticalOffset = yOffsetIndex * data.width; - const int xOffset = data.horizontalOffset + position->x; - const int glyphBufferOffset = lineIndex * static_cast( data.glyphBitmap.width ); - for( int index = 0, glyphWidth = static_cast( data.glyphBitmap.width ); index < glyphWidth; ++index ) + const int verticalOffset = yOffsetIndex * data.width; + const int xOffset = data.horizontalOffset + position->x; + const int glyphBufferOffset = lineIndex * static_cast(data.glyphBitmap.width); + for(int index = 0, glyphWidth = static_cast(data.glyphBitmap.width); index < glyphWidth; ++index) { const int xOffsetIndex = xOffset + index; - if( ( 0 > xOffsetIndex ) || ( xOffsetIndex > widthMinusOne ) ) + if((0 > xOffsetIndex) || (xOffsetIndex > widthMinusOne)) { // Don't write out of bounds. continue; } - uint8_t* bitmapBuffer = reinterpret_cast< uint8_t* >( data.bitmapBuffer.GetBuffer() ); - - if ( !isColorGlyph ) + if(!isColorGlyph) { // Update the alpha channel. - const uint8_t alpha = *( data.glyphBitmap.buffer + glyphBufferOffset + index ); + const uint8_t alpha = *(data.glyphBitmap.buffer + glyphPixelSize * (glyphBufferOffset + index) + alphaIndex); // Copy non-transparent pixels only - if ( alpha > 0u ) + if(alpha > 0u) { // Check alpha of overlapped pixels - uint8_t& currentAlpha = *( bitmapBuffer + verticalOffset + xOffsetIndex ); + uint8_t& currentAlpha = *(bitmapBuffer + verticalOffset + xOffsetIndex); // 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). - *( bitmapBuffer + verticalOffset + xOffsetIndex ) = std::max( currentAlpha, alpha ); + currentAlpha = std::max(currentAlpha, alpha); } } } @@ -244,30 +261,309 @@ void TypesetGlyph( GlyphData& data, } } -bool IsGlyphUnderlined( GlyphIndex index, - const Vector& underlineRuns ) +/// Draws the specified color to the pixel buffer +void WriteColorToPixelBuffer( + GlyphData& glyphData, + uint32_t* bitmapBuffer, + const Vector4& color, + const unsigned int x, + const unsigned int y) { - for( Vector::ConstIterator it = underlineRuns.Begin(), - endIt = underlineRuns.End(); - it != endIt; - ++it ) + // Always RGBA image for text with styles + uint32_t pixel = *(bitmapBuffer + y * glyphData.width + x); + uint8_t* pixelBuffer = reinterpret_cast(&pixel); + + // Write the color to the pixel buffer + uint8_t colorAlpha = static_cast(color.a * 255.f); + *(pixelBuffer + 3u) = colorAlpha; + *(pixelBuffer + 2u) = static_cast(color.b * colorAlpha); + *(pixelBuffer + 1u) = static_cast(color.g * colorAlpha); + *(pixelBuffer) = static_cast(color.r * colorAlpha); + + *(bitmapBuffer + y * glyphData.width + x) = pixel; +} + +/// Draws the specified underline color to the buffer +void DrawUnderline( + const unsigned int bufferWidth, + const unsigned int bufferHeight, + GlyphData& glyphData, + const float baseline, + const float currentUnderlinePosition, + const float maxUnderlineHeight, + const float lineExtentLeft, + const float lineExtentRight, + const UnderlineStyleProperties& commonUnderlineProperties, + const UnderlineStyleProperties& currentUnderlineProperties, + const LineRun& line) +{ + const Vector4& underlineColor = currentUnderlineProperties.colorDefined ? currentUnderlineProperties.color : commonUnderlineProperties.color; + const Text::Underline::Type underlineType = currentUnderlineProperties.typeDefined ? currentUnderlineProperties.type : commonUnderlineProperties.type; + const float dashedUnderlineWidth = currentUnderlineProperties.dashWidthDefined ? currentUnderlineProperties.dashWidth : commonUnderlineProperties.dashWidth; + const float dashedUnderlineGap = currentUnderlineProperties.dashGapDefined ? currentUnderlineProperties.dashGap : commonUnderlineProperties.dashGap; + + int underlineYOffset = glyphData.verticalOffset + baseline + currentUnderlinePosition; + uint32_t* bitmapBuffer = reinterpret_cast(glyphData.bitmapBuffer.GetBuffer()); + + for(unsigned int y = underlineYOffset; y < underlineYOffset + maxUnderlineHeight; y++) { - const GlyphRun& run = *it; + if(y > bufferHeight - 1) + { + // Do not write out of bounds. + break; + } + if(underlineType == Text::Underline::DASHED) + { + float dashWidth = dashedUnderlineWidth; + float dashGap = 0; - if( ( run.glyphIndex <= index ) && ( index < run.glyphIndex + run.numberOfGlyphs ) ) + for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++) + { + if(x > bufferWidth - 1) + { + // Do not write out of bounds. + break; + } + if(dashGap == 0 && dashWidth > 0) + { + WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y); + dashWidth--; + } + else if(dashGap < dashedUnderlineGap) + { + dashGap++; + } + else + { + //reset + dashWidth = dashedUnderlineWidth; + dashGap = 0; + } + } + } + else { - return true; + for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++) + { + if(x > bufferWidth - 1) + { + // Do not write out of bounds. + break; + } + WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y); + } } } + if(underlineType == Text::Underline::DOUBLE) + { + int secondUnderlineYOffset = underlineYOffset - ONE_AND_A_HALF * maxUnderlineHeight; + for(unsigned int y = secondUnderlineYOffset; y < secondUnderlineYOffset + maxUnderlineHeight; y++) + { + if(y > bufferHeight - 1) + { + // Do not write out of bounds. + break; + } + for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++) + { + if(x > bufferWidth - 1) + { + // Do not write out of bounds. + break; + } + WriteColorToPixelBuffer(glyphData, bitmapBuffer, underlineColor, x, y); + } + } + } +} - return false; +/// Draws the background color to the buffer +void DrawBackgroundColor( + Vector4 backgroundColor, + const unsigned int bufferWidth, + const unsigned int bufferHeight, + GlyphData& glyphData, + const float baseline, + const LineRun& line, + const float lineExtentLeft, + const float lineExtentRight) +{ + uint32_t* bitmapBuffer = reinterpret_cast(glyphData.bitmapBuffer.GetBuffer()); + + 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; + } + + WriteColorToPixelBuffer(glyphData, bitmapBuffer, backgroundColor, x, y); + } + } +} + +Devel::PixelBuffer DrawGlyphsBackground(const ViewModel* model, Devel::PixelBuffer& buffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, int horizontalOffset, int verticalOffset) +{ + // Retrieve lines, glyphs, positions and colors from the view model. + const Length modelNumberOfLines = model->GetNumberOfLines(); + const LineRun* const modelLinesBuffer = model->GetLines(); + const Length numberOfGlyphs = model->GetNumberOfGlyphs(); + const GlyphInfo* const glyphsBuffer = model->GetGlyphs(); + const Vector2* const positionBuffer = model->GetLayout(); + const Vector4* const backgroundColorsBuffer = model->GetBackgroundColors(); + const ColorIndex* const backgroundColorIndicesBuffer = model->GetBackgroundColorIndices(); + + // Create and initialize the pixel buffer. + GlyphData glyphData; + glyphData.verticalOffset = verticalOffset; + glyphData.width = bufferWidth; + glyphData.height = bufferHeight; + glyphData.bitmapBuffer = buffer; + glyphData.horizontalOffset = 0; + + ColorIndex prevBackgroundColorIndex = 0; + ColorIndex backgroundColorIndex = 0; + + // Traverses the lines of the text. + for(LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex) + { + const LineRun& line = *(modelLinesBuffer + lineIndex); + + // Sets the horizontal offset of the line. + glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast(line.alignmentOffset); + glyphData.horizontalOffset += horizontalOffset; + + // Increases the vertical offset with the line's ascender. + glyphData.verticalOffset += static_cast(line.ascender); + + // Include line spacing after first line + if(lineIndex > 0u) + { + glyphData.verticalOffset += static_cast(line.lineSpacing); + } + + float left = bufferWidth; + float right = 0.0f; + float baseline = 0.0f; + + // Traverses the glyphs of the line. + const GlyphIndex endGlyphIndex = std::min(numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs); + for(GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex) + { + // Retrieve the glyph's info. + const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex; + + if((glyphInfo->width < Math::MACHINE_EPSILON_1000) || + (glyphInfo->height < Math::MACHINE_EPSILON_1000)) + { + // Nothing to do if default background color, the glyph's width or height is zero. + continue; + } + + backgroundColorIndex = (nullptr == backgroundColorsBuffer) ? 0u : *(backgroundColorIndicesBuffer + glyphIndex); + + if((backgroundColorIndex != prevBackgroundColorIndex) && + (prevBackgroundColorIndex != 0u)) + { + const Vector4& backgroundColor = *(backgroundColorsBuffer + prevBackgroundColorIndex - 1u); + DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right); + } + + if(backgroundColorIndex == 0u) + { + prevBackgroundColorIndex = backgroundColorIndex; + //if background color is the default do nothing + continue; + } + + // Retrieves the glyph's position. + const Vector2* const position = positionBuffer + glyphIndex; + + if(baseline < position->y + glyphInfo->yBearing) + { + baseline = position->y + glyphInfo->yBearing; + } + + // Calculate the positions of leftmost and rightmost glyphs in the current line + if((position->x < left) || (backgroundColorIndex != prevBackgroundColorIndex)) + { + left = position->x - glyphInfo->xBearing; + } + + if(position->x + glyphInfo->width > right) + { + right = position->x - glyphInfo->xBearing + glyphInfo->advance; + } + + prevBackgroundColorIndex = backgroundColorIndex; + } + + //draw last background at line end if not default + if(backgroundColorIndex != 0u) + { + const Vector4& backgroundColor = *(backgroundColorsBuffer + backgroundColorIndex - 1u); + DrawBackgroundColor(backgroundColor, bufferWidth, bufferHeight, glyphData, baseline, line, left, right); + } + + // Increases the vertical offset with the line's descender. + glyphData.verticalOffset += static_cast(-line.descender); + } + + return glyphData.bitmapBuffer; +} + +/// Draws the specified strikethrough color to the buffer +void DrawStrikethrough(const unsigned int bufferWidth, + const unsigned int bufferHeight, + GlyphData& glyphData, + const float baseline, + const float strikethroughStartingYPosition, + const float maxStrikethroughHeight, + const float lineExtentLeft, + const float lineExtentRight, + const StrikethroughStyleProperties& commonStrikethroughProperties, + const StrikethroughStyleProperties& currentStrikethroughProperties, + const LineRun& line) +{ + const Vector4& strikethroughColor = currentStrikethroughProperties.colorDefined ? currentStrikethroughProperties.color : commonStrikethroughProperties.color; + + uint32_t* bitmapBuffer = reinterpret_cast(glyphData.bitmapBuffer.GetBuffer()); + + for(unsigned int y = strikethroughStartingYPosition; y < strikethroughStartingYPosition + maxStrikethroughHeight; y++) + { + if(y > bufferHeight - 1) + { + // Do not write out of bounds. + break; + } + + for(unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++) + { + if(x > bufferWidth - 1) + { + // Do not write out of bounds. + break; + } + + WriteColorToPixelBuffer(glyphData, bitmapBuffer, strikethroughColor, x, y); + } + } } } // namespace -TypesetterPtr Typesetter::New( const ModelInterface* const model ) +TypesetterPtr Typesetter::New(const ModelInterface* const model) { - return TypesetterPtr( new Typesetter( model ) ); + return TypesetterPtr(new Typesetter(model)); } ViewModel* Typesetter::GetViewModel() @@ -275,7 +571,25 @@ ViewModel* Typesetter::GetViewModel() return mModel; } -PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirection::Type textDirection, RenderBehaviour behaviour, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat ) +Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Pixel::Format pixelFormat) +{ + Devel::PixelBuffer imageBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat); + + if(Pixel::RGBA8888 == pixelFormat) + { + const unsigned int bufferSizeInt = bufferWidth * bufferHeight; + const unsigned int bufferSizeChar = 4u * bufferSizeInt; + memset(imageBuffer.GetBuffer(), 0u, bufferSizeChar); + } + else + { + memset(imageBuffer.GetBuffer(), 0, bufferWidth * bufferHeight); + } + + return imageBuffer; +} + +PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirection::Type textDirection, RenderBehaviour behaviour, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat) { // @todo. This initial implementation for a TextLabel has only one visible page. @@ -285,12 +599,12 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec // Retrieves the layout size. const Size& layoutSize = mModel->GetLayoutSize(); - const float outlineWidth = mModel->GetOutlineWidth(); + const int outlineWidth = static_cast(mModel->GetOutlineWidth()); // Set the offset for the horizontal alignment according to the text direction and outline width. int penX = 0; - switch( mModel->GetHorizontalAlignment() ) + switch(mModel->GetHorizontalAlignment()) { case HorizontalAlignment::BEGIN: { @@ -299,20 +613,20 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec } case HorizontalAlignment::CENTER: { - penX += ( textDirection == Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT ) ? -outlineWidth : outlineWidth; + penX += (textDirection == Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT) ? -outlineWidth : outlineWidth; break; } case HorizontalAlignment::END: { - penX += ( textDirection == Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT ) ? -outlineWidth * 2.0f : outlineWidth * 2.0f; + penX += (textDirection == Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT) ? -outlineWidth * 2 : outlineWidth * 2; break; } } // Set the offset for the vertical alignment. - int penY = 0; + int penY = 0u; - switch( mModel->GetVerticalAlignment() ) + switch(mModel->GetVerticalAlignment()) { case VerticalAlignment::TOP: { @@ -321,18 +635,19 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec } case VerticalAlignment::CENTER: { - penY = static_cast( 0.5f * ( size.height - layoutSize.height ) ); + penY = static_cast(0.5f * (size.height - layoutSize.height)); + penY = penY < 0.f ? 0.f : penY; break; } case VerticalAlignment::BOTTOM: { - penY = static_cast( size.height - layoutSize.height ); + penY = static_cast(size.height - layoutSize.height); break; } } // Calculate vertical line alignment - switch( mModel->GetVerticalLineAlignment() ) + switch(mModel->GetVerticalLineAlignment()) { case DevelText::VerticalLineAlignment::TOP: { @@ -342,13 +657,13 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec { const auto& line = *mModel->GetLines(); penY -= line.descender; - penY += static_cast(line.lineSpacing*0.5f + line.descender); + penY += static_cast(line.lineSpacing * 0.5f + line.descender); break; } case DevelText::VerticalLineAlignment::BOTTOM: { - const auto& line = *mModel->GetLines(); - const auto lineHeight = line.ascender + (-line.descender) + line.lineSpacing; + const auto& line = *mModel->GetLines(); + const auto lineHeight = line.ascender + (-line.descender) + line.lineSpacing; penY += static_cast(lineHeight - (line.ascender - line.descender)); break; } @@ -359,298 +674,392 @@ PixelData Typesetter::Render( const Vector2& size, Toolkit::DevelText::TextDirec // do all of these in CPU only, so that once the final texture is generated, // no calculation is needed in GPU during each frame. - const unsigned int bufferWidth = static_cast( size.width ); - const unsigned int bufferHeight = static_cast( size.height ); + const unsigned int bufferWidth = static_cast(size.width); + const unsigned int bufferHeight = static_cast(size.height); - const unsigned int bufferSizeInt = bufferWidth * bufferHeight; + const unsigned int bufferSizeInt = bufferWidth * bufferHeight; const unsigned int bufferSizeChar = 4u * bufferSizeInt; - Length numberOfGlyphs = mModel->GetNumberOfGlyphs(); + //Elided text in ellipsis at START could start on index greater than 0 + auto startIndexOfGlyphs = mModel->GetStartIndexOfElidedGlyphs(); + auto endIndexOfGlyphs = mModel->GetEndIndexOfElidedGlyphs(); Devel::PixelBuffer imageBuffer; - if( RENDER_MASK == behaviour ) + if(RENDER_MASK == behaviour) { // Generate the image buffer as an alpha mask for color glyphs. - imageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_MASK, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1 ); + imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_MASK, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); } - else if( RENDER_NO_TEXT == behaviour ) + else if(RENDER_NO_TEXT == behaviour || RENDER_OVERLAY_STYLE == behaviour) { // Generate an empty image buffer so that it can been combined with the image buffers for styles - imageBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, Pixel::RGBA8888 ); - memset( imageBuffer.GetBuffer(), 0u, bufferSizeChar ); + imageBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, Pixel::RGBA8888); + memset(imageBuffer.GetBuffer(), 0u, bufferSizeChar); } else { // Generate the image buffer for the text with no style. - imageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_NONE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs -1 ); + imageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_NONE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); } - if ( ( RENDER_NO_STYLES != behaviour ) && ( RENDER_MASK != behaviour ) ) + if((RENDER_NO_STYLES != behaviour) && (RENDER_MASK != behaviour)) { - // Generate the outline if enabled - const float outlineWidth = mModel->GetOutlineWidth(); - if ( outlineWidth > Math::MACHINE_EPSILON_1 ) + const uint16_t outlineWidth = mModel->GetOutlineWidth(); + if(outlineWidth != 0u && RENDER_OVERLAY_STYLE != behaviour) { // Create the image buffer for outline - Devel::PixelBuffer outlineImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_OUTLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs -1 ); + Devel::PixelBuffer outlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_OUTLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); // Combine the two buffers - imageBuffer = CombineImageBuffer( imageBuffer, outlineImageBuffer, bufferWidth, bufferHeight ); + imageBuffer = CombineImageBuffer(imageBuffer, outlineImageBuffer, bufferWidth, bufferHeight); } // @todo. Support shadow and underline for partial text later on. // Generate the shadow if enabled const Vector2& shadowOffset = mModel->GetShadowOffset(); - if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 ) + if(RENDER_OVERLAY_STYLE != behaviour && (fabsf(shadowOffset.x) > Math::MACHINE_EPSILON_1 || fabsf(shadowOffset.y) > Math::MACHINE_EPSILON_1)) { // Create the image buffer for shadow - Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1 ); + Devel::PixelBuffer shadowImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_SHADOW, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); // Check whether it will be a soft shadow const float& blurRadius = mModel->GetShadowBlurRadius(); - if ( blurRadius > Math::MACHINE_EPSILON_1 ) + if(blurRadius > Math::MACHINE_EPSILON_1) { - shadowImageBuffer.ApplyGaussianBlur( blurRadius ); + shadowImageBuffer.ApplyGaussianBlur(blurRadius); } // Combine the two buffers - imageBuffer = CombineImageBuffer( imageBuffer, shadowImageBuffer, bufferWidth, bufferHeight ); + imageBuffer = CombineImageBuffer(imageBuffer, shadowImageBuffer, bufferWidth, bufferHeight); } // Generate the underline if enabled const bool underlineEnabled = mModel->IsUnderlineEnabled(); - if ( underlineEnabled ) + if(underlineEnabled && RENDER_OVERLAY_STYLE == behaviour) { // Create the image buffer for underline - Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs - 1 ); + Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); // Combine the two buffers - imageBuffer = CombineImageBuffer( imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight ); + imageBuffer = CombineImageBuffer(imageBuffer, underlineImageBuffer, bufferWidth, bufferHeight); } // Generate the background if enabled - const bool backgroundEnabled = mModel->IsBackgroundEnabled(); - if ( backgroundEnabled ) + const bool backgroundEnabled = mModel->IsBackgroundEnabled(); + const bool backgroundMarkupSet = mModel->IsMarkupBackgroundColorSet(); + if((backgroundEnabled || backgroundMarkupSet) && RENDER_OVERLAY_STYLE != behaviour) { - Devel::PixelBuffer backgroundImageBuffer = CreateImageBuffer( bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, numberOfGlyphs -1 ); + Devel::PixelBuffer backgroundImageBuffer; + + if(backgroundEnabled) + { + backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_BACKGROUND, ignoreHorizontalAlignment, pixelFormat, penX, penY, startIndexOfGlyphs, endIndexOfGlyphs); + } + else + { + backgroundImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, pixelFormat); + } + + if(backgroundMarkupSet) + { + DrawGlyphsBackground(mModel, backgroundImageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, penX, penY); + } + + // Combine the two buffers + imageBuffer = CombineImageBuffer(imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight); + } + + // Generate the strikethrough if enabled + const bool strikethroughEnabled = mModel->IsStrikethroughEnabled(); + if(strikethroughEnabled && RENDER_OVERLAY_STYLE == behaviour) + { + // Create the image buffer for strikethrough + Devel::PixelBuffer strikethroughImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_STRIKETHROUGH, ignoreHorizontalAlignment, pixelFormat, penX, penY, 0u, endIndexOfGlyphs); // Combine the two buffers - imageBuffer = CombineImageBuffer( imageBuffer, backgroundImageBuffer, bufferWidth, bufferHeight ); + imageBuffer = CombineImageBuffer(imageBuffer, strikethroughImageBuffer, bufferWidth, bufferHeight); } + + // Markup-Processor + + imageBuffer = ApplyMarkupProcessorOnPixelBuffer(imageBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, penX, penY); } // Create the final PixelData for the combined image buffer - PixelData pixelData = Devel::PixelBuffer::Convert( imageBuffer ); + PixelData pixelData = Devel::PixelBuffer::Convert(imageBuffer); return pixelData; } -Devel::PixelBuffer Typesetter::CreateImageBuffer( const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset, GlyphIndex fromGlyphIndex, GlyphIndex toGlyphIndex ) +Devel::PixelBuffer Typesetter::CreateImageBuffer(const unsigned int bufferWidth, const unsigned int bufferHeight, Typesetter::Style style, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset, GlyphIndex fromGlyphIndex, GlyphIndex toGlyphIndex) { // Retrieve lines, glyphs, positions and colors from the view model. - const Length modelNumberOfLines = mModel->GetNumberOfLines(); - const LineRun* const modelLinesBuffer = mModel->GetLines(); - const Length numberOfGlyphs = mModel->GetNumberOfGlyphs(); - const GlyphInfo* const glyphsBuffer = mModel->GetGlyphs(); - const Vector2* const positionBuffer = mModel->GetLayout(); - const Vector4* const colorsBuffer = mModel->GetColors(); - const ColorIndex* const colorIndexBuffer = mModel->GetColorIndices(); + const Length modelNumberOfLines = mModel->GetNumberOfLines(); + const LineRun* const modelLinesBuffer = mModel->GetLines(); + const GlyphInfo* const glyphsBuffer = mModel->GetGlyphs(); + const Vector2* const positionBuffer = mModel->GetLayout(); + const Vector4* const colorsBuffer = mModel->GetColors(); + const ColorIndex* const colorIndexBuffer = mModel->GetColorIndices(); + const GlyphInfo* hyphens = mModel->GetHyphens(); + const Length* hyphenIndices = mModel->GetHyphenIndices(); + const Length hyphensCount = mModel->GetHyphensCount(); + + // Elided text info. Indices according to elided text and Ellipsis position. + const auto startIndexOfGlyphs = mModel->GetStartIndexOfElidedGlyphs(); + const auto endIndexOfGlyphs = mModel->GetEndIndexOfElidedGlyphs(); + const auto firstMiddleIndexOfElidedGlyphs = mModel->GetFirstMiddleIndexOfElidedGlyphs(); + const auto secondMiddleIndexOfElidedGlyphs = mModel->GetSecondMiddleIndexOfElidedGlyphs(); + const auto ellipsisPosition = mModel->GetEllipsisPosition(); // Whether to use the default color. - const bool useDefaultColor = ( NULL == colorsBuffer ); - const Vector4& defaultColor = mModel->GetDefaultColor(); + const bool useDefaultColor = (NULL == colorsBuffer); + const Vector4& defaultColor = mModel->GetDefaultColor(); // Create and initialize the pixel buffer. GlyphData glyphData; - glyphData.verticalOffset = verticalOffset; - glyphData.width = bufferWidth; - glyphData.height = bufferHeight; - glyphData.bitmapBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, pixelFormat ); + glyphData.verticalOffset = verticalOffset; + glyphData.width = bufferWidth; + glyphData.height = bufferHeight; + glyphData.bitmapBuffer = CreateImageBuffer(bufferWidth, bufferHeight, pixelFormat); glyphData.horizontalOffset = 0; - if ( Pixel::RGBA8888 == pixelFormat ) - { - const unsigned int bufferSizeInt = bufferWidth * bufferHeight; - const unsigned int bufferSizeChar = 4u * bufferSizeInt; - memset( glyphData.bitmapBuffer.GetBuffer(), 0u, bufferSizeChar ); - } - else - { - memset( glyphData.bitmapBuffer.GetBuffer(), 0, bufferWidth * bufferHeight ); - } - // Get a handle of the font client. Used to retrieve the bitmaps of the glyphs. - TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get(); + Length hyphenIndex = 0; + + const Character* textBuffer = mModel->GetTextBuffer(); + float calculatedAdvance = 0.f; + const Vector& glyphToCharacterMap = mModel->GetGlyphsToCharacters(); + const CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin(); // Traverses the lines of the text. - for( LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex ) + for(LineIndex lineIndex = 0u; lineIndex < modelNumberOfLines; ++lineIndex) { - const LineRun& line = *( modelLinesBuffer + lineIndex ); + const LineRun& line = *(modelLinesBuffer + lineIndex); // Sets the horizontal offset of the line. - glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast( line.alignmentOffset ); + glyphData.horizontalOffset = ignoreHorizontalAlignment ? 0 : static_cast(line.alignmentOffset); glyphData.horizontalOffset += horizontalOffset; // Increases the vertical offset with the line's ascender. - glyphData.verticalOffset += static_cast( line.ascender ); - - // Include line spacing after first line - if( lineIndex > 0u ) - { - glyphData.verticalOffset += static_cast( line.lineSpacing ); - } + glyphData.verticalOffset += static_cast(line.ascender); // Retrieves the glyph's outline width - float outlineWidth = mModel->GetOutlineWidth(); + float outlineWidth = static_cast(mModel->GetOutlineWidth()); - if( style == Typesetter::STYLE_OUTLINE ) + if(style == Typesetter::STYLE_OUTLINE) { glyphData.horizontalOffset -= outlineWidth; - if( lineIndex == 0u ) + if(lineIndex == 0u) { // Only need to add the vertical outline offset for the first line glyphData.verticalOffset -= outlineWidth; } } - else if ( style == Typesetter::STYLE_SHADOW ) + else if(style == Typesetter::STYLE_SHADOW) { const Vector2& shadowOffset = mModel->GetShadowOffset(); glyphData.horizontalOffset += shadowOffset.x - outlineWidth; // if outline enabled then shadow should offset from outline - if ( lineIndex == 0u ) + if(lineIndex == 0u) { // Only need to add the vertical shadow offset for first line glyphData.verticalOffset += shadowOffset.y - outlineWidth; } } - const bool underlineEnabled = mModel->IsUnderlineEnabled(); - const Vector4& underlineColor = mModel->GetUnderlineColor(); - const float underlineHeight = mModel->GetUnderlineHeight(); + const bool underlineEnabled = mModel->IsUnderlineEnabled(); + const bool strikethroughEnabled = mModel->IsStrikethroughEnabled(); + const float modelCharacterSpacing = mModel->GetCharacterSpacing(); + + // Get the character-spacing runs. + const Vector& characterSpacingGlyphRuns = mModel->GetCharacterSpacingGlyphRuns(); + + // Aggregate underline-style-properties from mModel + const UnderlineStyleProperties modelUnderlineProperties{mModel->GetUnderlineType(), + mModel->GetUnderlineColor(), + mModel->GetUnderlineHeight(), + mModel->GetDashedUnderlineGap(), + mModel->GetDashedUnderlineWidth(), + true, + true, + true, + true, + true}; + + // Aggregate strikethrough-style-properties from mModel + const StrikethroughStyleProperties modelStrikethroughProperties{mModel->GetStrikethroughColor(), + mModel->GetStrikethroughHeight(), + true, + true}; // Get the underline runs. - const Length numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns(); - Vector underlineRuns; - underlineRuns.Resize( numberOfUnderlineRuns ); - mModel->GetUnderlineRuns( underlineRuns.Begin(), 0u, numberOfUnderlineRuns ); + const Length numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns(); + Vector underlineRuns; + underlineRuns.Resize(numberOfUnderlineRuns); + mModel->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns); + + // Get the strikethrough runs. + const Length numberOfStrikethroughRuns = mModel->GetNumberOfStrikethroughRuns(); + Vector strikethroughRuns; + strikethroughRuns.Resize(numberOfStrikethroughRuns); + mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns); + + bool thereAreUnderlinedGlyphs = false; + bool thereAreStrikethroughGlyphs = false; - bool thereAreUnderlinedGlyphs = false; + float currentUnderlinePosition = 0.0f; + float currentUnderlineHeight = modelUnderlineProperties.height; + float maxUnderlineHeight = currentUnderlineHeight; + auto currentUnderlineProperties = modelUnderlineProperties; - float currentUnderlinePosition = 0.0f; - float currentUnderlineThickness = underlineHeight; - float maxUnderlineThickness = currentUnderlineThickness; + float currentStrikethroughHeight = modelStrikethroughProperties.height; + float maxStrikethroughHeight = currentStrikethroughHeight; + auto currentStrikethroughProperties = modelStrikethroughProperties; + float strikethroughStartingYPosition = 0.0f; - FontId lastUnderlinedFontId = 0; + FontId lastFontId = 0; - float lineExtentLeft = bufferWidth; + float lineExtentLeft = bufferWidth; float lineExtentRight = 0.0f; - float baseline = 0.0f; + float baseline = 0.0f; + bool addHyphen = false; // Traverses the glyphs of the line. - const GlyphIndex endGlyphIndex = std::min( numberOfGlyphs, line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs ); - for( GlyphIndex glyphIndex = line.glyphRun.glyphIndex; glyphIndex < endGlyphIndex; ++glyphIndex ) + const GlyphIndex startGlyphIndex = std::max(line.glyphRun.glyphIndex, startIndexOfGlyphs); + GlyphIndex endGlyphIndex = (line.isSplitToTwoHalves ? line.glyphRunSecondHalf.glyphIndex + line.glyphRunSecondHalf.numberOfGlyphs : line.glyphRun.glyphIndex + line.glyphRun.numberOfGlyphs) - 1u; + endGlyphIndex = std::min(endGlyphIndex, endIndexOfGlyphs); + + for(GlyphIndex glyphIndex = startGlyphIndex; glyphIndex <= endGlyphIndex; ++glyphIndex) { - if ( glyphIndex < fromGlyphIndex || glyphIndex > toGlyphIndex ) + if(glyphIndex < fromGlyphIndex || glyphIndex > toGlyphIndex) { // Ignore any glyph that out of the specified range continue; } + //To handle START case of ellipsis, the first glyph has been shifted + //glyphIndex represent indices in whole glyphs but elidedGlyphIndex represents indices in elided Glyphs + GlyphIndex elidedGlyphIndex = glyphIndex - startIndexOfGlyphs; + + //To handle MIDDLE case of ellipsis, the first glyph in the second half of line has been shifted and skip the removed glyph from middle. + if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE) + { + if(glyphIndex > firstMiddleIndexOfElidedGlyphs && + glyphIndex < secondMiddleIndexOfElidedGlyphs) + { + // Ignore any glyph that removed for MIDDLE ellipsis + continue; + } + if(glyphIndex >= secondMiddleIndexOfElidedGlyphs) + { + elidedGlyphIndex -= (secondMiddleIndexOfElidedGlyphs - firstMiddleIndexOfElidedGlyphs - 1u); + } + } + // Retrieve the glyph's info. - const GlyphInfo* const glyphInfo = glyphsBuffer + glyphIndex; + const GlyphInfo* glyphInfo; + + if(addHyphen && hyphens) + { + glyphInfo = hyphens + hyphenIndex; + hyphenIndex++; + } + else + { + glyphInfo = glyphsBuffer + elidedGlyphIndex; + } - if( ( glyphInfo->width < Math::MACHINE_EPSILON_1000 ) || - ( glyphInfo->height < Math::MACHINE_EPSILON_1000 ) ) + if((glyphInfo->width < Math::MACHINE_EPSILON_1000) || + (glyphInfo->height < Math::MACHINE_EPSILON_1000)) { // Nothing to do if the glyph's width or height is zero. continue; } - const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined( glyphIndex, underlineRuns ); - thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph; + Vector::ConstIterator currentUnderlinedGlyphRunIt = underlineRuns.End(); + const bool underlineGlyph = underlineEnabled || IsGlyphUnderlined(glyphIndex, underlineRuns, currentUnderlinedGlyphRunIt); + currentUnderlineProperties = GetCurrentUnderlineProperties(glyphIndex, underlineGlyph, underlineRuns, currentUnderlinedGlyphRunIt, modelUnderlineProperties); + currentUnderlineHeight = currentUnderlineProperties.height; + thereAreUnderlinedGlyphs = thereAreUnderlinedGlyphs || underlineGlyph; + + Vector::ConstIterator currentStrikethroughGlyphRunIt = strikethroughRuns.End(); + const bool strikethroughGlyph = strikethroughEnabled || IsGlyphStrikethrough(glyphIndex, strikethroughRuns, currentStrikethroughGlyphRunIt); + currentStrikethroughProperties = GetCurrentStrikethroughProperties(glyphIndex, strikethroughGlyph, strikethroughRuns, currentStrikethroughGlyphRunIt, modelStrikethroughProperties); + currentStrikethroughHeight = currentStrikethroughProperties.height; + thereAreStrikethroughGlyphs = thereAreStrikethroughGlyphs || strikethroughGlyph; // Are we still using the same fontId as previous - if( underlineGlyph && ( glyphInfo->fontId != lastUnderlinedFontId ) ) + if((glyphInfo->fontId != lastFontId) && (strikethroughGlyph || underlineGlyph)) { // We need to fetch fresh font underline metrics FontMetrics fontMetrics; - fontClient.GetFontMetrics( glyphInfo->fontId, fontMetrics ); - currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) ); - const float descender = ceil( fabsf( fontMetrics.descender ) ); - - if( fabsf( underlineHeight ) < Math::MACHINE_EPSILON_1000 ) - { - currentUnderlineThickness = fontMetrics.underlineThickness; - - // Ensure underline will be at least a pixel high - if ( currentUnderlineThickness < 1.0f ) - { - currentUnderlineThickness = 1.0f; - } - else - { - currentUnderlineThickness = ceil( currentUnderlineThickness ); - } - } + fontClient.GetFontMetrics(glyphInfo->fontId, fontMetrics); - // The underline thickness should be the max underline thickness of all glyphs of the line. - if ( currentUnderlineThickness > maxUnderlineThickness ) - { - maxUnderlineThickness = currentUnderlineThickness; - } + //The currentUnderlinePosition will be used for both Underline and/or Strikethrough + currentUnderlinePosition = FetchUnderlinePositionFromFontMetrics(fontMetrics); - // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font - if( currentUnderlinePosition > descender ) + if(underlineGlyph) { - currentUnderlinePosition = descender; + CalcualteUnderlineHeight(fontMetrics, currentUnderlineHeight, maxUnderlineHeight); } - if( fabsf( currentUnderlinePosition ) < Math::MACHINE_EPSILON_1000 ) + if(strikethroughGlyph) { - // Move offset down by one ( EFL behavior ) - currentUnderlinePosition = 1.0f; + CalcualteStrikethroughHeight(currentStrikethroughHeight, maxStrikethroughHeight); } - lastUnderlinedFontId = glyphInfo->fontId; - } // underline + // Update lastFontId because fontId is changed + lastFontId = glyphInfo->fontId; // Prevents searching for existing blocksizes when string of the same fontId. + } // Retrieves the glyph's position. - const Vector2* const position = positionBuffer + glyphIndex; - if ( baseline < position->y + glyphInfo->yBearing ) + Vector2 position = *(positionBuffer + elidedGlyphIndex); + + if(addHyphen) { - baseline = position->y + glyphInfo->yBearing; + GlyphInfo tempInfo = *(glyphsBuffer + elidedGlyphIndex); + const float characterSpacing = GetGlyphCharacterSpacing(glyphIndex, characterSpacingGlyphRuns, modelCharacterSpacing); + calculatedAdvance = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + elidedGlyphIndex))), characterSpacing, tempInfo.advance); + position.x = position.x + calculatedAdvance - tempInfo.xBearing + glyphInfo->xBearing; + position.y = -glyphInfo->yBearing; + } + + if(baseline < position.y + glyphInfo->yBearing) + { + baseline = position.y + glyphInfo->yBearing; } // Calculate the positions of leftmost and rightmost glyphs in the current line - if ( position->x < lineExtentLeft) + if(position.x < lineExtentLeft) { - lineExtentLeft = position->x; + lineExtentLeft = position.x; } - if ( position->x + glyphInfo->width > lineExtentRight) + if(position.x + glyphInfo->width > lineExtentRight) { - lineExtentRight = position->x + glyphInfo->width; + lineExtentRight = position.x + glyphInfo->width; } // Retrieves the glyph's color. - const ColorIndex colorIndex = *( colorIndexBuffer + glyphIndex ); + const ColorIndex colorIndex = useDefaultColor ? 0u : *(colorIndexBuffer + glyphIndex); Vector4 color; - if ( style == Typesetter::STYLE_SHADOW ) + if(style == Typesetter::STYLE_SHADOW) { color = mModel->GetShadowColor(); } - else if ( style == Typesetter::STYLE_OUTLINE ) + else if(style == Typesetter::STYLE_OUTLINE) { color = mModel->GetOutlineColor(); } else { - color = ( useDefaultColor || ( 0u == colorIndex ) ) ? defaultColor : *( colorsBuffer + ( colorIndex - 1u ) ); + color = (useDefaultColor || (0u == colorIndex)) ? defaultColor : *(colorsBuffer + (colorIndex - 1u)); } // Premultiply alpha @@ -660,186 +1069,236 @@ Devel::PixelBuffer Typesetter::CreateImageBuffer( const unsigned int bufferWidth // Retrieves the glyph's bitmap. glyphData.glyphBitmap.buffer = NULL; - glyphData.glyphBitmap.width = glyphInfo->width; // Desired width and height. + glyphData.glyphBitmap.width = glyphInfo->width; // Desired width and height. glyphData.glyphBitmap.height = glyphInfo->height; - if( style != Typesetter::STYLE_OUTLINE && style != Typesetter::STYLE_SHADOW ) + if(style != Typesetter::STYLE_OUTLINE && style != Typesetter::STYLE_SHADOW) { // Don't render outline for other styles outlineWidth = 0.0f; } - if( style != Typesetter::STYLE_UNDERLINE ) + + if(style != Typesetter::STYLE_UNDERLINE && style != Typesetter::STYLE_STRIKETHROUGH) { - fontClient.CreateBitmap( glyphInfo->fontId, - glyphInfo->index, - glyphInfo->softwareItalic, - glyphInfo->softwareBold, - glyphData.glyphBitmap, - outlineWidth ); + fontClient.CreateBitmap(glyphInfo->fontId, + glyphInfo->index, + glyphInfo->isItalicRequired, + glyphInfo->isBoldRequired, + glyphData.glyphBitmap, + static_cast(outlineWidth)); } - // Sets the glyph's bitmap into the bitmap of the whole text. - if( NULL != glyphData.glyphBitmap.buffer ) + if(NULL != glyphData.glyphBitmap.buffer) { - TypesetGlyph( glyphData, - position, - &color, - style, - pixelFormat); + if(style == Typesetter::STYLE_OUTLINE) + { + // Set the position offset for the current glyph + glyphData.horizontalOffset -= glyphData.glyphBitmap.outlineOffsetX; + glyphData.verticalOffset -= glyphData.glyphBitmap.outlineOffsetY; + } + + // Set the buffer of the glyph's bitmap into the final bitmap's buffer + TypesetGlyph(glyphData, + &position, + &color, + style, + pixelFormat); + + if(style == Typesetter::STYLE_OUTLINE) + { + // Reset the position offset for the next glyph + glyphData.horizontalOffset += glyphData.glyphBitmap.outlineOffsetX; + glyphData.verticalOffset += glyphData.glyphBitmap.outlineOffsetY; + } + // delete the glyphBitmap.buffer as it is now copied into glyphData.bitmapBuffer - delete []glyphData.glyphBitmap.buffer; + delete[] glyphData.glyphBitmap.buffer; glyphData.glyphBitmap.buffer = NULL; } - } - // Draw the underline from the leftmost glyph to the rightmost glyph - if ( thereAreUnderlinedGlyphs && style == Typesetter::STYLE_UNDERLINE ) - { - int underlineYOffset = glyphData.verticalOffset + baseline + currentUnderlinePosition; - - for( unsigned int y = underlineYOffset; y < underlineYOffset + maxUnderlineThickness; y++ ) + if(hyphenIndices) { - if( y > bufferHeight - 1 ) + while((hyphenIndex < hyphensCount) && (glyphIndex > hyphenIndices[hyphenIndex])) { - // Do not write out of bounds. - break; + hyphenIndex++; } - for( unsigned int x = glyphData.horizontalOffset + lineExtentLeft; x <= glyphData.horizontalOffset + lineExtentRight; x++ ) + addHyphen = ((hyphenIndex < hyphensCount) && ((glyphIndex + 1) == hyphenIndices[hyphenIndex])); + if(addHyphen) { - if( x > bufferWidth - 1 ) - { - // Do not write out of bounds. - break; - } - - // Always RGBA image for text with styles - uint32_t* bitmapBuffer = reinterpret_cast< uint32_t* >( glyphData.bitmapBuffer.GetBuffer() ); - uint32_t underlinePixel = *( bitmapBuffer + y * glyphData.width + x ); - uint8_t* underlinePixelBuffer = reinterpret_cast( &underlinePixel ); - - // Write the underline color to the pixel buffer - uint8_t colorAlpha = static_cast< uint8_t >( underlineColor.a * 255.f ); - *( underlinePixelBuffer + 3u ) = colorAlpha; - *( underlinePixelBuffer + 2u ) = static_cast< uint8_t >( underlineColor.b * colorAlpha ); - *( underlinePixelBuffer + 1u ) = static_cast< uint8_t >( underlineColor.g * colorAlpha ); - *( underlinePixelBuffer ) = static_cast< uint8_t >( underlineColor.r * colorAlpha ); - - *( bitmapBuffer + y * glyphData.width + x ) = underlinePixel; + glyphIndex--; } } } - // Draw the background color from the leftmost glyph to the rightmost glyph - if ( style == Typesetter::STYLE_BACKGROUND ) + // Draw the underline from the leftmost glyph to the rightmost glyph + if(thereAreUnderlinedGlyphs && style == Typesetter::STYLE_UNDERLINE) { - 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 ); + DrawUnderline(bufferWidth, bufferHeight, glyphData, baseline, currentUnderlinePosition, maxUnderlineHeight, lineExtentLeft, lineExtentRight, modelUnderlineProperties, currentUnderlineProperties, line); + } - // Write the background color to the pixel buffer - uint8_t colorAlpha = static_cast< uint8_t >( backgroundColor.a * 255.f ); - *( backgroundPixelBuffer + 3u ) = colorAlpha; - *( backgroundPixelBuffer + 2u ) = static_cast< uint8_t >( backgroundColor.b * colorAlpha ); - *( backgroundPixelBuffer + 1u ) = static_cast< uint8_t >( backgroundColor.g * colorAlpha ); - *( backgroundPixelBuffer ) = static_cast< uint8_t >( backgroundColor.r * colorAlpha ); + // Draw the background color from the leftmost glyph to the rightmost glyph + if(style == Typesetter::STYLE_BACKGROUND) + { + DrawBackgroundColor(mModel->GetBackgroundColor(), bufferWidth, bufferHeight, glyphData, baseline, line, lineExtentLeft, lineExtentRight); + } - *( bitmapBuffer + y * glyphData.width + x ) = backgroundPixel; - } - } + // Draw the strikethrough from the leftmost glyph to the rightmost glyph + if(thereAreStrikethroughGlyphs && style == Typesetter::STYLE_STRIKETHROUGH) + { + //TODO : The currently implemented strikethrough creates a strikethrough on the line level. We need to create different strikethroughs the case of glyphs with different sizes. + strikethroughStartingYPosition = (glyphData.verticalOffset + baseline + currentUnderlinePosition) - ((line.ascender) * HALF); // Since Free Type font doesn't contain the strikethrough-position property, strikethrough position will be calculated by moving the underline position upwards by half the value of the line height. + DrawStrikethrough(bufferWidth, bufferHeight, glyphData, baseline, strikethroughStartingYPosition, maxStrikethroughHeight, lineExtentLeft, lineExtentRight, modelStrikethroughProperties, currentStrikethroughProperties, line); } - // Increases the vertical offset with the line's descender. - glyphData.verticalOffset += static_cast( -line.descender ); + // Increases the vertical offset with the line's descender & line spacing. + glyphData.verticalOffset += static_cast(-line.descender+line.lineSpacing); } return glyphData.bitmapBuffer; } -Devel::PixelBuffer Typesetter::CombineImageBuffer( Devel::PixelBuffer topPixelBuffer, Devel::PixelBuffer bottomPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight ) +Devel::PixelBuffer Typesetter::CombineImageBuffer(Devel::PixelBuffer topPixelBuffer, Devel::PixelBuffer bottomPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight) { - unsigned char* topBuffer = topPixelBuffer.GetBuffer(); + unsigned char* topBuffer = topPixelBuffer.GetBuffer(); unsigned char* bottomBuffer = bottomPixelBuffer.GetBuffer(); Devel::PixelBuffer combinedPixelBuffer; - if ( topBuffer == NULL && bottomBuffer == NULL ) + if(topBuffer == NULL && bottomBuffer == NULL) { // Nothing to do if both buffers are empty. return combinedPixelBuffer; } - if ( topBuffer == NULL ) + if(topBuffer == NULL) { // Nothing to do if topBuffer is empty. return bottomPixelBuffer; } - if ( bottomBuffer == NULL ) + if(bottomBuffer == NULL) { // Nothing to do if bottomBuffer is empty. return topPixelBuffer; } // Always combine two RGBA images - const unsigned int bufferSizeInt = bufferWidth * bufferHeight; + const unsigned int bufferSizeInt = bufferWidth * bufferHeight; const unsigned int bufferSizeChar = 4u * bufferSizeInt; - combinedPixelBuffer = Devel::PixelBuffer::New( bufferWidth, bufferHeight, Pixel::RGBA8888 ); - uint8_t* combinedBuffer = reinterpret_cast< uint8_t* >( combinedPixelBuffer.GetBuffer() ); - memset( combinedBuffer, 0u, bufferSizeChar ); + combinedPixelBuffer = Devel::PixelBuffer::New(bufferWidth, bufferHeight, Pixel::RGBA8888); + uint8_t* combinedBuffer = reinterpret_cast(combinedPixelBuffer.GetBuffer()); + memset(combinedBuffer, 0u, bufferSizeChar); - for (unsigned int pixelIndex = 0; pixelIndex < bufferSizeInt; pixelIndex++) + for(unsigned int pixelIndex = 0; pixelIndex < bufferSizeInt; pixelIndex++) { // If the alpha of the pixel in either buffer is not fully opaque, blend the two pixels. // Otherwise, copy pixel from topBuffer to combinedBuffer. - unsigned int alphaBuffer1 = topBuffer[pixelIndex*4+3]; + unsigned int alphaBuffer1 = topBuffer[pixelIndex * 4 + 3]; - if ( alphaBuffer1 != 255 ) + if(alphaBuffer1 != 255) { // At least one pixel is not fully opaque // "Over" blend the the pixel from topBuffer with the pixel in bottomBuffer - combinedBuffer[pixelIndex*4] = topBuffer[pixelIndex*4] + ( bottomBuffer[pixelIndex*4] * ( 255 - topBuffer[pixelIndex*4+3] ) / 255 ); - combinedBuffer[pixelIndex*4+1] = topBuffer[pixelIndex*4+1] + ( bottomBuffer[pixelIndex*4+1] * ( 255 - topBuffer[pixelIndex*4+3] ) / 255 ); - combinedBuffer[pixelIndex*4+2] = topBuffer[pixelIndex*4+2] + ( bottomBuffer[pixelIndex*4+2] * ( 255 - topBuffer[pixelIndex*4+3] ) / 255 ); - combinedBuffer[pixelIndex*4+3] = topBuffer[pixelIndex*4+3] + ( bottomBuffer[pixelIndex*4+3] * ( 255 - topBuffer[pixelIndex*4+3] ) / 255 ); + combinedBuffer[pixelIndex * 4] = topBuffer[pixelIndex * 4] + (bottomBuffer[pixelIndex * 4] * (255 - topBuffer[pixelIndex * 4 + 3]) / 255); + combinedBuffer[pixelIndex * 4 + 1] = topBuffer[pixelIndex * 4 + 1] + (bottomBuffer[pixelIndex * 4 + 1] * (255 - topBuffer[pixelIndex * 4 + 3]) / 255); + combinedBuffer[pixelIndex * 4 + 2] = topBuffer[pixelIndex * 4 + 2] + (bottomBuffer[pixelIndex * 4 + 2] * (255 - topBuffer[pixelIndex * 4 + 3]) / 255); + combinedBuffer[pixelIndex * 4 + 3] = topBuffer[pixelIndex * 4 + 3] + (bottomBuffer[pixelIndex * 4 + 3] * (255 - topBuffer[pixelIndex * 4 + 3]) / 255); } else { // Copy the pixel from topBuffer to combinedBuffer - combinedBuffer[pixelIndex*4] = topBuffer[pixelIndex*4]; - combinedBuffer[pixelIndex*4+1] = topBuffer[pixelIndex*4+1]; - combinedBuffer[pixelIndex*4+2] = topBuffer[pixelIndex*4+2]; - combinedBuffer[pixelIndex*4+3] = topBuffer[pixelIndex*4+3]; + combinedBuffer[pixelIndex * 4] = topBuffer[pixelIndex * 4]; + combinedBuffer[pixelIndex * 4 + 1] = topBuffer[pixelIndex * 4 + 1]; + combinedBuffer[pixelIndex * 4 + 2] = topBuffer[pixelIndex * 4 + 2]; + combinedBuffer[pixelIndex * 4 + 3] = topBuffer[pixelIndex * 4 + 3]; } } return combinedPixelBuffer; } -Typesetter::Typesetter( const ModelInterface* const model ) -: mModel( new ViewModel( model ) ) +Devel::PixelBuffer Typesetter::ApplyUnderlineMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset) +{ + // Underline-tags (this is for Markup case) + // Get the underline runs. + const Length numberOfUnderlineRuns = mModel->GetNumberOfUnderlineRuns(); + Vector underlineRuns; + underlineRuns.Resize(numberOfUnderlineRuns); + mModel->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns); + + // Iterate on the consecutive underlined glyph run and connect them into one chunk of underlined characters. + Vector::ConstIterator itGlyphRun = underlineRuns.Begin(); + Vector::ConstIterator endItGlyphRun = underlineRuns.End(); + GlyphIndex startGlyphIndex, endGlyphIndex; + + //The outer loop to iterate on the separated chunks of underlined glyph runs + while(itGlyphRun != endItGlyphRun) + { + startGlyphIndex = itGlyphRun->glyphRun.glyphIndex; + endGlyphIndex = startGlyphIndex + itGlyphRun->glyphRun.numberOfGlyphs - 1; + + // Create the image buffer for underline + Devel::PixelBuffer underlineImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_UNDERLINE, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset, startGlyphIndex, endGlyphIndex); + // Combine the two buffers + topPixelBuffer = CombineImageBuffer(underlineImageBuffer, topPixelBuffer, bufferWidth, bufferHeight); + + itGlyphRun++; + } + + return topPixelBuffer; +} + +Devel::PixelBuffer Typesetter::ApplyStrikethroughMarkupImageBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset) +{ + // strikethrough-tags (this is for Markup case) + // Get the strikethrough runs. + const Length numberOfStrikethroughRuns = mModel->GetNumberOfStrikethroughRuns(); + Vector strikethroughRuns; + strikethroughRuns.Resize(numberOfStrikethroughRuns); + mModel->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns); + + // Iterate on the consecutive strikethrough glyph run and connect them into one chunk of strikethrough characters. + Vector::ConstIterator itGlyphRun = strikethroughRuns.Begin(); + Vector::ConstIterator endItGlyphRun = strikethroughRuns.End(); + GlyphIndex startGlyphIndex, endGlyphIndex; + + //The outer loop to iterate on the separated chunks of strikethrough glyph runs + while(itGlyphRun != endItGlyphRun) + { + startGlyphIndex = itGlyphRun->glyphRun.glyphIndex; + endGlyphIndex = startGlyphIndex + itGlyphRun->glyphRun.numberOfGlyphs - 1; + + // Create the image buffer for strikethrough + Devel::PixelBuffer strikethroughImageBuffer = CreateImageBuffer(bufferWidth, bufferHeight, Typesetter::STYLE_STRIKETHROUGH, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset, startGlyphIndex, endGlyphIndex); + // Combine the two buffers + topPixelBuffer = CombineImageBuffer(strikethroughImageBuffer, topPixelBuffer, bufferWidth, bufferHeight); + + itGlyphRun++; + } + + return topPixelBuffer; +} + +Devel::PixelBuffer Typesetter::ApplyMarkupProcessorOnPixelBuffer(Devel::PixelBuffer topPixelBuffer, const unsigned int bufferWidth, const unsigned int bufferHeight, bool ignoreHorizontalAlignment, Pixel::Format pixelFormat, int horizontalOffset, int verticalOffset) +{ + // Apply the markup-Processor if enabled + const bool markupProcessorEnabled = mModel->IsMarkupProcessorEnabled(); + if(markupProcessorEnabled) + { + topPixelBuffer = ApplyUnderlineMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset); + + topPixelBuffer = ApplyStrikethroughMarkupImageBuffer(topPixelBuffer, bufferWidth, bufferHeight, ignoreHorizontalAlignment, pixelFormat, horizontalOffset, verticalOffset); + } + + return topPixelBuffer; +} + +Typesetter::Typesetter(const ModelInterface* const model) +: mModel(new ViewModel(model)) { }