Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks

Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.

This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.

There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).

Part of #33027.
This commit is contained in:
Rémi Verschelde 2020-05-14 13:23:58 +02:00
parent 710b34b702
commit 0be6d925dc
1552 changed files with 1 additions and 33876 deletions

View file

@ -65,7 +65,6 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co
int chars_drawn = 0;
bool with_outline = has_outline();
for (int i = 0; i < p_text.length(); i++) {
int width = get_char_size(p_text[i]).width;
if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w)
@ -84,12 +83,10 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co
}
void Font::update_changes() {
emit_changed();
}
void Font::_bind_methods() {
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "string", "modulate", "clip_w", "outline_modulate"), &Font::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(-1), DEFVAL(Color(1, 1, 1)));
ClassDB::bind_method(D_METHOD("get_ascent"), &Font::get_ascent);
ClassDB::bind_method(D_METHOD("get_descent"), &Font::get_descent);
@ -108,7 +105,6 @@ Font::Font() {
/////////////////////////////////////////////////////////////////
void BitmapFont::_set_chars(const Vector<int> &p_chars) {
int len = p_chars.size();
//char 1 charsize 1 texture, 4 rect, 2 align, advance 1
ERR_FAIL_COND(len % 9);
@ -118,20 +114,17 @@ void BitmapFont::_set_chars(const Vector<int> &p_chars) {
const int *r = p_chars.ptr();
for (int i = 0; i < chars; i++) {
const int *data = &r[i * 9];
add_char(data[0], data[1], Rect2(data[2], data[3], data[4], data[5]), Size2(data[6], data[7]), data[8]);
}
}
Vector<int> BitmapFont::_get_chars() const {
Vector<int> chars;
const CharType *key = nullptr;
while ((key = char_map.next(key))) {
const Character *c = char_map.getptr(*key);
ERR_FAIL_COND_V(!c, Vector<int>());
chars.push_back(*key);
@ -150,7 +143,6 @@ Vector<int> BitmapFont::_get_chars() const {
}
void BitmapFont::_set_kernings(const Vector<int> &p_kernings) {
int len = p_kernings.size();
ERR_FAIL_COND(len % 3);
if (!len)
@ -158,18 +150,15 @@ void BitmapFont::_set_kernings(const Vector<int> &p_kernings) {
const int *r = p_kernings.ptr();
for (int i = 0; i < len / 3; i++) {
const int *data = &r[i * 3];
add_kerning_pair(data[0], data[1], data[2]);
}
}
Vector<int> BitmapFont::_get_kernings() const {
Vector<int> kernings;
for (Map<KerningPairKey, int>::Element *E = kerning_map.front(); E; E = E->next()) {
kernings.push_back(E->key().A);
kernings.push_back(E->key().B);
kernings.push_back(E->get());
@ -179,7 +168,6 @@ Vector<int> BitmapFont::_get_kernings() const {
}
void BitmapFont::_set_textures(const Vector<Variant> &p_textures) {
textures.clear();
for (int i = 0; i < p_textures.size(); i++) {
Ref<Texture2D> tex = p_textures[i];
@ -189,7 +177,6 @@ void BitmapFont::_set_textures(const Vector<Variant> &p_textures) {
}
Vector<Variant> BitmapFont::_get_textures() const {
Vector<Variant> rtextures;
for (int i = 0; i < textures.size(); i++)
rtextures.push_back(textures[i]);
@ -207,7 +194,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
clear();
while (true) {
String line = f->get_line();
int delimiter = line.find(" ");
@ -219,7 +205,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
pos++;
while (pos < line.size()) {
int eq = line.find("=", pos);
if (eq == -1)
break;
@ -249,7 +234,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
}
if (type == "info") {
if (keys.has("face"))
set_name(keys["face"]);
/*
@ -258,16 +242,13 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
*/
} else if (type == "common") {
if (keys.has("lineHeight"))
set_height(keys["lineHeight"].to_int());
if (keys.has("base"))
set_ascent(keys["base"].to_int());
} else if (type == "page") {
if (keys.has("file")) {
String base_dir = p_file.get_base_dir();
String file = base_dir.plus_file(keys["file"]);
Ref<Texture2D> tex = ResourceLoader::load(file);
@ -278,7 +259,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
}
}
} else if (type == "char") {
CharType idx = 0;
if (keys.has("id"))
idx = keys["id"].to_int();
@ -311,7 +291,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
add_char(idx, texture, rect, ofs, advance);
} else if (type == "kerning") {
CharType first = 0, second = 0;
int k = 0;
@ -335,67 +314,54 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
}
void BitmapFont::set_height(float p_height) {
height = p_height;
}
float BitmapFont::get_height() const {
return height;
}
void BitmapFont::set_ascent(float p_ascent) {
ascent = p_ascent;
}
float BitmapFont::get_ascent() const {
return ascent;
}
float BitmapFont::get_descent() const {
return height - ascent;
}
float BitmapFont::get_underline_position() const {
return 2;
}
float BitmapFont::get_underline_thickness() const {
return 1;
}
void BitmapFont::add_texture(const Ref<Texture2D> &p_texture) {
ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object.");
textures.push_back(p_texture);
}
int BitmapFont::get_texture_count() const {
return textures.size();
};
Ref<Texture2D> BitmapFont::get_texture(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, textures.size(), Ref<Texture2D>());
return textures[p_idx];
};
int BitmapFont::get_character_count() const {
return char_map.size();
};
Vector<CharType> BitmapFont::get_char_keys() const {
Vector<CharType> chars;
chars.resize(char_map.size());
const CharType *ct = nullptr;
int count = 0;
while ((ct = char_map.next(ct))) {
chars.write[count++] = *ct;
};
@ -403,7 +369,6 @@ Vector<CharType> BitmapFont::get_char_keys() const {
};
BitmapFont::Character BitmapFont::get_character(CharType p_char) const {
if (!char_map.has(p_char)) {
ERR_FAIL_V(Character());
};
@ -412,7 +377,6 @@ BitmapFont::Character BitmapFont::get_character(CharType p_char) const {
};
void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) {
if (p_advance < 0)
p_advance = p_rect.size.width;
@ -427,22 +391,18 @@ void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rec
}
void BitmapFont::add_kerning_pair(CharType p_A, CharType p_B, int p_kerning) {
KerningPairKey kpk;
kpk.A = p_A;
kpk.B = p_B;
if (p_kerning == 0 && kerning_map.has(kpk)) {
kerning_map.erase(kpk);
} else {
kerning_map[kpk] = p_kerning;
}
}
Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const {
Vector<BitmapFont::KerningPairKey> ret;
ret.resize(kerning_map.size());
int i = 0;
@ -455,7 +415,6 @@ Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const {
}
int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const {
KerningPairKey kpk;
kpk.A = p_A;
kpk.B = p_B;
@ -468,18 +427,15 @@ int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const {
}
void BitmapFont::set_distance_field_hint(bool p_distance_field) {
distance_field_hint = p_distance_field;
emit_changed();
}
bool BitmapFont::is_distance_field_hint() const {
return distance_field_hint;
}
void BitmapFont::clear() {
height = 1;
ascent = 0;
char_map.clear();
@ -489,7 +445,6 @@ void BitmapFont::clear() {
}
Size2 Font::get_string_size(const String &p_string) const {
float w = 0;
int l = p_string.length();
@ -498,7 +453,6 @@ Size2 Font::get_string_size(const String &p_string) const {
const CharType *sptr = &p_string[0];
for (int i = 0; i < l; i++) {
w += get_char_size(sptr[i], sptr[i + 1]).width;
}
@ -506,7 +460,6 @@ Size2 Font::get_string_size(const String &p_string) const {
}
Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) const {
ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height()));
int l = p_string.length();
@ -537,7 +490,6 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons
}
void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) {
for (Ref<BitmapFont> fallback_child = p_fallback; fallback_child != nullptr; fallback_child = fallback_child->get_fallback()) {
ERR_FAIL_COND_MSG(fallback_child == this, "Can't set as fallback one of its parents to prevent crashes due to recursive loop.");
}
@ -546,12 +498,10 @@ void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) {
}
Ref<BitmapFont> BitmapFont::get_fallback() const {
return fallback;
}
float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const {
const Character *c = char_map.getptr(p_char);
if (!c) {
@ -573,7 +523,6 @@ float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_c
}
Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const {
const Character *c = char_map.getptr(p_char);
if (!c) {
@ -585,14 +534,12 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const {
Size2 ret(c->advance, c->rect.size.y);
if (p_next) {
KerningPairKey kpk;
kpk.A = p_char;
kpk.B = p_next;
const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk);
if (E) {
ret.width -= E->get();
}
}
@ -601,7 +548,6 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const {
}
void BitmapFont::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_from_fnt", "path"), &BitmapFont::create_from_fnt);
ClassDB::bind_method(D_METHOD("set_height", "px"), &BitmapFont::set_height);
@ -645,19 +591,16 @@ void BitmapFont::_bind_methods() {
}
BitmapFont::BitmapFont() {
clear();
}
BitmapFont::~BitmapFont() {
clear();
}
////////////
RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
@ -676,17 +619,14 @@ RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_origi
}
void ResourceFormatLoaderBMFont::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("fnt");
}
bool ResourceFormatLoaderBMFont::handles_type(const String &p_type) const {
return (p_type == "BitmapFont");
}
String ResourceFormatLoaderBMFont::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "fnt")
return "BitmapFont";