Add measure string function to Typesetter.
This commit is contained in:
		
							parent
							
								
									9b16e015f6
								
							
						
					
					
						commit
						82d2027cf3
					
				@ -2,9 +2,7 @@
 | 
			
		||||
using Quik.Media;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Quik.Typography
 | 
			
		||||
{
 | 
			
		||||
@ -76,10 +74,38 @@ namespace Quik.Typography
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void TypesetHorizontalDirect(this CommandList list, string str, QVec2 origin, float size, QFont font)
 | 
			
		||||
        public static QVec2 MeasureHorizontal(ReadOnlySpan<char> str, float size, QFont font)
 | 
			
		||||
        {
 | 
			
		||||
            var enumerator = new LineEnumerator(str);
 | 
			
		||||
 | 
			
		||||
            float width = 0.0f;
 | 
			
		||||
            float height = 0.0f;
 | 
			
		||||
            
 | 
			
		||||
            while (enumerator.MoveNext())
 | 
			
		||||
            {
 | 
			
		||||
                ReadOnlySpan<char> line = enumerator.Current;
 | 
			
		||||
 | 
			
		||||
                float lineHeight = 0.0f;
 | 
			
		||||
 | 
			
		||||
                foreach (Rune r in line.EnumerateRunes())
 | 
			
		||||
                {
 | 
			
		||||
                    int codepoint = r.Value;
 | 
			
		||||
                    font.Get(codepoint, size, out FontGlyph glyph);
 | 
			
		||||
                    
 | 
			
		||||
                    width += glyph.Metrics.Advance.X;
 | 
			
		||||
                    lineHeight = Math.Max(lineHeight, glyph.Metrics.Size.Y);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                height += lineHeight;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new QVec2(width, height);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void TypesetHorizontalDirect(this CommandList list, ReadOnlySpan<char> str, QVec2 origin, float size, QFont font)
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<QImage, FontDrawInfo> drawInfo = new Dictionary<QImage, FontDrawInfo>();
 | 
			
		||||
            var enumerator = new LineEnumerator(str.AsSpan());
 | 
			
		||||
            var enumerator = new LineEnumerator(str);
 | 
			
		||||
           
 | 
			
		||||
            QVec2 pen = origin;
 | 
			
		||||
            while (enumerator.MoveNext())
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user