-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleTextRunLoop.cpp
53 lines (41 loc) · 1.12 KB
/
SimpleTextRunLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SimpleTextRunLoop.cpp
#include "SimpleTextRunLoop.h"
#include <algorithm>
SimpleTextRunLoop::SimpleTextRunLoop( ArrayRef<const wchar_t> text, ArrayRef<const TextFontRun> fonts )
: m_position( 0 )
, m_nextTab( 0 )
, m_text( text )
, m_fonts( fonts )
, m_font( m_fonts.begin() )
, m_fontStart( 0 )
{
}
bool SimpleTextRunLoop::Unfinished() const
{
return m_position < m_text.size();
}
SimpleTextRun SimpleTextRunLoop::NextRun()
{
size_t fontRunSize = m_font->count - ( m_position - m_fontStart );
if ( m_nextTab <= m_position )
m_nextTab = std::find( m_text.begin() + m_position, m_text.end(), '\t' ) - m_text.begin();
SimpleTextRun run( m_position, std::min( fontRunSize, m_nextTab - m_position ), m_font->fontid );
if ( run.textCount == 0 )
run.textCount = 1;
m_position += run.textCount;
if ( m_position == m_fontStart + m_font->count )
{
m_fontStart += m_font->count;
++m_font;
}
return run;
}
void SimpleTextRunLoop::NewLine( size_t start )
{
m_position = start;
while ( m_fontStart > m_position )
{
--m_font;
m_fontStart -= m_font->count;
}
}