Merge "Text improvement 1. Text - Layout text & icons. * Feature added to layout...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / text / bitmap-font.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/devel-api/text/bitmap-font.h>
20
21 // EXTERNAL INCLUDE
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/devel-api/text-abstraction/bitmap-font.h>
24
25 // INTERNAL INCLUDE
26 #include <dali-toolkit/internal/text/character-set-conversion.h>
27 #include <dali-toolkit/internal/text/text-definitions.h>
28
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35 using namespace Text;
36 namespace DevelText
37 {
38
39 Glyph::Glyph()
40 : url{},
41   utf8{ 0u },
42   ascender{ 0.f },
43   descender{ 0.f }
44 {}
45
46 Glyph::~Glyph()
47 {}
48
49 BitmapFontDescription::BitmapFontDescription()
50 : glyphs{},
51   name{},
52   underlinePosition{ 0.f },
53   underlineThickness{ 1.f }
54 {}
55
56 BitmapFontDescription::~BitmapFontDescription()
57 {}
58
59 void CreateBitmapFont( const BitmapFontDescription& description, TextAbstraction::BitmapFont& bitmapFont )
60 {
61   bitmapFont.glyphs.reserve( description.glyphs.size() );
62   bitmapFont.name = description.name;
63   bitmapFont.underlinePosition = description.underlinePosition;
64   bitmapFont.underlineThickness = description.underlineThickness;
65
66   for( const auto& glyph : description.glyphs )
67   {
68     // 1) Convert to utf32
69     Vector<Character> utf32;
70     utf32.Resize( glyph.utf8.size() );
71
72     const uint32_t numberOfCharacters = ( glyph.utf8.size() == 0 ) ? 0 :
73         Text::Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( glyph.utf8.c_str() ),
74                            glyph.utf8.size(),
75                            &utf32[0u] );
76     utf32.Resize( numberOfCharacters );
77
78     TextAbstraction::BitmapGlyph bitmapGlyph( glyph.url, utf32[0u], glyph.ascender, glyph.descender );
79
80     bitmapFont.glyphs.push_back( std::move( bitmapGlyph ) );
81   }
82 }
83
84 } // namespace DevelText
85
86 } // namespace Toolkit
87
88 } // namespace Dali