3 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
31 Length GetNumberOfGlyphsOfGroup( GlyphIndex glyphIndex,
32 GlyphIndex lastGlyphPlusOne,
33 const Length* const charactersPerGlyphBuffer )
35 Length numberOfGLyphsInGroup = 1u;
37 for( GlyphIndex index = glyphIndex; index < lastGlyphPlusOne; ++index )
39 if( 0u == *( charactersPerGlyphBuffer + index ) )
41 ++numberOfGLyphsInGroup;
49 return numberOfGLyphsInGroup;
52 void GetGlyphsMetrics( GlyphIndex glyphIndex,
53 Length numberOfGlyphs,
54 GlyphMetrics& glyphMetrics,
55 const GlyphInfo* const glyphsBuffer,
58 const GlyphInfo& firstGlyph = *( glyphsBuffer + glyphIndex );
60 Text::FontMetrics fontMetrics;
61 if( 0u != firstGlyph.fontId )
63 metrics->GetFontMetrics( firstGlyph.fontId, fontMetrics );
65 else if( 0u != firstGlyph.index )
67 // It may be an embedded image.
68 fontMetrics.ascender = firstGlyph.height;
69 fontMetrics.descender = 0.f;
70 fontMetrics.height = fontMetrics.ascender;
73 const bool isItalicFont = metrics->HasItalicStyle( firstGlyph.fontId );
75 glyphMetrics.fontId = firstGlyph.fontId;
76 glyphMetrics.fontHeight = fontMetrics.height;
77 glyphMetrics.width = firstGlyph.width + ( ( firstGlyph.isItalicRequired && !isItalicFont ) ? static_cast<unsigned int>( TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * static_cast<float>( firstGlyph.height ) ) : 0u );
78 glyphMetrics.advance = firstGlyph.advance;
79 glyphMetrics.ascender = fontMetrics.ascender;
80 glyphMetrics.xBearing = firstGlyph.xBearing;
82 if( 1u < numberOfGlyphs )
84 const float widthInit = firstGlyph.xBearing;
86 for( unsigned int i = 1u; i < numberOfGlyphs; ++i )
88 const GlyphInfo& glyphInfo = *( glyphsBuffer + glyphIndex + i );
90 glyphMetrics.width = glyphMetrics.advance + glyphInfo.xBearing + glyphInfo.width + ( ( firstGlyph.isItalicRequired && !isItalicFont ) ? static_cast<unsigned int>( TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * static_cast<float>( firstGlyph.height ) ) : 0u );
91 glyphMetrics.advance += glyphInfo.advance;
95 glyphMetrics.width -= widthInit;
101 } // namespace Toolkit