2 * Copyright (c) 2015 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/color-segmentation.h>
36 void SetColorSegmentationInfo( const Vector<ColorRun>& characterColorRuns,
37 const Vector<GlyphIndex>& charactersToGlyph,
38 const Vector<Length>& glyphsPerCharacter,
39 Vector<ColorGlyphRun>& glyphColorRuns )
41 const VectorBase::SizeType numberOfColorRuns = characterColorRuns.Count();
43 if( 0u == numberOfColorRuns )
49 // Resize the color runs for the glyphs.
50 glyphColorRuns.Resize( numberOfColorRuns );
52 // Get pointers to the buffers.
53 ColorGlyphRun* glyphColorRunsBuffer = glyphColorRuns.Begin();
54 const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
55 const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
57 // Convert from characters to glyphs.
59 for( Vector<ColorRun>::ConstIterator it = characterColorRuns.Begin(),
60 endIt = characterColorRuns.End();
64 const ColorRun& colorRun = *it;
66 if( 0u < colorRun.characterRun.numberOfCharacters )
68 // Get the next color glyph run.
69 ColorGlyphRun& colorGlyphRun = *( glyphColorRunsBuffer + index );
70 colorGlyphRun.color = colorRun.color;
72 // Convert the color run index from character to glyph.
73 colorGlyphRun.glyphRun.glyphIndex = *( charactersToGlyphBuffer + colorRun.characterRun.characterIndex );
75 // Get the index to the last character of the run.
76 const CharacterIndex lastIndex = colorRun.characterRun.characterIndex + colorRun.characterRun.numberOfCharacters - 1u;
78 // Calculate the number of glyphs.
79 colorGlyphRun.glyphRun.numberOfGlyphs = *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - colorGlyphRun.glyphRun.glyphIndex;
86 } // namespace Toolkit