|
|
@@ -609,6 +609,8 @@ assemble_text() {
|
|
|
* Returns the width of a single character, according to its associated font.
|
|
|
* This also correctly calculates the width of cheesy ligatures and accented
|
|
|
* characters, which may not exist in the font as such.
|
|
|
+ *
|
|
|
+ * This does not take kerning into account, however.
|
|
|
*/
|
|
|
PN_stdfloat TextAssembler::
|
|
|
calc_width(wchar_t character, const TextProperties &properties) {
|
|
|
@@ -1399,6 +1401,9 @@ assemble_row(TextAssembler::TextRow &row,
|
|
|
PN_stdfloat xpos = 0.0f;
|
|
|
align = TextProperties::A_left;
|
|
|
|
|
|
+ // Remember previous character, for kerning.
|
|
|
+ int prev_char = -1;
|
|
|
+
|
|
|
bool underscore = false;
|
|
|
PN_stdfloat underscore_start = 0.0f;
|
|
|
const TextProperties *underscore_properties = NULL;
|
|
|
@@ -1450,11 +1455,13 @@ assemble_row(TextAssembler::TextRow &row,
|
|
|
if (character == ' ') {
|
|
|
// A space is a special case.
|
|
|
xpos += properties->get_glyph_scale() * properties->get_text_scale() * font->get_space_advance();
|
|
|
+ prev_char = -1;
|
|
|
|
|
|
} else if (character == '\t') {
|
|
|
// So is a tab character.
|
|
|
PN_stdfloat tab_width = properties->get_tab_width();
|
|
|
xpos = (floor(xpos / tab_width) + 1.0f) * tab_width;
|
|
|
+ prev_char = -1;
|
|
|
|
|
|
} else if (character == text_soft_hyphen_key) {
|
|
|
// And so is the 'soft-hyphen' key character.
|
|
|
@@ -1493,6 +1500,7 @@ assemble_row(TextAssembler::TextRow &row,
|
|
|
placed_glyphs.push_back(placement);
|
|
|
|
|
|
xpos += advance * glyph_scale;
|
|
|
+ prev_char = -1;
|
|
|
|
|
|
} else {
|
|
|
// A printable character.
|
|
|
@@ -1521,6 +1529,14 @@ assemble_row(TextAssembler::TextRow &row,
|
|
|
<< "\n";
|
|
|
}
|
|
|
|
|
|
+ // Add the kerning delta.
|
|
|
+ if (text_kerning) {
|
|
|
+ if (prev_char != -1) {
|
|
|
+ xpos += font->get_kerning(prev_char, character);
|
|
|
+ }
|
|
|
+ prev_char = character;
|
|
|
+ }
|
|
|
+
|
|
|
// Build up a GlyphPlacement, indicating all of the Geoms that go into
|
|
|
// this character. Normally, there is only one Geom per character, but
|
|
|
// it may involve multiple Geoms if we need to add cheesy accents or
|