1 #ifndef DALI_TOOLKIT_TEXT_METRICS_H
2 #define DALI_TOOLKIT_TEXT_METRICS_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/devel-api/text-abstraction/font-client.h>
26 #include <dali-toolkit/internal/text/text-definitions.h>
38 typedef IntrusivePtr<Metrics> MetricsPtr;
41 * @brief A wrapper around FontClient used to get metrics.
43 class Metrics : public RefObject
48 * Create a new Metrics object
50 static Metrics* New( TextAbstraction::FontClient& fontClient )
52 return new Metrics( fontClient );
56 * @brief Used to switch between bitmap & vector based glyphs
58 * @param[in] glyphType The type of glyph; note that metrics for bitmap & vector based glyphs are different.
60 void SetGlyphType( TextAbstraction::GlyphType glyphType )
62 mGlyphType = glyphType;
66 * @brief Query the metrics for a font.
68 * @param[in] fontId The ID of the font for the required glyph.
69 * @param[out] metrics The font metrics.
71 void GetFontMetrics( FontId fontId, FontMetrics& metrics )
73 mFontClient.GetFontMetrics( fontId, metrics ); // inline for performance
77 * @brief Retrieve the metrics for a series of glyphs.
79 * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
80 * It may contain the advance and an offset set into the bearing from the shaping tool.
81 * On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
82 * @param[in] size The size of the array.
83 * @return True if all of the requested metrics were found.
85 bool GetGlyphMetrics( GlyphInfo* array, uint32_t size )
87 return mFontClient.GetGlyphMetrics( array, size, mGlyphType, true ); // inline for performance
91 * @brief Whether the font has Italic style.
93 * @param[in] fontId The font identifier.
95 * @return true if the font has italic style.
97 bool HasItalicStyle( FontId fontId ) const
99 return mFontClient.HasItalicStyle( fontId );
105 * A reference counted object may only be deleted by calling Unreference()
107 virtual ~Metrics() {}
114 Metrics( TextAbstraction::FontClient& fontClient )
115 : mFontClient( fontClient ),
116 mGlyphType( TextAbstraction::BITMAP_GLYPH )
120 Metrics(const Metrics&);
123 Metrics& operator=(const Metrics& rhs);
127 TextAbstraction::FontClient mFontClient;
128 TextAbstraction::GlyphType mGlyphType;
133 } // namespace Toolkit
137 #endif // DALI_TOOLKIT_TEXT_METRICS_H