MCPcopy Create free account
hub / github.com/SFML/SFML / shape

Method shape

src/SFML/Graphics/Text.cpp:270–376  ·  view source on GitHub ↗

Our shape function

Source from the content-addressed store, hash-verified

268
269 // Our shape function
270 std::vector<GlyphData> shape(
271 const sf::String& input,
272 const std::vector<std::uint32_t>& indices,
273 hb_script_t script,
274 hb_direction_t direction,
275 sf::Text::TextOrientation orientation,
276 sf::Text::ClusterGrouping clusterGrouping,
277 float outlineThickness,
278 std::uint32_t style)
279 {
280 assert(input.getSize() == indices.size() && "Input string length does not match indices count");
281
282 // Adjust the direction if a vertical orientation was set
283 if (orientation == sf::Text::TextOrientation::TopToBottom)
284 {
285 direction = HB_DIRECTION_TTB;
286 }
287 else if (orientation == sf::Text::TextOrientation::BottomToTop)
288 {
289 direction = HB_DIRECTION_BTT;
290 }
291
292 const std::lock_guard lock(mutex);
293 auto* buffer = shapingBuffer.get();
294
295 // Clear out and add the input to the buffer
296 hb_buffer_clear_contents(buffer);
297 hb_buffer_pre_allocate(buffer, static_cast<unsigned int>(input.getSize()));
298
299 // Instead of using hb_buffer_add_utf32, we have to use hb_buffer_add
300 // to specify the initial cluster IDs for every character
301 for (auto i = 0u; i < input.getSize(); ++i)
302 hb_buffer_add(buffer, input[i], indices[i]);
303
304 // hb_buffer_add doesn't automatically set the buffer content type so do it now
305 hb_buffer_set_content_type(buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
306
307 // Set the script and direction we detected during segmentation
308 hb_buffer_set_script(buffer, script);
309 hb_buffer_set_direction(buffer, direction);
310
311 // Try to guess the language of the text the user provided
312 hb_buffer_guess_segment_properties(buffer);
313
314 // Set the cluster level
315 switch (clusterGrouping)
316 {
317 case sf::Text::ClusterGrouping::Grapheme:
318 hb_buffer_set_cluster_level(buffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES);
319 break;
320 case sf::Text::ClusterGrouping::Character:
321 hb_buffer_set_cluster_level(buffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
322 break;
323 case sf::Text::ClusterGrouping::None:
324 hb_buffer_set_cluster_level(buffer, HB_BUFFER_CLUSTER_LEVEL_CHARACTERS);
325 break;
326 }
327

Callers 1

ensureGeometryUpdateMethod · 0.80

Calls 2

getMethod · 0.80
getSizeMethod · 0.45

Tested by

no test coverage detected