/*
- * Copyright (c) 2021 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.
{
namespace
{
+const int CUSTOM_PROPERTY_COUNT(5); // anim,premul,size,offset,multicol
+
const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
/**
GetBackgroundProperties(mController, value, Text::EffectStyle::DEFAULT);
map.Insert(Toolkit::DevelTextVisual::Property::BACKGROUND, value);
+
+ GetStrikethroughProperties(mController, value, Text::EffectStyle::DEFAULT);
+ map.Insert(Toolkit::DevelTextVisual::Property::STRIKETHROUGH, value);
}
void TextVisual::DoCreateInstancePropertyMap(Property::Map& map) const
Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY);
Shader shader = GetTextShader(mFactoryCache, TextType::SINGLE_COLOR_TEXT, TextType::NO_EMOJI, TextType::NO_STYLES);
- mImpl->mRenderer = Renderer::New(geometry, shader);
+ mImpl->mRenderer = VisualRenderer::New(geometry, shader);
+ mImpl->mRenderer.ReserveCustomProperties(CUSTOM_PROPERTY_COUNT);
}
void TextVisual::DoSetProperties(const Property::Map& propertyMap)
const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor();
if(mTextColorAnimatableIndex == Property::INVALID_INDEX)
{
- mTextColorAnimatableIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor);
+ mTextColorAnimatableIndex = mImpl->mRenderer.RegisterUniqueProperty("uTextColorAnimatable", defaultColor);
}
else
{
// Make zero if the alpha value of text color is zero to skip rendering text
if(!mOpacityConstraint)
{
+ // VisualRenderer::Property::OPACITY uses same animatable property internally.
mOpacityConstraint = Constraint::New<float>(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint);
mOpacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex));
}
SetBackgroundProperties(mController, propertyValue, Text::EffectStyle::DEFAULT);
break;
}
+ case Toolkit::DevelTextVisual::Property::STRIKETHROUGH:
+ {
+ SetStrikethroughProperties(mController, propertyValue, Text::EffectStyle::DEFAULT);
+ break;
+ }
}
}
const bool outlineEnabled = (mController->GetTextModel()->GetOutlineWidth() > Math::MACHINE_EPSILON_1);
const bool backgroundEnabled = mController->GetTextModel()->IsBackgroundEnabled();
const bool markupProcessorEnabled = mController->IsMarkupProcessorEnabled();
+ const bool strikethroughEnabled = mController->GetTextModel()->IsStrikethroughEnabled();
- const bool styleEnabled = (shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled);
+ const bool styleEnabled = (shadowEnabled || underlineEnabled || outlineEnabled || backgroundEnabled || markupProcessorEnabled || strikethroughEnabled);
+ const bool isOverlayStyle = underlineEnabled || strikethroughEnabled;
- AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled);
+ AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);
// Text rendered and ready to display
ResourceReady(Toolkit::Visual::ResourceStatus::READY);
return pixelData;
}
-void TextVisual::CreateTextureSet(TilingInfo& info, Renderer& renderer, Sampler& sampler, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled)
+void TextVisual::CreateTextureSet(TilingInfo& info, VisualRenderer& renderer, Sampler& sampler, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle)
{
TextureSet textureSet = TextureSet::New();
unsigned int textureSetIndex = 0u;
// Convert the buffer to pixel data to make it a texture.
+
if(info.textBuffer)
{
PixelData data = ConvertToPixelData(info.textBuffer, info.width, info.height, info.offsetPosition, info.textPixelFormat);
++textureSetIndex;
}
+ if(styleEnabled && isOverlayStyle && info.styleBuffer)
+ {
+ PixelData overlayStyleData = ConvertToPixelData(info.styleBuffer, info.width, info.height, info.offsetPosition, Pixel::RGBA8888);
+ AddTexture(textureSet, overlayStyleData, sampler, textureSetIndex);
+ ++textureSetIndex;
+ }
+
if(containsColorGlyph && !hasMultipleTextColors && info.maskBuffer)
{
PixelData maskData = ConvertToPixelData(info.maskBuffer, info.width, info.height, info.offsetPosition, Pixel::L8);
renderer.SetTextures(textureSet);
//Register transform properties
- mImpl->mTransform.RegisterUniforms(renderer, Direction::LEFT_TO_RIGHT);
+ mImpl->mTransform.SetUniforms(renderer, Direction::LEFT_TO_RIGHT);
// Enable the pre-multiplied alpha to improve the text quality
renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
renderer.RegisterProperty(PREMULTIPLIED_ALPHA, 1.0f);
// Set size and offset for the tiling.
- renderer.RegisterProperty(SIZE, Vector2(info.width, info.height));
- renderer.RegisterProperty(OFFSET, Vector2(info.offSet.x, info.offSet.y));
- renderer.RegisterProperty("uHasMultipleTextColors", static_cast<float>(hasMultipleTextColors));
+ renderer.SetProperty(VisualRenderer::Property::TRANSFORM_SIZE, Vector2(info.width, info.height));
+ renderer.SetProperty(VisualRenderer::Property::TRANSFORM_OFFSET, Vector2(info.offSet.x, info.offSet.y));
renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+ renderer.RegisterProperty("uHasMultipleTextColors", static_cast<float>(hasMultipleTextColors));
mRendererList.push_back(renderer);
}
-void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled)
+void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle)
{
Shader shader = GetTextShader(mFactoryCache, hasMultipleTextColors, containsColorGlyph, styleEnabled);
mImpl->mRenderer.SetShader(shader);
// No tiling required. Use the default renderer.
if(size.height < maxTextureSize)
{
- TextureSet textureSet = GetTextTexture(size, hasMultipleTextColors, containsColorGlyph, styleEnabled);
+ TextureSet textureSet = GetTextTexture(size, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);
mImpl->mRenderer.SetTextures(textureSet);
//Register transform properties
- mImpl->mTransform.RegisterUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
+ mImpl->mTransform.SetUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
mImpl->mRenderer.RegisterProperty("uHasMultipleTextColors", static_cast<float>(hasMultipleTextColors));
mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
}
// Create a textureset in the default renderer.
- CreateTextureSet(info, mImpl->mRenderer, sampler, hasMultipleTextColors, containsColorGlyph, styleEnabled);
+ CreateTextureSet(info, mImpl->mRenderer, sampler, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);
verifiedHeight -= maxTextureSize;
// Create a renderer by cutting maxTextureSize.
while(verifiedHeight > 0)
{
- Renderer tilingRenderer = Renderer::New(geometry, shader);
+ VisualRenderer tilingRenderer = VisualRenderer::New(geometry, shader);
tilingRenderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, Toolkit::DepthIndex::CONTENT);
// New offset position of buffer for tiling.
info.offsetPosition += offsetPosition;
// New offset for tiling.
info.offSet.y += maxTextureSize;
// Create a textureset int the new tiling renderer.
- CreateTextureSet(info, tilingRenderer, sampler, hasMultipleTextColors, containsColorGlyph, styleEnabled);
+ CreateTextureSet(info, tilingRenderer, sampler, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);
verifiedHeight -= maxTextureSize;
}
}
}
-TextureSet TextVisual::GetTextTexture(const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled)
+TextureSet TextVisual::GetTextTexture(const Vector2& size, bool hasMultipleTextColors, bool containsColorGlyph, bool styleEnabled, bool isOverlayStyle)
{
// Filter mode needs to be set to linear to produce better quality while scaling.
Sampler sampler = Sampler::New();
// It may happen the image atlas can't handle a pixel data it exceeds the maximum size.
// In that case, create a texture. TODO: should tile the text.
unsigned int textureSetIndex = 0u;
-
AddTexture(textureSet, data, sampler, textureSetIndex);
++textureSetIndex;
if(styleEnabled)
{
- // Create RGBA texture for all the text styles (without the text itself)
+ // Create RGBA texture for all the text styles that render in the background (without the text itself)
PixelData styleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_NO_TEXT, false, Pixel::RGBA8888);
-
AddTexture(textureSet, styleData, sampler, textureSetIndex);
++textureSetIndex;
+ // Create RGBA texture for overlay styles such as underline and strikethrough (without the text itself)
+ PixelData overlayStyleData = mTypesetter->Render(size, textDirection, Text::Typesetter::RENDER_OVERLAY_STYLE, false, Pixel::RGBA8888);
+ AddTexture(textureSet, overlayStyleData, sampler, textureSetIndex);
+ ++textureSetIndex;
}
if(containsColorGlyph && !hasMultipleTextColors)