2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/rendering/styles/underline-helper-functions.h>
27 bool IsGlyphUnderlined(GlyphIndex index,
28 const Vector<UnderlinedGlyphRun>& underlineRuns,
29 Vector<UnderlinedGlyphRun>::ConstIterator& currentUnderlinedGlyphRunIt)
31 for(Vector<UnderlinedGlyphRun>::ConstIterator it = underlineRuns.Begin(),
32 endIt = underlineRuns.End();
36 const UnderlinedGlyphRun& run = *it;
38 if((run.glyphRun.glyphIndex <= index) && (index < run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs))
40 currentUnderlinedGlyphRunIt = it;
48 float GetCurrentUnderlineHeight(const Vector<UnderlinedGlyphRun>& underlineRuns,
49 Vector<UnderlinedGlyphRun>::ConstIterator currentUnderlinedGlyphRunIt,
50 const float underlineHeight)
52 if(currentUnderlinedGlyphRunIt == underlineRuns.End())
54 return underlineHeight;
57 const UnderlinedGlyphRun& underlinedGlyphRun = *currentUnderlinedGlyphRunIt;
58 return (underlinedGlyphRun.properties.heightDefined ? underlinedGlyphRun.properties.height : underlineHeight);
61 UnderlineStyleProperties GetCurrentUnderlineProperties(const bool& isGlyphUnderlined,
62 const Vector<UnderlinedGlyphRun>& underlineRuns,
63 Vector<UnderlinedGlyphRun>::ConstIterator currentUnderlinedGlyphRunIt,
64 const UnderlineStyleProperties& commonUnderlineProperties)
66 return (isGlyphUnderlined && (currentUnderlinedGlyphRunIt != underlineRuns.End()))
67 ? currentUnderlinedGlyphRunIt->properties
68 : commonUnderlineProperties;
71 float FetchUnderlinePositionFromFontMetrics(const FontMetrics& fontMetrics)
73 //Helper method to fetch the underline metrics for the specified font glyph
74 const float descender = ceil(fabsf(fontMetrics.descender));
75 float underlinePosition = ceil(fabsf(fontMetrics.underlinePosition));
77 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
78 if(underlinePosition > descender)
80 underlinePosition = descender;
83 if(fabsf(underlinePosition) < Math::MACHINE_EPSILON_1000)
85 // Move offset down by one ( EFL behavior )
86 underlinePosition = 1.0f;
89 return underlinePosition;
92 void CalcualteUnderlineHeight(const FontMetrics& fontMetrics, float& currentUnderlineHeight, float& maxUnderlineHeight)
94 //Helper method to fetch the underline metrics for the specified font glyph
95 //Height of underline represents the thickness of line.
96 if(fabsf(currentUnderlineHeight) < Math::MACHINE_EPSILON_1000)
98 currentUnderlineHeight = fontMetrics.underlineThickness;
100 // Ensure underline will be at least a pixel high
101 if(currentUnderlineHeight < 1.0f)
103 currentUnderlineHeight = 1.0f;
107 currentUnderlineHeight = ceil(currentUnderlineHeight);
111 // The underline height should be the max underline height of all glyphs of the line.
112 if(currentUnderlineHeight > maxUnderlineHeight)
114 maxUnderlineHeight = currentUnderlineHeight;
120 } // namespace Toolkit