[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 04/23: [libgroff]: Fix code style nits.
From: |
G. Branden Robinson |
Subject: |
[groff] 04/23: [libgroff]: Fix code style nits. |
Date: |
Thu, 23 Sep 2021 08:12:31 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 3b2971b73c34b90676e5971bee0369a0216fd38e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Sep 22 19:56:57 2021 +1000
[libgroff]: Fix code style nits.
* src/libs/libgroff/font.cpp (font::font): Use initializer list as much
as possible in constructor.
(font::unit_scale, font::get_width, font::get_height, font::get_depth,
font::get_italic_correction, font::get_left_italic_correction,
font::get_subscript_correction, font::get_character_type,
font::get_code, font::get_special_device_encoding): These member
functions rely on the font being either indexed or associated with an
output device that uses the `unicode` directive in its `DESC` file.
The compiler doesn't know this, so annotate the `abort()` calls that
conclude them. Add an `assert()` before each one to more usefully
describe the violated invariant in the event this unreachable code is
somehow reached.
(font::get_width): Annotate special meaning of zero zoom factor.
---
ChangeLog | 19 +++++++++++++++++++
src/libs/libgroff/font.cpp | 46 ++++++++++++++++++++++++++--------------------
2 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a107e00..af165cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2021-09-22 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [libgroff]: Fix code style nits.
+
+ * src/libs/libgroff/font.cpp (font::font): Use initializer list
+ as much as possible in constructor.
+ (font::unit_scale, font::get_width, font::get_height,
+ font::get_depth, font::get_italic_correction,
+ font::get_left_italic_correction,
+ font::get_subscript_correction, font::get_character_type,
+ font::get_code, font::get_special_device_encoding): These member
+ functions rely on the font being either indexed or associated
+ with an output device that uses the `unicode` directive in its
+ `DESC` file. The compiler doesn't know this, so annotate the
+ `abort()` calls that conclude them. Add an `assert()` before
+ each one to more usefully describe the violated invariant in the
+ event this unreachable code is somehow reached.
+ (font::get_width): Annotate special meaning of zero zoom factor.
+
2021-09-21 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/include/font.h (UNDEFINED_GLYPH): Use idiomatic C++98 null
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 0514e4e..e3a3981 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -189,16 +189,13 @@ int glyph_to_unicode(glyph *g)
/* font functions */
-font::font(const char *s)
-: ligatures(0), kern_hash_table(0), space_width(0), special(false),
- ch_index(0), nindices(0), ch(0), ch_used(0), ch_size(0), widths_cache(0)
+font::font(const char *s) : ligatures(0), kern_hash_table(0),
+ space_width(0), special(false), internalname(0), slant(0.0), zoom(0),
+ ch_index(0), nindices(0), ch(0), ch_used(0), ch_size(0),
+ widths_cache(0)
{
name = new char[strlen(s) + 1];
strcpy(name, s);
- internalname = 0;
- slant = 0.0;
- zoom = 0;
- // load(); // for testing
}
font::~font()
@@ -285,7 +282,7 @@ bool font::unit_scale(double *value, char unit)
divisor = 2.54;
break;
default:
- assert(0);
+ assert(0 == "unit not in [cipP]");
break;
}
if (divisor) {
@@ -344,7 +341,7 @@ int font::get_width(glyph *g, int point_size)
int idx = glyph_to_index(g);
assert(idx >= 0);
int real_size;
- if (!zoom)
+ if (zoom == 0) // 0 means "don't zoom"
real_size = point_size;
else
{
@@ -392,7 +389,8 @@ int font::get_width(glyph *g, int point_size)
else
return scale(width, point_size);
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_height(glyph *g, int point_size)
@@ -407,7 +405,8 @@ int font::get_height(glyph *g, int point_size)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_depth(glyph *g, int point_size)
@@ -422,7 +421,8 @@ int font::get_depth(glyph *g, int point_size)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_italic_correction(glyph *g, int point_size)
@@ -437,7 +437,8 @@ int font::get_italic_correction(glyph *g, int point_size)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_left_italic_correction(glyph *g, int point_size)
@@ -452,7 +453,8 @@ int font::get_left_italic_correction(glyph *g, int
point_size)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_subscript_correction(glyph *g, int point_size)
@@ -467,7 +469,8 @@ int font::get_subscript_correction(glyph *g, int point_size)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
void font::set_zoom(int factor)
@@ -540,7 +543,8 @@ int font::get_character_type(glyph *g)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
int font::get_code(glyph *g)
@@ -563,7 +567,8 @@ int font::get_code(glyph *g)
return n;
}
// The caller must check 'contains(g)' before calling get_code(g).
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
const char *font::get_name()
@@ -588,7 +593,8 @@ const char *font::get_special_device_encoding(glyph *g)
// Unicode font
return 0;
}
- abort();
+ assert(0 == "glyph is not indexed and device lacks Unicode support");
+ abort(); // -Wreturn-type
}
const char *font::get_image_generator()
@@ -613,7 +619,7 @@ void font::alloc_ch_index(int idx)
nindices = idx + 10;
int *old_ch_index = ch_index;
ch_index = new int[nindices];
- memcpy(ch_index, old_ch_index, sizeof(int)*old_nindices);
+ memcpy(ch_index, old_ch_index, sizeof(int) * old_nindices);
for (int i = old_nindices; i < nindices; i++)
ch_index[i] = -1;
delete[] old_ch_index;
@@ -629,7 +635,7 @@ void font::extend_ch()
ch_size *= 2;
font_char_metric *old_ch = ch;
ch = new font_char_metric[ch_size];
- memcpy(ch, old_ch, old_ch_size*sizeof(font_char_metric));
+ memcpy(ch, old_ch, old_ch_size * sizeof(font_char_metric));
delete[] old_ch;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 04/23: [libgroff]: Fix code style nits.,
G. Branden Robinson <=