Flutter Engine
styled_runs.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "styled_runs.h"
18 
19 #include "flutter/fml/logging.h"
20 #include "utils/WindowsUtils.h"
21 
22 namespace txt {
23 
24 StyledRuns::StyledRuns() = default;
25 
26 StyledRuns::~StyledRuns() = default;
27 
29  styles_.swap(other.styles_);
30  runs_.swap(other.runs_);
31 }
32 
34  styles_.swap(other.styles_);
35  runs_.swap(other.runs_);
36  return *this;
37 }
38 
40  styles_.swap(other.styles_);
41  runs_.swap(other.runs_);
42 }
43 
44 size_t StyledRuns::AddStyle(const TextStyle& style) {
45  const size_t style_index = styles_.size();
46  styles_.push_back(style);
47  return style_index;
48 }
49 
50 const TextStyle& StyledRuns::GetStyle(size_t style_index) const {
51  return styles_[style_index];
52 }
53 
54 void StyledRuns::StartRun(size_t style_index, size_t start) {
55  EndRunIfNeeded(start);
56  runs_.push_back(IndexedRun{style_index, start, start});
57 }
58 
60  if (runs_.empty())
61  return;
62  IndexedRun& run = runs_.back();
63  if (run.start == end) {
64  // The run is empty. We can skip it.
65  runs_.pop_back();
66  } else {
67  run.end = end;
68  }
69 }
70 
71 StyledRuns::Run StyledRuns::GetRun(size_t index) const {
72  const IndexedRun& run = runs_[index];
73  return Run{styles_[run.style_index], run.start, run.end};
74 }
75 
76 } // namespace txt
size_t AddStyle(const TextStyle &style)
Definition: styled_runs.cc:44
void StartRun(size_t style_index, size_t start)
Definition: styled_runs.cc:54
void EndRunIfNeeded(size_t end)
Definition: styled_runs.cc:59
const TextStyle & GetStyle(size_t style_index) const
Definition: styled_runs.cc:50
void swap(StyledRuns &other)
Definition: styled_runs.cc:39
Run GetRun(size_t index) const
Definition: styled_runs.cc:71
const StyledRuns & operator=(StyledRuns &&other)
Definition: styled_runs.cc:33