renderer: Enforce valid alignment
No renderer_interface function (except change_alignment) should be called with a NONE alignment in the context.
This commit is contained in:
parent
fdaecdb113
commit
f37124f5af
@ -673,6 +673,7 @@ void renderer::fill_borders() {
|
|||||||
* Draw text contents
|
* Draw text contents
|
||||||
*/
|
*/
|
||||||
void renderer::render_text(const tags::context& ctxt, const string&& contents) {
|
void renderer::render_text(const tags::context& ctxt, const string&& contents) {
|
||||||
|
assert(ctxt.get_alignment() != alignment::NONE && ctxt.get_alignment() == m_align);
|
||||||
m_log.trace_x("renderer: text(%s)", contents.c_str());
|
m_log.trace_x("renderer: text(%s)", contents.c_str());
|
||||||
|
|
||||||
cairo::abspos origin{};
|
cairo::abspos origin{};
|
||||||
@ -742,6 +743,7 @@ void renderer::draw_offset(rgba color, double x, double w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void renderer::render_offset(const tags::context& ctxt, const extent_val offset) {
|
void renderer::render_offset(const tags::context& ctxt, const extent_val offset) {
|
||||||
|
assert(ctxt.get_alignment() != alignment::NONE && ctxt.get_alignment() == m_align);
|
||||||
m_log.trace_x("renderer: offset_pixel(%f)", offset);
|
m_log.trace_x("renderer: offset_pixel(%f)", offset);
|
||||||
|
|
||||||
int offset_width = units_utils::extent_to_pixel(offset, m_bar.dpi_x);
|
int offset_width = units_utils::extent_to_pixel(offset, m_bar.dpi_x);
|
||||||
@ -752,6 +754,7 @@ void renderer::render_offset(const tags::context& ctxt, const extent_val offset)
|
|||||||
|
|
||||||
void renderer::change_alignment(const tags::context& ctxt) {
|
void renderer::change_alignment(const tags::context& ctxt) {
|
||||||
auto align = ctxt.get_alignment();
|
auto align = ctxt.get_alignment();
|
||||||
|
assert(align != alignment::NONE);
|
||||||
if (align != m_align) {
|
if (align != m_align) {
|
||||||
m_log.trace_x("renderer: change_alignment(%i)", static_cast<int>(align));
|
m_log.trace_x("renderer: change_alignment(%i)", static_cast<int>(align));
|
||||||
|
|
||||||
@ -772,6 +775,7 @@ void renderer::change_alignment(const tags::context& ctxt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double renderer::get_x(const tags::context& ctxt) const {
|
double renderer::get_x(const tags::context& ctxt) const {
|
||||||
|
assert(ctxt.get_alignment() != alignment::NONE && ctxt.get_alignment() == m_align);
|
||||||
return m_blocks.at(ctxt.get_alignment()).x;
|
return m_blocks.at(ctxt.get_alignment()).x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,16 +31,21 @@ class FakeRenderer : public renderer_interface {
|
|||||||
FakeRenderer(action_context& action_ctxt) : renderer_interface(action_ctxt){};
|
FakeRenderer(action_context& action_ctxt) : renderer_interface(action_ctxt){};
|
||||||
|
|
||||||
void render_offset(const tags::context& ctxt, const extent_val offset) override {
|
void render_offset(const tags::context& ctxt, const extent_val offset) override {
|
||||||
|
EXPECT_NE(alignment::NONE, ctxt.get_alignment());
|
||||||
block_x[ctxt.get_alignment()] += offset.value;
|
block_x[ctxt.get_alignment()] += offset.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
void render_text(const tags::context& ctxt, const string&& str) override {
|
void render_text(const tags::context& ctxt, const string&& str) override {
|
||||||
|
EXPECT_NE(alignment::NONE, ctxt.get_alignment());
|
||||||
block_x[ctxt.get_alignment()] += str.size();
|
block_x[ctxt.get_alignment()] += str.size();
|
||||||
};
|
};
|
||||||
|
|
||||||
void change_alignment(const tags::context&) override{};
|
void change_alignment(const tags::context& ctxt) override {
|
||||||
|
EXPECT_NE(alignment::NONE, ctxt.get_alignment());
|
||||||
|
};
|
||||||
|
|
||||||
double get_x(const tags::context& ctxt) const override {
|
double get_x(const tags::context& ctxt) const override {
|
||||||
|
EXPECT_NE(alignment::NONE, ctxt.get_alignment());
|
||||||
return block_x.at(ctxt.get_alignment());
|
return block_x.at(ctxt.get_alignment());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,7 +125,7 @@ TEST_F(DispatchTest, ignoreFormatting) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bar_settings settings;
|
bar_settings settings;
|
||||||
m_dispatch->parse(settings, r, "%{O10}%{F#ff0000}abc%{F-}foo");
|
m_dispatch->parse(settings, r, "%{l}%{O10}%{F#ff0000}abc%{F-}foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DispatchTest, formatting) {
|
TEST_F(DispatchTest, formatting) {
|
||||||
@ -135,6 +140,7 @@ TEST_F(DispatchTest, formatting) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
InSequence seq;
|
InSequence seq;
|
||||||
|
EXPECT_CALL(r, change_alignment(match_left_align)).Times(1);
|
||||||
EXPECT_CALL(r, render_offset(_, extent_val{extent_type::PIXEL, 10})).Times(1);
|
EXPECT_CALL(r, render_offset(_, extent_val{extent_type::PIXEL, 10})).Times(1);
|
||||||
EXPECT_CALL(r, render_text(match_fg(c1), string{"abc"})).Times(1);
|
EXPECT_CALL(r, render_text(match_fg(c1), string{"abc"})).Times(1);
|
||||||
EXPECT_CALL(r, render_text(match_fg(bar_fg), string{"foo"})).Times(1);
|
EXPECT_CALL(r, render_text(match_fg(bar_fg), string{"foo"})).Times(1);
|
||||||
@ -149,7 +155,7 @@ TEST_F(DispatchTest, formatting) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_dispatch->parse(settings, r,
|
m_dispatch->parse(settings, r,
|
||||||
"%{O10}%{F#ff0000}abc%{F-}foo%{l}%{B#00ff00}bar%{R}123%{c}baz%{r}%{T123}def%{PR}"
|
"%{l}%{O10}%{F#ff0000}abc%{F-}foo%{l}%{B#00ff00}bar%{R}123%{c}baz%{r}%{T123}def%{PR}"
|
||||||
"ghi");
|
"ghi");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user