Skip to content

Commit 01a995b

Browse files
text rendering: tilde toggles overbar
1 parent 058c2c7 commit 01a995b

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

Diff for: src/canvas/text.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ std::pair<Coordf, Coordf> Canvas::draw_text0(const Coordf &p, float size, const
4242
}
4343
begin_group(layer);
4444
while (std::getline(ss, line, '\n')) {
45-
TextData::Decoration decoration = TextData::Decoration::NONE;
46-
if (line.size() && line.front() == '~') {
47-
line = line.substr(1);
48-
decoration = TextData::Decoration::OVERLINE;
49-
}
50-
const TextData td{line, font, decoration};
45+
const TextData td{line, font};
5146

5247
Placement tf;
5348
tf.shift.x = p.x;

Diff for: src/schematic/schematic_symbol.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,18 @@ void SchematicSymbol::apply_expand()
158158
symbol.apply_expand(*pool_symbol, expand);
159159
}
160160

161+
static std::string append_tilde(const std::string &s)
162+
{
163+
if (s.size() && s.front() == '~')
164+
return s + "~";
165+
return s;
166+
}
161167

162168
static void append_pin_name(std::string &name, const std::string &x)
163169
{
164170
if (name.size())
165171
name += " ";
166-
name += x;
172+
name += append_tilde(x);
167173
}
168174

169175
void SchematicSymbol::apply_pin_names()
@@ -175,24 +181,24 @@ void SchematicSymbol::apply_pin_names()
175181
for (auto &it_pin : symbol.pins) {
176182
auto pin_uuid = it_pin.first;
177183
for (auto &pin_name : gate->unit->pins.at(pin_uuid).names) {
178-
it_pin.second.name += pin_name + " ";
184+
it_pin.second.name += append_tilde(pin_name) + " ";
179185
}
180186
UUIDPath<2> path(gate->uuid, pin_uuid);
181187
if (component->custom_pin_names.count(path)) {
182-
it_pin.second.name += component->custom_pin_names.at(path) + " ";
188+
it_pin.second.name += append_tilde(component->custom_pin_names.at(path)) + " ";
183189
}
184-
it_pin.second.name += "(" + gate->unit->pins.at(pin_uuid).primary_name + ")";
190+
it_pin.second.name += "(" + append_tilde(gate->unit->pins.at(pin_uuid).primary_name) + ")";
185191
}
186192
}
187193
else if (pin_display_mode == SchematicSymbol::PinDisplayMode::CUSTOM_ONLY) {
188194
for (auto &it_pin : symbol.pins) {
189195
auto pin_uuid = it_pin.first;
190196
UUIDPath<2> path(gate->uuid, pin_uuid);
191197
if (component->custom_pin_names.count(path) && component->custom_pin_names.at(path).size()) {
192-
it_pin.second.name = component->custom_pin_names.at(path);
198+
it_pin.second.name = append_tilde(component->custom_pin_names.at(path));
193199
}
194200
else {
195-
it_pin.second.name = gate->unit->pins.at(pin_uuid).primary_name;
201+
it_pin.second.name = append_tilde(gate->unit->pins.at(pin_uuid).primary_name);
196202
}
197203
}
198204
}
@@ -204,7 +210,7 @@ void SchematicSymbol::apply_pin_names()
204210
if (component->pin_names.count(path) && component->pin_names.at(path).size()) {
205211
const auto &names = component->pin_names.at(path);
206212
if (names.count(-1) || (pin_display_mode == SchematicSymbol::PinDisplayMode::BOTH))
207-
it_pin.second.name = gate->unit->pins.at(pin_uuid).primary_name;
213+
it_pin.second.name = append_tilde(gate->unit->pins.at(pin_uuid).primary_name);
208214
for (const auto &it : names) {
209215
if (it == -2) {
210216
// nop, see later
@@ -222,7 +228,7 @@ void SchematicSymbol::apply_pin_names()
222228
}
223229
}
224230
else {
225-
it_pin.second.name = gate->unit->pins.at(pin_uuid).primary_name;
231+
it_pin.second.name = append_tilde(gate->unit->pins.at(pin_uuid).primary_name);
226232
}
227233
}
228234
}

Diff for: src/util/text_data.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,29 @@ static unsigned int codepoint_to_hershey(gunichar c, TextData::Font font)
178178

179179
extern const char *hershey_glyphs[];
180180

181-
bool operator&(TextData::Decoration a, TextData::Decoration b)
182-
{
183-
return static_cast<int>(a) & static_cast<int>(b);
184-
}
185-
186-
TextData::TextData(const std::string &str, Font font, Decoration decoration)
181+
TextData::TextData(const std::string &str, Font font)
187182
{
188183
Glib::ustring ustr(str);
189184
int x0 = 0;
190185
lines.reserve(ustr.size());
186+
int overbar_start = -1;
187+
const int bar_y = 24;
191188
for (const gunichar c : ustr) {
189+
if (c == '~') {
190+
if (overbar_start == -1) {
191+
overbar_start = x0;
192+
continue;
193+
}
194+
else {
195+
if (overbar_start != x0) {
196+
lines.emplace_back(std::piecewise_construct, std::forward_as_tuple(overbar_start, bar_y),
197+
std::forward_as_tuple(x0, bar_y));
198+
overbar_start = -1;
199+
continue;
200+
}
201+
overbar_start = -1;
202+
}
203+
}
192204
const char *s = hershey_glyphs[codepoint_to_hershey(c, font)];
193205
int left = s[0] - 'R';
194206
int right = s[1] - 'R';
@@ -211,7 +223,6 @@ TextData::TextData(const std::string &str, Font font, Decoration decoration)
211223
xmax = std::max(xmax, x0 + x + xshift);
212224
s += 2;
213225
if (n > 0) {
214-
215226
lines.emplace_back(std::piecewise_construct, std::forward_as_tuple(x0 + x + xshift, y),
216227
std::forward_as_tuple(x0 + x2 + xshift, y2));
217228
}
@@ -224,10 +235,8 @@ TextData::TextData(const std::string &str, Font font, Decoration decoration)
224235
x0 += right - left;
225236
}
226237
xright = x0;
227-
if (decoration & Decoration::OVERLINE) {
228-
int bar_y = 24;
229-
lines.emplace_back(std::piecewise_construct, std::forward_as_tuple(0, bar_y),
230-
std::forward_as_tuple(xright, bar_y));
231-
}
238+
if (overbar_start != -1)
239+
lines.emplace_back(std::piecewise_construct, std::forward_as_tuple(overbar_start, bar_y),
240+
std::forward_as_tuple(x0, bar_y));
232241
}
233242
} // namespace horizon

Diff for: src/util/text_data.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class TextData {
2020
SCRIPT_SIMPLEX,
2121
SCRIPT_COMPLEX
2222
};
23-
24-
enum class Decoration { NONE = 0, OVERLINE = (1 << 1) };
25-
26-
TextData(const std::string &s, Font font = Font::SIMPLEX, Decoration decoration = Decoration::NONE);
23+
TextData(const std::string &s, Font font = Font::SIMPLEX);
2724
std::vector<std::pair<Coordi, Coordi>> lines;
2825
int ymin = 0;
2926
int ymax = 0;

0 commit comments

Comments
 (0)