3 * Copyright (c) 2021 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>
28 Length GetNumberOfGlyphsOfGroup(GlyphIndex glyphIndex,
29 GlyphIndex lastGlyphPlusOne,
30 const Length* const charactersPerGlyphBuffer)
32 Length numberOfGLyphsInGroup = 1u;
34 for(GlyphIndex index = glyphIndex; index < lastGlyphPlusOne; ++index)
36 if(0u == *(charactersPerGlyphBuffer + index))
38 ++numberOfGLyphsInGroup;
46 return numberOfGLyphsInGroup;
49 void GetGlyphsMetrics(GlyphIndex glyphIndex,
50 Length numberOfGlyphs,
51 GlyphMetrics& glyphMetrics,
52 const GlyphInfo* const glyphsBuffer,
55 const GlyphInfo& firstGlyph = *(glyphsBuffer + glyphIndex);
57 Text::FontMetrics fontMetrics;
58 if(0u != firstGlyph.fontId)
60 metrics->GetFontMetrics(firstGlyph.fontId, fontMetrics);
62 else if(0u != firstGlyph.index)
64 // It may be an embedded image.
65 fontMetrics.ascender = firstGlyph.height;
66 fontMetrics.descender = 0.f;
67 fontMetrics.height = fontMetrics.ascender;
70 const bool isItalicFont = metrics->HasItalicStyle(firstGlyph.fontId);
72 glyphMetrics.fontId = firstGlyph.fontId;
73 glyphMetrics.fontHeight = fontMetrics.height;
74 glyphMetrics.width = firstGlyph.width;
75 glyphMetrics.advance = firstGlyph.advance;
76 glyphMetrics.ascender = fontMetrics.ascender;
77 glyphMetrics.xBearing = firstGlyph.xBearing;
79 if(1u < numberOfGlyphs)
81 float maxWidthEdge = firstGlyph.xBearing + firstGlyph.width;
83 for(unsigned int i = 1u; i < numberOfGlyphs; ++i)
85 const GlyphInfo& glyphInfo = *(glyphsBuffer + glyphIndex + i);
87 // update the initial xBearing if smaller.
88 glyphMetrics.xBearing = std::min(glyphMetrics.xBearing, glyphMetrics.advance + glyphInfo.xBearing);
90 // update the max width edge if bigger.
91 const float currentMaxGlyphWidthEdge = glyphMetrics.advance + glyphInfo.xBearing + glyphInfo.width;
92 maxWidthEdge = std::max(maxWidthEdge, currentMaxGlyphWidthEdge);
94 glyphMetrics.advance += glyphInfo.advance;
97 glyphMetrics.width = maxWidthEdge - glyphMetrics.xBearing;
100 glyphMetrics.width += (firstGlyph.isItalicRequired && !isItalicFont) ? TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * firstGlyph.height : 0.f;
105 } // namespace Toolkit