33SingleLineText::SingleLineText (core::smart_refctd_ptr<nbl::ext::TextRendering::FontFace>&& face, const std::string& text)
44{
55 m_face = std::move (face);
6- glyphBoxes.reserve (text.length ());
6+ m_glyphBoxes.reserve (text.length ());
7+
8+ m_boundingBox.min = float64_t2 (0.0 , 0.0 );
9+ m_boundingBox.max = float64_t2 (0.0 , 0.0 );
710
811 // Position transform
912 float64_t2 currentPos = float32_t2 (0.0 , 0.0 );
1013 for (uint32_t i = 0 ; i < text.length (); i++)
1114 {
1215 const auto glyphIndex = m_face->getGlyphIndex (wchar_t (text.at (i)));
13- const auto glyphMetrics = m_face->getGlyphMetricss (glyphIndex);
16+ const auto glyphMetrics = m_face->getGlyphMetrics (glyphIndex);
1417 const bool skipGenerateGlyph = (glyphIndex == 0 || (glyphMetrics.size .x == 0.0 && glyphMetrics.size .y == 0.0 ));
1518
1619 if (!skipGenerateGlyph)
@@ -25,7 +28,13 @@ SingleLineText::SingleLineText(core::smart_refctd_ptr<nbl::ext::TextRendering::F
2528 .size = glyphMetrics.size ,
2629 .glyphIdx = glyphIndex,
2730 };
28- glyphBoxes.push_back (glyphBbox);
31+
32+ m_boundingBox.min .x = nbl::core::min (m_boundingBox.min .x , glyphBbox.topLeft .x );
33+ m_boundingBox.min .y = nbl::core::min (m_boundingBox.min .y , glyphBbox.topLeft .y - glyphBbox.size .y );
34+ m_boundingBox.max .x = nbl::core::max (m_boundingBox.max .x , glyphBbox.topLeft .x + glyphBbox.size .x );
35+ m_boundingBox.max .y = nbl::core::max (m_boundingBox.max .y , glyphBbox.topLeft .y );
36+
37+ m_glyphBoxes.push_back (glyphBbox);
2938 }
3039 currentPos += glyphMetrics.advance ;
3140 }
@@ -36,7 +45,8 @@ void SingleLineText::Draw(
3645 SIntendedSubmitInfo& intendedNextSubmit,
3746 const float64_t2& baselineStart,
3847 const float32_t2& scale,
39- const float32_t & rotateAngle)
48+ const float32_t & rotateAngle,
49+ const float32_t4& color) const
4050{
4151 float32_t2 vec (cos (rotateAngle), sin (rotateAngle));
4252 float64_t3x3 rotationMulScaleMat =
@@ -54,11 +64,11 @@ void SingleLineText::Draw(
5464 float64_t3x3 transformation = mul (translationMat, rotationMulScaleMat);
5565
5666 LineStyleInfo lineStyle = {};
57- lineStyle.color = float32_t4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
67+ lineStyle.color = color ;
5868 const uint32_t styleIdx = drawResourcesFiller.addLineStyle_SubmitIfNeeded (lineStyle, intendedNextSubmit);
5969 auto glyphObjectIdx = drawResourcesFiller.addMainObject_SubmitIfNeeded (styleIdx, intendedNextSubmit);
6070
61- for (const auto & glyphBox : glyphBoxes )
71+ for (const auto & glyphBox : m_glyphBoxes )
6272 {
6373 const float64_t2 topLeft = mul (transformation, float64_t3 (glyphBox.topLeft , 1.0 )).xy ;
6474 const float64_t2 dirU = mul (transformation, float64_t3 (glyphBox.size .x , 0.0 , 0.0 )).xy ;
@@ -70,5 +80,4 @@ void SingleLineText::Draw(
7080 drawResourcesFiller.drawFontGlyph (m_face.get (), glyphBox.glyphIdx , topLeft, dirU, aspectRatio, minUV, glyphObjectIdx, intendedNextSubmit);
7181 }
7282
73- }
74-
83+ }
0 commit comments