1 #ifndef __DALI_TOOLKIT_TEXT_VECTOR_BLOB_ATLAS_H__
2 #define __DALI_TOOLKIT_TEXT_VECTOR_BLOB_ATLAS_H__
5 * Copyright (c) 2016 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.
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/images/buffer-image.h>
23 #include <dali/devel-api/rendering/texture-set.h>
24 #include <dali/devel-api/rendering/shader.h>
25 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
28 #include <dali-toolkit/internal/text/text-definitions.h>
39 typedef Dali::TextAbstraction::VectorBlob VectorBlob;
48 * @brief An atlas for vector blob data
51 class VectorBlobAtlas : public RefObject
56 * @brief Create a blob atlas.
58 * @param[in] textureWidth The atlas width.
59 * @param[in] textureHeight The atlas height.
60 * @param[in] itemWidth The width of an item in the atlas.
61 * @param[in] itemHeightQuantum The item height quantum.
62 * When blobs are added to columns in the atlas, the Y position is advanced by a multiple of this value.
64 VectorBlobAtlas( unsigned int textureWidth,
65 unsigned int textureHeight,
66 unsigned int itemWidth,
67 unsigned int itemHeightQuantum );
70 * @brief Query whether the atlas is full.
72 * @return True if the atlas is full.
77 * @brief Find the UV coordinates for a glyph in the atlas.
79 * @param[in] fontId The ID of the font containing the glyph.
80 * @param[in] glyphIndex The index of the glyph within the font.
81 * @param[out] coords If the glyph was found, an array of 4 UV coordinates will be returned.
82 * Otherwise coords will not be written into.
83 * @return True if the glyph was found.
85 bool FindGlyph( FontId fontId,
86 GlyphIndex glyphIndex,
87 BlobCoordinate* coords );
90 * @brief Add a glyph to the atlas.
92 * @param[in] fontId The ID of the font containing the glyph.
93 * @param[in] glyphIndex The index of the glyph within the font.
94 * @param[in] blobData A blob of vector data representing the glyph.
95 * @param[in] length The length of the blob data.
96 * @param[in] nominalWidth The width of the blob.
97 * @param[in] nominalHeight The height of the blob.
98 * @param[out] coords An array of 4 UV coordinates will be returned.
99 * @return True if the glyph was added. Otherwise the atlas is now full.
101 bool AddGlyph( unsigned int fontId,
102 unsigned int glyphIndex,
105 unsigned int nominalWidth,
106 unsigned int nominalHeight,
107 BlobCoordinate* coords );
110 * @brief Get the info required by the GLyphy shader.
112 * @return The shader uniform value.
114 Vector4 GetInfo() const
116 return Vector4( mTextureWidth, mTextureHeight, mItemWidth, mItemHeightQuantum );
120 * @brief Retrieve the atlas texture.
122 * @return The texture used for rendering.
124 TextureSet GetTextureSet()
132 * @brief Helper for uploading data to the texture atlas.
134 * @param[in] offsetX The x position within the atlas.
135 * @param[in] offsetY The y position within the atlas.
136 * @param[in] width The width of the data to upload.
137 * @param[in] height The height of the data to upload.
138 * @param[in] blob The blob of data to upload.
140 void TexSubImage( unsigned int offsetX,
141 unsigned int offsetY,
148 unsigned int mTextureWidth;
149 unsigned int mTextureHeight;
151 unsigned int mItemWidth;
152 unsigned int mItemHeightQuantum;
154 unsigned int mCursorX;
155 unsigned int mCursorY;
157 BufferImage mAtlasTexture;
159 TextureSet mTextureSet;
164 unsigned int glyphIndex;
165 unsigned int cacheIndex;
170 BlobCoordinate coords[4];
173 std::vector< Key > mItemLookup;
174 std::vector< Item > mItemCache;
181 } // namespace Toolkit
185 #endif // __DALI_TOOLKIT_TEXT_VECTOR_BLOB_ATLAS_H__