X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Frendering%2Fatlas%2Fatlas-mesh-factory.cpp;h=ac1c9bc1af0ac73991678d955b058f4717e97a7c;hp=4017f791e0b370b5c59f7689f9df5a2aa11c63c4;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=f3e45e41c5f16ccc2538b283897ed6efb07e4ea9 diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.cpp index 4017f79..ac1c9bc 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.cpp @@ -1,5 +1,5 @@ - /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. +/* + * Copyright (c) 2021 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,142 +19,138 @@ namespace Dali { - namespace Toolkit { - namespace Internal { - namespace AtlasMeshFactory { - -void CreateQuad( SizeType imageWidth, - SizeType imageHeight, - SizeType block, - const Toolkit::AtlasManager::AtlasSize& atlasSize, - const Vector2& position, - Toolkit::AtlasManager::Mesh2D& mesh ) +void CreateQuad(SizeType imageWidth, + SizeType imageHeight, + SizeType block, + const Toolkit::AtlasManager::AtlasSize& atlasSize, + const Vector2& position, + Toolkit::AtlasManager::Mesh2D& mesh) { Toolkit::AtlasManager::Vertex2D vertex; - SizeType blockWidth = atlasSize.mBlockWidth; + SizeType blockWidth = atlasSize.mBlockWidth; SizeType blockHeight = atlasSize.mBlockHeight; - float vertexBlockWidth = static_cast< float >( blockWidth ); - float vertexBlockHeight = static_cast< float >( blockHeight ); + float vertexBlockWidth = static_cast(blockWidth); + float vertexBlockHeight = static_cast(blockHeight); - SizeType atlasWidth = atlasSize.mWidth; + SizeType atlasWidth = atlasSize.mWidth; SizeType atlasHeight = atlasSize.mHeight; - SizeType atlasWidthInBlocks = ( atlasWidth - 1u ) / blockWidth; + SizeType atlasWidthInBlocks = (atlasWidth - 1u) / blockWidth; // Get the normalized size of a texel in both directions - float texelX = 1.0f / static_cast< float >( atlasWidth ); - float texelY = 1.0f / static_cast< float >( atlasHeight ); + float texelX = 1.0f / static_cast(atlasWidth); + float texelY = 1.0f / static_cast(atlasHeight); - float oneAndAHalfTexelX = texelX + ( texelX * 0.5f ); - float oneAndAHalfTexelY = texelY + ( texelY * 0.5f ); + float oneAndAHalfTexelX = texelX + (texelX * 0.5f); + float oneAndAHalfTexelY = texelY + (texelY * 0.5f); - float texelBlockWidth = texelX * vertexBlockWidth; + float texelBlockWidth = texelX * vertexBlockWidth; float texelBlockHeight = texelY * vertexBlockHeight; uint32_t pixelsX = imageWidth % blockWidth; uint32_t pixelsY = imageHeight % blockHeight; - if ( !pixelsX ) + if(!pixelsX) { pixelsX = blockWidth; } - if ( !pixelsY ) + if(!pixelsY) { pixelsY = blockHeight; } - float vertexWidth = static_cast< float >( pixelsX ); - float vertexHeight = static_cast< float >( pixelsY ); - float texelWidth = texelX * vertexWidth; - float texelHeight = texelY * vertexHeight; + float vertexWidth = static_cast(pixelsX); + float vertexHeight = static_cast(pixelsY); + float texelWidth = texelX * vertexWidth; + float texelHeight = texelY * vertexHeight; // We're going to 'blit' half a pixel more on each edge vertexWidth++; vertexHeight++; // Move back half a pixel - Vector2 topLeft = Vector2( position.x - 0.5f, position.y - 0.5f ); + Vector2 topLeft = Vector2(position.x - 0.5f, position.y - 0.5f); - float fBlockX = texelBlockWidth * static_cast< float >( block % atlasWidthInBlocks ); + float fBlockX = texelBlockWidth * static_cast(block % atlasWidthInBlocks); // In the next expression, we have purposely made ( block / atlasWidthInBlocks ) yield an integer value and then convert to float as // we do not want the remainder in that expression to affect the value of fBlockY - float fBlockY = texelBlockHeight * static_cast< float >( block / atlasWidthInBlocks ); + float fBlockY = texelBlockHeight * static_cast(block / atlasWidthInBlocks); // Add on texture filtering compensation ( half a texel plus compensation for filled pixel in top left corner ) fBlockX += oneAndAHalfTexelX; fBlockY += oneAndAHalfTexelY; - float texelWidthOffset = texelWidth + texelX; + float texelWidthOffset = texelWidth + texelX; float texelHeightOffset = texelHeight + texelY; // Top left - vertex.mPosition.x = topLeft.x; - vertex.mPosition.y = topLeft.y; + vertex.mPosition.x = topLeft.x; + vertex.mPosition.y = topLeft.y; vertex.mTexCoords.x = fBlockX; vertex.mTexCoords.y = fBlockY; - mesh.mVertices.Reserve( 4u ); - mesh.mVertices.PushBack( vertex ); + mesh.mVertices.Reserve(4u); + mesh.mVertices.PushBack(vertex); // Top Right - vertex.mPosition.x = topLeft.x + vertexWidth; - vertex.mPosition.y = topLeft.y; + vertex.mPosition.x = topLeft.x + vertexWidth; + vertex.mPosition.y = topLeft.y; vertex.mTexCoords.x = fBlockX + texelWidthOffset; vertex.mTexCoords.y = fBlockY; - mesh.mVertices.PushBack( vertex ); + mesh.mVertices.PushBack(vertex); // Bottom Left - vertex.mPosition.x = topLeft.x; - vertex.mPosition.y = topLeft.y + vertexHeight; + vertex.mPosition.x = topLeft.x; + vertex.mPosition.y = topLeft.y + vertexHeight; vertex.mTexCoords.x = fBlockX; vertex.mTexCoords.y = fBlockY + texelHeightOffset; - mesh.mVertices.PushBack( vertex ); + mesh.mVertices.PushBack(vertex); // Bottom Right - vertex.mPosition.x = topLeft.x + vertexWidth; - vertex.mPosition.y = topLeft.y + vertexHeight; + vertex.mPosition.x = topLeft.x + vertexWidth; + vertex.mPosition.y = topLeft.y + vertexHeight; vertex.mTexCoords.x = fBlockX + texelWidthOffset; vertex.mTexCoords.y = fBlockY + texelHeightOffset; - mesh.mVertices.PushBack( vertex ); + mesh.mVertices.PushBack(vertex); // Six indices in counter clockwise winding - mesh.mIndices.Reserve( 6u ); - mesh.mIndices.PushBack( 1u ); - mesh.mIndices.PushBack( 0u ); - mesh.mIndices.PushBack( 2u ); - mesh.mIndices.PushBack( 2u ); - mesh.mIndices.PushBack( 3u ); - mesh.mIndices.PushBack( 1u ); + mesh.mIndices.Reserve(6u); + mesh.mIndices.PushBack(1u); + mesh.mIndices.PushBack(0u); + mesh.mIndices.PushBack(2u); + mesh.mIndices.PushBack(2u); + mesh.mIndices.PushBack(3u); + mesh.mIndices.PushBack(1u); } -void AppendMesh( Toolkit::AtlasManager::Mesh2D& first, - const Toolkit::AtlasManager::Mesh2D& second ) +void AppendMesh(Toolkit::AtlasManager::Mesh2D& first, + const Toolkit::AtlasManager::Mesh2D& second) { const uint32_t verticesCount = first.mVertices.Size(); - first.mVertices.Insert( first.mVertices.End(), - second.mVertices.Begin(), - second.mVertices.End() ); + first.mVertices.Insert(first.mVertices.End(), + second.mVertices.Begin(), + second.mVertices.End()); const uint32_t indicesCount = first.mIndices.Size(); - first.mIndices.Insert( first.mIndices.End(), - second.mIndices.Begin(), - second.mIndices.End() ); - - for( Vector::Iterator it = first.mIndices.Begin() + indicesCount, - endIt = first.mIndices.End(); - it != endIt; - ++it ) + first.mIndices.Insert(first.mIndices.End(), + second.mIndices.Begin(), + second.mIndices.End()); + + for(Vector::Iterator it = first.mIndices.Begin() + indicesCount, + endIt = first.mIndices.End(); + it != endIt; + ++it) { *it += verticesCount; }