+
+void Changes::addToToc(DocIterator const & cdit, Buffer const & buffer,
+ bool output_active, TocBackend & backend) const
+{
+ if (table_.empty())
+ return;
+
+ shared_ptr<Toc> change_list = backend.toc("change");
+ AuthorList const & author_list = buffer.params().authors();
+ DocIterator dit = cdit;
+
+ for (ChangeRange const & cr : table_) {
+ docstring str;
+ switch (cr.change.type) {
+ case Change::UNCHANGED:
+ continue;
+ case Change::DELETED:
+ // ✂ U+2702 BLACK SCISSORS
+ str.push_back(0x2702);
+ break;
+ case Change::INSERTED:
+ // ✍ U+270D WRITING HAND
+ str.push_back(0x270d);
+ break;
+ }
+ dit.pos() = cr.range.start;
+ Paragraph const & par = dit.paragraph();
+ str += " " + par.asString(cr.range.start, min(par.size(), cr.range.end));
+ if (cr.range.end > par.size())
+ // ¶ U+00B6 PILCROW SIGN
+ str.push_back(0xb6);
+ docstring const & author = author_list.get(cr.change.author).name();
+ Toc::iterator it = TocBackend::findItem(*change_list, 0, author);
+ if (it == change_list->end()) {
+ change_list->push_back(TocItem(dit, 0, author, true));
+ change_list->push_back(TocItem(dit, 1, str, output_active));
+ continue;
+ }
+ for (++it; it != change_list->end(); ++it) {
+ if (it->depth() == 0 && it->str() != author)
+ break;
+ }
+ change_list->insert(it, TocItem(dit, 1, str, output_active));
+ }
+}
+
+
+void Changes::updateBuffer(Buffer const & buf)
+{
+ bool const changed = isChanged();
+ buf.setChangesPresent(buf.areChangesPresent() || changed);
+ previously_changed_ = changed;
+}
+
+
+void Change::paintCue(PainterInfo & pi, double const x1, double const y,
+ double const x2, FontInfo const & font) const
+{
+ if (!changed())
+ return;
+ // Calculate 1/3 height of font
+ FontMetrics const & fm = theFontMetrics(font);
+ double const y_bar = deleted() ? y - fm.maxAscent() / 3
+ : y + 2 * pi.base.solidLineOffset() + pi.base.solidLineThickness();
+ pi.pain.line(int(x1), int(y_bar), int(x2), int(y_bar), color(),
+ Painter::line_solid, pi.base.solidLineThickness());
+}
+
+
+void Change::paintCue(PainterInfo & pi, double const x1, double const y1,
+ double const x2, double const y2) const
+{
+ /*
+ * y1 /
+ * /
+ * /
+ * /
+ * /
+ * y2 /_____
+ * x1 x2
+ */
+ switch(type) {
+ case UNCHANGED:
+ return;
+ case INSERTED:
+ pi.pain.line(int(x1), int(y2) + 1, int(x2), int(y2) + 1,
+ color(), Painter::line_solid,
+ pi.base.solidLineThickness());
+ return;
+ case DELETED:
+ // FIXME: we cannot use antialias since we keep drawing on the same
+ // background with the current painting mechanism.
+ pi.pain.line(int(x1), int(y2), int(x2), int(y1),
+ color(), Painter::line_solid_aliased,
+ pi.base.solidLineThickness());
+ return;
+ }
+}
+
+