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 UnderlineStyleProperties GetCurrentUnderlineProperties(GlyphIndex index,
49 const bool& isGlyphUnderlined,
50 const Vector<UnderlinedGlyphRun>& underlineRuns,
51 Vector<UnderlinedGlyphRun>::ConstIterator& currentUnderlinedGlyphRunIt,
52 const UnderlineStyleProperties& commonUnderlineProperties)
54 UnderlineStyleProperties currentUnderlineStyleProperties = commonUnderlineProperties;
56 if(isGlyphUnderlined && (currentUnderlinedGlyphRunIt != underlineRuns.End()))
58 // Retrieve the latest run to handle the nested case.
59 for(Vector<UnderlinedGlyphRun>::ConstIterator it = currentUnderlinedGlyphRunIt + 1,
60 endIt = underlineRuns.End();
64 const UnderlinedGlyphRun& run = *it;
66 if((run.glyphRun.glyphIndex <= index) && (index < (run.glyphRun.glyphIndex + run.glyphRun.numberOfGlyphs)))
68 currentUnderlinedGlyphRunIt = it;
72 currentUnderlineStyleProperties.OverrideByDefinedProperties(currentUnderlinedGlyphRunIt->properties);
75 return currentUnderlineStyleProperties;
78 float FetchUnderlinePositionFromFontMetrics(const FontMetrics& fontMetrics)
80 //Helper method to fetch the underline metrics for the specified font glyph
81 const float descender = ceil(fabsf(fontMetrics.descender));
82 float underlinePosition = ceil(fabsf(fontMetrics.underlinePosition));
84 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
85 if(underlinePosition > descender)
87 underlinePosition = descender;
90 if(fabsf(underlinePosition) < Math::MACHINE_EPSILON_1000)
92 // Move offset down by one ( EFL behavior )
93 underlinePosition = 1.0f;
96 return underlinePosition;
99 void CalcualteUnderlineHeight(const FontMetrics& fontMetrics, float& currentUnderlineHeight, float& maxUnderlineHeight)
101 //Helper method to fetch the underline metrics for the specified font glyph
102 //Height of underline represents the thickness of line.
103 if(fabsf(currentUnderlineHeight) < Math::MACHINE_EPSILON_1000)
105 currentUnderlineHeight = fontMetrics.underlineThickness;
107 // Ensure underline will be at least a pixel high
108 if(currentUnderlineHeight < 1.0f)
110 currentUnderlineHeight = 1.0f;
114 currentUnderlineHeight = ceil(currentUnderlineHeight);
118 // The underline height should be the max underline height of all glyphs of the line.
119 if(currentUnderlineHeight > maxUnderlineHeight)
121 maxUnderlineHeight = currentUnderlineHeight;
127 } // namespace Toolkit