-
Notifications
You must be signed in to change notification settings - Fork 1
/
UniscribeLayoutData.cpp
51 lines (42 loc) · 2.1 KB
/
UniscribeLayoutData.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
// UniscribeLayoutData.cpp
#include "UniscribeLayoutData.h"
#include <cassert>
UniscribeLayoutData::UniscribeLayoutData( UTF16Ref text, bool endsWithNewline )
: length( text.size() )
, endsWithNewline( endsWithNewline )
{
if ( endsWithNewline )
length++;
}
void UniscribeLayoutData::AddRun( UniscribeTextRun run,
const std::vector<WORD>& runLogClusters,
const std::vector<WORD>& runGlyphs,
const std::vector<SCRIPT_VISATTR>& runVisAttrs,
const std::vector<int>& runAdvanceWidths,
const std::vector<GOFFSET>& runOffsets )
{
runs.push_back( run );
logClusters .insert( logClusters .end(), runLogClusters .begin(), runLogClusters .end() );
glyphs .insert( glyphs .end(), runGlyphs .begin(), runGlyphs .end() );
visAttrs .insert( visAttrs .end(), runVisAttrs .begin(), runVisAttrs .end() );
advanceWidths.insert( advanceWidths.end(), runAdvanceWidths.begin(), runAdvanceWidths.end() );
offsets .insert( offsets .end(), runOffsets .begin(), runOffsets .end() );
}
UniscribeTextRun UniscribeLayoutData::DiscardFrom( size_t position )
{
assert( !runs.empty() );
assert( position <= runs.back().textStart + runs.back().textCount );
assert( runs.front().textStart == 0 );
size_t i = runs.size() - 1;
while ( runs[i].textStart > position )
--i;
UniscribeTextRun run = runs[i];
run.textCount = position - run.textStart;
runs .erase( runs .begin() + i, runs .end() );
logClusters .erase( logClusters .begin() + run.textStart, logClusters .end() );
glyphs .erase( glyphs .begin() + run.glyphStart, glyphs .end() );
visAttrs .erase( visAttrs .begin() + run.glyphStart, visAttrs .end() );
advanceWidths.erase( advanceWidths.begin() + run.glyphStart, advanceWidths.end() );
offsets .erase( offsets .begin() + run.glyphStart, offsets .end() );
return run;
}